Re: Python Equivalent for dd fold

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

Re: Python Equivalent for dd fold

2009-07-16 Thread pdpi
On Jul 16, 3:12 pm, seldan24 selda...@gmail.com wrote: On Jul 15, 1:48 pm, Emile van Sebille em...@fenx.com wrote: On 7/15/2009 10:23 AM MRAB said... On Jul 15, 12:47 pm, Michiel Overtoom mot...@xs4all.nl wrote: seldan24 wrote: what can I use as the equivalent for the Unix 'fold'

Re: Python Equivalent for dd fold

2009-07-16 Thread ryles
On Jul 15, 1:14 pm, seldan24 selda...@gmail.com wrote: On Jul 15, 12:47 pm, Michiel Overtoom mot...@xs4all.nl 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

Re: Python Equivalent for dd fold

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

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 offsetlen(s):

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

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.

Re: Python Equivalent for dd fold

2009-07-15 Thread seldan24
On Jul 15, 12:47 pm, Michiel Overtoom mot...@xs4all.nl 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)

Re: Python Equivalent for dd fold

2009-07-15 Thread MRAB
seldan24 wrote: On Jul 15, 12:47 pm, Michiel Overtoom mot...@xs4all.nl 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.

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 mot...@xs4all.nl 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:] snip You might still need to tweak the