473,834 Members | 1,801 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 1819
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
3093
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
2584
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
1573
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
2954
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
2762
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
9797
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9644
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
10793
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...
0
10509
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10547
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
10219
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...
1
7757
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3081
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.