0
Python
                yanxu@staff.sina.com.cn




2009   11   4
yield




2009   11   4
def f1(t):
                   newt = []
                   for i in t:
                       newt.append(i+1)
           ...
[i+1 for i in arr]

                (i+1 for i in arr)




2009   11   4
__call__




2009   11   4
class M(object):
                    def __init__(self,f):
                       self.f = f
                    def __cal...
>>>t2 = M(2)
                >>>t2(5)
                10
                >>>t3 = M(3)
                >>>t3(10)
          ...
2009   11   4
__len__




2009   11   4
class A(object):
                    def __len__(self):
                       return 10




2009   11   4
>>>a = A()
                >>>len(a)
                10




2009   11   4
from multiprocessing import Process,Pool,cpu_count




2009   11   4
Meta Class




2009   11   4
New Style vs Old Style




2009   11   4
DClass = type(‘DClass’,(object,),{‘spam’:‘eggs’})




2009   11   4
Upcoming SlideShare
Loading in...5
×

Python交流

813

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
813
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
32
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Python交流"

  1. 1. Python yanxu@staff.sina.com.cn 2009 11 4
  2. 2. yield 2009 11 4
  3. 3. def f1(t): newt = [] for i in t: newt.append(i+1) return newt def f2(t): for i in t: yield i+1 2009 11 4
  4. 4. [i+1 for i in arr] (i+1 for i in arr) 2009 11 4
  5. 5. __call__ 2009 11 4
  6. 6. class M(object): def __init__(self,f): self.f = f def __call__(self,v): return v*self.f 2009 11 4
  7. 7. >>>t2 = M(2) >>>t2(5) 10 >>>t3 = M(3) >>>t3(10) 30 >>>callable(t2) True 2009 11 4
  8. 8. 2009 11 4
  9. 9. __len__ 2009 11 4
  10. 10. class A(object): def __len__(self): return 10 2009 11 4
  11. 11. >>>a = A() >>>len(a) 10 2009 11 4
  12. 12. from multiprocessing import Process,Pool,cpu_count 2009 11 4
  13. 13. Meta Class 2009 11 4
  14. 14. New Style vs Old Style 2009 11 4
  15. 15. DClass = type(‘DClass’,(object,),{‘spam’:‘eggs’}) 2009 11 4
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×