Edmonton.py

The Edmonton Python User Group

edmontonpy.com
@edmontonpy

edmontonpy.slack.com

Today's talks

Anatomy of an Open Source Python Project: From Idea to World Domination!

by Chris Want

Language Fundamentals - Python Types​

by Dustin Grue

Python Events

 

  • PyCon 2018​
    May 9-17, Cleveland, OH

  • DjangoCon 2018​
    October 14-19, San Diego, CA

 

NEXT MEETUP ON JUNE 11TH

Resources

Releases

  • No Major Releases to speak of.

Jobs!

  • The Organic Box is hiring a designer!
    (ask me about it here or on slack)
  • Fujitsu is hiring devops people and .net developers!
    (ask me about it here or both "Michael Dunham" on slack)

Articles

  • Python Tip: Function Argument Defaults 

A common Mistake in python is defining the default of an optional argument in the function declaration.

def all_kitten_names(names=[]):
    names.append("Ghost")
    return names
>>> all_kitten_names()
['Ghost']
>>> all_kitten_names()
['Ghost', 'Ghost']
>>> all_kitten_names()
['Ghost', 'Ghost', 'Ghost']
def all_kitten_names(names=None):
    if names is None:
       names = []
    names.append("Gambit")
    return names
>>> all_kitten_names()
['Gambit']
>>> all_kitten_names()
['Gambit']
>>> all_kitten_names()
['Gambit']

Wrong Way

Right Way

output:

output:

The Reason this happens is that the default value for a function is only evaluated once. This problem arises when you don't give arguments, so do it the right way!

May 2018

By EdmontonPy

May 2018

  • 258

More from EdmontonPy