+ 1

Python: Import modules

How should i import a module in Python? For example, is it "from datetime import datetime" OR "import datetime"?

1st Sep 2020, 8:01 AM
Adam Haller
Adam Haller - avatar
4 Answers
+ 4
It depends. datetime is the root module and also a child. If u only need the functions of child then use first variant. If u need further things like timezone use 2nd variant.
1st Sep 2020, 8:05 AM
Oma Falk
Oma Falk - avatar
+ 3
I prefer you use from datetime import datetime because this import only datetime file from datetime not all files and this method help to fast way to execute your files
1st Sep 2020, 8:03 AM
Akash Agrawal
Akash Agrawal - avatar
+ 2
You can go on with Oma Falk answer otherwise you can try this. from datetime import * This '*' refers to all
1st Sep 2020, 9:38 AM
Jenson Y
0
Thank you, guys.. Really appreciate it
1st Sep 2020, 12:52 PM
Adam Haller
Adam Haller - avatar