【问题标题】:python hebrew input\filesytem formatpython 希伯来语输入\文件系统格式
【发布时间】:2010-01-03 00:09:24
【问题描述】:
import os
import pprint
import subprocess
def  Convert (dir):
    curDir = dir
    pathToBonk = "C:\\Program Files\\BonkEnc\\becmd.exe" #Where the becmd.exe file lives
    problemFiles = [] #A list of files that failed conversion
    #
    for item in os.listdir(curDir):
        if item.upper().endswith('.M4A'):
            fullPath = os.path.join(curDir,item)
            cmd = '"%s" -e LAME -d "%s" "%s"' #The command to convert a single file
            cmd = cmd % (pathToBonk, curDir, fullPath)
            val = subprocess.call(cmd)
            if val == 0: #Successfull conversion, delete the original
                os.remove(fullPath)
            else:
                problemFiles.append(fullPath)
                print 'Problem converting %s' % item
                os.rename(fullPath, fullPath + ".BAD")
    print 'These files had problems converting and have been renamed with .BAD extensions:'
    pprint.pprint(problemFiles)     

var = raw_input("Insert Path: ")
var.decode("iso-8859-8")
Convert(var)

你好, 我想将我的音乐从 .m4a 重新格式化为 mp3 歌曲。 我使用 bonkenc 命令行。

问题是我的一些文件夹是希伯来语的。 当我在不包含希伯来语的文件夹中使用此脚本时 - 它可以完美运行。 但是当路径中有希伯来语时,脚本就不起作用了。

我尝试对希伯来语进行编码\解码,但没有任何帮助。

我运行 windows xps p2。 提前致谢, 利隆。

【问题讨论】:

  • 是的。但它有时会引发我无法捕获的异常。
  • 如果你说发生了什么问题会有所帮助。我知道你有一个例外 - 哪个?在哪里?是与您运行的外部 exe 相关的问题,还是如果您只留下 python 代码的骨架也会发生这种情况?

标签: python unicode hebrew


【解决方案1】:

只需使用 os.listdir(unicode(str)) 而不是 os.listdir(str) 以确保 str 是 Unicode,否则它将失败。

同样的问题可以在this question找到

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    • 1970-01-01
    • 2019-11-25
    • 2018-10-02
    • 2014-05-31
    • 2020-12-25
    相关资源
    最近更新 更多