我尝试使用批处理命令在python中重命名现有文件,但出现以下错误:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'
使用此代码:
import subprocess
from time import gmtime, strftime
now = strftime("%Y-%m-%d_%H:%M:%S", gmtime())
src = "C:\Users\Murph\xxx_yyy_.jpg"
dst = "xxx_yyy_zzz_" + now + "_.jpg"
subprocess.call('ren %s %s'%(src,dst), shell=True)
然后我尝试了不同的代码并得到了这个错误:SyntaxError :("在输入时没有可行的选择''%s''",
不同的代码:
import os
os.system(ren '%s','%s' < %(src,dst))
我错过了什么?
错误代码1:
[error] Abgebrochen
[error] Ein Fehler in Zeile 17
[error] Fehlermeldung: Traceback (most recent call last):
File "C:\Users\Murph\AppData\Local\Temp\sikuli-tmp8294784858223312402.py",
line 17, in
subprocess.call('ren %s %s'%(src,dst), shell=True)
File "D:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\subprocess.py",
line 456, in call
File "D:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\subprocess.py",
line 751, in __init__
File "D:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\subprocess.py",
line 1236, in _execute_child
TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'
错误代码2:
[error] Abgebrochen
[error] Ein Fehler in Zeile 17
[error] Fehlermeldung: Traceback (most recent call last):
File "C:\Users\Murph\AppData\Local\Temp\sikuli-tmp6179560160671230371.py",
line 17, in
os.system('ren %s %s' %(src,dst))
File "D:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\subprocess.py",
line 456, in call
File "D:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\subprocess.py",
line 751, in __init__
File "D:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\subprocess.py",
line 1236, in _execute_child
TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'
答案 0 :(得分:1)
该错误与Jython 2.5子进程模块有关:Error link
你应该使用Sikuli的最新版本。 (目前版本为1.1.1,Jython支持Python语言级别2.7)