Questions #1


@wraps (view) def wrapper



Download 85,32 Kb.
bet8/24
Sana06.07.2022
Hajmi85,32 Kb.
#752107
1   ...   4   5   6   7   8   9   10   11   ...   24
Bog'liq
interview en

@wraps (view)
def wrapper (request):
if perm in request.user.permissions:
return view(request)
else :
return HTTPRedirect( '/login' )
return wrapper
return decorator


@ has_perm( 'view_user' )
def users (request):
...

Why need @wraps?
wraps is a decorator from the standard Python distribution, functools module. It assigns the same __name__, __module__, __doc__ fields to the wrapper function as the original function you are decorating. This is necessary so that, after decorating, the wrapper function does not look like the original function in the stack traces.

Iteration and generators


What is the difference between [x for x in y] and (x for x in y)?
The first expression returns a list, the second a generator.
What's special about a generator?
The generator does not store all elements in memory, but only the internal state for calculating the next element. At each step, only the next element can be calculated, but not the previous one. You can only loop through the generator once.
How to declare a generator?

  • use syntax (x for x in seq)

  • yield statement in function body instead of return

  • the iter built-in function that calls the object's __iter__() method. This method must return a generator.

How to get a list from a generator?
Pass it to the list constructor: list(x for x in some_seq). It is important that after that it will no longer be possible to iterate over the generator.
Is it possible to extract a generator element by index?
No, there will be an error. The generator does not support the __getitem__ method.
What does iterating over a dictionary return?
Key. The order of the keys is not guaranteed. For small dictionaries, the order will be the same as in the declaration. For larger ones, the order depends on the location of the elements in memory. The special OrderedDict class respects the order in which keys are added.

Download 85,32 Kb.

Do'stlaringiz bilan baham:
1   ...   4   5   6   7   8   9   10   11   ...   24




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