[英]How to accept string starting with # in python?
我正在开发一个python程序,我需要以下列方式在终端中输入hastag:
[delta@localhost Desktop]$ python CheckHastag.py #football
执行后抛出错误,因为IndexError:列表索引超出范围
这是因为Python是不接受的字符串开始以“#”,但我没有试过#
即
[delta@localhost Desktop]$ python CheckHastag.py football
有用。 那么如何让我的程序接受标签即字符串启动
#?
shell将#
视为注释的开头,因此Python解释器永远不会看到#
后面的内容。
这可以使用echo
命令轻松演示:
$ echo #football
$ echo football
football
您有几种方法可以解决此问题:
$ python CheckHastag.py "#football"
$ python CheckHastag.py '#football'
$ python CheckHastag.py \#football
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.