-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathexample.py
66 lines (55 loc) · 2.29 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
"""example.py: This is an example of documenting a Python module.
This part is called a docstring. It can be multiple lines, or
a single line ended with the triple quote. Generally there should be
docstrings for all public modules, functions, classes, and methods.
Non-public methods should at least have a comment that describes what
the method does. (See https://www.python.org/dev/peps/pep-0008/ for more information.)
When a doc string is used, this will be information will be available as the __doc__
attribute for this module.
On the python command line, you could type
>>> import example
>>> help(example)
and it would print out this docstring.
"""
import sys
import os
import datetime
__author__ = "Sowmya Ramakrishnan"
__copyright__ = "Copyright (C) 2018 by Sowmya Ramakrishnan"
#
# Redistribution, modification or use of this software in source or binary
# forms is permitted as long as the files maintain this copyright. Users are
# permitted to modify this and use it to learn about the field of embedded
# software. Sowmya Ramakrishnan and the University of Colorado
# are not liable for any misuse of this material.
#
class Dog(object):
"""Dog: an example of a Python class from https://docs.python.org/3/tutorial/classes.html"""
kind = 'canine' # class variable for all dogs
def __init__(self, name):
"""Returns a Dog object with a name and an empty list of tricks"""
self.name = name
self.tricks = [] # creates a new empty list for each dog
def add_trick(self, trick):
"""Adds a new trick to a Dog's list of tricks"""
self.tricks.append(trick)
def walker(name):
"""walker: an example of a python function"""
dog1 = Dog(name)
dog1.add_trick("Play Dead")
print("Walking a new dog:")
print(" The kind of this thing is ",dog1.kind)
print(" This dog is ",dog1.name)
print(" It knows these tricks - ",dog1.tricks)
# You can run this code from a command line - something like
# C:\Source> python example.py Fido
# ...runs walker on the name Fido...
# or you can run it inside Python by importing example
# >>> import example
# >>> help(example)
# ...shows all the docstrings...
# >>> example.walker("Fred")
# ...runs walker on the name Fred...
if __name__ == "__main__":
walker((sys.argv[1]))