如何更改班级成员?

问题描述

我希望更改构造函数 init(self,arc,arc_type = '发现')。我无法更改的关键字是 arc_type = 'discover'。它只能是 如果使用诸如literature._arc_type = 'url'之类的类变量并位于 构造函数,但它只保存那里输入的信息('url'),永远不会改变 如果需要,另一个(例如“路径”)。谢谢。

Class Literature:
_arc_type = ()
def __init__(self,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'.
   ```     
   

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)