Python “错误”;应为字符串或缓冲区“;

Python “错误”;应为字符串或缓冲区“;,python,arabic,pillow,bidi,ligature,Python,Arabic,Pillow,Bidi,Ligature,我正在生成两个字符排列的图像,并使用阿拉伯语\u整形器连接字符。2对2字符的排列将生成4个图像,但在t1=阿拉伯语整形器(word)处生成错误“预期字符串或缓冲区” 如果问题不清楚,请提问 from bidi.algorithm import get_display import PIL.Image, PIL.ImageFont, PIL.ImageDraw import arabic_reshaper unicode_text = u"\u06F1"+ u"\u06CC"+ u"\u06A9

我正在生成两个字符排列的图像,并使用
阿拉伯语\u整形器
连接字符。2对2字符的排列将生成4个图像,但在t1=
阿拉伯语整形器(word)处生成错误
“预期字符串或缓冲区”
如果问题不清楚,请提问

from bidi.algorithm import get_display
import PIL.Image, PIL.ImageFont, PIL.ImageDraw
import arabic_reshaper

unicode_text = u"\u06F1"+ u"\u06CC"+ u"\u06A9"
list_of_letters = list (unicode_text)
folder = 1
n=2
for i in range(1,n+1):
    for word in itertools.permutations( list_of_letters,i):
        print word
        t1 =  arabic_reshaper.reshape(word)
        print t1
        img= PIL.Image.new("L", (200, 200))
        draw = PIL.ImageDraw.Draw(img)
        font = PIL.ImageFont.truetype( r"C:\Users\arabtype.ttf", 40)
        t2 = get_display(t1)      
        print t2# <--- here's the magic <---
        draw.text( (10,50), ' ' + t2, fill=220, font=font)
        img.show()
从bidi.algorithm导入获取显示
导入PIL.Image、PIL.ImageFont、PIL.ImageDraw
进口阿拉伯文整形器
unicode\u text=u“\u06F1”+u”\u06CC“+u”\u06A9”
字母列表=列表(unicode文本)
文件夹=1
n=2
对于范围(1,n+1)内的i:
对于itertools.排列中的单词(字母列表,i):
印刷字
t1=阿拉伯文\u整形器。整形(word)
打印t1
img=PIL.Image.new(“L”(200200))
draw=PIL.ImageDraw.draw(img)
font=PIL.ImageFont.truetype(r“C:\Users\arabtype.ttf”,40)
t2=获取显示(t1)

打印t2#问题在于
itertools.permutations
生成一个元组

您需要将其转换为字符串。大概是这样的:

for word in itertools.permutations( list_of_letters,i):
    word = u''.join(word)
    print word