Python Utilities - Educational Materials In this section, we look at a few of Python's many standard utility modules to solve common problems. File System -- os, os.path, shutil The *os* and *os.path* modules include many functions to interact with the file system. The *shutil* module can copy files. os module docs filenames = os.listdir(dir) -- list of filenames in that directory path (not including . and ..). The filenames are just the names in the directory, not their absolute paths.
s Python Class - Google's Python Class - Google Code Welcome to Google's Python Class -- this is a free class for people with a little bit of programming experience who want to learn Python. The class includes written materials, lecture videos, and lots of code exercises to practice Python coding. These materials are used within Google to introduce Python to people who have just a little programming experience. The first exercises work on basic Python concepts like strings and lists, building up to the later exercises which are full programs dealing with text files, processes, and http connections. The class is geared for people who have a little bit of programming experience in some language, enough to know what a "variable" or "if statement" is. Beyond that, you do not need to be an expert programmer to use this material.
s Python Class - Google's Python Class - Google Code Welcome to Google's Python Class -- this is a free class for people with a little bit of programming experience who want to learn Python. The class includes written materials, lecture videos, and lots of code exercises to practice Python coding. These materials are used within Google to introduce Python to people who have just a little programming experience. The first exercises work on basic Python concepts like strings and lists, building up to the later exercises which are full programs dealing with text files, processes, and http connections. Python Regular Expressions - Educational Materials Regular expressions are a powerful language for matching text patterns. This page gives a basic introduction to regular expressions themselves sufficient for our Python exercises and shows how regular expressions work in Python. The Python "re" module provides regular expression support. In Python a regular expression search is typically written as: match = re.search(pat, str)
Learn Python in 10 minutes NOTE: If you would like some Python development done, my company, Stochastic Technologies, is available for consulting. This tutorial is available as a short ebook. The e-book features extra content from follow-up posts on various Python best practices, all in a convenient, self-contained format. All future updates are free for people who purchase it. The Lair of the Python Welcome to the home of the Voidspace Python pages. Not a snake, Python is a dynamic scripting language with a beautifully clean syntax. There's lots of code here to peruse, as well as the Techie Blog which explores life from the point of view of a Pythoneer. Python is a dynamic, object orientated, programming language. Its focus is on allowing the programmer the maximum freedom and expressiveness. Because of this it inspires a particular elegance and symmetry of coding techniques.
Dive Into Python 3 You are here: • Dive Into Python 3 Dive Into Python 3 covers Python 3 and its differences from Python 2. Compared to Dive Into Python, it’s about 20% revised and 80% new material. Python Dict and File - Educational Materials Dict Hash Table Looking up or setting a value in a dict uses square brackets, e.g. dict['foo'] looks up the value under the key 'foo'. Strings, numbers, and tuples work as keys, and any type can be a value. Other types may or may not work correctly as keys (strings and tuples work cleanly since they are immutable). Looking up a value which is not in the dict throws a KeyError -- use "in" to check if the key is in the dict, or use dict.get(key) which returns the value or None if the key is not present (or get(key, not-found) allows you to specify what value to return in the not-found case). print dict['a'] ## Simple lookup, returns 'alpha' dict['a'] = 6 ## Put new key/value into dict 'a' in dict ## True ## print dict['z'] ## Throws KeyError if 'z' in dict: print dict['z'] ## Avoid KeyError print dict.get('z') ## None (instead of KeyError)
regex search and replace example scripts - Python Testing Search and replace is such a common task that it should be a tool that’s in every command line script author’s toolbox. There are probably endless solutions to the problem. I’ve put together my standard methods for tackling the problem. I’ll also show similar Perl versions, mainly for comparisons. use models Python Sorting - Educational Materials The easiest way to sort is with the sorted(list) function, which takes a list and returns a new list with those elements in sorted order. The original list is not changed. a = [5, 1, 4, 3] print sorted(a) ## [1, 3, 4, 5] print a ## [5, 1, 4, 3] It's most common to pass a list into the sorted() function, but in fact it can take as input any sort of iterable collection.
3. Using Python on Windows This document aims to give an overview of Windows-specific behaviour you should know about when using Python on Microsoft Windows. 3.1. Installing Python Unlike most Unix systems and services, Windows does not require Python natively and thus does not pre-install a version of Python. Python Lists - Educational Materials Python has a great built-in list type named "list". List literals are written within square brackets [ ]. Lists work similarly to strings -- use the len() function and square brackets [ ] to access data, with the first element at index 0. (See the official python.org list docs.) colors = ['red', 'blue', 'green'] print colors ## red print colors ## green print len(colors) ## 3 Assignment with an = on lists does not make a copy.
Installing Python on Windows First, download the latest version of Python 2.7 from the official Website. If you want to be sure you are installing a fully up-to-date version, click the Downloads > Windows link from the home page of the Python.org web site . The Windows version is provided as an MSI package. To install it manually, just double-click the file. The MSI package format allows Windows administrators to automate installation with their standard tools. By design, Python installs to a directory with the version number embedded, e.g.
Python Strings - Educational Materials Python has a built-in string class named "str" with many handy features (there is an older module named "string" which you should not use). String literals can be enclosed by either double or single quotes, although single quotes are more commonly used. Backslash escapes work the usual way within both single and double quoted literals -- e.g. \n \' \".