0

How to get the attributes in sub modules

example: in datetime module we have datetime sub module. which contains today method....when we invoke this method we get current time.....and also this method contains many attributes like minute seconds etc....so how can I view all those attributes?

7th Feb 2019, 5:07 AM
Uthpala
8 Respostas
+ 3
from datetime import datetime print(dir(datetime.today())) # note the parentheses after today
7th Feb 2019, 7:11 AM
Anna
Anna - avatar
+ 3
Look at the very first answer... date, time and datetime are submodules of datetime. In order to use the submodule datetime, you need to import it by writing "from datetime import datetime". The main module datetime doesn't have a method today(). It's part of the submodule. You could do this as well: import datetime print(datetime.datetime.today())
7th Feb 2019, 7:43 AM
Anna
Anna - avatar
+ 1
thanks Anna:)
7th Feb 2019, 7:29 AM
Uthpala
+ 1
Awesome Anna.... thank you so much got what I expected....but why I didn't get if I use directly like below import datetime print(dir(datetime.today())) if I use from datetime import datetime then it is working....why so?
7th Feb 2019, 7:36 AM
Uthpala
+ 1
Awesome Anna ....tq so much... really it helped a lot.... understood clearly
7th Feb 2019, 7:47 AM
Uthpala
0
Thanks Jay....but that lists only attributes of datetime.....my question is datetime sub module contains time,today, etc... methods which we invoke (x = datetime.today()) to get current time....we can also print only minutes or seconds from x using x = datetime.today(). minutes.....so how to list all available attributes of 'today'
7th Feb 2019, 5:24 AM
Uthpala
0
Hey Jey thank you....I got results but not what I want.... it is explaining what is 'today' ....it is not listing it's attributes like seconds minutes hours....
7th Feb 2019, 5:40 AM
Uthpala
0
Thanks Jay
7th Feb 2019, 5:45 AM
Uthpala