Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "copyright", "credits" or "license()" for more information. >>> colors = {} >>> colors['apple'] = 'red' >>> colors['orange'] = 'orange' >>> colors['apple'] 'red' >>> def make_attribute_set(): attribute = {} height = input('How tall are you? ') weight = input('How much do you weigh? ') color = input('What is your favorite color? ') attribute['height'] = height attribute['weight'] = weight attribute['color'] = color return(attribute) >>> people = {} >>> def classify_person(): person = input('What is your name? ') attributes = make_attribute_set() people[person] = attributes >>> classify_person() What is your name? Ben How tall are you? 5 11 How much do you weigh? 154 What is your favorite color? green >>> classify_person() What is your name? Zach How tall are you? 5 1 How much do you weigh? 99 What is your favorite color? black >>> people {'Ben': {'color': 'green', 'weight': '154', 'height': '5 11'}, 'Zach': {'color': 'black', 'weight': '99', 'height': '5 1'}} >>> people['Ben'] {'color': 'green', 'weight': '154', 'height': '5 11'} >>> people['Ben']['color'] 'green' >>> import os >>> os.name 'posix' >>> os.environ environ({'DYLD_LIBRARY_PATH': '/Applications/Python 3.1/IDLE.app/Contents/Frameworks', 'Apple_PubSub_Socket_Render': '/tmp/launch-sokzX6/Render', 'PYTHONPATH': '/Applications/Python 3.1/IDLE.app/Contents/Resources', 'SSH_AUTH_SOCK': '/tmp/launch-OEtjCn/Listeners', '__CF_USER_TEXT_ENCODING': '0x1F6:0:0', 'SHELL': '/bin/bash', 'DBUS_FINK_SESSION_BUS_SOCKET': '/tmp/launch-1eG3R5/unix_domain_listener', 'LOGNAME': 'adam', 'USER': 'adam', 'DYLD_FRAMEWORK_PATH': '/Applications/Python 3.1/IDLE.app/Contents/Frameworks', 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', 'HOME': '/Users/adam', 'DISPLAY': '/tmp/launch-57j7aX/org.x:0', 'TMPDIR': '/var/folders/Rx/Rxj0QoBPHm4mB-hvG3oBx++++TM/-Tmp-/', 'COMMAND_MODE': 'legacy'}) >>> os.linesep '\n' >>> os.sep '/' >>> os.cwd() Traceback (most recent call last): File "", line 1, in os.cwd() AttributeError: 'module' object has no attribute 'cwd' >>> os.cwd Traceback (most recent call last): File "", line 1, in os.cwd AttributeError: 'module' object has no attribute 'cwd' >>> os.getcwd() '/Users/adam/Documents' >>> os.listdir(os.getcwd()) ['.DS_Store', '.localized', '004-10-3-3.txt', '004-1101.txt', '004-1108.txt', '004-1201.txt', '004-class-notes-42011.txt', '004-oct-4-1.txt', '004-oct-4-2.txt', '004-sept-29.txt', '005-11-08.txt', '005-1101.txt', '005-1201.txt', '005-dictation.txt', '005-section-9-29.txt', '006-1109.txt', '006-sept30-1.txt', '006-sept30-2.txt', '006-Tues-sept-21.txt', '006.txt', '04-1201-dictation.txt', '05-dictation.txt', '2nd homework.txt', '5+5.txt', 'About Stacks.pdf', 'eReader', 'fire-island-password.docx', 'fixing ip on J computer.odt', 'Flu or Cold? Or Swine Flu? Know the Differences.webarchive', 'four_squares.py', 'HW_contract_5_14_2011.odt', 'HW_contract_5_17_2011.odt', 'idle-006-10-14', 'idle-buffer-sept14', 'idle-output-sept15.txt', 'joshua-meyers-sat-report.pdf', 'Microsoft User Data', 'NYCHEAregistration.docx', 'october-4-005.txt', 'Place holders for Fall 2010 classes.rtf', 'plus.py', 'Processing', 'sample-file.txt', 'sept-20-005-section.txt', 'sept22-004.txt', 'short-idle-output.txt', 'short_story.txt', 'short_story.txt~', 'testing-re-asterisk-and-plus.txt', 'testing-sequence2.txt', 'triangle-test.py', 'wed-922-05.txt', 'weekday_test.py', 'xfig'] >>> os.listdir(os.getcwd())[10] '005-11-08.txt' >>> os.chdir("/Users/adam/Desktop/Class Scripts Spring 2011") >>> os.getcwd() '/Users/adam/Desktop/Class Scripts Spring 2011' >>> os.rename('/Users/adam/Documents/plus.py','fred.py') >>> os.listdir(os.getcwd()) ['.DS_Store', '003-class-6.py', '003-magnify.py', '003-number.py', '003_phonebook.py', '003_phonebook.txt', '003_turtle_commands.py', '004-class-6-problems.py', '004-diamond-hourglass.py', '004-interlocking_strings.py', '004-magnify.py', '004-word-to-number.py', '004_phonebook', '004_phonebook.py', '004_phonebook.txt', '004_turtle_commands.py', '005-class-6.py', '005-hourglass.py', '005-magnify.py', '005-number.py', '005-phonebook.txt', '005-turtle-commands.py', '005_phonebook.py', '123.txt', 'british-royal.txt', 'common_words.py', 'common_words.pyc', 'diagnosis.py', 'example-string-functions.py', 'for_loop_checkerboard.py', 'four_squares.py', 'four_squares2-003.py', 'four_squares2-004.py', 'four_squares2-005.py', 'four_squares2.py', 'fred.py', 'future-days.py', 'goldilocks.py', 'hour-glass-003.py', 'IO-examples.py', 'IO-examples_003.py', 'IO-examples_004.py', 'IO-examples_005.py', 'letters', 'letters.zip', 'morphology.py', 'number-program.py', 'random_sentence.py', 'recursion-functions.py', 'regexp-experiments.py', 'sample-number-answer.py', 'spam', 'to-read'] >>> 'fred.py' in os.listdir(os.getcwd()) True >>> os.path.isfile('fred.py') True >>> os.path.isfile('alice.py') False >>> os.path.isdir('fred.py') False >>> os.chdir("/Users/adam/Documents") >>> ================================ RESTART ================================ >>> >>> read_story('short_story.txt') Traceback (most recent call last): File "", line 1, in read_story('short_story.txt') File "/Users/adam/Desktop/Summer 2011 Scripts/IO-examples.py", line 5, in read_story story = open(file,'r') IOError: [Errno 2] No such file or directory: 'short_story.txt' >>> os.chdir("/Users/adam/Documents") >>> read_story('short_story.txt') Once upon a time, there lived a little frog named Herman. He was really tall for a frog -- almost four feet tall. Nobody knew this because he was always slouching. His slouching was preventing him from pursuing his secret dream. After much thought, he decided to go to a physical therapist. After 3 years of hard work, he was cured. So he moved to New Jersey and started an umbrella factory. The End >>> ================================ RESTART ================================ >>> >>> read_story('/Users/adam/Documents/short_story.txt') Once upon a time, there lived a little frog named Herman. He was really tall for a frog -- almost four feet tall. Nobody knew this because he was always slouching. His slouching was preventing him from pursuing his secret dream. After much thought, he decided to go to a physical therapist. After 3 years of hard work, he was cured. So he moved to New Jersey and started an umbrella factory. The End >>> os.getcwd() '/Users/adam/Desktop/Summer 2011 Scripts' >>> take_dictation("dictation-output.txt") Please give next line or hit enter if you are done. It is 10:35 Please give next line or hit enter if you are done. I am wearing shoes Please give next line or hit enter if you are done. There are three X four lights in the ceiling with one missing Please give next line or hit enter if you are done. >>> filter_spam('letters','spam','to_read') >>> os.stat('spam/letter7.eml') posix.stat_result(st_mode=33152, st_ino=1913426, st_dev=234881026, st_nlink=1, st_uid=502, st_gid=20, st_size=177438, st_atime=1308667543, st_mtime=1290114007, st_ctime=1308667385) >>> os.stat('spam/letter7.eml').st_size() Traceback (most recent call last): File "", line 1, in os.stat('spam/letter7.eml').st_size() TypeError: 'int' object is not callable >>> os.stat('spam/letter7.eml').st_size 177438 >>> ================================ RESTART ================================ >>> >>> os.getcwd() '/Users/adam/Desktop/Summer 2011 Scripts' >>> os.mkdir('spam') Traceback (most recent call last): File "", line 1, in os.mkdir('spam') OSError: [Errno 17] File exists: 'spam' >>>