考虑以下示例 -
Python 2.4.3 (#1, Jan 14 2011, 00:20:04)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system("grep -i beatles blur.txt")
Blur's debut album Leisure (1991) incorporated the sounds of Madchester and shoegazing. Following a stylistic change.influenced by English guitar pop groups such as The Kinks, The Beatles and XTC.
0
>>> os.system("grep -i metallica blur.txt")
256
>>>
因此,在这种情况下,我不希望将搜索关键字的行打印在 Python shell 上,我只想要返回值,即如果关键字存在则返回 0,如果关键字不存在则返回非零。如何做到这一点?