Параметры не передаются должным образом - PullRequest
0 голосов
/ 27 февраля 2010

Вот выдержка из моего кода:

def listFrom(here):
    print "[DBG] here: " + here

def book(here, there, amount):
    print "[DBG] here: " + here + "; there: " + there + "; amount: " + str(amount)

# Code that takes input and stores it into the string input

# Yes, I know this is dangerous, but it's part of a
# school assignment where we HAVE to use eval.
eval(input, {"__builtins__": {}, "listAll": listAll, "listFrom": listFrom, "listFromTo": listFromTo, "book": book, "about": about, "commands": commands, "book": book})

Если я введу listFrom('LON'), программа вернет [DBG] here: LON как положено Однако когда я делаю book('LON', 'MAN', 8), я получаю необъяснимое [DBG] here: ☺; there: ☻; amount: ♥. Что может быть причиной этого?

1 Ответ

0 голосов
/ 27 февраля 2010

Этот код работает без проблем в Python 2.6 в Linux / x86-32:

>>> def listFrom(here):
...     print "[DBG] here: " + here
... 
>>> def book(here, there, amount):
...     print "[DBG] here: " + here + "; there: " + there + "; amount: " + str(amount)
... 
>>> book('LON', 'MAN', 8)
[DBG] here: LON; there: MAN; amount: 8
>>> input = """book('LON', 'MAN', 8)"""
>>> eval(input, {"__builtins__": {}, "listFrom": listFrom, "book": book})
[DBG] here: LON; there: MAN; amount: 8
>>> eval("""listFrom('LON')""", {"__builtins__": {}, "listFrom": listFrom, "book": book})
[DBG] here: LON

Какую версию Python вы используете? На какой ОС / архитектуре?

...