Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
import random
#1
Hello,

I am using
import random
in my code. Every time I try and use this import, this error codes up.
Error:
NameError:name 'istart' is not defined random.py line 185 Python doesn't know what istart stands for
Python is giving me error for the random import. How do I fix this?
Reply
#2
What version of python do you have?

Do you have a "random.py" in your local directory? Has the "random.py" in your python lib directory been edited?

Go to a different directory and run python -c 'import random'. Do you get the same error?
Reply
#3
Do you have a file named random.py that you created? Post the full text of the error verbatim.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
(Nov-15-2020, 05:24 AM)buran Wrote: Do you have a file named random.py that you created? Post the full text of the error verbatim.

No i dont have a file named random.py .But when i use import random, a file named random.py comes up. [Image: ERRRI_1.png]
Reply
#5
You didn't say what version of python you have. The file that pops up looks like it has been modified and is missing a line.

This is the Python 3.7 random.py file. Note the line before your error is missing from your copy. I think your local version of python has been modified after installing.

    def randrange(self, start, stop=None, step=1, _int=int):
        """Choose a random item from range(start, stop[, step]).

        This fixes the problem with randint() which includes the
        endpoint; in Python this is usually not what you want.

        """

        # This code is a bit messy to make it fast for the
        # common case while still doing adequate error checking.
        istart = _int(start)
        if istart != start:
            raise ValueError("non-integer arg 1 for randrange()")
        if stop is None:
            if istart > 0:
                return self._randbelow(istart)
            raise ValueError("empty range for randrange()")
buran likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to import random? 1nc1 1 4,430 Feb-20-2019, 07:19 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020