News for hackers. Stuff that matters.
Re:Spaceship Generator by y4mi on Saturday June 18, 2016 @04:23PM (#11930448)
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

Re:Spaceship Generator by ecdavis on Saturday June 18, 2016 @06:54PM (#11931003)
'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.

Re:Spaceship Generator by geofft on Saturday June 18, 2016 @05:30PM (#11930695)
Yes, 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.)