Python Equivalent for dd & fold

seldan24 seldan24 at gmail.com
Wed Jul 15 12:36:13 EDT 2009


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 have the file TESTFILE and I know it should be
formatted to 32 characters/line, I run:

dd if=TESTFILE,EBCDIC conv=ASCII | fold -w 32 > TESTFILE.ASCII

Luckily, the files have the packed decimal format common in COBOL
programs converted already prior to reaching me, so all I have to do
is the conversion and line width formatting.  The above works fine,
and I know I could (and may) just embed it using subprocess.Popen.
This, I've figured out how to do.  But, ideally, I'd like to convert
as much shell to native Python as possible, so that I can learn more.

I think I can figure out the first part by using the codecs module...
found some information on Google related to that.  My question is,
what can I use as the equivalent for the Unix 'fold' command?  I don't
really need to know how to do it, just a push in the right direction.

Thanks.



More information about the Python-list mailing list