Print the result of a Python def

Question:

I want to read the date and time of a image by using Pillow.
And now I want to print the result of the def to be shure I got the Date and Time. But when I type print(defname) I just get some weird numbers as the output.

My code:

import os
import time
import shutil 
import re
from PIL import Image, ExifTags
from PIL.ExifTags import TAGS

def get_date_taken(path):
    return Image.open(r"E:insert_folderDSC_3389.jpg")._getexif()[36867]

print(get_date_taken)

One more thing… If you understand what I want to do and if you understand my code, could you pls check if there is any fault in my code?
Thanks to you guys! <3

Asked By: Whoozy

||

Answers:

You have to execute your function:

It is

print(get_date_taken(""))

not

print(get_date_taken)
Answered By: M. Spiller

You are not calling the function, you are just printing a pointer to that function – this the memory address where the function is stored. In order to execute the function, add parenthesis.

get_date_taken("yourpathhere")

Also, what you are calling def and defname are called functions in Python.

Answered By: EugeneProut

you are just printing the definition of your function. To print the return value you have to call your function with the path:

print(get_date_taken("path of your image"))
Answered By: jawad-khan

Functions take magnificent things called parameters. You need to fill get_date_taken with a parameter such as get_date_taken("IMG_0001")

Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.