Hi all,
I was wondering if this is possible. In python v2.3 the import systems
was extended via PEP302 to cope with packages. *.py files in a directory
hierarchy can be imported as modules each level in the directory
hierarchy needs to contain at least an empty __init__.py file.
eg. With the file system
base/
__init__.py
branch1/
__init__.py
myModule.py
I can import myModule as follows
import base.branch1.myModule
At the same time its possible to store modules in a flat zip-file and
import modules with the following.
from myZip.zip import myModule.py
but is there a way to do both at the same time? eg.
from myZip.zip import base.branch1.myModule
I'm interested in this in the development of mobile code for some Grid
applications :-)
thanks in advance
p 4 1834
Peter Tillotson wrote: ... With the file system
base/ __init__.py branch1/ __init__.py myModule.py
At the same time its possible to store modules in a flat zip-file and import modules with the following.
from myZip.zip import myModule.py
Does this work for you? It gives me a syntax error.
Typically, put the zip file on the sys.path list, and import modules
and packages inside it. If you zip up the above structure, you can use:
sys.path.insert(0, 'myZip.zip')
import base.branch1.myModule
--Scott David Daniels Sc***********@Acm.Org
solution: have to add the zip archives to the PYTHONPATH, can be done in
the env but also as below
import sys, os.path
zipPackages=['base.zip']
for package in zipPackages:
sys.path.insert(0,os.path.join(sys.path[0],package))
import base.branch1.myModule
Peter Tillotson wrote: Hi all,
I was wondering if this is possible. In python v2.3 the import systems was extended via PEP302 to cope with packages. *.py files in a directory hierarchy can be imported as modules each level in the directory hierarchy needs to contain at least an empty __init__.py file.
eg. With the file system
base/ __init__.py branch1/ __init__.py myModule.py
I can import myModule as follows
import base.branch1.myModule
At the same time its possible to store modules in a flat zip-file and import modules with the following.
from myZip.zip import myModule.py
but is there a way to do both at the same time? eg.
from myZip.zip import base.branch1.myModule
I'm interested in this in the development of mobile code for some Grid applications :-)
thanks in advance
p
cheers Scott
should have been
from myZip.zip import base.branch1.myModule.py
and no it didn't work, anyone know a reason why this syntax is not
preferred ??
sorry posted the soln again, it works but feels nasty
Scott David Daniels wrote: Peter Tillotson wrote:
... With the file system
base/ __init__.py branch1/ __init__.py myModule.py
At the same time its possible to store modules in a flat zip-file and import modules with the following.
Does this work for you? It gives me a syntax error.
Typically, put the zip file on the sys.path list, and import modules and packages inside it. If you zip up the above structure, you can use:
sys.path.insert(0, 'myZip.zip') import base.branch1.myModule
--Scott David Daniels Sc***********@Acm.Org
Scott David Daniels <Sc***********@Acm.Org> writes on Wed, 29 Jun 2005 10:36:29 -0700: Peter Tillotson wrote: ... from myZip.zip import myModule.py
Does this work for you? It gives me a syntax error.
Typically, put the zip file on the sys.path list, and import modules and packages inside it. If you zip up the above structure, you can use:
sys.path.insert(0, 'myZip.zip') import base.branch1.myModule
The alternative is to use a "zipimporter" (from module "zipimport")
and use the "importer protocol" (documented in a PEP). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Active8 |
last post by:
I did this once and can't remember how <blush> so I read the
reportlab user guid. It says to unzip the reportlab archive - this
is on w2k, BTW, with Python23 - to a directory and make a file...
|
by: Tian |
last post by:
I am trying to use pyFMOD, I have installed all other supporting
libraries (hopefully), such as ctypes, numarray, I also installed FMOD
itself and copied its DLL files to python/DLLs. When I try to...
|
by: qwweeeit |
last post by:
The pythonic way of programming requires, as far as I know, to spread a
big application in plenty of more manageable scripts, using import or
from ... import to connect the various modules.
In...
|
by: Elmo Watson |
last post by:
I've been asked to develop a semi-automated type situation where we have a
database table (sql server) and periodically, there will be a comma
delimited file from which we need to import the data,...
|
by: Snozz |
last post by:
The short of it:
If you needed to import a CSV file of a certain structure on a regular
basis(say 32 csv files, each to one a table in 32 databases), what
would be your first instinct on how to...
|
by: Toby |
last post by:
Hi, I've managed to get my hands on the ms 2003 toolkit, and have
successfully (i think) created a .pyd file in win xp (setup.py is
provided intersystems cache):
...
|
by: kyosohma |
last post by:
Hi,
I am trying to create a post logon script which does various tasks,
like setup a printer based on location. While most of it works very
fast, I have a second Python script that I run that...
|
by: Chanman |
last post by:
This is probably a simple question to most of you, but here goes.
I've downloaded the xlrd (version 0.6.1) module and placed in in the
site-packages folder. Now, when I write a script, I type:
...
|
by: norseman |
last post by:
mercado mercado wrote:
==========================================================
Yes, but you may not like it.
I do what you do. Prod and devel subdirs.
I store the paths in a var at the top...
|
by: Aaron Scott |
last post by:
I've installed mod_python, and everything seems to be working, but it
fails when I try to import another file into the file that's actually
producing the output. I have these lines at the top of...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
| |