Problem with a tuple - newbie ignorance

Richard Chamberlain richard_chamberlainREMOVE at ntlworld.com
Mon Jan 15 14:26:49 EST 2001


Hi Steven,

I'm afraid that is pretty unclear to me - you'd be better posting a small
snippet of code. I can't tell from you explanation how you think your tuple
should be cleared.

A couple of things to be aware of:

Your tuple is in fact a list - anything in [1,2,3,4] is a list a tuple is
(1,2,3,4).

>From your description it sounds to me like you'd be better with a
dictionary. If your matching field names with values this would be ideal. A
dictionary is a key,value type.

Richard
Steven Citron-Pousty <steven.citron-pousty at yale.edu> wrote in message
news:3A633531.9010303 at yale.edu...
> Greetings all:
> So I am writing this program to parse text files. I am using a tuple to
> store the field names and values (i.e. [['id =', 't =',
> ...]['','',...]]. The program reads through all the files in the
> directory. For each file it writes all the all the matches in teh
> appropriate field.  I am having several problems, but the biggest right
> now is:
> When the program goes to parse the next file it doesn't clear out the
> contents from the last file. Here is how I thought it should work...
> <Header stuff>
> ifields = [[fields names list][list of just '','','']
> <FOR loop with all the file names from the directory>
> open file
> results = ifields
> <fill the results tuple>
> <print the results tuple>
> <go back to the top of the loop>
>
> For some reason I thought that each time results gets sets to ifields it
> should reset the contents of results. I have tried all sorts of other
> workarounds, such as using "del results" just before I go back and
> repeat the loop.
> What am I missing here?
> Thanks for your help...
> Steve
>





More information about the Python-list mailing list