Split Python Function is not working as expected -



Split Python Function is not working as expected -

if have file (users.txt) next info formatted:

x y z(t) x y z(t)

how can write python function reads in file (users.txt) , uses split function break each line of file 3 variables:

who x where y when_and_time z(t)

and prints screen such format who on @ when_and_time or variables x on y @ z(t)

what have far is:

user_info = open("~/users.txt").read() line in user_info: positions = line.split(',') = positions[0] = positions[1] when_and_time = positions[2] print(who + " on " + + " @ " + when_and_time) # press come in @ point

it gives me prompt more commands, @ point press come in 1 time again , receive following:

traceback (most recent phone call last): file "<stdin>", line 4, in <module> indexerror: list index out of range

what doing wrong??

the issue here you're doing split(","), split string on comma characters. since appear have formatted string spaces, it's not splitting anywhere, 1 element in list. want utilize split() no argument split on whitespace.

python

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -