473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

get script path

hg
Hi,

must I parse argv[0] to get it, or is there an easier way (that works under
Windows and *nix)?

Ex:

python /home/hg/test/test.py ==test.py #knows it is in /home/hg/test

Thanks,

hg

Dec 4 '06 #1
3 1784
hg
hg wrote:
Hi,

must I parse argv[0] to get it, or is there an easier way (that works
under Windows and *nix)?

Ex:

python /home/hg/test/test.py ==test.py #knows it is in /home/hg/test

Thanks,

hg
got it: os.path.dirname(sys.argv [0])

Dec 4 '06 #2

hg wrote:
Hi,

must I parse argv[0] to get it, or is there an easier way (that works under
Windows and *nix)?

Ex:

python /home/hg/test/test.py ==test.py #knows it is in /home/hg/test
IMHO it is easy enough:
>>dname, fname = os.path.split("/home/hg/test/test.py")
dname
'/home/hg/test'

--
HTH,
Rob

Dec 4 '06 #3
hg
Rob Wolfe wrote:
>
hg wrote:
>Hi,

must I parse argv[0] to get it, or is there an easier way (that works
under Windows and *nix)?

Ex:

python /home/hg/test/test.py ==test.py #knows it is in /home/hg/test

IMHO it is easy enough:
>>>dname, fname = os.path.split("/home/hg/test/test.py")
dname
'/home/hg/test'

--
HTH,
Rob
thanks

Dec 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: deko | last post by:
In regard to running php scripts with cron - Here is a sample script: <?php //debug.php echo "<br> This is a test"; ?> I can call debug.php from a web page on my site like this:
5
by: Shalen chhabra | last post by:
Hey, Can anyone give me a snippet for running a python program over all the files in the directory. For ex: I have ten files in a directory and I want to run a python program against all of...
1
by: CR1 | last post by:
I found a great cookie script below, but don't know how to make it also pass the values sent to the cookie, to a querystring as well for tracking purposes. Can anyone help? If there was a way to...
7
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
1
by: Oliver Marshall | last post by:
Hi, Im after a simple script to help sort my downloads. Basically I have a downloads folder, and at the moment I have directory browsing enabled so that i can download files. What I want is...
9
by: boris.smirnov | last post by:
Hi there, I have a problem with setting environment variable in my script that uses qt library. For this library I have to define a path to tell the script whre to find it. I have a script...
3
by: jaeden99 | last post by:
I was wandering if nyone has a script to move files older than x days old? i've seen several to delete, but I don't want to delete. I would like to create a backup of the files first verify with...
4
by: Chris8Boyd | last post by:
I am embedding Python in a MSVC++ (2005) application. The application creates some environment and then launches a Python script that will call some functions exported from the MSVC++ application....
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
7
by: jeddiki | last post by:
Hi, As I am in Turkey at present, I can not see vidoes on youtube. So I have tried a few proxies but keep finding them slow or not working. So I have installed myphpProxy on my server under...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.