Python class defined in the same file as another class - how do you get access to the one defined later in the file?

后端 未结 5 1812
迷失自我
迷失自我 2021-01-23 02:06

I\'m very new to Python, I figure this question should be easy to answer.

My problem simplified is this...

I have 2 classes in a File class A and class B. Class

5条回答
  •  抹茶落季
    2021-01-23 02:28

    To access B, you must first have defined B.

    If you want to access B when you define A, you need to move it above A in the file.

    If you want to access B when you call methods in A, you don't need to do anything: by the time you call a method of A, the interpreter has executed all the definitions.

提交回复
热议问题