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. 1 1278
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.p ath):
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.somefuncti on()
-Scott David Daniels Sc***********@A cm.Org This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 out the modules
internally.
I have a 'BulkSMS.Exceptions' module, which contains a base class and
(currently) all derived exceptions that my package throws. This has
been fine up until now, as the exceptions were generated by only one
|
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 it's proving useful, I think about releasing it.
I plan to model it after gentoo's portage, with less features of course.
Would this be acceptable?
|
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 -- just
my local modules. This is not the same question
that would be answered with py2exe or py2app. I
don't need to package the script into a binary
along with Python. I expect Python to be installed.
I also don't want to use distutils to install...
|
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 cache size is set at Maxapples * 8
Maxapples is at 500.
|
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 Access back-end. I have created a number of
reports in Access and I am starting them from the Visual Basic Front End.
However, I have a number of users who do not have a copy of Access which
means they will obviously need the run time files.
...
| |
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 final version however and when I tell it to
create a shortcut it includeds the path to access 2003 in the shortcut
C:\Program Files\Microsoft Office\OFFICE11\
my client is running access 2000. I could not figure any way to change
the access...
|
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 face or have faced these kind
of questions. I'd appreciate any suggestions.
I have developed a package in C++ and C# that consists of 3 apps. There is
a management app (C++), a playback app (C++) and a simplified C# interface
to a database used...
|
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
upd_startreconproc.sqc
and I precompile like so:
|
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 msvcr90.dll to run. So my question here is
if i can pack this file into my installer and redistribute it with
my application. For my case it would be just fine if the
dll would be in the same directory as the app is.
|
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 this
to the server in a manner that it'll be able to get and de-code the
MIME package in a valid way.
The big question is does this entire mime package belong in the
headers section of an HTTP request? If not, what is the best Pythonic
way to...
|
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...
| |
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,...
|
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,...
|
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...
|
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...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |