PythonOnlineDebugger/parser.py

41 lines
1.0 KiB
Python

# This is a sample Python script.
# Press ⌃R to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint.
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
def write_file(name, content):
try:
file = open(name, 'w')
file.write(content)
file.close()
except Exception:
print()
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
content = ""
name = "a.txt"
with open('source.txt', 'r') as f:
for line in f.readlines():
if "----" in line and (".py" in line or ".txt" in line or ".out" in line or ".in" in line):
write_file(name, content)
name = line[6:len(line) - 1]
content = ""
else:
content = content + line