Skip to content

Instantly share code, notes, and snippets.

@ids1024 ids1024/pyg-i.py forked from Synthetica9/pyg.py
Last active Aug 29, 2015

Embed
What would you like to do?
#!/bin/python3
#This is a fork of PYG (https://gist.github.com/Synthetica9/9796173) ported
#to python 3 with additional features.
#It requires forbiddenfruit to hack method aliases into built-in types.
#A golfed python 'accent'. Fully backwards compatible with python.
#NOT SUITED FOR DAY-TO-DAY PROGRAMMING!
#If you DO use it for a production (non-challenge/codegolf) program, I'm not
#responsible for anything bad that happens to you, your computer,
#your spare time, your code maintainability, any kittens that god might kill,
#or the tears of blood you will weep.
import sys
from math import *
Ex=sys.exit
Al=all
An=any
import collections
C=collections
CC = C.Counter
CD = C.deque
Cd = C.defaultdict
Cn = C.namedtuple
CO = C.OrderedDict
D=dict
E=eval
En=enumerate
F=None
G=None
H=None
I=__import__
Ip=input
import itertools
It=itertools
ItCo = It.count
ItCy = It.cycle
ItRe = It.repeat
ItCh = It.chain
ItCo = It.compress
ItDW = It.dropwhile
ItGB = It.groupby
ItiS = It.islice
ItSM = It.starmap
Itt = It.tee
ItTW = It.takewhile
ItiZL= It.zip_longest
ItPr = It.product
ItPe = It.permutations
ItCo = It.combinations
ItCoR= It.combinations_with_replacement
def J(iterable):
return "".join(iterable)
K=1000
L=list
M=map
Mx=max
Mn=min
N="\n"
O=None
P=print
#Print expand
def Pe(*args):
for arg in args:
print()
for subarg in arg:
print(subarg)
#Print joined
def PJ(*args):
print(J(args))
Q=None #Quine, this is defined later on.
R=range
import random
Ra=random
#Probably not neccesary, but hey :)
RaSe = Ra.seed
RaGS = Ra.getstate
RaSS = Ra.setstate
RaRB = Ra.getrandbits
#The interesting part:
RR = Ra.randrange
RI = Ra.randint
RS = Ra.shuffle
RC = Ra.choice
RSm = Ra.sample
RR = Ra.random
RU = Ra.uniform
RT = Ra.triangular
RBv = Ra.betavariate
REv = Ra.expovariate
RGv = Ra.gammavariate
RG = Ra.gauss
RLv = Ra.lognormvariate
RNv = Ra.normalvariate
RVv = Ra.vonmisesvariate
RPv = random.paretovariate
RWv = random.weibullvariate
import re
Re=re
#TODO: Add short notations
S=sorted
Se=set
Sp=" "
import string
ST=string
STl = string.ascii_letters
STlc = string.ascii_lowercase
STuc = string.ascii_uppercase
STd = string.digits
STod = string.octdigits
STp = string.punctuation
STP = string.printable
STw = string.whitespace
try:
STDI = sys.stdin
except AttributeError:
STDI = None
T=tuple
U=None
V=None
W=None
X=range
Y=None
Z=zip
#Hack methods of builtins
#Requires forbiddenfruit module
from forbiddenfruit import curse
curse(str, "f", str.format)
curse(str, "fi", str.find)
curse(str, "u", str.upper)
curse(str, "l", str.lower)
curse(str, "r", str.replace)
curse(str, "j", str.join)
curse(str, "c", str.count)
curse(str, "ca", str.capitalize)
curse(str, "e", str.encode)
curse(str, "in", str.index)
curse(str, "s", str.split)
curse(str, "st", str.strip)
curse(str, "t", str.translate)
curse(bytes, "d", bytes.decode)
curse(list, "i", list.insert)
curse(list, "in", list.index)
curse(list, "a", list.append)
curse(list, "p", list.pop)
curse(list, "c", list.count)
curse(list, "cl", list.clear)
curse(list, "cp", list.copy)
curse(list, "r", list.remove)
curse(list, "rv", list.reverse)
curse(set, "d", set.discard)
curse(set, "cp", set.copy)
if len(sys.argv)==1:
print("Usage: python",sys.argv[0],"[filename]")
else:
fle=open(sys.argv[1])
code=Q=fle.read()
#Q stands for quine. P(Q) works.
code=code.replace('λ ','lambda') #TODO: add \ escaping or some other method of using literal λ in code
code=code.replace('ι','while 1:')
code=code.replace('α','def a():')
code=code.replace('β','def b(x):')
code=code.replace('ε','else:')
code=code.replace('η','else if')
#Working on this \|/
"""
#This will attempt to close your parrens. DO CLOSE YOUR STRINGS!
parrens={"(":")","{":"}","[":"]"}
reqparrens=" "
for char in code:
if char in parrens:
reqparrens=parrens[char]+reqparrens
elif char == reqparrens[0]:
"""
exec(code)
fle.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.