[Tutor] How to group data?

tee chwee liong tcl76 at hotmail.com
Mon Feb 14 00:55:24 CET 2011


> for i in range(0, len(values), 128):
> # Step through the list of values, starting at 0,
> # taking 128 items at a time.
> temp = values[i:i+128]
> # Join the values into a string.
> s = ''.join(temp)
> # And make a row with a label.
> row = "Row" + str(counter) + " = " + s
> print row
> rows.append(row)

modified the code to be but it didnt print out anything:
###code
 
from __future__ import with_statement
def main():
    rows = []
    counter=1 #count row numbers
    values = []
    with open('test2.txt') as f:
        for i in range(0,len(values),128):
            #step through the list of values, starting at 0,
            #taking 128 items at a time
            temp=values[i:i+128]
            #join the values into a string
            s=''.join(temp)
            #and make a row with a label.
            values.append(line.rstrip('\n')[-1])
            row = "Row" + str(counter) + " = " + s
            print row
            rows.append(row)
if __name__ == '__main__':
    main()
 
#####
 
pls advise. tq 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110213/e08e0d17/attachment.html>


More information about the Tutor mailing list