我正在尝试制作一个将我连接到VPN Server'编号'(此编号作为变量)的Python脚本
我写道:
import os
VPNServer = 0
VPNServer += 1
os.system("networksetup -connectpppoeservice 'VPNServer {servernumber}'").format(servernumber = str(VPNServer))
print("→ Successfully connected to", "VPNServer", VPNServer)
但是每次我尝试运行它时,控制台都会给我一个AttributeError
AttributeError: 'int' object has no attribute 'format'
我不理解,因为我使用了变量的字符串版本
[如果有人可以帮助,那将非常酷
我在macOS上,正在使用Python 3.8.1
在您提供的代码段中,您写
os.system('<some string>').format(args)
您正在调用format
的返回值,该返回值恰好是整数。这等同于写,例如
os.system
由于os.system
对象没有属性5.format(args)
,所以您获得了您描述的int
。
您要写的是
format
在这种情况下,您的摘要应该重新显示
AttributeError