I am very new to python, I have a simple question.
For example
If I do
import A
then I can use A.b()
.
I am wondering, how to omit A
in A.b()
?
One of the most appropriate functions that we can use to exit from a Python program is the sys. exit() function. This function is available in the sys module and when called it raises the SystemException in Python that then triggers the interpreter to stop further execution of the current python script.
Aliasing ModulesIt is possible to modify the names of modules and their functions within Python by using the as keyword.
If you want to use b
from module A
:
from A import b
If you want to rename it:
from A import b as my_b
If you need several objects:
from A import b, c, d
If you need everything:
from A import *
About the import *
option, please do read this post.
It's rather short, but tl;dr: do not import everything from a module by from A import *
.
If you really need everything from the module, or a very big part of its content, prefer the normal import, possibly with renaming:
import numpy as np
import tkinter as tk
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With