Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 07:52:17 -0700, Ian Kelly wrote: >> I have no idea what was imported before. I just want to import >> hexdump(). Unfortunately, this does not work: >> >> from utilities import hexdump >> >> ImportError: cannot import name hexdump > > What is utilities? Is it a module on

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 15:31:45 +, John Gordon wrote: > The most likely explanation here is that the 'utilities' module simply > does not contain something named 'hexdump'. > > Have you inspected the 'utilities' module? Does it, in fact, contain > something named 'hexdump'? Yes -- https://ma

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 15:44:43 +, John Gordon wrote: > How did this error come up? Did the code work previously? If so, what > changed? The developers of this legacy code had this as well as other functions duplicated throughout the system, in order to avoid confronting these issues. I'm tr

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 15:44:43 +, John Gordon wrote: > In that case, the problem is most likely a circular import issue, as you > mentioned. The only way to fix it is to reorganize your modules. > > How did this error come up? Did the code work previously? If so, what > changed? What I nee

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 08:59:39 -0700, Ian Kelly wrote: > What happens if you just do 'import utilities'. Can you then call > utilities.hexdump? Can you see anything in the utilities module? Yes, that works! That's what I'm doing as a work around. I was trying to avoid doing that because I figured

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 16:30:30 +, Charles T. Smith wrote: >> Side observation: 'int' is a bad name for a package, because it will >> shadow the name of the 'int' built-in. > > > Boy oh boy have I experienced that now! :) (it wasn't me! ;)

Re: Refactoring in a large code base

2016-01-22 Thread Charles T. Smith
On Fri, 22 Jan 2016 12:19:50 +0200, Marko Rauhamaa wrote: > We need similar code sanity management. Developers are given much too > much power to mess up the source code. That's why "legacy" is considered > a four-letter word among developers. When I started in this business, in the mid-70s, ther

How a module is being marked as imported?

2016-02-04 Thread Jean-Charles Lefebvre
Hi all, The short version: How CPython marks a module as being fully imported, if it does, so that the same import statement ran from another C thread at the same time does not collide? Or, reversely, does not think the module is not already fully imported? The full version: I'm running CPytho

Re: How a module is being marked as imported?

2016-02-04 Thread Jean-Charles Lefebvre
ted. On Thursday, February 4, 2016 at 11:20:05 AM UTC+1, Jean-Charles Lefebvre wrote: > Hi all, > > The short version: How CPython marks a module as being fully imported, if it > does, so that the same import statement ran from another C thread at the same > time does not co

a clarification on the "global" statement sought

2016-03-11 Thread Charles T. Smith
When might a "global" statement be used in the outermost level of a module? (whereby, I assume a module is equivalent to a python file, correct?) TIA for any thoughts. cts -- https://mail.python.org/mailman/listinfo/python-list

Re: a clarification on the "global" statement sought

2016-03-11 Thread Charles T. Smith
On Fri, 11 Mar 2016 19:29:20 +1100, Chris Angelico wrote: > Usefully? Never. > > Simple question - simple answer :) > > ChrisA Right, that was the expected answer as well. I just ran into that in legacy code, checked out the documentation and couldn't really make that out. So I figured I bet

Re: a clarification on the "global" statement sought

2016-03-11 Thread Charles T. Smith
On Fri, 11 Mar 2016 08:31:22 +, Mark Lawrence wrote: > Never. Hopefully this > http://www.python-course.eu/python3_global_vs_local_variables.php can > explain it better than I can :) The article is good, I'm glad to have confirmed what I have so empirical stumbled over. ... Irrespective of t

hasattr() or "x in y"?

2016-03-11 Thread Charles T. Smith
>From the performance point of view, which is better: - hasattr() - x in y TIA cts -- https://mail.python.org/mailman/listinfo/python-list

Re: hasattr() or "x in y"?

2016-03-11 Thread Charles T. Smith
On Fri, 11 Mar 2016 21:44:27 +, Charles T. Smith wrote: > From the performance point of view, which is better: - hasattr() > - x in y > > TIA > cts I just realized that "in" won't look back through the class hierarchy... that clearly makes them not interc

Re: hasattr() or "x in y"?

