Sunday, 10 June 2012

tinker: . . to work unskillfully or clumsily at anything: . . . tk-tinker is still working itself out . . .  "Learning about computer programming is like learning to play a musical instrument: you have to do it,"

Thursday, 31 May 2012

Python Utility Robot - Python Learning Environment



PUR-PLE

RUR-PLE is an environment designed to help you learn computer programming using the language Python.

Highly recommended ... working through the lessons.



Rule # 1
Learning about computer programming is like learning to play a musical instrument: you have to do it, not simply read about it. 

Rule # 2
Write your computer programs to make them easy for people to read

Rule # 3
When writing computer programs, do not repeat yourself.
I repeat: do not repeat yourself!

The following extract is an example of the interesting content of the lessons.

Picture adapted from the public archive of the U.S. Naval Historical Center 
The project is current and the windows installer is seamless. 
Je trouve le navigateur de RUR-PLE suffire. En fait, je viens de charger 2 instances de RUR-PLE à travailler sur les exercices.

 

Saturday, 26 May 2012

turtle from Python Interpreter

http://docs.python.org/library/turtle.html

To activate turtle from Python Interpreter enter:

from turtle import *
# This imports Turtle and all of its commands.

turtle commands:

forward(distance)

 - Moves the turtle forward by the specified distance, in the direction the turtle is headed.

backward(distance)
- Move the turtle backward by distance, opposite to the direction the turtle is headed. Does not change the turtle’s heading.


right(angle) - Turn turtle right by angle units. (Units are by default degrees)

left(angle)
- Turn turtle left by angle units. (Units are by default degrees)

 goto (x,y)
     or
setposition (x,y)

-  Moves the turtle to coordinates (x,y) and if the pen is down, draw a line.

home( )

-  Moves the turtle back to (0,0)


circle
(radius, extent)
- Draws a circle with radius.
- extent refers to the number of degrees (e.g. 180 = semicircle)


 undo( )
- Undo (repeatedly) the last turtle action.
speed(speed)
 - Sets how fast the turtle will draw (1-10 arbitrary units)


position( )
- Returns the (x,y) coordinates of the turtle.


pendown( )
- Puts the pen down so it draws when the turtle moves.

penup( )
- Puts the pen up so it does not draw when the turtle moves.


pencolor(colorstring)
-  if colorstring == a color like "green" it will draw the line in that color.


reset( )

- Delete everything and set turtle back to 0


clear()
- Delete drawings but keeps turtle where it is.

 

Friday, 25 May 2012

>>> help()

maybe help ( ) can reduce my dependence on the internet
 
Welcome to Python 2.7!  This is the online help utility

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> LISTS
Mutable Sequence Types
**********************

List and ``bytearray`` objects support additional operations that
allow in-place modification of the object. 
 . . . example of help on topics

help> NAMESPACES
Naming and binding
******************

*Names* refer to objects.  Names are introduced by name binding
operations. Each occurrence of a name in the program text refers to
the *binding* of that name established in the innermost function block
containing the use.

A *block* is a piece of Python program text that is executed as a
unit. The following are blocks: a module, a function body, and a class
definition. Each command typed interactively is a block.  A script
file (a file given as standard input to the interpreter or specified
on the interpreter command line the first argument) is a code block.
...  next help with a module

help> turtle
Help on module turtle:

NAME
    turtle

FILE
    c:\python27\lib\lib-tk\turtle.py

DESCRIPTION
    Turtle graphics is a popular way for introducing programming to
    kids. It was part of the original Logo programming language developed
    by Wally Feurzig and Seymour Papert in 1966.
   
    Imagine a robotic turtle starting at (0, 0) in the x-y plane. Give it
    the command turtle.forward(15), and it moves (on-screen!) 15 pixels in
    the direction it is facing, drawing a line as it moves. Give it the
    command turtle.left(25), and it rotates in-place 25 degrees clockwise.
   
    By combining together these and similar commands, intricate shapes and
    pictures can easily be drawn.
   
    ----- turtle.py


help> keywords

Here is a list of the Python keywords.  Enter any keyword to get more help.

and                 elif                if                  print
as                  else                import              raise
assert              except              in                  return
break               exec                is                  try
class               finally             lambda              while
continue            for                 not                 with
def                 from                or                  yield
del                 global              pass               

helpful>

Initializing Lists

empty_list = []

string_list = [ 'a', 'list', 'of', 'strings']

number_list = [ 1, 1., 0]



