我是新來的蟒蛇,不知道爲什麼我有這個IndentationError問題IndentationError在Python中definiation
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test1.py", line 27
occ_profile = get_occ_profile(daytype)
^
IndentationError: expected an indented block
有什麼建議?
import numpy
def create_profiles(n,month,daytype):
if daytype in ['weekday','weekend']:
pass
else:
print 'error in daytype'
return 0
if month in range(1,13):
pass
else:
print 'error in month'
return 0
no_its = n
idstring = str(no_its) + 'x_' + 'month-' + str(month) + '_' + 'daytype-' + str(daytype)
occ_profile_for_file = numpy.zeros([no_its,144])
for i in range (0,no_its):
occ_profile = get_occ_profile(daytype)
occ_profile_for_file[i][:] = occ_profile
Occfile = file('Occfile_'+idstring+'.dat', 'a')
numpy.savetxt('Occfile_'+idstring+'.dat',occ_profile_for_file,fmt="%d", delimiter='\t')
Occfile.close
您有'IndentationError',因爲此行沒有正確縮進。在行之前檢查空格的數量。也許你有一個'tab'而不是空格,這也會導致錯誤。 – Psytho
使用autopep8,它會爲你處理所有這些格式問題。 https://pypi.python.org/pypi/autopep8/ –