By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

Problem using StringIO file object

P: n/a
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()
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Joshua Burvill" <jo**@mri.com.au> wrote in message news:<ma*************************************@pyth on.org>...
file_handle.write(zpt_code)
Okay, you've written to your file object, so your current "file
position" is at the end of the buffer, ready for more writes - reading
from it now will only produce an empty string.
You need to reset your file position to the beginning of the buffer.
ftp=FTP(printserver_ip)
ftp.login("","")
ftp.set_pasv(0)

I'd try putting in a
file_handle.seek(0)
here, so that your ftp object can read from the beginning
of the buffer
val=ftp.storlines("STOR " + portname, file_handle)
and another
file_handle.seek(0)
here so the read can also produce data.
return val, file_handle.read()


Regards, Myles.
Jul 18 '05 #2

P: n/a
"Joshua Burvill" <jo**@mri.com.au> wrote in message news:<ma*************************************@pyth on.org>...
file_handle.write(zpt_code)
Okay, you've written to your file object, so your current "file
position" is at the end of the buffer, ready for more writes - reading
from it now will only produce an empty string.
You need to reset your file position to the beginning of the buffer.
ftp=FTP(printserver_ip)
ftp.login("","")
ftp.set_pasv(0)

I'd try putting in a
file_handle.seek(0)
here, so that your ftp object can read from the beginning
of the buffer
val=ftp.storlines("STOR " + portname, file_handle)
and another
file_handle.seek(0)
here so the read can also produce data.
return val, file_handle.read()


Regards, Myles.
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.