pypy有時候執行python程式錯誤
#py15.py import sys def r(a): i = a.find('0') if i == -1: sys.exit(a) excluded_numbers = set() for j in range(i/9*9,i/9*9+9): #same row if j!=i: excluded_numbers.add(a[j]) for j in range(0*9+i%9,9*9+i%9,9): #same col if j!=i: excluded_numbers.add(a[j]) r0=i/27*3 #blk 1st row c0=i%9/3*3 #blk 1st col for j in range(9): #same blk if (r0+j/3)*9+c0+j%3!=i: excluded_numbers.add(a[(r0+j/3)*9+c0+j%3]) for m in '123456789': if m not in excluded_numbers: r(a[:i]+m+a[i+1:]) if __name__ == '__main__': if len(sys.argv) == 2 and len(sys.argv[1]) == 81: r(sys.argv[1]) else: print ("Usage: python sudoku.py puzzle")
同樣的程式在python 2.7中能正確完成。
D:\pypy>timer pypy py15.py 800000000003600000070090200050007000000045700000100030001000068008500010090000400 Timer 3.01 Copyright (c) 2002-2003 Igor Pavlov 2003-07-10 debug: OperationError: debug: operror-type: OverflowError debug: operror-value: long int too large to convert to int Kernel Time = 0.093 = 00:00:00.093 = 0% User Time = 0.187 = 00:00:00.187 = 1% Process Time = 0.280 = 00:00:00.280 = 2% Global Time = 11.169 = 00:00:11.169 = 100% D:\pypy>timer python py15.py 800000000003600000070090200050007000000045700000100030001000068008500010090000400 Timer 3.01 Copyright (c) 2002-2003 Igor Pavlov 2003-07-10 812753649943682175675491283154237896369845721287169534521974368438526917796318452 Kernel Time = 0.078 = 00:00:00.078 = 5% User Time = 0.452 = 00:00:00.452 = 32% Process Time = 0.530 = 00:00:00.530 = 38% Global Time = 1.389 = 00:00:01.389 = 100%
知道錯在哪裡了。根據文件。
sys.exit([arg])
Exit from Python. This is implemented by raising the SystemExit exception, so cleanup actions specified by finally clauses of try statements are honored, and it is possible to intercept the exit attempt at an outer level.
The optional argument arg can be an integer giving the exit status (defaulting to zero), or another type of object. If it is an integer, zero is considered “successful termination” and any nonzero value is considered “abnormal termination” by shells and the like. Most systems require it to be in the range 0-127, and produce undefined results otherwise. Some systems have a convention for assigning specific meanings to specific exit codes, but these are generally underdeveloped; Unix programs generally use 2 for command line syntax errors and 1 for all other kind of errors. If another type of object is passed, None is equivalent to passing zero, and any other object is printed to stderr and results in an exit code of 1. In particular, sys.exit("some error message") is a quick way to exit a program when an error occurs.
Since exit() ultimately “only” raises an exception, it will only exit the process when called from the main thread, and the exception is not intercepted.
python的sys.exit()可以輸出錯誤資訊,貌似pypy的這個函式只能填寫短整數。把上述程式的
if i == -1: sys.exit(a)
改為:
if i == -1: print(a) sys.exit(-1)
就能正常執行了。
D:\pypy2>\timer pypy sd0v2p.py 800000000003600000070090200050007000000045700000100030001000068008500010090000400 Timer 9.01 : Igor Pavlov : Public domain : 2009-05-31 812753649943682175675491283154237896369845721287169534521974368438526917796318452 Kernel Time = 0.031 = 6% User Time = 0.436 = 85% Process Time = 0.468 = 91% Global Time = 0.511 = 100%
相關文章
- JiveJdon執行後執行註冊的時候碰到的錯誤,請教各位?
- 執行dbca命令的時候報錯了
- 在使用jbuild7執行jive論壇的時候出現下列錯誤UI
- 新手常見的Python執行時的17個錯誤Python
- 最近執行VBA程式碼時候出現這樣錯誤,現已經找到了問題所在處
- 使用rman執行recover database 的時候出現RMAN-06054的錯誤提示Database
- 用 PyPy 讓你的 Python 程式碼執行得更快!Python
- IntelliJ IDEA 執行專案的時候提示 Command line is too long 錯誤IntelliJIdea
- 執行錯誤集
- onbar備份的時候返回錯誤程式碼142
- 執行news例子說ejb沒有繫結錯誤
- Java程式設計師在寫SQL程式時候常犯的10個錯誤Java程式設計師SQL
- 卡巴斯機 任務執行時出現錯誤
- 誰遇到過執行 monkey 的時候報 filenotfound 的報錯
- 使用代理時常見的錯誤程式碼有哪些?
- Python程式設計最常見的錯誤有哪些?Python程式設計
- hiberante執行時候出現,sql執行完畢,但帶有警告是什麼意思?SQL
- 關於 ABAP 的執行時錯誤 ITAB_ILLEGAL_ORDER
- Struts1.1執行錯誤!
- 請教執行錯誤提示
- PBOOTCMS網站程式提示“執行SQL發生錯誤!錯誤:DISK I/O ERROR”boot網站SQLError
- 程式出錯時如何找到錯誤?
- 為什麼有時候spring mvc的interceptor會執行兩次SpringMVC
- Python 指令碼中呼叫 Java 程式時 Classpath 錯誤Python指令碼Java
- jdon框架在jboss中執行有時時出現出現錯誤,是什麼原因,如何處理框架
- PbootCMS錯誤提示:執行SQL發生錯誤!錯誤:no such column: def1bootSQL
- 執行SQL發生錯誤!錯誤:disk I/O errorSQLError
- Monkey 執行的時候,音樂播放..
- python程式計算執行時間差Python
- sqlplus執行指令碼時遇到錯誤自動停止SQL指令碼
- 動態建立 @ViewChild 導致執行時錯誤的原因分析View
- 安裝clusterware時候遇到版本不相容錯誤
- linux 實時檢視一個 python 程式有幾個執行緒LinuxPython執行緒
- 執行Bex 出現 61704 錯誤
- 求救!!!!!!jsp執行錯誤;(轉)JS
- Laravel 日誌有時候有許可權有時候沒有許可權?Laravel
- PbootCMS執行SQL發生錯誤!錯誤:no such column: def1bootSQL
- 建立cache group 時遇到 錯誤5120 時候的解決方案