read line

Larry Bates larry.bates at websafe.com`
Tue May 6 16:17:24 EDT 2008


moustafa.elmihy at gmail.com wrote:
> hi every body,
> 
> I'm a new python user and I'm making a program to run useing Abaqus
> and there is something I can't do,
> 
> if i have a text file that has a line like this " 10   20  30     40
> 50" and I wana do the coding to put every number of these like 10 or
> 20 in a separate variable .. any suggestions ??
> 
> thanks in advance

The problem with you not actually trying anything and posting it here is that we 
have no real idea if 10, 20, ... 50 should be strings, integers, floats, 
hexadecimal, or decimal "variables".

Assuming you mean integers:

fp=open('textfile.txt')
l=fp.readline()
a,b,c,d,e = [int(x) for x in l.split()]
fp.close()

More likely you need:
values = [int(x) for x in l.split()]

-Larry



More information about the Python-list mailing list