粘贴时自动去掉python码前的数字
Automatically strip the number in front of python codes when pasting
当我阅读电子书或网站时,我显然可以复制并粘贴 python 代码,而不是低效地编写所有代码。但是有时 python 代码的格式在实际的 python 代码行前面有一个 数字、一个句点和一个 space,不知有没有technique/tools自动删除?例如,来自...
68. # File name: floatlayout.py
69.
70. from kivy.app import App
71. from kivy.uix.floatlayout import FloatLayout
到...
# File name: floatlayout.py
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
def remove_spaces(file_path):
with open(file_path) as myfile, open('newfile.py', mode='w+') as newfile:
for line in myfile:
idx = line.find(' ')
if idx < 0 or idx + 1 >= len(line) or is_int(line.strip()[:-1]):
newfile.write('\n')
continue
newfile.write(line[idx+1:] + '\n')
def is_int(str):
try: int(str)
except: return False
return True
当我阅读电子书或网站时,我显然可以复制并粘贴 python 代码,而不是低效地编写所有代码。但是有时 python 代码的格式在实际的 python 代码行前面有一个 数字、一个句点和一个 space,不知有没有technique/tools自动删除?例如,来自...
68. # File name: floatlayout.py
69.
70. from kivy.app import App
71. from kivy.uix.floatlayout import FloatLayout
到...
# File name: floatlayout.py
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
def remove_spaces(file_path):
with open(file_path) as myfile, open('newfile.py', mode='w+') as newfile:
for line in myfile:
idx = line.find(' ')
if idx < 0 or idx + 1 >= len(line) or is_int(line.strip()[:-1]):
newfile.write('\n')
continue
newfile.write(line[idx+1:] + '\n')
def is_int(str):
try: int(str)
except: return False
return True