'_iii',

'_oh',

'_sh',

'a',

'b',

'cos',

'cosine1',

'cosine2',

'exit',

'fout',

'fout1',

'get_ipython',

'product',

'quit',

'sin',

'sum1',

'sum2',

'sum3']


In [37]: fout1 = open("second{}.txt".format(cos(a)), "w")


In [38]: fout1.close()


In [39]: a

Out[39]: 2


In [40]: b

Out[40]: [1, 2, 3, 4]


In [41]: fout1 = open("second{}.txt".format(b), "w")


In [42]: fout1.close()


In [43]: import numpy as np


In [44]: fout1 = open("second{}.txt".format(np.cos(b)), "w")


In [45]: fout1.close()


In [46]: import urllib.request


In [47]: dir(urllib.request)

Out[47]:

['AbstractBasicAuthHandler',

'AbstractDigestAuthHandler',

'AbstractHTTPHandler',

'BaseHandler',

'CacheFTPHandler',

'ContentTooShortError',

'DataHandler',

'FTPHandler',

'FancyURLopener',

'FileHandler',

'HTTPBasicAuthHandler',

'HTTPCookieProcessor',

'HTTPDefaultErrorHandler',

'HTTPDigestAuthHandler',

'HTTPError',

'HTTPErrorProcessor',

'HTTPHandler',

'HTTPPasswordMgr',

'HTTPPasswordMgrWithDefaultRealm',

'HTTPPasswordMgrWithPriorAuth',

'HTTPRedirectHandler',

'HTTPSHandler',

'MAXFTPCACHE',

'OpenerDirector',

'ProxyBasicAuthHandler',

'ProxyDigestAuthHandler',

'ProxyHandler',

'Request',

'URLError',

'URLopener',

'UnknownHandler',

'__all__',

'__builtins__',

'__cached__',

'__doc__',

'__file__',

'__loader__',

'__name__',

'__package__',

'__spec__',

'__version__',

'_cut_port_re',

'_ftperrors',

'_have_ssl',

'_localhost',

'_noheaders',

'_opener',

'_parse_proxy',

'_proxy_bypass_macosx_sysconf',

'_randombytes',

'_safe_gethostbyname',

'_thishost',

'_url_tempfiles',

'addclosehook',

'addinfourl',

'base64',

'bisect',

'build_opener',

'collections',

'contextlib',

'email',

'ftpcache',

'ftperrors',

'ftpwrapper',

'getproxies',

'getproxies_environment',

'getproxies_registry',

'hashlib',

'http',

'install_opener',

'io',

'localhost',

'noheaders',

'os',

'parse_http_list',

'parse_keqv_list',

'pathname2url',

'posixpath',

'proxy_bypass',

'proxy_bypass_environment',

'proxy_bypass_registry',

'quote',

're',

'request_host',

'socket',

'splitattr',

'splithost',

'splitpasswd',

'splitport',

'splitquery',

'splittag',

'splittype',

'splituser',

'splitvalue',

'ssl',

'string',

'sys',

'tempfile',

'thishost',

'time',

'to_bytes',

'unquote',

'unquote_to_bytes',

'unwrap',

'url2pathname',

'urlcleanup',

'urljoin',

'urlopen',

'urlparse',

'urlretrieve',

'urlsplit',

'urlunparse',

'warnings']


In [48]: clean

Traceback (most recent call last):


File "<ipython-input-48-175388b0347c>", line 1, in <module>

clean


NameError: name 'clean' is not defined



In [49]: %clean

ERROR: Line magic function `%clean` not found.


In [50]: %clear

The system cannot find the path specified.


In [51]: clear

The system cannot find the path specified.


In [52]: %reset


Once deleted, variables cannot be recovered. Proceed (y/[n])? y


In [53]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/Lecture4.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')


In [54]: dir()

Out[54]:

['In',

'Out',

'__builtin__',

'__builtins__',

'__name__',

'_dh',

'_i',

'_i53',

'_i54',

'_ih',

'_ii',

'_iii',

'_oh',

'_sh',

'exit',

'fin',

'get_ipython',

'myfile_content',

'quit']


