Difference between revisions of "Programming:Python"

From WhyAskWhy.org Wiki
Jump to: navigation, search
(Copy/paste & minor edits)
 
m (Cleaned up content (formatting mostly) and included link at the top of page for subpages.)
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
[[Category:Python]]
 
[[Category:Python]]
 
[[Category:Tips]]
 
[[Category:Tips]]
 +
[[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 =====
+
* [http://www.python.org/dev/peps/pep-0008/ PEP 8 - Style Guide for Python Code, Official Python Style Guide]
 
+
* [http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html Code Like a Pythonista: Idiomatic Python]
==== Default Arguments ====
+
* [http://gfesuite.noaa.gov/developer/PythonCodingStandards.html Python Coding Guidelines]
 
+
* [http://www.voidspace.org.uk/python/articles/python_style_guide.shtml Python Coding Style & Standards]
=== 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>
+
=== 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]
  
<pre>
+
=== Not directly related, but useful ===
def f(a, L=[]):
 
    L.append(a)
 
    return L
 
  
print f(1)
+
* [http://sqlite.org/ SQLite]
print f(2)
 
print f(3)
 
</pre>
 
  
This will print:
+
=== Windows specific ===
  
<pre>[1]
+
* [http://python.net/crew/mhammond/win32/Downloads.html Python Win32 Extensions] - Win32api, COM, etc.
[1, 2]
+
** [https://sourceforge.net/projects/pywin32/|SourceForge.net project page]
[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>
+
=== Books ===
def f(a, L=None):
 
    if L is None:
 
        L = []
 
    L.append(a)
 
    return L
 
</pre>
 
  
=== Mutable defaults trap ===
+
====Current ====
  
From: [http://www.ferg.org/projects/python_gotchas.html#contents_item_6 Python Gotchas, Mutable defaults for function/method arguments]
+
* [http://www.informit.com/store/product.aspx?isbn=0132269937 Core Python Programming]
 +
** [http://corepython.com/|Errata, Support, Info]
  
<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>
+
==== 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>
  
===== Misc References =====
+
<references />
  
==== Tips/Tricks ====
 
  
==== Style ====
+
=== IDEs and Compilers ===
 
 
* [http://www.python.org/dev/peps/pep-0008/ PEP 8 - Style Guide for Python Code, Official Python Style Guide]
 
* [http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html Code Like a Pythonista: Idiomatic Python]
 
* [http://gfesuite.noaa.gov/developer/PythonCodingStandards.html Python Coding Guidelines]
 
* [http://www.voidspace.org.uk/python/articles/python_style_guide.shtml Python Coding Style & Standards]
 
  
==== Gotchas ====
+
''The descriptions are borrowed from the tool websites''
  
  * Python Gotchas ([[http://www.ferg.org/projects/python_gotchas.html|Here]] or [[http://pythonconquerstheuniverse.wordpress.com/2008/06/04/python-gotchas/|here]])
+
* [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://zephyrfalcon.org/labs/python_pitfalls.html|Python Pitfalls]]
 
  * [[http://onlamp.com/pub/a/python/2004/02/05/learn_python.html|When Pythons Attack]]
 

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.