I have a problem,look the codes:
But the result is different to the PC,Why?i want get the result is like VB's app.path,How should I do? Sorry my english!import os,sys
print os.getcwd()
for i in sys.path:
print i![]()
I have a problem,look the codes:
But the result is different to the PC,Why?i want get the result is like VB's app.path,How should I do? Sorry my english!import os,sys
print os.getcwd()
for i in sys.path:
print i![]()
Hello kingqq007
I think you meant the following code with correct indentations
Code:import os,sys print os.getcwd() for i in sys.path: print i
App.Path is a function in Visual Basic that returns a string with the "\" character at the end if the path is the root drive but without that character if it isn't . Most of the time we need the "\" at the end, so this function saves you the inconvenience of adding it every time.
For example app.path will return the following path for respective drives and folders
(e.g., "C:\") (e.g., "C:\Program Files")
Now coming back to Python we are using the os.getcwd() to get the path...We can also get the same path by (if the string is null)
Now if you want to get a "\" at the end of the path then just useCode:os.path.abspath('')
When your dealing with subfolders and folders you dont need to append the "\" so use the 1st code.I guess you will need the "\" only if its a Root Drive.Code:os.path.abspath('\')
Hope that helps
Pankaj Nathani
www.croozeus.com
THANK YOU!
My pys60 install path is E: ,My script's path is E:\PYTHON,
In my codes,i want to return it(Script's path),but it is return the "E:\private\2000b1a5"
![]()
Hello Kingqq007
I think u havent still got the meaning of os.getcwd()
So let me make it clear once again..
THE ABOVE CODE LINE PERFORMS THE FOLLOWING:Code:path = os.getcwd()
Instead of setting path to the directory where the currently running script is located, you set it to the current working directory instead. This will be whatever directory you were in before you ran the script, which is not necessarily the same as the directory the script is in. (Read that sentence a few times until you get it)
So now you may have know that it does'nt return the path where the scripts are located but it give path of the workign director,,,
I hope os.getcwd() is clear to you now...
this function is usually used for making scrips or code potable to other devices so that we do not need to change the path manually everytime...
Hope that helps
Pankaj Nathani
www.croozeus.com
I have got a working example for you at of os.getcwd()
http://croozeus.googlepages.com/os.getcwd%28%29
![]()
Pankaj Nathani
www.croozeus.com
Hi kingqq007!
- The getcwd ("Get current working directory") will return a string telling you where the current application is installed in our case.
If your script is in E:\\python, then I suppose that you are using the Python script shell which __IS__ the application. Then inside that application there a function call execfile(script_path, namespace) that execute your script.
- sys.path is a list of strings that specifies the search path for modules. It means in which directory Python need to search for a library when you import it. With PyS60 installed in C: (to avoid problems with standalone applications) I have the following search paths
You can create the last one to push Python libraries via bluetooth.Code:print sys.path ["C:\\private\\2000b1a5", "c:\\resource", "e:\\python\\lib"]
Now my question is why do you need to know the script path?
LFD
Devices:
Nokia E61 3rd Edition - pys60 1.4.0
Tips and modules:
http://www.lfdm.net/thesis
thanks two!
when i edit scripts,I need to use another file,now i need specified the another file's path each time,but the file's path and script's path as same,so i hope use codes return the file's path.not use define. file='e:\python\xxx.txt'
i hope use this:file=os.getcwd()+'\xxx.txt'
now i clear it,so thanks two.sorry my english!