Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If statement not working
#1
Using Linux Mint 18.2 and Python 2.7 with Python 3.5.
Help needed do not understand why the ' if (number == line_num) ' does
not work. The routine continues and gives results for ' expenses-18 '.
How to resolve this?
tia
oldcity
 #!/usr/bin/python3
 #
 ###############################################
 line_num = 1
 with open('Expenses-YY', 'r') as exp_yrs:
     for line in exp_yrs:
         yrs_file = line.strip(",")
         print '(', line_num, ')', yrs_file
         line_num+=1
 #
 #
 number = input(' Enter line #  : ')
 #
 line_num = 0
 with open('Expenses-YY', 'r') as exp_yrs:
     for line in exp_yrs:
         datafile1 = line.strip()
         line_num+=1
         print number, line_num, datafile1
         line_num = int(line_num)
     if (number == line_num):
        datafile = datafile1
 #
 #
 #
 datafile = datafile1.strip()
 #
 print datafile
 with open(datafile, 'r') as exp_data:
     for line in exp_data:
         (pdate,catg,amt,howp) = line.split(',')
         pdate = str(pdate)
         pdate = pdate.strip()
         pdate = str(pdate)
         length = len(pdate)
         howp = howp.strip()
         print pdate, catg, amt, howp

 #   Do stuff here not above line

 print 'job done'
###################################################

 # This is a sample of the resluts.

 ( 1 ) expenses-16

 ( 2 ) expenses-17

 ( 3 ) expenses-18

  Enter line #  : 2
 2 1 expenses-16
 2 2 expenses-17
 2 3 expenses-18

 expenses-18

 010318 2 19.67 2
 010518 5 82.40 2
 010518 6 195.87 2
 050818 2 18.96 2
 051718 3 15.37 2
 052918 1 0.00 2
 job done
Reply


Messages In This Thread
If statement not working - by oldcity - Oct-09-2018, 11:57 PM
RE: If statement not working - by stullis - Oct-10-2018, 12:39 AM
RE: If statement not working - by micseydel - Oct-10-2018, 12:41 AM
RE: If statement not working - by buran - Oct-10-2018, 06:48 AM
< SOLVED >RE: If statement not working - by oldcity - Oct-14-2018, 10:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question If, elif, and else statement not working PickleScripts 3 943 Mar-30-2023, 02:53 PM
Last Post: PickleScripts
  If statement not working correctly? MrKnd94 2 863 Nov-16-2022, 02:49 AM
Last Post: deanhystad
  If Statement not working...Why? Milfredo 2 2,232 Oct-17-2020, 03:23 AM
Last Post: Milfredo
  Invoking function in if else statement, not working! ibaad1406 13 5,719 May-30-2019, 09:05 PM
Last Post: ibaad1406
  if statement not working trent101010 8 5,045 Mar-14-2018, 03:19 PM
Last Post: wavic
  why is this try.....except statement not working? HenryJ 3 8,810 Feb-06-2018, 06:15 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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