Python 2.7.7 |Anaconda 2.0.1 (x86_64)| (default, Jun 2 2014, 12:48:16)

Type "copyright", "credits" or "license" for more information.


IPython 2.1.0 -- An enhanced Interactive Python.

Anaconda is brought to you by Continuum Analytics.

Please check out: http://continuum.io/thanks and https://binstar.org

? -> Introduction and overview of IPython's features.

%quickref -> Quick reference.

help -> Python's own help system.

object? -> Details about 'object', use 'object??' for extra details.

%guiref -> A brief reference about the graphical user interface.


In [1]: runfile('/Users/progprim/Desktop/use-my-lib.py', wdir='/Users/progprim/Desktop')

25


In [2]: runfile('/Users/progprim/Desktop/mylib.py', wdir='/Users/progprim/Desktop')

UMD has deleted: mylib

In line 13 of mylib.py


In [3]: runfile('/Users/progprim/Desktop/use-my-lib.py', wdir='/Users/progprim/Desktop')

In line 13 of mylib.py

25


In [4]: runfile('/Users/progprim/Desktop/mylib.py', wdir='/Users/progprim/Desktop')

UMD has deleted: mylib

File "/Users/progprim/Desktop/mylib.py", line 17

^

SyntaxError: invalid syntax



In [5]: runfile('/Users/progprim/Desktop/mylib.py', wdir='/Users/progprim/Desktop')


In [6]: runfile('/Users/progprim/Desktop/mylib.py', wdir='/Users/progprim/Desktop')


In [7]: demo()

The current temperature is 25


In [8]: runfile('/Users/progprim/Desktop/mylib.py', wdir='/Users/progprim/Desktop')

The current temperature is 25


In [9]: runfile('/Users/progprim/Desktop/use-my-lib.py', wdir='/Users/progprim/Desktop')

The current temperature is 25

25


In [10]: runfile('/Users/progprim/Desktop/mylib.py', wdir='/Users/progprim/Desktop')

UMD has deleted: mylib

The current temperature is 25


In [11]: runfile('/Users/progprim/Desktop/mylib.py', wdir='/Users/progprim/Desktop')

The __name__=__main__

The current temperature is 25


In [12]: runfile('/Users/progprim/Desktop/use-my-lib.py', wdir='/Users/progprim/Desktop')

The __name__=mylib

25


In [13]: import sys


In [13]:


In [13]:


In [14]: sys.path

Out[14]:

['',

'/Users/progprim/anaconda/lib/python2.7/site-packages/spyderlib/utils/external',

'/Users/progprim/Desktop',

'/Users/progprim/pythonlibs',

'/Users/progprim/anaconda/python.app/Contents/lib/python27.zip',

'/Users/progprim/anaconda/python.app/Contents/lib/python2.7',

'/Users/progprim/anaconda/python.app/Contents/lib/python2.7/plat-darwin',

'/Users/progprim/anaconda/python.app/Contents/lib/python2.7/plat-mac',

'/Users/progprim/anaconda/python.app/Contents/lib/python2.7/plat-mac/lib-scriptpackages',

'/Users/progprim/anaconda/python.app/Contents/lib/python2.7/lib-tk',

'/Users/progprim/anaconda/python.app/Contents/lib/python2.7/lib-old',

'/Users/progprim/anaconda/python.app/Contents/lib/python2.7/lib-dynload',

'/Users/progprim/anaconda/lib/python2.7/site-packages',

'/Users/progprim/anaconda/lib/python2.7/site-packages/PIL',

'/Users/progprim/anaconda/lib/python2.7/site-packages/runipy-0.1.0-py2.7.egg',

'/Users/progprim/anaconda/lib/python2.7/site-packages/setuptools-3.6-py2.7.egg',

'/Users/progprim/anaconda/lib/python2.7/site-packages/IPython/extensions',

'/Users/progprim/.ipython']


