Python Compile error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python Compile error (/thread-33864.html) |
Python Compile error - ajitnayak1987 - Jun-03-2021 I have simple program running on pyscripter 2.5 and similar code tried on jupyter notebook. How to resolve below error reference code taken from https://codeigo.com/python/import-class-from-another-file-and-directory car.py class Car: def init(self, company, model, year): self.company = company self.model = model self.year = year def get_details(self): details = str(self.year) + ' ' + self.company + ' ' + self.model return detailsmain.py from car import Car print(Car) print('enter the code') mycar = Car('Ford', 'Escort', 2000)error
RE: Python Compile error - buran - Jun-03-2021 note, it should be __init__ , not init
RE: Python Compile error - ajitnayak1987 - Jun-03-2021 Thanks It worked. I have similar example complexnumber.py class Complex: def __init__(self,real,imaginary): self.real=real self.imaginary=imaginary def __add__(self,right): return Complex(self.real+right.real,self.imaginary+right.imaginary) def __iadd__(self,right): self.real+=right.real self.imaginary+=right.imaginary return self def __repr__(self): return (f'({self.real}'+('+' if self.imaginary>=0 else '-')+ f'{abs(self.imaginary)}i)')But when try using ipython module i get error. But it work on pyscripter
RE: Python Compile error - jefsummers - Jun-03-2021 You are not showing the code where the error occurs. Can you paste more (all) of your code? RE: Python Compile error - ibreeden - Jun-03-2021 (Jun-03-2021, 10:16 AM)ajitnayak1987 Wrote:The name of the class is "Complex". Not "complex". Remember Python is case sensitive. |