【发布时间】:2016-06-03 03:43:35
【问题描述】:
我在 Windows 10 上运行 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 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= Curl.CalcDates(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'
为什么我在调用 Curl.CalcDates 时需要进行双重论证?
我怎样才能解决它,以便我可以使用一个论点?
【问题讨论】:
标签: python class python-3.x arguments