In [15]: runfile('/Users/progprim/Desktop/fifoqueue_outline.py', wdir='/Users/progprim/Desktop')

UMD has deleted: mylib

['Hawke', 'Fangohr']

Length of queue is 2

Next customer is Hawke

Next customer is Fangohr

Length of queue is 0


In [16]: show()

[]


In [17]: add("Test 1")


In [18]: add("Test 2")


In [19]: show()

['Test 1', 'Test 2']


In [20]: show()

['Test 1', 'Test 2']


In [21]: def show():

    ...: """SHOW queue: print list of waiting customers. Customer waiting longest

    ...: are shown at the end of the list."""

    ...: print("Customers waiting are:")

    ...: print(q)

    ...:



In [22]: show()

Customers waiting are:

['Test 1', 'Test 2']


In [23]: def show():

    ...: """SHOW queue: print list of waiting customers. Customer waiting longest

    ...: are shown at the end of the list."""

    ...: print("Customers waiting are:")

    ...: print(q)

    ...:

    ...:



In [24]: def show():

    ...: """SHOW queue: print list of waiting customers. Customer waiting longest

    ...: are shown at the end of the list."""

    ...: print("Customers waiting are:")

    ...: print(q)

    ...:

    ...:



In [25]: [2**i for i in range(10)]

Out[25]: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]


In [26]: range(10)

Out[26]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]


In [27]: [i**2 for i in range(10)]

Out[27]: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]


In [28]: [2*i for i in range(10)]

Out[28]: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]


In [29]: [i for i in range(10)]

Out[29]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]


In [30]: range(10)

Out[30]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]


In [31]: import math


In [32]: [math.sqrt(i) for i in range(10)]

Out[32]:

[0.0,

1.0,

1.4142135623730951,

1.7320508075688772,

2.0,

2.23606797749979,

2.449489742783178,

2.6457513110645907,

2.8284271247461903,

3.0]


In [33]: [i*"x" for i in range(10)]

Out[33]:

['',

'x',

'xx',

'xxx',

'xxxx',

'xxxxx',

'xxxxxx',

'xxxxxxx',

'xxxxxxxx',

'xxxxxxxxx']


In [34]: [len(i) for i in ['Hello', 'world', 'and', 'ngcm']]

Out[34]: [5, 5, 3, 4]


In [35]: d = {}


In [36]: d

Out[36]: {}


In [37]: type(d)

Out[37]: dict


In [38]: d['today'] = '25 deg C'


In [39]: d

Out[39]: {'today': '25 deg C'}


In [40]: d['yesterday'] = '29 deg C'


In [41]: d

Out[41]: {'today': '25 deg C', 'yesterday': '29 deg C'}


In [42]: d['today']

Out[42]: '25 deg C'


In [43]: d['yesterday']

Out[43]: '29 deg C'


In [44]: d['tomorrow']

Traceback (most recent call last):


File "<ipython-input-44-92bba45e062e>", line 1, in <module>

d['tomorrow']


KeyError: 'tomorrow'



In [45]: d.keys()

Out[45]: ['yesterday', 'today']


In [46]: d.values()

Out[46]: ['29 deg C', '25 deg C']


In [47]: d['tomorrow'] = "anybody's guess"


In [48]: d.keys()

Out[48]: ['yesterday', 'today', 'tomorrow']


In [49]: d['tomorrow']

Out[49]: "anybody's guess"


In [50]: d

Out[50]: {'today': '25 deg C', 'tomorrow': "anybody's guess", 'yesterday': '29 deg C'}


In [51]: d

Out[51]: {'today': '25 deg C', 'tomorrow': "anybody's guess", 'yesterday': '29 deg C'}


In [52]: d[42] = "the answer"


In [53]: d

Out[53]:

{42: 'the answer',

'today': '25 deg C',

'tomorrow': "anybody's guess",

'yesterday': '29 deg C'}


In [54]: