organizing many python scripts, in a large corporate environment.

bukzor workitharder at gmail.com
Tue Mar 15 00:44:48 EDT 2011


On Mar 14, 1:30 pm, "eryksun ()" <eryk... at gmail.com> wrote:
> On Monday, March 14, 2011 3:56:15 PM UTC-4, eryksun () wrote:
> > To be clear on the file structure, I'm picturing that 'base' is a
> > path on each user's shell path where all the accessible scripts
> > are linked, and that this is also the package directory.
>
> Wait, this won't work when the script is linked to from somewhere else, which means the code still has to be based on __file__ or sys.argv[0] or sys.path[0], and have to get the absolute/real path in case it's a link.
>
> Along those lines, you (bukzor) wrote that
>
> > What I do right now is to symlink this library to all script
> > directories to allow them to bootstrap and gain access to
> > libraries not in the local directory.
>
> Won't this also fail if it's running from a link? The link to the library won't necessarily be in the current directory.

You're right! QQ
Currently it requires either: 1) no symlinks to scripts or 2)
installation of the pathtools to site-packages.

Mostly I came here because I felt this was a real pain with no good
solution, and felt that I must be missing something essential if
nobody else is thinking or talking about it. When looking at google
code search, this kind of code is rampant (below). Is everyone really
happy with this?

sys.path.insert(0,
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

see: http://www.google.com/codesearch?hl=en&lr=&q=sys%5C.path.*__file__



More information about the Python-list mailing list