2016-03-11 Thread Charles T. Smith
On Fri, 11 Mar 2016 22:00:41 +, Grant Edwards wrote: > Since they behave differently, perhaps the question ought to be "which > does what you want to do?" For parsed msgs, I had this: elif hasattr (msg.msgBody, 'request'): It occurred to me that this was less abstruse:

sobering observation, python vs. perl

2016-03-18 Thread Charles T. Smith
I've really learned to love working with python, but it's too soon to pack perl away. I was amazed at how long a simple file search took so I ran some statistics: $ time python find-rel.py ./find-relreq *.out | sort -u TestCase_F_00_P TestCase_F_00_S TestCase_F_01_S TestCa

Re: sobering observation, python vs. perl

2016-03-19 Thread Charles T. Smith
On Thu, 17 Mar 2016 18:34:06 +0200, Marko Rauhamaa wrote: > n-vs-perl-performance Okay, that was interesting. Actually, I saw a study some years ago that concluded that python could be both slower and faster than perl, but that perl had much less deviation than python. I took that and accepted

Re: sobering observation, python vs. perl

2016-03-19 Thread Charles T. Smith
On Thu, 17 Mar 2016 17:47:55 +0200, Marko Rauhamaa wrote: > Can't comment on the numbers but the code segments are not quite > analogous. What about this one: > > #!/usr/bin/env python > # vim: tw=0 > import sys > import re > > isready = re.compile("(.*) is ready") > for

Re: sobering observation, python vs. perl

2016-03-19 Thread Charles T. Smith
On Thu, 17 Mar 2016 09:21:51 -0700, Ethan Furman wrote: >> well, I don't want to forgo REs in order to have python's numbers be >> better > > The issue is not avoiding REs, but using Python's strengths and idioms. > Write the code in Python's style, get the same results, then compare > t

Re: sobering observation, python vs. perl

2016-03-19 Thread Charles T. Smith
On Thu, 17 Mar 2016 17:48:54 +0200, Marko Rauhamaa wrote: > "Charles T. Smith" : > >> On Thu, 17 Mar 2016 15:29:47 +, Charles T. Smith wrote: >> >> And for completeness, and also surprising: >> >> time sed -n -e '/ is ready

Re: sobering observation, python vs. perl

2016-03-19 Thread Charles T. Smith
On Thu, 17 Mar 2016 18:07:12 +0200, Marko Rauhamaa wrote: > "Charles T. Smith" : > Ok. The LANG=C setting has a tremendous effect on the performance of > textutils. > > > Marko Good to know, thank you... -- https://mail.python.org/mailman/listinfo/python-list

Re: sobering observation, python vs. perl

2016-03-19 Thread Charles T. Smith
On Thu, 17 Mar 2016 10:26:12 -0700, Ethan Furman wrote: > On 03/17/2016 09:36 AM, Charles T. Smith wrote: > >> Yes, your point was to forgo REs despite that they are useful. >> I could have thought the search would have been better as: >> >> 'release[

Re: sobering observation, python vs. perl

2016-03-19 Thread Charles T. Smith
On Thu, 17 Mar 2016 18:30:29 +0200, Marko Rauhamaa wrote: > "Charles T. Smith" : > >> I need the second check to also be a RE because it's not >> separate tokens. > > The string "in" check doesn't care about tokens. > > > Marko

Re: sobering observation, python vs. perl

2016-03-19 Thread Charles T. Smith
On Thu, 17 Mar 2016 10:52:30 -0500, Tim Chase wrote: >> Not saying this will make a great deal of difference, but these two > items jumped out at me. I'd even be tempted to just use string > manipulations for the isready aspect as well. Something like > (untested) well, I don't want to forgo RE

Re: sobering observation, python vs. perl

