Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.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 _init_;()正好接受4个参数_Python_Command Line Arguments_Argparse - Fatal编程技术网

Python _init_;()正好接受4个参数

Python _init_;()正好接受4个参数,python,command-line-arguments,argparse,Python,Command Line Arguments,Argparse,Python 2.6.6 r266:8429220012年9月11日08:28:27[GCC 4.4.6 20120305 Red Hat 4.4.6-4]在linux2上 我试图根据传递给python程序的命令行参数的数量,在User.py中实例化用户类的实例。我得到了TypeError:uuu init_uuuuu正好接受4个参数3,代码如下: #!/usr/bin/python import sys, argparse from user import User if __name__

Python 2.6.6 r266:8429220012年9月11日08:28:27[GCC 4.4.6 20120305 Red Hat 4.4.6-4]在linux2上

我试图根据传递给python程序的命令行参数的数量,在User.py中实例化用户类的实例。我得到了TypeError:uuu init_uuuuu正好接受4个参数3,代码如下:

#!/usr/bin/python
import sys, argparse
from user import User

if __name__ == "__main__":
  # Parse args
  parser = argparse.ArgumentParser("Batch insert")
  parser.add_argument('-d','--dbfilepath', dest='dbfilepath', help='Absolute path and filename of the sqlite database file', required=False, default='/usr/local/foo/bar.sqlite')
  parser.add_argument('-v','--verbose', dest='verbose', help='Verbose output', required=False, action='store_true')
  parser.add_argument('-l', '--list', help='comma-delimited list of username password pairs', required=True, type=str)
  args = parser.parse_args()
  my_list = [str(item) for item in args.list.split(',')]
  # Only continue if we have even number of items in the un/pw list
  if len(my_list) % 2 == 0:
    count = 0
    u = User(args.dbfilepath, args.verbose)
    while (count < len(my_list)):
      u.create(my_list[count], my_list[count+1])
      count = count + 1
执行:

./batch-insert.py -d /tmp/sql.sqlite -v --list stinky,cat

Traceback (most recent call last):
  File "./create-users-batch.py", line 15, in <module>
    u = User(args.dbfilepath, args.verbose)
TypeError: __init__() takes exactly 4 arguments (3 given)

我做错了什么?这两个文件都在同一个目录中。

是否有user.pyc文件在同一个目录中,而该目录是从用户使用额外arg时开始的?@BryanOakley,否,但为了确保,我删除了user.pyc并重试。同样的问题。是的,你抓到的用户与你想象的不同。导入用户;打印用户。\ uuuu文件\ uuuu会很有趣。@tdelaney:`Python 2.6.6 r266:84292,2012年9月11日,08:28:27[GCC 4.4.6 20120305 Red Hat 4.4.6-4]在linux2上键入帮助、版权、信用证或许可证以获取更多信息。>>导入用户;打印用户。\uuuu文件\uuuu用户.pycokay,在黑暗中拍摄。。。类User在User.py中定义了两次吗?!Python发现了一个名为User的类,其init接受3个参数加上self。实际上,没有太多的选项可以只使用用户模块。
./batch-insert.py -d /tmp/sql.sqlite -v --list stinky,cat

Traceback (most recent call last):
  File "./create-users-batch.py", line 15, in <module>
    u = User(args.dbfilepath, args.verbose)
TypeError: __init__() takes exactly 4 arguments (3 given)