python 逆向生成正则表达式_用Python中的正则表达式生成lis
我有一個(gè)小腳本,用來產(chǎn)生一個(gè)預(yù)定義的字體和文本圖像。我想將其更改為使用多種字體來呈現(xiàn)相同的文本,例如字母A以5種字體呈現(xiàn)。我將我的字體列表定義為:
fonts = [ 'Georgia', 'Consolas', 'Arial']
然后我把它用在:for item in enumerate(fonts) :
...
我想用所有的例如Times New Roman家族字體生成列表。我試圖用正則表達(dá)式生成列表,但沒有成功。我真的不知道如何將它嵌入到列表中(用引號(hào),在開頭和結(jié)尾加/等等)
我嘗試過這樣的方法:fonts = [ '/^.Times.*$/' ]和這個(gè){},但沒有成功。在
第二個(gè)問題是當(dāng)我想使用3個(gè)單詞的字體,比如Luicida Console Regular,然后我得到了這個(gè)錯(cuò)誤:
^{pr2}$
腳本似乎只從字體名稱中獲取兩個(gè)單詞。在
編輯def main ():
surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
context = cairo.Context (surface)
source = context.get_source ()
font = sys.argv[1]
fonts = [ 'Georgia', 'Consolas', 'Arial', 'Lucida Console', 'Times New Roman' ]
output = sys.argv[2]
text = sys.argv[3]
background = cairo.SolidPattern (255, 255, 255)
context.rectangle (0, 0, WIDTH, HEIGHT)
context.set_source (background)
context.fill ()
pangctx = pangocairo.CairoContext (context)
layout = pangctx.create_layout ()
layout.set_width ((WIDTH - 2 * PADDING) * pango.SCALE)
layout.set_single_paragraph_mode (True)
layout.set_wrap (pango.WRAP_CHAR)
size = 40 * pango.SCALE
spacing = 10 * pango.SCALE
markup = ''
for index, item in enumerate(fonts):
print index, item
markup += '' + text +''
layout.set_markup (markup)
pangctx.update_layout (layout)
context.new_path ()
context.move_to (PADDING, PADDING)
context.set_source (source)
context.set_source_rgb (0, 0, 0)
pangctx.show_layout (layout)
surface.write_to_png (output)
編輯
似乎這仍然是pango中的一個(gè)bug launchpad link
總結(jié)
以上是生活随笔為你收集整理的python 逆向生成正则表达式_用Python中的正则表达式生成lis的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python pdf 图片_第一节:py
- 下一篇: python解析xml文件选用模块_py