Python Date and time, I am getting attribute error | Selenium Python Forum
N
Nitika Sharma Posted on 16/10/2020
 

Using the same code as mentioned but still getting error for strptime.Check attached screenshot


J
Jaspreet Replied on 16/10/2020

Hey 

Kindly please share your code so that it could be checked.


N
Nitika Sharma Replied on 16/10/2020

 
from _datetime import datetime

currentdate = datetime.now()
print(currentdate)
print(type(currentdate))

formattedDate = currentdate.strftime("%Y,%d %b")
print(formattedDate)
date = "28/09/2020"
string_formattedDate = datetime.strptime(date, "%d/%m/%Y")
print(string_formattedDate)


J
Jaspreet Replied on 16/10/2020

Hey

Your code is absolutely fine. The error that you are getting is because of the module name. Do not give the module names as same as the exisiting keywords otherwise interpreter starts searching for the attribute in the module made by you. Kindly change the name of your module to something other than datetime, it will run fine.


N
Nitika Sharma Replied on 17/10/2020

 

Sorry I did not get your point, where I need to change the module name, if I am changing datetime module name then it showing me error.Can you please share code for this.

from _datetime import datetime

currentdate = datetime.now()
print(currentdate)
print(type(currentdate))

formattedDate = currentdate.strftime("%Y,%d %b")
print(formattedDate)
date = "28/09/2020"
string_formattedDate = datetime.strptime(date, "%d/%m/%Y")
print(string_formattedDate)

where I need to change?


J
Jaspreet Replied on 17/10/2020

Hey

The code is correct, the name of the file is to be changed. You have the filename for this code as "datetime", change it to something else.


N
Nitika Sharma Replied on 18/10/2020

 

okay, issue has been resolved.Thanks


J
Jaspreet 4 days ago

Hey

Thank you for the update.


Related Posts