我已经在这个Python程序上工作了几周,终于在Ubuntu Bionic上使其工作了。他们必须具有较旧的Python版本,因为在Arch Linux的Reborn OS上,该程序将无法运行。它得到语法错误。 Ubuntu上的一个是2.7.15,而Reborn OS上的是3.6.6。我收到以下错误:
[caden@Reborn ~]$ python ~/Dropbox/kodebyter/kodebyter.py
File "/home/caden/Dropbox/kodebyter/kodebyter.py", line 34
print str(rotation)
^
SyntaxError: invalid syntax
我的脚本是这样的:
import string
import collections
def caesar(rotate_string, number_to_rotate_by):
upper = collections.deque(string.ascii_uppercase)
lower = collections.deque(string.ascii_lowercase)
upper.rotate(number_to_rotate_by)
lower.rotate(number_to_rotate_by)
upper = ''.join(list(upper))
lower = ''.join(list(lower))
return rotate_string.translate(string.maketrans(string.ascii_uppercase, upper)).translate(string.maketrans(string.ascii_lowercase, lower))
print("Welcome to Kode Byter!")
print("Press Ctrl+C at any time to exit")
print("Press Ctrl+Shift+C to copy")
print("Press Ctrl+Shift+V to paste")
print("Will exit in 5")
print("Enter message:")
message = raw_input()
print("Enter rotation:")
rotation = raw_input()
print str(rotation)
print caesar(message, int(rotation))
print("Will exit in 4")
print("Enter message:")
message = raw_input()
print("Enter rotation:")
rotation = raw_input()
print str(rotation)
print caesar(message, int(rotation))
print("Will exit in 3")
print("Enter message:")
message = raw_input()
print("Enter rotation:")
rotation = raw_input()
print str(rotation)
print caesar(message, int(rotation))
print("Will exit in 2")
print("Enter message:")
message = raw_input()
print("Enter rotation:")
rotation = raw_input()
print str(rotation)
print caesar(message, int(rotation))
print("Will exit in 1")
print("Enter message:")
message = raw_input()
print("Enter rotation:")
rotation = raw_input()
print str(rotation)
print caesar(message, int(rotation))
print("Will exit in 0")
print("Press enter to exit...")
exit = raw_input()
我需要使用它来处理Arch Linux,因为我将其制作成Arch Linux软件包,以便用户从pacman安装。