0

I have a file a.py with class to include, another file b.py with the main code. I want to create object by uer input in b.py file. I'm new at programming and I am really stuck.

Here is instance

Here is the first file a.py

class Sell:
    def __init__(self,x,y):
        self.x,self.y=x,y

Here is the second file b.py

#b.py
from a import Sell
x=input()
y=input()
s=Sell(x,y)

I have a weird error:

Type error: İnit takes 1 argument but you gave 3 argument. 

I really dont understand that init takes 1 argument,init(self,x,y)

İf someone help me ı can pray for his/her code works well in her/his project.

1
  • This worked nicely for me. Please try correcting the indentations and spellings, Especially change the spellings in the first file. I hope it will work! Commented Jan 28, 2021 at 19:28

2 Answers 2

1

The code works fine when you fix indentation issues. The class functions and init method must be inside the class definition, which means they must be indented. Also class keyword is lowercase.

This is the correct version

a.py

class Sell:
    def __init__(self,x,y):
        self.x,self.y=x,y

and b.py

from a import Sell
x=input()
y=input()
s=Sell(x,y)
Sign up to request clarification or add additional context in comments.

1 Comment

Your comment help me so much, ı paid attention that y is interger in my program y=int(input()) so work it now Thank you so much bro
0

Error was that; Type error: İnit takes 1 argument but you gave 3 argument.

İt is an type error so pay attention to strings and integers.

Whether you define it is integer and İf you give an integer, python think it is string. That is why tell you that you gave 3 argument despite you gave 2 argument

a.py

class Sell:
def __init__(self,x,y):
    self.x,self.y=x,y

and b.py

from a import Sell
x=input()
y=int(input()) # y was an integer input.
s=Sell(x,y)

İt works well now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.