1

I have written a return function for my group project. I am using python 3.4 and wrote this:

def readrouter(x, y): conn = sqlite3.connect('server.db') cur = conn.cursor() cur.execute("SELECT DISTINCT command FROM router WHERE function =? or type = ? ORDER BY key ASC",(x, y)) read = cur.fetchall() return read; a = input("x:") b = input("y:") for result in readrouter(a,b): print (result[0]) 

As my major member is using 2.7 and I need to follow his version now. After I re-input my .py into python 2.7 there is a error:

x:create vlan Traceback (most recent call last): File "C:/Users/f0449492/Desktop/2015225/database.py", line 322, in <module> a = input("x") File "<string>", line 1 create vlan ^ SyntaxError: unexpected EOF while parsing Process finished with exit code 1 

how to fix this bug?

0

2 Answers 2

2

In Python 2.7, replace input() with raw_input().

The former runs eval() on the input string and expects valid Python code as input. Your input create vlan isn't valid Python and can't be eval'ed. The latter just returns a string with no further processing.

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

2 Comments

Omg, thank you but I should not ask this stupid question
It's OK, you're probably not the first person to have tripped over this. Having this answer out in the wild will at least reduce the odds of others going through the same thing :)
0

As a follow up - to ensure compatibility with both Python branches you may use six .

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.