Re: creating class objects inside methods

2009-10-06 Thread Rhodri James
On Sun, 04 Oct 2009 19:44:48 +0100, horos11 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 someone who does t

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

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 hea

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 ha

Re: creating class objects inside methods

2009-10-04 Thread Simon Forman
On Sun, Oct 4, 2009 at 2:44 PM, horos11 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, 3:12 am, Albert Hopkins 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. In fairness, a lot

Re: creating class objects inside methods

2009-10-04 Thread Carl Banks
On Oct 4, 11:56 am, Benjamin Kaplan wrote: > On Sun, Oct 4, 2009 at 2:44 PM, horos11 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 phase inside my editor (vim), get a

Re: creating class objects inside methods

2009-10-04 Thread Benjamin Kaplan
On Sun, Oct 4, 2009 at 2:44 PM, horos11 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 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-04 Thread Simon Forman
On Sun, Oct 4, 2009 at 1:12 AM, horos11 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

Re: creating class objects inside methods

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

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 Carl Banks
On Oct 3, 11:45 pm, horos11 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 don

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 p

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 Carl Banks
On Oct 3, 11:14 pm, 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. I understand, and if you think it's overkill for your pedagogical application then feel free not to follow the suggestions

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,

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 Carl Banks
On Oct 3, 10:34 pm, horos11 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 this. No

Re: creating class objects inside methods

2009-10-03 Thread Carl Banks
On Oct 3, 10:12 pm, horos11 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

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

Re: creating class objects inside methods

2009-10-03 Thread Simon Forman
On Sat, Oct 3, 2009 at 11:32 PM, horos11 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 thing) > >