Python Generators - Talk at PySthlm meetup #15

  • 343 views
Uploaded on

Describing how you can use python generator functions to process a file without loading it all in memory before starting

Describing how you can use python generator functions to process a file without loading it all in memory before starting

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
343
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
4
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Python Generators PySthlm Meetup #15 – Python Best Practices – Oct 31, 2013 Samuel Lampa twitter.com/smllmp
  • 2. The “normal” (bad) way
  • 3. The “normal” (bad) way New temporary data structures created and kept in memory == BAD!!!
  • 4. Using Generator function
  • 5. Using Generator function A yield (“return”) for every iteration, so it can be used immediately without temp data structure == GOOD!
  • 6. Using Generator function A yield (“return”) for every iteration, so it can be used immediately without temp data structure == GOOD! So, this is the generator function
  • 7. Using Generator function A yield (“return”) for every iteration, so it can be used immediately without temp data structure == GOOD! So, this is the generator function … which can be iterated over, like this ...
  • 8. Using list-comprehension syntax
  • 9. Using list-comprehension syntax Here, the generator function Is defined in one row
  • 10. Chaining generator functions
  • 11. Chaining generator functions
  • 12. Creds and more info: ● David Beazleys Python Generator intro: →dabeaz.com/generators David Beazley on twitter: @dabeaz
  • 13. Thank you! Samuel Lampa G+: gplus.to/saml twitter: @smllmp Blog: saml.rilspace.org Developer @ www.uppmax.uu.se www.farmbio.uu.se www.rilpartner.se