[英]Python Class / NoneType
我有以下python函数:
def run(value, args):
offset = args[0]
return offset.asInt()
如果返回type(offset)
org.python.core.PyInteger
得到一个ClassName org.python.core.PyInteger
。 此类具有asInt()
, getValue()
,...等方法(这是一个Jython类),但是每次我调用一个方法时,都会出现错误:
NoneType object has no attribute ....
完整的错误消息:
javax.script.ScriptException: AttributeError: "NoneType" object has no attribute "asInt" in script.py at line number 3
我编写了一个简单的程序,将下面的类类型显示为“ str”(字符串类):
readFile = open("PATHtoFile", 'r')
data = readFile.read()
print(type(data))
<class 'str'>
因为,将文件保持打开状态是一种不好的做法,所以我将通过执行以下操作使用close方法关闭文件:
data = readFile.close()
print(data)
None
print(type(data))
<class 'NoneType'>
注意,类类型现在是'NoneType',因为自从我使用close方法以来,变量数据中什么都无法读取?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.