Parameters not getting passed properly

Here's an excerpt of my code:

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})

If I enter listFrom('LON'), the program returns [DBG] here: LON as expected. However, when I do book('LON', 'MAN', 8) I get an inexplicable [DBG] here: ☺; there: ☻; amount: ♥. What could be the cause of this?

Answers


This code works without problems in Python 2.6 on 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

What Python version are you using? On which OS/architecture?


Need Your Help

Elegant schema to log users' actions

database database-design notifications relational-database database-schema

I have a database schema to log operations users perform in my webapp:

Is .NET's GzipStream compatible with Qt's zlib-based qCompress/qUncompress?

.net qt compression gzip zlib

Is .NET's GzipStream compatible with Qt's zlib-based qCompress/qUncompress? I believe they both use the deflate algorithm, so would I be able to use .NET's DeflateStream or GzipStream to read data

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.