Problem using StringIO file object

Joshua Burvill josh at mri.com.au
Wed May 19 23:00:34 EDT 2004


Hello,

I have the following script for printing something to a print server using
ftplib, but it seems that I have a problem with putting the content into the
file object as is shown by the following output from the script.

Any tips?

-Josh

>>> mk_zeb_label()
('226 Closing.', '')
>>>

########################
## SCRIPT STARTS HERE ##
########################

def mk_zeb_label():

    from ftplib import FTP
    import string, cStringIO




    ## Create file-handle to a "file-like" string
    file_handle=cStringIO.StringIO()

    printserver_ip="192.168.2.177"
    portname="COM"
    zpt_code="""
^XA
^cfd,36,20
^by3,,50
^fo470,50
^abn,48,30^fdREPAIR^fs
^fo50,150
^fdSome text goes here.^fs
^fdSome text goes here.^fs
^fdSome text goes here.^fs
^fo50,50
^bc^fd114567^fs
^XZ
"""


    file_handle.write(zpt_code)
    ftp=FTP(printserver_ip)
    ftp.login("","")
    ftp.set_pasv(0)

    val=ftp.storlines("STOR " + portname, file_handle)

    return val, file_handle.read()





More information about the Python-list mailing list