【发布时间】:2011-03-08 15:01:16
【问题描述】:
这是向 Python 添加符号的 SymbolType 包。那些使用 Lisp/Scheme 做过任何有用事情的人能否告诉我如何在 Python 中利用这种类型?
它可以用来将来自外部(来自网络)的字符串与内部代码隔离开来吗?
$ sudo easy_install SymbolType
$ ipython
很遗憾,您不能使用符号将值作为 kwargs 传递:
In [7]: X = s('X', __name__)
In [9]: a = {X: 10}
In [12]: Y = s('Y', __name__)
In [13]: a.update({Y: 20})
In [14]: a
Out[14]: {X: 10, Y: 20}
In [15]: for (k, v) in a.items():
....: print k, v
Y 20
X 10
In [16]: def z(X=0,Y=1):
....: print X, Y
....:
In [17]: z(**a)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
...<ipython console> in <module>()
TypeError: z() keywords must be strings
【问题讨论】:
标签: python lisp types scheme symbols