473,594 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating Python Modules

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
2 1800
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
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_di r" option in your setup.py.

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

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

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3054
by: Berthold Hoellmann | last post by:
Hello, When I use ./configure --with-thread --with-fpectl --with-signal-module \ --with-pymalloc --enable-shared --with-cxx=g++ make test on 2.3.3 I get
30
2545
by: Sean R. Lynch | last post by:
I've been playing around with Zope's RestrictedPython, and I think I'm on the way to making the modifications necessary to create a capabilities-based restricted execution system. The idea is to strip out any part of RestrictedPython that's not necessary for doing capabilities and do all security using just capabilities. The basic idea behind capabilities is that you don't give any piece of code you don't trust a reference to something...
3
1566
by: Edwin Young | last post by:
Hi, I'm developing an application which is primarily in Python but has some C-coded extension modules. These modules aren't really useful to anyone other than the main application. The app works fine with Python 2.2 or 2.3, so ideally I'd like to create one install package which works with both. I have installation largely working using distutils to create a source tarfile and an RPM package. However I've noticed that the RPM installs
1
2939
by: Jerald | last post by:
Running python 2.3.4 on valgrind (a tool like purify which checks the use of uninitialized memory, etc), gives a lot of errors. See below. jfj@cluster:~/> python -V Python 2.3.4 jfj@cluster:~/> valgrind python ==10517== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
4
2744
by: Edvard Majakari | last post by:
Greetings, fellow Pythonistas! I'm about to create three modules. As an avid TDD fan I'd like to create typical 'use-cases' for each of these modules. One of them is rather large, and I wondered if it would be easy enough to create a code skeleton out of unit test module. Consider the following, though contrived, unit test code snippet: ==========================================================================
0
7876
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8251
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8003
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8234
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6654
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5408
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3897
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1210
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.