472,958 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

The file executing

How does one get the path to the file currently executing (not the
cwd). Thank you

Jul 3 '07 #1
5 1113
On Jul 3, 9:40 am, Benjamin <musiccomposit...@gmail.comwrote:
How does one get the path to the file currently executing (not the
cwd). Thank you
os.path.dirname(sys.argv[0])

Jul 3 '07 #2
On Jul 2, 9:47 pm, Justin Ezequiel <justin.mailingli...@gmail.com>
wrote:
On Jul 3, 9:40 am, Benjamin <musiccomposit...@gmail.comwrote:
How does one get the path to the file currently executing (not the
cwd). Thank you

os.path.dirname(sys.argv[0])
The returns the file that was called first, but not the one currently
executing...

Jul 3 '07 #3
On Jul 3, 8:56 am, Sebastian Wiesner <basti.wies...@gmx.netwrote:
[ Benjamin <musiccomposit...@gmail.com]
On Jul 2, 9:47 pm, Justin Ezequiel <justin.mailingli...@gmail.com>
wrote:
On Jul 3, 9:40 am, Benjamin <musiccomposit...@gmail.comwrote:
How does one get the path to the file currently executing (not the
cwd). Thank you
os.path.dirname(sys.argv[0])
The returns the file that was called first, but not the one currently
executing...

Use __file__ instead of sys.argv[0]
So:
if __name__ == "main":
currentDir = os.path.dirname(sys.argv[0])
else:
currentDir = os.path.dirname(__file__)
>
--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)

signature.asc
1KDownload

Jul 6 '07 #4
En Fri, 06 Jul 2007 17:15:22 -0300, Benjamin <mu**************@gmail.com>
escribió:
How does one get the path to the file currently executing (not the
cwd). Thank you
So:
if __name__ == "main":
currentDir = os.path.dirname(sys.argv[0])
else:
currentDir = os.path.dirname(__file__)
I think you meant to test for "__main__", but anyway, this should be
enough:
currentDir = os.path.dirname(__file__)
or perhaps os.path.dirname(os.path.abspath(__file__)). Try to determine
that early in your program because __file__ may contain a relative path
(and will give a wrong result after changing the current directory).

--
Gabriel Genellina

Jul 9 '07 #5
On Jul 9, 6:42 am, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Fri, 06 Jul 2007 17:15:22 -0300, Benjamin <musiccomposit...@gmail.com
escribió:
How does one get the path to the file currently executing (not the
cwd). Thank you
So:
if __name__ == "main":
currentDir = os.path.dirname(sys.argv[0])
else:
currentDir = os.path.dirname(__file__)

I think you meant to test for "__main__", but anyway, this should be
Yes
enough:
currentDir = os.path.dirname(__file__)
or perhaps os.path.dirname(os.path.abspath(__file__)). Try to determine
that early in your program because __file__ may contain a relative path
(and will give a wrong result after changing the current directory).
I do it right at the top of the first module. Thanks for the help.
>
--
Gabriel Genellina

Jul 9 '07 #6

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

Similar topics

6
by: vishal | last post by:
hi how can i get the file name from which the current executing file is called. i m making a scrript which will be called from many other scripts. this script performs some calculation and then...
9
by: TS | last post by:
i have code that creates assemblies and classes from the assemlby and methods from the classes to set properties of dynamically created controls. How i should go about validating the assemblies,...
7
by: David R. | last post by:
Hello all, I would like to generate a Sql-Script-File and a Batch-File to execute the Batch-File over C#-Code and use the SQL-File as an Input-File for the command "osql" in the Batch-File. I...
21
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
0
by: seye.ojumu | last post by:
Hello, I'm trying to nail down an issue and I'm not entirely sure what is wrong. It is this "loading pages that share a session problem." The solution, as I've read many places, should be to...
5
by: Eugene Anthony | last post by:
ds1.Tables.Rows.ItemArray.GetValue(0).ToString() contains the string path: images/5/Video1/qbert.flv if (File.Exists(ds1.Tables.Rows.ItemArray.GetValue(0).ToString())) { //code to execute } ...
7
by: CodeGrommet | last post by:
I'm testing out the system() command. I coded the following. How can I output the results into the given output file? Your help will be appreciated. /* system example : DIR */ //code based...
2
by: RaviRajhulk | last post by:
I have tried executing executing a batch file from a perl code using system("start c:\\temp\\sample.bat") but it is not executing ,Is there any way to execute batch file from a perl code
5
by: Arodicus | last post by:
I'm trying to get the pathname of the .js file that the currently-executing function resides in. This is useful if your .js file loads other assets within (or based on) the directory your .js file is...
4
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

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.