pycpython
pycpython

Reputation: 17

PyCharm configuration

I started a python project and attempted to have it OOP.

I used a script to call function from classes, in the following way:

class Object(): 
    def function(input):
       print(input)

The command Object.Object.function("example") used to work fine.

I had to reinstall pycharm, and now when running the same code I get the error of not sending enough input.

This can be solved by changing the call to Object.Object().function("example"),

and the function definition to def function(a,input):

Where the variable a is never used. This however causes new problems when using libraries.

How can I use the previous configuration?

Upvotes: 1

Views: 102

Answers (1)

fuglede
fuglede

Reputation: 18221

Object.Object.function("example") and Object.Object().function("example") are different beasts entirely. The first run invokes the method function on the class Object.Object, while in the latter, Object.Object() creates an instance of type Object.Object and invokes function on that instance (which fails as you must provide the instance itself as the first parameter to the method). It sounds like you are trying to make something like a staticmethod,

class A:
    @staticmethod
    def f(input):
        print(input)

for which both A.f and A().f will act as print.

Upvotes: 1

Related Questions