About Python, from and import, as

Note the difference between from and import used in python (using today function as an example, describe two methods)

(1) Only import the datetime module (file)

Describe that the today function of the datetime class of the datetime module is used.

import datetime
datetime.datetime.today()

as a result

datetime.datetime(2020, 3, 12, 23, 21, 41, 756354)

Will be.

(2) Import the datetime module (file) and datetiem class

In the above example, it is troublesome to use module name.class name. In such a case, use not only import but also from to import. from module name import class name (or function name or variable name) Describe that the today function of the datetime class is used.

from datetime import datetime
datetiem.today()

The result is similar

datetime.datetime(2020, 3, 12, 23, 21, 41, 756354)

Will be.

(3) Bonus

If you use as, you can use the library name (module name) in any word you like.

import datetime as t
t.datetime.today()

The result is similar

datetime.datetime(2020, 3, 12, 23, 21, 41, 756354)

Will be.

Recommended Posts

About Python, from and import, as
Python from or import
About python objects and classes
About Python variables and objects
About Python, len () and randint ()
About Python datetime and timezone
About Python and regular expressions
About Python and os operations
Python # About reference and copy
About Python sort () and reverse ()
[Introduction to Udemy Python3 + Application] 68. Import statement and AS
About installing Pwntools and Python2 series
Python, yield, return, and sometimes yield from
python> link> from __future__ import absolute_import
About python dict and sorted functions
About import
About dtypes in Python and Cython
Read and use Python files from Python
About Python pickle (cPickle) and marshal
[Python] About Executor and Future classes
About import
python> from six.moves import xrange> Six: Python 2 and 3 compatibility library> python2: xrange () / python3: range ()
About _ and __
A little more about references ~ Using Python and Java as examples ~
From Python to using MeCab (and CaboCha)
Porting and modifying doublet-solver from python2 to python3.
A story about Python pop and append
Module import and exception handling in python
Talking about old and new Python classes
Talking about Python class attributes and metaclasses
About python slices
About python yield
About python, class
sql from python
About python, range ()
MeCab from Python
About python decorators
About python reference
About Python decorators
[Python] About multi-process
Summarize Python import
A story about someone who wanted to import django from a python interactive shell and save things to a DB
Firebase: Use Cloud Firestore and Cloud Storage from Python
Import Excel file from Python (register to DB)
Study from Python Reading and writing Hour9 files
Read JSON with Python and output as CSV
[Python] How to read data from CIFAR-10 and CIFAR-100
Think about depth-priority and width-priority searches in Python
About the difference between "==" and "is" in python
Load and execute command from yml in python
PHP and Python integration from scratch on Laravel
Download and import files with Splunk external python
A story about modifying Python and adding functions
[Python] Learn about asynchronous programming and event loops
About the * (asterisk) argument of python (and itertools.starmap)
About shallow and deep copies of Python / Ruby
Generate and output plantuml object diagram from Python object
About Python external module import <For super beginners>
[python] Compress and decompress
About Python for loops
Use thingsspeak from python