Skip to main content

Home/ Python Programming/ Group items tagged cookbook

Rss Feed Group items tagged

jgomezdans

PLEAC-Python - 0 views

  •  
    Following the Perl Cookbook (by Tom Christiansen and Nathan Torkington, published by O'Reilly) spirit, the PLEAC Project aims to gather fans of programming, in order to implement the solutions in other programming languages. In this document, you'll find an implementation of the Solutions of the Perl Cookbook in the Python language.
reckoner reckoner

Louie - 0 views

  • Louie provides Python programmers with a straightforward way to dispatch signals between objects in a wide variety of contexts. It is based on PyDispatcher, which in turn was based on a highly-rated recipe in the Python Cookbook. Louie is licensed under The BSD License.
reckoner reckoner

ASPN : Python Cookbook : Permutation and Combination Enumerator - 0 views

  • def comb(items, n=None): if n is None: n = len(items) for i in range(len(items)): v = items[i:i+1] if n == 1: yield v else: rest = items[i+1:] for c in comb(rest, n-1): yield v + c
  • def perm(items, n=None): if n is None: n = len(items) for i in range(len(items)): v = items[i:i+1] if n == 1: yield v else: rest = items[:i] + items[i+1:] for p in perm(rest, n-1): yield v + p
  • Permutation and Combination Enumerator
reckoner reckoner

ASPN : Python Cookbook : SendKeys from the Windows Script Host (WSH) COM - 0 views

  • import win32api import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.Run("calc") win32api.Sleep(100) shell.AppActivate("Calculator") win32api.Sleep(100) shell.SendKeys("1{+}") win32api.Sleep(500) shell.SendKeys("2") win32api.Sleep(500) shell.SendKeys("~") # ~ is the same as {ENTER} win32api.Sleep(500) shell.SendKeys("*3") win32api.Sleep(500) shell.SendKeys("~") win32api.Sleep(2500)
reckoner reckoner

Python Cookbook : Read tabular data from Excel spreadsheets the fast and easy way - 0 views

  • Sometimes you get an Excel spreadsheet (say, from the marketing departement) and you want to read tabular data from it (i.e. a line with column headers and lines of data). There are many ways to do this (including ODBC + mxODBC), but the easiest way I've found is this one : provide a file name and a sheet name, and read the data !
Bruno Piguet

Cookbook/FittingData - - 0 views

    • Bruno Piguet
       
      difference between fitfunc = lambda p, x: p[0]*cos(2*pi/p[1]*x+p[2]) + p[3]*x and def fitfunc (p, x): p[0]*cos(2*pi/p[1]*x+p[2]) + p[3]*x ???
reckoner reckoner

Python Idioms and Efficiency Suggestions - 0 views

  • What idioms should I use to make my code easier to read? Read "The Python Cookbook", especially the first few chapters. It's a great source of well-written Python code examples.
  • Use function factories to create utility functions. Often, especially if you're using map and filter a lot, you need utility functions that convert other functions or methods to taking a single parameter. In particular, you often want to bind some data to the function once, and then apply it repeatedly to different objects. In the above example, we needed a function that multiplied a particular field of an object by 3, but what we really want is a factory that's able to return for any field name and amount a multiplier function in that family:
  • Use zip and dict to map fields to names. zip turns a pair of sequences into a list of tuples containing the first, second, etc. values from each sequence. For example, zip('abc', [1,2,3]) == [('a',1),('b',2),('c',3)]. You can use this to save a lot of typing when you have fields in a known order that you want to map to names:
  •  
    suggestions for better programming style.
1 - 12 of 12
Showing 20 items per page