Python
5
Вклад в тег
with open('tmp', 'w') as file:
file.write('line 1\n')
with open('tmp', 'a') as file:
file.write('line 2\n')
with open('tmp', 'r+') as fd:
contents = fd.readlines()
contents.insert(1, 'line 3\n')
fd.seek(0)
fd.writelines(contents)
with open('tmp', 'r+') as fd:
contents = fd.readlines()
contents.insert(2, 'line 4\n')
fd.seek(0)
fd.writelines(contents)
with open('tmp') as f:
for line in f:
print(line, end="")
import re
# Если скидку сделать отрицательной, то будет наценка 20% :)
discount = 0.2
def repl(match):
return str(int(float(match.group(0)) * (1 - discount)))
with open('table.html', 'r+') as fd:
new_lines = [re.sub(r'(\d+)', repl, line) for line in fd]
fd.seek(0)
fd.writelines(new_lines)