Skip to content

Instantly share code, notes, and snippets.

import contextlib
import sys
@contextlib.contextmanager
def logging_context_manager():
print('logging_context_manager: enter')
try:
yield 'You are in a with-block!'
print('logging_context_manager: normal exit')
except Exception:
def greet(msg):
return msg.upper()
print greet('Welcome to Functional Programming')
message = greet
print message('Welcome to Functional Programming')
def greet(msg):
return msg.upper()
def speak(msg):
return msg.lower()
def display(func):
# storing the function in a variable
message = func('Welcome to Python Programming.')
print message
def addition(i):
def adds(j):
return i + j
return adds
result_add = addition(30)
print result_add(20)
from order import Order
from customer import Customer
def main():
cust1 = Customer()
cust1.name = 'Rocky'
cust1.address = 'Florida'
cust1.enterprise = False
cust2 = Customer()
cust2.name = 'Jenifer'
class OrderItem:
name = ''
itemnumber = ''
quantity = 0
price = 0
backorderd = False
class Order:
# class attribute
orders = []
# instance attributes
orderid = 0
shipping_address = ''
expedited = False
shipped = False
customer = None
class Customer:
name = ''
address = ''
enterprise = False
class Order:
# class attribute
orders = []
# instance attributes
orderid = 0
shipping_address = ''
expedited = False
shipped = False
customer = None
class Order:
# class attribute
orders = []
# instance attributes
orderid = 0
shipping_address = ''
expedited = False
shipped = False
customer = None