473,467 Members | 1,446 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Package question.

I'm sure its been thrashed through a hundred times but googling for an answer left me more confused than before and yes, I did read the Tutorial (maybe not well enough, but I read it).

On Windows, I want to set up a package structure like :

Fred
Bob
test.py

So I can say :

from Fred.Bob import *

To do this I need to put the package on the python path. So I drop this into my python root in a file called Fred.pth :

C:\Fred\

Now I need to make sure that Fred and Bob both look like packages with empty __init__.py files like so :

C:\Fred
__init__.py
C:\Fred\Bob
__init__.py
test.py

so :

C:\python.exe -c from Fred.Bob import *

OK!

But if I do :

C:\>cd Fred
C:\Fred>python.exe -c "from Fred.Bob import *"
Traceback (most recent call last):
File "<string>", line 1, in ?
ImportError: No module named Fred.Bob

Now lets say I change my Fred.pth contents to C:\MyTest and put my whole directory structure under c:\MyTest :

C:\MyTest\Fred
__init__.py
C:\MyTest\Fred\Bob
__init__.py
test.py
C:\>cd MyTest\Fred
C:\MyTest\Fred>python.exe -c "from Fred.Bob import *"

Works fine.

Is this quirk expected? If yes, I would like to expand my python knowledge with the why.

Thanks for your attention on this long post.



Jul 18 '05 #1
1 1268
Ian Sparks wrote:
... On Windows, I want to set up a package structure like :
Fred\
Bob\
test.py
So I can say :
from Fred.Bob import *
To do this I need to put the package on the python path.
So I drop this into my python root in a file called Fred.pth :
C:\Fred\
Now to make sure that Fred and Bob both look like packages with
empty __init__.py files like so :
C:\Fred\
__init__.py
C:\Fred\Bob\
__init__.py
test.py so :
C:\python.exe -c from Fred.Bob import *
OK!

But this is a lucky accident. If you do:
import sys
for number, name in enumerate(sys.path):
print number, repr(path)
You'll see (I suspect) that '' is on your path, and the Fred.pth
value is irrelevant (it adds an entry for 'C:\\Fred\\', which allows
you to import from Bob, not Fred. You Fred.pth file should list the
directory _containing_ Fred (in this case, 'C:\\', not 'C:\\Fred\\').

Note, you'll still be surprised soon, because I suspect you think
that after:
from Fred.Bob import *
you can freely use:
test.somefunction()

-Scott David Daniels
Sc***********@Acm.Org

Jul 18 '05 #2

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

Similar topics

0
by: David M. Wilson | last post by:
Hello! I maintain a small package for talking to the API of BulkSMS.co.uk. I have been adding support for some new features recently, and found myself slightly indecisive over how best to lay...
8
by: Georg Brandl | last post by:
Hello c.l.py, what features would you expect of a Python package manager, similar to CPAN or rubygems? I am currently planning to write such a thing, at first privately for myself, and if...
10
by: Noah | last post by:
I would like to package my main script and all the modules it imports into a single script that will run just as the collection would. It should not need to package standard Python lib modules --...
10
by: datapro01 | last post by:
Running DB2 8.1.6A on AIX 5.1 We are experience package cache overflows. The high water mark for package cache is showing as 16,108,513 bytes, or approximately 3933 4K pages. The package...
4
by: Thornmastr | last post by:
Good Afternoon, I need to distribute an application which includes the run time files for Access 2002. I do have the Office XP Developer CD’s. The application itself is written in VB 6 with an...
6
by: tdmailbox | last post by:
I developed an access database in access 2003(keeping my database in the access 2000 format). It has been fully tested to be access 2000 compatible and works great. I am trying to package the...
3
by: Robert | last post by:
Hi, I realize that this might not be the right group to post this kind of question. If someone knows where I could post it instead please let me know. Still, I think that some of you must...
3
by: shorti | last post by:
running on AIX with DB2 v8.2.2 I ran across a problem with naming source files with similar names. For instance, if I have these three files: upd_startaccessingdb.sqc upd_startusingdb.sqc...
3
by: Kerem Gümrükcü | last post by:
Hi, until today i always forced users to download/install the complete package of the Microsoft Visual C++ 2008 Redistributable Package (x86), but mostly my applications only need the...
6
by: squishywaffle | last post by:
This has got me somewhat stumped, so I'll throw it up here in hopes that someone has ran into this before. I'm trying to send a MIME package to Esko Backstage. I'm a bit confused as to how to send...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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,...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.