2016-03-20 Thread Charles T. Smith
On Thu, 17 Mar 2016 19:08:58 +0200, Marko Rauhamaa wrote: > "Charles T. Smith" : > > > Compare Perl (http://www.perlmonks.org/?node_id=98357>): > >my $str = "I have a dream"; >my $find = "have"; >my $replace = "h

Re: sobering observation, python vs. perl

2016-03-20 Thread Charles T. Smith
On Thu, 17 Mar 2016 15:29:47 +, Charles T. Smith wrote: And for completeness, and also surprising: time sed -n -e '/ is ready/{s///;h}' -e '/release_req/{g;p}' *.out | sort -u TestCase_F_00_P TestCase_F_00_S TestCase_F_01_S TestCase_F_02_M real0m10.998s u

Re: sobering observation, python vs. perl

2016-03-20 Thread Charles T. Smith
On Thu, 17 Mar 2016 21:18:43 +0530, srinivas devaki wrote: > please upload the log file, Sorry, it's work stuff, can't do that, but just take any big set of files and change the strings appropriately and the numbers should be equivalent. > > and global variables in python are slow, so just ke

caught in the import web again

2014-11-15 Thread Charles T. Smith
Now, I'm getting these errors: ImportError: cannot import name ... and AttributeError: 'module' object has no attribute ... (what is 'module'?) Is there a way to resolve this without having to restructure my code every couple of days? I thought using imports of the form: from module i

Re: caught in the import web again

2014-11-16 Thread Charles T. Smith
On Sun, 16 Nov 2014 08:14:05 +0100, dieter wrote: > "Charles T. Smith" writes: >> Now, I'm getting these errors: >> >> ImportError: cannot import name ... >> >> and >> >> AttributeError: 'module' object has no attrib

Re: caught in the import web again

2014-11-17 Thread Charles T. Smith
On Mon, 17 Nov 2014 08:08:40 +0100, dieter wrote: > "Charles T. Smith" writes: >> ... >> Are others equally frustrated by this or is there a trick or principle >> that I'm missing. At this point, I guess the way I'll have to proceed >> is to put e

Re: caught in the import web again

2014-11-18 Thread Charles T. Smith
On Tue, 18 Nov 2014 00:00:42 -0700, Michael Torrie wrote: > On 11/17/2014 03:45 PM, Steven D'Aprano wrote: > >> Circular dependencies are not just a problem in Python, they are a >> problem throughout most of software design. > > Personally I find that duck typing eliminates a lot of the circula

pylint style convention

2007-07-23 Thread Mick Charles Beaver
Hello, I've been looking into using PyLint on some of my programs, just as a best practices kind of thing. Here's a snippet: #== if __name__ == '__main__': parser = optparse.OptionParser(usage='usage: %prog [OPTIONS]') pa

How to build Hierarchies of dict's? (Prototypes in Python?)

2007-02-23 Thread Charles D Hixson
I'm sure I've read before about how to construct prototypes in Python, but I haven't been able to track it down (or figure it out). What I basically want is a kind of class that has both class and instance level dict variables, such that descendant classes automatically create their own class a

Re: How to build Hierarchies of dict's? (Prototypes in Python?)

2007-02-23 Thread Charles D Hixson
Gabriel Genellina wrote: >> En Fri, 23 Feb 2007 17:53:59 -0300, Charles D Hixson >> <[EMAIL PROTECTED]> escribió: >> >> >>> I'm sure I've read before about how to construct prototypes in Python, >>> but I haven't been able to track

Re: How to build Hierarchies of dict's? (Prototypes in Python?)

2007-02-23 Thread Charles D Hixson
Larry Bates wrote: > Charles D Hixson wrote: > >> I'm sure I've read before about how to construct prototypes in Python, >> but I haven't been able to track it down (or figure it out). >> >> What I basically want is a kind of class that has both cla

Re: How to build Hierarchies of dict's? (Prototypes in Python?)

2007-02-24 Thread Charles D Hixson
Toby wrote: > Charles D Hixson wrote: > >> What I basically want is a kind of class that has both class and >> instance level dict variables, such that descendant classes >> automatically create their own class and instance level dict variables. >> The id

Re: How to build Hierarchies of dict's? (Prototypes in Python?)

2007-02-25 Thread Charles D Hixson
Toby wrote: > Charles D Hixson wrote: > >> a class whose sub-classes automatically have unique class variables of >> a determined form such that I can do a hierarchical search through them >> > > Something like this? > (scroll down to see the results

Iterators: Would "rewind" be a good idea?

2006-05-21 Thread Charles D Hixson
I was reading through old messages in the list and came up against an idea that I thought might be of some value: "Wouldn't it be a good idea if one could "rewind" an iterator?" Not stated in precisely those terms, perhaps, but that's the way I read it. I appreciate that one could use a sequence r

class level properties

2008-04-12 Thread Charles D Hixson
I'm trying to construct read-only variables at the class level. I've been unsuccessful. Any suggestions? Mixing @classmethod and @property doesn't appear to produce workable code. Ditto for mixing @classmethod and __getattr__. (The property approach compiles, but execution says that you can

Re: class level properties

2008-04-12 Thread Charles D Hixson
Arnaud Delobelle wrote: > On Apr 12, 8:36 pm, Charles D Hixson <[EMAIL PROTECTED]> > wrote: > >> I'm trying to construct read-only variables at the class level. I've >> been unsuccessful. Any suggestions? >> >> Mixing @classmethod and @pr

Re: class level properties

2008-04-13 Thread Charles D Hixson
Peter Otten wrote: > Charles D Hixson wrote: > > >> I want a hundred or so read-only variables, and I'm not sure the best >> way to achieve it. >> > > What do you really want to do? I recommend that you forget about bondage and > rely upon displin

Re: Trouble with os.system

2010-02-03 Thread Charles-Pierre Astolfi
That was it ! What a stupid error... Thank you ! -- Cp On Wed, Feb 3, 2010 at 20:13, Jerry Hill wrote: > On Wed, Feb 3, 2010 at 12:58 PM, Cpa wrote: >> Sure. >> >> import sys,re,os >> files2create = sys.argv[1:] >> os.system('mkdir tmp') >> >> # Some code to create the .tex >> >> # Compile t

PDB how to define a global inspection function?

2011-02-08 Thread Charles Fox (Sheffield)
ternal libraries). Is there a way to put it in the global scope for pdb to use? Also is there a way to automatically import it whenever pdb starts up (like a matlab startup file)? (I'm not using ipython as it's not happy with pdbtrack in emacs, so am launching from emacs M- x pdb

Re: PDB how to define a global inspection function?

2011-02-10 Thread Charles Fox (Sheffield)
db command). > > For debugging purposes it's OK to put your function into the __builtin__ > namespace: > > > > >>> def p(): print 42 > ... > >>> import __builtin__ > >>> __builtin__.p = p > > Try it out: > > >>> with open("tmp.py", "w") as f: > > ...     f.write("p()\n") > ...>>> import tmp > > 42 Thanks very much for your help, Peter, that's exactly what I was after :-) Charles -- http://mail.python.org/mailman/listinfo/python-list

