Hey new programmers to python.
I had a problem of importing the built-in module 'random'.
Make sure you do not name your program after the module.
a. If you do, you have to delete the newly created random.pyc or other
random. file name duplicates in the file which holds the random.py you
created. These are GUI files that can be placed in trashcan. This step
should solve 100% of your file duplicate problems if you have python
Learn to recognize the original files. From a mistake of my own I
found the path to the module in the Python standard library. MAC Path
just before module is named:
Use 'cd ..', 'ls', and 'cd' to get to python2.7 and enter 'ls' and you
will see a lot of original files with .py, .pyo, .pyc endings. This is
the location that they only should be in other than a similar path but
in a different python version.)
i. If you still think you have newly created files floating about in
the library use command;
find ./python2.7 -name random.* -ls
This will list the date of all files that start with 'random.' and
if there any have dates that do not match with the original
installation date or update dates, that is the file that is
causing the problem.
ii. You can also type this command into terminal to find
files but it doesn't list the time of installation;
mdfind kMDItemFSName == random.py
Obviously, since you know what the original file path looks like,
you'll be able to not target the wrong file!
Once you eliminated new files, rename your program anything other than random.py and possibly anything other than reserved words in python. I called mine generator.py
Make sure when in terminal you are in the right path before you start 'python', and type 'import generator' (or what the program is called).
To get to the right path use 'ls', 'cd' commands to get to the path that ends with the file that holds the program. (This was the last block to getting the import to work - I spent at least 6 hrs agonizing I had other hidden newly created .pyc files even when the command searches I had done above yielded none.
You find yourself blocked, take a break, and come back to it. Something clicked in my head after looking at several places online including stackflow, python.org (https://docs.python.org/2/tutorial/modules.html), and all this talk about paths.
I was never in the right path before I imported!!
Enter 'import generator'
You should get an output of 10 numbers from 0.0 to 1.0
I answered how to find new versions of random.py, random.pyc, and random.pyc. I partially answered how to clear the new ones, especially the ones you can manually dump in your trashcan. I still do not know how to find temporary cached version of the files because apparently that wasn't the problem! The problem was I named my program a bad name, and I was not in the right path before I started python and importing.