Python Forum
Doing calculation with ascii file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Doing calculation with ascii file
#2
To take a little further,and is better to use with open() then don't need to use close() as it dos automatically.
with open('col.txt') as f:
    next(f)
    for line in f:
        line = line.strip()
        num1, num2 = line.split(',')
        num1, num2 = int(num1), int(num2)
So now is ready to continue further,if i do a test after running this code.
>>> num1 + num2
803
As expected i get the last calculation.
Reply


Messages In This Thread
Doing calculation with ascii file - by Mike - Oct-02-2019, 11:09 AM
RE: Doing calculation with ascii file - by snippsat - Oct-02-2019, 11:42 AM
RE: Doing calculation with ascii file - by Mike - Oct-02-2019, 12:17 PM
RE: Doing calculation with ascii file - by Mike - Oct-02-2019, 01:34 PM
RE: Doing calculation with ascii file - by snippsat - Oct-02-2019, 01:55 PM
RE: Doing calculation with ascii file - by Mike - Oct-02-2019, 02:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Read ASCII File pyth0nus3r 3 8,379 May-23-2019, 11:13 PM
Last Post: michalmonday
  need algorithm to strip non-ascii characters from LONG csv file hereathome 3 3,764 Jan-12-2018, 02:04 AM
Last Post: hereathome

Forum Jump:

User Panel Messages

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