Read space in file

I’m reading lines in the file but i want to separate the arguments by spaces how can i do it?

f = open("file.txt" , "r")
    a = f.readlines()

    for i in a:
        i.rstrip("/n")

example output: save Toprak 120

if i add

        for j in i:
            print(j)

output is:

s
a
v
e

T
o
p
r
a
k

1
2
0

but i want take save
Toprak
etc. separately

Perhaps .split() would be useful? Give it an argument of ' ' and you would split the string it’s working on at every space.

Of course you might have to filter out extra space strings or empty strings, but a for loop or list comprehension would be an easy fix there.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.