如何确定python中传递的参数的类型

2024-04-18 23:10:58 发布

您现在位置:Python中文网/ 问答频道 /正文

具体来说,我想知道以下代码示例中的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文件上传示例的,它显示了文档中提供的几个属性。即filefilenamecontent_type

但是如何确定所有属性,或者更好地确定实际类型,以便打开源代码并读取属性?你知道吗


Tags: br示例readdatasize属性htmltype
1条回答
网友
1楼 · 发布于 2024-04-18 23:10:58

类型可以通过type(myFile)获得。您可以使用inspect模块或myFile.__dict__查看属性。你知道吗

如果您想查看源代码,请使用type(myFile).__module__查看它的定义位置。你知道吗

相关问题 更多 >