By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,884 Members | 949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,884 IT Pros & Developers. It's quick & easy.

Creating Python Modules

P: n/a
Greetings,

I am trying to create a python module for a series of class files that
because of their size I have divided into multiple files.

class Foo --> foo.py
class Boo --> boo.py

I have created a setup.py where I have for the "py_modules=['foo',
'boo']". when I run "%>./setup.py install" it copies all *.py and *.pyc
to /usr/lib/python2.2/site-packages.

When I goto use the module I have to use:

import foo
import boo

I would like if anyone could help me to be able to:
1.) Get the *.py and *.pyc (foo and boo) generated with the install to
install to "/usr/lib/python2.2/site-packages/mymodule".
2.) When using the module be able to use just one import and get source
code like:

import mymodule

foo = Foo()
boo = Boo()

I have read the tutorial docs on this and it has brought me to where I
am now but I have about 35 files/classes. I think that I need to define
a mymodule.py file and put an __init__()? method into it I am just not
sure what to do, so any help would be appreciated.
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
DH
Adam T. Gautier wrote:
Greetings,

I am trying to create a python module for a series of class files that
because of their size I have divided into multiple files.

class Foo --> foo.py
class Boo --> boo.py


Create an __init__.py file in your module's root directory that calls:
from foo import Foo
from boo import Boo

Then to use your module, a user would do:

from mymodule import Foo, Boo
foo = Foo()
boo = Boo()

or...

import mymodule
foo = mymodule.Foo()
boo = mymodule.Boo()

Jul 18 '05 #2

P: n/a
Adam T. Gautier wrote:
Greetings,

I am trying to create a python module for a series of class files
that because of their size I have divided into multiple files.

class Foo --> foo.py
class Boo --> boo.py

I have created a setup.py where I have for the "py_modules=['foo',
'boo']". when I run "%>./setup.py install" it copies all *.py and
*.pyc to /usr/lib/python2.2/site-packages.

When I goto use the module I have to use:

import foo
import boo

I would like if anyone could help me to be able to:
1.) Get the *.py and *.pyc (foo and boo) generated with the
install to install to "/usr/lib/python2.2/site-packages/mymodule".


I think you want to include the "packages" option or the
"package_dir" option in your setup.py.

See section "3.1 Listing whole packages" in "Distributing Python
Modules" at:

http://www.python.org/doc/current/dist/dist.html
Dave

--
http://www.rexx.com/~dkuhlman
dk******@rexx.com
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.