Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name 'xrange' is not defined in Python 3 [duplicate]

I try to execute following code but can't with mistake: name 'xrange' is not defined

pages = (
    requests.get(
        build_group_request({
            "offset": WINDOW_SIZE * i,
            "count": WINDOW_SIZE,
            "fields": "sex,interests,bdate"
        })
    ).json()['response']['items']
    for i in xrange(int(float(COUNT) / 100 + 1))
)
like image 430
Jello Avatar asked Jun 28 '15 20:06

Jello


People also ask

Why is Xrange not working Python?

The “NameError: name 'xrange' is not defined” error is raised when you try to use the xrange() method to create a range of numbers in Python 3. To solve this error, update your code to use the range() method that comes with Python 3. range() is the Python 3 replacement for xrange() .

Why is Raw_input not defined in Python?

The NameError: name 'raw_input' is not defined occurs when you try to call the raw_input() function using Python major version 3. You can only use raw_input() in Python 2. To solve this error, replace all instances of raw_input() with the input() function in your program.


1 Answers

You're probably using Python3, where xrange has become range.

like image 150
DeepSpace Avatar answered Oct 19 '22 03:10

DeepSpace