0

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_folder\DSC_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

Whoozy
  • 161
  • 17

4 Answers4

1

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("your\path\here")

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

EugeneProut
  • 298
  • 2
  • 12
  • 2
    There's no pointers in Python - what the OP is printing is the function object itself. The fact that the string representation of a Python function includes the function object's uid is just an implementation detail, and the fact that _in CPython_ objects uids are their memory address is even more of an implementation detail (other Python implementation - Jython, IronPython, etc - may use anything else as objects uids). – bruno desthuilliers Feb 17 '20 at 13:07
  • Thank you for the clarification, I will delete my answer. – EugeneProut Feb 17 '20 at 13:09
  • 1
    DONT !!! it's not a bad answer, it just needs to be edited to be accurate. – bruno desthuilliers Feb 17 '20 at 13:09
0

You have to execute your function:

It is

print(get_date_taken(""))

not

print(get_date_taken)
MSpiller
  • 3,500
  • 2
  • 12
  • 24
0

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"))
jawad-khan
  • 313
  • 1
  • 10
  • the OP are not printing "the definition of" the function, they are printing the function object itself (or more exactly the string representation of the function). – bruno desthuilliers Feb 17 '20 at 13:08
0

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