Re: [Tutor] Getting the directory the program is in

2006-12-12 Thread Andreas Kostyrka
* Laszlo Antal <[EMAIL PROTECTED]> [061212 18:12]: > Hi, > > I use this: > > # This is the file name this code is in > curfile = "findcurdir.py" > #__file__ gives everything so slice off the file name > curdir = __file__[:-len(curfile)] > print curdir > #will print the curdir the file is in > #ev

Re: [Tutor] Getting the directory the program is in

2006-12-12 Thread Laszlo Antal
Hi, I use this: # This is the file name this code is in curfile = "findcurdir.py" #__file__ gives everything so slice off the file name curdir = __file__[:-len(curfile)] print curdir #will print the curdir the file is in #even if this file(module) has been imported I hope it helps Laszlo Antal

Re: [Tutor] Getting the directory the program is in

2006-12-11 Thread Tor Hildrum
On 12/11/06, Jordan Greenberg <[EMAIL PROTECTED]> wrote: > Tor Hildrum wrote: > > The full pathname is in sys.argv[0] > At least on my system, it only includes the filename if executed from > the current directory. Hm, yeah, I thought the full path was standard behavior but I see it's not. I need

Re: [Tutor] Getting the directory the program is in

2006-12-11 Thread Christopher Arndt
Christopher Arndt schrieb: > Of course you have to do this before you (or some other code in your program) > do anything siilar to os.chris('/somewhere/else'). ^ That was some freudian slip of my narcissistic mind *LOL* Of course, I mean: os.chdir('/somewhere/else')

Re: [Tutor] Getting the directory the program is in

2006-12-11 Thread Christopher Arndt
Jordan Greenberg schrieb: > Slightly hackish and nasty, but seems to do the trick. Someone'll > probably suggest a better way, this is just the first thing I could come > up with: No, IMHO it's perfectly normal and safe practice, though this gets the full path name of the program. If you want the

Re: [Tutor] Getting the directory the program is in

2006-12-11 Thread Jordan Greenberg
Tor Hildrum wrote: > The full pathname is in sys.argv[0] At least on my system, it only includes the filename if executed from the current directory. Example: [EMAIL PROTECTED]:/$ cd ~ [EMAIL PROTECTED]:~$ cat > test.py from sys import argv print argv[0] [EMAIL PROTECTED]:~$ python test.py test.p

Re: [Tutor] Getting the directory the program is in

2006-12-11 Thread Jordan Greenberg
Toon Pieton wrote: > Hey friedly users! > > I was wondering: how can I get the directory the program is in? For example > "C:\Python Programs\Calculator\". > > Thanks in advance for reading, > Toon Pieton > Slightly hackish and nasty, but seems to do the trick. Someone'll probably suggest a bet

Re: [Tutor] Getting the directory the program is in

2006-12-11 Thread Tor Hildrum
On 12/11/06, Toon Pieton <[EMAIL PROTECTED]> wrote: > Hey friedly users! > > I was wondering: how can I get the directory the program is in? For example > "C:\Python Programs\Calculator\". >>> os.path.split.__doc__ 'Split a pathname. Returns tuple "(head, tail)" where "tail" is\n everything after