In [55]: myfile_content

Out[55]:

['Hello, this is my first text written into file.\n',

"And let's make it a bit longer, so that we can \n",

'play with the string operations.']


In [56]: type(myfile_content)

Out[56]: list


In [57]: len(myfile_content)

Out[57]: 3


In [58]: myfile_content[0]

Out[58]: 'Hello, this is my first text written into file.\n'


In [59]: myfile_content[1]

Out[59]: "And let's make it a bit longer, so that we can \n"


In [60]: myfile_content[2]

Out[60]: 'play with the string operations.'


In [61]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/Lecture4.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')

['Hello, this is my first text written into file.\n', "And let's make it a bit longer, so that we can \n", 'play with the string operations.']


In [62]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/Lecture4.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')

['Hello, this is my first text written into file.\n', "And let's make it a bit longer, so that we can \n", 'play with the string operations.']

Hello, this is my first text written into file.

And let's make it a bit longer, so that we can

play with the string operations.


In [63]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/Lecture4.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')

['Hello, this is my first text written into file.\n', "And let's make it a bit longer, so that we can \n", 'play with the string operations.']


Hello, this is my first text written into file.

And let's make it a bit longer, so that we can

play with the string operations.


In [64]: dir()

Out[64]:

['In',

'Out',

'_',

'_54',

'_55',

'_56',

'_57',

'_58',

'_59',

'_60',

'__',

'___',

'__builtin__',

'__builtins__',

'__name__',

'_dh',

'_i',

'_i53',

'_i54',

'_i55',

'_i56',

'_i57',

'_i58',

'_i59',

'_i60',

'_i61',

'_i62',

'_i63',

'_i64',

'_ih',

'_ii',

'_iii',

'_oh',

'_sh',

'exit',

'fin',

'get_ipython',

'myfile_content',

'myfile_content1',

'quit']


In [65]: type(myfile_content)

Out[65]: list


In [66]: type(myfile_content1)

Out[66]: str


In [67]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/Lecture4.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')

['Hello, this is my first text written into file.\n', "And let's make it a bit longer, so that we can \n", 'play with the string operations.']


Hello, this is my first text written into file.

And let's make it a bit longer, so that we can

play with the string operations.


In [68]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/Lecture4.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')

['Hello, this is my first text written into file.\n', "And let's make it a bit longer, so that we can \n", 'play with the string operations.']


Hello, this is my first text written into file.

And let's make it a bit longer, so that we can

play with the string operations.

Hello, this is my first text written into file.


And let's make it a bit longer, so that we can


play with the string operations.


In [69]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/Lecture4.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')

['Hello, this is my first text written into file.\n', "And let's make it a bit longer, so that we can \n", 'play with the string operations.']


Hello, this is my first text written into file.

And let's make it a bit longer, so that we can

play with the string operations.


Hello, this is my first text written into file.


And let's make it a bit longer, so that we can


play with the string operations.


In [70]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/Lecture4.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')

['Hello, this is my first text written into file.\n', "And let's make it a bit longer, so that we can \n", 'play with the string operations.']


Hello, this is my first text written into file.

And let's make it a bit longer, so that we can

play with the string operations.


['Hello, this is my first text written into file.\n', "And let's make it a bit longer, so that we can \n", 'play with the string operations.']


In [71]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/lecture4_read.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')


In [72]: total_cost("shoppinglist.txt")

1.39 $

1.56 $

4.35 $

8.97 $

55.00000000000001 $

Out[72]: 71.27000000000001


In [73]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/lecture4_read.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')


In [74]: total_cost("shoppinglist.txt")

['bread 1 1.39\n', 'tomatoes 6 0.26\n', 'milk 3 1.45\n', 'coffee 3 2.99\n', 'beer 50 1.10']

1.39 $

1.56 $

4.35 $

8.97 $

55.00000000000001 $

Out[74]: 71.27000000000001


