![]() |
Invoking function in if else statement, not working! - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Invoking function in if else statement, not working! (/thread-18764.html) Pages:
1
2
|
Invoking function in if else statement, not working! - ibaad1406 - May-30-2019 I am invoking a function header_gps,header_glonass etc. in if else statement but the variables defined in there seem not be stored as they should be. May be i am missing something , please help. I am writing my code here itself. """Script for header section of rinex navigation file""" from header_gps import header_gps from header_glonass import header_glonass from header_galileo import header_galileo from header_beidou import header_beidou def header(filepath): with open(filepath) as fp: data = fp.read() data=data.split("END OF HEADER") data=data[0] i=0 while i>=0: if data[i]==' ': i=i+1 continue else: break if data[i]=='2': print("Rinex_2") #Rinex_2 elif data[i]=='3': print("Rinex_3") if 'GPS' in data[0:80]: print(" GPS") header_gps(data) elif 'GALILEO' in data[0:80]: print(" GALILEO") header_galileo(data) elif 'GLONASS' in data[0:80]: header_glonass(data) print("glonass") elif 'BEIDOU' in data[0:80]: print("BEIDOU") header_beidou(data) #Rinex_3 else: print("Version is not defined") filepath='/home/ibaad/Downloads/rinexfile/ABMF00GLP_R_20180010000_01H_EN.rnx' header(filepath) RE: Invoking function in if else statement, not working! - SheeppOSU - May-30-2019 You may have to close the file at the end filename.close() RE: Invoking function in if else statement, not working! - volcano63 - May-30-2019 (May-30-2019, 06:54 PM)SheeppOSU Wrote: You may have to close the file at the endNo, he does not - with operator guarantees closing of the file RE: Invoking function in if else statement, not working! - buran - May-30-2019 can you share the file ABMF00GLP_R_20180010000_01H_EN.rnx you work with? RE: Invoking function in if else statement, not working! - ibaad1406 - May-30-2019 can't attach the requested due to forum rule. however if you can provide me with your email, i can send it over there. RE: Invoking function in if else statement, not working! - buran - May-30-2019 Per forum rules you need to have 5 post in order to be able to attach files. However I've elevated your permissions, so now you can attach file RE: Invoking function in if else statement, not working! - volcano63 - May-30-2019 This piece of code makes no sense while i>=0: if data[i]==' ': i=i+1 continue else: break
The last - but not the least - it is un-Pythonic , iterating over indices in Python is redundant and considered a bad style.for char in data: if char !+ = ' ': breakNo need for index at all! RE: Invoking function in if else statement, not working! - ibaad1406 - May-30-2019 i get an error when attaching the file. "The type of file that you attached is not allowed. Please remove the attachment or choose a different type" RE: Invoking function in if else statement, not working! - buran - May-30-2019 isn't it simple text file? just change the file extension to txt RE: Invoking function in if else statement, not working! - ibaad1406 - May-30-2019 here is the file @volcano63 having unpythonic is not the issue. the issue is how to invoke some function inside if else statement. kindly help me out. |