dynamic insert using mysql and csv file

I am learning python....I am trying to load a csv file into mysql. I am getting the below error. can someone please help?

   ordinal code:
   import csv
   import sqlalchemy




  NULL_FIELD_VALUE = r'\N'
  file_name = "C:/105AML11232020.txt"
  tbl_name="aml_master"

  engine = sqlalchemy.create_engine('mysql+mysqlconnector://root:xxxxx@localhost:3306/test',
                              connect_args={'auth_plugin': 'mysql_native_password'})
  connection = engine.connect()
  with open(file_name) as csvfile: 
      reader = csv.DictReader(csvfile, delimiter='|')

      insert_table = table(tbl_name,*[column(field) for field in reader.fieldnames])
      insert_dict = [{k: None if v == NULL_FIELD_VALUE else v for k,v in row.items()} for row in reader]
      connection.execute(insert_table.insert(), insert_dict)

Error:

 insert_dict = [{k: None if v == NULL_FIELD_VALUE else v for k,v in row.items()} for row in reader] ^ 
 IndentationError: unindent does not match any outer indentation level



from Recent Questions - Stack Overflow https://ift.tt/3l9VgW4
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations