【发布时间】:2013-12-21 15:36:20
【问题描述】:
我需要让我的计算机自动打印来自相机的图像。
我的一个朋友推荐了这个代码
monRep = "/**/Desktop/DATA/"
import os, mimetypes, random
fpaths = []
for fname in os.listdir(monRep):
fpath = os.path.join(monRep, fname)
if os.path.isfile(fpath):
mt = mimetypes.guess_type(fpath)[0]
ext = os.path.splitext(fpath)[1]
if mt: mt = mt.split('/')[0].lower()
else: mt = False
#if ext.lower() in ('.bmp','.pict', '.JPG', '.jpg'): mt = 'image'
if mt in ('image',): fpaths.append(fpath)
choix = random.choice(fpaths)
command = "lpr "+choix
print (command)
os.system(command)
它有效,但仅适用于一张图片。我需要打印所有图像。
这是我的想法
- 检查文件夹“DATA”
- 查找图片1
- 打印图像1
- 暂停 30 秒(等待下一张图片)
- 重复步骤 1
【问题讨论】:
-
os.listdir(monRep)将不工作,除非你有一个名为/**的实际目录...我假设你在那儿省略了一条路径。 :-) -
当然,我放了一个真实的路径...
-
你真的尝试过实现你的想法吗?