Pycharm – die besten Beiträge

Python Code testen

Ich habe einen Python code geschrieben und würde mich über ehrliche tester freuen

import os
#os.system('cls' if os.name == 'nt' else 'clear')
liste = []
def addToClipBoard(text):
    with open("temp_clipboard.txt", "w", encoding="utf-8") as f:
        f.write(text)
    os.system("type temp_clipboard.txt | clip")
    os.remove("temp_clipboard.txt")
def hinzufügen():
    produkt = input("Welches Produkt möchten sie hinzufügen ")
    anzahl = int(input(f"Wie oft möchten sie {produkt} kaufen "))
    add = [str(produkt), str(anzahl)]
    liste.append(add)
def anzeigen():
    for i in range(0, len(liste)):
        print(liste[i][0], liste[i][1])
def entfernen():
    print("Welches Produkt möchten sie entfernen ")
    for i in range(0, len(liste)):
        print(f"{i + 1}: ",liste[i][0], liste[i][1])
    auswahl = int(input("")) - 1
    os.system('cls' if os.name == 'nt' else 'clear')
    print("Produkt wurde entfernt!")
    del liste[auswahl]

while True:
    auswahl = int(input("1: Produkt hinzufügen \n2: Produkt entfernen \n3: Liste anzeigen \n4: Liste leeren \n5: Liste kopieren\n"))
    os.system('cls' if os.name == 'nt' else 'clear')

    if auswahl == 1:
        try:
            hinzufügen()
        except ValueError:
            print("Fehler!")
            continue
    elif auswahl == 2:
        try:
            entfernen()
        except IndexError:
            print("Fehler!")
            continue
    elif auswahl == 3:
        anzeigen()
        if liste == []:
            print("Deine Einkaufsliste ist leer")
            continue
    elif auswahl == 4:
        liste = []
        print("Liste wurde geleert!")
    elif auswahl == 5:
        outlist = str(liste)
        outlist = "\n".join([f"{produkt}: {anzahl}" for produkt, anzahl in liste])

        print("Liste wurde in die Zwischenablage kopiert")
        addToClipBoard(str(outlist))

Schreibt gerne eure meinung und startet das Programm im Terminal

Code, Programmiersprache, Python, Pycharm

Python discord NonType Error?

Ich habe einen Error in meinem Code:

async def on_submit(self, interaction2: discord.Interaction):
    response = await sendRequests(str(self.username), str(self.email), str(self.password))
    if response == "email":
        await interaction2.response.send_message("Incorrect email format", ephemeral=True)
        return
    if response == "password":
        await interaction2.response.send_message("Incorrect password format. The password must meet these requirements: \nOne Uppercase letter \nOne lowercase letter \nOne number\n A special character ", ephemeral=True)
        return
    if response == "maintenance":
        await interaction2.response.send_message("The system is currently under maintenance. Please look in #news for more infos.", ephemeral=True)
    query = "INSERT INTO users VALUES (?, ?, ?, ?)"
    main.cursor.execute(query, (interaction2.user.id, str(self.username), str(self.email), str(self.password)))
    main.database.commit()
    await interaction2.response.send_message("You are now in the registration process. This can take up to one hour.", ephemeral=True)
    channel = main.bot.get_channel(1309925591146958933)
    await channel.send("make a recaptcha, registration from user : " + str(interaction2.user.name) + " with id: " + str(interaction2.user.id))

Error:
[2024-11-23 19:32:43] [ERROR  ] discord.ui.modal: Ignoring exception in modal <RegisterModal timeout=None children=3>:

Traceback (most recent call last):

 File ".venv\Lib\site-packages\discord\ui\modal.py", line 189, in _scheduled_task

   await self.on_submit(interaction)

 File "TestButton.py", line 41, in on_submit

   await channel.send("make a recaptcha, registration from user : " + str(interaction2.user.name) + " with id: " + str(interaction2.user.id))

         ^^^^^^^^^^^^

AttributeError: 'NoneType' object has no attribute 'send'

Bot, Code, Programmiersprache, Python, Webentwicklung, Python 3, Pycharm, Discord, Discord Bot

Meistgelesene Beiträge zum Thema Pycharm