Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将Python字符串转换为原始值或对象值?_Python - Fatal编程技术网

如何将Python字符串转换为原始值或对象值?

如何将Python字符串转换为原始值或对象值?,python,Python,我通过脚本在Scribus中创建页面来放置文本和图像。 我希望使用pyexviv2读取/写入Exif XPKeywords。通过使用“human_value”来转换返回的字节值,可以从中读取。我意识到我不需要改变信仰,除非看到它起作用。 我正在从一个标记中拆分获得的字符串,并希望将一部分写入另一个标记。 我理解我不能反向使用“人的价值”(只读)。 谁能给我指一下正确的方向吗?下面是到目前为止的进展,获得文件名的第5部分,这很好 [编辑]正在添加。。。元数据['Exif.Image.XPKeywo

我通过脚本在Scribus中创建页面来放置文本和图像。 我希望使用pyexviv2读取/写入Exif XPKeywords。通过使用“human_value”来转换返回的字节值,可以从中读取。我意识到我不需要改变信仰,除非看到它起作用。 我正在从一个标记中拆分获得的字符串,并希望将一部分写入另一个标记。 我理解我不能反向使用“人的价值”(只读)。 谁能给我指一下正确的方向吗?下面是到目前为止的进展,获得文件名的第5部分,这很好

[编辑]正在添加。。。元数据['Exif.Image.XPKeywords']=要写入的部分[4]给出了值错误:无效值

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import scribus #will test that Scribus is running
import pyexiv2
import string

metadata = pyexiv2.ImageMetadata('j:/BOOK/Banns/1.jpg')
metadata.read()

metadata.exif_keys
['Exif.Image.ImageDescription',
 'Exif.Image.DocumentName',
 'Exif.Image.XPComment',
 'Exif.Image.XPAuthor',
 'Exif.Image.XPSubject',
 'Exif.Image.XPKeywords',
 'Exif.Image.DateTime',
 'Exif.Image.Artist',
 'Exif.Image.Copyright',
 'Exif.Image.ExifTag']

tag=metadata['Exif.Image.DocumentName']
txt=tag.human_value
scribus.messageBox("", txt)     #instead of raw_value or just value
parts=txt.split(',',5)         #Split filename at ',' i.e. 5 strings in a List
scribus.messageBox("",parts[4]) #Separate Place from List

经过4个小时的研究,我通过反复试验找到了一个可能对其他人有用的有效答案

我补充了一个问题。。。 要写入的“元数据['Exif.Image.XPKeywords']=parts[4]”给出了值错误:无效值 答案如下,因为XPF关键字是utf-16

metadata['Exif.Image.XPKeywords']=pyexiv2.utils.string_to_undefined(parts[4].encode('utf-16'))
metadata.write()