-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_dealing.py
154 lines (132 loc) · 2.83 KB
/
file_dealing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "Bonnie Li"
# Email: bonnie922713@126.com
# Date: 4/8/18
# read
# f = open('model.txt','r')
#
# for line in f:
# print(line.strip())
#
# f.close()
#write +append
# f = open('model_1.txt','r',encoding='utf-8')
# print(f.readable())
# f.write('\n'+'路飞学成1')
# f.close()
#r+ 都写模式
# f = open('model.txt','r+')
# data = f.read()
#
# print('content',data)
#
# f.write('\nnew line 1')
# f.write('\nnew line 2')
#
# print('content',f.read())
#
# f.close()
#w+ 写度模式
# readable()
#随意位置加入 ,缺点是可能会覆盖了之前的数据,不建议
# f = open('model.txt','r+')
#
# f.seek(10)
#
# f.write('edifer 333')
#
# f.close()
#占硬盘的插入方式
# import os
#
# f_name = 'model.txt'
# f_new_name = '%s.new' %f_name
#
# old_str = 'bonnie'
# new_str = '花花'
#
# f = open(f_name,'r')
# f_new = open(f_new_name,'w')
#
# for line in f:
# if old_str in line:
# line = line.replace(old_str,new_str)
# f_new.write(line)
#
# f.close()
# f_new.close()
#
# os.rename(f_new_name,f_name)
# 占内存模式的
# f = open('model.txt','r+')
#
# data = f.read()
#
# new_data = data.replace('123', "huahua")
#
# print(new_data)
#
# f.seek(0)
#
# f.write(new_data)
# f.close()
# #homework_1
#
# import sys
# import os
#
# file_name = sys.argv[1]
# file_name_new = 'model_new.txt'
# f1 = open(file_name_new,'w')
#
# old_str = sys.argv[2]
# new_str = sys.argv[3]
#
# with open(file_name,'r') as f:
# for line in f:
# if old_str in line:
# line = line.replace(old_str,new_str)
# print(line)
# f1.write(line)
#
# f1.close()
#
# os.rename(file_name_new,file_name)
#homework 2
user_info = []
count = 0
password_count = 0
passward_flag = True
f = open('model_1.txt','r')
f1 = open('user_1.txt','w')
while True:
name = input('input your name >>').strip()
for line in f:
user_info = line.split()
if name == user_info[0]:
if user_info[2] == 'lock':
exit("you have tried 3 time, please try next day'")
else:
while passward_flag:
passward = input('input your password>>').strip()
if passward == user_info[1]:
print('welcome')
exit()
else:
password_count+=1
if password_count == 3:
passward_flag = False
else:
passward_flag = True
print('input 3 times for the wrong passward')
break
line = line.replace('unlock','lock')
# else:
# print('input your name again>>')
f1.write(line)
else:
count+=1
f.close()
f1.close()
# print('you have tried 3 time')