小编suf*_*ffa的帖子

我想使用正则表达式来检查名称中包含空格的文件,并用下划线替换空格

我写了一个应用程序,它使用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 regex

1
推荐指数
1
解决办法
805
查看次数

使用if语句条件查看NULL用户输入并打印:"sometext ..."

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)

python if-statement while-loop

0
推荐指数
1
解决办法
8773
查看次数

我定义了一个搜索路径,但正在搜索otrher文件夹中的文件

有人可以告诉我为什么下面的代码正在搜索指定路径中的子文件夹.我只想要搜索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)

python regex path

0
推荐指数
1
解决办法
150
查看次数

是否有一个首选的Python gui使用

我正在尝试将使用cmd模块编码的Python应用程序转换为gui.最初,我遇到了EasyGui.但经过尝试,我发现它非常有限,gui屏幕不一致,总体上不容易看到.我读到了IronPython(Python + .NET),但找不到足够的文档.在我从IronPython上订购亚马逊的书之前(因为这看起来最合法),有没有人知道Python的一个不错的gui替代品?谢谢!

python user-interface

0
推荐指数
1
解决办法
1520
查看次数

我如何从一行文本的开头获取数字,将它们拆分并打印出来

这是我的困境:我正在用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)

python text file

0
推荐指数
1
解决办法
153
查看次数

我试图了解为什么我似乎无法用循环删除列表中的每个索引

我不确定为什么我的列表没有删除基于第二个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)

谢谢你的帮助 ....

python list

0
推荐指数
1
解决办法
116
查看次数

如何使用Python反转字符串中的单词

我试图扭转一个字符串的单词,但有困难,任何帮助将不胜感激:

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 string reverse

-4
推荐指数
1
解决办法
4772
查看次数

标签 统计

python ×7

regex ×2

file ×1

if-statement ×1

list ×1

path ×1

reverse ×1

string ×1

text ×1

user-interface ×1

while-loop ×1