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
Answers:
You have to execute your function:
It is
print(get_date_taken(""))
not
print(get_date_taken)
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.
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"))
Functions take magnificent things called parameters. You need to fill get_date_taken
with a parameter such as get_date_taken("IMG_0001")
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
You have to execute your function:
It is
print(get_date_taken(""))
not
print(get_date_taken)
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.
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"))
Functions take magnificent things called parameters. You need to fill get_date_taken
with a parameter such as get_date_taken("IMG_0001")