Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50255
| X-Received | by 10.224.41.145 with SMTP id o17mr17803964qae.3.1373382467797; Tue, 09 Jul 2013 08:07:47 -0700 (PDT) |
|---|---|
| X-Received | by 10.182.50.199 with SMTP id e7mr35721obo.22.1373382467685; Tue, 09 Jul 2013 08:07:47 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!t19no871119qam.0!news-out.google.com!f7ni1652qai.0!nntp.google.com!t19no912903qam.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Tue, 9 Jul 2013 08:07:47 -0700 (PDT) |
| In-Reply-To | <mailman.4452.1373379861.3114.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=83.219.194.71; posting-account=rw-dqgoAAADVhc0S25SKuNs1NXqmNkSF |
| NNTP-Posting-Host | 83.219.194.71 |
| References | <3b5b02ee-90a3-4a19-af96-b83b4a1039a2@googlegroups.com> <mailman.4452.1373379861.3114.python-list@python.org> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <bb4592bf-dabf-409b-927f-21cd095e3452@googlegroups.com> (permalink) |
| Subject | Re: Reading File Into 2D List |
| From | alex.hanga@gmail.com |
| Injection-Date | Tue, 09 Jul 2013 15:07:47 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Xref | csiph.com comp.lang.python:50255 |
Show key headers only | View raw
> 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