473,508 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

find a .py path

hg
Hi,

Is there an easy way for a script being executed (from anywhere) to know
where is is ... something in os.path ?

Thanks,

hg

Jan 5 '07 #1
6 2344
hg
hg wrote:
Hi,

Is there an easy way for a script being executed (from anywhere) to know
where is is ... something in os.path ?

Thanks,

hg
oops: os.path.abspath(sys.argv[0])

hg

Jan 5 '07 #2
hg i'rta:
Hi,

Is there an easy way for a script being executed (from anywhere) to know
where is is ... something in os.path ?
__file__

You can also use os.argv[0] but that is not the same...

Laszlo
Jan 5 '07 #3
hg
Laszlo Nagy wrote:
hg i'rta:
>Hi,

Is there an easy way for a script being executed (from anywhere) to know
where is is ... something in os.path ?
__file__

You can also use os.argv[0] but that is not the same...

Laszlo
Thanks

Jan 5 '07 #4
hg írta:
hg wrote:

>Hi,

Is there an easy way for a script being executed (from anywhere) to know
where is is ... something in os.path ?

Thanks,

hg

oops: os.path.abspath(sys.argv[0])
Be aware with this. It is different when you do

/usr/bin/python prog.py

and

../prog.py

In the first case, sys.argv[0] will be /usr/bin/python!

You should better use

os.path.abspath(__file__)

(that will work for normal python programs, but not for py2exe compiled
programs or for modules imported from a zip file...)

Best,

Laszlo

Jan 5 '07 #5
Hi,

What about :

import os.path
print os.path.abspath(__file__)

hg a écrit :
Hi,

Is there an easy way for a script being executed (from anywhere) to know
where is is ... something in os.path ?

Thanks,

hg
Jan 5 '07 #6
On 5 ene, 13:33, Laszlo Nagy <gand...@designaproduct.bizwrote:
Be aware with this. It is different when you do

/usr/bin/python prog.py

and

./prog.py

In the first case, sys.argv[0] will be /usr/bin/python!
No, sys.argv[0] is always the running script, and sys.argv[1] the first
argument after the script, and so on. It doesn't matter if you call
python implicitely, or with other options. Try this:
/usr/bin/python -i -u -O prog.py

--
Gabriel Genellina

Jan 7 '07 #7

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

Similar topics

10
33657
by: hokieghal99 | last post by:
import os, string print " " setpath = raw_input("Enter the path: ") def find_replace(setpath): for root, dirs, files in os.walk(setpath): fname = files for fname in files: find =...
6
1762
by: Peter Hansen | last post by:
Greetings. Im trying to write a program that can be run from the command line. If I want to search for example after a file with the ending .pdf, I should be able to write in the command line:...
1
3706
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
1
53411
by: Matthias Ludwig | last post by:
I'm trying to create a directory on the web server with a vb.net code: .... Dim dirName As String = "w:\filepath\images" If Not Directory.Exists(dirName) Then...
1
4472
by: Alex | last post by:
Hello, in my company, we have a diagnostic tool for hardware. Depending on the hardware projcet, a different project configuration is needed. The configuration file is written in XML and...
0
1654
by: haylow | last post by:
Hi I am new to ASP.NET and am working on an application that runs on a webserver. The user will open up the web interface in a browser on their local machine and enter a path to a directory. I...
0
1319
by: John Doe | last post by:
Windows XP Visual Studio 2003 NET Visual C++ When I tried to run without debugging, I get a message that says it can't find a path. The path did exist on my computer. I cannot find the path...
3
4404
by: Alan Cohen | last post by:
This seems like a really, really dumb question, but I can't seem to find the simple answer that it seems to deserve. My C#/ASP.net 2.0 app needs to email a URL link back to the site from a web...
6
2904
by: HONOREDANCESTOR | last post by:
Suppose I have a dll which might be installed in the directory c: \MyClass\. I want to be able to find the path of this dll from within the dll. In other words, I want a function that can return...
0
1490
by: sndive | last post by:
I have a weid problem. If i do this: import elementtree.ElementTree as ET .... tree = ET.parse("whatever") root = tree.getroot() r = root.find('last') print r return root where last is not an...
0
7223
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
7115
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...
0
7321
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
7377
jinu1996
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...
0
5624
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,...
1
5047
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...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.