Last login: Mon Feb 28 08:25:58 on ttys002 The default interactive shell is now zsh. To update your account to use zsh, please run `chsh -s /bin/zsh`. For more details, please visit https://support.apple.com/kb/HT208050. MAC:Mon Feb 28:14:11:~> python Python 3.10.0 (v3.10.0:b494f5935c, Oct 4 2021, 14:59:19) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> type(range(10)) <class 'range'> >>> for item in range(10): ... print(item, item*item) ... 0 0 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 >>> for item in range(5): ... print("Bart is a brat.") ... Bart is a brat. Bart is a brat. Bart is a brat. Bart is a brat. Bart is a brat. >>> for item in range(2,6): ... print(item) ... 2 3 4 5 >>> for item in range(2, 200, 7): ... print(item) ... 2 9 16 23 30 37 44 51 58 65 72 79 86 93 100 107 114 121 128 135 142 149 156 163 170 177 184 191 198 >>> for item in range(0, 1, .1): ... print(item) ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'float' object cannot be interpreted as an integer >>> ## ugly >>> for item in range(10,-1, -1): ... print(item) ... 10 9 8 7 6 5 4 3 2 1 0 >>> for item in reversed(range(0,11)): ... print(item) ... 10 9 8 7 6 5 4 3 2 1 0 >>> x = ["a", "b", "c", "d", "e"] >>> >>> for k in x: ... print(k) ... a b c d e >>> for k in reversed(x): ... print(k) ... e d c b a >>> t = ("a", "b", "c", "d", "e") >>> for k in t: ... print(k) ... a b c d e >>> d = {"cat": "meow", "dog", "woof", "pig":"reeet"} File "<stdin>", line 1 d = {"cat": "meow", "dog", "woof", "pig":"reeet"} ^ SyntaxError: ':' expected after dictionary key >>> d = {"cat": "meow", "dog": "woof", "pig":"reeet"} >>> for item in d: ... print(item) ... cat dog pig >>> for item in d: ... print(d[item]) ... meow woof reeet >>> for item in d.values(): ... print(item) ... meow woof reeet >>> s = {1,2,3,4,"cow", "elephant", (1,2,3)} >>> for k in s: ... print(k) ... 1 2 elephant 3 4 cow (1, 2, 3) >>> for k in s: ... print(k) ... 1 2 elephant 3 4 cow (1, 2, 3) >>> for quack in "mallard": ... print(quack) ... m a l l a r d >>> ^D MAC:Mon Feb 28:14:30:~> ls 20212022 211 ACSL App.class App.java Applications CLASSES Classes20161017 Classes20172018 Classes20182019 Classes20192020 Classes20202021 Crash.class Crash.java D3Book Desktop Documents Downloads Driver.class Driver.java Hello.java HelloFX.class HelloFX.java LSPCobol Library Math-for-Programmers Movies Music Order.class Person.class Person.java Pictures Pictures.zip Point.class Point.java Point.py Public Stand.java Test.java a.out a.py accident amigocode api_key.txt apple.txt assorted bash bigFractionAssignment bin bin.txt book books box buf challenge chararrays codingBooks com.paloaltonetworks.GlobalProtect.settings.plist comp convert.sed convert.set data dataviz-with-python-and-js dump.txt eclipse eclipse-workspace endian endian.c fatCow.txt.moo first.cbl flask foo foo.asm foo.c foo.cpp foo.o foo.py gdb-entitlement.xml generatorInfo.docx google-cloud-sdk gs gs.c guineapig hello hello.c hello.cbl hello.cob hello.js hello.o hello.py hint.py image.php is_perfect.py javaclass javaprep.sh leaker leaker.c leaker.dSYM logins.csv miles.dat miles1.dat miniterm moo moo.dSYM moreProgramming morrison morrison.c newEdition nodeLists node_modules ocw package-lock.json package.json personal personal2 phone.txt pictures2 pix programming recursion reeeet regex rodent sample.py sampler.txt schoolImages stackHeap.py startPage.html stateConvert.sed sum teaching test test.awk test.c test.js test_harder.py words.txt youTube MAC:Mon Feb 28:14:30:~> B MAC:Mon Feb 28:14:30:4240> ls 0221 commando.py list_tupe.zip roster.txt 0222 detect_os.py list_tuple rosterB.txt 0228 first.py list_tuple.py rosterF.txt Bsessions foo list_tuple_key.py students Fsessions half_triangle.py match.py triggie.py __pycache__ hello.py match_game.py unit_convert.py client.py iffy.py new_folder wabbit.py MAC:Mon Feb 28:14:30:4240> mkdir 0228F MAC:Mon Feb 28:14:30:4240> cd 0228F MAC:Mon Feb 28:14:30:0228F> vi sampler.txt MAC:Mon Feb 28:14:31:0228F> python Python 3.10.0 (v3.10.0:b494f5935c, Oct 4 2021, 14:59:19) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> fp = open("sampler.txt", "r") >>> print(fp) <_io.TextIOWrapper name='sampler.txt' mode='r' encoding='UTF-8'> >>> for foo in fp: ... print(fp + "FOO") ... Traceback (most recent call last): File "<stdin>", line 2, in <module> TypeError: unsupported operand type(s) for +: '_io.TextIOWrapper' and 'str' >>> for foo in fp: ... print(foo + "FOO") ... ABCDEFGHIJKLMNOPQRSTUVWXYZ FOO 0123456789 FOO !@#$%^&*() FOO >>> fp = open("sampler.txt", "r") >>> for line in fp: ... print(line, end = "") ... abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 !@#$%^&*() >>> KeyboardInterrupt >>> ^D MAC:Mon Feb 28:14:36:0228F> vi copy.py MAC:Mon Feb 28:14:41:0228F> python copy.py sampler.txt foo.txt MAC:Mon Feb 28:14:42:0228F> diff sampler.txt foo.txt MAC:Mon Feb 28:14:42:0228F> cat foo.txt abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 !@#$%^&*() MAC:Mon Feb 28:14:42:0228F> !vi vi copy.py MAC:Mon Feb 28:14:45:0228F> cp copy.py copy_better.py MAC:Mon Feb 28:14:45:0228F> vi copy_better.py MAC:Mon Feb 28:14:47:0228F> ls copy.py copy_better.py foo.txt sampler.txt MAC:Mon Feb 28:14:47:0228F> python Python 3.10.0 (v3.10.0:b494f5935c, Oct 4 2021, 14:59:19) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> with open("copy.py", "r") as fp: ... entrails = fp.read() ... >>> print(entrails) ## python copy.py donor recipient from sys import argv import os donor = argv[1] recipient = argv[2] if len(argv) < 3: print("Usage: python copy.py donor recipient") quit() ## open the donor for readding if not os.path.exists(donor): print("Donor file does not exist. Bailing!") quit() fp_in = open(donor, "r") ## open the recipient for writing fp_out = open(recipient, "w") ## get a line from donor, place in recippent until donor exhausted for line in fp_in: fp_out.write(line) ## Mr. Rogers: close files when done. fp_in.close() fp_out.close() >>> entrails '## python copy.py donor recipient\nfrom sys import argv\nimport os\ndonor = argv[1]\nrecipient = argv[2]\nif len(argv) < 3:\n print("Usage: python copy.py donor recipient")\n quit()\n## open the donor for readding\nif not os.path.exists(donor):\n print("Donor file does not exist. Bailing!")\n quit()\nfp_in = open(donor, "r")\n## open the recipient for writing\nfp_out = open(recipient, "w")\n## get a line from donor, place in recippent until donor exhausted\nfor line in fp_in:\n fp_out.write(line)\n## Mr. Rogers: close files when done.\nfp_in.close()\nfp_out.close()\n\n\n' >>> "donor in entrails File "<stdin>", line 1 "donor in entrails ^ SyntaxError: unterminated string literal (detected at line 1) >>> "donor" in entrails True >>> fp.tell() Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: I/O operation on closed file. >>> fp = open("sampler.txt", "r") >>> fp.read(5) 'abcde' >>> fp.read(1) 'f' >>> fp.read() 'ghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n0123456789\n!@#$%^&*()\n' >>> fp.tell() 76 >>> fp.read() '' >>> fp.seek(0) 0 >>> fp.seek(50) 50 >>> fp.read(1) 'X' >>> x = os.listdir() Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'os' is not defined >>> import os >>> x = os.listdir() >>> for item in x: ... print(item) ... copy.py foo.txt copy_better.py sampler.txt >>> for item in x: ... if item.endswith(".py"): ... print(item) ... copy.py copy_better.py >>> ^D MAC:Mon Feb 28:14:54:0228F> ls copy.py copy_better.py foo.txt sampler.txt MAC:Mon Feb 28:14:55:0228F> sftp utility0 Connected to utility0. sftp> cd public_html/currentClasses/4240/Feb/28Feb22/F sftp> put * Uploading copy.py to /home/morrison/public_html/currentClasses/4240/Feb/28Feb22/F/copy.py copy.py 100% 575 104.9KB/s 00:00 Uploading copy_better.py to /home/morrison/public_html/currentClasses/4240/Feb/28Feb22/F/copy_better.py copy_better.py 100% 473 60.6KB/s 00:00 Uploading foo.txt to /home/morrison/public_html/currentClasses/4240/Feb/28Feb22/F/foo.txt foo.txt 100% 76 10.1KB/s 00:00 Uploading sampler.txt to /home/morrison/public_html/currentClasses/4240/Feb/28Feb22/F/sampler.txt sampler.txt 100% 76 12.3KB/s 00:00 sftp> quit MAC:Mon Feb 28:14:56:0228F>