I have a collection of packages and I want to put them under single unifying
name. my goal is to reduce namespace pollution and make all these packages
accessible as 'import vvv.aaa'. In more detail, if I have packages 'aaa' and
'bbb', what do I do to put those packages under unifying name such as 'vvv'?
the only way I can see to do it is to create 'vvv' as a directory with its own
__init__.py but I'm not sure that were work right either.
thanks. 2 1231
Eric S. Johansson wrote:
I have a collection of packages and I want to put them under single
unifying
name. my goal is to reduce namespace pollution and make all these
packages accessible as 'import vvv.aaa'. In more detail, if I have
packages 'aaa' and 'bbb', what do I do to put those packages under
unifying name such as 'vvv'? the only way I can see to do it is to create
'vvv' as a directory with its own __init__.py but I'm not sure that were
work right either.
Of course you could make a module vvv.py with lots of import statements
import aaa
import bbb
....
import zzz
but then all submodules are imported eagerly with
import vvv
And then there's the hack
import sys
class Importer(object ):
def __getattr__(sel f, name):
module = __import__(name ) # you can do anything here
setattr(self, name, module)
return module
sys.modules["vvv"] = Importer()
Peter
Eric S. Johansson wrote:
I have a collection of packages and I want to put them under single
unifying name. my goal is to reduce namespace pollution and make all
these packages accessible as 'import vvv.aaa'. In more detail, if I have
packages 'aaa' and 'bbb', what do I do to put those packages under
unifying name such as 'vvv'? the only way I can see to do it is to
create 'vvv' as a directory with its own __init__.py but I'm not sure
that were work right either.
thanks.
I don't see why it would be a problem:
pyimport os
pyfor afile in os.listdir('pyp ack'):
.... if not afile.endswith( 'pyc'):
.... print '# %s' % afile
.... print open(os.path.jo in('pypack', afile)).read(). strip()
.... print '# end of file\n\n'
....
# __init__.py
from mod1 import x
from mod2 import y
# end of file
# mod1.py
x = 14
# end of file
# mod2.py
y = 42
# end of file
pyimport pypack
pydir(pypack)
['__builtins__',
'__doc__',
'__file__',
'__name__',
'__path__',
'mod1',
'mod2',
'x',
'y']
pypypack.mod1
<module 'pypack.mod1' from 'pypack/mod1.py'>
James This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Chris Barker |
last post by:
Hi all,
We've been having a discussion over on the wxPython-users mailing list
about how to deal with multiple versions of wxPython. During the
discussion it came up that this isn't a problem faced only by
wxPython, but would have to be dealt with by virtually all packages.
The root of the problem is what to do when you install a new version
of wxPython, and want to be able to keep using the old one. This
question comes up frequently...
|
by: Nick Coghlan |
last post by:
Anyone playing with the CPython interpreter's new command line switch might have
noticed that it only works with top-level modules (i.e. scripts that are
directly on sys.path). If the script is inside a package, the invocation will
fail with a "Module not found" error.
This PEP is aimed at fixing that :)
Cheers,
Nick.
|
by: Nick Coghlan |
last post by:
Python 2.4's -m command line switch only works for modules directly on sys.path.
Trying to use it with modules inside packages will fail with a "Module not
found" error. This PEP aims to fix that for Python 2.5.
Previously, posting of a draft version of the PEP to python-dev and python-list
didn't actually generate any responses. I'm not sure if that's an indication
that people don't see the restriction to top-level modules as a problem...
|
by: Jerry Cramer |
last post by:
I am attempting to generate FREE PACKAGE statements to get rid of
package from old versions of vendor products. I am refering to
SYSIBM.SYSPACKAGE to select packages generated by the DBRMLIB's of
past releases. The PDSNAMES in the IN clause of the first select
below are the old release DBRM libraries but I wanted to ensure that I
did not FREE any packages that were used in the prior release and were
still used in the current release....
|
by: koorb |
last post by:
Is there any reason why Microsoft is keeping the languages separate or
will they eventual replace all the languages with one, just to
simplify?
And why do people keep talking about switching to C#.Net, is there
something special planned for it?
| |
by: Mike Meyer |
last post by:
It seems that the distinction between tuples and lists has slowly been
fading away. What we call "tuple unpacking" works fine with lists on
either side of the assignment, and iterators on the values side. IIRC,
"apply" used to require that the second argument be a tuple; it now
accepts sequences, and has been depreciated in favor of *args, which
accepts not only sequences but iterators.
Is there any place in the language that still...
|
by: klh |
last post by:
We just installed DB2 ESE V8 FP12 on our Windows 2003 servers. We also
installed the DB2 ADMCL V8 FP12 on our websphere servers. We use the
JDBC Type 4 drivers on our websphere servers to directly hit our DB2
Z/OS V7 databases.
When we originally set up this environment (DB2 V8 FP8) we had to bind
the JDBC type 4 drivers using the syntax:
java com.ibm.db2.jcc.DB2Binder -url jdbc:db2://(ip address):(port
number)/(system name) -user...
|
by: giovanni gherdovich |
last post by:
Hello,
first of all:
Is this the right place to ask plastek-related
questions?
I'm trying to make plastex work on my Ubuntu Dapper
Drake. For LaTeX, I have the all-in-one package
tetex.
|
by: Doug Robinson |
last post by:
If I try to access another jar files default package I have no
problem. When I try to access anythig else i.e. package com.mine.thing,
I always get the not found message.
What special thing do I need to do to make it work?
package a.b.c.*;
import Another.*;
|
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: 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...
| |
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...
|
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: 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();...
|
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?
| |