gpt4 book ai didi

python - 类型错误 : open() missing required argument 'file' (pos 1)

转载 作者:太空宇宙 更新时间:2023-11-03 21:30:35 25 4
gpt4 key购买 nike

我尝试使用 Python 在 mturk 上发布示例问题,因此我按照教程并复制其代码,如下所示。但是,我总是收到如下错误:

File "C:/Users/jingh/PycharmProjects/test/example.py", line 22, in
<module>
question = open(name='questions.xml',mode='r').read()
TypeError: open() missing required argument 'file' (pos 1)

Process finished with exit code 1
question = open(name='questions.xml',mode='r').read()
new_hit = client.create_hit(
Title = 'Is this Tweet happy, angry, excited, scared, annoyed or upset?',
Description = 'Read this tweet and type out one word to describe the emotion of the person posting it: happy, angry, scared, annoyed or upset',
Keywords = 'text, quick, labeling',
Reward = '0.15',
MaxAssignments = 1,
LifetimeInSeconds = 172800,
AssignmentDurationInSeconds = 600,
AutoApprovalDelayInSeconds = 14400,
Question = question,
)
print ("A new HIT has been created. You can preview it here:")
print ("https://workersandbox.mturk.com/mturk/preview?groupId=" + new_hit['HIT']['HITGroupId'])
print ("HITID = " + new_hit['HIT']['HITId'] + " (Use to Get Results)")

最佳答案

python open() 函数的第一个参数是 file。所以改变这个

question = open(name='questions.xml',mode='r').read()

question = open(file='questions.xml',mode='r').read()

或简单地

question = open('questions.xml',mode='r').read()

关于python - 类型错误 : open() missing required argument 'file' (pos 1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53552734/

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