×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    18

    Simple but hard for a beginner...

    Dear Friends,

    I am trying to write a code and stucked here:

    I have an .ini file which "clear" is written in it... What i wanted to do is read this "clear" from settings.ini and use it in if-else but i think "clear" is character and i cant use it as integers... if i write numbers instead of chars in the .ini file there is no problem but if i write chars then my code not working... How can i read chars and use it in if else situations?

    Here my example code that i want to do:

    Code:
    filea = "c:\\data\\settings.ini"
    
    def read_file1():
        f = codecs.open(filea, 'r', 'utf8')
        set = f.read()
        f.close()
        return set 
    
    def run():
        tp = read_file1()
        set = int(tp)
        if set == clear: #my problem is here !!!!
            appuifw.note(u"RIGHT VALUE !", 'info')
        else:
            appuifw.note(u"WRONG VALUE !", 'info')

    Regards...

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Simple but hard for a beginner...

    Yes, you already found the answer
    "clear" is a word that contains non-numeric characters, so you cannot convert it to an integer number using the int() function. But from what I understand you don't have to. Simply compare what you read from the file with the word "clear":
    Code:
    filea = "c:\\data\\settings.ini"
    
    def read_file1():
        f = codecs.open(filea, 'r', 'utf8')
        set = f.read()
        f.close()
        return set 
    
    def run():
        set = read_file1()
        if set == "clear":
            appuifw.note(u"RIGHT VALUE !", 'info')
        else:
            appuifw.note(u"WRONG VALUE !", 'info')

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    18

    Re: Simple but hard for a beginner...

    Dear Bogdan Galiceanu,

    Thanks again for your fast reply... Now the code is working flawlessly... As i started to learn python, i get more and more excited day by day...

    Regards...

Similar Threads

  1. Replies: 3
    Last Post: 2009-05-04, 10:15
  2. Please help a real beginner with carbide.c++
    By edward.quan in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2006-06-07, 07:29
  3. Advice needed --> absolute beginner
    By logismon in forum Mobile Java Tools & SDKs
    Replies: 2
    Last Post: 2006-03-06, 13:29

Posting Permissions

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