Re: creating class objects inside methods

2009-10-04 Thread horos11
> > > Thanks for the info, but a couple of points: > > >     1. it wasn't meant to be production code, simply a way to teach > > python. > > Speaking as someone who does teach Python, "Ew, no!"  If you start by > teaching people bad habits, every educator who comes along afterwards > will curse yo

Re: creating class objects inside methods

2009-10-03 Thread horos11
> It's not a bug.  In Python classes and global variables share the same > namespace. > > Don't you think you should learn a bit more about how Python manages > objects and namespaces before going around calling things bugs? > > Carl Banks No, I don't think so.. Say you went to another country,

defaults for function arguments bound only once(??)

2009-10-03 Thread horos11
All, Another one, this time a bit shorter. It looks like defaults for arguments are only bound once, and every subsequent call reuses the first reference created. Hence the following will print '[10,2]' instead of the expected '[1,2]'. Now my question - exactly why is 'default_me()' only called

Re: creating class objects inside methods

2009-10-03 Thread horos11
Carl, Thanks for the info, but a couple of points: 1. it wasn't meant to be production code, simply a way to teach python. 2. this should either be a compile time or a runtime error. 'Actions at a distance' like this are deadly both to productivity and to correctness - not only is this

Re: creating class objects inside methods

2009-10-03 Thread horos11
Anyways, I see what's going on here: With the line, for state in curstate.next_states(): if not state.to_string() in seen_states: dq.append(state) Inadvertently using the name of a module as a variable seems to be causing this. In any case, this shouldn't cause issues with construct

Re: creating class objects inside methods

2009-10-03 Thread horos11
> >>> a > > <__main__.Myclass instance at 0x95cd3ec b > > <__main__.Myclass instance at 0x95cd5ac> > > What's the problem? Like I said, the code was a sample of what I was trying to do, not the entire thing.. I just wanted to see if the metaphor was kosher. It sounds to me from your answer t

creating class objects inside methods

2009-10-03 Thread horos11
All, I've got a strange one.. I'm trying to create a class object inside another class object by using the code template below (note.. this isn't the exact code.. I'm having difficulty reproducing it without posting the whole thing) Anyways, the upshot is that the first time the Myclass() constr

syntax checker in python

2009-08-07 Thread horos11
ps - I just realized that it isn't enough to do: python -c 'import /path/to/script' since that actually executes any statement inside of the script (wheras all I want to do is check syntax) So - let me reprhase that - exactly how can you do a syntax check in python? Something like perl's -c:

importing fully qualified scripts to check syntax

2009-08-07 Thread horos11
hey all, I'm trying to make a syntax checker, where I say: python -c "import /path/to/script" to check the syntax of the script named '/path/to/script' (note: no py extension needed). Of course this doesn't work because the functionality for import is bundled up with the environment.. So - is t