list_of_lists = [  'empty_list', [ 1, 1., 0], string_list]

list_of_tuples = [ (1, 'a'), ('Fad', 'book'), ('Fade','book') ]








# append method built-in

string_list.append ('or letters')

#  I like lists because
#  they are simple and powerful

concatenating_lists = ['lists', 'are', 'versatile'] + [('and','fun')]

print string_list
print concatenating_lists









 P.Guo web application used as an illustrated print statement. Online Python Tutor
related blog entry

Thursday, 24 May 2012

Purple Turtle






















>>> pen_down()
Is it just me or is this turtle purple.

>>> color("purple") 
The windows installer works perfectly.
The environment is standalone.
This turtle incorporates interactive Python interpreter 2.6


>>> color("green")

PurpleTurtle was written 






...  The default Python prompt of the interactive shell when entering code for an indented code block.




I say "Blogger auto-generated html is a bit clumsy."

 postscriptum
 
"Programs must be written for people to read, and only incidentally for machines to execute."
- Abelson & Sussman, SICP, preface to the first edition

The Turtle interpreter supports
>>> import this

Wednesday, 23 May 2012

RUR-PLE Interpreter

RUR-PLE

Starts with the Robot(Turtle) lessons,
builds with Python concepts incorporated into the Robot lessons,
then introduces the Python interpreter.



RUR-PLE

 Python, the interpreter.
"... we will learn about the Python interpreter. We will also learn about numbers, strings, lists, tuples and dictionaries. This part is very similar to a traditional beginner's tutorial to Python ... except that we can still have fun with Reeborg!"

 >>> The default Python prompt of the interactive shell.
Often seen for code examples which can be executed interactively in the interpreter.  



L'interpréteur interactif

L'installation
Python comprend un interpréteur interactif que vous pouvez utiliser pour exécuter du code comme vous le tapez. Il s'agit d'un excellent outil à utiliser pour essayer de petits échantillons et voir le résultat immédiatement, sans avoir à gérer les sorties ou les déclarations d'impression.



Malheureusement l'interpréteur interactif en RUR-PLE ne supporte pas help (). C'est une fonction que j'utilise (beaucoup).


Sunday, 20 May 2012

Saturday, 19 May 2012


Horizontal Scroll Bars for IDLE

from http://code.activestate.com/lists/python-list/26878/ (not my code, found it on this site) It is dated Wed, 08 Mar 2000
Works for Python 2.7.3


"I finally got around to adding horizontal scroll bars to the IDLE editor window to help when you get those LONG lines of code and very small boxes when transcribing/reading. The changes are rather minor (4 new lines of code) and were made in the EditorWindow.py module.
First  renamed EditorWindow.pyc  to EditorWindow_org.pyc

To make the code changes in IDLE, I opened EditorWindow.py  in Notepad++
and performed a search for 'vbar' which is in the EditorWindow class, init method.



Add those lines that have ### appended to them and VOILA you have it.

Jonathan P.

(Stack Overflow answer by Amber)
















Code Listing:
    self.vbar = vbar = Scrollbar(top, name='vbar') 
    self.hbar=hbar=Scrollbar(top,orient=HORIZONTAL,name='hbar')  ###
    ...
    vbar['command'] = text.yview
    vbar.pack(side=RIGHT, fill=Y)
    hbar['command'] = text.xview        ###
    hbar.pack(side=BOTTOM, fill=X)      ###

    text['yscrollcommand'] = vbar.set
    text['xscrollcommand'] = hbar.set   ###

Friday, 18 May 2012

Exploring Programming Languages ... Online


repli.it
 



The repl.it project is an attempt to create an online environment for interactively exploring programming languages. It provides a fully-featured terminal emulator and code editor, powered by interpreter engines for more than 15 languages.

Tuesday, 15 May 2012

Tuples with P. Guo's Online Python Tutor

Tuples


Code Listing:
unique_tuple  = 'a', 'tuple', 'is',
unique_tuple2 = 'an', 'ordered', 'list',
unique_tuple3 = 'of', 'elements'

unique_tuple  = 'A tuple, values','separated'
unique_tuple2 = 'by', 'commas'
unique_tuple3 = 'immutable', 'object'
print "strings, numbers, and tuples are immutable"


Monday, 14 May 2012

Dictionaries -- Idle Shell Output -- Online Tutor


Idle Shell Output
Crib_Dist4_3.py

