Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中打印变量插值时出错_Python_Variables_Interpolation - Fatal编程技术网

在python中打印变量插值时出错

在python中打印变量插值时出错,python,variables,interpolation,Python,Variables,Interpolation,我是python新手,在python中面临变量插值概念的问题 我已经写了一个方法来检查参数,但是它在打印行时给出了错误 import re import sys import os.path def CheckArgument(argv) : for arg in argv : if (re.match('^-a$|^-b$|^-c$',argv) != 1) : if os.path.isfile(arg) != 1 :

我是python新手,在python中面临变量插值概念的问题 我已经写了一个方法来检查参数,但是它在打印行时给出了错误

   import re
   import sys
   import os.path

   def CheckArgument(argv) :
     for arg in argv :
      if (re.match('^-a$|^-b$|^-c$',argv) != 1) :
        if os.path.isfile(arg) != 1 :
            print ("file %s doesnot exists", % arg)
                            #above line is giving error
        elif re.match('-help',arg) == 1 :
             print "......."


   CheckArgument(sys.argv)

首先,
re.match()
返回一个
MatchObject
实例,而不是整数。表情

re.match('^-a$|^-b$|^-c$',argv) != 1
永远都是真的。只需使用
而不是

if not re.match('^-a$|^-b$|^-c$', argv):
以及:

您需要从打印语句中删除
%
运算符作用于左侧的字符串,但这并不意味着在两个字符串之间不应有逗号:

print ("file %s doesnot exists" % arg)
看起来好像您正在尝试解析命令行参数。你可以用这个来代替

print ("file %s doesnot exists" % arg)