[Idle-dev] Re: idlefork merge underway - errata
Guido van Rossum
guido@digicool.com
Thu, 12 Jul 2001 10:41:02 -0400
> Guido van Rossum wrote:
> > > Guido, I just merged idle.py, and am moving on to it's bretheren, but I'm
> > > curious about the change:
> > >
> > > ! idle_dir = os.path.split(sys.argv[0])[0]
> > > ---
> > > ! idle_dir = os.path.dirname(IdleConf.__file__)
> > >
> > > What is the reason for moving to the second form of working out idle_dir
> > > ??
> >
> > This is trying to find IDLE's source directory so that it can look
> > there for config files and icons (I think).
> >
> > The old form just *assumes* that sys.argv[0] is the absolute pathname
> > of idle.py. This isn't always the case (depends on shell and OS).
> >
> > The second one assumes that the IdleConf module lives in the IDLE
> > source directory. That's a pretty good assumption I believe!
>
> Isn't
>
> idle_dir = os.path.abspath(sys.path[0]) + os.sep
>
> os independent, and without worrying about the existence of particular files
> or modules??
Concatenating os.sep is not OS dependent. On the Mac, os.sep is ':'
but '::' is the equivalent of '../' and ':::' is '../../', etc. I've
also seen Windows balk about excess trailing slashes in some cases.
On Unix, sys.path[0] is not the right place to look into. It might be
just "idle" when the "idle" script is found on $PATH and the user
typed "idle". (Most shells sustitute the full pathname found, but not
all do.)
So please just do what I said. :-)
--Guido van Rossum (home page: http://www.python.org/~guido/)