python - AttributeError: 'str' object has no attribute 'fileno' -
code:
import subprocess def printit(): in range(6): j in range(6): query = "select rxpkts, txpkts ./log.csv datapath = "+str(i)+" , port = "+str(j) filename = str(i)+"_"+str(j)+".csv" open(filename, "w+"): p = subprocess.popen(["python", "q", "-h", "-d", ",", query], stdout=filename) printit()
error:
$ python processlog.py traceback (most recent call last): file "processlog.py", line 11, in <module> printit() file "processlog.py", line 9, in printit p = subprocess.popen(["python", "q", "-h", "-d", ",", query], stdout=filename) file "/usr/lib/python2.7/subprocess.py", line 702, in __init__ errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr) file "/usr/lib/python2.7/subprocess.py", line 1128, in _get_handles c2pwrite = stdout.fileno() attributeerror: 'str' object has no attribute 'fileno'
what issue? using q
the stdout
argument needs file object, not string filename.
try using -
import subprocess def printit(): in range(6): j in range(6): query = "select rxpkts, txpkts ./log.csv datapath = "+str(i)+" , port = "+str(j) filename = str(i)+"_"+str(j)+".csv" open(filename, "w+") f: p = subprocess.popen(["python", "q", "-h", "-d", ",", query], stdout=f) printit()
Comments
Post a Comment