# filename: Crib_Dist4_3.py
# 4.3 ---   Dictionaries

section = "4.3 ---   Dictionaries"
print '\n' + section +'\n'


print 'Dictionaries are lists of Key:Value pairs'

Flintstones = {} # creates empty dictionary .. Flintstones
print "Flintstones  # dictionary is empty"
print Flintstones 
Flintstones_neighbours ={'Barney Rubble':'sidekick', \
'Betty Rubble':'wife', 'Bamm-Bamm':'son'}
print 'Flintstones neighbours'
print Flintstones_neighbours

print '# Add Fred & Wilma to the Flintstones dictionary'





Flintstones['Fred'] = 'star'
Flintstones['Wilma'] = 'wife'
print '# Add Pebbles'
Flintstones['Pebbles'] = 'daughter'

print 'Dictionaries are not ordered'

print 'Flintstones'
print Flintstones

# dictionaries are like hashes in Perl

print "# adding pets"
Flintstones.update({'Dino':'dino-dog'})
print Flintstones
Flintstones_neighbours.update({'Hoppy':'dino-roo'})
print Flintstones_neighbours
print '# Merging 2 dictionaries'
Flintstones.update(Flintstones_neighbours) 
print Flintstones














Highly recommend you enter the code into Online Tutor and try out the tool.

Strings & Lists with P. Guo's Online Python Tutor


Click to Enlarge Image
Code Listing
#4    --- Data
#4.1 ---  Strings
chapter = "4   ---  Data"
section = "4.1 ---  Strings"
print chapter
print section

string = "'abc is part of this text string'"
print 'Concatenation works with strings:' + 'abc' + 'def ' + string

# 4.2 ---   Lists
section = "4.2 ---   Lists"
print '\n' + section +'\n'

# the following constructs/assigns a list
print "# the following constructs/assigns a list"
print """d_list = ['lists','are', 'a', 'sequence', 'of', 'items',1,2]"""
defining_list = ['lists','are', 'a', 'sequence', 'of', 'items',1,2]
print defining_list

Python List Illustrated Code

repl.it displaying code and output for list_practice.py


Code Listing

# list_practise_repl_it.py
# 4.2 Lists
print """a_list = ['a','b','cow',1,2]     # constructs/assigns a list"""
a_list = ['a','b','cow',1,2]
print a_list
print                   # adds extra line to console output

print """a_list.append('antelope')  # Adds item to the end of the list."""
a_list.append('antelope')
print a_list

print
print """a_list.sort()              # Sorts the items of the list, """
a_list.sort()
print a_list
print
print "The built-in function len() also applies to lists."
print "It returns the number of items in the list:"
print "With the following list: " , a_list
print "len(a_list) # currently returns count of  %i"  %  len(a_list)
print
print """ Since Python starts counting from 0
Indexing: L[0]  (first element),
              L[1]  (second element),
          ...
              L[5]  (sixth element)
          or
              L[-1] (last element)
              """

print """a_list [0:0] = ['zebra']   # insert item at start of the list."""
a_list[0:0] = ['zebra']
print a_list

Sunday, 13 May 2012

Program Flow Control

Output from Control_example.py
Code Listing:
#  Control_example.py
print "if | elif | else statements code examples"  # Selecting actions
name = 'Bamm-Bamm'
if name == 'Barney':              
    print "Flintstones' neighbours"
elif name != 'Betty':
    print name
else:
    son = 'Bamm-Bamm'
   
print "while statement code example"
z = 3
while z>0:                          # General Loops
    print z
    z = z-1
   
print "for code example"            # Sequence iteration
for x in ['this', 'is', 'a','sequence']:  
    print x
 
print "range code example"
for y in range(5):                  # Python count 0 .. 4
    print y

print "Breaking out of a loop: code example"
a_list = ['Jill', 1, "Bob", 'Brown', 'Jones', 333, 333, 1234.5]
for name in a_list:
    if name == 'Jones':
         break
    print name

Online Python Tutor .. Data Illustrated


Variables & Assignment with P. Guo's Online Python Tutor

Text in the following video is blurry. It is what happens if you click the Visualize execution button


Code Listing:
#  <-----  that symbol starts a comment in the code

#  1 ---   Variables and assignment - Creating references

name = 'Betty'

firstname,lastname = 'Fred','Flintstone'

# There is no need to declare variables.

print "print statement output messages to the console"

print "any"
print "string"
print 'Betty'
print "print statement will 'print' variables"
print name
print firstname
print lastname

