Skip to main content

Home/ Python Programming/ Group items tagged try

Rss Feed Group items tagged

reckoner reckoner

Cross platform way of finding number of processors on a machine? - comp.lang.python | G... - 0 views

  • > Is there a way to find the number of processors on a machine (on linux/ > windows/macos/cygwin) using python code (using the same code/cross > platform code)? From processing <http://cheeseshop.python.org/pypi/processing/0.34> : def cpuCount():     '''     Returns the number of CPUs in the system     '''     if sys.platform == 'win32':         try:             num = int(os.environ['NUMBER_OF_PROCESSORS'])         except (ValueError, KeyError):             pass     elif sys.platform == 'darwin':         try:             num = int(os.popen('sysctl -n hw.ncpu').read())         except ValueError:             pass     else:         try:             num = os.sysconf('SC_NPROCESSORS_ONLN')         except (ValueError, OSError, AttributeError):             pass     if num >= 1:         return num     else:         raise NotImplementedError --
reckoner reckoner

SWIG problems with gcc and Cygwin? - 0 views

  • try $ gcc -I/usr/include/python2.4 -L/lib/python2.4/config --shared example.c example_wrap.c -lpython2.4 -o _example.dll
reckoner reckoner

Preexisting code indentation - Vim Tips Wiki - a Wikia wiki - 0 views

  • lternative: if your file has indent 4 and you want an indent of 3 and gg=G is not working as expected, try :set inde=indent(v:lnum)/4*3 then go ahead with the well known gg=G use tabs or spaces, doesn't matter
reckoner reckoner

Allen's Weblog: PyMeta: How and Why - 0 views

  • One of the main difficulties I've had using parser generators has been the difficulty of figuring out why a grammar didn't work. Fixing shift-reduce and reduce-reduce conflicts seemed like voodoo to me, and though I slightly understand better how to fix such things now it's still a different mode of thinking that I don't want to try to get into when I just want to parse something simple. PyMeta uses a variation on the Parsing Expression Grammar (PEG) approach to parsing. The chief consequence of this is there's no possibility of ambiguity in a parse: a successful parse will yield exactly one result, and you can trace the control flow through the grammar to figure out how it got there.
reckoner reckoner

Kill process based on window name (win32) - 0 views

  • Re: Kill process based on window name (win32) Thank you Roger. Your advice did the trick. For anyone interested, the basic code to terminate a process (politely) would be something like this (hwnd is retrieved using win32gui.EnumerateWindows): # Get the window's process id's t, p = win32process.GetWindowThreadProcessId(hwnd) # Ask window nicely to close win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) # Allow some time for app to close time.sleep(10) # If app didn't close, force close try: handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, p) if handle: win32api.TerminateProcess(handle,0) win32api.CloseHandle(handle) except: pass:
reckoner reckoner

PyCha - Trac - 0 views

  • Pycha is a very simple Python package for drawing charts using the great Cairo library. Its goals are: Lightweight Simple to use Nice looking with default values Customization It won't try to draw any possible chart on earth but draw the most common ones nicely. There are some other options you may want to look at like pyCairoChart Pycha is based on Plotr which is based on PlotKit. Both libraries are written in JavaScript and are great for client web programming. I needed the same for the server side so that's the reason I ported Plotr to Python. Now we can deliver charts to people with JavaScript disabled or embed them in PDF reports.
reckoner reckoner

[IPython-user] setting breakpoints in code - 0 views

  • Robin, Give this a try: from IPython.Debugger import Tracer; debugger = Tracer() debugger() #add this line where you want to break barr
reckoner reckoner

Voice recognition - 0 views

  • Speech Recognition may be possible with COM. I found an example of how its done in Python.
  • Looks like foom is busy. Anyway, here is the verbatim translation of the script foom linked. I can't test it myself as no mike is installed on my machine. If you hear "Starting Succeeded", then, try to say one/two/three. NEED CoHelper.ahk.
reckoner reckoner

python_match.vim - Extend the % motion and define g%, [%, and ]% motions for Python fil... - 0 views

  •  
    This script redefines the % motion so that (in addition to its usual behavior) it cycles through if/elif/else, try/except/catch, for/continue/break, and while/continue/break structures. The script also defines g% to cycle in the opposite direction. Two ot
reckoner reckoner

Charming Python: Functional programming in Python, Part 1 - 0 views

  • Document options Document options requiring JavaScript are not displayed Rate this pageHelp us improve this contentLevel: IntroductoryDavid Mertz (mertz@gnosis.cx), Applied Metaphysician, Gnosis Software, Inc. 01 Mar 2001Although users usually think of Python as a procedural and object-oriented language, it actually contains everything you need for a completely functional approach to programming. This article discusses general concepts of functional programming, and illustrates ways of implementing functional techniques in Python. We'd better start with the hardest question: "What is functional programming (FP), anyway?" One answer would be to say that FP is what you do when you program in languages like Lisp, Scheme, Haskell, ML, OCAML, Clean, Mercury, or Erlang (or a few others). That is a safe answer, but not one that clarifies very much. Unfortunately, it is hard to get a consistent opinion on just what FP is, even from functional programmers themselves. A story about elephants and blind men seems apropos here. It is also safe to contrast FP with "imperative programming" (what you do in languages like C, Pascal, C++, Java, Perl, Awk, TCL, and most others, at least for the most part).
dshekhar17

Python Multiple Exception Handling (Try-Except) | Hack The Developer - 0 views

  •  
    Multiple Exception Handling in Python
anonymous

Intermediate and Advanced Software Carpentry in Python - 4 views

  • try: import psyco psyco.full() except ImportError: pass
  • >>> def simple_cache(fn): ... cache = {} ... ... def new_fn(n): ... if n in cache: ... print 'FOUND IN CACHE; RETURNING' ... return cache[n] ... ... # otherwise, call function & record value ... val = fn(n) ... cache[n] = val ... return val ... ... return new_fn
1 - 13 of 13
Showing 20 items per page