Python – referencing a class from another Python file

· Python
Authors

Use the “from” keyword in addition to “import”, to reference the other file

Syntax: from other_file_name import class_name_to_import

Example:

file first.py has class A definition

To use in file second.py, add to the header of second.py:

from first import A

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: