Date time - python3


#1



https://www.codecademy.com/courses/python-beginner-en-zFPOx/0/4?curriculum_id=4f89dab3d788890003000096


When running the code of this exercise in python 3 i get an error,

File "time.py", line 4
print '%s/%s/%s' % (now.month, now.day, now.year)
^
SyntaxError: invalid syntax

should it be formatted in a different way in python 3 ? could you add a comment about that in the lesson ?


from datetime import datetime
now = datetime.now()

print '%s/%s/%s' % (now.month, now.day, now.year)


#2

in python3, print changed from statement to function call:

# python2
print True
# python 3
print(True)

#3

They're not going to do that

While it's silly how long they've been avoiding the version bump of the python track, this is something you should google same as all the other issues you'll run into while writing code

Also, datetime.datetime.strftime is probably the better tool for formatting datetime


#4

so how would the code above then look in python 3 ?


#5

with parentheses as i demonstrated in my example?


#6

this python 2 code :slight_smile:

from datetime import datetime
now = datetime.now()

print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year, now.hour, now.minute, now.second)

looks like this : in python 3 ?


#7

the same, but with parentheses, see this example:

# python2
print True
# python 3
print(True)

#8

its not that clear , to be honest, will this there be an python 3 course in the future ? Would like to switch to that as soon as possible ...

python 3 code looks like this , after some search..

from datetime import datetime
now = datetime.now()

print("%s/%s/%s %s:%s:%s" % (now.month, now.day, now.year, now.hour, now.minute, now.second))


#9

read the blog, it might get upgraded to python3

With some searching, you should indeed find how to add parentheses


#10

Thank you for your feedback, its really helpfull, and dont get me wrong, codecademy has the best courses around. Lets hope that they move to Python3 to make it even better, because thats the future. Its not clear on the blog if they will, but one can guess thats the way to go. Have a nice day :wink:


#11

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.