Difference between revisions of "Programming:Python"

From WhyAskWhy.org Wiki
Jump to: navigation, search
m (Deoren moved page Python to Programming:Python without leaving a redirect)
m (Cleaned up content (formatting mostly) and included link at the top of page for subpages.)
 
Line 4: Line 4:
 
[[Category:NeedsCleanup]]
 
[[Category:NeedsCleanup]]
  
====== My notes on Python ======
+
== Subpages ==
  
===== Module Structure and Layout =====
+
{{Special:PrefixIndex/Programming:Python/}}
  
From [http://cpp.wesc.webfactional.com/ Core Python Programming ], 2E (3.4.1)
 
  
# Startup line (Unix)
+
== Online Resources ==
# module documentation
+
''Various resources in no particular order (I'll eventually organize them)''
# module imports
 
# variable declarations (Global)
 
# class declarations
 
# function declarations
 
# "main" body
 
  
===== Generating GUIDs =====
+
* [http://www.python.org/|Python Homepage]
 +
* [[wikipedia:Python_(programming_language)]]
 +
* [http://rgruet.free.fr/ Richard Gruet's Python page] - Python Quick Reference, modules, etc.
 +
* [http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html When Pythons Attack, Common Mistakes of Python Programmers]
 +
* [http://oss.itsystementwicklung.de/download/pysqlite/doc/index.html pysqlite's documentation]
 +
* [http://oss.itsystementwicklung.de/trac/pysqlite/ The pysqlite wiki]
 +
* [http://www.employees.org/~donn/python/ Donn Lee's Python Cookbook]
 +
* [http://www.doughellmann.com/PyMOTW/ Python Module of the Week] - tour of the Python standard library through short examples.
  
<pre>
+
=== Style ===
  import uuid
 
  uuid.uuid4()
 
</pre>
 
 
 
===== Functions =====
 
 
 
==== Default Arguments ====
 
 
 
=== Evaluated only once ===
 
 
 
From the [[http://docs.python.org/tutorial/controlflow.html#default-argument-values|official Python documentation]]:
 
 
 
<blockquote>'''Important warning''': The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes. For example, the following function accumulates the arguments passed to it on subsequent calls:</blockquote>
 
 
 
 
 
<pre>
 
def f(a, L=[]):
 
    L.append(a)
 
    return L
 
 
 
print f(1)
 
print f(2)
 
print f(3)
 
</pre>
 
 
 
This will print:
 
 
 
<pre>[1]
 
[1, 2]
 
[1, 2, 3]
 
</pre>
 
 
 
If you don’t want the default to be shared between subsequent calls, you can write the function like this instead:
 
 
 
<pre>
 
def f(a, L=None):
 
    if L is None:
 
        L = []
 
    L.append(a)
 
    return L
 
</pre>
 
 
 
=== Mutable defaults trap ===
 
 
 
From: [http://www.ferg.org/projects/python_gotchas.html#contents_item_6 Python Gotchas, Mutable defaults for function/method arguments]
 
 
 
<blockquote>You should never, never, NEVER use a list or a dictionary as a default value for an argument to a class method. Unless, of course, you really, really, REALLY know what you're doing</blockquote>
 
 
 
 
 
===== Misc References =====
 
 
 
==== Tips/Tricks ====
 
 
 
==== Style ====
 
  
 
* [http://www.python.org/dev/peps/pep-0008/ PEP 8 - Style Guide for Python Code, Official Python Style Guide]
 
* [http://www.python.org/dev/peps/pep-0008/ PEP 8 - Style Guide for Python Code, Official Python Style Guide]
Line 81: Line 28:
 
* [http://www.voidspace.org.uk/python/articles/python_style_guide.shtml Python Coding Style & Standards]
 
* [http://www.voidspace.org.uk/python/articles/python_style_guide.shtml Python Coding Style & Standards]
  
==== Gotchas ====
+
=== Gotchas ===
 
 
  * Python Gotchas ([[http://www.ferg.org/projects/python_gotchas.html|Here]] or [[http://pythonconquerstheuniverse.wordpress.com/2008/06/04/python-gotchas/|here]])
 
  * [[http://zephyrfalcon.org/labs/python_pitfalls.html|Python Pitfalls]]
 
  * [[http://onlamp.com/pub/a/python/2004/02/05/learn_python.html|When Pythons Attack]]
 
 
 
 
 
===== Online Resources =====
 
//Various resources in no particular order (I'll eventually organize them)//
 
 
 
  * [[http://www.python.org/|Python Homepage]]
 
  * [[wp>Python_(programming_language)|Python Wikipedia entry]]
 
  * [[http://rgruet.free.fr/|Richard Gruet's Python page]] - Python Quick Reference, modules, etc.
 
  * [[http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html|When Pythons Attack, Common Mistakes of Python Programmers]]
 
  * [[http://oss.itsystementwicklung.de/download/pysqlite/doc/index.html|pysqlite's documentation]]
 
  * [[http://oss.itsystementwicklung.de/trac/pysqlite/|The pysqlite wiki]]
 
  * [[http://www.employees.org/~donn/python/|Donn Lee's Python Cookbook]]
 
  * [[http://www.doughellmann.com/PyMOTW/|Python Module of the Week]] - tour of the Python standard library through short examples.
 
  
==== Not directly related, but useful ====
+
* Python Gotchas ([http://www.ferg.org/projects/python_gotchas.html Here] or [http://pythonconquerstheuniverse.wordpress.com/2008/06/04/python-gotchas/ here])
 +
* [http://zephyrfalcon.org/labs/python_pitfalls.html Python Pitfalls]
 +
* [http://onlamp.com/pub/a/python/2004/02/05/learn_python.html When Pythons Attack]
  
  * [[http://sqlite.org/|SQLite]]
+
=== Not directly related, but useful ===
  
==== Windows specific ====
+
* [http://sqlite.org/ SQLite]
  
  * [[http://python.net/crew/mhammond/win32/Downloads.html|Python Win32 Extensions]] - Win32api, COM, etc.
+
=== Windows specific ===
    * [[https://sourceforge.net/projects/pywin32/|SourceForge.net project page]]
 
  
 
+
* [http://python.net/crew/mhammond/win32/Downloads.html Python Win32 Extensions] - Win32api, COM, etc.
==== Forums ====
+
** [https://sourceforge.net/projects/pywin32/|SourceForge.net project page]
 
 
 
 
 
 
===== Books =====
 
  
  
 +
=== Books ===
  
 
====Current ====
 
====Current ====
  
  * [[amazon>0132269937|Core Python Programming]]
+
* [http://www.informit.com/store/product.aspx?isbn=0132269937 Core Python Programming]
    * [[http://corepython.com/|Errata, Support, Info]]
+
** [http://corepython.com/|Errata, Support, Info]
 
 
 
 
====Queued ====
 
 
 
  * Most of the Python books listed [[books:ebooks:mycollection|here]].
 
 
 
  * [[http://inventwithpython.com/|Invent Your Own Computer Games with Python]] ((Free, Open Source book/ebook))
 
  
 +
==== Queued ====
  
 +
* Most of the Python books listed [[Books:EBooks/Collection|here]].
 +
* [http://inventwithpython.com/ Invent Your Own Computer Games with Python] <ref>Free, Open Source book/ebook</ref>
  
 +
<references />
  
  
===== IDEs and Compilers =====
+
=== IDEs and Compilers ===
//The descriptions are borrowed from the tool websites//
 
  
 +
''The descriptions are borrowed from the tool websites''
  
  * [[http://code.google.com/p/pyscripter/|pyscripter]] is a free and open-source Python Integrated Development Environment (IDE) created with the ambition to become competitive in functionality with commercial Windows-based IDEs available for other languages
+
* [http://code.google.com/p/pyscripter/ pyscripter] is a free and open-source Python Integrated Development Environment (IDE) created with the ambition to become competitive in functionality with commercial Windows-based IDEs available for other languages.

Latest revision as of 16:42, 8 July 2012


Subpages


Online Resources

Various resources in no particular order (I'll eventually organize them)

Style

Gotchas

Not directly related, but useful

Windows specific


Books

Current

Queued

  1. Free, Open Source book/ebook


IDEs and Compilers

The descriptions are borrowed from the tool websites

  • pyscripter is a free and open-source Python Integrated Development Environment (IDE) created with the ambition to become competitive in functionality with commercial Windows-based IDEs available for other languages.