[Tutor] file object in memory

Monika Jisswel monjissvel at googlemail.com
Fri Jul 4 18:16:12 CEST 2008

Hi everyone,

In my program I have this code :

self.run_cmd_0 = subprocess.Popen(self.cmd_0, stdout = subprocess.PIPE,
> shell = True)     #(1)
> self.run_cmd_1 = subprocess.Popen(self.TOCOL, stdin =
> self.run_cmd_0.stdout, stdout = subprocess.PIPE, shell = True)    #(2)
> self.result_0 = StringIO.StringIO(self.run_cmd_1.communicate()[0])
> #(3)

(1) :  executes cmd_0 as a subprocess with stdout to PIPE
(2) : executes cmd_1 a second process with stdin from the previouse cmd_0
(3) : Here I tried to use StringIO module to create a file object from
stdout of cmd_1 : I need a file object because I have a mysql query later in
my program to load it into the database :

self.cmd_sql_2 = "load data local infile '%s' into table statistics fields
> terminated by '\t' lines terminated by '\n'" % self.FILE

so self.cur.execute(self.cmd_sql_2) fails.
the problem is that  mysql  is expecting a REAL file for this query !! is
there any pythonic way of avoiding to write to disk before loading into
Mysql database ? some sort of in-memory file oject.

Thanks In Advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080704/0501eb05/attachment.htm>

More information about the Tutor mailing list