[PLUG] Python Lists and File Reads
Rich Shepard
rshepard at appl-ecosys.com
Fri Jul 15 23:23:53 UTC 2005
On Fri, 15 Jul 2005, Shahms King wrote:
> I think you probably want to get rid of the quotes around both of those
> ~ arguments. Additionally, what's the point of passing "input" and
> "output" as parameters if you never actually use the values?
Shahms,
I tried using input, but it was an empty string. After I assigned it I
could see the contents.
I've four books on python (two ORA books by Mark Lutz and a couple
downloaded from the web), but I cannot find answers to questions such as I've
posted here. I wanted to use input as a list, not just a file handle, but
that wasn't working for me.
> | src = input.read()
>
> This will read the entire input into a single string.
> You probably meant to say:
>
> src = input.read().split()
Thank you.
> Additionally, (assuming I read your intention correctly) your loop
> probably makes more sense as:
>
> ----------------------------------
> for i,elem1 in enumerate(src):
> ~ for j,elem2 in enumerate(src):
> ~ if i < j:
> ~ print >>output, (elem1,elem2)
> ----------------------------------
>
> Or, alteratively:
>
> ----------------------------------
> for i,elem1 in enumerate(src):
> ~ for elem2 in src[i+1:]:
> ~ print >>output, (elem1, elem2)
> -----------------------------------
The loop worked fine when I was working with a list. I've no idea if I
want a list or a split string. My references did not give me any insight into
this.
Many thanks,
Rich
--
Dr. Richard B. Shepard, President | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
More information about the PLUG
mailing list