https://github.com/wklchris/python-sgfutil
为棋类爱好者开发的一个 SGF 操作库。| An SGF utilization library for Go/chess game players.
https://github.com/wklchris/python-sgfutil
chess-games par python3 sgf
Last synced: 4 months ago
JSON representation
为棋类爱好者开发的一个 SGF 操作库。| An SGF utilization library for Go/chess game players.
- Host: GitHub
- URL: https://github.com/wklchris/python-sgfutil
- Owner: wklchris
- License: mit
- Created: 2021-03-31T04:04:38.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-23T06:05:16.000Z (almost 5 years ago)
- Last Synced: 2025-01-14T02:04:10.901Z (about 1 year ago)
- Topics: chess-games, par, python3, sgf
- Language: Python
- Homepage:
- Size: 442 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: ReadMe-auto.py
- License: LICENSE
Awesome Lists containing this project
README
# Modified from: https://stackoverflow.com/questions/59078333
import code
import enum
import sys
from io import StringIO
import pyperclip
import re
with open('demo.py', 'r', encoding='utf8') as f:
filestr = f.read()
splits = re.split(r'("""[\s\S]*?""")', filestr)
cmd_str = ''.join([f"READMEAUTO={i}" if s.startswith('"""') else s for i, s in enumerate(splits)])
file = StringIO(cmd_str)
def readfunc(prompt):
try:
line = next(file).rstrip()
except StopIteration:
raise EOFError
print(prompt, line, sep='')
return line
stdout = sys.stdout
sys.stdout = StringIO()
code.interact(readfunc=readfunc)
output = sys.stdout.getvalue()
sys.stdout = stdout
# Post-process: replace back Readme paragraphs
for i, s in enumerate(splits):
if s.startswith('"""'):
output = output.replace(f">>> READMEAUTO={i}", "```" + s.strip('"') + "```")
output = output.strip("`") + "```"
print(output)
pyperclip.copy(output)