Python确实比较好用,简洁高效,不用像c,c++这类强定义类型语言那样抠的恨死。
而且有些任务用脚本语言来实现,比动不动就请出c,c++这类火力强悍的工具更省事。
可我总是对python 很迷糊,尤其是对其环境设置有种心虚和恐惧。
一年前用过Python Image Library,使用其中的Pilconvert.py进行图片格式转换,将jpg转换为pgm格式。
当时是在linux平台上做的,做完了没有留下任何使用记录,也许当时觉得没啥好记录的吧。
现在在windows下,要实现同样的功能,却搞不定了,脑子迷迷糊糊的,不知道从哪下手,不知道代码该到哪去。
搞不清python 的IDLE,也就是python shell能干些什么。
IDLE在Python doc中解释为 integrated development environment, IDLE offers a Python shell similar to interactive Python interpreter sessions but richer in functionality. It also includes a text editor optimized to edit python source code, an interactive debugger, and several specialized browsers/viewers.
我的程序如下,功能是遍历某个目录下的jpg文件,将其转变为pgm格式
from os.path import walk, join, normpath
from os import chdir, remove
import Image
from os import execv
from PIL import Image
def scan(arg, dirname, names):
for file in names:
print file
if file[-4:]==".jpg":
fname=dirname+file
print fname
newname=fname[:-4]+".pgm"
pilconvert fname newname
if __name__== "__main__":
walk("D://data//",scan,0)
总是提示错误,Name error , global name pilconvert is not defined
也就是说,没找到pilconvert.py这个文件.
我已经安装了python image library(pil-1.1.7)到C:/Python26/Lib/site-packages/目录下了,pilconvert.py也存在于C:/Python26/Scripts目录下了。另外还拷了一份到当前目录下。
为什么还认不到呢?