简体   繁体   English

Python中奇怪的意外缩进错误

[英]Odd unexpected indent error in Python

I know there's many questions with the same title, but non like my problem. 我知道有很多标题相同的问题,但与我的问题不同。

I'm trying to use a class from a another script on a new script, but I get an indent error on the same line I'm importing the script. 我正在尝试在新脚本上使用另一个脚本中的类,但是在导入脚本的同一行上出现了缩进错误。 It's odd cause there's no indentation or spaces and I've checked. 奇怪的是,没有缩进或空格,我已经检查过了。 Backspaced many time and nothing. 退格很多时间,什么也没有。 Here's the .py where I'm importing the class: 这是我要导入类的.py

from logInScreen import checkValidation #the undexpected indent is on this line


class hello:

    cv = checkValidation()

    def show(self):

        print(self.cv.user)

h = hello()

h.show()

THIS IS JUST AN EXAMPLE! 这只是一个例子! I named the hello class differently. 我用不同的方式命名了hello类。

This is a bit of the class I'm trying to import from another .py . 这是我尝试从另一个.py导入的类的一部分。 I'll show just before the 1st method cause That's all I'm using. 我将在第一种方法之前演示,因为这就是我正在使用的全部。

class checkValidation:

    fail = 0

    user = "name"

    password = "1234"

Here's I picture of the error: 这是错误的图片:

在此处输入图片说明

I know it sounds stupid, but I can't seems to find a way to fix it. 我知道这听起来很愚蠢,但是我似乎找不到解决它的方法。 I made sure both scripts are on the same folder. 我确保两个脚本都在同一文件夹中。

Your problem has nothing to do with any of the code you've posted. 您的问题与您发布的任何代码无关。 The traceback shows that on line 61 of logInScreen.py , the line 追溯显示在logInScreen.py第61行上

os.system("mainPage3.py 1")

is indented more than it should be. 缩进超过应有的程度。 Take a look at that line and the lines surrounding it, and figure out what level it should be indented to. 看一看那条线及其周围的线,找出应该缩进的高度。

If the indentation looks fine, see if you're mixing tabs and spaces. 如果缩进看起来不错,请查看您是否混用了制表符和空格。 If you are, convert the tabs to spaces. 如果是这样,将选项卡转换为空格。 Python handles tabs like Notepad does, as enough spaces to reach the next 8-space indentation level. Python会像记事本一样处理选项卡,因为足够的空间可以达到下一个8位缩进级别。 That is almost certainly not what you were expecting. 几乎可以肯定这不是您所期望的。

61行有5个空格,而不是4个空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM