擅长:python、mysql、java
<p>这里是您的代码稍微修改一下,使其工作</p>
<pre><code>#!/usr/bin/python
fo=open("/home/asb/crt/id2tcpvpncom443.ovpn")
for line in fo:
if line.strip().startswith('remote'): # startswith is a bit more direct here
vpn=line.split() # split without argument splits at any whitespace
if len(vpn) > 2: # not necessary but defensive -> good
servervpn=vpn[1]
hostvpn=vpn[1]
portvpn=vpn[2]
# if you like you can short-circuit here:
break
print 'server: ' + ':'.join([servervpn, portvpn])
</code></pre>