to write set of values to a file from python

Scott David Daniels scott.daniels at acm.org
Fri Dec 16 19:01:42 CET 2005


Scott David Daniels wrote:
> 
>     def lagged(source):
>         '''produce element,islast for elements in source'''
>         generator = iter(source)
>         previous = generator.next()
>         for element in generator:
>             yield previous, False
>         yield previous, True

Oops:
      def lagged(source):
          '''produce element,islast for elements in source'''
          generator = iter(source)
          previous = generator.next()
          for element in generator:
              yield previous, False
              previous = element
          yield previous, True

> 
>     file = open ('C:\some.csv','r')
>     reader = csv.reader(file)
>     for row, final in lagged(reader):
>         print row
>         if final:
>             print 'final:', row
>         else:
>             print 'leads:', row
> 
> 
> --Scott David Daniels
> scott.daniels at acm.org


-- 
-Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list