直接貼出全部代碼吧,新手開始學py啦~
import random
import os
import linecache
def find():
txt = open(os.getcwd()+'/cookie.txt','rb')
data = txt.read().decode('utf-8') #python3一定要加上這句不然會編碼報錯!
txt.close()
n = data.count('\n')
i = random.randint(1, (n+1))
print("本次使用的行數",i) #我的文檔我數了一下是120行,這里就是1~121
###得到對應的i行的數據
line=linecache.getline(os.getcwd()+'/cookie.txt',i)
return line
print(find())
