在IT圈子里,大家经常调侃,程序员最熟练的两个快捷键是ctrl+c 和 ctrl+v。
最近,播妞在知乎上看到一个问题很有意思,程序员被老板发现从网上抄代码,后果是怎么样?该问题的浏览量已经超过3万+,不少程序员在下方留言回答。
也经常有人好奇,程序员都在抄代码,而且还拿着不错的薪水?
也太轻松了吧?今天,我们就来聊聊程序员“抄”代码的那些事!
下面介绍 python 抄代码方法之一:
开始是这样:
抄完后是这样:
上代码:replace.txt
[{'old': '<', 'new': '<'},
{'old': '>', 'new': '>'},
{'old': '@', 'new': '@'},
{'old': '=', 'new': '='},
{'old': '"', 'new': '"'},
{'old': ''', 'new': "'"},
{'old': '+', 'new': '+'},
{'old': ',', 'new': ','},
{'old': '(', 'new': '('},
{'old': ')', 'new': ')'},
{'old': ':', 'new': ':'},
{'old': ';', 'new': ';'},
{'old': '?', 'new': '?'},
{'old': '"', 'new': '"'},
{'old': '!', 'new': '!'},
{'old': '¥', 'new': '¥'},
{'old': '~', 'new': '~'}]
把要须要抄html代码 写入1.txt,效果如下:
<pre><span style="color:#0000ff;">import</span><span style="color:#000000;"> PIL.ImageOps
</span><span style="color:#0000ff;">from</span> PIL <span style="color:#0000ff;">import</span><span style="color:#000000;"> Image
img </span>= Image.open(<span style="color:#800000;">'</span><span style="color:#800000;">D:\\Desktop\\计算机视觉\\image\\0.png</span><span style="color:#800000;">'</span><span style="color:#000000;">)
img </span>= img.convert(<span style="color:#800000;">'</span><span style="color:#800000;">1</span><span style="color:#800000;">'</span><span style="color:#000000;">)
img.show()
img </span>= img.convert(<span style="color:#800000;">'</span><span style="color:#800000;">L</span><span style="color:#800000;">'</span><span style="color:#000000;">)
img </span>=<span style="color:#000000;"> PIL.ImageOps.invert(img)
img </span>= img.convert(<span style="color:#800000;">'</span><span style="color:#800000;">1</span><span style="color:#800000;">'</span><span style="color:#000000;">)
img.show()</span></pre>
主程序 2.py
def replace_data(str_):
f = open("replace.txt", 'r', encoding="utf8")
data = f.read()
# 判断文件是否为空
if len(data) > 0:
# 从文件中获取的数据默认是字符串类型的数据
data = eval(data)
# 把数据加载到了 replace_info_list
replace_info_list = data
for key in replace_info_list:
str_=str_.replace(key['old'],key['new'])
f.close()
return str_
def str_all_index(str_,a):
index_list=[]
start=0
while True:
x=str_.find(a,start)
if x>-1:
start=x+1
index_list.append(x)
else:
break
return index_list
rf = open("1.txt","r",encoding="utf8")
ts=rf.read()
one=str_all_index(ts,"<")
two=str_all_index(ts,">")
str_list=[]
for i in range(len(one)): #利用列表a的长度设置遍历次数
str_list.append(ts[int(one[i]):int(two[i])+1])
str_list=set(str_list)
for i in str_list:
ts=ts.replace(i,'')
ts=replace_data(ts)
wf = open('2.txt', "w", encoding="utf8")
#文件必须存储字符串数据
wf.write(ts)
wf.close()
rf.close()
运行 2.bat
python 2.py
pause
生成文件 2.txt ,效果如下:
import PIL.ImageOps
from PIL import Image
img = Image.open('D:\\Desktop\\计算机视觉\\image\\0.png')
img = img.convert('1')
img.show()
img = img.convert('L')
img = PIL.ImageOps.invert(img)
img = img.convert('1')
img.show()
源代码,欢迎大家下载:
https://download.csdn.net/download/liujava56/88049477?spm=1001.2014.3001.5503