Last active
August 2, 2017 21:13
-
-
Save anaved/ea43f74cf8643bd2befb71658d1b6942 to your computer and use it in GitHub Desktop.
Simple partial example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import partial | |
def power(number, order): | |
"""This is a power function""" | |
return number ** order | |
square = partial( power, order = 2) | |
cube = partial( power, order = 3) | |
if __name__ == "__main__": | |
print square(2) | |
print cube(2) | |
>>>4 | |
>>>8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ssh_execute(host,username,password,command): | |
connection = ssh_connection(host,port,username,password) | |
return connection.execute(command) | |
prod_server = partial(ssh_execute, 'prod_host','prod_username', 'prod_pass' ) | |
dev_server = partial(ssh_execute, 'dev_host','dev_username', 'dev_pass' ) | |
prod_server('whoami') | |
dev_server('whoami') | |
>>>prod_user | |
>>>dev_user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment