Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet260/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   256   257   258   259   260   261   262   263   ...   453
lISTINg 12-1: 
 Discovering the default action and installed filters
# Import the required modules.
import warnings
# Display the default action. 
print ‘Default action:’, warnings.default_action
# Display the default filters.
print ‘\nDefault Filters:’ 
for filter in warnings.filters:
print ‘Action:’, filter[0],
print ‘Msg:’, filter[1],
print ‘Cat:’, str(filter[2]).split(“‘“)[1].split(‘.’)[1],
print ‘Module:’, filter[3],
print ‘Line:’, filter[4]
# Add new filters. 
warnings.filterwarnings(‘always’, message=’Test’, category=UserWarning)
warnings.filterwarnings(‘always’, message=’Test2’, category=UserWarning,
module=’Test’) 
warnings.filterwarnings(‘always’, message=’Test3’, category=UserWarning,
module=’Test’, append=True)
# Display the updated filters.
print ‘\nUpdated Filters:’ 
for filter in warnings.filters:
print ‘Action:’, filter[0],
try:
print ‘Msg:’, filter[1].pattern,
except AttributeError:
print ‘None’,
print ‘Cat:’, str(filter[2]).split(“‘“)[1].split(‘.’)[1],
try:
if len(filter[3].pattern) == 0:
print ‘Module: Undefined’,
else:
print ‘Module:’, filter[3].pattern,
except AttributeError:
548592c12.indd 246
2/24/10 12:48:46 PM
www.finebook.ir


Understanding IronPython Warnings
 

 
247
print ‘Module: None’,
print ‘Line:’, filter[4]
# Pause after the debug session.
raw_input(‘\nPress any key to continue...’)
The code begins by importing the 
warnings
module. It then displays (using 
warnings.default_
action
) the default action that the interpreter will take when it encounters a warning. As shown in 
Figure 12-4 and described in Table 12-2, the default action is 
‘default‘
.
FIgURE 12-4: 
The example shows the default actions and filters, along with the output of filter changes.
Because of space limitations in this book, the text of Listing 12-1
shows two lines of code as being split, when they should appear on a
single line. You would type the 
warnings.filterwarnings(‘always‘, 
message=‘Test2‘, category=UserWarning, module=‘Test‘)
 and
warnings.filterwarnings(‘always‘, message=‘Test3‘, 
category=UserWarning, module=‘Test‘, append=True)
 lines of code
on a single line. The example won’t work if you type the code on multiple 
lines as shown.
The next step is to show the default filters that the interpreter provides for you. It may surprise you 
to know that the interpreter does include some default filters for the 
PendingDeprecationWarning

ImportWarning
, and 
BytesWarning
, as shown in Figure 12-4. These default filters make the interpreter 
easier and more enjoyable to use, but could also hide important bugs, so you need to be aware of them.
In order to show how actions and filters work, the example adds three filters using the 
warnings 
.filterwarnings()
function. The first filter simply tells the interpreter to always display warnings 
about the 
Test
message provided in the 
UserWarning
category. The second filter specifies that the 
Test2
warning will appear in the 
Test
module. The third filter specifies that the interpreter should 
548592c12.indd 247
2/24/10 12:48:46 PM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   256   257   258   259   260   261   262   263   ...   453




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish