Sunday 15 June 2014

Assigning a fieldname to a variable in Python -


I'm new to Python and I'm trying to check the tap in CSV. I'm using a DictReader object with key pair values. I am using key pair values ​​in the loop (km at this frequency) for information.

I go to run the program and it does not like my variable assignment. Here's the error that I'm receiving.

  file "./csvtokml3.py", line 31 latvable = str (line ["lat_degrees"]), longwidth = str (line ["lon_degrees"]) Syntax Error: To Call Can not assign to   

Here is the code for the program.

  #! / Usr / bin / python # # Import csv #Input file name Fname = raw_input ("Enter file name without extension") data = csv.DictReader (open (fname + '.csv'), delimiter = ',' ) # Open the file to be typed. F = Open ('csv2kml.kml', 'w') #km file. F.write ("& lt ;? Xml version = '1.0' encoding = 'UTF-8'? & Gt; \ n") f.write ("& lt; kml xmlns = 'http: //www.opengis. F.write ("document & gt; \ n") f.write ("& lt; name"; + + fname + '.kml'); f.write ("net / kml / 2.2" & gt; \ n " + "& Lt; / name & gt; \ n") for the row in the data: f.write ("placemart> gtk; \ n") f.write ("name & gt;" + Str (line ["station"]) "+ & lt; / name & gt; \ n") ### f.write ("Description", "+ str (line [0]) +" & Lt; / description & gt; \ n ") f.write (" & lt; point & gt; \ n ") # Check nulls for if the Latvian! = Faucet and longevity! = Null: f.write ("& lt; coordinate"; + str (late and long wave = str (line ["lat_degrees"]), longwidth = str (line ["lon_degrees"]) row ["lat_degrees"]) + "Str +" (strings ["lon_degrees"]) "+" & lt; / coordinates & gt; \ n ") f.write (" & lt; / point> \ n ") f.write" & Lt; / placemark & ​​gt; \ n ") f.write (" & lt; / document & gt; \ n ") f.write (" & lt; / kml> \ n ") f.close (Print) "File created." Press "ENTER to exit." Raw_input ()    

Your syntax is incorrect, for yo you: Multiple values ​​for multiple names are optional, for example,

  Latvian, longvariable = str (line ["lat_degrees"]), str (line ["lon_degrees"])   

Two statements have been put in separate rows:

  Latvable = str (line ["lat_degrees"]) longvariable = str (line ["lon_degrees"])  < / Pre> 

You can not combine several assignment statements with the comas Like you tried; Which works in javascript but not in Python.

No comments:

Post a Comment