Simple import question about mac osx

jmDesktop needin4mation at gmail.com
Tue Apr 29 20:14:57 CEST 2008


On Apr 29, 1:54 pm, s0s... at gmail.com wrote:
> On Apr 29, 12:46 pm, jmDesktop <needin4mat... at gmail.com> wrote:
>
>
>
>
>
> > On Apr 29, 1:16 pm, jmDesktop <needin4mat... at gmail.com> wrote:
>
> > > Hi, I have this code (learning from Core Python, Chun's book), module
> > > named chap2.py.
>
> > > class FooClass(object):
> > >         version=0.1
>
> > >         def __init__(self, nm='John Doe'):
> > >                 self.name=nm
> > >                 print 'Created a class instance for ', nm
> > >         def showname(self):
> > >                 print 'Your name is', self.name
> > >                 print 'My name is', self.__class__.__name__
>
> > > On Windows, if I compile this and then in the python interpreter type:
>
> > > >>> import chap2
> > > >>> foo1=FooClass()
>
> > > Created a class instance for  John Doe
>
> > > If I do the same think on my Mac OS X 10.5.2
>
> > > NameError: name 'FooClass' is not defined.
>
> > > I thought it was the path and did export PATH=$PATH:/mypath/
> > > topythoncode
>
> > > but it did not help.
>
> > > What am I doing wrong?  Thank you.
>
> > forgot to say that on the mac I can do import chap2, but when I try
> > and instantiate I get the error above.
>
> It shouldn't work under Windows, either. You have to qualify the name
> of the class with the name of the module, as in chap2.FooClass(). Or
> you can type "from chap2 import FooClass" and then you'll be able to
> simply say FooClass().- Hide quoted text -
>
> - Show quoted text -

Thanks.  That worked on mac.  But it does work like I said in
Windows.  Don't know why.  Mr. Chun must also be using Windows because
that is the way he does it in his book.



More information about the Python-list mailing list