This is mainly a remainder to myself, because I always forget it and spend to much time to find it again. It's so simple/basic that it is almost embarrassing.
To get the current working directory of in a python script, like you have pwd (print working directory) on a Linux/Unix command line:
import os print os.getcwd()
so very nice :)
so very nice :)
Another method
import subprocess
subprocess.Popen('pwd', shell = True)
this allows you to use bash commands in Python, so handy for changing directory's, copying files etc
Terrible idea
Yeah, that's a horrible idea.
You also can't change directory like that. Popen makes a new process, and if that new process changes directory, it has no impact on the process that launched it.
Great. thank you
It worked fine for me, I'm a learning Python. hanks a lot
And you can always >>>
And you can always
>>> fin,fout = os.popen4("pwd")
>>> result = fout.read()
>>> print result
You can always do that if you
You can always do that if you want a non-portable solution that will crash on any system without a 'pwd' command.
This is exactly what you don't have to deal with if you use os.getcwd()
everyman...
everyman needs their own wiki...
thanks for sharing yours!
It works! thank you
It works! thank you
Thank you.
Thank you.
Thanks a lot! Didn't know
Thanks a lot!
Didn't know that it's this easy!!!
Post new comment