Python Forum
Doing calculation with ascii file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Doing calculation with ascii file
#4
I guess I solved my problem.
Here is the script:
with open('file.txt',"r") as in_file, open('file2.txt',"w") as out_file:
	next(in_file)
	for line in in_file:
		line = line.strip()
		num1, num2 = line.split(',')
		num1, num2 = int(num1), int(num2)
		num3 = num1 + num2
		out_file.write(str(num1) + "," + str(num2) + "," + str(num3) + "\n")
		continue
Which outputs external file "file2.txt", although without headers that I removed using command "next(in_file)"
Output:
324,234,558 346,341,687 147,346,493 234,567,801 368,405,773 344,643,987 235,235,470 236,567,803
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,763 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