faqts : Computers : Programming : Languages : Python : Snippets : Strings

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 4 people (75%) answered Yes
Recently 2 of 3 people (67%) answered Yes

Entry

Can I get the output of the uuencode() function into a string, instead of a file or stdout?

Jul 5th, 2000 10:00
Nathan Wallace, unknown unknown, Hans Nowak, Snippet 172, Fred L. Drake


"""
Packages: crypto;basic_datatypes.strings;text
"""
"""
 > Is it possible to get the output of the uuencode() function
 > into a string, instead of a file or stdout?
  The output file can be a StringIO instance; a convenience function
to handle this could be written as (untested):
"""
#------------------------------------------------------------------------
import StringIO
import uu
def uu2string(data, mode=None):
    outfile = StringIO.StringIO()
    infile = StringIO.StringIO(data)
    uu.decode(infile, outfile, mode)
    return outfile.getvalue()
#------------------------------------------------------------------------