【发布时间】:2023-03-31 05:15:01
【问题描述】:
我的 html 由名字、姓氏、年龄和性别组成。我正在从中取出值并希望将这些值写入文件中。但是我收到 IOError: Bad file descriptor 的错误。
在我的 html 页面上,点击提交时,我调用了这个 test.py,它应该将数据写入文件名“copy.txt”
我的 test.py 代码:
#!/usr/bin/python
import cgi
print "Content- type : text/html\n"
form = cgi.FieldStorage()
Fname = form.getvalue('firstname')
Lname = form.getvalue('lastname')
Age = form.getvalue('age')
Gender = form.getvalue('gender')
f = open("copy","w")
for data in f:
f.write("Fname")
f.write("Lname")
f.write("age")
f.write("gender")
f.close()
错误:
Traceback (most recent call last):
File "test.py", line 16, in <module>
for data in f:
IOError: [Errno 9] Bad file descriptor
【问题讨论】:
-
你必须使用
f = open("copy.txt","w") -
@GamesBrainiac:在上述链接中找不到解决方案
-
@GamesBrainiac:你能租用帮助吗?我不明白上面的链接