0

My code:

import csv

def  searchProxy():

     csv_file = csv.reader(open ('C:/Users/Keanu/Documents/CSV/07-12-report.csv', 'r'))
     cardIdentifier = input('Enter proxy')

     for row CardIdentifier in csv_file:
         if Card Identifier == row[0]:
             print(row)

print ('Enter to search card identifier')
src = int(input ("Enter here: "))

I'm getting this SyntaxError:

File "C:\Users\Keanu\Documents\PythonProjects\main.py", line 8
    for row CardIdentifier in csv_file:
            ^
SyntaxError: invalid syntax
Process finished with exit code 1

CardIdentifier is the name of a column in my csv file, and I'm search through each row. What could be causing the error?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • You can not spaces in your variable names. – Klaus D. Jul 16 '21 at 18:44
  • I highly recommend programming in an IDE, like the free one PyCharm, so that it'll tell you about errors long before you even run the script. If you're not already doing that. – Random Davis Jul 16 '21 at 18:46
  • Using a IDE isn't going to help if you don't know the language or read the documentation. `for row CardIdentifier in csv_file:` ***is*** syntactically incorrect. I suggest you review the documentation on the [`for`](https://docs.python.org/3/reference/compound_stmts.html#the-for-statement) statement as well on that of the [`csv.reader`](https://docs.python.org/3/library/csv.html#csv.reader). – martineau Jul 16 '21 at 19:18
  • P.S. You're not even opening the CSV file properly — see the example in the documentation. – martineau Jul 16 '21 at 19:26

2 Answers2

0

You can try this:

def searchProxy():
     csv_file = csv.reader(open ('C:/Users/Keanu/Documents/CSV/07-12-report.csv', 'r'))
     cardIdentifier = input('Enter proxy')
     for row in csv_file:
         if cardIdentifier == row[0]: #I don't think row[0] as well I think it is row only
             print(row)

You aren't supposed to use space between variable name! You have so, many typos errors in your code as well.

You had wrote somewhere cardIdentifier and somewhere CardIdentifier which is completely different thing. Just remember main/one things, you can't give space in variable name, like test csv you can either do test_csv or testcsv, But not space!

imxitiz
  • 3,920
  • 3
  • 9
  • 33
0

You shouldn't have the variable CardIdentifier on the for row line.

You miswrote the variable name on the next line. The first letter is c, not C, and you added a space in it.

You also didn't indent the if line correctly.

     for row in csv_file:
        if cardIdentifier == row[0]:
            print(row)
Barmar
  • 741,623
  • 53
  • 500
  • 612