×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    15

    How to import python files in a python script?

    Hi

    I am starting on programing python in a S60 phone.
    I have 2 python files (main.py, action.py) and i want to import on file to the other and i cant do it.
    I have tried:

    Main file:
    Code:
    import action.py
    
    num = '1'
    action.main(num)
    i put both files in C:\Python but when i run main.py it says that there is no module called action.py
    Is pyS60 different from default python on the way to import files? or i am missing something?
    tks!

  2. #2
    Regular Contributor
    Join Date
    Sep 2008
    Location
    London, UK
    Posts
    176

    Re: How to import python files in a python script?

    you need to add your source folder to the sys.path
    for example, if the path to your file is "c:\data\python\action.py"

    Code:
    import sys
    sys.path.append("c:\\data\\python")
    
    import action.py
    The86Hitman
    PyS60 1.9.7 on E71
    http://www.drhtailor.com/pys60

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    15

    Re: How to import python files in a python script?

    I tried that to but i have the 2 files in same directory C:\Python.

    However i already tried:
    Code:
    import sys
    sys.path.append("C:\\Python\\action.py")
    import action.py
    
    num = '1'
    action.main(num)
    and this:

    Code:
    import sys
    sys.path.append("C:\\Python")
    import action.py
    
    num = '1'
    action.main(num)
    and still saying in the phone "no module called action.py"

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    15

    Re: How to import python files in a python script?

    Ok i managed to work by puting main file in C:\Python and the other in C:\Data then i set sys.path.append("c:\\data") and it worked.

  5. #5
    Regular Contributor
    Join Date
    Sep 2008
    Location
    London, UK
    Posts
    176

    Re: How to import python files in a python script?

    oops, slip of the finger... omit ".py"

    Code:
    import sys
    sys.path.append("c:\\python")
    import action
    The86Hitman
    PyS60 1.9.7 on E71
    http://www.drhtailor.com/pys60

Similar Threads

  1. Python for S60 1.9.1 released
    By tvijayan in forum Symbian
    Replies: 30
    Last Post: 2009-02-26, 06:16
  2. Python for S60 1.9.0 released
    By tvijayan in forum Symbian
    Replies: 48
    Last Post: 2009-01-27, 15:39
  3. Replies: 3
    Last Post: 2009-01-09, 18:53
  4. Starting Python script from C++
    By haviital in forum Symbian
    Replies: 10
    Last Post: 2008-11-14, 10:00
  5. help me write a python script
    By psychologe in forum Symbian
    Replies: 10
    Last Post: 2008-01-17, 11:12

Posting Permissions

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