Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python类/非类型_Python_Jython_Nonetype - Fatal编程技术网

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

我有以下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.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'>