Python类/非类型
我有以下python函数:Python类/非类型,python,jython,nonetype,Python,Jython,Nonetype,我有以下python函数: def run(value, args): offset = args[0] return offset.asInt() 如果我返回type(offset)我会得到一个类名org.python.core.PyInteger。此类具有类似于asInt(),getValue()。。。(这是一个Jython类)但每次我调用一个方法时,都会得到一个错误: NoneType object has no attribute .... 完整错误消息: javax
def run(value, args):
offset = args[0]
return offset.asInt()
如果我返回type(offset)
我会得到一个类名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(“路径文件”,“r”)
data=readFile.read()
打印(类型(数据))
因为,让文件保持打开状态是不好的做法,我将使用close方法通过执行以下操作来关闭:
data = readFile.close()
print(data)
None
print(type(data))
<class 'NoneType'>
data=readFile.close()
打印(数据)
没有一个
打印(类型(数据))
请注意,类类型现在是“NoneType”,因为自从我使用close方法以来,变量数据中没有任何内容可以读取?那么哪一行抛出异常?你真的应该包括完整的回溯,而不仅仅是异常行。你能编写并发布一个复制同样错误的小程序吗?
data = readFile.close()
print(data)
None
print(type(data))
<class 'NoneType'>