TypeError: open() missing required argument 'file' (pos 1)
Question:
I try to publish a sample question on mturk using Python, so I follow the tutorial and copy their code like follows. However, I always get an Error like:
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)")
Answers:
The first arguemnt to python open()
function is file
. So change this
question = open(name='questions.xml',mode='r').read()
to
question = open(file='questions.xml',mode='r').read()
or simply
question = open('questions.xml',mode='r').read()
You can also try: With with
keyword your file with be normally closed. Saving you from memory leak
with open('questions.xml','r') as fp:
myXMLfile=fp.read()
I try to publish a sample question on mturk using Python, so I follow the tutorial and copy their code like follows. However, I always get an Error like:
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)")
The first arguemnt to python open()
function is file
. So change this
question = open(name='questions.xml',mode='r').read()
to
question = open(file='questions.xml',mode='r').read()
or simply
question = open('questions.xml',mode='r').read()
You can also try: With with
keyword your file with be normally closed. Saving you from memory leak
with open('questions.xml','r') as fp:
myXMLfile=fp.read()