[Tutor] Alternative File I/O for Tuples

Kent Johnson kent37 at tds.net
Sun Jun 26 15:24:10 CEST 2005

Don Parris wrote:
> When I pickle a SQL result into a file (ASCII mode), it lays out the data in
> an interesting format.  

pickle format is not intended for pretty-printing or readability for that matter. You have to write the file yourself in the format you want.

> When I send it to the printer, I'd like to see it
> arranged more like it is on the console screen - in tabbed columns.  None of
> the tutorial type stuff I've seen even mentions printing files, or accessing
> the files you create in a Python program.  I did manage to find an example
> of a print function.

It sounds like you want to write a file for later printing. Writing files should be covered in any Python tutorial; the standard tutorial talks about it here:

Danny has given you some hints about how to do the formatting. This recipe has a very complete solution for formatting tables. You could easily change the example to print to a file:


> Here is some sample data from the resulting file:
> ((S'Everybody'
> S'Anonymous'
> Nt(S'James'
> S'Austin'
> S'704-111-1234'
> t(S'Janet'
> S'Austin'
> S'704-111-1234'
> I would like to see something more like when the file is printed:
> Austin    James    704-111-1234
> Austin    Janet    704-111-1234
> etc.
> Is this a simple task, or am I jumping into deep water? :)
> Don

More information about the Tutor mailing list