嵌套类Python和缩进错误

时间:2014-07-22 12:30:36

标签: python class nested indentation

在Python中,我已经创建了几个嵌套类,但是我得到了持续的缩进错误。我觉得缩进没有错,我没有想法。

截至目前的错误是[错误] SyntaxError(!! WHILE IMPORTING !!不匹配的输入' self'期待INDENT(patient.py,第69行))

来自sikuli import *

班级病人():

firstname = ""
middlename
Surname = ""
title = ""
ppsno = ""
gender = ""
testID = ""
birthDate = ""
address1 = ""
address2 = ""
address3 = ""
address4 = ""
town = ""
county = ""
country = ""
email = ""
mobile = ""

#Default Constructor for the class patient
def __init__(
    self, 
    testID, 
    firstname = None, 
    surname = None, 
    gender = None, 
    birthDate = None):


    self.testID = testID
    if (firstname is None): 
        firstname = "Test"             
        self.firstname = firstname        
    if (surname is None): 
        surname = "Patient"
        self.surname = surname        
    if (gender is None): 
        gender = "Male"               
        self.gender = gender        
    if (birthDate is None): 
        birthDate = "08081988"             
        self.birthDate = birthDatename

#Use this to create a patient with more detailed information

def __init__(
    self, 
    testID, 
    firstname = None, 
    middlename = None, 
    surname = None, 
    gender = None, 
    birthDate = None, 
    title = None, 
    ppsno = None, 
    address1 = None, 
    address2 = None, 
    address3 = None, 
    address4 = None, 
    town = None, 
    county = None, 
    country = None, 
    email = None, 
    mobile = None):

    self.testID = testID

    if (firstname is None): 
        firstname = "Sample"             
        self.firstname = firstname        
    if (surname is None): 
        surname = "Patient"               
        self.surname = surname  
    if (middlename is None): 
        middlename = "Mary"             
        self.middlename = middlename
    if (gender is None): 
        gender = "Female"               
        self.gender = gender        
    if (birthDate is None): 
        birthDate = "03091959"             
        self.birthDate = birthDatename
    if (title is None): 
        title = "Mrs"             
        self.title = title
    if (ppsno is None): 
        ppsno = "7445213P"             
        self.ppsno = ppsno           
    if (address1 is None): 
        address1 = "100"             
        self.address1 = address1    
    if (address2 is None): 
        address2 = "Green Glade"             
        self.address1 = address1
    if (address3 is None): 
        address3 = "Pleasent Way"             
        self.address3 = address3
    if (address4 is None): 
        address4 = "Ballybehy"             
        self.address4 = address4
    if (town is None): 
        town = "Abbeyfeale"             
        self.town = town
    if (county is None): 
        county = "Limerick"             
        self.county = county
    if (country is None): 
        country = "Ireland"             
        self.country = country
    if (email is None): 
        email = "supertest69@freewebmail.ie"             
        self.email = email
    if (mobile is None): 
        mobile = "0870563229"             
        self.mobile = mobile

def getStuff(self):
     #return self.stuff

class schemeDetails(): 
    cardNumber = ""
    scheme = ""
    cardNumber = ""
    month = ""
    year = ""
    setSchemeAsDefault = ""

    def __init__(
        self, 
        scheme = None, 
        cardNumber = None, 
        month = None, 
        year = None, 
        setSchemeAsDefault = None ):

        if (scheme is None): 
            scheme = "GM"
            self.scheme = scheme
        if (cardNumber is None): 
            month = "1231456A"
            self.cardNumber = cardNumber
        if (month is None): 
            month = "September"
            self.month = month
        if (year is None): 
            year = "2015"
            self.year = year
        if (setSchemeAsDefault is None): 
            setSchemeAsDefault = "true"
            self.setSchemeAsDefault = setSchemeAsDefault

    def getStuff(self):
        #return self.stuff

#Inner class for creating basic dispenses
class basicDispense():
    drug = ""
    packSize = ""
    dosageSystem = ""
    scheme = ""
    #Constructor for the class basicDispense
    def __init__(
        self, 
        drug = None, 
        packSize = None, 
        dosageSystem = None, 
        scheme = None):

        if (drug is None): 
            drug = "ABBOTT THIN LANCET TYPE C GMS"
            self.drug = drug
        if (packSize is None): 
            packSize = "28"
            self.packSize = packSize
        if (dosageSystem is None): 
            dosageSystem = "MD"
            self.dosageSystem = dosageSystem
        if (scheme is None): 
            scheme = "GM"
            self.scheme = scheme

        def getStuff(self):
            #return self.stuff


    #Inner class of basicDispenses for printing Labels    
    #Constructor for the class Labels       
    class labels():
        def __init__(
            self, 
            testID, 
            printBagLabel = None, 
            printDrugLabel = None):                    

            self.testID = testID
            if (printBagLabel is None): 
                printBagLabel = "false"
                self.drug = drug
            if (printDrugLabel is None): 
                printDrugLabel = "false"
                self.printDrugLabel = printDrugLabel

