* 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
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
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
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')
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
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
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
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