Reputation: 1056
Specifically I want to know which properties are available on myFile
in the following code sample:
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
This is taken from the CherryPy file upload example, and it shows a couple of the properties available in the documentation. Namely file
, filename
, content_type
But how can I determine all the properties, or better what the actual type is so I can open the source and read the properties?
Upvotes: 1
Views: 121
Reputation: 6881
The type can be obtained with type(myFile)
. You can use inspect
module or myFile.__dict__
to see properties.
If you want to see the source code, use type(myFile).__module__
to see where it is defined.
Upvotes: 2