Think before you speak, read before you think.

python随机取出列表元素

dns 三台,分别选出一台和两台

#!/usr/bin/env python
import random

resolv_servers = ['192.168.1.1', '192.168.1.2', '192.168.1.3']
# 选出一个
print random.choice(resolv_servers)
# 选出两个,做为一个列表
print random.sample(resolv_servers, 2)

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *