Discussion Board

Results 1 to 12 of 12
  1. #1
    Regular Contributor roidayan's Avatar
    Join Date
    Jan 2008
    Posts
    56
    hey

    i want my script to write/read configuration file.
    how should i save it ? as in location.
    so it will know if its in memory card or on the phone
    and also after i make my scripts to sis so if a user install to storage card or phone config will be created in appropriate location.

    thx

  2. #2
    Registered User carlus1's Avatar
    Join Date
    Feb 2008
    Posts
    4
    Read this, ...
    http://discussion.forum.nokia.com/fo...d.php?t=127983

    you can save your configuration in a file and read the file after that...

  3. #3
    Regular Contributor roidayan's Avatar
    Join Date
    Jan 2008
    Posts
    56
    that doesnt answer my question.
    I want to know how my script can know to location to save the configuration file.
    as if to somewhere in the storage card if script is in storage card or to phone memory if script is in phone memory.

  4. #4
    Nokia Developer Moderator bogdan.galiceanu's Avatar
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471
    Quote Originally Posted by roidayan View Post
    that doesnt answer my question.
    I want to know how my script can know to location to save the configuration file.
    as if to somewhere in the storage card if script is in storage card or to phone memory if script is in phone memory.
    Are you talking about a configuration file that you create? Because if it's so, you just specify where to create/save the file in your script. If you're talking about a pre-existing file, I don't know.

  5. #5
    Regular Contributor roidayan's Avatar
    Join Date
    Jan 2008
    Posts
    56
    yes i create.
    my question is how i check where to create.
    i want the script to check itself if its on the memory card or the phone memory so based this it will use diff location

  6. #6
    Regular Contributor aya42's Avatar
    Join Date
    Mar 2003
    Location
    UK
    Posts
    125
    Quote Originally Posted by roidayan View Post
    i want my script to write/read configuration file.
    how should i save it ? as in location.
    so it will know if its in memory card or on the phone
    and also after i make my scripts to sis so if a user install to storage card or phone config will be created in appropriate location.
    Best place is probably CWD, which is the directory which the active SIS is installed to. Something like this...

    Code:
    # Example config data
    CONFIG = 'foo';
    
    # Save it
    f = open('config', 'w')
    f.write(CONFIG)
    f.close()
    
    # Load it
    f = open('config', 'r')
    CONFIG = f.read()
    f.close()

  7. #7
    Regular Contributor roidayan's Avatar
    Join Date
    Jan 2008
    Posts
    56
    ha ok thx.
    if i run the script from python shell before making it sis
    it will create/read the config from the same dir as the script file ?

  8. #8
    Regular Contributor aya42's Avatar
    Join Date
    Mar 2003
    Location
    UK
    Posts
    125
    Quote Originally Posted by roidayan View Post
    if i run the script from python shell before making it sis
    it will create/read the config from the same dir as the script file ?
    No. It will go into the directory the PythonScriptShell was installed to - something like E:\Private\2000b1a5.

    If you want to save to the directory where the currently running script is located, then try...

    Code:
    import sys, os
    
    CONFIG_FILENAME = 'config.cfg'
    
    try:
        raise Exception
    catch Exception:
        filepath = sys.exc_info()[2].tb_frame.f_code.co_filename
    filedir, filename = os.path.split(filepath)
    configfile = os.path.join(filedir, CONFIG_FILENAME)
    f = open(configfile, 'w')
    # etc.

  9. #9
    Regular Contributor roidayan's Avatar
    Join Date
    Jan 2008
    Posts
    56
    seems sys.exc_info always gives me (None, None, None)
    tried also os.path.dirname(sys.argv[0]) which gives the pythonshell dir i think

  10. #10
    Regular Contributor aya42's Avatar
    Join Date
    Mar 2003
    Location
    UK
    Posts
    125
    Quote Originally Posted by roidayan View Post
    seems sys.exc_info always gives me (None, None, None)
    It will only return something meaningful when called inside an 'except' block. Looks like I erroneously used the word 'catch' rather than 'except' in the code I previously posted. Try the following code verbatim...

    Code:
    try:
        raise Exception
    except Exception:
        print sys.exc_info()
    If that prints (None, None, None), then there's something seriously wrong with Python.


    Quote Originally Posted by roidayan View Post
    tried also os.path.dirname(sys.argv[0]) which gives the pythonshell dir i think
    Indeed, that's why the above code uses the traceback object to find the filename of the currently running script, which, as far as I know, is the only reliable way to get it.

    When packed as a SIS file, sys.argv[0] will point to the default.py script, but when run from the PythonScriptShell, it will point to the PythonScriptShell's default.py, which is not the file you want.

  11. #11
    Super Contributor JOM's Avatar
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976
    Impressive, very many thanx !!! Been looking for this for months !!! ...got close, but never thought about raising an exception by myself !!! Can't wait the evening to try it out

    Cheers,

    --jouni

  12. #12
    Regular Contributor miohtama's Avatar
    Join Date
    Jan 2004
    Location
    Helsinki
    Posts
    376
    Quote Originally Posted by JOM View Post
    Impressive, very many thanx !!! Been looking for this for months !!! ...got close, but never thought about raising an exception by myself !!! Can't wait the evening to try it out

    Cheers,

    --jouni
    You can do this if you import the module

    Code:
    import os, sys
    
    mod = sys.modules[__name__]
    file = mod.__file__
    path = os.path.dirname(file)
    Mikko Ohtamaa

    http://mfabrik.com
    http://blog.mfabrik.com

Similar Threads

  1. [moved] Theme Studio Error
    By TalJ in forum Themes/Carbide.ui
    Replies: 2
    Last Post: 2009-09-06, 03:39
  2. Theme Studio 3.1 not creating themes
    By zemm in forum Themes/Carbide.ui
    Replies: 11
    Last Post: 2008-10-18, 08:41
  3. File reading & writing help, wav file redaing help
    By shubhamlahoti in forum Mobile Java General
    Replies: 6
    Last Post: 2007-06-27, 09:07
  4. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31
  5. Series 60 SDK Appwizard on windows xp
    By moonjoor in forum Symbian Tools & SDKs
    Replies: 15
    Last Post: 2003-12-24, 10:22

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved