【发布时间】:2018-04-05 18:52:38
【问题描述】:
这感觉就像一个愚蠢的错误,我要把自己踢倒,但我觉得我已经尝试了一切。
基本上,当我尝试从孩子访问父方法时,它说我缺少目标参数:
Traceback (most recent call last):
File "remote_submission_rand.py", line 113, in <module>
XYZ.rsyncFile(source, outfiles)
TypeError: rsyncFile() missing 1 required positional argument: 'destination'
这显然听起来像是我在组织继承时对 self 做错了,但我已经玩了几个小时并且无法得到有效的东西。有什么建议会很感激吗?
请参阅下面的父类和子类:
儿童班:
from abc import ABCMeta, abstractmethod
import subprocess
import sys
class Connection(metaclass=ABCMeta):
"""This is an abstract class that all cluster classes inherit from."""
def __init__(self, cluster_user_name, ssh_config_alias, path_to_key):
"""In order to initiate this class the user must have their ssh config file set up to have their cluster connection as an alias."""
self.user_name = cluster_user_name
self.ssh_config_alias = ssh_config_alias
self.path_to_key = path_to_key
# add the ssh key so that if there's a password then the user can enter it now
ssh_add_cmd = "eval `ssh-agent -s`;ssh-add " + self.path_to_key
subprocess.check_output(ssh_add_cmd, shell=True)
self.job_numbers_to_wait_for = []
# instance methods
def rsyncFile(self, source, destination, rsync_flags = "-aP"):
rsync_cmd = ["rsync", rsync_flags, source, self.ssh_config_alias + ":" + destination]
exit_code = self.sendCommand(rsync_cmd)
return exit_code
父类:
from base_connection import Connection
import subprocess
class XYZ(Connection):
def __init__(self, cluster_user_name, ssh_config_alias, path_to_key):
Connection.__init__(self, cluster_user_name, ssh_config_alias, path_to_key)
#instance methhods
def rsyncFile(self, source, destination, rsync_flags = "-aP"):
super(XYZ, self).rsyncFile(source, destination, rsync_flags)
return
类的使用:
from connections import XYZ
outfiles = '/path/to/outfiles'
source_path = '/path/a_file.list'
XYZ.rsyncFile(source_path, outfiles)
补充: 我也试过在 XYZ 类中完全没有 rsyncFile 函数,得到了完全相同的错误。
【问题讨论】:
标签: python-3.x class inheritance