In [75]: a = "Hello Wolrd"


In [76]: a.split()

Out[76]: ['Hello', 'Wolrd']


In [77]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/lecture4_read.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')


In [78]: total_cost("shoppinglist.txt")

['bread 1 1.39\n', 'tomatoes 6 0.26\n', 'milk 3 1.45\n', 'coffee 3 2.99\n', 'beer 50 1.10']

['bread', '1', '1.39']

1.39 $

['tomatoes', '6', '0.26']

1.56 $

['milk', '3', '1.45']

4.35 $

['coffee', '3', '2.99']

8.97 $

['beer', '50', '1.10']

55.00000000000001 $

Out[78]: 71.27000000000001


In [79]: a = "1!

File "<ipython-input-79-fc3da429757e>", line 1

a = "1!

^

SyntaxError: EOL while scanning string literal



In [80]: a = "1"


In [81]: b = "2"


In [82]: a*b

Traceback (most recent call last):


File "<ipython-input-82-8201c27d19b7>", line 1, in <module>

a*b


TypeError: can't multiply sequence by non-int of type 'str'



In [83]: a+b

Out[83]: '12'


In [84]: float(a)

Out[84]: 1.0


In [85]: float(b)

Out[85]: 2.0


In [86]: float(a)+float(b)

Out[86]: 3.0


In [87]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/lecture4_read.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')


In [88]: total_cost("shoppinglist.txt")

['bread 1 1.39\n', 'tomatoes 6 0.26\n', 'milk 3 1.45\n', 'coffee 3 2.99\n', 'beer 50 1.10']

['bread', '1', '1.39']

1.39

1.39 $

['tomatoes', '6', '0.26']

1.56

1.56 $

['milk', '3', '1.45']

4.35

4.35 $

['coffee', '3', '2.99']

8.97

8.97 $

['beer', '50', '1.10']

55.00000000000001

55.00000000000001 $

Out[88]: 71.27000000000001


In [89]: ord("W")

Out[89]: 87


In [90]: chr(87)

Out[90]: 'W'


In [91]: "R"

Out[91]: 'R'


In [92]: ord("R")

Out[92]: 82


In [93]: ord("r")

Out[93]: 114


In [94]: chr(36)

Out[94]: '$'


In [95]: ord("£")

Out[95]: 163


In [96]: chr(163)

Out[96]: '£'


In [97]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/lecture4_read.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')


In [98]: total_cost("shoppinglist.txt")

['bread 1 1.39\n', 'tomatoes 6 0.26\n', 'milk 3 1.45\n', 'coffee 3 2.99\n', 'beer 50 1.10']

['bread', '1', '1.39']

1.39

1.39 £

['tomatoes', '6', '0.26']

1.56

1.56 £

['milk', '3', '1.45']

4.35

4.35 £

['coffee', '3', '2.99']

8.97

8.97 £

['beer', '50', '1.10']

55.00000000000001

55.00000000000001 £

Out[98]: 71.27000000000001


In [99]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/lecture4_read.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')


In [100]: total_cost("shoppinglist.txt")

['bread 5 1.39\n', 'tomatoes 6 0.26\n', 'milk 3 1.45\n', 'coffee 3 2.99\n', 'beer 50 1.10']

['bread', '5', '1.39']

6.949999999999999

6.949999999999999 £

['tomatoes', '6', '0.26']

1.56

1.56 £

['milk', '3', '1.45']

4.35

4.35 £

['coffee', '3', '2.99']

8.97

8.97 £

['beer', '50', '1.10']

55.00000000000001

55.00000000000001 £

Out[100]: 76.83000000000001


In [101]: runfile('//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4/lecture4_read.py', wdir='//filestore.soton.ac.uk/users/oh1m12/mydocuments/20172018/Lecture4')


In [102]: ls

The system cannot find the path specified.


In [103]: pwd

Out[103]: '\\\\filestore.soton.ac.uk\\users\\oh1m12\\mydocuments\\20172018\\Lecture4'


In [104]: