Python 为什么调用我的类来让我的类工作时需要两个arg?
我正在Windows10上运行Python 3.3.4 以下是我的班级代码-Python 为什么调用我的类来让我的类工作时需要两个arg?,python,class,python-3.x,arguments,Python,Class,Python 3.x,Arguments,我正在Windows10上运行Python 3.3.4 以下是我的班级代码- class Curl(): def __init__(self): self.file7 = file7 self.Days1 = Days1 def readfile(self): ticknum = 0 read_ticker = [] ins = open(file7, "r" ) for line
class Curl():
def __init__(self):
self.file7 = file7
self.Days1 = Days1
def readfile(self):
ticknum = 0
read_ticker = []
ins = open(file7, "r" )
for line in ins:
if line.endswith('\n'):
line=line[:-1]
read_ticker.append(line)
ticknum =+1
ins.close()
return read_ticker
def CalcDates(self, Days1): # Determine dates
calculated_dates = dict()
Run_Time = (time.strftime("%H/%M/%S"))
calculated_dates['Run_Time']= Run_Time
Today = date.today()
calculated_dates['Today'] = Today
End_Date = (Today - timedelta(days=Days1))
calculated_dates ['Start_Date'] = Today
Start_Day = str(Today.strftime("%d"))
calculated_dates['Start_Day'] = Start_Day
Start_Month = str(Today.strftime("%m"))
calculated_dates['Start_Month'] = Start_Month
Start_Year = str(Today.strftime("%Y"))
calculated_dates['Start_Year']= Start_Year
End_Day = str(End_Date.strftime("%d"))
calculated_dates['End_Day'] = End_Day
End_Month = str(End_Date.strftime("%m"))
calculated_dates['End_Month']= End_Month
End_Year = str(End_Date.strftime("%Y"))
calculated_dates['End_Year']= End_Year
return calculated_dates
如果我执行以下操作,它将运行:
file7 = 'C:\\...\\file1.txt'
fileList = Curl.readfile(file7)
print('readTickers is complete')
print(fileList)
D1 = Curl.CalcDates( 90, 90)
print(D1)
我希望它运行,如果我改变了D1行如下;
D1=旋度计算值(90)
但它没有-我得到以下错误
Traceback (most recent call last):
File "C:\Users\Edge\Desktop\readTICKR class432.py", line 56, in <module>
D1 = Curl.CalcDates(90)
TypeError: CalcDates() missing 1 required positional argument: 'Days1'
回溯(最近一次呼叫最后一次):
文件“C:\Users\Edge\Desktop\readTICKR class432.py”,第56行,在
D1=旋度计算值(90)
TypeError:CalcDates()缺少1个必需的位置参数:“Days1”
为什么在调用Curl.CalcDates时需要进行双重论证?如何修复它以便使用单个参数?原因是
CalcDates
是一个实例方法,因此需要首先创建Curl
对象
D1 = Curl(file7, Days1).CalcDates(90)
您还需要修复\uuuuu init\uuuu
函数
def __init__(self, file7, Days1):
self.file7 = file7
self.Days1 = Days1