3 ms·
i'm not the author but i frequently code in python and am unable to understand what you're saying from that snipped of code. 1. you can overwrite everything in
by y4mi 10y ago
i'm not the author but i frequently code in python and am unable to understand what you're saying from that snipped of code.
1. you can overwrite everything in python
2. seed has been set to a string
3. obj uses the value of previously set 'seed' variable, which should be a string at that point.
its not a good idea, like overwriting the id variable, but it should work...
and just in case somebody wonders: its still possible to use the "true" seed() by calling it over __builtins__.seed()
i did similar stuff previously without realizing and only found out about this after i switched to a real IDE that warned me about overwriting inbuilt functions
- geofft 10y agoYes, that's correct. >>> from random import seed >>> seed(10) >>> seed <bound method Random.seed of <random.Random object at 0x24721c0>> >>> seed = 50 >>> seed 50 >>> from random import seed >>> seed <bound method Random.seed of <random.Random object at 0x24721c0>> (You can't get it as __builtins__.seed because it's not a builtin, but you can re-import it from random to get it back.)
- ecdavis 10y ago'seed' is explicitly imported on line 18, then overwritten on line 736, and yet it's used as a function on line 526. As far as I can tell, that is an error. >>> from random import seed >>> def f(): return seed(10) >>> seed = 50 >>> f() Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> f() File "<pyshell#2>", line 1, in f def f(): return seed(10) TypeError: 'int' object is not callable >>> I haven't run the script, so take this with a grain of salt. EDIT: Since generate_spaceship is always called with an empty random_seed parameter, this error won't happen when the script is run.