gpt4 book ai didi

python - 如何在 Gimp python 脚本中将信息输出到控制台?

转载 作者:太空狗 更新时间:2023-10-29 21:22:48 24 4
gpt4 key购买 nike

我刚开始学习使用 Python 编写 Gimp 脚本,我想知道如何将文本输出到控制台?我在 Windows 7 上使用 2.7.5 版。

我尝试了打印功能,但它没有向 python-fu 控制台或使用 Gimp 启动的开发控制台写入任何内容。我应该使用什么功能来做到这一点?或者这是 2.7.5 版本的问题?我发现了一些关于“gimp-message”的提及,但这似乎是与 Scheme (Script-fu) 一起使用的函数

谢谢!

(也作为主题发布 here )

最佳答案

我们可以重定向标准输出和标准错误。

#!/usr/bin/env python
# coding: iso-8859-1

from gimpfu import *
import sys
sys.stderr = open( 'c:\\temp\\gimpstderr.txt', 'w')
sys.stdout = open( 'c:\\temp\\gimpstdout.txt', 'w')

def MyUsefulFilter(img, drw):

# these print redirected to gimpstdout.txt
print 'hello world'
print img
print drw

# this error redirected to gimpstderr.txt
x = 0
y = 1/x


pdb.gimp_image_undo_group_start(img)
# useful code here
pdb.gimp_image_undo_group_end(img)


register(
"useful_filter",
"very useful indeed",
"",
"MF",
"GPL",
"2013",
"<Image>/Filters/Photo/Useful Filter",
"RGB*",
[],
[],
MyUsefulFilter)

main()

关于python - 如何在 Gimp python 脚本中将信息输出到控制台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9955834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com