简体   繁体   English

python 代码不起作用。 解密不会返回解密的短语

[英]python code just won't work. the decryption doesn't return back the decrypted phrase

I tried putting print hello's everywhere and tried to find what wasn't working, and the if filename == x part wouldn't work.我尝试将 print hello's 放在任何地方,并试图找出什么不起作用,并且 if filename == x 部分不起作用。 there certainly is the text.txt file.肯定有 text.txt 文件。 the program won't respond.程序不会响应。 It's like the code doesn't exist please help好像代码不存在请帮忙

import os
def translate(y):
    y = y.replace("quebrqerubfq92983rgh", "A")

x = "text.txt"
a = os.path.realpath(__file__)
a = a.split(":")
a = a[0]
for foldername, subfolders, filenames in os.walk(a + ":"):
    for subfolder in subfolders:
        for filename in filenames:
            if filename == x:
                s = open(x, "r")
                y = s.read()
                y = str(y)
                result = translate(y)
                s = s.close()

You are not printing, returning, nor writing anything, that's your problem.你没有打印、返回或写任何东西,那是你的问题。 Your translate function needs a return.您的translate function 需要退货。 And what do you want to do with y after you translated it?翻译后你想用y做什么?

Edit: try this out.编辑:试试这个。

import os
def translate(y):
    y = y.replace("quebrqerubfq92983rgh", "A")
    return y

x = "text.txt"
a = os.path.realpath(__file__)
a = a.split(":")
a = a[0]
for foldername, subfolders, filenames in os.walk(a + ":"):
    for subfolder in subfolders:
        for filename in filenames:
            if filename == x:
                s = open(x, "r")
                y = s.read()
                y = str(y)
                result = translate(y)
                s = s.close()

print(result)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM