How to manipulate a contents of file as record structures
gagsl-py2 at yahoo.com.ar
Sat Jan 31 11:49:25 CET 2009
En Sat, 31 Jan 2009 08:35:44 -0200, CK Raju <ck.thrissur at gmail.com>
> I have a text file containing the following alphanumerals.
> I need to read the contents as single line, one after the other
> and append the sum of digits at the end.
> What would be a simple way to achieve this ?
Suppose f is the open file. To read it a line at a time:
for line in f:
To search for a number, try the re module:
To do some calculation with those numbers, remember to convert them to
x+y gives "1234"
int(x)+int(y) gives 46
More information about the Python-list