I know I can do this by get sys.argv[0], tell if it's a full path, and if not,
somehow join the relative path with getcwd(). Just wondering if there's a
simpler way to do this. Thanks! 7 2772
Duh - the way I described seems to be simple enough:
pathToScript=os.join(os.getcwd(),os.path.split(sys .argv[0])[0])
On Sat, 27 Dec 2003, Benjamin Han wrote: I know I can do this by get sys.argv[0], tell if it's a full path, and if not, somehow join the relative path with getcwd(). Just wondering if there's a simpler way to do this. Thanks!
Should be:
pathToScript=\
os.path.normpath(os.path.join(os.getcwd(),os.path. split(sys.argv[0])[0]))
On Sat, 27 Dec 2003, Benjamin Han wrote: Duh - the way I described seems to be simple enough:
pathToScript=os.join(os.getcwd(),os.path.split(sys .argv[0])[0])
On Sat, 27 Dec 2003, Benjamin Han wrote:
I know I can do this by get sys.argv[0], tell if it's a full path, and if not, somehow join the relative path with getcwd(). Just wondering if there's a simpler way to do this. Thanks!
On Sat, 2003-12-27 at 18:02, Benjamin Han wrote: Duh - the way I described seems to be simple enough:
pathToScript=os.join(os.getcwd(),os.path.split(sys .argv[0])[0])
Or:
#!/usr/bin/env python
import sys
import os
me = sys.argv[0]
print "This is how you invoked me: %s" % (me,)
print "This is the absolute path: %s" % (os.path.abspath(me),)
Usage:
mark@dev /var/tmp/buffer
$ python ../junk.py
This is how you invoked me: ../junk.py
This is the absolute path: /var/tmp/junk.py
Cheers,
// m
On Sat, 27 Dec 2003, Mark McEahern wrote: On Sat, 2003-12-27 at 18:02, Benjamin Han wrote: Duh - the way I described seems to be simple enough:
pathToScript=os.join(os.getcwd(),os.path.split(sys .argv[0])[0])
me = sys.argv[0] print "This is the absolute path: %s" % (os.path.abspath(me),)
Thank you - this is even better!
> #!/usr/bin/env python import sys import os
me = sys.argv[0] print "This is how you invoked me: %s" % (me,) print "This is the absolute path: %s" % (os.path.abspath(me),)
Usage:
mark@dev /var/tmp/buffer $ python ../junk.py This is how you invoked me: ../junk.py This is the absolute path: /var/tmp/junk.py
Is this going to work well cross platform? How about from IDLE?
I was using sys.path[0] which I thought was working well, but
apparently fails when the script is run from IDLE on windows.
i normally use the following:
import inspect
print inspect.getsourcefile( lambda:None )
the lambda function could be any object; the getsourcefile returns the
path to the file where that object was defined.
_wolf
Hi,
Wolfgang Lipp schrieb: import inspect print inspect.getsourcefile( lambda:None )
Nice idea!
Enhancement: when using inspect.getfile() the snippet will work even for
module without sourcefile, too.
--
Regards
Hartmut Goebel
| Hartmut Goebel | We build the crazy compilers |
| h.******@crazy-compilers.com | Compiler Manufacturer | This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Preston Crawford |
last post by:
I'm looking to quickly get a photo album online. Very simple, thumbnails,
a few pages, maybe a description, but hopefully a small script that's easy
to edit and work into my existing site. I know...
|
by: Peter Schwalm |
last post by:
I'd like to modify the python search path depending on the source
directory of the script being started. The reason is: I use a version
control system, and the python scripts and modules are...
|
by: (Pete Cresswell) |
last post by:
I've got a .BAT file that I use for executing various MS Access apps that I
wrote way back in the days of 2.0.
It's evolved over time, but it still contains a number of possible paths to...
|
by: PHaroZ |
last post by:
Hi,
I want to retrieve the complete full path to the directory
of my current page but i don't find how to do that.
For example i want : D:\myWebSite\firstDotNetWebApp\dir1\
I tried...
|
by: Q. John Chen |
last post by:
I have Vidation Controls
First One: Simple exluce certain special characters:
say no a or b or c in the string:
*
Second One:
I required date be entered in "MM/DD/YYYY" format:
//+4 How...
|
by: Sridhar |
last post by:
Hi,
I have a web form where it has a <input type=file id=file1> control. I
have an Upload button to upload the file. WHen I click on browse and select
one file, it is showing the full file path...
|
by: gmax2006 |
last post by:
Hi,
I use RedHat linux.
How can I find where exactly the current python script is running?
I use this code:
#test.py
import os,sys
|
by: somank.sharma |
last post by:
I am running an exe created in C. I need the full path (absolute path)
of this exe. In the first argument of main, I am getting the exe name.
How can I get the full path for this exe.
|
by: misceverything |
last post by:
Hello,
I would like to write a script that would enumerate all running
processes and return the full path to the EXE of each running
process. However, I can't seem to find any good info on how...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |