0

I was trying to see how nose & unittesting were being used in a package I'm learning about. This package uses nosetester, which is provided with numpy (why this is done also confuses me). My nosetester.py is in /usr/local/lib/python2.7/dist-packages/numpy/testing/. I am running Python 2.7.6. However, when I add a tracing statement of the form:

print "Hi"

to the __init__ method of the NoseTester class, I get a syntax error:

  File "/usr/local/lib/python2.7/dist-packages/numpy/testing/nosetester.py", line 182
print "Hi"
         ^

SyntaxError: invalid syntax

When I use

print ("Hi")

things work fine. I know my Python interpreter is using 2.7.6:

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

This leaves me wondering why the insistence on Python3 and is there anywhere else that I might run into this?

1
  • 3
    Is there a from __future__ import print_function line in nosetester.py? Commented Jan 28, 2015 at 15:39

1 Answer 1

2

Looks like nosetester.py has a line like

from __future__ import print_function

This makes the Python2-style print statement print "foo" unavailable and requires you to use the Python3-style print function print("foo") instead.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.