472,342 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 2305
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
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...
6
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,...
1
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...
1
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...
1
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...
0
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...
0
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...
3
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...
6
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. ...
0
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 =...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.