Python module error:Randint
Question: 
    from random import randint
    

This is the code I've used to import the Random module. When I run the code,
it instead imports a file of mine for testing code called **random.py**. This
was leading to all sorts of errors, so I 'permanently' deleted it in the
Recycle Bin and all it's shortcuts I could find.Yet it still is there
somewhere and it causes errors.My entire program depends on

    
    
    x = randint(1, 100)
    if x % 2 == 0:
        b = 'c'
    

The game I'm making depends in randint to randomly create ships and
submarines. I am running Windows 7.

Thanks


Answer: Python creates a _bytecode cache_ for each python module you import; for
Python 2 the same name as the original file with the extension `.pyc` is used.
It is that file that is imported when you import `random`, even if the source
`.py` file was deleted.

Use:

    
    
    import random
    print(random.__file__)
    

to locate the stale `random.pyc` bytecode file and delete it.

In Python 3 these files are normally stored in a subdirectory called
`__pycache__` but these are ignored if there is no corresponding `.py` source
file. People that want to distribute just the bytecode files (to obfuscate
their code in commercial software distributions, for eample) they'll have to
use the [`compilall` script with the `-b`
switch](https://docs.python.org/3/library/compileall.html#cmdoption-
compileall-b), something you almost certainly did not do.

