FreeKB - Python (Scripting) import module
Python (Scripting) - import module

The import keyword is used to import a module. There are several built in modules, such as platform. Here is how you would import and then use the platform module.

import platform

foo = platform.system()
print("Platform = " + foo)

 

Running this script should return something like this.

Platform = Linux

 

What has happened here is that the platform.py module was used. The platform.py module should be found somewhere in sys.path.

 


No module named

Let's say you try to import a bogus platform.

import foo

 

Running this script should return something like this.

Traceback (most recent call last):
  File "testing.py", line 1, in <module>
    import foo
ImportError: No module named foo

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 01058 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |