【发布时间】:2012-12-06 13:32:27
【问题描述】:
背景:我在 Eclipse SDK 4.2.1 (Juno) 中使用 python 3.2,我注意到一些奇怪的事情 - 虽然我的程序在 Eclipse 中完美运行,但如果我从文件管理器打开它们,它们总是会出现错误关闭.我设法在 cmd 关闭之前获得了截图:
程序似乎在“images”和“Cy.png”之间插入了一个额外的“\”。但是,我不能只从我的程序中删除一个斜杠 - 在其中,我使用了两个斜杠,因为您需要在字符串中包含一个斜杠。 我的程序如下:
from PIL import Image
def pathConstruction(count, imageName):
l = []
l.append('images\\')
if count == 1:
l.append('Sepia')
l.append(imageName)
imagePath = ''.join(l)
return imagePath
def grayscale(pix, width, height):
for col in range(width):
for row in range(height):
r,g,b = pix[col, row]
avg = ((r + g + b) / 3)
r = int(avg)
g = int(avg)
b = int(avg)
pix[col, row] = r,g,b
def sepia(pix, width, height):
for col in range(width):
for row in range(height):
r,g,b = pix[col, row]
newR = (r * 0.393 + g * 0.769 + b * 0.189)
newG = (r * 0.349 + g * 0.686 + b * 0.168)
newB = (r * 0.272 + g * 0.534 + b * 0.131)
pix[col, row] = int(newR),int(newG),int(newB)
imageName = input("Please input the full name of your image, including extension: ")
count = 0
imagePath= pathConstruction(count, imageName)
count = count + 1
img = Image.open(imagePath)
pix = img.load()
width, height = img.size
grayscale(pix, width, height)
sepia(pix, width, height)
imagePath = pathConstruction(count, imageName)
img.save(imagePath)
img.show()
问题:如何在 Eclipse 之外运行此程序?
【问题讨论】:
-
您可以将
sys.excepthook设置为将未捕获的异常记录到文件的函数。无需等待程序退出即可登录文件,设置:logging.basicConfig(filename='example.log',level=logging.DEBUG),登录:logging.info('message')。 -
我确定了实际问题 - 问题已相应更新。
-
配置日志并在
input()之后添加logging.debug(repr(imageName))。您是否在 example.log 中的图像名称处看到\r? -
是的,图片名称后面有一个
\r,如图所示。
标签: eclipse python-3.x special-characters