![]() |
instance of a class in different files - 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: instance of a class in different files (/thread-15555.html) |
instance of a class in different files - DionisiO - Jan-21-2019 Hello All! I'm new to Python ![]() Trying to understand how classes work around, i'm trying to use a method that is in another class from a different file. Note: I'm using Pycharm and i created a simple project, both files are in the same folder. Any ideas on how to access classB methods?? Eg: File1.py from File2 import classB classA: my_object = classB() my_object.showGreeting() File2.py classB: def showGreeting(self): print("Welcome!!!") RE: instance of a class in different files - woooee - Jan-21-2019 ## File1.py import File2 class A: def __init__(self): ## note that ClassB was incorrectly named in your code ## there is a space in the name and it is not CamelCase class_b_instance=File2.ClassB() class_b_instance.showGreeting() RE: instance of a class in different files - DionisiO - Jan-21-2019 Nice! wooooee Thanks for your help man ![]() |