背景:我正在使用 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 之外运行该程序?