Tools, FAQ, Tutorials:
'import' Module Loading Statement
How to use "import" statement to load Python modules?
✍: FYIcenter.com
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'
2022-08-26, 1111🔥, 0💬
Popular Posts:
FYIcenter JSON Validator and Formatter is an online tool that checks for syntax errors of JSON text ...
How to use the XML to JSON Conversion Tool at freeformatter.com? If you want to try the XML to JSON ...
How to read RSS validation errors at w3.org? If your RSS feed has errors, the RSS validator at w3.or...
Why am I getting this "Docker failed to initialize" error? After installing the latest version of Do...
Where to find tutorials on HTML language? I want to know how to learn HTML. Here is a large collecti...