gpt4 book ai didi

python - 类型错误 : 'encoding' is an invalid keyword argument for this function

转载 作者:行者123 更新时间:2023-12-03 01:35:57 28 4
gpt4 key购买 nike

我的 python 程序无法打开文本文件。当我使用基本打开文件进行读取时,出现 ascii 错误。有人帮助我添加了一个在空闲状态下运行良好的编码参数,但是当我通过终端运行程序时,我收到此错误消息:“TypeError:'encoding'是此函数的无效关键字参数”我该怎么办读取此文本文件以使用其数据?

try:
import tkinter as tk
from tkinter import *
except:
import Tkinter as tk
from Tkinter import *

import time
import sys
import os
import random

flashcards = {}


def Flashcards(key, trans, PoS):
if not key in flashcards:
flashcards[key] = [[trans], [PoS]]
else:
x = []
for item in flashcards[key][0]:
x.append(item)
x.append(trans)
flashcards[key][0] = x
x = []
for item in flashcards[key][1]:
x.append(item)
x.append(PoS)
flashcards[key][1] = x


def ImportGaeilge():
flashcards = {}
with open('gaeilge_flashcard_mode.txt','r', encoding='utf8') as file:
for line in file:
line1 = line.rstrip().split("=")
key = line1[0]
trans = line1[1]
PoS = line1[2]
Flashcards(key, trans, PoS)

def Gaeilge():
numberCorrect = 0
totalCards = 0
ImportGaeilge()
wrongCards = {}
x = input('Hit "ENTER" to begin. (Type "quit" to quit)')
while x != quit:
os.system('cls')
time.sleep(1.3)
card = flashcards.popitem()
if card == "":
## WRONG CARDS
print ("Deck one complete.")
Gaeilge()
print("\n\n")
print(str(card[0])+":")
x = input("\t:")
if x == 'quit':
break
else:
right = False
for item in card[1]:
if x == card[1]:
right = True
print("\nCorrect!")
numberCorrect += 1
if right == False:
print(card[0])

totalCards += 1
print("Correct answers:", str(numberCorrect) +"/"+str(totalCards))


Gaeilge()

gaeilge_flashcard_mode.txt:

I=mé=(pron) (emphatic)
I=mise=(n/a)
you=tú=(pron) (subject)
you=tusa=(emphatic)
y'all=sibh=(plural)
y'all=sibhse=(emphatic)
he=sé=(pron)
he=é=(n/a)
he=seisean=(emphatic)
he=eisean=(n/a)
she=sí=(pron)
she=í=(n/a)
she=sise=(emphatic)
she=ise=(emphatic)
him=é=(pron)
him=eisean=(emphatic)
her=í=(pron)
her=ise=(emphatic)
her=a=(adj)

最佳答案

您尝试运行此程序的终端可能使用 Python 2.x 作为标准。

尝试在终端中专门使用命令“Python3”:

$ Python3 yourfile.py

(经过测试并确认 2.7 会给出该错误,而 Python3 可以很好地处理它。)

关于python - 类型错误 : 'encoding' is an invalid keyword argument for this function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12541370/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com