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?
8 Respostas
+ 3
from datetime import datetime
print(dir(datetime.today())) # note the parentheses after today
+ 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())
+ 1
thanks Anna:)
+ 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?
+ 1
Awesome Anna ....tq so much... really it helped a lot.... understood clearly
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'
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....
0
Thanks Jay