나는 어디에서나 검색을하고 어디에서나 대답을 찾을 수 없으며, 코드에 문제가 있습니다. 간단한 인벤토리를 사용하려고합니다. peewee. 이 오류가 있습니다.들여 쓰기를 처리하는 방법 들여 쓰기 : 들여 쓰기가 바깥 쪽 들여 쓰기 레벨과 일치하지 않습니다.
File "inventario.py", line 38
if selection =='1':
^
IndentationError: unindent does not match any outer indentation level
공백이 섞여있는 탭을 읽었을 때 이미 확인했는데 도구를 사용해도 SublimeText는 탭으로 공백을 넣어야합니다.
from peewee import *
db = SqliteDatabase('stockpy.db') #creates db
class Product(Model): #data to create product table
id_prod = IntegerField()
name = CharField()
price = IntegerField()
stock = IntegerField()
class Meta:
database = db #tells which db to use
Product.create_table() #creates table
def newProd(id_prod, name, price, stock):
Product.create(id_prod = id_prod, name = name, price = price, stock = stock) #adds new product with input
def deleteProd(name): #Deletes de product with the given name
todelete = Product.get(Product.name == name)
todelete.delete_instance()
def viewStock():
for name in Product.select(): #shows whats in the table
print Product.id_prod, Product.name, Product.price, Product.stock
menu = {} #simple menu
menu['1']="Add product."
menu['2']="Delete product."
menu['3']="View stock"
menu['4']="Exit"
while True:
options=menu.keys()
options.sort()
for entry in options:
print entry, menu[entry]
selection=raw_input("Please Select:")
if selection =='1':
print "Need the following data:"
id_prod = raw_input("Product id: ")
int(id_prod)
name = raw_input("Product name: ")
price = raw_input("Product price: ")
int(price)
stock = raw_input ("How many are there: ")
int(stock)
print "You're adding the following data", id_prod, name, price, stock
newProd()
elif selection == '2':
name = raw_input ("Enter the name of the product you want to delete: ")
deleteProd(name)
elif selection == '3':
print "Here's your stock"
viewStock()
elif selection == '4':
print "Goodbye"
break
else:
print "Unknown Option Selected!"
도움이나 힌트를 주시면 감사하겠습니다. 미리 감사드립니다.
들여 쓰기가 완전히 엉망입니다. –
'옵션에있는 입력 :'앞에는 공백이 두 개 있습니다. 'selection == '1':'은 세 개가 있습니다. – senshin
'options in entry'에 2 탭, 다음 라인에 6 탭?! 코드의 들여 쓰기를 규칙 성을 닮은 것으로 고치십시오. – inspectorG4dget