"""
Dumps `dis` tokens to `tokens.py`.
"""
import dis
import sys

s = """# _V!{version_info}
# This file was automatically generated by `dump_dis.py`.
# This file is designed for Python {version_info}.
import sys

# Check Python version
if sys.version_info[0:2] != {version_info}:
    raise SystemError("Inappropriate Python version for these bytecode symbols.")

# Begin tokens. These are ordered.
""".format(version_info=sys.version_info[0:2])

# iterate over and dump
for op, value in sorted(dis.opmap.items(), key=lambda x: x[1]):
    # format
    s += "\n{token} = {val}".format(token=op, val=value)

s += "\n"
# Save file
with open("tokens.py", 'w') as f:
    f.write(s)

"""
Dumps `dis` tokens to `tokens.py`.
"""
import dis
import sys

s = """# _V!{version_info}
# This file was automatically generated by `dump_dis.py`.
# This file is designed for Python {version_info}.
import sys

# Check Python version
if sys.version_info[0:2] != {version_info}:
    raise SystemError("Inappropriate Python version for these bytecode symbols.")

# Begin tokens. These are ordered.
""".format(version_info=sys.version_info[0:2])

# iterate over and dump
for op, value in sorted(dis.opmap.items(), key=lambda x: x[1]):
    # format
    s += "\n{token} = {val}".format(token=op, val=value)

s += "\n"
# Save file
with open("tokens.py", 'w') as f:
    f.write(s)

Dumps `dis` tokens to `tokens.py`. # _V!{version_info} # This file was automatically generated by `dump_dis.py`. # This file is designed for Python {version_info}. import sys  # Check Python version if sys.version_info[0:2] != {version_info}:     raise SystemError("Inappropriate Python version for these bytecode symbols.")  # Begin tokens. These are ordered. # iterate over and dump # format # Save file