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
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. ** **
>>> 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.
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. ..
How to use Python, import (from, as, recommended style of PEP8, notes, etc.)
Recommended Posts