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

1

24

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))
)
Sophi answered 28/6, 2015 at 20:27 Comment(4)
Are you in python 3?Aguiar
Refer to: #135541Edrei
@Sophi xrange doesn't exist in python 3 anymore you can use range insteadAguiar
Duplicate (not to mention the first hit for "python nameerror xrange"... come on): https://mcmap.net/q/54908/-nameerror-global-name-39-xrange-39-is-not-defined-in-python-3/3001761Cymar
R
59

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

Rattler answered 28/6, 2015 at 20:30 Comment(2)
Is it equivalent? Can I replace xrange in a python 2.x code with range so it works in python 3.x?Belldame
@A.Vieira You must, not canRattler

© 2022 - 2024 — McMap. All rights reserved.