[Tutor] How do I go from a textFile.txt to a list [] AND from a textFile.txt to a dictionary of dictionaries?

Mark Lawrence breamoreboy at yahoo.co.uk
Mon Jul 23 00:47:49 CEST 2012


On 22/07/2012 23:33, Gregory Lund wrote:
> Only my second try to post to this list.
> This is a dumb question with a simple (I presume) solution...
> but...
> how do I take a txt file with semicolon separated values and create a
> dictionary and a list?
> ( in 2.6 because I'm working with ArcGIS.)
>
> text file is as follows: (saved as text_data.txt) (it's looooonger,
> this is just a sample)
>
> ObjID;Xval;Yval;LineID;PolyID
> 0;1279027.0;246427.9375;0;1
> 1;1279069.625;246433.234375;0;1
> 2;1279091.0;246435.046875;1;1
> 3;1279112.5;246436.3125;1;1
> 4;1279134.0;246437.0;2;1
> 5;1279176.875;246436.71875;2;1
> 6;1279198.375;246435.734375;3;1
> 7;1279219.75;246434.1875;3;1
>
> I'd like to create a list from said text data...
> and a dictionary of dictionaries from said data.
>
> Eventually I will create a point, line and polygon shapefiles from this file.
> With the data above, it would be an 8 point pnt file, a 3 line line
> file and 1 polygon. (point 7 connecting back to point 0)
>
> Right now, I'm just trying to get started by creating a list and a
> dictionary (to see which I want to use when creating my shapefiles.)
>
> And, I need to do it in 2.6 because I'm working with ArcGIS.
>
> Thanks in advance for your thoughts?
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Your starter for 10 is the csv module specifically 
http://docs.python.org/library/csv.html#csv-fmt-params

-- 
Cheers.

Mark Lawrence.



More information about the Tutor mailing list