Saturday 15 February 2014

python - Populating a model from csv: __init__ arguments error -


I have a large number of columns that should be populated with a CSV file. I have the following __ init __ code inside the definition of the model

  class table column 1 = ............ column 2 = ............. ....... def __init__ (Self, ** kwargs): self .__ dict __. Update (kwargs)   

is the code to read from the csv file (load_csv.py)

  in the csv_file line for data_file = "data.csv" Csv_file = csv.DictReader (open (data_file, 'ru'), delimiter = ','): table_entries = {} in row, value in row.items (): table_entries [key] = value table_row = table_entries Db.session.add (table_row) db.session.commit ()   

I get an error in loading load_csv.py

  table_row = table ( Table_entries) TypeError: __init __ () takes exactly 1 argument (2 given)   

I have read because it is using the default __ init__ But I can not see how this code is defined in the __init __ function I. Any help in solving this problem would be greatly appreciated.

You want to apply the dictionary as a keyword argument:

 < Code> table_row = To get a table, replace the table (** table_entries)   

or your table () class:

 < Code> class table def __int __ (self, line): auto_dial dial__. Update (line)    

No comments:

Post a Comment