Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 instance of a class in different files
#1
Hello All!

I'm new to Python Smile

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!!!")
Quote
#2
## 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()
Quote
#3
Nice!

wooooee Thanks for your help man Dance
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Python complains that class instance is not defined colt 3 425 Sep-17-2019, 12:32 AM
Last Post: ichabod801
  how to add class instance attributes from list 999masks 2 420 Jul-22-2019, 07:59 AM
Last Post: 999masks
  spread same class into separate files in python asheru93 3 590 Jun-19-2019, 02:06 PM
Last Post: ichabod801
  Trying to set an instance variable to current value of a class variable ScottDiesing 3 712 Feb-15-2019, 03:12 PM
Last Post: ScottDiesing
  Printing class instance P13N 2 718 Dec-23-2018, 10:28 PM
Last Post: P13N
  How I can create reference to member of the class instance? AlekseyPython 8 920 Dec-05-2018, 06:24 AM
Last Post: AlekseyPython
  Class object instance. Link instance attribute to class. Can it be done easier. Windspar 7 1,039 Dec-03-2018, 11:16 PM
Last Post: Windspar
  Difference between self and a reference to own class. (unique instance) Dupletor 1 859 Nov-01-2018, 11:14 AM
Last Post: Gribouillis
  Help creating a class instance dynamically Kotevski 9 1,415 Aug-17-2018, 05:23 AM
Last Post: Gribouillis
  How to check if class instance exists in a list of class instance objects? sonicblind 23 6,085 May-27-2018, 05:44 AM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)