Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help.
#5
[list=1]
[*]import math

#def calcDistance(x1, x2, y1, y2, z1, z2):
 #   distance = math.sqrt((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2)
    
  #  return distance

output_file = open('output.txt', 'w') 
nums = []
nums.append(open('input.txt', 'r'))

lines_of_file = []
for lines in nums:
    lines_of_file.append(lines.readlines())
       
print(lines_of_file)
[/list]
print returns: [['1 2 3 4 5 6\n', '7 8 9 0 1 2\n', '9 8 7 1 2 3\n', '11 12 13 14 15 16\n', '99 99 99 99 99 99\n', '\n']]
This is the correct numbers from the sample file he provided, however it should probably be [['1, 2, 3, 4, 5, 6], [etc, etc]] in order to work with it further

How can I split the contents of each string? When I use the split function it returns an error:

AttributeError: 'list' object has no attribute 'str'
Reply


Messages In This Thread
Need help. - by msp1981 - Apr-06-2019, 01:26 AM
RE: Need help. - by ichabod801 - Apr-06-2019, 01:42 AM
RE: Need help. - by msp1981 - Apr-06-2019, 02:13 AM
RE: Need help. - by scidam - Apr-06-2019, 05:01 AM
RE: Need help. - by msp1981 - Apr-06-2019, 02:13 PM
RE: Need help. - by scidam - Apr-06-2019, 11:41 PM

Forum Jump:

User Panel Messages

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