Python IndentationError:应为缩进块(涉及类的异常缩进错误)

2024-09-27 21:29:56 发布

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

在尝试开发一个类时,我遇到了这个错误。在

from __future__ import division
import numpy as np
import scipy as sp
import itertools as it
from scipy.integrate import quad
import astropy.cosmology
from astropy import units as u

class NFW:  

File "/Users/alexandres/Illustris/Scripts/NFWprofile2.py", line 10

               ^
IndentationError: expected an indented block
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/Users/alexandres/Illustris/Scripts/NFWprofile2.py"]
[dir: /Users/alexandres/Illustris/Scripts]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

这怎么会是缩进错误?在

不管我是将类定义为NFW()还是NFW(object),都会发生这种情况。在

这是正在编辑的崇高3


Tags: frompyimportbinusras错误scripts
2条回答

如果这是您的整个文件,则缺少所需的类主体。您可以使用pass语句创建空正文:

class NFW:  
    pass

发生错误是因为您有一个块中没有语句。在

也就是说,class NFW是空的。在

为了创建一个最小的类

class MyEmptyClass:
        pass

对你来说

^{pr2}$

pass语句什么也不做。当语法上需要语句但程序不需要操作时,可以使用它。在

相关问题 更多 >

    热门问题