python - Distutils - Where Am I going wrong? -


i wanted learn how create python packages, visited http://docs.python.org/distutils/index.html.

for exercise i'm using python 2.6.2 on windows xp.

i followed along simple example , created small test project:

person/      setup.py      person/        __init__.py        person.py 

my person.py file simple:

class person(object):        def __init__(self, name="", age=0):         self.name = name         self.age = age      def sound_off(self):         print "%s %d" % (self.name, self.age) 

and setup.py file is:

from distutils.core import setup setup(name='person',     version='0.1',     packages=['person'],     ) 

i ran python setup.py sdist , created manifest, dist/ , build/. next ran python setup.py install , installed site packages directory.

i run python console , can import person module, cannot import person class.

>>>import person >>>from person import person traceback (most recent call last):   file "<stdin>", line 1, in <module> importerror: cannot import name person 

i checked files added site-packages , checked sys.path in console, seem ok. why can't import person class. did go wrong?

person/    __init__.py    person.py 

you've got package called person, , module inside called person.person. defined class in module, access you'd have say:

import person.person p= person.person.person('tim', 42) 

if want put members directly inside package person, you'd put them in __init__.py file.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -