writing serial port data to the gzip file

Petr Jakes mcbooczech at gmail.com
Mon Dec 18 18:26:55 EST 2006


Hi Dennis,
thanks for your reply.
Dennis Lee Bieber napsal:
> > def dataOnSerialPort():
> >     data=s.readLine()
>
> 	Unless you are using a custom serial port module, that should be
> s.readline()
sorry for the typo
>
> >     if data:
> >         return data
> >     else:
> >         return 0
>
> 	This if statement is meaningless -- if "data" evaluates to false,
> return a numeric value that evaluates to false.
I see, it is OK just to return data (or an empty string "")
>
> >
> > while 1:
> >     g=gzip.GzipFile("/root/foofile.gz","w")
> >     while dataOnSerialPort():
> >         g.write(data)
>
> 			"data" is an uninitialized value here
> >     else: g.close()
>
> 	And what is the purpose of closing the file if you immediately turn
> around and create it again (assuming gzip.GzipFile() behaves as open()
> does, a mode of "w" means delete the old file and create a new one.
> There is NO exit from the above.
>
> 	Since I can't read your mind with regards to some of your looping...
>
> s = ... #somewhere you had to open the serial port
>
> g = gzip.GzipFile("/root/foofile.gz", "w")
> while True:
> 	data = s.readline()
> 	if not data: break
> 	g.write(data)
> g.close()

what I am trying to say is g.close() does not close the g file (try to
add the line "print g" after g.close())
Petr




More information about the Python-list mailing list