Error – die besten Beiträge

TypeError bei Python-Programm?

Ich habe folgendes Programm:

import itertools

# Daten aus der Tabelle einlesen
data = []
with open('tour1.txt', 'r') as file:
    for line in file:
        parts = line.strip().split(',')
        data.append((parts[0], int(parts[1]), parts[2] == 'X'))

# Essentielle Tourpunkte auswählen
essential_points = [place for place, year, is_essential in data if is_essential]

# Funktion zur Berechnung der Teiltour
def calculate_tour(places, essential_places):
    min_distance = float('inf')
    min_tour = None

    for perm in itertools.permutations(essential_places):
        tour = [places[0][0]] + [places[i][0] for i in perm] + [places[0][0]]
        total_distance = 0

        for i in range(len(tour) - 1):
            total_distance += abs([x[1] for x in places if x[0] == tour[i]][0] - [x[1] for x in places if x[0] == tour[i + 1]][0])

        if total_distance < min_distance:
            min_distance = total_distance
            min_tour = tour

    return min_tour

# Sortieren der Orte nach ihrem Jahr
sorted_data = sorted(data, key=lambda x: x[1])

# Die Teiltour berechnen
shortest_tour = calculate_tour(sorted_data, essential_points)

# Ergebnis ausgeben
for point in shortest_tour:
    print(point, end=" -> ")
print(shortest_tour[0])  # Zum Startpunkt zurückkehren

Beim Ausführen wird mir folgender Fehler ausgegeben: TypeError: list indices must be integers or slices, not str

Die Textdatei ist nach dem Format "Brauerei,1613,X,0" (als Beispiel) aufgebaut.
Ich habe probiert das Problem durch ein voranstellen von Int() bei den Listen zu Lösen, was nicht funktioniert hat...
Gibt es eine andere Möglichkeit zur Lösung?

Vielen Dank!

Error, Programmiersprache, Python

Error bei Elegoo RFID-RC522-Sensor?

Hallo,

ich versuche von meinem Elegoo Uno R3 auf dem RFID-RC522 meinen NFC-Tag auszulesen, aber es kommt nur der folgende Error:

Card UID: BC FD E1 37
Failed to authenticate to card for reading, could not set UID: 
Timeout in communication.
New UID and contents:
Card UID: BC FD E1 37
Card SAK: 08
PICC type: MIFARE 1KB
Sector Block  0 1 2 3  4 5 6 7  8 9 10 11 12 13 14 15 AccessBits
 15   63 PCD_Authenticate() failed: Timeout in communication.
 14   59 PCD_Authenticate() failed: Timeout in communication.
 13   55 PCD_Authenticate() failed: Timeout in communication.
 12   51 PCD_Authenticate() failed: Timeout in communication.
 11   47 PCD_Authenticate() failed: Timeout in communication.
 10   43 PCD_Authenticate() failed: Timeout in communication.
  9   39 PCD_Authenticate() failed: Timeout in communication.
  8   35 PCD_Authenticate() failed: Timeout in communication.
  7   31 PCD_Authenticate() failed: Timeout in communication.
  6   27 PCD_Authenticate() failed: Timeout in communication.
  5   23 PCD_Authenticate() failed: Timeout in communication.
  4   19 PCD_Authenticate() failed: Timeout in communication.
  3   15 PCD_Authenticate() failed: Timeout in communication.
  2   11 PCD_Authenticate() failed: Timeout in communication.
  1   7 PCD_Authenticate() failed: Timeout in communication.
  0   3 PCD_Authenticate() failed: Timeout in communication.

Liegt es daran, dass ich den Tag schon mal beschrieben habe? Und wie kann ich das Problem lösen?

LG

Error, RFID, NFC, NFC-Tag, Elegoo

Meistgelesene Beiträge zum Thema Error