python 希伯来文输入\文件系统格式

标签 python unicode hebrew

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。 提前致谢, 利龙。

最佳答案

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

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

关于python 希伯来文输入\文件系统格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1993402/

相关文章:

search-engine - 在哪里可以找到希伯来停用词列表?

dictionary - 有没有更好的 pythonic 方法来做到这一点?

python - GET curl 调用不返回 JSON 对象

emacs - 无法向 SLIME 发送有趣的字符

PHP PCRE unicode 转义

java - 使用 iText 库从 *.xhtml 转换为 *.pdf 时,无法设置希伯来字母的 RTL 方向

javascript - 使从左到右的语言写成从右到左的 html

python - 具有不同输入的集成模型(预计会看到 2 个数组)

python - Pygame 圆及其关联的用于碰撞检测的矩形

java - 检测 PDF 中丢失/损坏的 Unicode 映射