trouble with datetime

In addition to what the others said (reading the docs is always a good course of action, especially for this type of information!), I would like to point out the detail in your example's output that also contains the information you're asking about finding because being able to speak the same language as the interpreter/compiler/etc. is an invaluable skill.

Specifically, the output is (emboldening emphasis mine):

"the current time is <built-in method now of type object at 0x6ED39D18> cst"

That's not an error, by the way, it's perfectly valid and expected Python output. If you compare your string interpolation to the output, where you're expecting the date/time to be printed you're instead getting this (again, emphasis mine):

<built-in method now of type object at 0x6ED39D18>

Both time's I've emphasized "method". The term "method" in the context of programming/coding/whatnot means "function that belongs to an object". A method is a specific type of function, only differing from other functions in that it belongs to an object. The now() method you're using here is a function that belongs to the datetime objects from the datetime module (full reference if you just import the module is datetime.datetime.now()). By comparison, the len() function available at the built-in level is just a function because it does not belong to an object. Compare the following python shell interaction:

>>> print(len)  # prints information about the 'len' object which is a "built-in function"
<built-in function len>
>>> import datetime
>>> print(datetime.datetime.now)  # prints information about the 'now' object
<built-in method now of type object at 0x10a7f0558>
>>> print(datetime.datetime.now())  # the parenthesis tell the interpreter to call the 'now' object (which is a method) and the value returned from that call is printed
2015-06-01 15:44:41.023072

So, if you see a similar message when printing something out, it means that you're probably missing a set of parentheses after a method name (unless you were trying to print out that specific string).

/r/learnpython Thread Parent