Created
December 23, 2020 04:24
-
-
Save Xevion/e8677db28d50180412f2eaaad0180e4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InfiniteError(Exception): | |
def __init__(self, func): | |
super().__init__("Oops!") | |
func() | |
def func(): | |
"""Very useful docstring. | |
Long enough so lemon approves. | |
""" | |
raise InfiniteError(func) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
content = """class Oops(Exception): | |
\"\"\"Oops!\"\"\" | |
pass""" | |
import os, sys | |
# path to exception file | |
path = os.path.join(sys.path[0], 'exception.py') | |
for x in range(1,4378): | |
print(x) | |
# if arbitrary conditions apply | |
if (x % 7 == 0) and ((x * 2) % 19 == 0): | |
# open file, write our exception to it | |
file = open(path, 'w+') | |
file.write(content) | |
file.close() | |
# import exception then delete file | |
from exception import Oops | |
os.remove(path) | |
# Oops! | |
raise Oops('Oops!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
value = True | |
{True: 'String ok', False: 'String nok'}[value == 'ok'] | |
('NOT OK', 'OK')[value == "ok"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment