What happens if you do "import A, B as C" in Python?

Introduction

When importing modules in Python

import os

And,

from sys import path

However, if you use as, you can refer to it by the name you want to use. For example

import numpy as np

Then use the name np instead of the name numpy to create the module

arr = np.asarray([1,2,3])
arr = numpy.asarray([1,2,3]) #Same as above

You can refer to it like this.

I was addicted to this time

I was addicted to this time

import A, B as C

Then, ** what are the names of modules A and B **? Which of the following?

--Same as import A as C --Same as import B as C --importError

** According to PEP8, modules should not be bulk imported separated by commas. This time, let's assume that you have no choice but to come across such a scene. ** **

I've tried

>>> import os, sys as test
>>> os #No error
<module 'os' from 'C:\\Python37\\lib\\os.py'>
>>> sys #error
['', ...'.']
>>> test #No error
<module 'sys' (built-in)>

So it seems that it depends on the module sys. If you actually try without "as test",

>>> import os, sys
>>> os #No error
<module 'os' from 'C:\\Python37\\lib\\os.py'>
>>> sys #No error
<module 'sys' (built-in)>

It works well.

Conclusion

It is not good to get lost at a glance, so I will add multiple modules in the future

import A, B, C

Do not write by connecting multiple items like. ..

References

How to use Python, import (from, as, recommended style of PEP8, notes, etc.)

Recommended Posts

What happens if you do "import A, B as C" in Python?
What to do if you get a minus zero in Python
Why do you add a main ()-if statement in Python?
What to do if you can't log in as root
Solve ABC175 A, B, C in Python
What to do if you get Swagger-codegen in python and Import Error: No module named
If you want a singleton in python, think of the module as a singleton
What to do if a symbolic link error occurs in import cv while trying to install OpenCV in Python
What to do if you get a "No versions found" error in pipenv
[Beginner] What happens if I write a program that runs in php in Python?
What to do if a Unicode Encode Error occurs in Sublime Text Python
What to do if you get "Python not configured." Using PyDev in Eclipse
If you encounter a "Unicode Decode Error" in Python
What to do if a UnicodeDecodeError occurs in pip
Solve Atcoder ABC176 (A, B, C, E) in Python
What to do if you get `No kernel for language python found` in Hydrogen
What to do if you get an error when importing matplotlib in Python (Mac)
What to do if you can't hit the arrow keys in the Python interactive console
What to do if you run python in IntelliJ and end with an error
What to do if you get the error RuntimeError: Python is not installed as a framework when trying to use matplitlib and pylab in Python 3.3
What to do if ʻarguments [0] .scrollIntoView ();` fails in python selenium
If you write TinderBot in Python, she can do it
What to do if pip gives a DistributionError in Homebrew
How to import a file anywhere you like in Python
What to do if you get "coverage unknown" in Coveralls
What to do if a 0xC0000005 error occurs in tf.train.start_queue_runners ()
ABC127 A, B, C Explanation (python)
Do you need a Python re.compile?
ABC166 in Python A ~ C problem
Solve ABC036 A ~ C in Python
ABC128 A, B, C commentary (python)
ABC126 A, B, C Explanation (python)
What to do if you get a Cannot retrieve metalink for repository error in yum
Solve ABC037 A ~ C in Python
Python | What you can do with Python
What to do if you can't install pyaudio with pip #Python
Investigating what could be used as a Markdown parser in Python
What to do if you get a UnicodeDecodeError with pip install
If you want to assign csv export to a variable in python
What to do if you can't use the trash in Lubuntu 18.04.
What to do if you get angry with'vertices' must be a 2D list ... in matplotlib arrow
What to do if you get an error saying c compiler cannot create executables in configure
What to do if you get a must override `get_config` error when trying to model.save in Keras
What to do if you get `locale.Error: unsupported locale setting` when getting the day of the week from a date in Python
Do a non-recursive Euler Tour in Python
python> keyword arguments> hoge (** {'a': 1,'b': 2,'c': 3})
Solve ABC165 A, B, D in Python
What to do if you can't find PDO in Laravel or CakePHP
What to do if you couldn't send an email to Yahoo with Python.
What to do if you get lost in file reference with FileNotFoundError
Python --How do you split a list into evenly sized chunks in Python?
What to do if you get angry in TensorFlow v2 without attribute'app'
What to do if No Python documentation found for ... appears in pydoc
What to do if you can't install with pip in babun environment
What to do if you get a "Wrong Python Platform" warning when using Python with the NetBeans IDE
[Mac OS] What to do when Python is not installed as a framework. Is displayed when import matplotlib is performed.
What to do if you get angry with "Value Error: unknown local: UTF-8" in python manage.py syncdb
What to do if you get the error Target WSGI script'/var/www/xxx/xxx.wsgi' cannot be loaded as python module
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup
[Python] What to do if an error occurs in pip (pyinstaller, pyautogui, etc.)
Output formatted output in Python, such as C / C ++ printf.