我对 python 很陌生,所以这可能有一个非常明显和简单的解决方案,但它是:我创建了一个自定义模块,将其导入另一个脚本 [script2],并希望使用 script2 中定义的局部变量作为导入模块中函数的参数
模块:
def encrypt(inputstr, securitykey = 1, encryptionkey = 1, decryptionkey = 1): #default value of keys is 1
inputstr = str(inputstr)
[converts inputed string into number ids based on encryption key and security key; this is like a 80 line long process, so I won't show it here]
inputstr = int(inputstr)
inputstr = inputstr * decryptionkey * securitykey
inputstr = str(int(inputstr)) #<this is stupid, I know, but for some reason this was the only way it worked
return inputstr
脚本2:
from ModuleDirectory import encryption
msg = input("Enter your message: \n \n")
seckey = input("Enter security key: \n \n")
enckey = input("Enter enrcyption key: \n \n")
deckey = input("Enter decryption key: \n \n")
encrypted = encryption.encrypt(msg,seckey,enckey,deckey)
print(encrypted)
当我这样做时,我得到一个 NameError。如何告诉 Python 我想使用 script2 中定义的变量作为我从模块导入的函数的参数?正如我所说,我对 Python 还很陌生,所以我可能只是个白痴。