Re: creating class objects inside methods

2009-10-06 Thread Rhodri James
On Sun, 04 Oct 2009 19:44:48 +0100, horos11 horo...@gmail.com wrote: [somehow managing to trim all other attributions: he's the innermost, then me next] 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

Re: creating class objects inside methods

2009-10-04 Thread Carl Banks
On Oct 3, 10:12 pm, horos11 horo...@gmail.com wrote: 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

Re: creating class objects inside methods

2009-10-04 Thread Carl Banks
On Oct 3, 10:34 pm, horos11 horo...@gmail.com wrote: 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

Re: creating class objects inside methods

2009-10-04 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-04 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, where

Re: creating class objects inside methods

2009-10-04 Thread Carl Banks
On Oct 3, 11:14 pm, horos11 horo...@gmail.com wrote: 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. I understand, and if you think it's overkill for your pedagogical application then feel free not to follow the

Re: creating class objects inside methods

2009-10-04 Thread Dave Angel
horos11 wrote: 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 -

Re: creating class objects inside methods

2009-10-04 Thread Hendrik van Rooyen
On Sunday, 4 October 2009 08:14:08 horos11 wrote: Saying that 'whoa, this coding error should be handled by naming convention' may be the only practical way of getting around this limitation, but it is a limitation nonetheless, and a pretty big one. You misunderstand the dynamic nature of

Re: creating class objects inside methods

2009-10-04 Thread Carl Banks
On Oct 3, 11:45 pm, horos11 horo...@gmail.com wrote: 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

Re: creating class objects inside methods

2009-10-04 Thread Albert Hopkins
Just by a brief look at your code snippet there are a few things that I would point out, stylistically, that you may consider changing in your code as they are generally not considered pythonic: * As already mentioned the state class is best if given a name that is capitalized.

Re: creating class objects inside methods

2009-10-04 Thread Rhodri James
On Sun, 04 Oct 2009 07:14:08 +0100, horos11 horo...@gmail.com wrote: 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. Speaking as someone who does teach Python, Ew, no! If you start by teaching people bad habits,

Re: creating class objects inside methods

2009-10-04 Thread Simon Forman
On Sun, Oct 4, 2009 at 1:12 AM, horos11 horo...@gmail.com wrote: 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

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 your name.  

Re: creating class objects inside methods

2009-10-04 Thread Benjamin Kaplan
On Sun, Oct 4, 2009 at 2:44 PM, horos11 horo...@gmail.com wrote: 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,

Re: creating class objects inside methods

2009-10-04 Thread Carl Banks
On Oct 4, 11:56 am, Benjamin Kaplan benjamin.kap...@case.edu wrote: On Sun, Oct 4, 2009 at 2:44 PM, horos11 horo...@gmail.com wrote: ( ps - an aside, but what was the rationale behind only displaying one error at a time on trying to run a script? I typically like to run a compilation

Re: creating class objects inside methods

2009-10-04 Thread Carl Banks
On Oct 4, 3:12 am, Albert Hopkins mar...@letterboxes.org wrote:       * You define a to_string() method. To have a string representation         of a class, one usually defines a __str__ method.  This gives         the advantage whereby print myobject or '%s' % myjobject just         work.

Re: creating class objects inside methods

2009-10-04 Thread Simon Forman
On Sun, Oct 4, 2009 at 2:44 PM, horos11 horo...@gmail.com wrote: 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,

Re: creating class objects inside methods

2009-10-04 Thread Rob Williscroft
Benjamin Kaplan wrote in news:mailman.838.1254682604.2807.python- l...@python.org in comp.lang.python: And how do you just check a script's syntax without running it anyways? ) Because these aren't compile-time errors. Python has no compilation phase- Sure it does, compilation happens

Re: creating class objects inside methods

2009-10-04 Thread Stephen Hansen
Anyways, maybe I got off to a bad start, but I'm a bit leery of the language. In my estimation it's trying to be 'too clever by half', and this coming from a veteran bash/perl programmer. I mean, free form is one thing, but too much of a good thing can be harmful to your programming health.

Re: creating class objects inside methods

2009-10-04 Thread Terry Reedy
horos11 wrote: Anyways, maybe I got off to a bad start, Blaming programming errors on non-existent bugs in the interpreter is not a way to endear yourself. And perhaps Python truly is not your style. Maybe PyChecker or PyLint will help, I don't know. I do not use them, but others swear

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()

Re: creating class objects inside methods

2009-10-03 Thread Simon Forman
On Sat, Oct 3, 2009 at 11:32 PM, horos11 horo...@gmail.com wrote: 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

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 that this is

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