📜  Python 程序从文件中读取随机行 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:15.033000             🧑  作者: Mango

代码示例2
import random
def randnum(fname):
    lines=open(fname).read().splitlines()
    print(lines)
    return random.choice(lines)

print(randnum('file1.txt'))