Adding to your PythonArmoryColton Myers@basepibasepi.net
• Configuration management• Remote execution• Orchestration• Much, much more• Easy to set up, easy to usesaltstack.com
Where we’re going• List Comprehensions• Generators• Decorators
files.basepi.net/talks/pyarmory.zip
Most of the code is stolen.files.basepi.net/talks/pyarmory.zip
List Comprehensions• Shortcut to map/filter operations• Condense a whole loop to one line• Very readable (to a point)
List ComprehensionsExamples
Generators
Generators• Infinite iterators• Memory-intensive iteration• Cooperative Multi-threading
# Build and return a listdef firstn(n):num = 0nums = []while num < n:nums.append(num)num += 1return numssumofn = sum(first...
What if integers were each 10MB?
What if we want the list to not end?
Solution?
Solution? Generators
GeneratorsTime for MoreExamples!
GeneratorsHow do they work?
ContinuationsHow do they work?
Continuations• “The rest”• Saves the execution stack, ready to resume• Continuations deserve their own talk
Decorators
Decoratorswrap functions
Decorators• Count function calls• Add additional output (debugging!)• Timing code• Thread synchronization (locks)• Type Ch...
DecoratorsExamples
Questions?Colton Myerscolton.myers@gmail.com@basepihttp://basepi.nethttp://files.basepi.net/talks/pyarmory.zip
Upcoming SlideShare
Loading in …5
×

Adding to your Python Armory - OpenWest 2013

759 views

Published on

This Python tutorial will touch on many Python "weapons" that you can add to your armory. We will touch on list comprehensions, decorators and generators. Some familiarity with Python is required as basic syntax is not covered. This presentation was given by Colton Myers, SaltStack engineer, at OpenWest 2013.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
759
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Adding to your Python Armory - OpenWest 2013

  1. 1. Adding to your PythonArmoryColton Myers@basepibasepi.net
  2. 2. • Configuration management• Remote execution• Orchestration• Much, much more• Easy to set up, easy to usesaltstack.com
  3. 3. Where we’re going• List Comprehensions• Generators• Decorators
  4. 4. files.basepi.net/talks/pyarmory.zip
  5. 5. Most of the code is stolen.files.basepi.net/talks/pyarmory.zip
  6. 6. List Comprehensions• Shortcut to map/filter operations• Condense a whole loop to one line• Very readable (to a point)
  7. 7. List ComprehensionsExamples
  8. 8. Generators
  9. 9. Generators• Infinite iterators• Memory-intensive iteration• Cooperative Multi-threading
  10. 10. # Build and return a listdef firstn(n):num = 0nums = []while num < n:nums.append(num)num += 1return numssumofn = sum(firstn(1000000))
  11. 11. What if integers were each 10MB?
  12. 12. What if we want the list to not end?
  13. 13. Solution?
  14. 14. Solution? Generators
  15. 15. GeneratorsTime for MoreExamples!
  16. 16. GeneratorsHow do they work?
  17. 17. ContinuationsHow do they work?
  18. 18. Continuations• “The rest”• Saves the execution stack, ready to resume• Continuations deserve their own talk
  19. 19. Decorators
  20. 20. Decoratorswrap functions
  21. 21. Decorators• Count function calls• Add additional output (debugging!)• Timing code• Thread synchronization (locks)• Type Checking
  22. 22. DecoratorsExamples
  23. 23. Questions?Colton Myerscolton.myers@gmail.com@basepihttp://basepi.nethttp://files.basepi.net/talks/pyarmory.zip

×