Shared memory python between two separate shell-launched processes

2011-02-10 Thread Charles Fox (Sheffield)
there any other ways to do this? thanks, Charles -- http://mail.python.org/mailman/listinfo/python-list

Re: Shared memory python between two separate shell-launched processes

2011-02-10 Thread Charles Fox (Sheffield)
On Feb 10, 3:43 pm, Jean-Paul Calderone wrote: > On Feb 10, 9:30 am, "Charles Fox (Sheffield)" > wrote: > > > Hi guys, > > I'm working on debugging a large python simulation which begins by > > preloading a huge cache of data.  I want to step through

Re: Shared memory python between two separate shell-launched processes

2011-02-11 Thread Charles Fox (Sheffield)
On Feb 10, 6:22 pm, Jean-Paul Calderone wrote: > On Feb 10, 12:21 pm, "Charles Fox (Sheffield)" > wrote: > > > > > On Feb 10, 3:43 pm, Jean-Paul Calderone > > wrote: > > > > On Feb 10, 9:30 am, "Charles Fox (Sheffield)" > > >

help with an error msg please

2017-05-14 Thread Charles T. Smith
I'm stumped by this: $ PYTHONPATH= python except Traceback (most recent call last): File "except", line 7, in except getopt.error, msg: AttributeError: 'module' object has no attribute 'error' The program is: $ cat except #!/usr/bin/env python import getopt try: opts, args = get

Re: help with an error msg please

2017-05-14 Thread Charles T. Smith
On Sun, 14 May 2017 15:30:52 +0200, Pavol Lisy wrote: > On 5/14/17, Charles T. Smith wrote: >> I'm stumped by this: ... > Did you create getopt.py in your working directory? If so then try to > rename it. > > PL. That was it! Not in my working directory, but in th

<    1   2   3   4