[Python] Error from Pycharm: Expected type 'SupportsIndex | slice', got 'str' instead

Discussão em 'Python' iniciado por Stack, Março 10, 2025.

  1. Stack

    Stack Membro Participativo

    My input file, infile is as follows:

    NUMBER,SYMBOL
    1,AAPL
    2,MSFT
    3,NVDA


    Here is my code:

    import csv

    infile = "stock-symbols-nasdaq-SO.csv"

    with open(infile, encoding='utf-8') as csvfile:
    reader = csv.DictReader(csvfile) # Read CSV as a dictionary
    for row in reader:
    print(row)
    symbol = row['SYMBOL'] # Error from Pycharm: Expected type 'SupportsIndex | slice', got 'str' instead
    print(symbol)


    This code "appears" to run correctly, but why is Pycharm indicating an error? Is their anything that I can do to remove it?

    Continue reading...

Compartilhe esta Página