どこでも検索しましたが、答えがどこにも見つかりません。コードに問題がありました。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!"
どんな助けやヒントも大歓迎です。前もって感謝します。