×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    11

    Question HELP ME!ABOUT SYS.PATH

    I have a problem,look the codes:

    import os,sys
    print os.getcwd()
    for i in sys.path:
    print i
    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!

  2. #2
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,800

    Re: HELP ME!ABOUT SYS.PATH

    Quote Originally Posted by kingqq007 View Post
    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!
    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)
    Code:
    os.path.abspath('')
    Now if you want to get a "\" at the end of the path then just use
    Code:
    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.

    Hope that helps
    Pankaj Nathani
    www.croozeus.com

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    11

    Unhappy Re: HELP ME!ABOUT SYS.PATH

    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"

  4. #4
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,800

    Re: HELP ME!ABOUT SYS.PATH

    Quote Originally Posted by kingqq007 View Post
    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..

    Code:
     path = os.getcwd()
    THE ABOVE CODE LINE PERFORMS THE FOLLOWING:

    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

  5. #5
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,800

    Re: HELP ME!ABOUT SYS.PATH

    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

  6. #6
    Super Contributor
    Join Date
    May 2006
    Location
    Oulu, Finland
    Posts
    622

    Re: HELP ME!ABOUT SYS.PATH

    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
      Code:
      print sys.path
      ["C:\\private\\2000b1a5", "c:\\resource", "e:\\python\\lib"]
      You can create the last one to push Python libraries via bluetooth.


    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

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    11

    Smile Re: HELP ME!ABOUT SYS.PATH

    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!

  8. #8
    Registered User
    Join Date
    Nov 2006
    Location
    Recife, Brazil
    Posts
    79

    Re: HELP ME!ABOUT SYS.PATH

    Hi,

    I need to know the script path to open another application inside the same working directory. Any way?

    Quote Originally Posted by lfd View Post
    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
      Code:
      print sys.path
      ["C:\\private\\2000b1a5", "c:\\resource", "e:\\python\\lib"]
      You can create the last one to push Python libraries via bluetooth.


    Now my question is why do you need to know the script path?

    LFD

Similar Threads

  1. Help me!about Mail
    By yinjialiang in forum Symbian
    Replies: 3
    Last Post: 2004-09-19, 08:48

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×