Class 如何更换班级成员?
我希望更改构造函数init中关键字的参数(self,arc, arc_type='discover')。我不能更改的关键字是arc_type='discover'。只能是 如果使用诸如文学之类的类变量,则会发生更改。_arc_type='url',并位于 构造函数,但它只保存在那里输入的信息('url'),并且从不更改为 如果需要,另一个(如“路径”)。谢谢Class 如何更换班级成员?,class,variables,constructor,keyword,Class,Variables,Constructor,Keyword,我希望更改构造函数init中关键字的参数(self,arc, arc_type='discover')。我不能更改的关键字是arc_type='discover'。只能是 如果使用诸如文学之类的类变量,则会发生更改。_arc_type='url',并位于 构造函数,但它只保存在那里输入的信息('url'),并且从不更改为 如果需要,另一个(如“路径”)。谢谢 Class Literature: _arc_type = () def __init__(self, arc, arc_type ='d
Class Literature:
_arc_type = ()
def __init__(self, arc, arc_type ='discover'):
self.arc = arc
self.arc_type = arc_type
Literature._arc_type = self.arc_type
def _discover_url(self):
Literature._arc_type = str('url')
self.arc_http = self.arc
def _discover_path(self):
self.arc_path = self.arc
Literature._arc_type = 'path'
def main():
#Instantiate Class
#Here I wish to update to arc_type='url'
p=Literature(arc =None, arc_type = 'url)
arc_http = input('Enter URL:\t')
resp_1 = arc_http.startswith('http')
if resp_1 !='False':
p.arc = src_http
p._discover_url() #Call this Class Function
#Here I wish to update to arc_type='path'
p = Literature(arc =None, arc_type = 'path')
arc_path = input(r'Enter path to your file: ')
resp_2 = arc_path.endswith('txt')
if resp_2 !='False':
p.arc = arc_path
# Update to arc_type='path'
p._discover_path()
# The keyword argument arc_type never changes and always remains 'discover'.
```