Python 属性错误:';str';对象没有属性';公司';
我想不出来。我想我对如何调用对象是错的。 表面上看,对象不称为公司名称 客户注册后,选择2进入子菜单显示客户列表, 然后写下客户名称以显示有关特定客户的更多信息Python 属性错误:';str';对象没有属性';公司';,python,class,oop,object,Python,Class,Oop,Object,我想不出来。我想我对如何调用对象是错的。 表面上看,对象不称为公司名称 客户注册后,选择2进入子菜单显示客户列表, 然后写下客户名称以显示有关特定客户的更多信息 # APP REVOLUTIO SOLUTIONS - OverView ARS v1.0 class OVARS: def __init__(self, company, kNr, adr, tlf, sp, app, appV, date, afd, ini): self.company = com
# APP REVOLUTIO SOLUTIONS - OverView ARS v1.0
class OVARS:
def __init__(self, company, kNr, adr, tlf, sp, app, appV, date, afd, ini):
self.company = company
self.kNr = kNr
self.adr = adr
self.tlf = tlf
self.sp = sp
self.app = app
self.appV = appV
self.date = date
self.afd = afd
self.ini = ini
class udskriv(OVARS):
def __init__(self):
super(OVARS, self).__init__()
def udskriv_kunde(self, cuna):
print(cuna.company)
print(cuna.kNr)
print(cuna.adr)
print(cuna.tlf)
print(cuna.sp)
print(cuna.app)
print(cuna.appV)
print(cuna.date)
print(cuna.afd)
print(cuna.ini)
######################## PROGRAM START ########################
udskrivKALD = udskriv()
print('OverView ARS v1.0')
customerList = []
i = 0
while True:
try:
menuChoice = int(input('''
1. apply new customer
2. show existing customers
3. exit
\n'''))
except ValueError:
print('choice not accepted.\n')
continue
print()
if menuChoice == 1:
addCompanyName = input('enter company name: ')
addKundeNr = input('enter customer ID.: ')
addAdresse = input('enter address: ')
addTelefon = input('enter telephone nr.: ')
addSP = input('enter Servicepackage: ')
addApp = input('enter app: ')
addAppV = input('enter App version: ')
addDate = input('enter Date: ')
addAfd = input('enter department: ')
addIni = input('enter Inititials: ')
customerList.append(addCompanyName)
print('\ncustomer registered: ' + str(addCompanyName) + '\n')
newCustomer = addCompanyName
newCustomer = OVARS(addCompanyName, addKundeNr, addAdresse, addTelefon, addSP, addApp, addAppV, addDate, addAfd, addIni)
continue
elif menuChoice == 2:
i = 0
j = 0
k = 1
for i in customerList:
print(str(k) + ': ' + customerList[j])
j += 1
k += 1
subMenu2Choice = input('''
choose customer to show customer information,
or choose 0 to go back to first menu
\n''')
if subMenu2Choice == 0:
continue
elif subMenu2Choice in customerList:
udskrivKALD.udskriv_kunde(subMenu2Choice)
else:
print('wrong choice')
continue
elif menuChoice == 3: # Exiting Program
break
else:
print('choice not accepted.\n')
continue
#udskrivKALD.udskriv_kunde(newCustomer)
print()
# END OF PROGRAM
请帮助D:
更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情更多详情这里有一个快速解决方案:
正如注释中已经提到的,您正试图将字符串传递给需要特定对象的函数。您可以使用customerList
存储所有创建的对象,而不仅仅是company
属性:
customerList.append(新客户)
对于show existing customers修复,请使用以下代码段:
elif any(i.company==subMenu2Choice for i in customerList):
for i in customerList:
if i.company==subMenu2Choice:udskrivKALD.udskriv_kunde(i)
代码:
udskriv_kunde
需要一个OVARS
实例(cuna
),但您传递的是一个字符串:udskrivKALD.udskriv_kunde(subMenu2Choice)
(subMenu2Choice=input(…
)。我知道,我的目的是让您看到一个客户列表,然后在输入中写入客户名称,但是当registeredIt应该工作时,对象永远不会使用客户名称创建。只需在子菜单选项2中输入companyName字符串。哦,等等,您想输入条目的id还是公司名称来获取信息,??我当前的代码需要字符串。
# APP REVOLUTIO SOLUTIONS - OverView ARS v1.0
class OVARS:
def __init__(self, company, kNr, adr, tlf, sp, app, appV, date, afd, ini):
self.company = company
self.kNr = kNr
self.adr = adr
self.tlf = tlf
self.sp = sp
self.app = app
self.appV = appV
self.date = date
self.afd = afd
self.ini = ini
class udskriv(OVARS):
def __init__(self):
super(OVARS, self).__init__()
def udskriv_kunde(self, cuna):
print(cuna.company)
print(cuna.kNr)
print(cuna.adr)
print(cuna.tlf)
print(cuna.sp)
print(cuna.app)
print(cuna.appV)
print(cuna.date)
print(cuna.afd)
print(cuna.ini)
######################## PROGRAM START ########################
udskrivKALD = udskriv()
print('OverView ARS v1.0')
customerList = []
i = 0
while True:
try:
menuChoice = int(input('''
1. apply new customer
2. show existing customers
3. exit
\n'''))
except ValueError:
print('choice not accepted.\n')
continue
print()
if menuChoice == 1:
addCompanyName = input('enter company name: ')
addKundeNr = input('enter customer ID.: ')
addAdresse = input('enter address: ')
addTelefon = input('enter telephone nr.: ')
addSP = input('enter Servicepackage: ')
addApp = input('enter app: ')
addAppV = input('enter App version: ')
addDate = input('enter Date: ')
addAfd = input('enter department: ')
addIni = input('enter Inititials: ')
print('\ncustomer registered: ' + str(addCompanyName) + '\n')
newCustomer = addCompanyName
newCustomer = OVARS(addCompanyName, addKundeNr, addAdresse, addTelefon, addSP, addApp, addAppV, addDate, addAfd, addIni)
customerList.append(newCustomer)
continue
elif menuChoice == 2:
i = 0
j = 0
k = 1
for i in customerList:
print(str(k) + ': ' + customerList[j].company)
j += 1
k += 1
subMenu2Choice = input('''
choose customer to show customer information,
or choose 0 to go back to first menu
\n''')
if subMenu2Choice == 0:
continue
elif any(i.company==subMenu2Choice for i in customerList):
for i in customerList:
if i.company==subMenu2Choice:udskrivKALD.udskriv_kunde(i)
else:
print('wrong choice')
continue
elif menuChoice == 3: # Exiting Program
break
else:
print('choice not accepted.\n')
continue
#udskrivKALD.udskriv_kunde(newCustomer)
print()
# END OF PROGRAM