【问题标题】:i have txt file have numbers like this 888|33/22|000 how can i print only one of 888 or 03/22 or 000我有 txt 文件有这样的数字 888|33/22|000 我怎样才能只打印 888 或 03/22 或 000 之一
【发布时间】:2021-05-27 19:26:09
【问题描述】:

我的 txt 文件有这样的数字 888|33/22|000 我如何只打印 888 或 03/22 或 000 之一

如何只打印 888 或 03/22 或 000 之一


888|33/22|000
with open('jack.txt') as fp:
   line = fp.readline()
   cnt = 1
   while line:
       print(cyan,time.asctime(time.localtime(time.time())),gr,"Plugin or Extension {} \033[1;37;40m : {} ".format(cnt, line.strip()))
       time.sleep(0.0001)
       print (part.of.lin)e


output
888

【问题讨论】:

  • 拆分并随机选择一个

标签: python-3.x list readline


【解决方案1】:

逐行随机抽取一个

import random
 
x = "888|33/22|000"

x = x.split('|')

print(random.choice(x))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    • 2021-04-18
    相关资源
    最近更新 更多