| ![]() ![]()
Among published | ![]() ![]() ![]() |
| ![]()
Tips for Scripting Java with Jython by O'Reilly and Noel Rappin covers 11 specific features of Jython that Java programmers can be excited about. Within IBM's DeveloperWorks Java Zone, Developing Web services with Python can help you understand the workings of Jython development. | ![]() ![]() ![]() |
|
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
| ![]() Writing the 33 programs of the PythonChallenge is a fun and way to learn. pytut.infogami.com offers Python official docs in a community-modifiable `Wiki.
Beginning Python: From Novice to Professional (2005) by Magnus Hetland comes highly recommended. Python in a Nutshell (O'Reilly) by Alex Martelli presents a good quick reference.
Dive Into Python by Mark Pilgrim Also online at Dive Into Python (good coverage in excellent prose).
| ![]() ![]() ![]() |
|
""" hello.py - Wilson Mar - 24oct2005 Some simple program Coded for Jython version 2.5 for Windows 32-bit. """ class MessageError(Exception): """Base class for errors in this package.""" # To raise ValueError('message')" def func1(): pass def func2(): pass dispatch = {'go': func1, 'stop': func2} # Note lack of parens for funcs dispatch[get_input()]() # Note trailing parens to call function def func2(a, b): """Returns the average of *two* (and only two) arguments. :param arg1: a numeric value :type arg1: **any** numeric type :param arg2: another numeric value :type arg2: **any** numeric type :return: mid-point (or arithmetic mean) between two values :rtype: numeric type compatible with the args. """ a = 'new-value' a = unicode('new-value','latin-1') print a.encode('latin-1','replace') b = 0xa5 + 1 # Hex decimal 165+1 c = 010 # Octal 10 = decimal 8 d = x010 # Octal 10 = decimal 8 return a, b while True: line = f.readline() if not line: break #...do something with line... for line in f: # do something else |
Comments can contain doc strings.
Doc strings can be retrieved using the print docstring.__doc__ attribute.
The backward slash is Python's line continuation character.
Instead of semicolons at the end of each expression (as with C or Java), like VBScript
Python uses a carriage return to separate statements.
This is perhaps the most distinguishing characteristics of Python.
Python uses {} curly braces to define dictionaries.
To separate code blocks Python uses
indentation (4 spaces)
to delimit statement groups.
Sequential lines indented at the same level are treated as the same block.
To continue a line, add a \ back slash and indent the following line.
The # hash (or pound sign as some call it) begins comments (as with C). This can't follow a continuation character on the same line.
"..." elipses (3 periods) precedes each multi-line construct.
Python's high-level data types allow complex operations to be expressed in a single statement.
The Python community has a saying: "Python comes with batteries included." Python is extensible: functions can be added by adding modules.
The pass statement does nothing.
A leading '0' (zero) indicates octal, '0x' indicates a hex number,
'\u' goes in front of hex Unicode
code point, a different type than a string in Python v2.x but Unicode in Python v3.x. Unicode types have .encode and .decode methods not in string types. See PEP 3120, 3131.
"_" (the underline character) stands in for the last variable used (read-only).
"\" backslash character at the end of a line is used to specify continuation to the next line.
"\n" is an escape character
for "next line" (not necessary between triple quotes).
"\\" is thus necessary to specify back-slash separators between folders in a directory path.
"+" is used to concantenate strings (rather than the amersand & in C).
Strings can be encased between either double or single quotes.
Unlike C, assignments are not allowed within expressions.
|
>>> import tck.hello.py Traceback (most recent call l File "<stdin>", line 1, in ImportError: No module named |
When naming python modules, do not use special characters such as a period or a dash,
which have special meaning to python. The result of such attempts are shown at right.
When a module is imported for the first time (or when the source is more recent than the current compiled file) Python parses and translates it into a bytecode files suffixed with .pyc in the same folder as the source file.
Python scripts are made into an executable Windows script
when its named with a
.cmd suffix and contains this first line:
| ![]() ![]()
| ![]() ![]() ![]() |
| ![]() ![]()
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
Python's de-facto standard for the most commonly used | ![]() ![]() ![]() |
|
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
|
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
|
| ![]() ![]() ![]() |
|
| ![]() ![]() ![]() |
|
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
|
| ![]() ![]() ![]() |
|
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
| ![]()
| ![]() ![]() ![]() |
![]() ![]() ![]() |
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
|
| ![]() ![]() ![]() |
Related Topics:
Keyboard Shortcuts
Project Software
Project Central
![]()
| Your first name: Your family name: Your location (city, country): Your Email address: |
Top of Page ![]() Thank you! |