'import' Module Loading Statement
How to use "import" statement to load Python modules?
If you created a Python module file called "firstModule.py" as described in the previous tutorial, you can load it into your Python execution session using the "import" statement:
1. Make sure the module file is in the current directory:
\fyicenter>dir firstModule.py 147 firstModule.py
2. Start the Python in interactive mode:
\fyicenter>python Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
3. Load the module file. Note that the Python code in the module file will be executed once when you load it for the first time. If you load it again, it will not be executed any more.
>>> import firstModule Loading firstModule.py... >>> import firstModule
4. Access module properties and methods:
>>> firstModule.__doc__ 'My first Python module' >>> firstModule.1.00 '1.0' >>> firstModule.sayHello() Greetings from first module!
5. Using module classes:
>>> firstModule.firstClass.sayHello() Greetings from first class! >>> x = firstModule.firstClass() >>> x.1.00 '1.1'
2017-09-12, 118👍, 0💬
How To Upload Files into Database in PHP? To store uploaded files to MySQL database, you can use the...
How To Create Table Borders? There are two sets of borders within a table: Outer Borders - Borders t...
How To Connect to MySQL from a PHP Script in PHP? If you want access the MySQL server, you must crea...
Where to find tutorials on RSS specifications? I want to learn it to describe my API services. Here ...
Can You Specify the "new line" Character in Single-Quoted Strings? You can not specify the "new line...