import pyperclip
from pathlib2 import Path
import os
def creteTXT():
current_path = os.path.abspath(__file__)
parent_dir = os.path.dirname(current_path)
if os.path.exists('lest.txt')==False:
full_path = parent_dir + '\\lest.txt'
file = open(full_path, 'w')
# print(file)
file.close()
return parent_dir
file_list = creteTXT() + '\lest.txt'
filepath = file_list.replace("\\","/")
print("txt文件路径:" + filepath)
def readtest():
file = open(filepath, mode='r')
# print(file)
data = file.read()
# print(data)
file.close()
if data=="":
writetest()
else:
wosnfai()
def writetest():
a = input("请输入: ")
file = open(filepath, mode='w', encoding='utf-8')
# write 写入
file.write(a)
# 关闭文件,不关闭文件可能会出问题
file.close()
wosnfai()
def dewritetest():
a = input("请输入你: ")
if len(a) != 6:
panduan()
file = open(filepath, mode='w', encoding='utf-8')
# write 写入
file.write(a)
# 关闭文件,不关闭文件可能会出问题
file.close()
def panduan():
print("校验错误,请重~ ")
dewritetest()
def wosnfai():
for i in range(100):
a = input("请输单号: ")
if a == "123456":
dewritetest()
else:
print(a)
readtest()
python修改txt写入内容校验一下
最新推荐文章于 2024-10-02 10:53:34 发布