We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.
Pyline Classic
Jump to navigation
Jump to search
Pyline Classic is an esoteric subset of Python 3.5 where the whole source file has to be a single expression. Unlike Pyline, which has a walrus operator, Pyline Classic does not have an ergonomic variable-assignment expression.
Idioms
| Python | Pyline Classic |
|---|---|
if 1 + 1 == 2:
print("Hello, ")
print("World! ")
|
1 + 1 == 2 and (
print("Hello, "),
print("World! ")
)
(
print("Hello, "),
print("World! "),
) if 1 + 1 == 2 else None
(
print("Hello, ") and 0 or
print("World! ")
) if 1 + 1 == 2 else None
|
if i == 1:
...
elif i == 2:
...
else:
...
|
(
...
) if i == 1 else (
...
) if i == 2 else (
...
)
|
for i in range(10):
print(i)
|
all( (print(i),) for i in range(10) ) [(
print(i),
) for i in range(10)]
next(
None for i in range(10)
if not (
print(i) and 0 or
True
)
)
|
while cond:
print(1)
|
all( cond and (print(1),) for _ in iter(int,1) ) [(
print(1),
) for _ in iter(lambda: cond, False)]
next(
None for _ in __import__("itertools").count()
if not (
print(1) and 0 or
cond
)
)
|
arr[0] += 1 |
arr.insert(0, arr.pop(0) + 1) arr.__setitem__(0, arr[0] + 1) |
obj.var = 5 |
setattr(obj, "var", 5) |
raise err |
(_ for _ in "_").throw(err) |
Examples
Hello World
print("hello world")
Quine
(lambda s:print(f'{s}({chr(34)}{s}{chr(34)})'))("(lambda s:print(f'{s}({chr(34)}{s}{chr(34)})'))")
A shorter one:
print((lambda s:s%s)('print((lambda s:s%%s)(%r))'))
Truth machine
[print("1", end="") for _ in __import__("itertools").count()] if input(":") == "1" else print("0")
A version that doesn't use __import__:
[print(1,end="")for _ in iter(lambda:0,1)]if input(":")=="1"else print(0)
A shorter one:
input()=="1"and{print(end="1")for _ in iter(set,0)}or print(0)
Print 0 to 49
(
lambda obj:
all(
obj.a<50 and (
print(obj.a),
setattr(obj,'a',obj.a+1)
)
for _ in iter(int,1)
)
)(type('obj',(),{'a':0}))
This approach achieves something similar to local scope without having to modify the global like __builtins__ does
Brainfuck interpreter
(setattr(__builtins__,'i',input),
setattr(__builtins__,'p',i()),
setattr(__builtins__,'c',0),
setattr(__builtins__,'l',[0]),
setattr(__builtins__,'r',[0]),
setattr(__builtins__,'s',lambda l,i,e:l.__setitem__(i,e)),
setattr(__builtins__,'a',lambda l,e:l.append(e)),
[(setattr(__builtins__,'o',p[c]),
setattr(__builtins__,'ll',len(l)-1),
setattr(__builtins__,'lr',len(r)-1),
setattr(__builtins__,'lf',l[-1]),
setattr(__builtins__,'rf',r[-1]),
(
(
(o=='+')and s(l,ll,(lf+1)%256)),
(o=='-')and s(l,ll,(lf-1)%256),
(o=='<')and(a(r,lf),(ll>0)and l.pop()),
(o=='>')and(a(l,rf),(lr>0)and r.pop()),
(o=='.')and(print(chr(lf),end='',flush=1)),
(o==',')and(l.pop(),a(l,ord(i()or chr(lf))%256)),
setattr(__builtins__,'c',c+1)
)
if not o in '[]'else
(setattr(__builtins__,'b',c),
setattr(__builtins__,'j',1),
setattr(__builtins__,'m',[-1,1][o=='[']),
[(setattr(__builtins__,'b',b+m),setattr(__builtins__,'n',p[b]),
(n=='[')and setattr(__builtins__,'j',j+m),
(n==']')and setattr(__builtins__,'j',j-m)
)
for _ in iter(lambda:j,0)],
setattr(__builtins__,'c',b)if [lf,lf==0][(m+1)//2] else setattr(__builtins__,'c',c+1)
)
)
for _ in iter(lambda:len(p)>c,0)]
)
Underload interpreter
Written by User:I am islptng.
(lambda code,_=type("",(object,),{"_":lambda s,l,v:setattr(s,l,v)})():(
_._("stack",[]),
_._("prog",list(code)[::-1]),
[None for __ in iter(lambda:_.prog,[]) if _._("l",_.prog.pop()) or (
_.stack.append(_.stack.pop(-2)+_.stack.pop()) if _.l == "*"
else _.prog.extend(list(_.stack.pop())[::-1]) if _.l == "^"
else _.stack.append(_.stack.pop(-2)) if _.l == "~"
else _.stack.append(_.stack[-1]) if _.l == ":"
else _.stack.pop() if _.l == "!"
else _.stack.append("("+_.stack.pop()+")") if _.l == "a"
else print(end=_.stack.pop()) if _.l == "S"
else (
_._("bs",""),
_._("depth",1),
all(_.depth != 0 and (
_._("ch",_.prog.pop()),
_._("bs",_.bs+_.ch),
_._("depth",_.depth+1) if _.ch == "("
else _._("depth",_.depth-1) if _.ch == ")"
else None
) for __ in iter(int,1)),
_.stack.append(_.bs[:-1])
) if _.l == "(" else ")"
) and False]
))("""(:(1)*(:(2)*(:(3)*(:(4)*(:(5)*(:(6)*(:(7)*(:(8)*(:(9)*(!~:^)))))))))):(
)!(~^~(~a~*~a~*)~a*^:(0)*)~a*~:(a(:^)*())~*a(:^)*~()~(0)((!^~)())(
)!((:(~:(,)*S~^!^)~a*^:^~!a~^*a*)~a*^:^):^""")