我写了一个应用程序,它使用ffmpeg将文件转换为特定文件夹中的不同fomat.该文件夹托管.mpg,.mp3,.avi,.flv ...或者决定添加的任何音频/视频文件.当我使用我的应用程序选择要转换的文件名称中有空格时,会出现问题; 应用程序立即关闭,而没有将文件转换为其他格式.目前,我必须重命名名称中包含空格的任何文件,然后才能通过我的app-> ffmpeg进行转换.我正在尝试编写一个函数,从我的应用程序开始检查特定文件夹中的文件名是否为空格,用下划线('_')替换这些空格.我在使用正则表达式时遇到了一些麻烦; 我不擅长编写/配置它们来解决问题.有人可以建议我使用正确的正则表达式来查找文件名中的白/空格吗?以下是我到目前为止:
import os
import re
pattern = r"([^\s]+(?=\.(mp3|mov|mpg|mp4|flv|avi|mpeg4|mkv|mpeg|mpg2|.wav))\.\2)"
def replace_Wspace(self, fName):
if re.match(pattern, fName):
fname = fName.replace(' ', '_')
return fname
Run Code Online (Sandbox Code Playgroud)
我正在根据请求添加处理ffmpeg调用的应用程序中的代码部分:
def convertButton(self, e):
unit1 = self.format_combo1.GetValue()
#Media Formats
unit2 = self.format_combo2.GetValue()
unit3 = self.format_combo3.GetValue()
unit4 = None
unit5 = self.format_combo5.GetValue()
bitRate = self.format_combo6.GetValue()
unit6 = bitRate
if unit3 == '-qmax':
unit4 = self.format_combo4.GetValue()
else:
pass
os.chdir("c:\\d-Converter\\ffmpeg\\bin")
wrkdir = os.getcwd()
newfile = unit1
stripped = newfile.strip('mpeg3aviovfl4w2c.') #Strips the extension from the original file name
progname='c:\\d-Converter\\ffmpeg\\bin\\ffmpeg.exe' …Run Code Online (Sandbox Code Playgroud) Python的缩进,没有分号和括号,花了一些时间让我习惯......来自C++.这个,我肯定是一个简单的修复,但我似乎无法找到问题.非常感谢您的帮助.这就是我所拥有的.当我运行此代码时,它就像第二个'if'语句不存在一样.即使我注释掉第一个'if'语句,第二个'if'语句中的打印行也永远不会打印到屏幕上:
import re
while True:
stringName = raw_input("Convert string to hex & ascii(type stop to quit): ").strip()
if stringName == 'stop':
break
if stringName is None: print "You must enter some text to proceed!"
print "Hex value: ", stringName.encode('hex')
print "ASCII value: ", ', '.join(str(ord(c)) for c in stringName)
Run Code Online (Sandbox Code Playgroud) 有人可以告诉我为什么下面的代码正在搜索指定路径中的子文件夹.我只想要搜索c:\ Python27中的所有.txt和.log文件.但搜索显示c:\ Python27\Doc中的.txt和.log文件的结果......依此类推.谢谢.
elif searchType =='3':
print "Directory to be searched: c:\Python27 "
print " "
directory = os.path.join("c:\\","Python27")
regex = re.compile(r'3[0-9]\d{10}')
for root,dirname, files in os.walk(directory):
for file in files:
if file.endswith(".log") or file.endswith(".txt"):
f=open(os.path.join(root,file))
for line in f.readlines():
searchedstr = regex.findall(line)
for word in searchedstr:
print "String found: " + word
print "File: " + os.path.join(root,file)
break
f.close()
Run Code Online (Sandbox Code Playgroud) 我正在尝试将使用cmd模块编码的Python应用程序转换为gui.最初,我遇到了EasyGui.但经过尝试,我发现它非常有限,gui屏幕不一致,总体上不容易看到.我读到了IronPython(Python + .NET),但找不到足够的文档.在我从IronPython上订购亚马逊的书之前(因为这看起来最合法),有没有人知道Python的一个不错的gui替代品?谢谢!
这是我的困境:我正在用Python编写一个应用程序,它允许我搜索特定字符串的平面文件(KJV bible.txt),并返回搜索的行号,书和字符串.但是,我还想返回找到字符串的章节和经文.这要求我走到行的开头并获得章节和诗节编号.我是Python新手,目前我还在阅读Guido van Rossum的Python教程.这是我想要为圣经学习小组完成的事情; 便携式的东西几乎可以在任何地方运行在cmd模块中.我感谢任何帮助...谢谢.以下是圣经章节的一个例子的摘录:
Daniel
1:1 In the third year of the reign of Jehoiakim king of Judah came
Nebuchadnezzar king of Babylon unto Jerusalem, and besieged it.
Run Code Online (Sandbox Code Playgroud)
说我搜索了'Jehoiakim',其中一个搜索结果是上面的第一行.我想去这行前面的数字(在这种情况下是1:1)并得到章节(1)和第(1)节并将它们打印到屏幕上.
1:2 And the Lord gave Jehoiakim king of Judah into his hand, with part
of the vessels of the house of God: which he carried into the land of
Shinar to the house of his god; and he brought the vessels into the
treasure house of his god.
Run Code Online (Sandbox Code Playgroud)
码:
import …Run Code Online (Sandbox Code Playgroud) 我不确定为什么我的列表没有删除基于第二个List索引的每个char.以下是代码:
L1 = ['e', 'i', 'l', 'n', 's', 't']
L2 = ['e', 'i', 'l', 'n', 's', 't']
for n_item in range(len(L1)):
if L1[n_item] in L2:
del L2[n_item]
Run Code Online (Sandbox Code Playgroud)
以下是我得到的错误:
Traceback (most recent call last):
File "<pyshell#241>", line 3, in <module>
del L2[n_item]
IndexError: list assignment index out of range
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助 ....
我试图扭转一个字符串的单词,但有困难,任何帮助将不胜感激:
S = " what is my name"
def reversStr(S):
for x in range(len(S)):
return S[::-1]
break
Run Code Online (Sandbox Code Playgroud)
我现在得到的是: eman ym si tahw
但是,我想得到:( tahw is ym eman个别话语反转)
python ×7
regex ×2
file ×1
if-statement ×1
list ×1
path ×1
reverse ×1
string ×1
text ×1
while-loop ×1