Web Browser and Time Access Module
The webbrowser module provides high level interface to allowing the display of web-based documents
to users.
To import the webbrowser module, use an import statement.
Syntax:
import webbrowser
Example:
import webbrowser
The webbrowser module include an open method that allows user to open a page based on the
specified URL(Uniform Resource Locator).
Syntax:
[Link](URL)
Example:
[Link](“[Link]
The time module allows various time related functions. To use the time module, use import time. The
time module includes a sleep method that suspends program execution for a given number of seconds.
Syntax:
[Link](number of seconds)
Example:
[Link](10)
Take a Break Application
import time
import webbrowser
total_breaks = 3
break_count = 0
while(break_count < total_breaks):
[Link](10)
[Link]("[Link]
break_count = break_count + 1
for each statement
-iterates the contents of an array variable. Array variables are variables that handle one or more values.
Syntax:
for variable in array_variable:
statement(s)
-to create an array variable, use the following syntax:
array_variableName=[‘element1’,’element2’,’elementN’]
OS Module
- provides a portable way of using operating system dependent functionality.
-to use the os module, use an import statement.
Syntax:
import os
Listing Files in the Directories
-to list files in a specified directory, use the listdir function.
Syntax:
[Link](r”folderName”)
Example:
[Link](r”C:\Myfolder”)
Renaming Files
-to rename a file, use rename function.
Syntax:
[Link](oldName,newName);
-to remove characters from a filename, use the [Link] function.
Syntax:
[Link](table,characters to remove);
Getting the Current Directory
-to get the current active directory, use the getcwd function.
Syntax:
[Link]() import Message
Secret os Application
def secretMessage():
array_files = [Link](r”C:\Users\photos”)
Changing Directory
print(array_files)
-to change directories, use the chdir function.
[Link](r”C:\Users\photos)
Syntax:
for strfilename in array_files:
[Link](r”folderName”) [Link](strfilename, [Link](None,
"0123456789"))
secretMessage ()
Prelim Projects in Programming Logic and Design
1. Make a TAKE A BREAK APPLICATION that will remind the user to take a break every two hours thrice a
day by automatically playing his/her favorite YouTube music video.
2. Develop a SECRET MESSAGE APPLICATION. The secret message should be intended for your family or
loved one. Use your own alphabet photos.
Creating a Media Player
Introduction to Linux Documentation Sources
Important Linux documentation sources include:
The man pages (short for manual pages)
GNU Info
The help command and --help option
Other Documentation Sources, e.g. [Link]
The man pages
The man pages are the most often-used source of Linux documentation. They provide in-depth
documentation about many programs and utilities as well as other topics, including configuration files,
system calls, library routines, and the kernel.
Typing man with a topic name as an argument retrieves the information stored in the topic's man
pages. Some Linux distributions require every installed program to have a corresponding man page,
which explains the depth of coverage. (Note: man is actually an abbreviation for manual.) The man
pages structure were first introduced in the early UNIX versions of the early 1970s.
man
The man program searches, formats, and displays the information contained in the man pages. Because
many topics have a lot of information, output is piped through a terminal pager program such as less to
be viewed one page at a time; at the same time the information is formatted for a good visual display.
When no options are given, by default one sees only the dedicated page specifically about the topic. You
can broaden this to view all man pages containing a string in their name by using the -f option. You can
also view all man pages that discuss a specified subject (even if the specified subject is not present in
the name) by using the –k option.
man –f generates the same result as typing whatis.
man –k generates the same result as typing apropos.
Manual Chapters
The man pages are divided into nine numbered chapters (1 through 9). Sometimes, a letter is appended
to the chapter number to identify a specific topic. For example, many pages describing part of the X
Window API are in chapter 3X The chapter number can be used to force man to display the page from a
particular chapter; it is common to have multiple pages across multiple chapters with the same name,
especially for names of library functions or system calls With the -a parameter, man will display all pages
with the given name in all chapters, one after the other.
$ man 3 printf
$ man -a printf
GNU Info System
The next source of Linux documentation is the GNU Info System.
This is the GNU project's standard documentation format (info) which it prefers as an
alternative to man. The info system is more free-form and supports linked sub-
sections.
Functionally, the GNU Info System resembles man in many ways. However, topics
are connected using links (even though its design predates the World Wide Web).
Information can be viewed through either a command line interface, a graphical help
utility, printed or viewed online.
Command Line Info Browser
Typing info with no arguments in a terminal window displays an index of available
topics. You can browse through the topic list using the regular movement
keys: arrows, Page Up, and Page Down.
You can view help for a particular topic by typing info <topic name>. The system
then searches for the topic in all available info files.
Some useful keys are: q to quit, h for help, and Enter to select a menu item.
info Page Structure
The topic which you view in the info page is called a node.
Nodes are similar to sections and subsections in written documentation. You can move
between nodes or view each node sequentially. Each node may contain menus and
linked subtopics, or items.
Items can be compared to Internet hyperlinks. They are identified by an asterisk (*) at
the beginning of the item name. Named items (outside a menu) are identified with
double-colons (::) at the end of the item name. Items can refer to other nodes within
the file or to other files. The table lists the basic keystrokes for moving between nodes.
Key Function
n Go to the next node
p Go to the previous node
u Move one node up in the index
Introduction to the help Option
The third source of Linux documentation is use of the help option.
Most commands have an available short description which can be viewed using the
--help or the -h option along with the command or application. For example, to learn
more about the man command, you can run the following command:
$ man --help
The --help option is useful as a quick reference and it displays information faster than
the man or info pages.
About the help Command
Some popular commands (such as echo) when run in a bash command
shell silently run their own built-in versions of system programs or utilities,
because it is more efficient to do so. (We will discuss command shells in great
detail later.) To view a synopsis of these built-in commands, you can simply type help.
For these built-in commands, help performs the same basic function as the -h and --
help arguments (which we will discuss shortly) perform for stand-alone programs.
Laboratory Activity: Finding Linux Documentation
Lab 1: Finding Info Documentation From the command line, bring up the info page for the grep
command. Bring up the usage section.
Lab 2: Finding man pages From the command line, bring up the man page for the man command. Scroll
down to the EXAMPLES section.
Lab 3: Finding man pages by Topic What man pages are available that document file compression?
Lab 4: Finding man pages by Section From the command line, bring up the man page for the printf
library function. Which manual page section are library functions found?
Lab 5: Command-Line Help List the available options for the mkdir command. How can you do this?
There is more than just one way.