-5

I am getting following error while running below python3 code . Input CSV file has 2 columns which I have to load into oracle table.

Error 1:

 File "csv_package_script_1.py", line 15
    if lines[0] = "":
                    ^
TabError: inconsistent use of tabs and spaces in indentation

Error 2:

IndexError: array index out of range

Code:

import cx_Oracle
import csv
import os 

INPUT_PATH = 'C:\\Users\\leorbts\\Projects\\Recon\\Python_Codes\\ITDate_Python\\data\\incoming\\'
infile     = 'Platform_List.csv'
data_file  = os.path.join(INPUT_PATH, infile)

with open(data_file, "r") as csv_file:
    csv_reader = csv.reader(csv_file, delimiter='|')
    for lines in csv_reader:
        lines.split(',')
        if lines[0] = "":
           lines[0] = "Not Available'
        if lines[1] = "":`enter code here`
           lines[1] = "Not Available'
        print(lines[0], lines[1])
        db_curr.execute("INSERT INTO CDC_STG_TBL(TechStakName, ProvisionDate) VALUES ( :1, :2 )", (lines[0], lines[1]))
db_curr.close()
db_conn_str.commit()
db_conn_str.close()
wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • when you begin a quote with `"` you cant end it with `'` . Also comparisons are done with `==`, not `=`. – Ahmet Jul 06 '20 at 21:11
  • Welcome to SO! Check out the [tour]. How are you getting two different errors? Just one should be enough to terminate the program. Anyway, they seem to be unrelated, so I'm voting to close the question as "too broad". Questions should cover only one problem. You also have a syntax error, as amad pointed out. See [ask] for advice. You can [edit] the question. – wjandrea Jul 06 '20 at 21:11

3 Answers3

0

On Line 14, there is no ending speech mark to "Not Available(") <= this is missing

Also look at Line 15, there are some misused speech marks and there as well (back ticks are cannot enclose strings in Python).

I hope this is helpful.

amad
  • 1
0

i fixed some of the errors in proper code formatting, you had mixed up quotations and double quotations, along with mistakes in doing comparison operators. You also forgot to replace lines with the list after the split has occured.

import cx_Oracle
import csv
import os 

INPUT_PATH = 'C:\\Users\\leorbts\\Projects\\Recon\\Python_Codes\\ITDate_Python\\data\\incoming\\'
infile     = 'Platform_List.csv'
data_file  = os.path.join(INPUT_PATH, infile)

with open(data_file, "r") as csv_file:
    csv_reader = csv.reader(csv_file, delimiter='|')
    for lines in csv_reader:
        lines = lines.split(',')
        if lines[0] == "":
           lines[0] = "Not Available"
        if lines[1] == "":
           lines[1] = "Not Available"
        print(lines[0], lines[1])
        db_curr.execute("INSERT INTO CDC_STG_TBL(TechStakName, ProvisionDate) VALUES ( :1, :2 )", (lines[0], lines[1]))
db_curr.close()
db_conn_str.commit()
db_conn_str.close()
0

In python if statements, you need to write it like this;

if lines[0] == "":

This might help you: https://realpython.com/python-conditional-statements/