#esoteric-python

1 messages · Page 43 of 1

earnest snow
#

my memory's really bad so I probably misunderstood whatever I read

#

gonna search it up though

#

!e the same thing applies to integers smaller than 256

print(id(256 - 1) == id(255)) # True
#

how tf did I wrote ì as a typo?

night quarryBOT
earnest snow
#

don't know on how many other things this applies tbh

earnest snow
glacial lantern
#

id(256) gives me 140733508675992 on 3.12

arctic skiff
#

also on 3.12

#

3.12.3

#

(tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32

glacial lantern
#
print(id(301 - 1) == id(300))

This is also true for me.

arctic skiff
#

why it wouldn't?

glacial lantern
#

They wrote above that it's only true for [-5; 256], but maybe I misunderstand.

sly root
#

!e ```py
n = 10000
def _range_list():
[()for()in range(n)]

def _mul_list():
[()]*n

import dis
print(dis.dis(_range_list))
print("===================================\n")
print(dis.dis(_mul_list))

night quarryBOT
# sly root !e ```py n = 10000 def _range_list(): [()for()in range(n)] def _mul_list():...

:white_check_mark: Your 3.12 eval job has completed with return code 0.

001 |   2           0 RESUME                   0
002 | 
003 |   3           2 LOAD_GLOBAL              1 (NULL + range)
004 |              12 LOAD_GLOBAL              2 (n)
005 |              22 CALL                     1
006 |              30 GET_ITER
007 |              32 BUILD_LIST               0
008 |              34 SWAP                     2
009 |         >>   36 FOR_ITER                 5 (to 50)
010 |              40 UNPACK_SEQUENCE          0
011 |              44 LOAD_CONST               1 (())
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/ZMNJ4LEJFW5RU6X7DIJPX4FOOQ

sly root
#

the second is just getting optimized by the interpreter

fleet bridge
#

it is not optimized

#

it is doing exactly what is written there

twin roost
#

!e

test = lambda: 10**5
import dis
dis.dis(test)
night quarryBOT
twin roost
#

are there any other examples when python would do some simple calculations during compilation?

#

!e

test = lambda: 5+2*3+25**2
import dis
dis.dis(test)
night quarryBOT
twin roost
#

!e

test = lambda: 5+2*3+25**2+2.0
import dis
dis.dis(test)
night quarryBOT
twin roost
#

oh, it can do a type coercion

quartz wave
#

i don't have time to explain it yet since i need to go to school :>

versed eagle
#

constant expression folding

#

so its really id(300) == id(300)

#

!e ```py
import dis
dis.dis("id(301 - 1)")

night quarryBOT
versed eagle
#

see the LOAD_CONST (300)

quartz wave
#

!e ```py
x = 301
exec(f"print(id(x - 1) == id({x - 1}))")

night quarryBOT
fleet bridge
#

!e ```py
x = 301
print(x-1 is x-1)

night quarryBOT
fleet bridge
#

simpler

glacial lantern
#

Ok, now this actually works only up to and including 256.

#

Thx.

errant crescent
quartz wave
quartz wave
#

..who pinged me =へ=

arctic skiff
#

accidently

quartz wave
#

oki

pseudo ermine
#

a

arctic skiff
gleaming linden
#

@fallow ingot please use #bot-commands for testing code

fallow ingot
#

oh sorry

gleaming linden
#

no problem

scarlet mango
#

Yo

earnest snow
fleet bridge
#

it came from python2

earnest snow
#

why does it use print as output generator?

fleet bridge
#

because it is a debugging tool

earnest snow
#

K makes sense

versed eagle
earnest snow
#

doesnt returning your code as a data structure would be nice as well? or there's AST for that, (even though, this seems more powerful, haven't readed the entire file but, yk)

#

dis.Bytecode exists, I still don't like it though, and dis.Bytecode.dis returns a buffer instead of printing everything

versed eagle
#

with compile

earnest snow
# versed eagle its already as bytecode

yeah but I mean something like List[Instruction], but something a little bit more structurized, and Instruction with cached dissasembled data instead of recalculating it each time Instruction._disassemble is called

#

that's why I don't like just having that Bytecode

earnest snow
#

instead of raw bytecode, a struct Instruction containing information about the decompiled instruction, and if they were structurized in functions out of a module or something like that, it would also be useful for code-analizing tools; something like
dis(x, *, file=None, depth = None) -> List[Instruction] | Dict[str, List[Instruction]] | Bytecode (Bytecode because it could have it's input buffered and have smth like disassemble(2) which disassembles 2 instructions and gives that to you, some sort of buffered disassembly)
that may have not many usecases but seems more, idk, usable than printing everything as it's being disassembled instead of creating it into a data-object and then making functions to represent that

versed eagle
karmic pumice
versed eagle
#

thats not what i meant

karmic pumice
#

so what do you not know pithink

versed eagle
#

why a function would do this
List[Instruction] | Dict[str, List[Instruction]] | Bytecode

#

seems like a very weird design!

karmic pumice
#

perhaps

quartz wave
#

i thought this was common knowledgee =~=

earnest snow
unique heath
#

CEDS

quartz wave
#

nuuuu ><

#

IT"S NOT CHRONICC

dusty zodiac
#

DEES-N
Depraved Esopy Enthusiast Syndrome

quartz wave
#

anjnj.

versed eagle
#

you've been here for more than three months, after all

grave grail
#

Are there anyway to make so NameError is not raised but instead make it as a variable with a object of a custom class

fleet bridge
#

patch globals().__getitem__

#

or globals().__missing__

grave grail
#

Oh, nice idea, haven't thought of that

fleet bridge
#

i thought this was common knowledgee =~=

grave grail
#

But you have to think of the knowledge

quartz wave
#

STOPPPLR

grave grail
#

And well, I failed to make it lul

quartz wave
#

!e ```py
from ctypes import py_object
class A:
def init(self, x):
self.name = x

class globols(dict):
slots = ()
missing = lambda _, x: A(x)

py_object.from_address(id(globals())+tuple.itemsize).value = globols
print(b)

night quarryBOT
quartz wave
#

ehh =-=

fleet bridge
#

print is not a global variable, so A() is assigned to it

versed eagle
#

at least here

karmic pumice
#

!e

skibidi = "def"
dop = "main"
dоp = "()"
yes = " -> "
yеs = " None:"
hi = "print("
mark = "\"Hello, World!\")"
уes = "if __name__ == \"__main__\":"
уеs = "main()"

exec(f"""
{skibidi} {dop} {dоp} {yes} {yеs}
    {hi} {mark}
{уes}
    {уеs}
""")
night quarryBOT
quartz wave
night quarryBOT
versed eagle
#

since that already happens

quartz wave
#

mkay

#

!e ```py
from ctypes import py_object
class A:
def init(self, x):
self.name = x

py_object.from_address(id(builtins.dict)+tuple.itemsize).value = type("missing", (dict,), {"slots": (), "missing": lambda _, x: A(x)})

print(b)

night quarryBOT
quartz wave
#

yea that works

dusty zodiac
#
@lambda x : print(f'${x(input().split()):1.2f}')
def uwo(num):
    return sum(map(lambda x : {'quarter' : 0.25,'dime' : 0.10,'penny': 0.01,'nickel' : 0.05,}[x],num))
grave grail
#

Nice

import builtins
import io
import sys
import types
from ctypes import py_object
from forbiddenfruit import curse
from typing import Never, Type, Optional, Any

class MISSING:
    pass

class Undefined:
    def __init__(self, name: str):
        self._name = name
        self._value = MISSING()
    def __undefined__(self) -> Never:
        raise NameError(f'name \'{self._name}\' is undefined\'')
    def __del__(self):
        if not isinstance(self._value, MISSING):
            globals()[self._name] = self._value
    __add__ = __undefined__
    __radd__ = __undefined__
    __mul__ = __undefined__
    __rmul__ = __undefined__
    __sub__ = __undefined__
    __rsub__ = __undefined__
    __getitem__ = __undefined__
    __setitem__ = __undefined__
    __delitem__ = __undefined__
    __str__ = __undefined__
    __int__ = __undefined__
    __bool__ = __undefined__

def writer(self: io.TextIOWrapper, content):
    self.write(content)
    return self

def reader(self: io.TextIOWrapper, val: Undefined):
    name = val._name
    content = self.readline()
    val._value = content
    if name in locals():
        locals()[name] = content
    elif name in globals():
        globals()[name] = content
    return content

sys.ENDL = '\n'


class globols(dict):
    __slots__ = ()
    def __missing__(_, x, builtins=__builtins__) -> Any:
        try:
            return builtins.__dict__[x]
        except KeyError:
            return Undefined(x)

py_object.from_address(id(globals())+tuple.__itemsize__).value = globols


curse(io.TextIOWrapper, '__lshift__', writer)
curse(io.TextIOWrapper, '__rshift__', reader)
curse(str, '__lshift__', lambda x, y: x+y)

sys.stdin >> b
sys.stdout << b << sys.ENDL

Thx to ceweal and denball

uncut vale
#

Hello

versed eagle
#

plus it works in other modules :3

twin roost
#

!e

def local_function():
    def square(x):
        return x * x
    square(25)

def square(x):
    return x * x

def global_function():
    square(25)

import timeit
n = 10000000
print(timeit.timeit(local_function, number=n), local_function)
print(timeit.timeit(global_function, number=n), global_function)
night quarryBOT
twin roost
#

why local is slower?

#

I thought it's compiling square just once and save it to local_function.__code__.co_consts and then calling it inside local_function should be faster as it's local name and you don't need to go to globals() dictionary as it will do in global_function

quartz wave
twin roost
#

!e

def local_function():
    def square(x):
        return x * x
    square(25)

print(local_function.__code__.co_consts)
night quarryBOT
quartz wave
#

notice how it says "code object"

#

it only saves the compiled code (since it's guaranteed immutable under normal circumstances)

#

!e ```py
from dis import dis
def local_f():
def square(x):
return x * x
square(25)

def square(x):
return x * x

def global_f():
square(25)

dis(local_f)
print("---------------------------")
dis(global_f)

twin roost
#

ohhh

night quarryBOT
# quartz wave !e ```py from dis import dis def local_f(): def square(x): return x ...

:white_check_mark: Your 3.12 eval job has completed with return code 0.

001 |   2           0 RESUME                   0
002 | 
003 |   3           2 LOAD_CONST               1 (<code object square at 0x7ff76f4453b0, file "/home/main.py", line 3>)
004 |               4 MAKE_FUNCTION            0
005 |               6 STORE_FAST               0 (square)
006 | 
007 |   5           8 PUSH_NULL
008 |              10 LOAD_FAST                0 (square)
009 |              12 LOAD_CONST               2 (25)
010 |              14 CALL                     1
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/HA56KUDCNJLUNDVIYMQCOHXARM

twin roost
#

basically it still does square = FunctionType(...) every time

quartz wave
#

sorta

#

that takes up 3 extra instructions as you can see

twin roost
#

is there a way to avoid this?

#

and keep it local

quartz wave
#

yeah
put it in the defaults

#

!ti ```py
def square(x):
return x * x

def foo(square=square):
return square(25)

```py
foo()
night quarryBOT
quartz wave
#

!ti ```py
def square(x):
return x * x

def foo():
return square(25)

```py
foo()
night quarryBOT
quartz wave
#

!e ```py
from dis import dis
def square(x):
return x * x

def local_f(square=square):
square(25)

def global_f():
square(25)

dis(local_f)
print("---------------------------")
dis(global_f)

night quarryBOT
quartz wave
#

the 3 extra instructions are now gone :>

twin roost
#

!e

def create_local_function():
    def square(x):
        return x * x
    
    def local_function():
        return square(25)
    
    return local_function

# Create the local function once
local_function = create_local_function()

def square(x):
    return x * x

def global_function():
    square(25)

import timeit
n = 10000000
print(timeit.timeit(local_function, number=n), local_function)
print(timeit.timeit(global_function, number=n), global_function)
night quarryBOT
quartz wave
#

although it seems like global is still faster even with the default-value approach -.-

#

must be because of the combined PUSH_NULL in LOAD_GLOBAL

twin roost
#

was wondering how slow compilation at runtime would be

#

!e

def compile_at_runtime():
    def square(x):
        return x * x
    local_namespace = {}
    exec(compile("def square(x): return x * x", "<string>", "exec"), local_namespace)
    local_namespace["square"](25)

def square(x):
    return x * x

def global_function():
    square(25)
import timeit
n = 10000
print(timeit.timeit(compile_at_runtime, number=n), compile_at_runtime)
print(timeit.timeit(global_function, number=n), global_function)

night quarryBOT
twin roost
#

ahh, how can I make bot reload the code?

#

I believe there was some way to do it with reactions

#

basically results are

0.082665600000837 <function compile_at_runtime at 0x00000216AF6604A0>
0.0005457999995996943 <function global_function at 0x00000216AF8B2660>
quartz wave
#

although it only automatically adds it after an edit within 10 seconds of the thing being posted

#

so basically 10 seconds to edit the code

twin roost
#

got it, thanks

earnest snow
#

like with code.co_const compile it and pass it as an argument to the function being decorated

#

but idk how you would rewrite the function's code in runtime easily

#

could probably be done with some effort though

#

¿anyone wanna try? because I don't

magic wraith
#

here's where I first saw that in practice

#

other example is PjOrion obfuscation function generates python functions which take code objects, and then access their co_consts, which are also accessed by those code objects themselves (functions like these are specifically crafted for that)

earnest snow
#

A way of getting the bytecode and modifying it such that It doesnt 'load_const *' and then 'make_func' but call compile it, get It to an object and then get 'load_const' to the made function

#

If I knew how bytecode is encoded and decoded I could try, but it's just an idea

#

This hasnt got many usecases though

magic wraith
#

ah, you mean load_const the function, but instead of make_func then load_name, it would CALL it immediately?

earnest snow
#

Yeah

#

Because the decorator loaded the function already compiled it

#

¿Does that make sense?

magic wraith
#

hmm, i'll send an example in a few moments, so you tell me is that what you meant

earnest snow
#

K

magic wraith
#

!e first, code object and function object are not the same
MAKE_FUNCTION will consume the code object and spit a function object onto the stack, as demonstrated here: ```py
code1 = '''
import types

print(sentinel)
def print_square(x):
return print(x*x)
'''

import types,dis

def modify_bytecode(co, new_bytecode):
return types.CodeType(co.co_argcount, co.co_posonlyargcount, co.co_kwonlyargcount, co.co_nlocals, co.co_stacksize, co.co_flags, new_bytecode, co.co_consts, co.co_names, co.co_varnames, co.co_filename, co.co_name, co.co_qualname, co.co_firstlineno, co.co_linetable, co.co_exceptiontable)
co1 = compile(code1, 'filename', 'exec')
bytecode1 = bytearray(co1.co_code)

copy the LOAD_CONST and MAKE_FUNCTION bytecodes

to be the argument to print() call above

notice the function object gets printd

bytecode1[14:16] = bytecode1[26:30]
new_co = modify_bytecode(co1, bytes(bytecode1))
exec(new_co)
print('-'*47)
print(print_square)```

night quarryBOT
magic wraith
#

(to keep things short and clean I didn't send disassembly here, but you can just dis.dis(code1) yourself on python 3.12)

#

!e however I didn't manage to get it working with directly using the function object after MAKE_FUNCTION opcode, as opposed to STORE_NAME the function obj then LOAD_NAME it back, it probably has something to do with the PUSH_NULL

code2 = '''
import types
def print_square(x):
    return print(x*x)
sentinel(701)'''  # sentinel gets replaced
import types,dis

def modify_bytecode(co, new_bytecode):
    return types.CodeType(co.co_argcount, co.co_posonlyargcount, co.co_kwonlyargcount, co.co_nlocals, co.co_stacksize, co.co_flags, new_bytecode, co.co_consts, co.co_names, co.co_varnames, co.co_filename, co.co_name, co.co_qualname, co.co_firstlineno, co.co_linetable, co.co_exceptiontable)

co2 = compile(code2, 'filename', 'exec')
bytecode2 = bytearray(co2.co_code)
del bytecode2[14:20]
new_co2 = modify_bytecode(co2, bytes(bytecode2))
print('crashes here')
exec(new_co2)```
night quarryBOT
earnest snow
#

There's gotta be a way through that segfault

#

I get AttributeError: 'code' object has no attribute 'co_qualname'. Did you mean: 'co_filename'

versed eagle
earnest snow
#
  2           0 LOAD_CONST               0 (0)
              2 LOAD_CONST               1 (None)
              4 IMPORT_NAME              0 (types)
              6 STORE_NAME               0 (types)

  3           8 LOAD_CONST               2 (<code object print_square at 0x000002F6CD9C4240, file "filename", line 3>)
             10 LOAD_CONST               3 ('print_square')
             12 MAKE_FUNCTION            0
             14 CALL_FUNCTION            1

  5          16 POP_TOP
             18 LOAD_CONST               1 (None)
             20 RETURN_VALUE

Disassembly of <code object print_square at 0x000002F6CD9C4240, file "filename", line 3>:
  4           0 LOAD_GLOBAL              0 (print)
              2 LOAD_FAST                0 (x)
              4 LOAD_FAST                0 (x)
              6 BINARY_MULTIPLY
              8 CALL_FUNCTION            1
             10 RETURN_VALUE
earnest snow
#

does it usually do that or is it that some bytecode logic is wrong?

versed eagle
versed eagle
#

yes

earnest snow
#

?

versed eagle
#

thats the name of the function

earnest snow
#

K

#

if I wanted to encode LOAD_CONST (<function something at $ADDR>) into the bytecode, how would that be done?

#

😛

#

like create those instructions, and then replace that section of code with the newly made instructions

#

that point to a function object that has already been created

#

yk what I mean?

versed eagle
#

the code objects are

earnest snow
#

then how would that be done?

#

clap it into the function's locals?

#
def function(x):
    def example():pass
    print(x*x)

code = function.__code__
instructions = dis.get_instructions(code)
l = list(instructions)
# todo, do some search for this instructions, with dis I saw it was the first instruction, but, yk, search for it better
CODE_EXAMPLE_LOADED = l[0].argval 

func = types.FunctionType(CODE_EXAMPLE_LOADED, globals())
func.__name__ = 'example'
# todo, replace those instructions (from instruction 0 to instruction 3) with something to load the object `func` to the variable `example`

#

after that, create new code object and create new function object with that, dealloc original function and replace it with the new one

#

that's cursed now that I think 'bout it

#

and yeah, ik you can pass a name to the types.FunctionType constructor, but last time I checked it didnt work (I didnt check)

#

I'll think about it tomorrow

magic wraith
#

and then set that function something at the index 3 of co_consts

#

and, of course, make a new code object with that

#

!e @earnest snow ```py
import dis, types
code = '''def print_square(x):
print(x*x)
print_square(555)'''

def modify_bytecode(co, new_bytecode, new_consts):
return types.CodeType(co.co_argcount, co.co_posonlyargcount, co.co_kwonlyargcount, co.co_nlocals, co.co_stacksize, co.co_flags, new_bytecode, new_consts, co.co_names, co.co_varnames, co.co_filename, co.co_name, co.co_qualname, co.co_firstlineno, co.co_linetable, co.co_exceptiontable)

co = compile(code, 'xd', 'exec')

bytecode = bytearray(co.co_code)
bytecode[2:12] = [] # remove actual opcodes up to loading the number 555
bytecode[2:2] = [dis.opmap['LOAD_CONST'], 0]

consts = list(co.co_consts)
consts[0] = types.FunctionType(consts[0], globals())

new_co = modify_bytecode(co, bytes(bytecode), tuple(consts))

dis.dis(new_co)
exec(new_co) # crashes!

night quarryBOT
quartz wave
quartz wave
#

a better alternative would be a simple assignment to a sentinel value that gets replaced later

#

oops :p

versed eagle
quartz wave
# magic wraith !e <@990391928300404748> ```py import dis, types code = '''def print_square(x): ...

!e ```py
import dis, types
code = '''def print_square(x):
print(x*x)
print_square(555)'''

def modify_bytecode(co, new_bytecode, new_consts):
return co.replace(co_code=new_bytecode, co_consts=new_consts)

co = compile(code, 'xd', 'exec')

bytecode = bytearray(co.co_code)
bytecode[2:12] = [] # remove actual opcodes up to loading the number 555
bytecode[2:2] = [dis.opmap['PUSH_NULL'], 0, # needed for CALL mechanism
dis.opmap['LOAD_CONST'], len(co.co_consts)] # use len(consts) because we're appending the function constant later

consts = list(co.co_consts)
consts.append(types.FunctionType(consts[0], globals()))

new_co = modify_bytecode(co, bytes(bytecode), tuple(consts))

dis.dis(new_co)
exec(new_co) # doesn't crash!

night quarryBOT
quartz wave
#

magic!!

twin roost
#

I wonder why python compiler just doesn't optimize it by itself since it's clear that this function won't change at runtime

twin roost
quartz wave
modest skiff
quartz wave
#

hmm.

#

"extremely" seems a bit over..

#

it definitely does get better though :>

#

also function creation doesn't get optimized

#

only function calls

dusty zodiac
#

Does anyone have any code that uses different bitwise operators that I can have a look at?

clear venture
magic wraith
magic wraith
quartz wave
#

=v=

#

i mean- they just knew but like-

versed eagle
#

they were silly :3

quartz wave
#

:3

sick hound
#

Please guys answer this:

If I have list say list=[1,2,3] & I need to output a single element each runtime, how do I do it with only a for & if statment? So when I run the code I get 1 only as my outout first only & when I again run the code I get 2 only as my output.

bleak wadi
#

If you mean that each time the python interpreter starts up and runs your module you should get a different number, then I think you'll have to use something outside of Python to do it. The simplest is to write the number to a text file on close and read it on start (maybe treating the file not existing as 1).

If the process can continue running in the background and "running" it means talking to it with some IPC like a pipe, a generator could probably do this for you.

twin roost
#

didn't know that reduce is slower just doing a simple loop

#

!e

products = [
    {"name": "Product A", "price": 10},
    {"name": "Product B", "price": 20},
    {"name": "Product C", "price": 15},
    {"name": "Product D", "price": 25},
]
from functools import reduce

def classic_way():
    most_expensive = None
    max_price = 0
    for product in products:
        if product["price"] > max_price:
            most_expensive = product
            max_price = product["price"]

def reduce_way_no_lambda():
    def condition_no_lambda(prev, next):
        if next["price"] > prev["price"]:
            return next
        return prev
    most_expensive = reduce(condition_no_lambda, products)

import timeit
n = 10000
print(timeit.timeit(classic_way, number=n), classic_way)
print(timeit.timeit(reduce_way_no_lambda, number=n), reduce_way_no_lambda)
night quarryBOT
quartz wave
#

i mean- >->

quartz wave
#

mhm

twin roost
#

🤔

quartz wave
#
  1. function is made
  2. C code incurs function calling overhead for every item
twin roost
#

I though one of the points of reduce that #2 will be faster than just doing it yourself

quartz wave
#

eh.

#

a simple for loop in python beats almost all contenders that mainly does the job in python.

#

that also includes just using max() with a key=

twin roost
#

yeah

#

max made the thing 4x times slower

quartz wave
#

hm

#

2x slower for me

twin roost
#
def reduce_way_lambda():
    most_expensive = reduce(lambda prev, next: max(prev, next, key=lambda x: x["price"]), products)
# 0.0017248999997718784 <function classic_way at 0x000001BE4D5704A0>
# 0.009213199999976496 <function reduce_way_lambda at 0x000001BE4D73D9E0>
# 0.009563799999796174 <function reduce_way_half_lambda at 0x000001BE4D7D5F80>
# 0.0026268999999956577 <function reduce_way_no_max at 0x000001BE4D7D5EE0>
# 0.002238399999896501 <function reduce_way_no_lambda at 0x000001BE4D7D60C0>
quartz wave
#

okay

#

i don't think that's how it works

#

why not just max(products, key=lambda x: x["price"])

twin roost
#

yeah, that's probably not the best example for reduce, true

quartz wave
# modest skiff .bm brain hurting code

!e ```py
class foo:
def or(self, other):
first_name = None
second_name = None
for name, obj in globals().items():
if obj == self or obj == other:
if first_name is None:
first_name = name
continue # redundant, for readability only
else:
second_name = name
break
else:
# the break didn't happen (which means we didn't get 2 names)
raise RuntimeError("iterator exhausted")
# return the 2 names joined by a space
return f"{first_name} {second_name}"

Hello = World = foo()
print(Hello | World)

night quarryBOT
modest skiff
#

thanks

dense mural
#
>>> def f(a,b,c): return locals()
...
>>> f(1,2,3)
{'a': 1, 'b': 2, 'c': 3}

Is This A Good Trick or Just esoteric?

sick hound
#

what is this wow

dense mural
#

!d locals

night quarryBOT
#

locals()```
Update and return a dictionary representing the current local symbol table. Free variables are returned by [`locals()`](https://docs.python.org/3/library/functions.html#locals) when it is called in function blocks, but not in class blocks. Note that at the module level, [`locals()`](https://docs.python.org/3/library/functions.html#locals) and [`globals()`](https://docs.python.org/3/library/functions.html#globals) are the same dictionary.

Note

The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter.
clear venture
#

is cute

earnest snow
#

you want to see something worth this channel?

#

!e

import types

def _const_mockery(fnc, *consts):
    if not isinstance(fnc, types.FunctionType):
        return fnc
    cfnc = fnc.__code__
    r =  list(cfnc.co_consts)
    for i, rplc in enumerate(consts):
        if isinstance(rplc, tuple):
            i,rplc = rplc
        i += 1
        r[i] = rplc
    
    ncfnc = cfnc.replace(co_consts=tuple(r))
    
    return types.FunctionType(ncfnc, globals(), name=fnc.__name__)

def const_mockery_decorator(*consts):
    def deco(fnc):
        return _const_mockery(fnc, *consts)
    return deco

@const_mockery_decorator("you cannot")
def example():
    print("I can!")

example()
night quarryBOT
earnest snow
#

got a dependencies error for a second

#

!e

import types

def _const_mockery(fnc, *consts):
    if not isinstance(fnc, types.FunctionType):
        return fnc
    cfnc = fnc.__code__
    r =  list(cfnc.co_consts)
    for i, rplc in enumerate(consts):
        if isinstance(rplc, tuple):
            i,rplc = rplc
        i += 1
        r[i] = rplc
    
    ncfnc = cfnc.replace(co_consts=tuple(r))
    
    return types.FunctionType(ncfnc, globals(), name=fnc.__name__)

def const_mockery_decorator(*consts):
    def deco(fnc):
        return _const_mockery(fnc, *consts)
    return deco

@const_mockery_decorator("you cannot Jaja", "=")
def example():
    print("can I please?")
    print(4 * 30)

example()
night quarryBOT
earnest snow
#

it's just = instead of '=' * 30 because python's precalculating the result

karmic pumice
#

!e

const_mockery_decorator=lambda*a:lambda f:(f,setattr(f,"__code__",f.__code__.replace(co_consts=tuple(value if idx==0 or len(a)<idx else a[idx-1] for idx, value in enumerate(f.__code__.co_consts)))))[0]
@const_mockery_decorator("nah", "=")
def example():
  print("can i please?")
  print(4 * 30)
example()
night quarryBOT
karmic pumice
#

lmao the parens
lisp incident

earnest snow
#

def _const_mockery(fnc, *consts, ffilter:Optional[Callable] = None, mapping:Optional[Callable] = None):
    if not isinstance(fnc, types.FunctionType):
        return fnc
    if mapping and len(consts):
        raise ValueError("map and consts are incompatible")
    
    cfnc = fnc.__code__
    r =  list(cfnc.co_consts)
    assert len(r)
    if mapping:
        return types.FunctionType(
            cfnc.replace(co_consts=tuple(map(mapping, r))),
            globals(),
            name=fnc.__name__)
    ffilter = ffilter or (lambda *v:False)
    
    cindx = 0
    for indx, vv in enumerate(r[1:]):
        c = ffilter(vv)
        if c:
            r[indx + 1] = c
            continue
        if len(consts) < cindx:
            v = consts[cindx]
            if isinstance(v, tuple):
                j, v = v
                j = j or cindx
                r[j + 1] = v
            else:
                r[cindx + 1] = v                        
        cindx += 1

    ncfnc = cfnc.replace(co_consts=tuple(r))
    
    return types.FunctionType(ncfnc, globals(), name=fnc.__name__)

as far as I'm concerned, this should work ¿right?

#

like it passes my tests but they're not rigorous

#

the return value is also affected by this

#

nice

twin roost
#

is there a way to get the original dict of the object using gc? since x is probably referring to it's original __dict__ somehow internally but can't seem to find it in gc.get_referents or gc.get_referrers. Though there is a solution without gc - #1230932562499862578 message but still curious

import gc
def get_true_dict(obj: object) -> dict:
    import gc
    ...


# blocked setattr and __dict__ and __class__
d = {}
class X:
    __dict__ = d
    __class__ = 42
    __setattr__ = lambda *_: 1/0
x = X()
assert x.__dict__ is d
assert get_true_dict(x) is not x.__dict__

d = get_true_dict(x)
d['a'] = 42
assert x.a == 42
d['b'] = 24
assert x.b == 24
print(d)
quartz wave
fleet bridge
earnest snow
twin roost
fleet bridge
#
>>> import gc
>>> class X: ...
...
>>> x = X()
>>> gc.get_referents(x)
[X]
>>> x.a = 1
>>> x.b = 'f'
>>> gc.get_referents(x)
[1, 'f', X]
>>> x.__dict__
{'a': 1, 'b': 'f'}
>>> gc.get_referents(x)
[{'a': 1, 'b': 'f'}, X]
>>> x.__dict__ = {}
>>> gc.get_referents(x)
[{}, X]
>>> x.c = 42
>>> gc.get_referents(x)
[{'c': 42}, X]
#

i guess there is some lazy dict creation going on

#

unless you explicitly request x.__dict__, it is not fully created, so it is not present in gc.get_referents(x)

#

not sure how that even works

twin roost
#

Looks like if dict is not created then get_referents is using dict internal contents and just displays it's values

fleet bridge
twin roost
#

that's interesting

versed eagle
versed eagle
#

there must be some internal python reference from x to a true dict

#

wrt. that, the above file is useful probably

rigid trench
#

!e ```py
class DeloFile:
def init(self, file) -> None:
self.file = file
self.__contents = None
self.__parsed = None
self.__vars = {}

def __code(self):
    self.__contents = open(self.file, "r").readlines()

def __parse(self):
    self.__parsed = [x.strip() for x in self.__contents if x.strip()]

def __main(self):
    self.__code()
    self.__parse()

    for code in self.__parsed:
        opcode = code.split()

        if opcode[0] == "new":
            name = opcode[1]
            value = " ".join(opcode[2:])

            try:
                value = eval(value)
            except:
                pass

            self.__vars[name] = value

def get_data(self):
    self.__main()

    return self.__vars
night quarryBOT
twin roost
#

is there shorter version for get_unique_by_name?

#

!e


from dataclasses import dataclass
from typing import Iterable
@dataclass
class O: name: str

objects = [O("a"), O("b"), O("a"), O("c"), O("b")]
def get_unique_by_name(l: list[O]) -> Iterable[O]:
    d = {}
    for o in l: d.setdefault(o.name, o)
    return d.values()
#

import inspect
unique = get_unique_by_name(objects)
assert len(unique) == 3
assert set(o.name for o in unique) == {"a", "b", "c"}
code = '\n'.join(inspect.getsource(get_unique_by_name).splitlines()[1:])
golf = len(code)
print(golf, unique)
night quarryBOT
karmic pumice
#

!e

from dataclasses import dataclass
from typing import Iterable
@dataclass
class O: name: str

objects = [O("a"), O("b"), O("a"), O("c"), O("b")]
get_unique_by_name=lambda l:(d:={},[d.setdefault(o.name,o)for o in l])[0].values()
#

import inspect
unique = get_unique_by_name(objects)
assert len(unique) == 3
assert set(o.name for o in unique) == {"a", "b", "c"}
code = '\n'.join(inspect.getsource(get_unique_by_name).splitlines()
  [1:] # well...
)
golf = len(code)
print(golf, unique)
night quarryBOT
twin roost
#

oh, I think we can just use a dict

#

!e


from dataclasses import dataclass
from typing import Iterable
@dataclass
class O: name: str

objects = [O("a"), O("b"), O("a"), O("c"), O("b")]
def get_unique_by_name(l: list[O]) -> Iterable[O]:
    return{o.name:o for o in l}.values()
#

import inspect
unique = get_unique_by_name(objects)
assert len(unique) == 3
assert set(o.name for o in unique) == {"a", "b", "c"}
code = '\n'.join(inspect.getsource(get_unique_by_name).splitlines()[1:])
golf = len(code)
print(golf, unique)
night quarryBOT
brazen arrow
#

is this the greatest eso-py hello world of all time

unique heath
#

beauty is in the eyes of the beholder

twin roost
#

is there a way to handle an Exception in one line?

#

besides contextlib.suppress that allows skipping it

unique heath
#

fastest way to get valueerror

heres mine

int("")```
quartz wave
unique heath
#
$ python -c "int('')" | time
shell  0.02s user 0.07s system 0% cpu 1:21:06.60 total
children  0.50s user 1.31s system 0% cpu 1:21:06.60 total
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: invalid literal for int() with base 10: ''

$ python -c "raise ValueError" | time
shell  0.03s user 0.08s system 0% cpu 1:21:15.54 total
children  0.62s user 1.49s system 0% cpu 1:21:15.54 total
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError``` dont think so
quartz wave
#

you're measuring the entire python startup process

#
>py -m timeit "try: raise ValueError" "except: pass"
2000000 loops, best of 5: 127 nsec per loop

C:\Users\JerielPC>py -m timeit "try: int('')" "except: pass"
500000 loops, best of 5: 949 nsec per loop
unique heath
quartz wave
unique heath
#

also i meant shortest lmao

twin roost
#

haha

#

why would you need to raise ValueError that way?

#

when you're writing something obscure you usually just need to raise any Exception and 1/0 works for this the best

#

!e

0.0 is 0
night quarryBOT
# twin roost !e ```python 0.0 is 0 ```

:white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | /home/main.py:1: SyntaxWarning: "is" with 'float' literal. Did you mean "=="?
002 |   0.0 is 0
twin roost
#

omg, python added some syntax warning for this :<

ivory ermine
#

!e

print("Hello World!")
night quarryBOT
clear venture
# twin roost is there a way to handle an Exception in one line?

yes, you can create a class with __enter__ and __exit__ implementations in one line using type which can handle errors for you

try: print(1/int(input()))
except ZeroDivisionError: ...

#suppressing errors using a custom context manager implementation

with type('',(),{'__enter__': lambda self: self, '__exit__': lambda self, *args: isinstance(args[1], ZeroDivisionError)})(): print(1/int(input()))
twin roost
#

Found a hack to change global variable in that __exit__

#

!e

a = 25
(lambda: (globals().__setitem__('a', 45),  None)[1])()
print(a)

night quarryBOT
twin roost
#

:<

#

!e

def test():
    a = 25
    (lambda: (nonlocals().__setitem__('a', 45),  None)[1])()
    print(a)
test()
night quarryBOT
# twin roost !e ```py def test(): a = 25 (lambda: (nonlocals().__setitem__('a', 45), ...

:x: Your 3.12 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "/home/main.py", line 5, in <module>
003 |     test()
004 |   File "/home/main.py", line 3, in test
005 |     (lambda: (nonlocals().__setitem__('a', 45),  None)[1])()
006 |   File "/home/main.py", line 3, in <lambda>
007 |     (lambda: (nonlocals().__setitem__('a', 45),  None)[1])()
008 |               ^^^^^^^^^
009 | NameError: name 'nonlocals' is not defined. Did you mean: 'locals'?
twin roost
#

There seems to be no way to dynamically bind a nonlocal variable in python when variable name is provided from another variable

fleet bridge
#

you can get parent frame, and change variable there

quartz wave
#

there's no easy way to dynamically have a nonlocal variable

#

at the very least, the variable has to first be declared nonlocal

#

i've created a class for it but the example looks like this ```py
from nonlocals_proxy import nonlocals

def a():
b = 25
def g():
nonlocal b # still needs this
nonlocals()['b'] *= 2
print(b)
g()
print(b)

a()

twin roost
#

!e

globals()["new_global"] = 25
print("new_global in globals()", "new_global" in globals()) # True
print("new_global", new_global) # 25

def test():
    locals()["b"] = 25
    print("b in locals", "b" in locals())
    # NameError: name 'b' is not defined
    print("b", b)

test()
night quarryBOT
twin roost
#

ohh, python is being safe

#

!e

def test_nonlocals():
    a = 35
    d = locals()
    print("original")
    print(id(d), d)

    def change_nonlocal():
        d["a"] = 50
        print("inside subfunction")
        print(id(d), d)

    change_nonlocal()
    print("original after subfunction")
    print(id(d), d)

    b = d["a"]

    updated_d = locals()
    print("new locals()")
    print(id(updated_d), updated_d)
    print("original after running locals()")
    print(id(d), d)

    print(f"a = {a}")  # 35
    print(f"b = {b}")  # 35


test_nonlocals()
night quarryBOT
# twin roost !e ```python def test_nonlocals(): a = 35 d = locals() print("origin...

:white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | original
002 | 139843347679296 {'a': 35}
003 | inside subfunction
004 | 139843347679296 {'a': 50}
005 | original after subfunction
006 | 139843347679296 {'a': 50}
007 | new locals()
008 | 139843347679296 {'a': 35, 'change_nonlocal': <function test_nonlocals.<locals>.change_nonlocal at 0x7f2fd11214e0>, 'b': 50, 'd': {...}}
009 | original after running locals()
010 | 139843347679296 {'a': 35, 'change_nonlocal': <function test_nonlocals.<locals>.change_nonlocal at 0x7f2fd11214e0>, 'b': 50, 'd': {...}}
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/EWJHTYWEEJ3TEXAUYP2ZX37WAY

dusty zodiac
#
class Solution:
    @lambda uwu : uwu 
    def scoreOfString(self, uwu: str) -> int:
        uwo,omo=range,ord;return sum(abs(~omo(uwu[owo])-~omo(uwu[owo+1]))for owo in uwo(0,len(uwu)-1))

My current answer to today's LeetCode. Open to opinions on how to Obfuscate it further.

quartz wave
#

first thing i'll do is golf it

#

then try to obfuscate

#
class Solution:scoreOfString=lambda _,u:sum(abs(ord(x)-ord(y))for x,y in zip(u,u[1:]))
``` golfed
clear venture
#

think you lost the bitwise nots

quartz wave
#

useless

#

anyway

dusty zodiac
#

Other than that yeah it serves no purpose.

#
class Solution:scoreOfString=lambda _,uwo,omo=zip,owu=ord,:sum(abs(~owu(owo)-~owu(uwu))for owo,uwu in omo(uwo,uwo[1:]))
#

This runs faster than my previous code lol. It's at 30ms and the other one runs at 36ms.

twin roost
#

guess what this will print

def execute(f):
    x = 45
    f()

def nonlocals():
    x = 25
    @execute
    def do_nonlocal():
        nonlocal x
        x += 11
    print(x)

nonlocals()

def high_order():
    x = 25
    def do_nonlocal():
        nonlocal x
        x += 11
        print('do_nonlocal', x)
    return do_nonlocal

def execute_and_print(func):
    x = 45
    func()
    print(x)

func = high_order()
execute_and_print(func)
dusty zodiac
#
36
do_nonlocal 36
45
dusty zodiac
#

This is what it will print.

twin roost
quartz wave
clear venture
#

no, he has a point catnerd

#

if your golf isn't a single expression you are a fake golfer

fleet bridge
#

less statements == shorter
regardless of character length

dusty zodiac
fleet bridge
clear venture
#

exec is cheating and you know it catStare

clear venture
#

you chose violence today huh?

quartz wave
#

nope

#

i responded to it

clear venture
#

you wouldn't use eval in a golf

#

we both know

dusty zodiac
#

Is it technically cheating if there are no witnessses

clear venture
#

O.o

quartz wave
clear venture
dusty zodiac
fleet bridge
clear venture
#

sure but only when there's not a shorter alternative

quartz wave
clear venture
#

not as a way to technically make your code a single expression even though it's hella statements lol

clear venture
quartz wave
clear venture
#

"a golf with multiple statements is cheating" ->
"eval" (implying that you can use eval to make your multiple statements into an expression even though it's killing the point) ->
"you wouldn't use eval in a golf" (you [ceweal] wouldn't use it as a way to turn your code into a single expression)

quartz wave
#

maybe speak clearer next time =w=

clear venture
twin roost
#

Why statements are bad in golf? I mean a newline is just 1 character 😄

quartz wave
#

or some variations of golfing

#

code must be one statement/one expression only

clear venture
#

it produces more interesting code when you make it into a single statement/expression, and you have reduce the code down in a way that a lot of people don't even know how to do, where using semi colons can be done by literally anyone who knows a little python to turn a program into one line

dusty zodiac
twin roost
#
import zen_of_golf
clear venture
#

actually that would be a hilarious pypi package

#

a one line zen of python

twin roost
#

Hahaha

dusty zodiac
#

Just one line that says KeepItShort

#

Wait no ShortenIt

twin roost
#

"Golf it."

dusty zodiac
#

GolfIt

quartz wave
#

at the very least, absolute golfing

clear venture
#

ofc

#

it's still less interesting

twin roost
#

It seems sometimes (besides the cases when we're inside some indentation block) a semicolon doesn't really help in golfing since it's still just 1 character as a newline and it only makes things appear more obfuscated

quartz wave
# dusty zodiac ```py class Solution:scoreOfString=lambda _,uwo,omo=zip,owu=ord,:sum(abs(~owu(ow...
class Solution((OwO:=(iwt:=(umu:=sum)((IvI:=zip)((owu:=range)((IwT:=int)()))))or[qwq:=5,pwq:=(uvu:=eval)(QwQ:=f"{qwq}*-{qwq}")-(pwp:=QwQ.count(chr(qwq+b'0'[0]))),pwq//(owo:=qwq-pwp)*~owo,qwq+iwt,-uvu(TwT:="(ovo:=%u%%u)"%-~-IwT()%iwt)-owo,*[owo*(-pwq-ovo*pwp),pwq+ovo,qwp:=~qwq][::~iwt],-qwp,qwp,pwp,pwp*~-~iwt]).__class__.__mro__[qwp+qwq]):
 @(lambda _w_:lambda uwu:_w_.__ior__({f'{(c:="%c"*(bwd:=pwp-qwp))}t{c[:bwd>>pwp+~IwT()]*pwp}'%(*[x3+umu(OwO[:-~iwi])for iwi,x3 in IvI(*[uvu('b%r'%uwu.__name__),owu(owo*qwq**qwq)][::~iwt])],):uwu}))(locals())
 def nya__OwOhehe(_,uwo):uwo=uvu('b%r'%uwo);return umu(abs(Ywy-ywY)for Ywy,ywY in IvI(uwo,uwo[qwp//-qwq:]))
quartz wave
dusty zodiac
#

I can't believe that beat my old code which uses less characters.

#

36ms

dusty zodiac
#
print(Gramaticallyᅠcorrectᅠvariableᅠnameᱹ:='Hello World')
twin roost
#

!e

print(Gramaticallyᅠcorrectᅠvariableᅠnameᱹ:='Hello World')
print(globals())
night quarryBOT
# twin roost !e ```python print(Gramaticallyᅠcorrectᅠvariableᅠnameᱹ:='Hello World') print(glo...

:white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | Hello World
002 | {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7f117a384d70>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': '/home/main.py', '__cached__': None, 'Gramaticallyᅠcorrectᅠvariableᅠnameᱹ': 'Hello World'}
twin roost
#

looks like a programming crime

sick hound
#

Look what I have done with Python https://youtu.be/cw7qHNntBas?si=GJBrYyhuxUVxbWvF, its a binary waterfall with the famous emulator MelonDS for Windows

This video will install melonDS (a Nintendo DS emulator) into your brain, this is compatible for all brain softwares. No need to do anything, just watch and listen to all those noises and it will successfully install
END OF DESCRIPTION

SOCIAL MEDIA

DISCORD: https://discord.gg/J4xqCPQzDz
FACEBOOK: https://www.facebook.com/macosfangamer
TWITTER ...

▶ Play video
clear venture
twin roost
#

is there way to make it work?

def same_address(a, b):
    return a is b

def test():
    a = 25
    def do_nonlocal():
        nonlocal a
        a = 50
    do_nonlocal()
    assert same_address(a, do_nonlocal.__closure__[0].cell_contents)
    b = 50
    assert not same_address(a, b)
    assert not same_address(a, 50)

test()
quartz wave
twin roost
#

in this example do_nonlocal.__closure__[0].cell_contents actually points to a

#

and changing do_nonlocal.__closure__[0].cell_contents will change a and vice versa

#

and I'm curious if it's possible to check if they are the same

#

besides changing them

fleet bridge
#

same_address() checks that two objects are the same, not two variables

quartz wave
#

you mean they're different based on the location in which they're assigned?

#

that's hard to do

#

maybe impossible

twin roost
#

I mean a is pointing to some address xxxx in memory and do_nonlocal.__closure__[0].cell_contents is pointing to the same address and curious if there is a way to get that address to see if two variables are actually pointing to the same address.

but checking id() doesn't work to get this address for ints and other literals as i,j = 5, 5; assert i is j; assert id(i) == id(j)

fleet bridge
#

b is pointing to the same address as well

quartz wave
fleet bridge
#

a is b works perfectly, it tells you exactly what you want: are two objects located at the same address or not

twin roost
#

!e

def test():
    a = 25
    def do_nonlocal():
        nonlocal a
        a = 50
    do_nonlocal()
    print('after call', a, do_nonlocal.__closure__[0].cell_contents)
    a = 77
    print('a value changed', a, do_nonlocal.__closure__[0].cell_contents)
    do_nonlocal.__closure__[0].cell_contents = 99
    print('closure value changed', a, do_nonlocal.__closure__[0].cell_contents)

test()
night quarryBOT
twin roost
#

it's like a and do_nonlocal.__closure__[0].cell_contents are pointers and they're pointing to the same *container.

and to assert they're pointing to the same *container we'll need to now &container

but when we do id(a) or id(do_nonlocal.__closure__[0].cell_contents) it's more like we're getting the container instead (address of the value in the container instead of the container address).

#

if this makes sense 😄

versed eagle
versed eagle
twin roost
#

I was just curious if it's possible to get that address

versed eagle
#

or ctypes

#

id is easier

twin roost
#

id won't work here

versed eagle
#

wdym

twin roost
#

!e

def test():
    a = 25
    def do_nonlocal():
        nonlocal a
        a = 50
    do_nonlocal()
    print('after call', a, do_nonlocal.__closure__[0].cell_contents)
    a = 77
    print('a value changed', a, do_nonlocal.__closure__[0].cell_contents)
    do_nonlocal.__closure__[0].cell_contents = 99
    print('closure value changed', a, do_nonlocal.__closure__[0].cell_contents)
    b = 99
    print(id(a), id(do_nonlocal.__closure__[0].cell_contents), id(99), id(b))

test()
night quarryBOT
twin roost
#

all 4 pointing to the same address

#

though only a and do_nonlocal.__closure__[0].cell_contents are actually correlate

versed eagle
versed eagle
#

but thats not relevant because you dont want the id of b, nor do you want the id of some arbitrary const; you want the id of a

versed eagle
twin roost
versed eagle
#

that is not how it works

#

also thats c++ lol

versed eagle
#

have you read through any of the CPython source?

twin roost
#

no

#

it's made up code

#

just to illustrate the behaviour

versed eagle
twin roost
#

when we change a it also change cell_contents and vice versa but id appears to be the same for both of them and also b

quartz wave
#

which container?

quartz wave
#

you mean the cell?

#

do_nonlocal.__closure__[0]?

versed eagle
fleet bridge
#

you can change cell_contents, then look at a and if it changed as well, then they are storing pointer in the same location

twin roost
twin roost
#

everything else is probably hidden somewhere deep in memory

fleet bridge
#

another way is to look at the code with your eyes

quartz wave
#

that's the primary cell container

#

every other container level is basically the equivalent of internal locals()

versed eagle
#

its not shared though
a is a PyObject*

#

directly

#

pretty much

twin roost
quartz wave
#

a dynamically loads do_nonlocal.__closure__[0].cell_contents everytime it's mentioned

quartz wave
#

!e ```py
from dis import dis

dis(r"""
def test():
a = 25
def do_nonlocal():
nonlocal a
print(a)
""")

night quarryBOT
# quartz wave !e ```py from dis import dis dis(r""" def test(): a = 25 def do_nonloca...

:white_check_mark: Your 3.12 eval job has completed with return code 0.

001 |   0           0 RESUME                   0
002 | 
003 |   2           2 LOAD_CONST               0 (<code object test at 0x7fe932151b50, file "<dis>", line 2>)
004 |               4 MAKE_FUNCTION            0
005 |               6 STORE_NAME               0 (test)
006 |               8 RETURN_CONST             1 (None)
007 | 
008 | Disassembly of <code object test at 0x7fe932151b50, file "<dis>", line 2>:
009 |               0 MAKE_CELL                1 (a)
010 | 
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/DHVYQLSHYN6JEWF4KHEPBLEPVI

night quarryBOT
#

Python/bytecodes.c lines 1613 to 1620

inst(LOAD_DEREF, ( -- value)) {
    PyCellObject *cell = (PyCellObject *)GETLOCAL(oparg);
    value = PyCell_GetRef(cell);
    if (value == NULL) {
        _PyEval_FormatExcUnbound(tstate, _PyFrame_GetCode(frame), oparg);
        ERROR_IF(true, error);
    }
}```
versed eagle
quartz wave
#

ah

#

in that case it's the exact same thing

twin roost
quartz wave
#

!e ```py
from dis import dis

dis(r"""
def test():
a = 25
def do_nonlocal():
nonlocal a
print(a)
print(a)
""")

night quarryBOT
# quartz wave !e ```py from dis import dis dis(r""" def test(): a = 25 def do_nonloca...

:white_check_mark: Your 3.12 eval job has completed with return code 0.

001 |   0           0 RESUME                   0
002 | 
003 |   2           2 LOAD_CONST               0 (<code object test at 0x7fe852a261f0, file "<dis>", line 2>)
004 |               4 MAKE_FUNCTION            0
005 |               6 STORE_NAME               0 (test)
006 |               8 RETURN_CONST             1 (None)
007 | 
008 | Disassembly of <code object test at 0x7fe852a261f0, file "<dis>", line 2>:
009 |               0 MAKE_CELL                1 (a)
010 | 
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/PYB7DLUOP7JWQK3A67NPBAZ2TY

quartz wave
#

yea

versed eagle
#

yes

twin roost
#

so, basically there is just one pyobject * and therefore there is no need to have common container between them

versed eagle
#

yes

quartz wave
#

huh?

twin roost
# quartz wave huh?

I just thought before that a and cell_content are using two separate pyobjects and therefore there would be some common container between them, so they would be able to share the same value

quartz wave
#

and only one object inside that container

#

unless you include the container which is an object itself

rigid trench
#

!e ```py
import random

group_1 = ["`", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "[", "]", "{", "}", "\", "|", ";", ":", "'", """, ",", ".", "<", ">", "/", "?"]
group_2 = [str(x) for x in range(0, 9)]
group_3 = ["A", "E", "I", "O", "U", "Y"]
group_4 = ["B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Z"]

def encode(message):
split = [x for x in message]
split = [x.upper() for x in split]

for index, char in enumerate(split):
    print(split)
    if char in group_1:
        split[index] = "SC" + str(group_1.index(char)).zfill(2)
    
    elif char in group_2:
        split[index] = "N" + char

    elif char in group_3:
        split[index] = "V" + char

    elif char in group_4:
        split[index] = "C" + char

    elif char == " ":
        split[index] = "S"

return ''.join(split)

def decode(encoded_message):
decoded_message = ""
index = 0

while index < len(encoded_message):
    if encoded_message[index:index+2] == "SC":
        char_index = int(encoded_message[index+2:index+4])
        decoded_message += group_1[char_index]
        index += 4

    elif encoded_message[index] == "N":
        decoded_message += encoded_message[index+1]
        index += 2

    elif encoded_message[index] == "V":
        decoded_message += encoded_message[index+1]
        index += 2

    elif encoded_message[index] == "C":
        decoded_message += encoded_message[index+1]
        index += 2

    elif encoded_message[index:index+2] == "S":
        decoded_message += " "
        index += 2

return decoded_message

message = """Hit the showers!"""

encoded_result = encode(message)
decoded_result = decode(encoded_result)

print(f"original message: {message}")
print(f"encoded message: {encoded_result}")
print(f"decoded message: {decoded_result}")

rich hound
#

!e

B=getattr
A=bytes
_______='BQAAAAEAAABzDAAAAPADAQEB2QAFgGSFC3IDAAAA'
_____='ZQBkAKsBAAAAAAAAAQB5ASkCegI6M04pAdoFcHJp'
____='LjNNNNNNNNNNNNNNNNZNNNNNNNNN8kDNNNPKNNVN'
______='y5TZsVHZv1GPIovPn5WayR3c8gg+AAAAAMPApSnb'
__import__(B(__import__(A([98,97,115,101,54,52]).decode()),A([98,54,52,100,101,99,111,100,101]).decode())(A([89,110,86,112,98,72,82,112,98,110,77,61])).decode()).exec(__import__(B(__import__(A([98,97,115,101,54,52]).decode()),A([98,54,52,100,101,99,111,100,101]).decode())(A([98,87,70,121,99,50,104,104,98,65,61,61])).decode()).loads(__import__(B(__import__(A([98,97,115,101,54,52]).decode()),A([98,54,52,100,101,99,111,100,101]).decode())(A([89,109,70,122,90,84,89,48])).decode()).b64decode(__import__(B(__import__(A([98,97,115,101,54,52]).decode()),A([98,54,52,100,101,99,111,100,101]).decode())(A([89,50,57,107,90,87,78,122])).decode()).decode(____,__import__(B(__import__(A([98,97,115,101,54,52]).decode()),A([98,54,52,100,101,99,111,100,101]).decode())(A([89,109,70,122,90,84,89,48])).decode()).b64decode('cm90MTM=').decode())+_____+______[::-1]+_______)))
night quarryBOT
rich hound
#

i love goofing off with this

#

!e

import base64, lzma; exec(compile(lzma.decompress(base64.b64decode(b'/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4BcyBNxdAC/rhAeiEv8hIKAMtZdqenDYr68Xwx03OtBiFWoJJh7Sb1x5Xyg0jzZRen5Co2eix4DvAxFW3QXe11T1eFeYbCxaIhJaua8r0p4Fd0QeKNSUVCftwj3NP56jbxsBDZ3fnkChRBtFMM0kF+Xzc6cdlfErf4Xrc9gwR8aR3TtB5anYtz5cjIGTww0PJKnC6CPPbuW44NcgM5I6wTdTDuj7k6JNVZ4cOCZCDOJLifXXkMC0dG7ZlDJLc20p4vjyeY/8zT7BFFCohFOjIYUn0O/p+8f4CJdrcDv2OG7p0EWLtmQdpsbNwVqdvlAn0z8JYGyWyWB0w/7hXADviN0l3ytL+74vWGmMg6miFI9VZhlWWGKcYFSvmZnUTYgJcQaEVARQAKRazmDQ8OjYYYVAiHAL3jNk+Oa+v4LWUJfQY70TIZ2ewttLegWKDi9En6i/hRzdjMnXAQddMtB3clkVDP26ZpQyXSZAh/g8XMZ6dUlDdfyHX6HUc6qnvYrTQirf/lquAdOkL4Kjh156rwZpyLLM+DY0XujDZEF3NcO+QrMhESczueOFcaKso2mVi2fhNI7Kon+h7+DQfB0XEr2Wc/HxMnFtKJcVm8JQisH6zSadDAxGyzJ/Agqr3QvP2kCp7IaFOyR2jmYvowPEFtH7yLQzOnWX7osAaZzfkg+R4FufBQqaWy+fExzXaqa2AZermbfMwB/NnwXi/khuEYeHnbnbCxCZJuzBz2V8xIFzIPwwd4s1OeMq17981PzSprJEsj6PZq06fNFmpdpt1ohPfCFCFmh93+eIVbCKbt0uQjQSWdfu1t/HG5seMYN7rXxUNF43JCeiVrneaqXoSUA1tmfkyVN8TKCL8pX297KiXF7ZRyOhHnhdGLesQqwuZC36oGBZnwCktARkEZm6Ha69sAOMZ3VRUNvIHdePE2F1E6uWnIyYc2ctzuqvf/LzYV3NAx8SW/N42pQVHNm3ESTlVnuMTWB2klkbGmzy05SLFXgvWH1hKupDbTX4buqrC6BmYypg6/y7XuRiqtJ0XMyaSMxcwAV0qaKkpH6EXCQvlae88slkh5u8reIhEq6oWFwxYzQlb5Q11frhe9nQOs9F51aZhBFEPLx885lpNTE+AhzBZEFnFpGGmYWYZu+KxD8KutfRYqi1GrOiYIJl9wLZrw1EQT9yJdu6e6ufH+lzNSaD2WRFMkuEkmfYVUwzBmbvyBI+0YrGmnSbAvLHiSKQnONqVkqAirzGWxP7XJ8C/5Gx+ZAtMl9nW1KIitFe1tVcsBBAa8eFBmZXCzV4DSQFg3VMMOIrY7pbNsx4/xmxHdh4PVxwkCbOIjsoiMjw7XfiafgoC8nvTLwHTXRHXs2pGo5wiTTgoQo0pUOc/D/6cOpWccj7rkfoMGcWXK3RbJwr4hAIYOAJqdjsBAAM2mIuyb3hAh4fYVQZn1Z1yOSAnQB/sdqUjXXpSGYbc4TcL3bFQYvl4rm/tzg/TZGj0pnRxjXhyFuizUq7/RaLBe3lLwSLSPQ8yi6VeAAmeRPRGTyMvRyovE8UdQeYS7NM2z+8XIf0FaAYv/Ru66CM0Gm6BoTlBG271LwiCdml3MmnDi0MMU4kHfVfjHF3CwbIy5UyH0CZPfD0OycQ/s/OQ9qmlePI4Y2SWbUyTwrHMNJSiQdDAGLhmqlSweoSAAH4CbMuAABGp5AKscRn+wIAAAAABFla')), "<string>", "exec"))
#

LOL

#

i did it wrong

night quarryBOT
rich hound
twin roost
#

!e

hello = 25
print(f'{hello=}'.split('=', 1)[0])
night quarryBOT
quartz wave
#

because a lot of redundant operations can be removed

#
import base64, lzma
import os
_L0 = b"base64"
_L1 = b"b64decode"
A = eval
B = getattr
C = __import__
D = bytes
E = lambda string: compile(string, "<string>", "exec")
G = r"""
import marshal, codecs
A = 'LjNNNNNNNNNNNNNNNNLNNNNNNNNN8mbNNNPKNNVNMDOxNNVNMDSxNnfONNNNNNNNntDNNNNN'
B = '8gg++cmbpJHdzxDC6DAAAAw8AkqcyVGZ0NnBa/1X0J3bw1Waf9lCaTnbpJHcFo9Ap4EZuV2A'
C = 'AAAAAAAAAAAAAAAAAABkAqwDqwMAAAAAAAABAHkEKQV6Ajoz2gNzeXN6AgkKKQLaBGZpbGXa'
D = 'bW9kdWxlPnIKAAAAAQAAAHMcAAAA8AMBAQHZAAWAZJEamEXTESLXESnRESmoZtYANXIIAAAA'
exec(marshal.loads(base64.b64decode(codecs.decode(A, base64.b64decode('cm90MTM=').decode()) + C + B[::-1] + D)))
"""
try:
    exec(E(G))
    os._exit(0)
except lzma.LZMAError:
    ...
#
import os
G = r"""
print(":3", file=__import__("sys").stderr, end="\t\n")
"""
exec(G)
os._exit(0)
#
import os
print(":3", file=__import__("sys").stderr, end="\t\n")
os._exit(0)
#

that's about uhh 24 minutes to decode

#

(all the imports were made into statements for "convenience")

rich hound
#

tbh

#

the code behind it is uh

#

something,

unique heath
rich hound
#

well

#

first part of how it works

O,N,L,J,I,H,G,F,C='exec','<string>',False,'eval','bytes','getattr','__import__',list,True
import random as P,string,base64 as E,codecs as Q,argparse as R,os as A,sys
def encryptstring(string,config={},func=L):
    K=string;A=config;N=F(b'base64');O=F(b'b64decode');__import__=A.get(G,G);getattr=A.get(H,H);bytes=A.get(I,I);eval=A.get(J,J)
    if not func:return f"{getattr}({__import__}({bytes}({N}).decode()), {bytes}({O}).decode())({bytes}({F(E.b64encode(K.encode()))})).decode()"
    else:
        B=K.split('.');P=encryptstring(B[0],A);B=F(map(lambda x:encryptstring(x,A,L),B[1:]));C=''
        for(Q,M)in enumerate(B):
            if Q==0:C=f"{getattr}({eval}({P}), {M})"
            else:C=f"{getattr}({C}, {M})"
        return C

print(f"exec({encryptstring('print("?")')})")

fleet bridge
#

!e ```py

def f():
try:
print(end='.')
f()
except:
print(end='!')
f()
finally:
print(end='@')
f()

f()

night quarryBOT
# fleet bridge !e ```py def f(): try: print(end='.') f() except: ...

:x: Your 3.12 eval job timed out or ran out of memory.

.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................!
... (truncated - too long)

Full output: https://paste.pythondiscord.com/3M2UTJJQEUHC2E23QR2JWP5YKQ

fleet bridge
#

well, beginning of it is boring

#

after 1k chars it becomes interesting

#

it is also becomes slower and slower over time, and takes up more and more memory

quartz wave
grave grail
#

!e

for i in range(1,99):
    for(e)in(a:=[[]for()in[()]*i]):e+=a
    print(i, e)
night quarryBOT
# grave grail !e ```py for i in range(1,99): for(e)in(a:=[[]for()in[()]*i]):e+=a print...

:x: Your 3.12 eval job has completed with return code 143 (SIGTERM).

001 | 1 [[...]]
002 | 2 [[[...], [...]], [...]]
003 | 3 [[[...], [[...], [...], [...]], [...]], [[[...], [...], [...]], [...], [...]], [...]]
004 | 4 [[[...], [[...], [...], [[...], [...], [...], [...]], [...]], [[...], [[...], [...], [...], [...]], [...], [...]], [...]], [[[...], [...], [[...], [...], [...], [...]], [...]], [...], [[[...], [...], [...], [...]], [...], [...], [...]], [...]], [[[...], [[...], [...], [...], [...]], [...], [...]], [[[...], [...], [...], [...]], [...], [...], [...]], [...], [...]], [...]]
005 | 5 [[[...], [[...], [...], [[...], [...], [...], [[...], [...], [...], [...], [...]], [...]], [[...], [...], [[...], [...], [...], [...], [...]], [...], [...]], [...]], [[...], [[...], [...], [...], [[...], [...], [...], [...], [...]], [...]], [...], [[...], [[...], [...], [...], [...], [...]], [...], [...], [...]], [...]], [[...], [[...], [...], [[...], [...], [...], [...], [...]], [...], [...]], [[...], [[...], [...], [...], [...], [...]], [...], [...], [...]], [..
... (truncated - too long)

Full output: too long to upload

grave grail
#

:(

#

!e

for i in range(1,99):
    for(e)in(a:=[[]for()in[()]*i]):e+=a
    repr(e)
    print(i)
night quarryBOT
grave grail
#

Each i make it exponentially harder to represent

#

!eval

import time
for i in range(1,99):
    gen_start = time.perf_counter()
    for(e)in(a:=[[]for()in[()]*i]):e+=a
    gen_end = time.perf_counter()
    repr(e)
    repr_end = time.perf_counter()
    print(f"{i} gen:{gen_end-gen_start} repr:{repr_end-gen_end}")
#

lol, this more on memory issue here

#

!eval

import time
for i in range(1,99):
    gen_start = time.perf_counter()
    for(e)in(a:=[[]for()in[()]*i]):e+=a
    gen_end = time.perf_counter()
    d = repr(e)
    repr_end = time.perf_counter()
    size = len(d)
    print(f"{i} gen:{gen_end-gen_start} repr:{repr_end-gen_end} resolved:{size}")
night quarryBOT
# grave grail !eval ```py import time for i in range(1,99): gen_start = time.perf_counter(...

:x: Your 3.12 eval job timed out or ran out of memory.

001 | 1 gen:2.7799978852272034e-06 repr:1.0979827493429184e-05 resolved:7
002 | 2 gen:2.7599744498729706e-06 repr:2.6598572731018066e-06 resolved:23
003 | 3 gen:1.5601981431245804e-06 repr:2.9900111258029938e-06 resolved:85
004 | 4 gen:1.2700911611318588e-06 repr:8.180039003491402e-06 resolved:373
005 | 5 gen:1.500127837061882e-06 repr:3.31709161400795e-05 resolved:1955
006 | 6 gen:1.6700942069292068e-06 repr:0.0001745428889989853 resolved:12067
007 | 7 gen:1.8300488591194153e-06 repr:0.0012010619975626469 resolved:86113
008 | 8 gen:2.6999041438102722e-06 repr:0.011023266008123755 resolved:698705
009 | 9 gen:4.2798928916454315e-06 repr:0.08726717694662511 resolved:6356863
grave grail
#
1 gen:4.842004273086786e-06 repr:3.0520022846758366e-06 resolved:7
2 gen:3.905995981767774e-06 repr:3.335997462272644e-06 resolved:23
3 gen:5.086010787636042e-06 repr:9.846989996731281e-06 resolved:85
4 gen:3.905995981767774e-06 repr:2.1321990061551332e-05 resolved:373
5 gen:0.00031872501131147146 repr:0.00010506197577342391 resolved:1955
6 gen:5.6150020100176334e-06 repr:0.0005939529801253229 resolved:12067
7 gen:5.616020644083619e-06 repr:0.002996092982357368 resolved:86113
8 gen:5.817972123622894e-06 repr:0.019604859000537544 resolved:698705
9 gen:1.102700480259955e-05 repr:0.1897019449970685 resolved:6356863
10 gen:1.794402487576008e-05 repr:1.9098649919906165 resolved:64116655
11 gen:1.2329983292147517e-05 repr:21.2753957209934 resolved:710215277
Killed

[Program finished]
#

From my phone (if you want a more comprehensive info

fleet bridge
#

def ():
 ᅠᅠ,ᅠᅠᅠ=(ᅠ!=ᅠ)+(ᅠ!=ᅠ),(ᅠ==ᅠ)+(ᅠ!=ᅠ)
 while ᅠ:
  ᅠᅠ,ᅠᅠᅠ=ᅠᅠᅠ,ᅠᅠ+ᅠᅠᅠ
  ᅠ-=ᅠ==ᅠ
 return ᅠᅠ
#

can you guess what it does?

grave grail
#

...

#

Who decided unicode character is a good idea as a variable name

quartz wave
#

a good 2 minutes of looking at the assignments and thinking "hmm, this looks familiar"

quartz wave
#

oh

#

i forgot to select one character

fleet bridge
#

for each expression find such x (or produce x with some code, or replace x with some expression), so that expression evaluates to True: ```py
isinstance(x, int) is x
type(x) is x.class is x is x()
x==42 and x!=42
x==42 and not (x==42)
x is not x
object() is x
id(x) % 997 == 42
hasattr(x, 'x') and not hasattr(x, 'x')
dir(x) == []
len(x) is x
id(x) is x
type(x) is str and eval(x, {}, {}) == x
type(x) is str and (t:=eval(x, {}, {})) == x and type(t) is str # same as previous one, but more constrained :)
type(x) is str and eval(x42, {}, {}) == 42
type(x) is str and eval(x
42, {}, {}) == 69

rules are not very strict, the only goal is to have fun
#

i guess it would be a good idea to hide your answers behind a spoiler

quartz wave
# fleet bridge for each expression find such `x` (or produce `x` with some code, or replace `x`...

||```py
x = True
isinstance(x, int) is x

from ctypes import py_object
class x(type):
new = lambda *a: x
init = lambda *a: None
py_object.from_address(id(x)+tuple.itemsize).value = x
type(x) is x.class is x is x()

@type.call
class x:
eq = ne = lambda *a: True
x==42 and x!=42

@type.call
class x:
def eq(_, a, b=[]):
if t := a not in b: b.append(a)
return t
x==42 and not (x==42)

x is not x

[] is not []

object = lambda: x
x = ...
object() is x

t = []
while id(x := []) % 997 != 42: t.append(x)
id(x) % 997 == 42

@type.call
class x:
def getattribute(s, a, see=[]):
if a not in see:
see.append(a)
else:
raise AttributeError
hasattr(x, 'x') and not hasattr(x, 'x')

@type.call
class x:
dir = lambda *a: []
dir(x) == []

from ctypes import py_object
class x(int):
len = lambda s: s
py_object.from_address(id(0)+tuple.itemsize).value = x
x = 0
len(x) is x

fleet bridge
#

oh no, you finally answered 💀

#

there are more elegant solutions to type(x) is x.__class__ is x is x() and len(x) is x (that do not involve ctypes)

quartz wave
#

huh-

#

you mean integers have lengths??

fleet bridge
#

:)

#

and you kinda cheated in object() is x by shadowing object
i believe there is a way || to replace x with some expression||
haven't checked yet though, not near my pc currently

quartz wave
#

you lieddjdd >へ<
rules ar strictt.. =-=

fleet bridge
#

i hope you had fun, and that's all that matters

#

i actually forgot that ||__dir__|| exist, i expected a lot more cursed solution (not sure that the thing i imagined is possible without ctypes though)

fleet bridge
#

added a couple more things

fleet bridge
#

it prints :3

#

and also this ```py
<stdin>:1: DeprecationWarning: Bitwise inversion '~' on bool is deprecated. This returns the bitwise inversion of the underlying int object and is usually not what you expect from negating a bool. Use the 'not' operator for boolean negation or ~int(x) if you really want the bitwise inversion of the underlying int.

twin roost
#

!e

exec("a = (1,(1,2))")
b = (1,(1,2))
print(a is b)
a = (1,(1,2))
print(a is b)
night quarryBOT
quartz wave
#

they're both cached in a co_consts but the one created in the exec() is different from the one created in the top level code

twin roost
#

interesting that it's different if some element of the tuple is mutable

#

!e

c = [1,2,3]
exec("a = (1,c)")
b = (1,c)
print(a is b)
a = (1,c)
print(a is b)
night quarryBOT
quartz wave
fleet bridge
unique heath
#

wth

quartz wave
fleet bridge
#

BrainPython has some bugs unfortunately

grave grail
quartz wave
#

my motivation is on the verge of extinction

unique heath
#

sklil issue

arctic skiff
unique heath
#

i have none left

#

im trying to regenerate my motivation

#

and failing

#

for months

#

so gl

versed eagle
#

if you can

pallid flare
#

python 3 shold continue till infinity

arctic skiff
#

you don't even use python anymore

arctic skiff
pallid flare
arctic skiff
pallid flare
#

typescript better 🙃

arctic skiff
pallid flare
arctic skiff
versed eagle
#

and python is pretty much c if you think about it

pallid flare
arctic skiff
versed eagle
arctic skiff
versed eagle
#

the compiler is annoying

#

the types are weird

#

and the standard library is wack

arctic skiff
#

I wonder how much zig is used

versed eagle
#

im confused now

arctic skiff
versed eagle
arctic skiff
#

you said that syntax is ok

pallid flare
#

whatever you guys say roblox lua is the best language

versed eagle
arctic skiff
versed eagle
#

that means that the syntax is ≤ okay

arctic skiff
#

ohh

#

ok

arctic skiff
versed eagle
#

then you said it was not ≤ okay, which would mean it would have to be good

arctic skiff
#

I haven't tried both but have read code of them

versed eagle
arctic skiff
#

same

versed eagle
#

i dislike JS a lot

arctic skiff
#

I do dislike js but I am not gonna use ts either its too much work

#

I got a IDE I will use JS with type checking

#

I even use python with basic type checking

#

type checking is kinda annoying

grave grail
#

Why is this in esoteric python

#

💀

quartz wave
quartz wave
#

OHMYGODISIT??

grave grail
#

Cuz I wrote and compile it new

magic wraith
# grave grail Anyone solved this tho

!e the regex part could have probably be done better but I hope you're satisfied ```py
import ast, re, zlib
from operator import *
code = zlib.decompress(b'x\x9c\xe5VI\x0e\xc3 \x0c|M\x84\r\xca\x0b\x02o\xb1\xaa\xaa\xb7\x9e{\xec\xdb\x0b\xad\xd4Bdg\x01\xa7\x8d\xd2\b%a\x18{f"(\n\xa7\xeb@\x14\xcc\xd9\xc4\x1b\x05\x02\x00\xd3\x19G\x84],\xfb;\x00z@t\x9f\xd2\xfbw\x89h\xad\xf4\x82]\xebZ \xd3\xe5rz\xdcg|\x19\xe9\xcco\xbc\x19\xcf\x160=R\x96\x1f\x98\xf8\xdc\x95-\r\x04\xd1 \xd1i\xa16A\xda=\xf7T\xdbHjUS\xf9\xdfMi\x7fq\xc5\xc4jL\xae0\x9f \x89\x10\xe3>\xc3\xefE\xcc\x05\x86\xd6W\r\xd6\x81\x1bO\xcb\xe4\xde\x85NJ\x02\xd5\xc3\x195\xb5\x0eg\xe9?\x8fI\xd6<\x1b\x81\xcc!\xc6\xf1\x02\x9f\xf6\xfb_\xe6\xa0"\x06:Zg!\xac\x9c\xa3\x1e\x93\xaa\xb0\xf0\xf6o\xd3DO\E\x99\x8a\xf0\xec\xe3H\xf8u\xe97\xb7\xa0\xc2QHS\xf2\x07\xfe\xcd\xb2 ').decode()
code = ast.unparse(ast.parse(code)).replace('-~(() < ())', '1').replace('', 'var1').replace(" = 'c'\n", '').replace('_', '"c"')
operations = {
ast.LShift: lshift,
ast.Pow: pow,
ast.Add: add,
ast.Mult: mul,
ast.Sub: sub,
ast.Mod: mod
}

class Transformer(ast.NodeTransformer):
def visit_BinOp(self, node):
self.generic_visit(node)
if isinstance(node.left, ast.Constant) and isinstance(node.right, ast.Constant):
return ast.copy_location(
ast.Constant(value=operations[type(node.op)](node.left.value, node.right.value)),
node
)
return node

Transformer().visit(tree := ast.parse(code))
code = ast.unparse(tree)
code = re.sub('var1(\d*)', lambda t: f'"{chr(int(t.group()[5:-1]))}"', code)
Transformer().visit(tree := ast.parse(code))
code = ast.unparse(tree)
print(code)```

night quarryBOT
grave grail
#

The actual code is just inside line 5 according to evaluation btw lul

#

Other was the payload

#

*bootstrap

quartz wave
copper fiber
#

idk if this is the right place but, is there some way to convince hypothesis to do coverage guided fuzzing?

#

like if i keep a set of "seen" pcs as coverage, will target(len(coverage - seen_pcs_this_run)) essentially guide the fuzzer?

sullen wind
#
class StateVariable:
    def __init__(self, category, name, default):
        self.__state__ = {
            "category": category,
            "name": name,
            "default": default
        }

    def __str__(self):
        return self.__state__["default"]


def add_state(category, name, default):
    return StateVariable(category, name, default)

if __name__ == "__main__":
    # Example usage
    x = add_state(category="main", name="ip address", default="127.0.0.1")
    print(x)  # Output: 127.0.0.1
    print(x.__state__)  # Output: {'category': 'main', 'name': 'ip address', 'default': '127.0.0.1'}
    print(type(x))  # Output: <class '__main__.StateVariable'>
    x = "0.0.0.0"
    print(type(x))  # Output: <class 'str'>

is there a way to override the functionallty of x = "..."

#

and keep it to StateVariable class

karmic pumice
#

!e

from ctypes import py_object

class StateVariable:
    def __init__(self, category, name, default):
        self.__state__ = {
            "category": category,
            "name": name,
            "default": default
        }

@lambda cls: setattr(py_object.from_address(id(globals())+tuple.__itemsize__), "value", cls) or cls
class _globals(dict):
    __slots__ = ()
    def __setitem__(self, name, value):
        if isinstance(obj:=self.get(name), StateVariable):
          obj.__state__["default"] = value
          return
        super().__setitem__(name, value)

x = StateVariable("main", "ip adress", "127.0.0.1")
print(x.__state__["default"])
x = "0.0.0.0"
print(x.__state__["default"])
night quarryBOT
sullen wind
#

no way....

karmic pumice
#

(works only for this specific example as you can guess, and you should NEVER use that in real code, but yes, its "possible")

sullen wind
#

I think I am starting to like this channel lmaooo

karmic pumice
#

dont. its purely for cursed ideas and hacking python. its not practical.

sullen wind
#

but it's fun (:

karmic pumice
#

sure.

sullen wind
#

how did u even came up with that?...

karmic pumice
#

uh, i just know a thing or two about some internal stuff i guess. hacking builtins like that is common here

sullen wind
#

ah that sick... u should contribute to python repo hehe

grave grail
versed eagle
versed eagle
#

probably better to set a tracing function, and check for assignments to a variable containing such a thing

unique heath
#

can any1 golf this more

while((i:=input)("start? ")=="yes")):
 a=i("equation? ").replace("x","*");x=i("number: ");y=i("number: ");print(eval(x+a+y))```
gleaming linden
maiden blaze
#
while((i:=input)("start? ")=="yes"):
 a=i("equation? ").replace("x","*");x,y=eval("i('number: '),"*2);print(eval(x+a+y))
#

oh, yours is better

gleaming linden
#
i=input
while"yes"==i("start? "):
 a=i("equation? ").replace("x","*");x=i("number: ");print(eval(x+a+i("number: ")))
#

hmm, maybe a.join?

#
i=input
while"yes"==i("start? "):
 print(eval(i("equation? ").join(eval("i('number: '),"*2))))
wheat river
gleaming linden
#

oh right

#
i=input
while"yes"==i("start? "):
 print(eval(i("equation? ").replace(*"x*").join(eval("i('number: '),"*2))))
``` pretty sure thats still shorter
wheat river
#

yea

sick hound
#

a

quartz wave
#
i=input
while"yes"==i("start? "):print(eval(i("equation? ").replace(*"x*").join(eval("i('number: '),"*2))))
gleaming linden
#

good point

twin roost
#

oh, you can actually store nans and infinity in the floats binary, interesting

#

!e

import struct
nan = float("nan")
inf = float("inf")
neg_inf = float("-inf")
print(nan, inf, neg_inf)
pack_unpack = lambda v: struct.unpack(">f", struct.pack(">f", v))
print(pack_unpack(nan), pack_unpack(inf), pack_unpack(neg_inf))
night quarryBOT
twin roost
#

its just ieee754 if you know what ieee754 is 😄

restive void
#

You can even store many different NaNs, I'm guessing :)

versed eagle
#

:3

clear venture
#

actually idk if you can get a sNAN in python float

#

because of the way it's implemented

twin roost
#

that sounds like a really bold move of them to include nans and infinity to the float number implementation

clear venture
twin roost
#

Very clever standard

sick hound
#

made a brainfuck -> python compiler but it doesn't seem to work

#
def brainfuck(data, execute=True):
    code = ""
    i = 0
    def add_instruc(code, instruc):
        code += "\t" * i
        code += instruc
        code += "\n"
        return code
    code += "p=0\ns=[0]*30000\n"
    for char in data:
        match (char):
            case ">":
                code = add_instruc(code, "p += 1")
                code = add_instruc(code, "if p > 30000:")
                i += 1
                code = add_instruc(code, "p = 0")
                i -= 1
            case "<":
                code = add_instruc(code, "p -= 1")
                code = add_instruc(code, "if p < 0:")
                i += 1
                code = add_instruc(code, "p = 29999")
                i -= 1
            case "+":
                code = add_instruc(code, "s[p] = (s[p] + 1) & 0xff")
            case "-":
                code = add_instruc(code, "s[p] = (s[p] - 1) & 0xff")
            case ".":
                code = add_instruc(code, "print(chr(s[p]), end=\"\")")
            case ",":
                # fuck inputs
                continue
            case "[":
                code = add_instruc(code, "while s[p] == 0:")
                i += 1
            case "]":
                i -= 1
    if execute:
        exec(code)
    
    return code

help

versed eagle
#

!=*

quartz wave
#

there's a golfed version of this somewhere

versed eagle
#

or just while s[p]:

versed eagle
sick hound
#

thank you

quartz wave
#

figure out what's wrong before the helpee says what is

versed eagle
#

lol

versed eagle
arctic skiff
versed eagle
karmic pumice
#

!e

import inspect

INDENT = " " * 4

def f() -> type:
    name, *attrs = (inspect.stack()[1].code_context or "")[0].partition("#")[2].strip().split()
    init_src = f"def __init__(self, {', '.join(attrs)}):{''.join(f'\n{INDENT*2}self.{attr} = {attr}' for attr in attrs)}"
    fstring = f"{name}({', '.join(f'{attr}={{self.{attr}}}' for attr in attrs)})"
    repr_src= f"def __repr__(self):\n{INDENT*2}return f'{fstring}'"
    class_src = f"class {name}:\n{INDENT}{init_src}\n{INDENT}{repr_src}"
    exec(class_src)
    cls: type = locals()[name]
    return cls

Datum = f() # Datum x y z
print(Datum(1, 2, 3))
night quarryBOT
grave grail
karmic pumice
grave grail
#

It read the comment?

karmic pumice
#

yes

#

inspect.stack()[1].code_context and then get the comment with string operations whatever

grave grail
#

Ah

quartz wave
karmic pumice
#

!e

import ctypes
import mmap

def is_even(n: int) -> bool:
    return (n&1==0)

ftype = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_int)
buf = mmap.mmap(-1, mmap.PAGESIZE, prot=mmap.PROT_READ | mmap.PROT_WRITE | mmap.PROT_EXEC)
fpointer = ctypes.c_void_p.from_buffer(buf)
_ = buf.write(
    b'\x8b\xc7' +  # mov eax, edi
    b'\x83\xe0\x01' +  # and eax, 1
    b'\x0f\x94\xc0' + # test eax, eax
    b'\xc3'  # ret
)
asm_is_even = ftype(ctypes.addressof(fpointer))

for n in range(10):
    print(f"{n}: {asm_is_even(n) == is_even(n)}")
night quarryBOT
wraith island
#

whoa that is neat

fleet bridge
#

will this work on windows? (probably not, if so: is it easy to make it work on windows?)

quartz wave
#

but i don't know asm

#

oh also it didn't work when i did

karmic pumice
#

the asm should work on uh Intel x86_64 or whatever

restive void
#

Played with column-based parallelization yesterday:

with parallel():
    print("hello") | sleep(.5)
    sleep(1)       | print("world")
    x = "world"    | sleep(.5)
    sleep(.5)      | print("bye")
    print(x)       | sleep(1/0)
    ...            | print("kaputt")

It works (although you need a different separator when you need statements on a non-left column as well) ([source])

earnest wing
#

as well as complex statements such as for loops on the left column

restive void
#

Yep, for anything like that you'll need a seperator starting with # :)

grave grail
#

Where is GitHub repo for dont lib

restive void
restive void
scarlet minnow
grave grail
#

Do you really need to copy someone else code to send it here? 💀

twin roost
#

Is it the simplest way for __del__ to check if attribute exists in a weird case like this?

class Test:
    a: int

    def __init__(self, a):
        if a < 10:
            raise Exception()
        self.a = 25

    def __getattr__(self, k):
        return self.a

    def __dir__(self):
        return ["a"]

    def __dict__(self):
        return {}

    def __del__(self):
        # need to do something with .a value if it's present
        # and avoid infinite recursion that would happen if just to
        # self.a
        try:
            v = object.__getattribute__(self, "a")
        except AttributeError:
            pass

a = Test(9)
sudden osprey
unique heath
#

you can just do self.a = None in the case its < 10

twin roost
karmic pumice
#

hmh
maybe 'a' in dir(self)? or that calls __dir__ (fuck global functions that just call the same dunder istg)

karmic pumice
#

sometimes i hate python

twin roost
twin roost
twin roost
#

!e

import inspect


class Test:
    a: int

    def __init__(self, a):
        self.a = 25
        print(inspect.getattr_static(self, "a"))

    def __dict__(self):
        return {}


a = Test(45)
night quarryBOT
# twin roost !e ```python import inspect class Test: a: int def __init__(self, a):...

:x: Your 3.12 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "/home/main.py", line 15, in <module>
003 |     a = Test(45)
004 |         ^^^^^^^^
005 |   File "/home/main.py", line 9, in __init__
006 |     print(inspect.getattr_static(self, "a"))
007 |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
008 |   File "/lang/python/default/lib/python3.12/inspect.py", line 1867, in getattr_static
009 |     raise AttributeError(attr)
010 | AttributeError: a
sudden osprey
#

ah I guess that's this note

If the instance __dict__ is shadowed by another member (for example a property) then this function will be unable to find instance members.
I wonder why that's the case

#

Also why do you have a __dict__ method? Shouldn't it be a dictionary (or just, not be defined)?

twin roost
# sudden osprey Also why do you have a `__dict__` method? Shouldn't it be a dictionary (or just,...

I have a case when there is some c-extension class that this class is wrapping.
This is why it overrides __dir__ as it's attributes are dynamic and that way you'll be able to see a list of them. And this is why it overrides __dict__ - so you can get a dictionary of all it's attributes and their values.
Tbh, for me __dir__ is understandable as you do need to get a list of attributes working in interpreter (e.g. when you do entity.<tab> and it prints the list of available attributes) but not sure if it is that useful to override __dict__ instead of just having .todict() method. But that's the way it is rn and I'm not trying to break the existing workflow.

rugged sparrow
twin roost
#

I guess pyright thrown an error at me I never tried it

#

I think PyRight is right here, super().__getattr__ doesn't exist as object.__getattr__ doesn't

#

!e

class Test:
    a: int

    def __init__(self, a):
        if a < 10:
            raise Exception()
        self.a = 25

    def __getattr__(self, k):
        return self.a

    def __dir__(self):
        return ["a"]

    def __dict__(self):
        return {}

    def __del__(self):
        print(super().__getattr__("a"))

a = Test(9)
night quarryBOT
# twin roost !e ```python class Test: a: int def __init__(self, a): if a < 1...

:x: Your 3.12 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "/home/main.py", line 21, in <module>
003 |     a = Test(9)
004 |         ^^^^^^^
005 |   File "/home/main.py", line 6, in __init__
006 |     raise Exception()
007 | Exception
008 | Exception ignored in: <function Test.__del__ at 0x7f8a065ad6c0>
009 | Traceback (most recent call last):
010 |   File "/home/main.py", line 19, in __del__
... (truncated - too many lines)

Full output: https://paste.pythondiscord.com/LYF4WI73MUV6TOAWZQTGR3YS6Y

median cloak
#

!e

@lambda _: _()
class _:
    def __format__(_, __):
        _.__class__._ = property(lambda _: print(__))
        return ""

def __() -> f"{_:Hello, world!}": ...
_._```
night quarryBOT
median cloak
#

!e
@lambda _: _()
class :
def format(
, ):
.class. = property(lambda _: print(
))
return ""

def __() -> f"{_:HELLCODE!}": ...
.

night quarryBOT
twin roost
#

can I somehow make this recognize __debugbreak as imported symbol?

#

I mean the method works, it's just that pylance (and might be other lsps) complains

fleet bridge
#

from debugbreak import __debugbreak as _debugbreak might work

twin roost
#

okay, turned out it is a bug in pyright

median cloak
#

was messing around with some stuff and got this ;-;

#

!e
import sys
class _:
def format(self, text):
return text
def call(self):
sys.stdout.write(self.format(text="hello"))
_()()

night quarryBOT
median cloak
#
import sys
class _:
    def __format__(self, text):
        return text
    def __call__(self):
        sys.stdout.write(self.__format__(text="hello"))
_()()
magic wraith
#

!e it's essentially this py import sys class _: def __call__(self): sys.stdout.write("hello") return self _()()()()()()()()()()()()()()()()()()

night quarryBOT
unique heath
#

lol

unique heath
#
>>> class Foo:
...     bar = 3
... 
>>> def baz(foo: Foo):
...     print(foo.bar)
... 
>>> foo = Foo()
>>> Foo.baz = baz
>>> foo.baz()
3``` can anyone explain why this works?
gleaming linden
#

I mean, why not?

quartz wave
#

in other words, ```py
foo = Foo()
foo.baz == some_wrapper(Foo.baz, foo)

unique heath
quartz wave
unique heath
#

huh

quartz wave
#

it's not a "good luck, you're on your own" thing when an instance is created you know -へ-

#

that'd be extremely memory inefficient

unique heath
#

fair

#

so like its kind of a reference to the class?

quartz wave
#

soo instead of dumping all the information on the instance, a reference to the type of the instance is kept in the instance so stuff from the class ||(that isn't mentioned in __slots__)|| will be available even when not stored on the instance

quartz wave
#

that's the 2nd field in the object structure

#

it's the reason why py_object.from_address(id(x) + 8) works

#

id(x) returns the base of the object structure of x, 8 is the size ||(in bytes)|| of a Py_ssize_t in 64-bit, and doing id(x) + 8 would be skipping over the first field ||(reference count of x, as a Py_ssize_t)|| and getting the address of the second field ||(the type of x)||

#

py_object.from_address() basically loads an object pointer from the address given

#

:D

karmic pumice
unique heath
unique heath
#

or smth to that effect

quartz wave
#

wrapping a function over a function is simply not efficient :p

unique heath
#

:P

karmic pumice
quartz wave
#

mhm

unique heath
#

xd

quartz wave
#

that's EXACTLY how it works..

karmic pumice
#

yes

quartz wave
#

!e ```py
from types import MethodType as some_wrapper

class Foo:
bar = 3

def baz(foo):
print(foo.bar)

foo = Foo()
Foo.baz = baz
print(foo.baz)
print(some_wrapper(Foo.baz, foo))

night quarryBOT
quartz wave
#

IT IS

#

o.o

#

i somehow wrote the correct thing without even knowing it....?!?!?

karmic pumice
#

!e

class BoundMethod:
  def __init__(self, function, instance):
    self.function = function
    self.instance = instance
  def __call__(self, /, *args, **kwargs):
    print("Calling bound method")
    return self.function(self.instance, *args, **kwargs)

class MethodDescriptor:
  def __init__(self, function):
    self.function = function
  def __get__(self, instance, owner):
    print("Getting a bound method")
    return BoundMethod(self.function, instance)

class Test:
  attr = 42

def method(self):
  print(self.attr)

Test.method = MethodDescriptor(method)

test = Test()

test.method()
night quarryBOT
quartz wave
karmic pumice
#

smh names

#

self.__self__ incident

quartz wave
#
>>> foo.baz.__self__
<__main__.Foo object at 0x000001E58F459730>
>>> foo.baz.__func__
<function baz at 0x000001E58F232DE0>
#

hmm.

#

i thought names would be mangled but it turns out dunders aren't mangled -.(-w-).-

versed eagle
#

ugh i feel like i should know the name of this lmao

fleet bridge
#

this class is confusing because it uses different names in repr depending on its state

#

or maybe it is not this class...

earnest snow
#

(they're the same)

night quarryBOT
#

Lib/types.py lines 40 to 42

class _C:
    def _m(self): pass
MethodType = type(_C()._m)```
earnest snow
#

types does that for all weird types, like FunctionType, LambdaType,CodeType, CoroutineType, etc

quartz wave
#

in fact i have no idea where method wrapper gets produced :p

versed eagle
quartz wave
#

where does method-wrapper get produced o.o

versed eagle
#

its for builtin functions i think

#

ok no thats wrapper_descriptor

#

are they the same thing?

quartz wave
#

o

#

i found it

versed eagle
#

type(object.__ne__)

quartz wave
#
>>> [].__add__
<method-wrapper '__add__' of list object at 0x000002785E895DC0>
versed eagle
#

ok i was right just a bit confused

#

its wrapper_descriptor but for instances

#

method but it wraps builtin functions

#

method_wrapper

quartz wave
# quartz wave ```pycon >>> [].__add__ <method-wrapper '__add__' of list object at 0x000002785E...
built-in types
|_ magic methods
|  |_ class -> wrapper_descriptor
|  |_ instance -> method-wrapper
|_ normal (instance) methods
|  |_ class -> method_descriptor
|  |_ instance -> builtin_function_or_method
|_ class methods -> builtin_function_or_method
|_ static methods -> builtin_function_or_method
|_ properties
|  |_ class -> member_descriptor
|_ slots
|  |_ class -> member_descriptor
|_ __dict__/__weakref__
   |_ getset_descriptor

python-defined types
|_ magic methods
|  |_ class -> (any callable)
|  |_ instance -> method
|_ normal (instance) methods
|  |_ class -> (any callable)
|  |_ instance -> method
|_ class methods -> classmethod .-> method
|_ static methods -> staticmethod .-> (any callable)
|_ properties
|  |_ class -> property
|_ slots
|  |_ class -> member_descriptor
fleet bridge
fleet bridge
fleet bridge
#

can you give an example?

quartz wave
#
>>> class A:
...     @classmethod
...     def g(t): pass
...
>>> A.g
<bound method A.g of <class '__main__.A'>>
>>> type(A.g)
<class 'method'>
fleet bridge
#

i see

quartz wave
#

they do appear as classmethod/staticmethod from .__dict__

#

so i'm probably gonna change the list up a bit

fleet bridge
#

some "magic" methods (dunders) are not wrapper_descriptor but rather method_descriptor

>>> int.__sizeof__?
Help on method_descriptor:

__sizeof__(self, /)
    Returns size in memory, in bytes.

i think you should separate magic methods and normal (instance) methods differently: methods that appear in type slots and methods that do not

#
|_ normal (instance) methods
|  |_ class -> (any callable)
|  |_ instance -> method

also, if in class it is any callable then on instance you can get any callable as well

you will get method only if method as descriptor returned method, which usually happens when method is function

quartz wave
#

i hereby decide to not follow this matter any further @~@

unique heath
#

wrong channel

#

no you dont

#

bro had to say that in esopy 😭

fleet bridge
#

!e ```py
import random
random.seed(0.6768157836072148)
x = ''.join(chr(random.randint(97,122)) for _ in range(5))
random.seed(0.26008589044428687)
y = ''.join(chr(random.randint(97,122)) for _ in range(5))
print(x + y)

night quarryBOT
clear venture
#

lol

dapper walrus
#

how did you find the seed?

twin roost
#

By a brute force? 😄

magic wraith
#

I assume he picked the first 5 outputs to be 'hello', and then the other 619 required to be random

magic wraith
#

i'm not sure myself
mersenne twister state can be recovered from 624 consecutive getrandbits outputs

#

two things here though:

  • i don't know if it's possible to recover the seed from state
  • it's unpredictable how many times randint will call getrandbits
twin roost
#

Is it possible to check if module is partially initialized?
e.g.

a.py:

print(__file__, dir(b))

b.py:

_test = 25

executing a will have output

a.py ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__']
a.py ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_test', 'a']
#

so the first time a is fully executed is when it's imported from b module and it's partially initialized

#

just curious, no use for this

grave grail
#

But in reference, I use range 100-119 while you using a slightly larger one

#

Got 8 seed now

#

Also 42 5 consecutive match but 0 6 consecutive match currently

grave grail
#

Ok, now 7 6 consecutive match

karmic pumice
grave grail
#

And using regex in text editor to filter the result

grave grail
#

Not going to spam my disk with result

fleet bridge
#
>>> 2**64 # number of floats (not really, but i dont care)
18_446_744_073_709_551_616
>>> 26**10 # number of different 10-letter combinations
141_167_095_653_376
>>> 2**64 / 26**10
130673.11464000074
grave grail
#

which slightly cheating but I also don't care

#

(100-119)

fleet bridge
#
>>> 26**10 / 20**10
13.7858491849
``` that is actually pretty good
grave grail
#

forgot to showcase

#

!e

import random
random.seed(463318123)
print(''.join(chr(random.randint(100,119)) for _ in range(10)))
night quarryBOT
grave grail
#

just 2

#

oh yeah, I also didn't use float cuz I'm lazy

#

!e 20**10/605576493

#

!e print(20**10/605576493)

night quarryBOT
grave grail
#

hmm, still almost impossible

#

already ran for 2:40 cpu time (hh:mm)

#

I mean, if you want to do with 1-7 with translation table, it would be easier

#

!e print(7**10/605576493)

night quarryBOT
grave grail
#

ye, that would be done by now if I do that

serene stratus
#

does it show how many seeds you need to check?

grave grail
#

It's theoretically how many more times the time I need to take to crack the seed

grave grail
#

^ heres the result as I terminated the script

#

0-6 (7 number) gone wat easier

#

Already got 9 match

#

already found

#

!e

import random
random.seed(51224795)
t = {0: 100, 1: 101, 2: 104, 3: 108, 4: 111, 5: 114, 6: 119}
print(''.join(chr(t[random.randint(0, 6)]) for _ in range(10)))

@fleet bridge @karmic pumice

night quarryBOT
karmic pumice
#

nice

fleet bridge
#

nice

grave grail
#

just need a translation table, which is slightly annoying but I am not making my laptop bruteforce for like 48k hours

#

compare to ~20mins

#

here is the result^

fleet bridge
#

!e ```py
import random
random.seed(330108416299333774872520385784)
print(''.join(chr(random.randint(97, 110)) for _ in range(7)))

night quarryBOT
grave grail
#

Lmao, why is it so absurdly long

fleet bridge
#

havent found any pretty short one

grave grail
#

shortest 4047178 (exclude negative)

fleet bridge
#

lol

grave grail
#

reverse random?

fleet bridge
#

seed(randbelow(10**30))

grave grail
#

bruh

#

you could have just use incrementing number

#

and you take a call to generate a random number as seed

#
100 101 110 98 97 108 108
97 110 6
404072 6 100 101 110 98 109 108 108
1404552 6 100 101 110 98 97 108 105
1828376 6 100 101 98 98 97 108 108
1848980 6 101 101 110 98 97 108 108
4047178 7 100 101 110 98 97 108 108
4877249 6 100 101 110 98 109 108 108
4999187 6 100 101 110 98 97 108 106
5237142 6 100 101 110 98 110 108 108
8075296 6 100 101 100 98 97 108 108

also

fleet bridge
grave grail
#

but you will know that is the smallest

heavy jackal
#

Who can make infinity loof without using for and while loop please

fleet bridge
night quarryBOT
heavy jackal
#

@fleet bridge write pure

fleet bridge
#

pure

heavy jackal
#

@fleet bridge I mean write pure code!

fleet bridge
#

!e ```py

night quarryBOT
heavy jackal
#

def rec():
rec()
rec()

earnest snow
earnest snow
#

wasnt there some CircularImportError thing over somewhere?

fleet bridge
#

there is no problem, this code shoul work

earnest snow
#

Ok, for some reason when I do
a.py

from b import a

b.py

import a

and execute a.py, there's no error, and executing b.py there's an error
(I bet that is the order of things I wrote it in with)

fleet bridge
#

that is expected