Problem using StringIO file object
Joshua Burvill
josh at mri.com.au
Wed May 19 23:54:57 EDT 2004
I found the solution myself by going back to the documentation.
http://docs.python.org/lib/module-StringIO.html
I should have used the following ways of setting the "file" contents, and
returning the file contents respectively.
## Create file-handle to a "file-like" string
file_handle=cStringIO.StringIO(zpt_code)
file_handle.getvalue()
Thanks to the list anyway, as posting probably clarified things, also my
previous question was answered very quickly and correctly.
Rgds, Josh
-----Original Message-----
From: python-list-bounces+josh=mri.com.au at python.org
[mailto:python-list-bounces+josh=mri.com.au at python.org]On Behalf Of
Joshua Burvill
Sent: Thursday, 20 May 2004 1:01 PM
To: python-list at python.org
Subject: Problem using StringIO file object
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()
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list