Python/Import
|
[edit] importPython Module: core [edit] DescriptionThis is a part of the core Python syntax and does not require importing a module to use Import is a special Python keyword used to import other modules into your current script. It should be placed at the head of scripts. Import is NOT a method so uniquely does not have a bracketed syntax. There are a couple of variations on the syntax that allow special modes of import [edit] Syntaximport <module>
Imports all the methods and classes of a module, in the script they become available via: <module>.<method / class>()
from <module> import <method /class OR *> Imports only a specific method or class form a named module, it is then available directly (without reference to the module). Alternatively using * imports all the methods / classes from the named module for direct reference in the script.
from <module> import <method / class> as <name> import <module> as <name>
Works the same as the first 2 but assigns the module, class or method (depending on the variation) to name
[edit] Examplesimport es from es import server_var import time as waffles # es is imported so we can call methods in it es.msg("Hello World!") # As we specifically imported server_var method we can call it directly here svar = server_var("a_var") # And finally methods in the time module can be accessed via the waffles keyword # Sleeps for 10 seconds... waffles.sleep(10) [edit] Notes
|
|