Python Crib Sheet 01

Loaded Crib_Sheet01.py listed below

Run Crib_Sheet01.py listed below
# <-- that symbol starts a comment in the code


#  1   ---   Variables and assignment - Creating references

name = 'Betty'
program = name = "Python"
firstname,lastname = 'Fred','Flintstone'
# There is no need to declare variables.

#  2   ---    Control

# >>>note indentation:
# >>>    is important

print "if | elif | else statements code examples"  # Selecting actions
if name == 'Barney':                
    print program, version_of[program]
elif name != 'Wilma':
    print name
else:
    program = 'Bamm-Bamm'
    
print "for code example"     # Sequence iteration

for x in ['this is','a','list']:   
    print x
   
print "range code example"
for y in range(5):                    # 0 .. 4
    print y

print "while statement code example"
z = 3
while z>0:                            # General Loops
    print z
    z = z-1

print "Breaking out of a loop: code example"

a_list = ['Jill', 1, "Bob", 'Brown', 'Jones', 333, 333, 1234.5]
for name in a_list:
    if name == 'Jones':
         break
    print name

# 3   ---  Data   ---   Strings

string = 'abc'
print 'Concatenation works:' + 'abc' + 'def' + string

print '''
For multi-line strings use triple quotes.
For example this is a long sentence which
goes on beyond a single line.'''

print 'My name is %s' % name
print string
#    ------------    alternatively:
name = "Ted"
string = 'My name is ' + name
print string

Monday, 7 May 2012

Quick look back at mod_python

 mod_python was depreciated

The Apache Software Foundation June board meeting, which took place on June 16, 2010, unanimously passed a resolution to terminate Apache Quetzalcoatl Project (umbrella project for mod_python)

mod_python in effect was superceded by mod_wsgi
(an alternative Apache module for running Python web applications) also offers a daemon mode that is more secure and easier handled for a non-root webhosting user.

Web Server Gateway Interface (wsgi)

Werkzeug The Python WSGI Utility Library
Flask is a microframework for Python based on Werkzeug, Jinja 2
WebOb WSGI request and response objects

Tutorials
Release 3.3.1
January 29, 2007

"Currently mod_python is not under active development.
The code and the project are mature enough that very little is required to maintain it". Gregory Trubetskoy
Note: to get help with installation and other issues is the mod python mailing list.  ... by sending an e-mail with the word ‘subscribe’ in the subject to
mod python-request@modpython.org


"a bug in mod_python was exposed by some changes to the Apache runtime library and since no mod_python release has been made since then, only option was for distributions to patch it themselves. "


Saturday, 5 May 2012

Interactive Python 2.5



Looking forward to this web site/tool

Python Essential Reference




"concise reference of
 Python" v2.6 & 3  717 pages
 preview






Feb 2006  3rd Edition  Python 2.4  625 pages













June 2001  2nd Edition  Python 2.1






















1st Edition  300 pages

Python in 10 minutes


I might be a bit skeptical about time estimates for deliveries on their development quotes.

Web Site .. Python in 10 minutes

A quick read,
a cheatsheet?

Having read the web page, in theory,  I've already spent too much time on it.

 BeginnersGuide Programmers
Website

Let's see
Download & Install any Python
 ... then
Study documentation and internet tutorials
Type in examples
repeat several hundred times.

Friday, 4 May 2012

KeepNote 0.7.8



    This page was first created in KeepNote then the html code was cut and pasted into this Blogger.


What is KeepNote 

  KeepNote is a note taking application that works on Windows, Linux, and MacOS X. With KeepNote, you can store your class notes, TODO lists, research notes, journal entries, paper outlines, etc in a simple notebook hierarchy with rich-text formatting, images, and more. Using full-text search, you can retrieve any note for later reference.

 KeepNote is designed to be cross-platform (implemented in Python and PyGTK) and stores your notes in simple and easy to manipulate file formats (HTML and XML). Archiving and transferring your notes is as easy as zipping or copying a folder.

  To make this post. Downloaded KeepNote Windows installer. Even though the application is written in Python
the Window install is seamless.

 To hold this app's 'notebooks' created C:\Keepers

 File menu item
   New Notebook

etc.


The program may not have been designed to edit Blogger pages but it seems to work.

I really like the integrated Python prompt.
In case you can't read the screen captures, I typed in 5 lines of codes and then executed them as a group.

Very neat.

Looks like this program is a keeper.