Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1579

Python • Re: New to Python Topic

$
0
0
Not too much information about the code structure in your post.

Here a working sample of two files
- file_A.py, defines a class A
- main.py, imports a class A from file_A.py. Calls a method from this class A from a class B defined in main.py

Post your code if more assistance is needed.

Code:

# file_A.pyclass A:    def __init__(self):        print("class A")    def method(self):        print("class A method()")

Code:

# main.pyimport file_Aclass B:    def __init__(self):        print("class B")    def method(self):        print("class B.method() call to class A method()")        # class_A is global in main.py        class_A.method()        class_A = file_A.A()class_A.method()# expected#          class_A#          class_A.method()class_B = B()class_B.method()# expected#          class_B#          class_B.method() call to class A method()#          class_A.method()

Statistics: Posted by ghp — Wed Dec 10, 2025 8:05 am



Viewing all articles
Browse latest Browse all 1579

Trending Articles