473,395 Members | 1,464 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,395 software developers and data experts.

Importing modules through directory shortcuts on Windows

Recently, I became responsible for maintaining some Python code, which
was organized as follows:

user/pylib
ui
...
project2/pylib
ui
...
project3/pylib
ui
...
python-packages/user => /user/pylib
project2 => /project2/pylib
project3 => /project3/pylib

The idea is that "python-packages" is added to sys.path and then every
project can import the library package from every other project. NOTE: I
think that this structure is crazy but I'm just the poor maintenance
programmer.

Anyway, the problem is that Windows does not have a symlink facility to
accommodate this (AFAIK) and the Python import mechanism does not
resolve shortcuts.

Therefore, I wrote a very simple import hook to get around that problem.
If you are interested, the code is here:
http://www.sweetapp.com/shortcut/shortcutimporter.py

BTW, does anyone else think that this functionality should be part of
core Python?

Cheers,
Brian
Apr 26 '06 #1
2 1425
Brian Quinlan wrote:
Anyway, the problem is that Windows does not have a symlink facility to
accommodate this (AFAIK) and the Python import mechanism does not
resolve shortcuts.


Windows does have the equivalent of symlinks provided you are running on
NTFS with Windows 2000 or later (Google for 'XP junction'). However, by
default the system provides no support for manipulating junction points, so
they are only really useful in an environment where you can control the
tools on the system, not something you can expect to use on arbitrary
systems.
Apr 26 '06 #2
You can use win32file.DeviceIoControl to link directories.
I can post some code to do so if anyone's interested.

Roger
"Brian Quinlan" <br***@sweetapp.com> wrote in message news:ma***************************************@pyt hon.org...
Recently, I became responsible for maintaining some Python code, which was organized as follows:

user/pylib
ui
...
project2/pylib
ui
...
project3/pylib
ui
...
python-packages/user => /user/pylib
project2 => /project2/pylib
project3 => /project3/pylib

The idea is that "python-packages" is added to sys.path and then every project can import the library package from every other
project. NOTE: I think that this structure is crazy but I'm just the poor maintenance programmer.

Anyway, the problem is that Windows does not have a symlink facility to accommodate this (AFAIK) and the Python import
mechanism does not resolve shortcuts.

Therefore, I wrote a very simple import hook to get around that problem. If you are interested, the code is here:
http://www.sweetapp.com/shortcut/shortcutimporter.py

BTW, does anyone else think that this functionality should be part of core Python?

Cheers,
Brian



----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Apr 27 '06 #3

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

Similar topics

2
by: Vsevolod (Simon) Ilyushchenko | last post by:
Hi, Last year I have written a Perl module to serve as a backend to Macromedia Flash applications: http://www.simonf.com/amfperl I have just rewritten it in Python, which I have not used...
0
by: Mark English | last post by:
Basic problem: If there is a C-extension module in a package and it tries to import another python module in the same package without using the fully qualified path, the import fails. Config:...
3
by: Charles Krug | last post by:
List: I'm trying to use the example files from Programming Python, 2nd Ed. I've copied them into c:\Python24\Examples\PP2E. Launching any of the examples programs by themselves seems to work...
2
by: spike grobstein | last post by:
I'm a total Python newbie, so bear with me here... I'm writing a program that has a user-configurable, module-based architecture. it's got a directory where modules are stored (.py files) which...
6
by: Kamilche | last post by:
I have a large project that is getting complex, and I would like to print the docstrings without importing the modules. The only Python utility I could find references is apparently defunct and...
6
by: rh0dium | last post by:
Hi all, Basically I have a bunch of pluggins in a directory (METDIR). For each one of these templated pluggins I want to do a specific routine. Let's start with a basic template file...
6
by: Walter Brunswick | last post by:
What is the best way to import all modules in a directory (and possibly a subdirectory/subdirectories), possibly including conditionals, such as regexes?
29
by: Natan | last post by:
When you create and aspx page, this is generated by default: using System; using System.Collections; using System.Collections.Specialized; using System.Configuration; using System.Text; using...
0
by: Martin P. Hellwig | last post by:
Hello all, I had some troubles in the past how to arrange my packages and modules, because I usually don't develop my stuff in the Lib\site-packages directory I have some troubles when importing...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
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...
0
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...

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.