Python异常处理

来源:互联网 发布:淘宝怎么花钱推广 编辑:程序博客网 时间:2024/06/02 02:15


1.报错:

Traceback (most recent call last):
  File "C:\Python33\jiyu\source\SimulationModule\SimulationProcess.py", line 198, in <module>
    task1.actor =  schedule_agent.ResourceAllocate("task1","all",current_time,new_case)
  File "C:\Python33\jiyu\source\SimulationModule\AllocationAlgorithms.py", line 864, in ResourceAllocate
    max_Q = -1*sys.maxint
AttributeError: 'module' object has no attribute 'maxint'

解决办法:

对报错的那行代码做如下修改 

try:
        max_Q = -1*sys.maxint
 except:
        return False 


2.再报错:

Traceback (most recent call last):
  File "C:\Python33\jiyu\source\SimulationModule\SimulationProcess.py", line 9, in <module>
    from AllocationAlgorithms import Random_Allocation, SWL_Allocation, SPT_Allocation, SCT_Allocation,Q_Learning_S_All_r1,Q_Learning_Table_Allocation,Q_Learning_Allocation_With_Workload,Q_Learning_Allocation_With_Workload_V2,Q_Learning_Allocation_With_Workload_V2_SC
  File "C:\Python33\jiyu\source\SimulationModule\AllocationAlgorithms.py", line 865
    max_Q = -1*sys.maxint
                        ^
TabError: inconsistent use of tabs and spaces in indentation

这个是外用文本编辑器对于tab 和 空格的定义问题,python里对于缩进有统一的要求,一般都用4个空格代替tab

解决办法:

a. 英文版,notepad++ --> view --> show symbol --> show all character

b.中文版, notepad++ --> 视图 --> 显示符号 --> 显示所有符号。

显示所有字符后,把tab都替换成4个空格。

0 0