Re: Python Equivalent for dd & fold

2009-07-16 Thread MRAB
Michiel Overtoom wrote: seldan24 wrote: I know that Emile suggested that I can slice out the substrings rather than do the gradual trimming of the string variable as is being done by moving around the length. An excellent idea. def fold(s,chunklength): offset=0 while offset More Pyt

Re: Python Equivalent for dd & fold

2009-07-16 Thread MRAB
seldan24 wrote: On Jul 15, 1:48 pm, Emile van Sebille wrote: On 7/15/2009 10:23 AM MRAB said... On Jul 15, 12:47 pm, Michiel Overtoom wrote: seldan24 wrote: what can I use as the equivalent for the Unix 'fold' command? def fold(s,len): while s: print s[:len] s=s[len

Re: Python Equivalent for dd & fold

2009-07-16 Thread ryles
On Jul 15, 1:14 pm, seldan24 wrote: > On Jul 15, 12:47 pm, Michiel Overtoom wrote: > > > > > seldan24 wrote: > > > what can I use as the equivalent for the Unix 'fold' command? > > > def fold(s,len): > >      while s: > >          print s[:len] > >          s=s[len:] > > > s="A very long string i

Re: Python Equivalent for dd & fold

2009-07-16 Thread pdpi
On Jul 16, 3:12 pm, seldan24 wrote: > On Jul 15, 1:48 pm, Emile van Sebille wrote: > > > > > > > On 7/15/2009 10:23 AM MRAB said... > > > >> On Jul 15, 12:47 pm, Michiel Overtoom wrote: > > >>> seldan24 wrote: > > what can I use as the equivalent for the Unix 'fold' command? > > >>> def fol

Re: Python Equivalent for dd & fold

2009-07-16 Thread Casey Webster
On Jul 16, 10:12 am, seldan24 wrote: > On Jul 15, 1:48 pm, Emile van Sebille wrote: > > > > > On 7/15/2009 10:23 AM MRAB said... > > > >> On Jul 15, 12:47 pm, Michiel Overtoom wrote: > > >>> seldan24 wrote: > > what can I use as the equivalent for the Unix 'fold' command? > > >>> def fold(s

Re: Python Equivalent for dd & fold

2009-07-16 Thread Michiel Overtoom
seldan24 wrote: I know that Emile suggested that I can slice out the substrings rather than do the gradual trimming of the string variable as is being done by moving around the length. An excellent idea. def fold(s,chunklength): offset=0 while offsethttp://www.catb.org/~esr/halloween

Re: Python Equivalent for dd & fold

2009-07-16 Thread seldan24
On Jul 15, 1:48 pm, Emile van Sebille wrote: > On 7/15/2009 10:23 AM MRAB said... > > >> On Jul 15, 12:47 pm, Michiel Overtoom wrote: > >>> seldan24 wrote: > what can I use as the equivalent for the Unix 'fold' command? > >>> def fold(s,len): > >>>      while s: > >>>          print s[:len]

Re: Python Equivalent for dd & fold

2009-07-15 Thread Emile van Sebille
On 7/15/2009 10:23 AM MRAB said... On Jul 15, 12:47 pm, Michiel Overtoom wrote: seldan24 wrote: what can I use as the equivalent for the Unix 'fold' command? def fold(s,len): while s: print s[:len] s=s[len:] You might still need to tweak the above code as regards ho

Re: Python Equivalent for dd & fold

2009-07-15 Thread MRAB
seldan24 wrote: On Jul 15, 12:47 pm, Michiel Overtoom wrote: seldan24 wrote: what can I use as the equivalent for the Unix 'fold' command? def fold(s,len): while s: print s[:len] s=s[len:] s="A very long string indeed. Really that long? Indeed." fold(s,10) Output: A

Re: Python Equivalent for dd & fold

2009-07-15 Thread seldan24
On Jul 15, 12:47 pm, Michiel Overtoom wrote: > seldan24 wrote: > > what can I use as the equivalent for the Unix 'fold' command? > > def fold(s,len): >      while s: >          print s[:len] >          s=s[len:] > > s="A very long string indeed. Really that long? Indeed." > fold(s,10) > > Output:

Re: Python Equivalent for dd & fold

2009-07-15 Thread Michiel Overtoom
seldan24 wrote: what can I use as the equivalent for the Unix 'fold' command? def fold(s,len): while s: print s[:len] s=s[len:] s="A very long string indeed. Really that long? Indeed." fold(s,10) Output: A very lon g string i ndeed. Rea lly that l ong? Indee d. Greeting

Python Equivalent for dd & fold

2009-07-15 Thread seldan24
Hello, I have a shell script, that I'm attempting to convert to Python. It FTP's files down from an AS/400 machine. That part is working fine. Once the files arrive, the script converts them from EBCDIC to ASCII and then formats their line width based on a pre-determined size. For example, if I