Python:变更输出文件的一部分的大写

发布于 2025-02-07 05:08:30 字数 387 浏览 2 评论 0原文

我正在尝试更改旨在检测文件中文本语言的Python脚本。它检测到语言&在文件名末尾以ISO格式检测到的语言。不幸的是,它以所有小写都输出Lang代码。

现在,我在脚本中的几个位置找到了此sub_lang = fileName [-3] .lower(),但不幸的是将其更改为.upper 毫无用处来更改输出。

所有文件将以.lan.vtt.eng.srt.123.SSA带有3个字符扩展以及3字符语言代码。我编辑的脚本具有输出3个字符或2个字符ISO代码的能力,但是对于我的使用,我将始终使用3个。

我认为这是一个简单的更改,但是我发现的所有内容似乎都没有用

I'm trying to change a python script that is designed to detect the language of the text in a file. It detects the language & puts the language detected in ISO format at the end of the filename. Unfortunately it outputs the Lang code in all lowercase.

Now a few places in the script I found this sub_lang = filename[-3].lower() but unfortunately changing those to .upper does nothing to change the output.

All files will end in .LAN.vtt or .ENG.srt or .123.ssa with a 3 character extension as well as a 3 character LANGUAGE code. The script I'm editing has the ability to output either 3 character or 2 character ISO codes, but for my use I will always be using 3.

I thought this would be a simple change but everything I've found does not seem to work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾`听者〃 2025-02-14 05:08:30

我发现自己的错误,我在争论错误的地方。
有一条行

def to_3_letter_lang(lang):
    try:
        return iso639.to_iso639_2(lang)

,当我添加.upper()时,它会按照我的意愿进行更改。我一直以为较早的参数指定.lower()这是问题所在,但这不是

这样:

def to_2_letter_lang(lang):
    try:
        return iso639.to_iso639_1(lang).upper()
    except iso639.NonExistentLanguageError:
        return False


def to_3_letter_lang(lang):
    try:
        return iso639.to_iso639_2(lang).upper()
    except iso639.NonExistentLanguageError:
        return False

如果有人有任何其他信息,我直到明天才能将其标记为解决要添加

以便答案是用.upper()标签,只需要将其附加到正确的字段上

I discovered my error, I was arguing the wrong place.
There a line

def to_3_letter_lang(lang):
    try:
        return iso639.to_iso639_2(lang)

that when I added the .upper() it altered it as I wanted. I had thought since the earlier argument specified the .lower() it was the problem, but it was not

The context of this:

def to_2_letter_lang(lang):
    try:
        return iso639.to_iso639_1(lang).upper()
    except iso639.NonExistentLanguageError:
        return False


def to_3_letter_lang(lang):
    try:
        return iso639.to_iso639_2(lang).upper()
    except iso639.NonExistentLanguageError:
        return False

I'll not mark it as solved until tomorrow if anyone has any further information to add

So the answer is with the .upper() tag, it just needs to be attached to the correct field

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文