Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Python±ê×¼¿â tracebackÄ£¿é

Example 2-18 չʾÁË traceback Ä£¿éÔÊÐíÄãÔÚ³ÌÐòÀï´òÓ¡Òì³£µÄ¸ú×Ù·µ»Ø
(Traceback)ÐÅÏ¢, ÀàËÆÎ´²¶»ñÒ쳣ʱ½âÊÍÆ÷Ëù×öµÄ. Èç Example 2-18 Ëùʾ. 2.11.0.1. Example
2-18. ʹÓà traceback Ä£¿é´òÓ¡¸ú×Ù·µ»ØÐÅÏ¢ File: traceback-example-1.py # note!
import
Example 2-18 չʾÁË traceback Ä£¿éÔÊÐíÄãÔÚ³ÌÐòÀï´òÓ¡Òì³£µÄ¸ú×Ù·µ»Ø (Traceback)ÐÅÏ¢, ÀàËÆÎ´²¶»ñÒ쳣ʱ½âÊÍÆ÷Ëù×öµÄ. Èç Example 2-18 Ëùʾ.
2.11.0.1. Example 2-18. ʹÓà traceback Ä£¿é´òÓ¡¸ú×Ù·µ»ØÐÅÏ¢
File: traceback-example-1.py
# note! importing the traceback module messes up the
# exception state, so you better do that here and not
# in the exception handler
# ×¢Òâ! µ¼Èë traceback »áÇåÀíµôÒ쳣״̬, ËùÒÔ
# ×îºÃ±ðÔÚÒì³£´¦Àí´úÂëÖе¼Èë¸ÃÄ£¿é
import traceback
try:
raise SyntaxError, "example"
except:
traceback.print_exc()
Traceback (innermost last):
File "traceback-example-1.py", line 7, in ?
SyntaxError: example
Example 2-19 ʹÓà StringIO Ä£¿é½«¸ú×Ù·µ»ØÐÅÏ¢·ÅÔÚ×Ö·û´®ÖÐ.
2.11.0.2. Example 2-19. ʹÓà traceback Ä£¿é½«¸ú×Ù·µ»ØÐÅÏ¢¸´ÖƵ½×Ö·û´®
File: traceback-example-2.py
import traceback
import StringIO
try:
raise IOError, "an i/o error occurred"
except:
fp = StringIO.StringIO()
traceback.print_exc(file=fp)
message = fp.getvalue()
print "failure! the error was:", repr(message)
failure! the error was: 'Traceback (innermost last):\012 File
"traceback-example-2.py", line 5, in ?\012IOError: an i/o error
occurred\012'
Äã¿ÉÒÔʹÓà extract_tb º¯Êý¸ñʽ»¯¸ú×Ù·µ»ØÐÅÏ¢, µÃµ½°üº¬´íÎóÐÅÏ¢µÄÁбí, Èç Example 2-20 Ëùʾ.
2.11.0.3. Example 2-20. ʹÓà traceback Module Ä£¿é±àÂë Traceback ¶ÔÏó
File: traceback-example-3.py
import traceback
import sys
def function():
raise IOError, "an i/o error occurred"
try:
function()
except:
info = sys.exc_info()
for file, lineno, function, text in traceback.extract_tb(info[2]):
print file, "line", lineno, "in", function
print "=>


Ïà¹ØÎĵµ£º

pythonϵÄweb¿ª·¢¿ò¼Ü Django,djangoÄ£°åµÄʹÓÃ

Ä£°åÊǼòµ¥µÄÎı¾Îļþ£¬Ëü¿ÉÒÔÊÇhtml¸ñʽ»òÊÇxml,csvµÈ¸ñʽµÄ
Ä£°å°üÀ¨±äÁ¿£¬À¨Ëü»á±»ÖµËùÌæ´úµ±ÔËÐÐʱ£¬ÒÔ¼°±êÇ©Ëü¿ØÖÆÄ£°åµÄÂß¼­ÔËËãÈçif,elseµÈ
ÏÂÃæÊÇÒ»¸ö¼òµ¥µÄÄ£°å£¬ÎÒÃǽ«»á¶ÔËü×öÏêϸµÄ˵Ã÷
{% extends "base_generic.html" %}
{% block title %}{{ section.title }}{% endblock %}
{% block content %}
< ......

pythonϵÄweb¿ª·¢¿ò¼Ü Django,urlÅäÖÃ

urlÅäÖÃ
ÎÒÃÇÔÚpollsÕâ¸öappÏ´´½¨Ò»¸ö
helloworld.py
from django.http import HttpResponse
def index(request):
    return HttpResponse("Hello, Django.")
ÐÞ¸Ä urls.py
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
# from django.contrib ......

pythonµÄ±Õ°ü(3.0֮ǰ¼°Ö®ºó)

Ê×ÏÈ, ˵˵pythonÀïÃæµÄ±Õ°ü°É:
1. ÐèÒªº¯ÊýǶÌ×, ¾ÍÊÇÒ»¸öº¯ÊýÀïÃæÔÙдһ¸öº¯Êý.
2. Íⲿº¯ÊýÐèÒª·µ»ØÒ»¸öÄÚ²¿º¯ÊýµÄÒýÓÃ
3. Íⲿº¯ÊýÖÐÓÐһЩ¾Ö²¿±äÁ¿, ²¢ÇÒ, ÕâЩ¾Ö²¿±äÁ¿ÔÚÄÚ²¿º¯ÊýÖÐÓÐʹÓÃ
¸ÅÄî:
1. ×ÔÓɱäÁ¿: Íⲿº¯ÊýÖж¨ÒåµÄ¾Ö²¿±äÁ¿, ²¢ÇÒÔÚÄÚ²¿º¯ÊýÖб»Ê¹ÓÃ.
2. ±Õ°ü: ÄǸöʹÓÃÁË×ÔÓɱäÁ¿²¢±»·µ»ØµÄÄÚ²¿º¯Ê ......

PythonÖеĵ¥Ôª²âÊÔ

   ½ñÍíÊÔÁËÒ»ÏÂPython×Ô´øµÄµ¥Ôª²âÊÔ£¬Ö÷ÒªÊDzο¼ÁËPythonµ¥Ôª²âÊÔ¿ò¼Ü
µÄÓйØ×ÊÁÏ£¬ÕÛÌÚÁËÒ»¸öСʱ×óÓÒ£¬×ÜËãÔÚEric 4ͨ¹ýµÄ¼¸¸ö¼òµ¥µÄµ¥Ôª²âÊÔ¡£ÔÚÕâÀォËùµÃµÄÏà¹ØÖªÊ¶¼Ç¼ÏÂÀ´£¬·½±ã½«À´²éѯ¡£
    python×Ô´øµÄµ¥Ôª²âÊÔÄ£¿éÊÇunittest£¬´Ó2.1ÒÔºóΪ±ê×¼¿âµÄÒ»²¿·Ö
    1 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