Python TypeError不支持%的操作数类型:' file'和' unicode' [英] Python TypeError unsupported operand type(s) for %: 'file' and 'unicode'
本文介绍了Python TypeError不支持%的操作数类型:' file'和' unicode'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在进行django字段验证,但无法弄清楚为什么我在本节中遇到类型错误:
I'm working on a django field validation and I can't figure out why I'm getting a type error for this section:
def clean_tid(self):
data = self.cleaned_data['tid']
stdout_handel = os.popen("/var/www/nsmweb/jre1.6.0_14/bin/java -jar /var/www/nsmweb/sla.jar -t %s grep -v DAN") % data
result = stdout_handel.read()
在将数据作为字符串变量传递之前,是否需要以某种方式转换数据?
Do I have to convert data somehow before I can pass it in as a string variable?
推荐答案
检查括号.
错
stdout_handel = os.popen("/var/www/nsmweb/jre1.6.0_14/bin/java -jar /var/www/nsmweb/sla.jar -t %s grep -v DAN") % data
可能是正确的.
stdout_handel = os.popen("/var/www/nsmweb/jre1.6.0_14/bin/java -jar /var/www/nsmweb/sla.jar -t %s grep -v DAN" % data )
这篇关于Python TypeError不支持%的操作数类型:' file'和' unicode'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文