Importing a function from a class in another file?

后端 未结 6 653
北恋
北恋 2020-12-05 03:55

I\'m writing a Python program for fun but got stuck trying to import a function from a class in another file. Here is my code:

#jurassic park mainframe

from         


        
6条回答
  •  清歌不尽
    2020-12-05 04:36

    First you need to make sure if both of your files are in the same working directory. Next, you can import the whole file. For example,

    import myClass
    

    or you can import the entire class and entire functions from the file. For example,

    from myClass import
    

    Finally, you need to create an instance of the class from the original file and call the instance objects.

提交回复
热议问题