Problem: Ich habe Probleme beim Aufrufen von Klassen in einem Programm.Python: Problem beim Importieren der Klassendefinition von einer .py in eine andere
Ich habe ein Programm mit dem Namen example.py, die den folgenden Code hat:
class ExampleBase:
"""
This is the ExampleBase class
"""
def __init__(self, company_name="N/A", stock_dict={}):
"""
class constructor
"""
self.company_name = company_name
self.stock_dict = stock_dict
return
def __str__(self):
"""
Prints the company name string
"""
str = "The Company name is: %s" %\
(self.company_name
)
return str
def add_purchase(self, addtlSTK):
"""
Adds item to stock_dict
"""
self.stock_dict.update(addtlSTK)
return
Ich bin versucht ExampleBase in einem anderen Programm, dessen Code zu nennen ist:
import example
if __name__ == "__main__":
a = {"10-01-2014":(10, 11.25), "10-02-2014":(11, 12.25), "10-03-2014":(12, 13.25)}
b = example.ExampleBase("Bern", a)
Was das Problem ist, und/oder Fehler, den Sie bekommen? – GWW
Haben Sie die erste Datei korrekt eingerückt? Alle Funktionsaufrufe sollten von der Klasse eingerückt werden Beispiel: – smb564
Mögliches Duplikat von: https://Stackoverflow.com/a/4142178/3991696 –