Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change three occurences of xrange() to range() for compatibility with… #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

warrickball
Copy link

I just tried to run this basic example on my system under Python 3, which I called test_pymacula.py:

#!/usr/bin/env python3

import numpy as np
import matplotlib.pyplot as pl
import pymacula

t = np.arange(0, 500, 0.05)
model = pymacula.MaculaModel()
pl.plot(t, model(t))
pl.show()

and ran into the error

Traceback (most recent call last):
  File "test_pymacula.py", line 8, in <module>
    model = pymacula.MaculaModel()
  File "/home/wball/pypi/pymacula/pymacula/macula.py", line 179, in __init__
    self.spots = [Spot() for i in xrange(nspots)]
NameError: name 'xrange' is not defined

So I replaced three occurences of xrange to range. This gets the code running under Python 3. I haven't tested under Python 2 but as long as the number of spots is small I don't imagine there's a problem. If there is and you want to preserve Python 2 compatibility we can use a trick like

try:
    range = xrange
except NameError:
    pass

or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant