ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
Re: [Tutor] Alternative File I/O for Tuples (fwd)
by Danny Yoo other posts by this author
Jun 26 2005 1:09PM messages near this date
[Tutor] Improving printouts from IDLE | Re: [Tutor] Alternative File I/O for Tuples (fwd)
---------- Forwarded message ----------
Date: Sun, 26 Jun 2005 14:29:22 -0400
From: Don Parris <webdev@[...].org> 
To: Danny Yoo <dyoo@[...].edu> 
Subject: Re: [Tutor] Alternative File I/O for Tuples

On Sat, 25 Jun 2005 22:52:08 -0700 (PDT)
Danny Yoo <dyoo@[...].edu>  wrote:

> 
> 
>  > In your example, it looks like every row is ten characters long.  A
>                                         ^^^
>  Hi Don,
> 
>  Gaa, that's why I'm so bad at matrix math.  I meant "column", not "row".
>  Sorry about that.


I guess I should have used a different example - some names are longer than
others.  Williams is shorter than Vandenbosch, for example.  So the columns
will need to be formatted appropriately.  I'll play with this a bit.  I
should also have said that I need to work primarily with GNU/Linux -
printing with Windows can come a little later.


Kent is kind of on track.  I let the user view the report on the console
screen (nice to verify what you're about to print), and then give them the
choice of printing it, or returning to the menu for other tasks.  For
instance, they may simply want to look up a number, not print out the phone
list.

### Print or Return to Menu ###
    if whatNext == 'p':
        os.system("lpr mbrPhone.txt")    # prints the pickled file.
    elif whatNext == 'r':
        pass                    # BTW, is this a good use of "pass"?

The screen print out is as it should be - nice, neat columns.  So, instead
of this:

    print 'Phone List'
    for record in Results:
        print '%s\t%s\t%s' % record    # prints to screen
        mbrPhone = open('mbrPhone.txt', 'w')
        cPickle.dump(Results, mbrPhone)    # pickles the data into a file
        mbrPhone.close()


I tried this:
mbrPhone = open('mbrPhone.txt', 'w')
mbrPhone.writelines(repr(Results))
mbrPhone.close()



Which produces this in the text file:
(('Everybody', 'Anonymous', None), ('James', 'Austin', '704-111-1234'),
('Janet', 'Austin', '704-111-1234'), ('James', 'Austin', '704-111-1234'),

This is an improvement over pickling the data into a file.  Still, it's not
quite the columnar layout I'd like to achieve.  I'll try that recipe that
was suggested to see if I can get it working with files.  If it's the one
I'm thinking of, it offers a fantastic layout ('bout as good as it gets with
ASCII text) for printing out to screen.

I guess I'm asking two closely-related questions:
(1) how to format the file so it can be readable, and
(2) how to send that file to the printer.  I used os.system('lpr, filename')
above.  Is there another way?


Don
-- 
evangelinux    GNU Evangelist
http://matheteuo.org/                   http://chaddb.sourceforge.net/
"Free software is like God's love - you can share it with anyone anytime
anywhere."

_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Danny Yoo
Kent Johnson
Don Parris
Don Parris
Kent Johnson
Don Parris
Kent Johnson
Don Parris
Kent Johnson
Don Parris
Kent Johnson
Don Parris

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved