|
|
|
|
Beginning Python (Indianapolis, Ind.: Wiley, 2005)
by Peter Norton
Among published |
|
|
Jython
|
|
|
Jython Essentials
(O'Reilly, March 21, 2002)
by Samuele Pedroni, Noel Rappin
|
|
|
|
|
|
# hello.py - Wilson Mar - 24oct2005
# Some simple program
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):
a = 'new-value'
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
|
Python coders can avoid continuation and escape characters because, with Python, multi-line string blocks are within as set of triple double-quotes.
# begins comments (as with C). It can't follow a continuation character on the same line.
Instead of semicolons at the end of each expression (as with C or Java), like VBScript
Python uses a carriage return to separate statements.
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.
"..." 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.
"_" (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 " |
When naming modules, do not use special characters such as
a period or a dash, which have special meaning to python.
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.
You will not see the >>> prompt while a called module is running. On Windows, press Alt+Tab to switch to the app's window.
Python scripts are made into an executable Windows script when its named with a .cmd suffix and contains this first line:
|
Python Programming On Win32 (Beijing ; Sebastopol, CA: O'Reilly, 2000)
by Mark Hammond, Andy Robinson
|
|
|
|
|
Python's de-facto standard the most commonly used |
|
|
|
|
|
|
|
It uses reflection, MSIL parsing, and callgraph analysis to inspect assemblies for more than 200 defects The tool has both GUI and command line versions,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| The Deitel Family's books are wordy and expensive ($75), but colorful. C# For Experienced Programmers JoeGrip says you can learn C# in just 5 hours with their interactive audio courses online.
|
|
|
|
|
|
|
|
|
|
|
|
|
A class is the particular object type created by executing a class statement. Class objects are used as templates to create instance objects, which embody both the data (attributes) and code (methods) specific to a datatype.
A class can be based on one or more other classes, called its base class(es). It then inherits the attributes and methods of its base classes. This allows an object model to be successively refined by inheritance.
|
| Object Scope Modifier keyword | Purpose |
|---|---|
native | method bodies are found outside the JVM, usually in a library written in C++ or other low-level language. Native method declarations are ended with a semi-colon and not curly braces having no body, indicating that the implementation is not provided in the class. |
abstract | classes and methods are not instantiated by the new constructor so that implementation is deferred to a subclass. The compiler requires a class to be abstract if any of its methods is abstract. However, an abstract class can have non abstract methods. |
final | defined in a superclass (or interface) a constant specified with an initial value that cannot be changed. Final classes can't be sub-classed (extended) and must be overridden by the implementing class. Such static variables are usually in upper case and referenced by the class name as a prefix. A final variable must have an initial value or may be initialized in every constructor. |
transient | variables are not stored as part of its object's persistent state. Such objects may implement the Serializable or Externalizable interfaces to have their state serialized and written to destinations outside the JVM by passing the object to the writeObject() method of the ObjectOutputStream class. |
volatile | variables might be modified asynchronously in multiprocessor environments. |
| Class Modifier | Purpose |
|---|---|
static | methods and variables are called class methods and variables because they are associated with the class itself rather than an instance of that class. Methods cannot be declared inside a static block. So static members and variables are referenced by class name rather than instance name. Inside a static method there is no this reference to an instance. Static methods can't be overridden. Static methods, variables, and blocks of code are created only once for all instances to share. |
static inner | have access to the static members of the enclosing class, even to those that are private. They do not have implicit reference to members of the instances of the enclosing class. |
member inner | (not static) can access all the members of the enclosing class, even if they are protected or private. |
local inner | specified within a method definition of the enclosing class. It cannot be declared as static, public, protected, or private. It can access local variables that are specified as final. |
Anonymous inner | are use just once and not again. They do not have a class name / constructors. They can access final local variables |
The synchronized modifier is used to control access to critical code in multi-threaded programs.
|
|
|
|
|
|
|
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! | |||