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: 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> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: 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 > Replace te **start line with something like: >=20 >=20 >=20 > object_data.append([]) >=20 > i +=3D 1 >=20 >=20 >=20 > This assumes a few missing lines, which must have been there or you=20 >=20 > would have already had runtime errors. For example, you'll need i=3D0=20 >=20 > before the loop. >=20 >=20 >=20 > Another comment about the append with all those calls to float(). When= =20 >=20 > you see a line like that, you want to seriously consider making it a=20 >=20 > loop, or a comprehension, or something. >=20 >=20 >=20 > Given that elem is a list of strings, you could convert it to a list of= =20 >=20 > float, then convert that to a tuple (if you really wanted that). At=20 >=20 > that point, you just append it. All this could be done in one line if=20 >=20 > you like, something like (untested): >=20 >=20 >=20 > object_data[i].append(tuple(map(float, row.split(",")))) >=20 >=20 >=20 >=20 >=20 >=20 >=20 > --=20 >=20 > DaveA Yes, indeed there are a few lines missing. Just the read file and the i=3D0= 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 e= asy 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 wo= rk, hehe. Again, thank you so much!