2 个答案:

答案 0 :(得分:1)

我只看了你的代码,你正在使用空格和23,33,172行应该都是空格而不是制表符。第69-118行都应该用空格缩进。好的,所以你对return语句的评论搞砸了,这段代码编译得很好。你也没有将middleName初始化为任何东西,所以我把它初始化为""。

firstname = ""
middlename = ""
Surname = ""
title = ""
ppsno = ""
gender = ""
testID = ""
birthDate = ""
address1 = ""
address2 = ""
address3 = ""
address4 = ""
town = ""
county = ""
country = ""
email = ""
mobile = ""

#Default Constructor for the class patient
def __init__(
    self,
    testID,
    firstname = None,
    surname = None,
    gender = None,
    birthDate = None):


    self.testID = testID
    if (firstname is None):
        firstname = "Test"
        self.firstname = firstname
    if (surname is None):
        surname = "Patient"
        self.surname = surname
    if (gender is None):
        gender = "Male"
        self.gender = gender
    if (birthDate is None):
        birthDate = "08081988"
        self.birthDate = birthDatename

#Use this to create a patient with more detailed information

def __init__(
    self,
    testID,
    firstname = None,
    middlename = None,
    surname = None,
    gender = None,
    birthDate = None,
    title = None,
    ppsno = None,
    address1 = None,
    address2 = None,
    address3 = None,
    address4 = None,
    town = None,
    county = None,
    country = None,
    email = None,
    mobile = None):

    self.testID = testID

    if (firstname is None):
        firstname = "Sample"
        self.firstname = firstname
    if (surname is None):
        surname = "Patient"
        self.surname = surname
    if (middlename is None):
        middlename = "Mary"
        self.middlename = middlename
    if (gender is None):
        gender = "Female"
        self.gender = gender
    if (birthDate is None):
        birthDate = "03091959"
        self.birthDate = birthDatename
    if (title is None):
        title = "Mrs"
        self.title = title
    if (ppsno is None):
        ppsno = "7445213P"
        self.ppsno = ppsno
    if (address1 is None):
        address1 = "100"
        self.address1 = address1
    if (address2 is None):
        address2 = "Green Glade"
        self.address1 = address1
    if (address3 is None):
        address3 = "Pleasent Way"
        self.address3 = address3
    if (address4 is None):
        address4 = "Ballybehy"
        self.address4 = address4
    if (town is None):
        town = "Abbeyfeale"
        self.town = town
    if (county is None):
        county = "Limerick"
        self.county = county
    if (country is None):
        country = "Ireland"
        self.country = country
    if (email is None):
        email = "supertest69@freewebmail.ie"
        self.email = email
    if (mobile is None):
        mobile = "0870563229"
        self.mobile = mobile

def getStuff(self):
     return self.stuff

class schemeDetails():
    cardNumber = ""
    scheme = ""
    cardNumber = ""
    month = ""
    year = ""
    setSchemeAsDefault = ""

    def __init__(
        self,
        scheme = None,
        cardNumber = None,
        month = None,
        year = None,
        setSchemeAsDefault = None ):

        if (scheme is None):
            scheme = "GM"
            self.scheme = scheme
        if (cardNumber is None):
            month = "1231456A"
            self.cardNumber = cardNumber
        if (month is None):
            month = "September"
            self.month = month
        if (year is None):
            year = "2015"
            self.year = year
        if (setSchemeAsDefault is None):
            setSchemeAsDefault = "true"
            self.setSchemeAsDefault = setSchemeAsDefault

    def getStuff(self):
        return self.stuff

#Inner class for creating basic dispenses
class basicDispense():
    drug = ""
    packSize = ""
    dosageSystem = ""
    scheme = ""
    #Constructor for the class basicDispense
    def __init__(
        self,
        drug = None,
        packSize = None,
        dosageSystem = None,
        scheme = None):

        if (drug is None):
            drug = "ABBOTT THIN LANCET TYPE C GMS"
            self.drug = drug
        if (packSize is None):
            packSize = "28"
            self.packSize = packSize
        if (dosageSystem is None):
            dosageSystem = "MD"
            self.dosageSystem = dosageSystem
        if (scheme is None):
            scheme = "GM"
            self.scheme = scheme

        def getStuff(self):
            return self.stuff


    #Inner class of basicDispenses for printing Labels
    #Constructor for the class Labels
    class labels():
        def __init__(
            self,
            testID,
            printBagLabel = None,
            printDrugLabel = None):

            self.testID = testID
            if (printBagLabel is None):
                printBagLabel = "false"
                self.drug = drug
            if (printDrugLabel is None):
                printDrugLabel = "false"
                self.printDrugLabel = printDrugLabel

答案 1 :(得分:0)

打开文件,按Ctrl + A,转到菜单Edit -> Blank Operations -> TAB to space,然后修复所有文字,并将标识更改为空格。

在这种情况下,Sublime Text更加一致。