Re: Ideas for a module to process command line arguments
On Jan 12, 6:09 pm, Alice Bevan–McGregor wrote: > entirely sure what you mean by 'smart' options. If your'e referring to > using a single hyphen and a list of characters to represent a long > option (which, to the rest of the world, use two leading hyphens) then > that's pretty weird. ;) > > One major system in the world that doesn't really differentiate between > long and short options is... DOS, and by extension, Windows. But they > also use / as a switch character. Yes, and plac (it is argparse actually) can accomodate the Windows convention by setting the prefix_chars to "/". I wanted to be able to give that freedom even if personally am more used to the GNU double-dash convention. > Anyway; I'm happy with what I have wrought (and am continuing to update > with support for class-based sub-command dispatch) and will be > utilizing it for all scripts in the Marrow suite. To each their own, > but reinvention itself can be for motivations other than NIH. I wanted > something pure-Python, portable across the 3k barrier without code > modification (no 2to3), that didn't use optparse, getopt, or argparse > and basically be a translation layer. It can be simpler than that, as > marrow.script demonstrates. No arguing against that. BTW, I was not criticizing marrow.script, I was simply deploring the situation in the standard library. If the same approach for parsing command-line options is being reinvented by different people multiple times there must be something wrong with the current standard. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to populate all possible hierarchical clusterings from a set of elements?
lst = [1, 2, 3, 4, 5] def maketup(lst): cur_item = lst[-1] lst = lst[:-1] if len(lst): return maketup(lst), cur_item else: return cur_item print maketup(lst) 1, 2), 3), 4), 5) But I'm confused as to what you mean by : > Among them, I want to pair up terminals until there is only one left > at the end. One what? one pair?, one terminal meaning one number? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to populate all possible hierarchical clusterings from a set of elements?
def maketup(lst): if len(lst) == 1: return lst[0] elif len(lst) == 2: return (lst[0],lst[1]) elif len(lst) > 2: return ( (maketup(lst[:-2]), lst[-2]), lst[-1]) maketup(lst) 1, 2), 3), 4), 5) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to populate all possible hierarchical clusterings from a set of elements?
justin writes: > Suppose I have [1,2,3,4,5], then there are many ways of making > clustering. > Among them, I want to pair up terminals until there is only one left > at the end. Are you trying "ascending hierarchical clustering" by any chance? In that case you're supposed to use some kind of distance to select the (unique) pair of elements to merge at each step. > For example, 1,2),3),4),5), (1,(2,(3,(4,5, or (((1,2),(3,4)), > 5) would be legitimate ones. > > How do you think can I, using the modules of Python such as itertools > as much as possible, make all possible such clusterings? I don't know about itertools, but the basic idea is: def clusterings(l): if len(l) == 1: print repr(l) else: n = len(l) for i in xrange(n): for j in xrange(i+1,n): clusterings(l[:i]+l[i+1:j]+l[j+1:]+[[l[i],l[j]]]) Test this with: import sys clusterings([i for i in xrange(int(sys.argv[1]))]) Do you realize there are *many* such clusterings? (the exact number should be (n!)*((n-1)!)/2^(n-1) given the code above, if I'm not mistaken.) -- Alain. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to populate all possible hierarchical clusterings from a set of elements?
DevPlayer writes: > def maketup(lst): > > if len(lst) == 1: > return lst[0] > > elif len(lst) == 2: > return (lst[0],lst[1]) > > elif len(lst) > 2: > return ( (maketup(lst[:-2]), lst[-2]), lst[-1]) The OP wants all binary trees over the elements, not just one. -- Alain. -- http://mail.python.org/mailman/listinfo/python-list
File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
Hello! I wrote a python (2.6) deamon running on linux. Program (deamon, manager) collects lets say work-orders from db and creates sub- processes for each one. Sub-processes do their job with out problems, errors, exceptions. However, sometimes deamon throws: Traceback (most recent call last): File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "/usr/lib/python2.6/multiprocessing/util.py", line 281, in _exit_function p.join() File "/usr/lib/python2.6/multiprocessing/process.py", line 119, in join res = self._popen.wait(timeout) File "/usr/lib/python2.6/multiprocessing/forking.py", line 117, in wait return self.poll(0) File "/usr/lib/python2.6/multiprocessing/forking.py", line 106, in poll pid, sts = os.waitpid(self.pid, flag) OSError: [Errno 4] Interrupted system call the main deamon process crushes (after some time) and the sub- processes (childs) work fine until their work is finished. below sample code that is responsible for creating sub_processes : #!/usr/bin/python2.6 import pwd import os import sys import time import multiprocessing import signal import traceback from deamon import deamon from post import post class manager(deamon): def __run_subprocess(self, typ, work_order): def runrun(t, z): self.__info('creating object post for %s' %(z)) wns = post(z) self.__info('done creating object post for %s' %(z)) #slownik z choiceem opcji choice = {'typ1': wns.typ1, 'typ2': wns.typ2, 'typ3': wns.typ3} if typ in choice: self.__info('lounching %s for %s' %(t, z)) choice[typ]() else: self.__blad('nie znam %s typu operacji post, znam tylko %s' \ %(t, str(choice))) wns.endit() del(wns) self.__blad('problem with starting proces for =%s, typ= %s' %(z, t)) try: p = multiprocessing.Process(target=runrun, args=(typ,work_order)) self.__info('done preparing proces...') p.start() self.__info('done lounching process...doing join...') p.join() return p.pid except Exception, err: ex = sys.exc_info() sys.stderr.write(str(sys.exc_info())) msg = 'manager.__run_subprocess %s error in line %s' sys.stderr.write(msg %(str(err), ex[2].tb_lineno)) #traceback.print_last() return None def __liczba_wierszy(self, active_child): return int(self._deamon__liczba_proces - active_child) def run(self): try: while True: active_child = len(multiprocessing.active_children()) #czy liczba pod-procesow <= liczba mozliwych pod- procesow if active_child <= self._deamon__liczba_proces: lista_zlecen = self._deamon__baza.get_work( self.__liczba_wierszy(active_child)) if len(lista_zlecen) > 0: for work_order in lista_zlecen: self.__info('start %s' %(work_order)) pid = self.__run_subprocess('typ1',work_order) self.__info('end %s %s' %(work_order, str(pid))) time.sleep(self._deamon__sleep) elif active_child == self.__liczba_proces: msg = 'number of processes %i is equal to maximum %i, '\ 'going sleep for %i seconds' %( active_child, self.__liczba_proces, self._deamon__sleep) self.__info(msg) time.sleep(self._deamon__sleep) else: self.__info('nothing to do... going sleep for %i seconds' %(self._deamon__liczba_proces)) #self._deamon__baza.zamknij_polacznie() time.sleep(self._deamon__sleep) except Exception, err: ei = sys.exc_info() msg = 'manager.run %s\n' %(str(err)) sys.stderr.write('error in line %s\n' % (str(ei[2].tb_lineno))) sys.stderr.write(msg) def receive_sygnal(self, signum, stack): if signum == 10: #print 'otrzymalem sygnal', signum self.__zapisz_status() elif signum == 12: self.__info('cheking if there are any active sub- processes') while len(multiprocessing.active_children()) > 0: self.__info('liczba podprocesow > 0, ide spac na 10 sekund') time.sleep(10) else: print 'got unknown signal', signum -- http://mail.python.org/mailman/listinfo/python-list
Re: How to populate all possible hierarchical clusterings from a set of elements?
tuple([ (tuple(lst[x-1:x+1]) if len(tuple(lst[x-1:x+1]))==2 else lst[x-1]) for x in lst[::2]]) ((1, 2), (3, 4), 5) # or x = ((tuple(lst[x-1:x+1]) if len(tuple(lst[x-1:x+1]))==2 else lst[x-1]) for x in lst[::2]) x.next() (1, 2) x.next() (3, 4) x.next() 5 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to populate all possible hierarchical clusterings from a set of elements?
Ah. out of my depth. -- http://mail.python.org/mailman/listinfo/python-list
Re: cipher encoding
> Dear all, > > I hope someone out there can help me. > > The output string of my code is close to what i need, but i need it > 1)printed on one line and > 2) reversed > > #mycode: > s= input("Enter message: ") > key=1 > for letter in s: > num=(chr(ord(letter)+1)) > print(num) > #or is there a better way to rewrite it with elementary level Python, > which happens 2b my current ranking. > #Your insight is always appreciated:) If you want it on one line the simplest thing would be to have it in one string: num='' for letter in s: num+=chr(ord(letter)+1) print num[::-1] But if you don't want it that way you can simply write print num, in your original code. The comma suppresses '\n' at the end of print. Only you have to feed letters to the loop in reverse order if you want it reversed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested structures question
Physics Python wrote: Hello, I am teaching myself python using the book: Python Programming for Absolute Beginners, 2nd edition by Michael Dawson. I am using python 2.7.1. In chapter 3 we are learning to use structures (while, if, elif) to write a program that has the user guess a number between 1 and 100. Here is the code for the baseline program: [snip] here is an example of code using a for loop, which is always better than a while loop, when applicable of course. It uses the for... else... statement which is rather strange at first glance but has some uses, it's always good to know it exists. http://paste.pocoo.org/show/319931/ JM -- http://mail.python.org/mailman/listinfo/python-list
Re: How to populate all possible hierarchical clusterings from a set of elements?
On Jan 13, 10:02 am, Alain Ketterlin wrote: > justin writes: > > Suppose I have [1,2,3,4,5], then there are many ways of making > > clustering. > > Among them, I want to pair up terminals until there is only one left > > at the end. > > Are you trying "ascending hierarchical clustering" by any chance? In > that case you're supposed to use some kind of distance to select the > (unique) pair of elements to merge at each step. > > > For example, 1,2),3),4),5), (1,(2,(3,(4,5, or (((1,2),(3,4)), > > 5) would be legitimate ones. > > > How do you think can I, using the modules of Python such as itertools > > as much as possible, make all possible such clusterings? > > I don't know about itertools, but the basic idea is: > > def clusterings(l): > if len(l) == 1: > print repr(l) > else: > n = len(l) > for i in xrange(n): > for j in xrange(i+1,n): > clusterings(l[:i]+l[i+1:j]+l[j+1:]+[[l[i],l[j]]]) > > Test this with: > > import sys > clusterings([i for i in xrange(int(sys.argv[1]))]) > > Do you realize there are *many* such clusterings? (the exact number > should be (n!)*((n-1)!)/2^(n-1) given the code above, if I'm not > mistaken.) > > -- Alain. Actually the number of such "clusterings" is the (n-1)th Catalan number. http://en.wikipedia.org/wiki/Catalan_numbers Chard. -- http://mail.python.org/mailman/listinfo/python-list
Re: Career path - where next?
I would second the recommendation for Django: on LinkedIn, the python jobs postings (there is a Python group there) most often mention Django. I also would second the recommendation to participate in open source projects. I met a couple of days ago with a college sophomore who is a core contributor to the Cappuccino project(cappuccino.org -- warning: not Python ). My employer said, on my relating the pleasant and interesting conversation we had, "he doesn't need to finish college: anyone would hire him." >From a selfish (to you and to me ) perspective, may I suggest the pyjamas >(pyjs.org) project and accompanying visual designer >(http://pyjsglade.sourceforge.net), which brings the GWT widgets to Python, >for desktop and web apps. Selfish to me because I'm porting our VFP framework >to there over the next year or so. To you because, well, you've been spoiled >by having the most productive data-oriented software development framework >available, past or present, for maybe as many years as have I (21 at this >point, started with FoxPro 1.0), and that's the end result at which I'm aiming. Hank -- http://mail.python.org/mailman/listinfo/python-list
Re: How to populate all possible hierarchical clusterings from a set of elements?
Richard Thomas writes: > On Jan 13, 10:02 am, Alain Ketterlin >> def clusterings(l): >> if len(l) == 1: >> print repr(l) >> else: >> n = len(l) >> for i in xrange(n): >> for j in xrange(i+1,n): >> clusterings(l[:i]+l[i+1:j]+l[j+1:]+[[l[i],l[j]]]) >> [...] there are *many* such clusterings? (the exact number should be >> (n!)*((n-1)!)/2^(n-1) given the code above, if I'm not mistaken.) > Actually the number of such "clusterings" is the (n-1)th Catalan > number. > > http://en.wikipedia.org/wiki/Catalan_numbers I don't think Catalan numbers exactly captures this number. As far as I remember (and wikipedia seems to confirm this), Cn is the number of ways you can repeatedly apply a binary operator to a sequence of objects, where sequence means that the objects are ordered, which is not the case here. To use wikipedia's example, C3 is 5 because you can do: ((ab)c)d (a(bc))d (ab)(cd) a((bc)d) a(b(cd)) If we list clusterings we can also have: ((ac)b)d ((ac)d)b (ac)(bd) ... Actually, for each of the 5 "catalan expressions" above, you have 4! valid permutations of the objects (leading to a complete count of n!*C(n-1)). But this leads to many "duplicates", because (ab)(cd) and (cd)(ab) are considered the same. I just realize that the code I've given above also produces duplicates (in particular, the example I've just used). At least, my counting was correct w.r.t. the code :-) The plot thickens... -- Alain. -- http://mail.python.org/mailman/listinfo/python-list
Re: File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
On 1/13/2011 5:28 AM, dzizes451 wrote: Hello! I wrote a python (2.6) deamon running on linux. Program (deamon, manager) collects lets say work-orders from db and creates sub- processes for each one. Sub-processes do their job with out problems, errors, exceptions. However, sometimes deamon throws: Traceback (most recent call last): File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) I would either just try 2.7 or at least examine What's New or even Misc/NEWS in the repository to see if there were changes that affect this. My impression is that there were. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: How to populate all possible hierarchical clusterings from a set of elements?
On Jan 13, 3:59 pm, Alain Ketterlin wrote: > Richard Thomas writes: > > On Jan 13, 10:02 am, Alain Ketterlin > >> def clusterings(l): > >> if len(l) == 1: > >> print repr(l) > >> else: > >> n = len(l) > >> for i in xrange(n): > >> for j in xrange(i+1,n): > >> clusterings(l[:i]+l[i+1:j]+l[j+1:]+[[l[i],l[j]]]) > >> [...] there are *many* such clusterings? (the exact number should be > >> (n!)*((n-1)!)/2^(n-1) given the code above, if I'm not mistaken.) > > Actually the number of such "clusterings" is the (n-1)th Catalan > > number. > > >http://en.wikipedia.org/wiki/Catalan_numbers > > I don't think Catalan numbers exactly captures this number. As far as I > remember (and wikipedia seems to confirm this), Cn is the number of ways > you can repeatedly apply a binary operator to a sequence of objects, > where sequence means that the objects are ordered, which is not the case > here. To use wikipedia's example, C3 is 5 because you can do: > > ((ab)c)d (a(bc))d (ab)(cd) a((bc)d) a(b(cd)) > > If we list clusterings we can also have: > > ((ac)b)d ((ac)d)b (ac)(bd) ... > > Actually, for each of the 5 "catalan expressions" above, you have 4! > valid permutations of the objects (leading to a complete count of > n!*C(n-1)). But this leads to many "duplicates", because (ab)(cd) and > (cd)(ab) are considered the same. > > I just realize that the code I've given above also produces duplicates > (in particular, the example I've just used). At least, my counting was > correct w.r.t. the code :-) The plot thickens... > > -- Alain. Okay, I misunderstood the problem, sorry about that. This makes it rather hard to define a nice recurrence relation for the number of such clusterings: C(1) = 1 C(2n+1) = Sigma(1; n; choose(2n+1, r) * C(r) * C(2n+1-r)) C(2n) = Sigma(1; n-1; choose(2n, r) * C(r) * C(2n-r)) + choose(2n, n) * C(n) * C(n) / 2 See, very ugly. I can't reduce it to anything workable so I just computed it. Clearly its more than exponential. Some values: In [1]: [cluster(n) for n in xrange(1, 21)] Out[1]: [1, 1, 3, 15, 105, 945, 10395, 135135, 2027025, 34459425, 654729075, 13749310575L, 316234143225L, 7905853580625L, 213458046676875L, 6190283353629375L, 191898783962510625L, 6332659870762850625L, 221643095476699771875L, 8200794532637891559375L] Anyway, I'm done counting things for now. Chard. -- http://mail.python.org/mailman/listinfo/python-list
Re: Career path - where next?
Hank Fay wrote: > ... From a selfish (to you and to me ) perspective, may I suggest > the pyjamas (pyjs.org) project and accompanying visual designer > (http://pyjsglade.sourceforge.net), which brings the GWT widgets > to Python, for desktop and web apps. Selfish to me because I'm > porting our VFP framework to there over the next year or so. > To you because, well, you've been spoiled by having the most > productive data-oriented software development framework available, > past or present, for maybe as many years as have I (21 at this point, > started with FoxPro 1.0), and that's the end result at which I'm > aiming. Hank, I have a dbf* package which supports VFP dbf files up to 6, and I would like to implement support for compound index files. So far, I have been unable to locate the algorithms necessary to do so. If you have any information that would help me, I would be very grateful! ~Ethan~ *http://pypi.python.org/pypi/dbf/0.88.16 -- http://mail.python.org/mailman/listinfo/python-list
troubles compiling pythonwebkit
Hello Python enthusiasts, I'm trying to install the "Python Webkit DOM Bindings" (http://www.gnu.org/software/pythonwebkit/) but am not successful. The trouble starts when trying to 'make' pywebkitgtk. I've tried the prepatched version and downloading and patching myself. In both case the 'make' fails but with different errors. Here are the steps I performed and the error output. Thanks for any insight in resolving this problem. :-) I'm running Ubuntu 10.04 32bit sudo apt-get remove python-webkit sudo apt-get install python-dev sudo apt-get install python-ply sudo apt-get install autoconf sudo apt-get install automake sudo apt-get install autotools-dev sudo apt-get install bison sudo apt-get install flex sudo apt-get install gperf sudo apt-get install glib-networking <---E: Couldn't find package glib-networking sudo apt-get install gtk-doc-tools sudo apt-get install libenchant-dev sudo apt-get install libgail-dev sudo apt-get install libgeoclue-dev sudo apt-get install libglib2.0-dev sudo apt-get install libgstreamer-plugins-base0.10-dev sudo apt-get install libgtk2.0-dev sudo apt-get install libicu-dev sudo apt-get install libjpeg62-dev sudo apt-get install libpango1.0-dev sudo apt-get install libpng12-dev sudo apt-get install libsoup2.4-dev sudo apt-get install libsqlite3-dev sudo apt-get install libtool sudo apt-get install libxslt-dev sudo apt-get install libxt-dev sudo apt-get install git-core git clone git://git.savannah.gnu.org/pythonwebkit.git cd pythonwebkit git checkout -b python_codegen sudo mkdir build cd build sudo ../autogen.sh sudo ../configure sudo make sudo make install cd ../.. sudo apt-get install libxslt1-dev sudo apt-get install python-gtk2-dev sudo apt-get install liblogthread-dev git clone git://github.com/lkcl/pywebkitgtk.git cd pywebkitgtk git checkout -b pythonwebkitgtk_1_1_8 sudo ./autogen.sh sudo ./configure sudo make results in the following: make all-am make[1]: Entering directory `/home/david/Downloads/pywebkitgtk' /bin/bash ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I/usr/include/python2.6 -pthread -I/usr/include/libxml2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pygtk-2.0 -pthread -D_REENTRANT -I/usr/local/include/webkit-1.0 -I/usr/local/include/libsoup-2.4 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -I/usr/include/libxml2 -g -O2 -MT webkit/webkit_la-webkitmodule.lo -MD -MP -MF webkit/.deps/webkit_la-webkitmodule.Tpo -c -o webkit/webkit_la-webkitmodule.lo `test -f 'webkit/webkitmodule.c' || echo './'`webkit/webkitmodule.c libtool: compile: gcc -DHAVE_CONFIG_H -I. -I/usr/include/python2.6 -pthread -I/usr/include/libxml2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pygtk-2.0 -pthread -D_REENTRANT -I/usr/local/include/webkit-1.0 -I/usr/local/include/libsoup-2.4 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -I/usr/include/libxml2 -g -O2 -MT webkit/webkit_la-webkitmodule.lo -MD -MP -MF webkit/.deps/webkit_la-webkitmodule.Tpo -c webkit/webkitmodule.c -fPIC -DPIC -o webkit/.libs/webkit_la-webkitmodule.o libtool: compile: gcc -DHAVE_CONFIG_H -I. -I/usr/include/python2.6 -pthread -I/usr/include/libxml2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pygtk-2.0 -pthread -D_REENTRANT -I/usr/local/include/webkit-1.0 -I/usr/local/include/libsoup-2.4 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -I/usr/include/libxml2 -g -O2 -MT webkit/webkit_la-webkitmodule.lo -MD -MP -MF webkit/.deps/webkit_la-webkitmodule.Tpo -c webkit/webkitmodule.c -o webkit/webkit_la-webkitmodule.o >/dev/null 2>&1 mv -f webkit/.deps/webkit_la-webkitmodule.Tpo webkit/.deps/webkit_la-webkitmodule.Plo /bin/bash ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I/usr/include/python2.6 -pthread -I/usr/include/libxml2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pygtk-2.0 -pthread -D_REENTRANT -I/usr/local/include/webkit-1.0 -I/usr/local/include/libsoup-2.4 -I/usr/in
how to use priority queue with multiprocessing
Hey, -- question -- How can I use a priority queue to schedule jobs within the "multiprocessing pool" module? -- my scenario -- I want to run several jobs on a server. The jobs are being sent by users. However, all jobs have a different priority, and high-priority jobs should be processed before any low-priority job gets touched. Currently I just append all incoming jobs to the multiprocessing worker pool as follows: ### initialize worker pool pool= PriorityPool(processes=worker_count) process_handles = [] ### distribute function execution over several processes for job_parameter in job_parameter_list: handle = pool.apply_async(process_function, [job_parameter,]) process_handles.append(handle) This will only put the jobs in some kind of a list - and execute the jobs in the order they come in. Is it possible to use a priority queue for the process-pool? Kind Regards, Marco -- http://mail.python.org/mailman/listinfo/python-list
Re: apscheduler error
In cases like that instead of sleep() can use pause(). E.g., from apscheduler.scheduler import Scheduler import signal sched = Scheduler() sched.start() def some_job(): print "Decorated job" sched.add_interval_job(some_job,minutes=1) signal.pause() Mosalam -- http://mail.python.org/mailman/listinfo/python-list
Re: How to populate all possible hierarchical clusterings from a set of elements?
Peter Otten <__pete...@web.de> writes: > justin wrote: > >> The title sounds too complex, but my question is actually simple. >> >> Suppose I have [1,2,3,4,5], then there are many ways of making >> clustering. >> Among them, I want to pair up terminals until there is only one left >> at the end. >> For example, 1,2),3),4),5), (1,(2,(3,(4,5, or (((1,2),(3,4)), >> 5) would be legitimate ones. >> >> How do you think can I, using the modules of Python such as itertools >> as much as possible, make all possible such clusterings? > > Here's my first attempt: > > def cluster(items): > if len(items) == 2: > yield items > return > > for i in range(len(items)-1): > for c in cluster(items[:i] + (items[i:i+2],) + items[i+2:]): > yield c > > def unique(items): > seen = set() > for item in items: > if item not in seen: > seen.add(item) > yield item > > if __name__ == "__main__": > for item in unique(cluster(tuple("abcd"))): > print item more simply: def clusters(l): if len(l) == 1: yield l[0] return for i in range(1, len(l)): for left in clusters(l[:i]): for right in clusters(l[i:]): yield (left, right) That would give all solutions without duplicates. In fact, this is simply finding all full binary trees which order l. However, somewhere else in the thread someone claims that no ordering is implied on the initial list of items (which is not at all obvious from the OP). -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
python 3 and Unicode line breaking
Hi, Is there an equivalent to the textwrap module that knows about the Unicode line breaking algorithm (UAX #14, http://unicode.org/reports/tr14/ )? -- http://mail.python.org/mailman/listinfo/python-list
GURU NEEDED : break a command into several lines and comment each line
Basically, I have spent a few hours experimenting and searching on the comp.unix.shell how to break a command with several switches into more than one line AND to be able to put some comment on each line. #!/bin/bash -xv command \ # comment1 -sw1 \ # comment2 -sw2 \ # comment3 arguments One ought to be able to comment every single switch if desired for whatever reason. Bolega -- http://mail.python.org/mailman/listinfo/python-list
Re: GURU NEEDED : break a command into several lines and comment each line
On Thu, Jan 13, 2011 at 1:18 PM, bolega wrote: > Basically, I have spent a few hours experimenting and searching on the > comp.unix.shell > > how to break a command with several switches into more than one line > AND to be able to put some comment on each line. > > #!/bin/bash -xv > > command \ # comment1 > -sw1 \ # comment2 > -sw2 \ # comment3 > arguments > > One ought to be able to comment every single switch if desired for > whatever reason. This doesn't seem to have anything whatsoever to do with Python... Regards, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: GURU NEEDED : break a command into several lines and comment each line
bolega writes: > Basically, I have spent a few hours experimenting and searching on the > comp.unix.shell > > how to break a command with several switches into more than one line > AND to be able to put some comment on each line. > > #!/bin/bash -xv > > command \ # comment1 > -sw1 \ # comment2 > -sw2 \ # comment3 > arguments How about --- #!/bin/bash -xv COMMAND=command # comment1 COMMAND=$COMMAND -sw1 \ # comment2 COMMAND=$COMMAND -sw2 \ # comment3 COMMAND=$COMMAND arguments $COMMAND - ? Regards Berthold > One ought to be able to comment every single switch if desired for > whatever reason. > > Bolega > > -- A: Weil es die Lesbarkeit des Textes verschlechtert. F: Warum ist TOFU so schlimm? A: TOFU F: Was ist das größte Ärgernis im Usenet? pgphL9fkvnoiY.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: GURU NEEDED : break a command into several lines and comment each line
On Thu, 13 Jan 2011 16:18:31 -0500, bolega wrote: how to break a command with several switches into more than one line AND to be able to put some comment on each line. command \ # comment1 -sw1 \ # comment2 Not what you want to hear, but that will not work. With the above, the backslash is being used to escape the following space, rather then a newline, as is required to continue the line. Even if it were to work that way, would the next line be considered a continuation of the command, or of the comment? Your stuck with command \ -sw1 # comment1 # comment2 Regards, Dave Hodgins -- Change nomail.afraid.org to ody.ca to reply by email. (nomail.afraid.org has been set up specifically for use in usenet. Feel free to use it yourself.) -- http://mail.python.org/mailman/listinfo/python-list
Re: python 3 and Unicode line breaking
On Thu, 13 Jan 2011 12:45:31 -0800, leoboiko wrote: > Hi, > > Is there an equivalent to the textwrap module that knows about the > Unicode line breaking algorithm (UAX #14, > http://unicode.org/reports/tr14/ )? Is access to Google blocked where you are, or would you just like us to do your searches for you? If you have tried searching, please say so, otherwise most people will conclude you haven't bothered, and most likely will not bother to reply. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Multiple independently started python processes and sharing of a module
Hi all, I have the following problem (which I already have a hacked around solution that works but I'd would like some more input on it): I have a situation where multiple python processes are started independently from each other but by the same user with the same environment (as happens with mod_wsgi, when not using daemon mode). All of these processes access a single module which needs synchronization for some of the commands, for example a db (MySQLdb) module where when a select is done, the fetchall must be done of that same process before another process can do anything else. How would I go and provide synchronization? Locking does not seem to work because there is no relationship between all the python processes except that they are started by the same user. Currently my solution is to wrap the module around a module that when used creates a directory and pipes to the process (multiprocessing.Connection) thus enforcing single access and within that I have wrapped the db function around again so that select statement as mentioned above is actually an execute followed by a fetchall. I still have the nagging feeling that I have reinvented a squared wheel or am totally missing the point. Any suggestions/comments are greatly appreciated, Thanks in advanced, Martin P. Hellwig -- http://mail.python.org/mailman/listinfo/python-list
Re: GURU NEEDED : break a command into several lines and comment each line
On Thu, 13 Jan 2011 13:49:06 -0800, Chris Rebert wrote: > On Thu, Jan 13, 2011 at 1:18 PM, bolega wrote: >> Basically, I have spent a few hours experimenting and searching on the >> comp.unix.shell [...] > This doesn't seem to have anything whatsoever to do with Python... Well, I launch Python scripts from the shell, so there's your connection. *wink* -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to parse a HUGE(1gb) xml file
In article , Stefan Behnel wrote: > >Try > > import xml.etree.cElementTree as etree > >instead. Note the leading "c", which hints at the C implementations of >ElementTree. It's much faster and much more memory friendly than the Python >implementation. Thanks! I updated our codebase this afternoon... -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "The volume of a pizza of thickness 'a' and radius 'z' is given by pi*z*z*a" -- http://mail.python.org/mailman/listinfo/python-list
Re: Resolve circular reference
On 2011-01-07 03:24, moerchendiser2k3 wrote: Everything works fine, the problem starts when I start to make a circular reference in Python. I didn't quite grok your example, but concerning CPython GC & circular references... >>> import gc >>> class X: ... def __del__(self): ... print 'Deleted', self ... >>> a = X() >>> del a Deleted <__main__.X instance at 0x00CCCF80> >>> a=X() >>> b=X() >>> a.b=b >>> b.a=a >>> del a >>> gc.collect() 0 >>> del b >>> gc.collect() 4 >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: How to read ansic file into a pre-defined class?
On 2011-01-08 04:24, Ying Zu wrote: How to read ansic file into a pre-defined class? I have a series of files written in the following format, ... You might like to take a look at the json module if you aren't locked to the exact format you suggested. http://json.org/ http://docs.python.org/library/json.html#module-json -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple independently started python processes and sharing of a module
- Original message - > Hi all, > > I have the following problem (which I already have a hacked around > solution that works but I'd would like some more input on it): > > I have a situation where multiple python processes are started > independently from each other but by the same user with the same > environment (as happens with mod_wsgi, when not using daemon mode). > > All of these processes access a single module which needs > synchronization for some of the commands, for example a db (MySQLdb) > module where when a select is done, the fetchall must be done of that > same process before another process can do anything else. > If the processes are independent, they are not sharing the database connection, unless you've taken steps to make it so. MySQLdb imported in one process should not interfere with MySQLdb importerd in another process. > -- regards, kushal -- http://mail.python.org/mailman/listinfo/python-list
Re: GURU NEEDED : break a command into several lines and comment each line
> #!/bin/bash -xv > command \ # comment1 > -sw1 \ # comment2 > -sw2 \ # comment3 > arguments > One ought to be able to comment every single switch if desired for > whatever reason. Thanks for the riddle. Here's a solution: command$(: # comment1 )-sw1 $(: # comment2 )-sw2 $(: # comment3 )arguments -- Stefan -- http://mail.python.org/mailman/listinfo/python-list
overplot while keeping the axes fixed
Hi folks, I was trying to split the frame into 2 panels using "subplot", fig = matplotlib.pyplot.figure() plt1 = fig.add_subplot(2,1,1 ) plt2 = fig.add_subplot(2,1,2 ) plt1.plot(x1, y1, 'g-') plt2.plot(x2, y2, 'g-') then I need to overplot other curves on each subplot panel using the same axes/ticksize settings, although the new data points extend a longer x-range plt1.plot(x3, y3, 'g-') will simply overplot the new x3/y3 by extending the x-axis, is there a simply option or way to hold the axes/ ticksize setting fixed while doing overplot? I am writing a pipeline to analyze thousands of sets of data points, so a tunning on the pyplot would be a lot more preferred than finding the xrange individually for each data sets. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to populate all possible hierarchical clusterings from a set of elements?
Arnaud Delobelle wrote: > more simply: > > def clusters(l): > if len(l) == 1: > yield l[0] > return > for i in range(1, len(l)): > for left in clusters(l[:i]): > for right in clusters(l[i:]): > yield (left, right) > > That would give all solutions without duplicates. In fact, this is > simply finding all full binary trees which order l. Easy, now that I see it ;) -- http://mail.python.org/mailman/listinfo/python-list