Python Forum
Invoking function in if else statement, not working!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Invoking function in if else statement, not working!
#1
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)
Reply
#2
You may have to close the file at the end
filename.close()
Reply
#3
(May-30-2019, 06:54 PM)SheeppOSU Wrote: You may have to close the file at the end
filename.close()
No, he does not - with operator guarantees closing of the file
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#4
can you share the file ABMF00GLP_R_20180010000_01H_EN.rnx you work with?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
can't attach the requested due to forum rule. however if you can provide me with your email, i can send it over there.
Reply
#6
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
This piece of code makes no sense
        while i>=0:
            if data[i]==' ':
                i=i+1
                continue
            else:
                break

  1. You are incrementing i- it cannot become lesser than 0, no overflow in Python
  2. continue is absolutely redundant
  3. You can run out of data

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 !+ = ' ':
        break
No need for index at all!
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#8
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"
Reply
#9
isn't it simple text file? just change the file extension to txt
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#10
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.

Attached Files

.txt   ABMF00GLP_R_20180010000_01H_EN.txt (Size: 37.97 KB / Downloads: 140)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  invoking python in Terminal Euler 2 591 Aug-25-2023, 06:17 AM
Last Post: perfringo
Shocked kindly support with this dropna function not working gheevarpaulosejobs 2 617 Jul-24-2023, 03:41 PM
Last Post: deanhystad
Question If, elif, and else statement not working PickleScripts 3 841 Mar-30-2023, 02:53 PM
Last Post: PickleScripts
  If statement not working correctly? MrKnd94 2 797 Nov-16-2022, 02:49 AM
Last Post: deanhystad
Exclamation Function Not Working Alivegamer 7 1,817 Jul-19-2022, 01:03 PM
Last Post: deanhystad
  try function working on PC but not raspberry pi AnotherSam 1 1,499 Oct-11-2021, 04:51 AM
Last Post: bowlofred
  How to invoke a function with return statement in list comprehension? maiya 4 2,752 Jul-17-2021, 04:30 PM
Last Post: maiya
  If Statement not working...Why? Milfredo 2 2,163 Oct-17-2020, 03:23 AM
Last Post: Milfredo
  Input() function not working in VS Code darpInd 7 13,088 Feb-17-2020, 03:28 PM
Last Post: snippsat
  Unrelated new function causing existing working function to fail Nick_G 2 2,213 Jan-27-2020, 07:21 PM
Last Post: Nick_G

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020