[Tutor] Line matching without a for statement?
Tom Tucker
tktucker at gmail.com
Thu Oct 28 04:35:25 CEST 2004
Tutors,
Good evening. Is it possible to search/query a variable without doing
a for statement (ie. for line in ouptut). Hopefully my terminology is
correct. The below example script might make more sense. Thoughts?
Thanks,
Tom
SCRIPT (Example)
######################
#!/usr/bin/python
import os, re
output = os.popen('/sbin/ifconfig -a').readlines()
interface = re.compile(r'^eth\d')
if interface.search(output):
print "found an interface"
ERROR OUTPUT
###########################
Traceback (most recent call last):
File "./test.py", line 9, in ?
if interface.search(output):
TypeError: expected string or buffer
More information about the Tutor
mailing list