1: | File Filtering. Display all lines of a file, except those that start with a pound sign ( # ), the comment character for Python, Perl, Tcl, and most other scripting languages.
|
2: | File Access. Prompt for a number N and file F, and display the first N lines of F.
|
3: | File Information. Prompt for a filename and display the number of lines in that text file.
|
4: | File Access. Write a "pager" program. Your solution should prompt for a file name, and display the text file 25 lines at a time, pausinLg each time to ask the user to "press a key to continue."
|
5: | Test Scores. Update your solution to the test scores problems (Exercises 53 and 64) by allowing a set of test scores be loaded from a file. We leave the file format to your discretion.
|
6: | File Comparison. Write a program to compare two text files. If they are different, give the line and column numbers in the files where the first difference occurs.
|
7: | Parsing Files. Windows users: create a program that parses a Windows .ini file. Unix users: create a program that parses the /etc/services file. All other platforms: create a program that parses an system file with some kind of structure to it.
|
8: | Module Introspection. Extract module attribute information. Prompt the user for a module name (or accept it from the command-line). Then, using dir() and other built-in functions, extract all its attributes, and display their names, types, and values.
|
9: | "PythonDoc." Go to the directory where your Python standard library modules are located. Examine each .py file and determine whether a __doc__ string is available for that module. If so, format it properly and catalog it. When your program has completed, it should present a nice list of those modules which have documentation strings and what they are. There should be a trailing list showing which modules do not have documentation strings (the shame list). EXTRA CREDIT: extract documentation for all classes and functions within the standard library modules.
|
10: | Home Finances. Create a home finance manager. Your solution should be able to manage savings, checking, money market, certificate of deposit (CD), and similar accounts. Provide a menu-based interface to each account as well as operations such as deposits, withdrawals, debits, and credits. An option should be given to a user to remove transactions as well. The data should be stored to file when the user quits the application (but randomly during execution for backup purposes).
|
11: | Web Site Addresses.
(a)Write a URL bookmark manager. Create a text-driven menu-based application which allows the user to add, update, or delete entries. Entries include a site name, Website URL address, and perhaps a one-line description (optional). Allow search functionality so that a search "word" looks through both names and URLs for possible matches. Store the data to a disk file when the user quits the application, and load up the data when the user restarts.
(b)Upgrade your solution to part (a) by providing output of the bookmarks to a legible and syntactically correct HTML file (.htm or .html) so that users can then point their browser to this output file and be presented with a list of their bookmarks. Another feature to implement is allowing the creation of "folders" to allow grouping of related bookmarks. EXTRA CREDIT: Read the literature on regular expressions and the Python re module. Add regular expression validation of URLs that users enter into their database.
|
12: | Users and Passwords.
(a)Do Exercise 7-5, which keeps track of usernames and passwords. Update your code to support a "last login time." See the documentation for the time module to obtain timestamps for when users "login" to the system. Also, create the concept of an "administrative" user which can dump a list of all the users, their passwords (you can add encryption on top of the passwords if you wish), and their last login times. The database should be stored to disk, one line at a time, with fields delimited by colons ( : ), i.e., "joe:boohoo:953176591.145," for each user. The number of lines in the file will be the number of users which are part of your system.
(b)Further update your example such that instead of writing out one line at a time, you "pickle" the entire database object and write that out instead. Read the documentation on the pickle module to find out how to "flatten" or "serialize" your object, as well as how to perform I/O using picked objects. With the addition of this new code, your solution should take up fewer lines than your solution in part (a).
|
13: | Command-line arguments.
(a)What are they, and why might they be useful?
(b)Write code to display the command-line arguments which were entered.
|
14: | Logging Results. Convert your calculator program (Exercise 5-6) to take input from the command-line, i.e.,
% calc.py 1 + 2
Output the result only. Also, write each expression and result to a disk file. Issuing a command of
% calc.py print
will cause the entire contents of the "register tape" to be dumped to the screen and file reset/truncated. Here is an example session:
% calc.py 1 + 2
3
% calc.py 3 ^ 3
27
% calc.py print
1 + 2
3
3 ^ 3
27
% calc.py print
%
|
15: | Copying Files. Prompt for two file names (or better yet, use command-line arguments). The contents of the first file should be copied to the second file.
|
16: | Text Processing. You are tired of seeing lines on your e-mail wrap because people type lines which are too long for your mail reader application. Create a program to scan a text file for all lines longer than 80 characters. For each of the offending lines, find the closest word before 80 characters and break the line there, inserting the remaining text to the next line (and pushing the previous next line down one). When you are done, there should no longer be lines longer than 80 characters.
|
17: | Text Processing. Create a crude and elementary text file editor. Your solution is menu-driven, with the following options: (1) create file [prompt for file name and any number of lines of input], (2) display file [dump its contents to the screen], (3) edit file (prompt for line to edit and allow user to make changes), (4) save file, and (5) quit.
|
18: | Searching Files. Obtain a byte value (0-255) and a file name. Display the number of times that byte appears in the file.
|
19: | Generating Files. Create a sister program to the previous problem. Create a binary data file with random bytes, but one particular byte will appear in that file a set number of times. Obtain the following three values: (1) a byte value (0255), (2) the number of times that byte should appear in the data file, and (3) the total number of bytes that make up the data file. Your job is to create that file, randomly scatter the request byte across the file, and to ensure that there are no duplicates and that the file contains exactly the number of occurrences that byte was requested for, and that the resulting data file is exactly the size requested.
|