具体来说,我想知道以下代码示例中的myFile
上有哪些属性可用:
def upload(self, myFile):
out = """<html>
<body>
myFile length: %s<br />
myFile filename: %s<br />
myFile mime-type: %s
</body>
</html>"""
# Although this just counts the file length, it demonstrates
# how to read large files in chunks instead of all at once.
# CherryPy reads the uploaded file into a temporary file;
# myFile.file.read reads from that.
size = 0
while True:
data = myFile.file.read(8192)
if not data:
break
size += len(data)
return out % (size, myFile.filename, myFile.content_type)
upload.exposed = True
这是来自CherryPy文件上传示例的,它显示了文档中提供的几个属性。即file
、filename
、content_type
但是如何确定所有属性,或者更好地确定实际类型,以便打开源代码并读取属性?你知道吗
类型可以通过
type(myFile)
获得。您可以使用inspect
模块或myFile.__dict__
查看属性。你知道吗如果您想查看源代码,请使用
type(myFile).__module__
查看它的定义位置。你知道吗相关问题 更多 >
编程相关推荐