top of page
Search
baogrates389eoi

Solucionariovibracionesmecanicasraopdf11 Deancher







How to read text file line by line in Python? I have a text file with content like this : 12345678 b23dafgd3ddasad3dda 12345678 4befddafgd3ddasad3dda 12345678 2dcfdafgd3ddasad3dda 12345678 64befddafgd3ddasad3dda I need the output to be like this: 12345678 b23dafgd3ddasad3dda 12345678 4befddafgd3ddasad3dda 12345678 2dcfdafgd3ddasad3dda 12345678 64befddafgd3ddasad3dda I need to split every second line by the content between the first " " and the second " " in the string. Any ideas? A: You could use the open() function to open the file and read() to read each line: with open('file.txt', 'r') as file: for line in file.read().splitlines(): print line Then, if you wanted to extract the data in that line, you could use the split() function to split the line on whitespace, then split() again on the first space: with open('file.txt', 'r') as file: for line in file.read().splitlines(): data = line.split()[0].split(' ')[1:] print(data) EDIT If you wanted to iterate over the lines in the file and print the data out, you could use something like this: with open('file.txt', 'r') as file: for line in file.read().splitlines(): print(line) Q: Convert vector to list of vectors Let's say I have a vector c(5,7) and I want to convert it to a list list(c(5,7)) So as to then get a list of two vectors like list ac619d1d87


Related links:

3 views0 comments

Recent Posts

See All

Comments


bottom of page