[Tutor] Working Directory

Lloyd Kvam pythontutor@venix.com
Fri, 03 May 2002 08:10:35 -0400


 >>> import mx.DateTime
 >>> mx.DateTime.__file__
'F:\\Python22\\Lib\\site-packages\\mx\\DateTime\\__init__.pyc'

I hope this fits the bill.  I believe that if the module comes from your
current directory, it simply returns the file name.

Russell Bungay wrote:

> Hello,
> 
> Just before I start, thankyou everyone, I have been reading Tutor for
> months now, and have extracted much useful information from it, groovy.
> 
> I am currently working on a little app and am having difficulties with
> finding out about what directory I am working in.  I need this
> information for two reasons, 1.  for the creation and use of a
> ConfigParser object and related file. 2.  To import a module held in the
> same directory as the module that I am currently working on.
> 
> I am aware 2.  is not a pretty reason for using this information, I
> should be sticking the imported module somewhere more sensible, using
> packages for example, but I haven't read up on such things yet (my shiny
> new copy of Programming Python came in the post yesterday), and thought
> that as I needed the same stuff for 1.  I might as well reuse it.
> 
> Solutions then:
> 
> os.getcwd() won't always return the directory in which my main module is
> hiding.
> I don't want to hard code the directory in, for obvious reasons.
> I can't think of a way in which passing the directory as an command line
> argument will guarantee precision.
> I am perhaps missing the obvious function that will tell what I need?
> 
> All help gratefully received :o)
> 
> Thankyou very much,
> 
> Russell
> --
> http://www.bigmaddrongo.com
> President of York University Trampoline Club:
> http://york.trampolining.net
> Chair of The York Glee Singers:
> http://www.gleesingers.co.uk
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582