switch_source()用于获取文本信息
rewrite_source()用于将信息顺序轮换,其参数times表示要轮换多少次,
def switch_source():
tmp = []
with open('switch_source.txt','r') as ss:
for i in ss:
tmp.append(i.strip())
return tmp
def rewrite_source(times):
tmp = switch_source()
for i in range(times):
tmp.append(tmp[i])
for i in range(times):
tmp.remove(tmp[i - i])
with open('switch_source.txt','w') as rew_src:
for i in tmp:
rew_src.write(str(i) + ' ')
rewrite_source(2)
switch_source.txt原始内容如下:
1
2
3
4
5
轮换2次后效果为:
3
4
5
1
2