[[python]]
 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

python [2012/02/05 02:37]
dblume
python [2013/03/13 21:52] (current)
dblume
Line 1: Line 1:
-====== Python ====== +{{indexmenu>.:python|js}}
- +
-Man, there's too much to do and note.  Logging some stuff to investigate later... +
- +
-  * [[http://pycon.blogspot.com/2011/12/announcing-pycon-2012-tutorials.html|2011 PyCon tutorials announcement]] further details at the [[https://us.pycon.org/2012/schedule/lists/tutorials/|tutorial list]]. +
-  * They mention using [[http://ipython.org/|IPython]] enhanced shell.  Hmm. +
-  * [[http://pytools.codeplex.com/releases/view/76089|Python Tools for Visual Studio 2010]]. +
-  * [[http://wiki.python.org/moin/PythonSpeed/PerformanceTips|Python Performance Tips at the Python wiki]]. +
-  * Of course, there's getting Python running under Xampp. [[xampp]] +
-  * There's [[http://www.infoworld.com/d/application-development/pillars-python-six-python-web-frameworks-compared-169442|A comparison of CubicWeb, Django, Pyramid, Web.py, Web2py, and Zope 2]] +
- +
-===== Template Files to Start With ===== +
- +
-You have some template files in svn: +
- +
-<code> +
-/Code/python_templates/trunk/make_standalone_application.bat +
-/Code/python_templates/trunk/setup.py +
-/Code/python_templates/trunk/template_cron_job.py +
-/Code/python_templates/trunk/template_gui_app.py +
-/Code/python_templates/trunk/template_gui_app_with_worker_thread.py +
-</code> +
- +
-===== Linux or Bash Tips ===== +
- +
-Useful bash command for finding strings within python files... +
- +
-<code bash> +
-find . -name \*.py -print0 | xargs -0 grep -nI "timeit" +
-</code> +
- +
-Interesting way to use ''grep -v'' to remove paths from a list generated by ''find''.  Not sure about the escaped ''|'' character, though... +
- +
-<code bash> +
-#!/bin/bash +
-find $PWD -regex ".*\.[hcHC]\(pp\|xx\)?" | grep -v " \|unwantedpath/unwantedpath2\|unwantedpath3" > cscope.files +
-cscope -q -b +
-</code> +
- +
-And this one has nothing to do with Python.  Here's how to find if a symbol is in a library... +
- +
-<code bash> +
-nm obj-directory/libmyobject.a | c++filt | grep Initialize_my_obj +
-</code> +
-===== For / Else (Nobreak) ===== +
- +
-Python has a [[http://nedbatchelder.com/blog/201110/forelse.html|For/Else keyword]] that should have been called, "nobreak." +
- +
-===== Sorting ===== +
- +
-From an old [[http://dblume.livejournal.com/28319.html|note-to-self]]... +
-<code python+
-import operator +
- +
-rows.sort(key=operator.itemgetter(4)) +
-# or +
-rows.sort(lambda x, y : x[4] == y[4] and cmp(x[2],y[2]) or cmp(x[4], y[4])) +
-</code> +
- +
-...not like I could just find the same info at the [[http://wiki.python.org/moin/HowTo/Sorting|Python wiki]] or anything. :-P +
- +
-===== Prepopulating lists with objects ===== +
- +
-Remember when you lost a couple of hours thinking that the following line created a list of objects. +
- +
-<code python> +
-    l = [Obj()] * n +
-</code> +
- +
-It doesn't. It creates a list of references to one object. +
- +
-What you meant to write was this: +
- +
-<code python> +
-    l = [Obj() for _ in range(n)] +
-</code> +
- +
-===== Linux script that takes either stdin or files ===== +
- +
-<code python> +
-if __name__=='__main__': +
-    if len(sys.argv) < 2: +
-        # Process lines coming from stdin. +
-        while 1: +
-            line = sys.stdin.readline() +
-            if not line: +
-                break +
-            my_process_line( line.rstrip() ) +
-    else: +
-        # Process lines of the files specified. +
-        for fname in sys.argv[1:]: +
-            if not os.path.exists( fname ): +
-                treat_argument_as_literal( fname ) +
-                continue +
-            with open( fname, 'r' ) as f: +
-                while 1: +
-                    line = f.readline() +
-                    if not line: +
-                        break +
-                    my_process_line( line.rstrip() ) +
-</code> +
- +
-===== The With statement ===== +
- +
-[[http://amix.dk/blog/post/19663#Making-ugly-code-more-beautiful-using-Pythons-with-statement|Making code more beautiful with "with"]].  (Also mentions yield.) +
- +
-===== timeit ===== +
- +
-<code python> +
-import timeit +
- +
-def Use_a(): +
-    pass +
- +
-def Use_b(): +
-    pass +
- +
-def Run_all_tests(): +
-    my_setup() +
-    Use_a() +
-    Use_b() +
- +
-if __name__ == '__main__': +
- +
-#    t = timeit.timeit( 'Run_all_tests()', 'from __main__ import Run_all_tests', number=1 ) +
-#    print dir( t ) +
-#    print t +
- +
-    t = timeit.Timer( 'Run_all_tests()', 'from __main__ import Run_all_tests' ) +
-    print t.timeit() +
-</code> +
- +
-====== TODO ====== +
-TODO Link to my tips from LiveJournal and GMail, and why I chose which timing modules.+
python.1328438248.txt.gz · Last modified: 2012/02/05 02:37 by dblume
 
Recent changes RSS feed Driven by DokuWiki