Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python “AttributeError:'list'对象没有属性'get'”_Python_Python 3.x - Fatal编程技术网

Python “AttributeError:'list'对象没有属性'get'”

Python “AttributeError:'list'对象没有属性'get'”,python,python-3.x,Python,Python 3.x,在这里,我试图将英语日期转换为尼泊尔日期。 当我运行代码时,我得到AttributeError:'list'对象没有属性'get'作为错误。 下面是我的代码 from datetime import date import datetime import time import calendar engMonth=int(input('Enter birth month in A.D.')) engDate=int(input('Enter birth date in A.D.')) eng

在这里,我试图将英语日期转换为尼泊尔日期。 当我运行代码时,我得到AttributeError:'list'对象没有属性'get'作为错误。 下面是我的代码

from datetime import date
import datetime 
import time
import calendar

engMonth=int(input('Enter birth month in A.D.'))
engDate=int(input('Enter birth date in A.D.'))
engYear=int(input('Enter birth year in A.D.'))
以下是有效范围内每年每月的天数列表

尼泊尔年-月列表,其中,2000、2001、2002等为尼泊尔年,30、32、31等为月份的总天数

nepaliMonths = [
            [ 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],  #2000
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],  #2001
            [ 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
            [ 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
            [ 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
            [ 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
            [ 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],  #2071
            [ 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],  #2072
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],  #2073
            [ 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
            [ 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 ],
            [ 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30 ],
            [ 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 ],
            [ 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30 ],
            [ 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30 ],
            [ 31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30 ],
            [ 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30 ],
            [ 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30 ],
            [ 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 ],
            [ 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 ],  #2090
            [ 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30 ],
            [ 30, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30 ],
            [ 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 ],
            [ 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 30, 30 ],
            [ 30, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
            [ 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 ],
            [ 31, 31, 32, 31, 31, 31, 29, 30, 29, 30, 29, 31 ],
            [ 31, 31, 32, 31, 31, 31, 30, 29, 29, 30, 30, 30 ]   #2099
        ]


#define the least possible English date 1944/01/01 Saturday.

startingEngYear = 1944
startingEngMonth = 1
startingEngDay = 1
dayOfWeek = calendar.SATURDAY  #1944 is a saturday


#Let's define the equivalent Nepali date 2000/09/17.

startingNepYear = 2000
startingNepMonth = 9
startingNepday = 17


# Let's calculate the number of days between the two English dates as follows:

date0=date(engYear,engMonth,engDate)
date1=date(startingEngYear,startingEngMonth,startingEngDay)
delta=date0 - date1
# print (delta.days)


#initialize required nepali date variables with starting  nepali date
nepYear = startingNepYear
nepMonth = startingNepMonth
nepDay = startingNepday
此代码块中存在错误

# decreament delta.days until its value becomes zero
while delta.days != 0:

    # getting total number of days in month nepMonth in a year nepYear
    daysInMonth = nepaliMonths.get(nepYear)[nepMonth]
    nepDay+=1 # incrementing nepali day

    if(nepDay > daysInMonth):
        nepMonth+=1
        nepDay = 1

    if(nepMonth > 12):
        nepYear+=1
        nepMonth = 1

    dayOfWeek+=1 #counting the days in terms of 7 days
    if(dayOfWeek > 7):
        dayOfWeek = 1

    delta.days-=1   
Help

NepaliMonts是一个列表,实际上,列表没有.get方法

也许你指的是NepaLimonts[nepYear-startingNepYear][nepMonth]?

NepaLimonts是一个列表,实际上,列表没有.get方法

也许你指的是尼泊尔月[Nepyer-StartingNepyer][nepMonth]?

为什么不使用一个

有了字典,你可以有这样的东西:

nepaliMonths = { 2000: [ 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
                 2001: [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],

                 # Fill with rest of data . . .

                 2099: [ 31, 31, 32, 31, 31, 31, 30, 29, 29, 30, 30, 30 ] }
然后,为数据集编制索引,只需使用nepalimonts[年][月-1]

示例:尼泊尔月[2000][0]==30和尼泊尔月[2000][11]==31

另一种方法:

在当前的实现中,您只需使用nepalimonts[year-2000][month-1]

示例:尼泊尔月[0][0]==30和尼泊尔月[0][11]==31

为什么不使用一个数字

有了字典,你可以有这样的东西:

nepaliMonths = { 2000: [ 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
                 2001: [ 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],

                 # Fill with rest of data . . .

                 2099: [ 31, 31, 32, 31, 31, 31, 30, 29, 29, 30, 30, 30 ] }
然后,为数据集编制索引,只需使用nepalimonts[年][月-1]

示例:尼泊尔月[2000][0]==30和尼泊尔月[2000][11]==31

另一种方法:

在当前的实现中,您只需使用nepalimonts[year-2000][month-1]


示例:尼泊尔月[0][0]==30和尼泊尔月[0][11]==31

该错误非常具有描述性。您不能使用GetYear访问列表您正在使用nepyear作为idex,即2000。。。即使你删除了.get,你仍然会遇到超出范围的idex。问题在于你的错误列表,这个错误是非常描述性的。您不能使用GetYear访问列表您正在使用nepyear作为idex,即2000。。。即使你删除了.get,你仍然会遇到超出范围的idex。问题是你的nepyear@JohnGordon列表我尝试了你的方法,得到了索引器:列表索引超出范围作为错误@JohnGordon我尝试了你的方法,得到了索引器:列表索引超出范围作为错误