473,385 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to shortcut a package path?

Is there any way to create a shortcut for a package path?
For instance, if I have the following path structure,

dir1/dir2/program.py

what should I do if I want to import program with

from dir1 import program

, not with

from dir1.dir2 import program
Thanks in advance.

Daehyok Shin
Jul 18 '05 #1
2 1661
on dir1/__init__.py:

import dir2.program
program = dir2.program
But why do you want to do this ?
On 16 Aug 2003 17:05:46 -0700
sd****@yahoo.com (sdhyok) wrote:
Is there any way to create a shortcut for a package path?
For instance, if I have the following path structure,

dir1/dir2/program.py

what should I do if I want to import program with

from dir1 import program

, not with

from dir1.dir2 import program
Thanks in advance.

Daehyok Shin
--
http://mail.python.org/mailman/listinfo/python-list


Jul 18 '05 #2
sdhyok wrote:
Is there any way to create a shortcut for a package path?
For instance, if I have the following path structure,

dir1/dir2/program.py

what should I do if I want to import program with

from dir1 import program

, not with

from dir1.dir2 import program


If it were me, I would lay it out as such:

#----------------------------------------------------------
# myapp.py

from dir1 import program
#----------------------------------------------------------
# dir1/__init__.py

from dir1.dir2 import program

# or, from dir2 import program, see note below.

#----------------------------------------------------------
# dir1/dir2/__init__.py

"""Required, of course"""
#----------------------------------------------------------
# dir1/dir2/program.py

"""Your code"""
Side note: In dir1/__init__.py, I used "from dir1.dir2 import program"
instead of "from dir2 import program". Either one would work, but
sometimes you have to be careful not to mix the two (the absolute and
the relative) approaches. Mixing them can lead to the a module being
initialized twice, which can sometimes lead to some strange and
hard-to-debug behaviour. Given the Python zen-ism of "explicit is better
than implicit", my vote is for the side-effect-free, "full path" approach.

Here's one of many c.l.py threads that refers to this
double-initialization behaviour (maybe not the best, but the first I found):

http://tinyurl.com/k98r
Pedro asked why you want to do this... Personally, I might use this
technique would be if I wanted "dir1" to act as a Facade, or API, to a
set of subpackages. Import all of the "public" classes and functions
into the dir1.__init__ module, and then your users are less inclined to
access your "private" subpackages. This isn't a security technique, of
course, it's just clean API design.

-- Graham

Jul 18 '05 #3

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

Similar topics

27
by: aa | last post by:
Thought this question might be out of this NG's scope, there are always knowledgable people who might hava an answer. A hyperlink to a shortcut to a file returnes an empty screen, and the source...
2
by: Benjamin | last post by:
I have a very strange problem. I have developed a .NET solution. To set up user clients I have also included a "Deployment Project" in the solution: Using "File System Editor | User's Program...
3
by: Agent86 | last post by:
I have created install packages for my ade on mssql installation as a windows installer package in installshield and it all works fine except; 1. I want to determine whether Access 2002 is...
4
by: I_AM_DON_AND_YOU? | last post by:
There is one more problem I am facing but didn't get the solution. In my Setup Program I am not been able to create 2 things (when the program is intalled on the client machine ) : (1) create...
2
by: TN | last post by:
I think I am losing my mind. I've got a simple application for which I have a setup project to install the application. I create a shortcut to the applications project in the user's desktop. ...
6
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I am deploying vb2005 apps using Click Once deployment. This works fine. The problem is that the user needs to be able to launch a 2nd app from the 1st app, but the application...
10
by: Matthew Wells | last post by:
I'm trying to make a shortcut that will open an mdb in the same folder as the shortcut - regardless of where the file/shortcut may be. In other words, I want to be able to copy and paste the two...
4
by: Coolfusion | last post by:
Hi there, I want the programe to search for the shortcut exe file on the desktop and display the file path of the file. To obtain the file path manually, right-click the shortcut exe file and go...
5
by: remya1000 | last post by:
i'm using VB.NET 2003 application program. by using OpenFileDialog, we can select the file name or file path. OpenFileDialog1.ShowDialog() pgmPath.Text =...
0
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,...
0
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$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...

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.