Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50255
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-07-09 08:07 -0700 |
| References | <3b5b02ee-90a3-4a19-af96-b83b4a1039a2@googlegroups.com> <mailman.4452.1373379861.3114.python-list@python.org> |
| Message-ID | <bb4592bf-dabf-409b-927f-21cd095e3452@googlegroups.com> (permalink) |
| Subject | Re: Reading File Into 2D List |
| From | alex.hanga@gmail.com |
> Replace te **start line with something like:
>
>
>
> object_data.append([])
>
> i += 1
>
>
>
> This assumes a few missing lines, which must have been there or you
>
> would have already had runtime errors. For example, you'll need i=0
>
> before the loop.
>
>
>
> Another comment about the append with all those calls to float(). When
>
> you see a line like that, you want to seriously consider making it a
>
> loop, or a comprehension, or something.
>
>
>
> Given that elem is a list of strings, you could convert it to a list of
>
> float, then convert that to a tuple (if you really wanted that). At
>
> that point, you just append it. All this could be done in one line if
>
> you like, something like (untested):
>
>
>
> object_data[i].append(tuple(map(float, row.split(","))))
>
>
>
>
>
>
>
> --
>
> DaveA
Yes, indeed there are a few lines missing. Just the read file and the i=0 pretty much. The help you gave me solved my problem, thank you very much!
I know the calls to float() are sub par and quite stupidly made but I'm not that good at python scripting (yet) so I try to keep my functions rather easy to read so I understand what is happening. A bit later I will take the time to make my code more sophisticated, but as of now I just want it to work, hehe.
Again, thank you so much!
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Reading File Into 2D List alex.hanga@gmail.com - 2013-07-09 06:30 -0700
Re: Reading File Into 2D List Dave Angel <davea@davea.name> - 2013-07-09 10:24 -0400
Re: Reading File Into 2D List alex.hanga@gmail.com - 2013-07-09 08:07 -0700
csiph-web