Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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 解决TypeError的方法:需要一个整数(get type str)_Python_Python 3.x_Python 2.7 - Fatal编程技术网

Python 解决TypeError的方法:需要一个整数(get type str)

Python 解决TypeError的方法:需要一个整数(get type str),python,python-3.x,python-2.7,Python,Python 3.x,Python 2.7,我对计算年份的选择有问题 python flux2nc.py ../data/output/fluxes/ ../data/output/ IMPORTANT: ../data/output/fluxes/ SHOULD CONTAIN ONLY FLUXES FILES!!! Choose output parameter 1 - Precipitation 2 - Evapotranspiration 3 - Runoff 4 - Base f

我对计算年份的选择有问题

python flux2nc.py ../data/output/fluxes/ ../data/output/
    IMPORTANT: ../data/output/fluxes/ SHOULD CONTAIN ONLY FLUXES FILES!!!
    Choose output parameter
    1 - Precipitation
    2 - Evapotranspiration
    3 - Runoff
    4 - Base flow
    5 - Snow Water Equivalent
    6 - Soil moisture
    Choose output (1 a 6)>3
    Enter start year:2011
    End year:2012
    Traceback (most recent call last):
      File "flux2nc.py", line 240, in <module>
        main()
      File "flux2nc.py", line 234, in main
        flux2nc(sys.argv[1],sys.argv[2])
      File "flux2nc.py", line 120, in flux2nc
        inidate = dt.date(start_year,1,1)
    TypeError: an integer is required (got type str)

您的错误可能是您忘记将
输入(…)
强制转换为
int

start_year = input('Enter start year')
start_year = int(start_year)
对于
年终
输出
,您也应该这样做


注意:如果没有源代码,很难帮助您。我需要推断很多东西来帮助您诊断此错误。

您好!既然你看起来是新来的,请过去看看。这会帮助别人帮助你。如果您有疑问,请提供您的代码作为参考。快乐编码!请注意,错误是“需要一个整数(get type str)”。当您通过
input()
获得用户输入时,您会得到一个字符串
dt.date
需要整数(请参阅,因此您必须转换输入。此问题可能会有所帮助:。
start_year = input('Enter start year')
start_year = int(start_year)