简体   繁体   English

打印 Python def 的结果

[英]Print the result of a Python def

I want to read the date and time of a image by using Pillow.我想使用 Pillow 读取图像的日期和时间。 And now I want to print the result of the def to be shure I got the Date and Time.现在我想打印 def 的结果,以确保我得到了日期和时间。 But when I type print(defname) I just get some weird numbers as the output.但是当我输入print(defname)我只会得到一些奇怪的数字作为输出。

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 <3

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.此外,您所称的 def 和 defname 在 Python 中称为函数。

You have to execute your function:你必须执行你的功能:

It is这是

print(get_date_taken(""))

not不是

print(get_date_taken)

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")您需要使用get_date_taken("IMG_0001")等参数填充get_date_taken

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM