【发布时间】:2013-05-20 05:32:51
【问题描述】:
我有一个可以工作的 Python 脚本,但在 Python 3 中一定发生了一些变化。
例如,如果我想将参数 1 转换为小写:
import string
print(string.lower(sys.argv[1]))
上面写着'module' object has no attribute 'lower' - 好的,我明白了,string 现在是一个模块。
如果我删除导入,只写string.lower('FOO'),它会抱怨name 'string' is not defined。
那么将字符串转换为小写的正确方法是什么?
【问题讨论】:
-
是的,您的第二个示例中没有
string变量。那么你想转换什么? -
为什么不
sys.argv[1].lower()? -
啊,我的错。我没有注意到我从谷歌搜索中找到的文档是针对 2.7 版的
标签: python string python-3.x