Skip to content

Latest commit

 

History

History
206 lines (165 loc) · 7.29 KB

File metadata and controls

206 lines (165 loc) · 7.29 KB

PyCon 2015 Presentations

NOTE: Presentation titles link to corresponding youtube videos.

  • By: Adam Palay
  • How can we use use Python to suplement our reading of Shakespeare?
  • How can we get Python to read for us?
  • Shakespeare in XLM
  • Classifier - How to tell if speech is from a tragedy or comedy?
  • Bag of Words - Frequencey of all words in text
rhymes = get_rhymes(sonnets)
fd = nltk.FreqDist(rhymes)
for rhyme, freq in fd.most_common(10):
 print rhyme, freq

# most common words that rhyme with 'thee'
rhymes = rhymes + [tuple(reversed(rhyme)) for rhyme in rhymes]
cfd = nltk.CondaitionalFreqDist(rhymes)
for word, freq in cfd['thee'].most_common():
 print word, freq
favorites = [7, 33, 99]
log('Favorite numbers', *favorites)

# Equivalent to:
log('Favorite numbers', 7, 33, 99)

# If you pass a generator with *, it will break
  • Provide optional behavior with keyword arguments def foo(bar=123)
  • Allows you to add functionality over time without breaking the callers
  • Enforce clarity with keyword-only arguments def foo(*, bar=123)
  • Everything that comes after a * is required to passed as a keyword
  • Use keyword-only args to extend *args def log(message, *values, seq=None)
  • Python 2: def log(message, *values, **kwargs)
  • Consider generators instead of returning lists yield foo
  • Be defensive when iterating over arguments
  • Python can't tell the difference between an empty iterator and an iterator that's been exhausted
  • If you iterate over an iterator, you get the same iterator
  • If you itereate over a sequence twice, you get different iterators
  • You can create an iterable container. When you do this, you get a new iterator with every call.
class LoadCities(object):

 def __init__(self, path):
  self.path = path
 
 def __iter__(self):
  with open(self.path) as handle:
   for line in handle:
    city,count = line.split('\t')
    yield city, int(count)
    
# The defensive code then becomes:
def normalize_defensive(pop):
 if iter(pop) is iter(pop):
  raise TypeError('Must be a container')
 total = ...
  • By: Andrew Godwin
  • Soft Failure - causes you to ignore or complete miss issues. Crash hard on serious error.
  • No constant low-level warmings. If you ignore it for a week, delete the warning.
  • Test to the limits. Don't completely rely on automation.
  • Checklists for everything. Minimize people reliance. Reduce workload at critical times.
  • Priorities: What are the key things that must be done?
  • Clear command (who makes the dicusion) and communication (others always listened to).
  • Blame the process not the person.
  • Deadlines:
  • Don't schedule everyone at maximum
  • Always expect unknown problems
  • Ship good code rather than to a deadline
  • By: Soups Ranjan
  • By: Raymond Hettinger
  • By: Brett Cannon
  • By: David Baumgold
  • By: David Beazley
  • By: Michelle Fullwood
  • By: Titus Brown
  • By: Jake VanderPlas
mkdir envs
cd envs
virtualenv projname1
source projname1/bin/activate
deactivate

virtualenv projname2
...
echo $PATH
  • virtualenvs handle dependency isolation. They don't handle environment variables.
  • Use shell aliases: alias projname1='source ~/envs/projname1/bin/activate; cd path_to/workproj1; ./setenvs.sh;'
  • By: Greg Ward
  • By: Dan Crosta
  • By: Andreas Dewes
  • By: Nina Zakharenko
  • By: Ned Batchelder
  • By: Itamar Turner-Trauring
  • By: Mali Akmanalp
  • By: Laura Rupprecht
  • By: Daniel Vanderkam
  • By: Alex Gaynor
  • By: Sasha Laundy
  • By: Hynek Schlawack
  • By: Sarah Bird
  • By: Geoff Gerrietts

(Docker)