FYI
http://scummos.blogspot.com/2011/09/kdev-python-argument-type-guessing.html I'm not used to big ide/rad for python... but I think this work is excellent! Are there alternatives (pydev? others?) capable of this sort of thinks (I mean "guessing the type" and method autocomplete) -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing a file using multithreads
Abhishek Pratap wrote: > >My application is not I/O bound as far as I can understand it. Each >line is read and then processed independently of each other. May be >this might sound I/O intensive as #N files will be read but I think if >I have 10 processes running under a parent then it might not be a >bottle neck. Your conclusion doesn't follow from your premise. If you are only doing a little bit of processing on each line, then you almost certainly WILL be I/O bound. You will spend most of your time waiting for the disk to deliver more data. In that case, multithreading is not a win. The threads will all compete with each other for the disk. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: using python in web applications
"Littlefield, Tyler" writes: > I'm curious if there are some good solutions for using Python in web > applications. Start with: http://docs.python.org/howto/webservers.html#frameworks> http://wiki.python.org/moin/WebFrameworks> and try your criteria against what you find there. -- \ “As scarce as truth is, the supply has always been in excess of | `\ the demand.” —Josh Billings | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
using python in web applications
Hello all: I'm curious if there are some good solutions for using Python in web applications. I'm not feeling particularly masochistic, so I do not want to develop this project in PHP; essentially I'm looking to build a web-based MMO. I know that you can use nginx with Python with servers like Flask, but I'm not really sure how well all of those work. Since this will be a game, I can expect quite a few users; I've already got quite a lot of interest. I don't much care for PHP, but the thing that can be said for it is it's pretty quick. How does Python compare? Are there some solutions (I was told about PyPy today) that would be quicker that I could still use for the web app? I'm also curious what databases are suggested? I've always done most of my work in MYSql, but from what I understand postgresql is becoming more popular to. Thanks all for the input, -- Take care, Ty Web: http://tds-solutions.net The Aspen project: a light-weight barebones mud engine http://code.google.com/p/aspenmud Sent from my toaster. -- http://mail.python.org/mailman/listinfo/python-list
Re: killing a script
On Sat, Sep 10, 2011 at 11:25 AM, Steven D'Aprano wrote: >> This is implemented by calling the Standard C function system(), and >> has the same limitations. >> >> and sure enough, "man 3 system" says: > > I don't consider having to look up documentation for a function in a > completely different language (in this case, C) as "documented behaviour of > os.system". > The Python docs chain to the C docs. It'd be nice to have a link somewhere, but that's platform-dependent - the online docs could link to an online man page, but local docs can't, etc. It's fairly normal for high level languages to expose a lot of C API functions, with all the concerns and features given. Not a lot of point bloating the Python docs with every little detail, imho. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: killing a script
Cameron Simpson wrote: > On 09Sep2011 22:16, Steven D'Aprano > wrote: > | Hans Mulder wrote: > | > On 9/09/11 11:07:24, Steven D'Aprano wrote: > | >> Sure enough, I now have to hit Ctrl-C repeatedly, once per invocation > | >> of script.py. While script.py is running, it receives the Ctrl-C, the > | >> calling process does not. > | > > | > You misinterpret what you are seeing: the calling process *does* > | > receive the ctrl-C, it just chooses to ignore it. > | > > | > This is documented behaviour of os.system. > | > | Documented where? Neither the on-line documentation nor the function > | docstring mentions anything about it that I can see: > | > | http://docs.python.org/py3k/library/os.html#os.system > > My copy of the 2.7 docs says: > > This is implemented by calling the Standard C function system(), and > has the same limitations. > > and sure enough, "man 3 system" says: I don't consider having to look up documentation for a function in a completely different language (in this case, C) as "documented behaviour of os.system". Does the C standard define the behaviour of system(), or is that implementation dependent? It sounds to me that the Python developers are implicitly refusing responsibility for the detailed behaviour of os.system by noting that it depends on the C function. What do Jython, PyPy and IronPython do? Perhaps the docs for os.system should explicitly note that the behaviour is implementation dependent, rather than just hint at it. Either that or explicitly state what os.system does. > os.system() is very convenient for simple stuff, but one size does not > fit all. I never said it does. Back in my first comment on this thread, I said "Possibly using the subprocess module may help." > Continuing with the Python docs for os.system: > > On Unix, the return value is the exit status of the process encoded in > the format specified for wait(). > > and it is easy to inspect that value for "the subprocess died from a > signal". Not inspecting the exit status correctly will always be an > opportunity for incorrect app behaviour. Except that the subprocess can catch the KeyboardInterrupt before exiting, and there's no guarantee that it will return an appropriate error code. You're right though, os.system is good for simple stuff and not much more. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
RE: Installing 2.6 on Win 7
Brian, Thank you, that was great. Ray Joseph, PE832 586-5854r...@aarden.us Original Message Subject: Re: Installing 2.6 on Win 7From: Brian CurtinDate: Fri, September 09, 2011 3:14 pmTo: ray Cc: python-list@python.orgOn Fri, Sep 9, 2011 at 15:04, ray wrote:>> I have not found binaries for this install. The page> http://www.python.org/download/windows/> takes me to> http://www.python.org/download/releases/> which goes to> http://www.python.org/download/releases/2.6.7/> Here are Gzip and Bzip tar balls. The readme files describe linux> builds and the content seems to match.>> Are there win binaries or source files?As stated at the top of that page..."""Python 2.6.7 is a security-fix only source release for Python2.6.6, fixing several reported security issues. Python 2.6.7 wasreleased on June 3, 2011."""If you work backwards, http://www.python.org/download/releases/2.6.6/is the last version binaries were created for. -- http://mail.python.org/mailman/listinfo/python-list
Re: IOError 35 when trying to read the result of call to urllib2.urlopen
matt wrote: > When I try to look at "resp_body" I get this error: > > IOError: [Errno 35] Resource temporarily unavailable > > I posted to the same URI using curl and it worked fine, so I don't > think it has to do with the server. Are your Python code and curl both using the same proxy? It may be that one is going direct and the other is using a proxy. Or perhaps the destination is just flaky, and the resource genuinely is temporarily unavailable. Or it doesn't like your useragent string and is lying. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: can't generate list from iterator [was: can't generate iterator from list]
Dr. Phillip M. Feldman wrote: > > It is supposed to be possible to generate a list representation of any > iterator that produces a sequence of finite length, but this doesn't > always work. Here's a case where it does work: > > Input: > > from itertools import combinations > list(combinations(range(4),2)) > > Output: > > [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] > > When I define my own classes that produce iterators, conversion to a list > works for some of these classes but not for others. Here's a case where it > doesn't work: > > In: list(balls_in_numbered_boxes(2, [3,3,3])) > > Out: > > [array([0, 0, 1]), > array([0, 0, 1]), > array([0, 0, 1]), > array([0, 0, 1]), > array([0, 0, 1])] But it does work -- it generates a list, exactly as expected. The problem is not that you can't generate a list. The problem is that the list you generate is not what you expect. What you have here is a list containing the same array, repeated three times. When you print the permutations one at a time, you don't notice, but by collecting them all at once, you see clearly that they are the same array object. Try this: combos = list(balls_in_numbered_boxes(2, [3,3,3])) [id(a) for a in combos] I expect you will see something like [123456, 123456, 123456]. The simplest fix is to fix the next() method so that it returns a copy of self.distribution instead of the array itself. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
IOError 35 when trying to read the result of call to urllib2.urlopen
I'm using urllib2's urlopen function to post to a service which should return a rather lengthy JSON object as the body of its response. Here's the code: {{{ ctype, body = encode_multipart(fields, files) url = 'http://someservice:8080/path/to/resource' headers = {'Content-Type': ctype, 'Content-Length': str(len(body))} req = urllib2.Request(url, body, headers) resp = urllib2.urlopen(req) resp_body = resp.read() }}} When I try to look at "resp_body" I get this error: IOError: [Errno 35] Resource temporarily unavailable I posted to the same URI using curl and it worked fine, so I don't think it has to do with the server. Any thoughts? -- http://mail.python.org/mailman/listinfo/python-list
Re: can't generate iterator from list
1. Can you post the code somewhere where it's indented properly? (http://paste.pocoo.org/) 2. In the list example you call balls_in_numbered_boxes(2, [3,3,3]) but in the interactive example you call balls_in_numbered_boxes(3,[3,3,3]) -- http://mail.python.org/mailman/listinfo/python-list
can't generate iterator from list
It is supposed to be possible to generate a list representation of any iterator that produces a sequence of finite length, but this doesn't always work. Here's a case where it does work: Input: from itertools import combinations list(combinations(range(4),2)) Output: [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] When I define my own classes that produce iterators, conversion to a list works for some of these classes but not for others. Here's a case where it doesn't work: In: list(balls_in_numbered_boxes(2, [3,3,3])) Out: [array([0, 0, 1]), array([0, 0, 1]), array([0, 0, 1]), array([0, 0, 1]), array([0, 0, 1])] Note that if I apply the `next` method to the object, the output is correct: In [5]: x=balls_in_numbered_boxes(3,[3,3,3]) In [6]: x.next() Out[6]: array([3, 0, 0]) In [7]: x.next() Out[7]: array([2, 1, 0]) In [8]: x.next() Out[8]: array([1, 2, 0]) In [9]: x.next() Out[9]: array([0, 3, 0]) In [10]: x.next() Out[10]: array([0, 2, 1]) In [11]: x.next() Out[11]: array([0, 1, 2]) In [12]: x.next() Out[12]: array([0, 0, 3]) In [13]: x.next() --- StopIteration Traceback (most recent call last) Code is attached (see below). Any suggestions as to what's going wrong will be appreciated. class balls_in_numbered_boxes(object): """ OVERVIEW This class generates an iterator that produces all distinct distributions of indistinguishable balls among numbered boxes with specified capacity limits. (This is a generalization of the most common formulation of the problem, where each box is sufficiently large to accommodate all of the balls, and is an important example of a class of combinatorics problems called 'weak composition' problems). CONSTRUCTOR INPUTS n: the number of balls limits: This argument is a list of length 1 or greater. The length of the list corresponds to the number of boxes. `limits[i]` is a positive integer that specifies the maximum capacity of the ith box. If `limits[i]` equals `n` (or greater), then the ith box can accommodate all `n` balls and thus effectively has unlimited capacity. """ def __init__(self, n=None, limits=None): if n < 0 or not isinstance(n,int): raise BadInput("The number of balls n must be a non-negative integer.") if not isinstance(limits,list) or len(limits)<1: raise BadInput("`limits` must be a non-empty list.") for limit in limits: if not isinstance(limit,int) or limit<1: raise BadInput("Items in `limits` must be positive integers.") # Copy constructor inputs to object attributes. We make a `deepcopy` of # `limits` to protect against the possibility of the calling program # modifying it before all calls to the `next` method have been completed. self.n= n self.limits= deepcopy(limits) self.distribution= None def __iter__(self): return self def next(self): # If `self.distribution` is `None`, this is the initial call to `next`, # in which case we generate the initial distribution by assigning as many # balls as possible to the first box, as many balls that remain to the # next box, and so on. if self.distribution is None: self.distribution= zeros(len(self.limits), dtype='i4') balls= self.n for box in xrange(len(self.limits)): # Store as many balls as possible in the current box: self.distribution[box]= min(balls,self.limits[box]) balls-= self.distribution[box] if balls == 0: break else: # We fell through the above loop, which means that it was impossible # to distribute all of the balls: raise BadInput("The total capacity of the boxes is less than the " "number of balls to be distributed.") # Make first box the "current" box, i.e., the box from which a ball # will be moved when the `next` method is invoked: self.box= 0 return self.distribution # `self.distribution` is not `None`, which means that this is not the # initial invocation of `next`. We create the next distribution by moving # one ball to the right, unless this is impossible. self.distribution[self.box]-= 1 for box in xrange(self.box+1,len(self.limits)): # If this box is full, advance to the next one: if self.distribution[box] == self.limits[box]: continue self.distribution[box]+= 1 break else: # We fell through the above loop, which means that it was impossible # to find a new home for the ball that we were trying to move. raise StopIteration # If the current box--the box from which we have been removing balls-- is # empty, advance to the next box: if self.distribution[self.box] == 0: self.box+=
Re: can't generate list from iterator
The title should have been "can't generate list from iterator". -- View this message in context: http://old.nabble.com/can%27t-generate-iterator-from-list-tp32435519p32435569.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: killing a script
On 09Sep2011 22:16, Steven D'Aprano wrote: | Hans Mulder wrote: | > On 9/09/11 11:07:24, Steven D'Aprano wrote: | >> Sure enough, I now have to hit Ctrl-C repeatedly, once per invocation of | >> script.py. While script.py is running, it receives the Ctrl-C, the | >> calling process does not. | > | > You misinterpret what you are seeing: the calling process *does* receive | > the ctrl-C, it just chooses to ignore it. | > | > This is documented behaviour of os.system. | | Documented where? Neither the on-line documentation nor the function | docstring mentions anything about it that I can see: | | http://docs.python.org/py3k/library/os.html#os.system My copy of the 2.7 docs says: This is implemented by calling the Standard C function system(), and has the same limitations. and sure enough, "man 3 system" says: The system() function hands the argument command to the command interpreter sh(1). The calling process waits for the shell to finish executing the command, ignoring SIGINT and SIGQUIT, and blocking SIGCHLD. os.system() is very convenient for simple stuff, but one size does not fit all. Continuing with the Python docs for os.system: On Unix, the return value is the exit status of the process encoded in the format specified for wait(). and it is easy to inspect that value for "the subprocess died from a signal". Not inspecting the exit status correctly will always be an opportunity for incorrect app behaviour. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Mac OS X. Because making Unix user-friendly is easier than debugging Windows. - Mike Dawson, Macintosh Systems Administrator and Consultation. mdaw...@mac.com http://herowars.onestop.net -- http://mail.python.org/mailman/listinfo/python-list
Re: try... except with unknown error types
Chris Torek wrote: > (I have also never been sure whether something is going to raise > an IOError or an OSError for various OS-related read or write > operation failures -- such as exceeding a resource limit, for > instance -- so most places that do I/O operations on OS files, I > catch both. Still, it sure would be nice to have a static analysis > tool that could answer questions about potential exceptions. :-) ) There is an effort to fix this: http://www.python.org/dev/peps/pep-3151/ And an implementation ... http://hg.python.org/features/pep-3151/ ... together with a feature request: http://bugs.python.org/issue12555 I think the whole concept makes a lot of sense and is really worth taking a look at. Stefan Krah -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing 2.6 on Win 7
On 9/9/2011 2:04 PM, ray wrote: I have not found binaries for this install. The page http://www.python.org/download/windows/ takes me to http://www.python.org/download/releases/ which goes to http://www.python.org/download/releases/2.6.7/ Here are Gzip and Bzip tar balls. The readme files describe linux builds and the content seems to match. Are there win binaries or source files? http://www.python.org/getit/releases/2.6.6/ has a release for windows x86 and x64 ray -- Take care, Ty Web: http://tds-solutions.net The Aspen project: a light-weight barebones mud engine http://code.google.com/p/aspenmud Sent from my toaster. -- http://mail.python.org/mailman/listinfo/python-list
Re: what's the command for (cd ..) in python
On 9/9/2011 6:07 AM, kaustubh joshi wrote: Hello friends, How do we carry out the command "*cd ..*" in python? os.chdir, like so: >>> os.getcwd() '/home/tyler' >>> os.chdir("../") >>> os.getcwd() '/home' So you could do something like: os.chdir("../foo") My problem is : I have a set of folders say m=1,2,3,4. In each of these folders, I have subfolders with common name say m_5,m_6,m_7,m_8. In each of these subfolder, there is a file which I have edit. 1 23 4 | | | | -- 1_5, 1_6, 1_7, 1_8 2_5 ,2_6, 2_7, 2_8 3_5, 3_6, 3_7, 3_8 4_5, 4_6, 4_7, 4_8 That is how I designed it When I run my script, it follows the route 1 ---> 1_5-> do the edit job in the file. Now it need to change the subfolder from 1_5 to 1_6, which is not happening. I created the folders using variable like m for folder taking values 1,2,3,4 and m_n for subfolders with n=5,6,7,8. I am trying with os.chdir(path), but stuck with how to use m_n in it. What I am missing at the moment is something that do the job "cd .." does. Any help Karan -- Take care, Ty Web: http://tds-solutions.net Sent from my toaster. -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing 2.6 on Win 7
On Sep 9, 2011 4:07 PM, "ray" wrote: > > I have not found binaries for this install. The page > http://www.python.org/download/windows/ > takes me to > http://www.python.org/download/releases/ > which goes to > http://www.python.org/download/releases/2.6.7/ > Here are Gzip and Bzip tar balls. The readme files describe linux > builds and the content seems to match. > > Are there win binaries or source files? > > ray > -- There is no such thing as the windows source vs. the Linux source. Just different build files, both of which are in those folders. Since 2.6 is in security-fix only mode, python.org doesn't provide binaries. You may be able to find binaries from ActiveState if you don't want to build it yourself. -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing 2.6 on Win 7
On Fri, Sep 9, 2011 at 15:04, ray wrote: > > I have not found binaries for this install. The page > http://www.python.org/download/windows/ > takes me to > http://www.python.org/download/releases/ > which goes to > http://www.python.org/download/releases/2.6.7/ > Here are Gzip and Bzip tar balls. The readme files describe linux > builds and the content seems to match. > > Are there win binaries or source files? As stated at the top of that page... """Python 2.6.7 is a security-fix only source release for Python 2.6.6, fixing several reported security issues. Python 2.6.7 was released on June 3, 2011.""" If you work backwards, http://www.python.org/download/releases/2.6.6/ is the last version binaries were created for. -- http://mail.python.org/mailman/listinfo/python-list
Installing 2.6 on Win 7
I have not found binaries for this install. The page http://www.python.org/download/windows/ takes me to http://www.python.org/download/releases/ which goes to http://www.python.org/download/releases/2.6.7/ Here are Gzip and Bzip tar balls. The readme files describe linux builds and the content seems to match. Are there win binaries or source files? ray -- http://mail.python.org/mailman/listinfo/python-list
Re: what's the command for (cd ..) in python
On 9/9/2011 9:03 AM, Steven D'Aprano wrote: kaustubh joshi wrote: Hello friends, How do we carry out the command "*cd ..*" in python? import os os.chdir('..') But think carefully before doing this. Some functions may be confused if you change directories while they are running. You may be better off staying in the same directory, and adjusting the path names to the files as you work with them. Or, use it once at the top of the main module, with an absolute path, to make sure you start at a known place where you want to start. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
A bit of a boggle about subprocess.poll() and the codes it receives from a process
Hi, I need a bit of help sorting this out... I have a memory test script that is a bit of compiled C. The test itself can only ever return a 0 or 1 exit code, this is explicitly coded and there are no other options. I also have a wrapper test script that calls the C program that should also only return 0 or 1 on completion. The problem i'm encountering, however, involves the return code when subprocess.poll() is called against the running memory test process. The current code in my wrapper program looks like this: def run_processes(self, number, command): passed = True pipe = [] for i in range(number): pipe.append(self._command(command)) print "Started: process %u pid %u: %s" % (i, pipe[i].pid, command) sys.stdout.flush() waiting = True while waiting: waiting = False for i in range(number): if pipe[i]: line = pipe[i].communicate()[0] if line and len(line) > 1: print "process %u pid %u: %s" % (i, pipe[i].pid, line) sys.stdout.flush() if pipe[i].poll() == -1: waiting = True else: return_value = pipe[i].poll() if return_value != 0: print "Error: process %u pid %u retuned %u" % (i, pipe[i].pid, return_value) passed = False print "process %u pid %u returned success" % (i, pipe[i].pid) pipe[i] = None sys.stdout.flush() return passed So what happens here is that in the waiting loop, if pipe[i].poll returns a -1, we keep waiting, and then if it returns anything OTHER than -1, we exit and return the return code. BUT, I'm getting, in some cases, a return code of 127, which is impossible to get from the memory test program. The output from this bit of code looks like this in a failing situation: Error: process 0 pid 2187 retuned 127 process 0 pid 2187 returned success Error: process 1 pid 2188 retuned 127 process 1 pid 2188 returned success I'm thinking that I'm hitting some sort of race here where the kernel is reporting -1 while the process is running, then returns 127 or some other status when the process is being killed and then finally 0 or 1 after the process has completely closed out. I "think" that the poll picks up this intermediate exit status and immediately exits the loop, instead of waiting for a 0 or 1. I've got a modified version that I'm getting someone to test for me now that changes if pipe[i].poll() == -1: waiting = True to this if pipe[i].poll() not in [0,1]: waiting = True So my real question is: am I on the right track here, and am I correct in my guess that the kernel is reporting different status codes to subprocess.poll() during the shutdown of the polled process? -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: object.__init__() takes no parameters
On 9/9/2011 1:47 AM, Oliver wrote: If I want to run shapes.py I receive this error message: Others have explained why code that ran once now does not. class Container(object): """Container to store a number of non-overlapping rectangles.""" def __init__(self, xsize=1200, ysize=800): super(Container, self).__init__(xsize, ysize) Remove this line and the error will go away. It *never* did anything. self.rect = Rectangle(0, 0, xsize, ysize) self.boxes = [] self.last_placement_strategy = 0 -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing a file using multithreads
Hi All @Roy : split in unix sounds good but will it be as efficient as opening 10 different file handles on a file. I haven't tried it so just wondering if you have any experience with it. Thanks for your input. Also I was not aware of the python's GIL limitation. My application is not I/O bound as far as I can understand it. Each line is read and then processed independently of each other. May be this might sound I/O intensive as #N files will be read but I think if I have 10 processes running under a parent then it might not be a bottle neck. Best, -Abhi On Fri, Sep 9, 2011 at 6:19 AM, Roy Smith wrote: > In article > , > aspineux wrote: > >> On Sep 9, 12:49 am, Abhishek Pratap wrote: >> > 1. My input file is 10 GB. >> > 2. I want to open 10 file handles each handling 1 GB of the file >> > 3. Each file handle is processed in by an individual thread using the >> > same function ( so total 10 cores are assumed to be available on the >> > machine) >> > 4. There will be 10 different output files >> > 5. once the 10 jobs are complete a reduce kind of function will >> > combine the output. >> > >> > Could you give some ideas ? >> >> You can use "multiprocessing" module instead of thread to bypass the >> GIL limitation. > > I agree with this. > >> First cut your file in 10 "equal" parts. If it is line based search >> for the first line close to the cut. Be sure to have "start" and >> "end" for each parts, start is the address of the first character of >> the first line and end is one line too much (== start of the next >> block) > > How much of the total time will be I/O and how much actual processing? > Unless your processing is trivial, the I/O time will be relatively > small. In that case, you might do well to just use the unix > command-line "split" utility to split the file into pieces first, then > process the pieces in parallel. Why waste effort getting the > file-splitting-at-line-boundaries logic correct when somebody has done > it for you? > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://mail.python.org/mailman/listinfo/python-list
Re: How to structure packages
Kayode: Are the number of pages in that tutorial planned? :P > On Sat, Sep 10, 2011 at 1:57 AM, Kayode Odeyemi wrote: >> You might want to have a look at this: >> http://www.ccs.neu.edu/home/matthias/htdc.html >> >> On Fri, Sep 9, 2011 at 2:37 AM, Chris Angelico wrote: >>> >>> On Fri, Sep 9, 2011 at 10:45 AM, Nobody wrote: >>> > The Java compiler also acts as a "make" program. If it doesn't find >>> > a .class file for a needed class, it will search for the corresponding >>> > .java file and compile that. So to compile a complex program, you only >>> > need to compile the top-level file (e.g. HelloWorld.java), and it will >>> > compile everything which is required. No Makefile is needed, as the >>> > relationship between classes, object files and source files is fixed. >>> > >>> >>> If that's the entire benefit, then I think this is a rather hefty >>> price to pay for the elimination of a makefile. Oh wow, I can type >>> "javac MyClass.java" and it picks up all the others! If you're >>> dividing a project into multiple files already, is it that hard to >>> have one more that defines the relationships between the others? >>> >>> Chris Angelico >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >> >> >> >> -- >> Odeyemi 'Kayode O. >> http://www.sinati.com. t: @charyorde >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Outlook-style rules
Something like this? http://stackoverflow.com/questions/387606/using-user-input-to-find-information-in-a-mysql-database On Sat, Sep 10, 2011 at 12:29 AM, Brian wrote: > I'm about to create a system which will need to allow hundreds of > users to create and maintain their own rules in a similar fashion to > MS Outlook rules. ie. > Each rule consists of one or more user configurable conditions and if/ > when the conditions are met then one or more user configurable actions > will be applied. > > The conditions will be things like "a specified key in a dictionary is > in a specified list of values" (where the user can choose the key and > the values), or "a specific record is in the specified > database" (where the user chooses the primary key of the record and > the database table to look in). > > The actions will be things like "send an email to address" (where the > user chooses the address and the email template to use). > > The user will do their configuration in a browser. Also, I need to be > able to continue to add new conditions and actions to the system over > time. > > Is there a python module (preferably free/open source) which already > does (some of) this? I can write the back-end logic easily enough > (although I'd rather not re-invent the wheel) but I'd particularly > like to find a widget or similar which will make the front-end look > nice and be cross-browser compatible. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: How to structure packages
You might want to have a look at this: http://www.ccs.neu.edu/home/matthias/htdc.html On Fri, Sep 9, 2011 at 2:37 AM, Chris Angelico wrote: > On Fri, Sep 9, 2011 at 10:45 AM, Nobody wrote: > > The Java compiler also acts as a "make" program. If it doesn't find > > a .class file for a needed class, it will search for the corresponding > > .java file and compile that. So to compile a complex program, you only > > need to compile the top-level file (e.g. HelloWorld.java), and it will > > compile everything which is required. No Makefile is needed, as the > > relationship between classes, object files and source files is fixed. > > > > If that's the entire benefit, then I think this is a rather hefty > price to pay for the elimination of a makefile. Oh wow, I can type > "javac MyClass.java" and it picks up all the others! If you're > dividing a project into multiple files already, is it that hard to > have one more that defines the relationships between the others? > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -- Odeyemi 'Kayode O. http://www.sinati.com. t: @charyorde -- http://mail.python.org/mailman/listinfo/python-list
Python and Outlook-style rules
I'm about to create a system which will need to allow hundreds of users to create and maintain their own rules in a similar fashion to MS Outlook rules. ie. Each rule consists of one or more user configurable conditions and if/ when the conditions are met then one or more user configurable actions will be applied. The conditions will be things like "a specified key in a dictionary is in a specified list of values" (where the user can choose the key and the values), or "a specific record is in the specified database" (where the user chooses the primary key of the record and the database table to look in). The actions will be things like "send an email to address" (where the user chooses the address and the email template to use). The user will do their configuration in a browser. Also, I need to be able to continue to add new conditions and actions to the system over time. Is there a python module (preferably free/open source) which already does (some of) this? I can write the back-end logic easily enough (although I'd rather not re-invent the wheel) but I'd particularly like to find a widget or similar which will make the front-end look nice and be cross-browser compatible. -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: object.__init__() takes no parameters
Duncan Booth wrote: > Steven D'Aprano wrote: >> In Python 2.2, the default object constructor accepts, and ignores, any >> parameters. In Python 2.3 on up, that becomes an error. >> > More recently than that. It only became an error in 2.6: For __init__, sure, but it was an error for __new__ back in 2.3. Sorry for not being more clear. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: object.__init__() takes no parameters
Steven D'Aprano wrote: > Thomas Rachel wrote: > >> Am 09.09.2011 07:47 schrieb Oliver: >>> class Container(object): >>> """Container to store  a number of non-overlapping rectangles.""" >>> def __init__(self, xsize=1200, ysize=800): >>> super(Container, self).__init__(xsize, ysize) >> >> And this is the nonsense: Container derives from object and tries to >> call its superclass's constructor with 2 parameters - which won't work. > > Not nonsense. Merely a backward-incompatible change: > > > [steve@sylar ~]$ python2.2 > Python 2.2.3 (#1, Aug 12 2010, 01:08:27) > [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. object("two", "parameters") > > > > In Python 2.2, the default object constructor accepts, and ignores, any > parameters. In Python 2.3 on up, that becomes an error. > More recently than that. It only became an error in 2.6: [dbooth@localhost ~]$ python2.5 -c "object().__init__(42)" [dbooth@localhost ~]$ python2.6 -c "object().__init__(42)" Traceback (most recent call last): File "", line 1, in TypeError: object.__init__() takes no parameters -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing a file using multithreads
In article , aspineux wrote: > On Sep 9, 12:49 am, Abhishek Pratap wrote: > > 1. My input file is 10 GB. > > 2. I want to open 10 file handles each handling 1 GB of the file > > 3. Each file handle is processed in by an individual thread using the > > same function ( so total 10 cores are assumed to be available on the > > machine) > > 4. There will be 10 different output files > > 5. once the 10 jobs are complete a reduce kind of function will > > combine the output. > > > > Could you give some ideas ? > > You can use "multiprocessing" module instead of thread to bypass the > GIL limitation. I agree with this. > First cut your file in 10 "equal" parts. If it is line based search > for the first line close to the cut. Be sure to have "start" and > "end" for each parts, start is the address of the first character of > the first line and end is one line too much (== start of the next > block) How much of the total time will be I/O and how much actual processing? Unless your processing is trivial, the I/O time will be relatively small. In that case, you might do well to just use the unix command-line "split" utility to split the file into pieces first, then process the pieces in parallel. Why waste effort getting the file-splitting-at-line-boundaries logic correct when somebody has done it for you? -- http://mail.python.org/mailman/listinfo/python-list
Re: what's the command for (cd ..) in python
kaustubh joshi wrote: > Hello friends, > How do we carry out the command "*cd ..*" in > python? import os os.chdir('..') But think carefully before doing this. Some functions may be confused if you change directories while they are running. You may be better off staying in the same directory, and adjusting the path names to the files as you work with them. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: what's the command for (cd ..) in python
2011/9/9 kaustubh joshi : > Hello friends, > How do we carry out the command "cd .." in python? > > My problem is : > I have a set of folders say m=1,2,3,4. In each of these folders, I have > subfolders with common name say m_5,m_6,m_7,m_8. In each of these subfolder, > there is a file which I have edit. > 1 > 2 3 > 4 > | > | | > | > > -- > 1_5, 1_6, 1_7, 1_8 2_5 ,2_6, > 2_7, 2_8 3_5, 3_6, 3_7, 3_8 4_5, 4_6, 4_7, 4_8 > > That is how I designed it > > When I run my script, it follows the route 1 ---> 1_5-> do the edit job > in the file. Now it need to change the subfolder from 1_5 to 1_6, which is > not happening. > > I created the folders using variable like m for folder taking values 1,2,3,4 > and m_n for subfolders with n=5,6,7,8. > > I am trying with os.chdir(path), but stuck with how to use m_n in it. > > What I am missing at the moment is something that do the job "cd .." does. > > Any help > > > Karan > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi, Would maybe adjusting the path like this work? >>> my_path = "c://d/e/f/g/" >>> os.path.abspath(my_path + os.pardir) 'c:\\d\\e\\f' >>> hth, vbr -- http://mail.python.org/mailman/listinfo/python-list
Re: killing a script
Hans Mulder wrote: > On 9/09/11 11:07:24, Steven D'Aprano wrote: >> Sure enough, I now have to hit Ctrl-C repeatedly, once per invocation of >> script.py. While script.py is running, it receives the Ctrl-C, the >> calling process does not. > > You misinterpret what you are seeing: the calling process *does* receive > the ctrl-C, it just chooses to ignore it. > > This is documented behaviour of os.system. Documented where? Neither the on-line documentation nor the function docstring mentions anything about it that I can see: http://docs.python.org/py3k/library/os.html#os.system >>> help(os.system) Help on built-in function system in module posix: system(...) system(command) -> exit_status Execute the command (a string) in a subshell. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
what's the command for (cd ..) in python
Hello friends, How do we carry out the command "*cd ..*" in python? My problem is : I have a set of folders say m=1,2,3,4. In each of these folders, I have subfolders with common name say m_5,m_6,m_7,m_8. In each of these subfolder, there is a file which I have edit. 1 23 4 | | | | -- 1_5, 1_6, 1_7, 1_8 2_5 ,2_6, 2_7, 2_8 3_5, 3_6, 3_7, 3_8 4_5, 4_6, 4_7, 4_8 That is how I designed it When I run my script, it follows the route 1 ---> 1_5-> do the edit job in the file. Now it need to change the subfolder from 1_5 to 1_6, which is not happening. I created the folders using variable like m for folder taking values 1,2,3,4 and m_n for subfolders with n=5,6,7,8. I am trying with os.chdir(path), but stuck with how to use m_n in it. What I am missing at the moment is something that do the job "cd .." does. Any help Karan -- http://mail.python.org/mailman/listinfo/python-list
plz see this
http://123maza.com/65/clock747/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to check that you are at the beginning (the end) of an iterable?
On Fri, Sep 9, 2011 at 9:04 PM, Peter Otten <__pete...@web.de> wrote: [x] = "" > Traceback (most recent call last): > File "", line 1, in > ValueError: need more than 0 values to unpack [x] = "a" [x] = "ab" > Traceback (most recent call last): > File "", line 1, in > ValueError: too many values to unpack > Hey look, it's a new operator - the "assign-sole-result-of-iterable" operator! x ,= "a" :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to check that you are at the beginning (the end) of an iterable?
Cameron Simpson wrote: > About the only time I do this is my personal "the()" convenience > function: > > def the(list, context=None): > ''' Returns the first element of an iterable, but requires there to be > exactly one. > ''' > icontext="expected exactly one value" > if context is not None: > icontext=icontext+" for "+context > > first=True > for elem in list: > if first: > it=elem > first=False > else: > raise IndexError, "%s: got more than one element (%s, %s, ...)" \ > % (icontext, it, elem) > > if first: > raise IndexError, "%s: got no elements" % icontext > > return it > > Which I use as a definite article in places where an iterable should > yield exactly one result (eg SQL SELECTs that ought to get exactly > one hit). I can see I wrote that a long time ago - it could do with some > style fixes. And a code scan shows it sees little use:-) A lightweight alternative to that is unpacking: >>> [x] = "" Traceback (most recent call last): File "", line 1, in ValueError: need more than 0 values to unpack >>> [x] = "a" >>> [x] = "ab" Traceback (most recent call last): File "", line 1, in ValueError: too many values to unpack -- http://mail.python.org/mailman/listinfo/python-list
Re: Create an index from a webpage [RANT, DNFTT]
Simon Cropper wrote: > Certainly doable but > considering the shear commonality of this task I don't understand why a > simple script does not already exist - hence my original request for > assistance. I think you may have underestimated the complexity of the task in general. To do it for a remote website you need to specify what you consider to be a unique page. Here are some questions: Is case significant for URLs (technically it always is, but IIS sites tend to ignore it and to contain links with random permutations of case)? Are there any query parameters that make two pages distinct? Or any parameters that you should ignore? Is the order of parameters significant? I recently came across a site that not only had multiple links to identical pages with the query parameters in different order but also used a non- standard % to separate parameters instead of &: it's not so easy getting crawlers to handle that mess. Even after ignoring query parameters are there a finite number of pages to the site? For example, Apache has a spelling correction module that can effectively allow any number of spurious subfolders: I've seen a site where "/folder1/index.html" had a link to "folder2/index.html" and "/folder2/index.html" linked to "folder1/index.html". Apache helpfully accepted /folder2/folder1/ as equivalent to /folder1/ and therefore by extension also accepted /folder2/folder1/folder2/folder1/... Zope is also good at creating infinite folder structures. If you want to spider a remote site then there are plenty of off the shelf spidering packages, e.g. httrack. They have a lot of configuration options to try to handle the above gotchas. Your case is probably a lot simpler, but that's just a few reasons why it isn't actually a trivial task. Building a list by scanning a bunch of folders with html files is comparatively easy which is why that is almost always the preferred solution if possible. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: killing a script
On 9/09/11 11:07:24, Steven D'Aprano wrote: Sure enough, I now have to hit Ctrl-C repeatedly, once per invocation of script.py. While script.py is running, it receives the Ctrl-C, the calling process does not. You misinterpret what you are seeing: the calling process *does* receive the ctrl-C, it just chooses to ignore it. This is documented behaviour of os.system. It you don't want this, then use the subprocess module, which does not behave this way. -- HansM -- http://mail.python.org/mailman/listinfo/python-list
Re: Django or web2py
On Sep 9, 12:47 pm, Vineet wrote: > On Sep 9, 3:29 am, Paul Watson wrote: > > > I have read some of the talk around these two frameworks. > > > Would you say that web2py is more geared toward the enterprise? > > > Which one do you believe will be on Python 3 more quickly? > > Both Django & web2py are good frameworks. > I have tried both of them + others & then chosen a hybrid of web2py + > DABO bizobj for my work. > (DABO is a desktop app framework; so I have chosen only the BizObj > layer from it, which can do its job in any other python web or desktop > framework). > > Typically, my apps are data-centric business apps. > web2py wins in simplicity, flexibility, no install, no dependencies, > good docs & community, low learning curve, etc. > > DABO BizObj excels in managing the business logic aspect. > With DABO bizobj layer, apart from the business logic, managing > multiple tables insert/update/delete, rollback, before-insert, after- > save, etc. is very handy... the list is quite long) > (I know you will say that every framework has got its own DAL. It's > true. But most of them are designed for basic database functions.) > > Some useful > links---http://web2py.comwww.web2pyclices.comhttp://thewinecellarbook.com/daboDocTestAlt/dabo.lib.datanav.Bizobj.B...http://dabodev.com/ > > Also, there are threads in stackoverflow.com which discuss in-depth > the +1 & -1 for these frameworks. > Contributors to these threads include the lead developers including > Massimo himself. > > Hope this helps. > > ---Vineet Re. your point about porting from py2 to py3, the following thread makes it clear. http://groups.google.com/group/web2py/browse_thread/thread/5fcd0e97452e9ab8/d38f99b959778cfb?lnk=gst&q=python+3#d38f99b959778cfb ---Vineet -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: object.__init__() takes no parameters
Thomas Rachel wrote: > Am 09.09.2011 07:47 schrieb Oliver: >> class Container(object): >> """Container to store a number of non-overlapping rectangles.""" >> def __init__(self, xsize=1200, ysize=800): >> super(Container, self).__init__(xsize, ysize) > > And this is the nonsense: Container derives from object and tries to > call its superclass's constructor with 2 parameters - which won't work. > > Write this as super(Container, self).__init__(). > It isn't nonsense, just poor and outdated practice. You might subclass Container with something that puts another base class into the mro between Container and object and in that case calling super(Container, self). __init__() would be wrong. object.__init__() used to accept and silently ignore any parameters. This meant you could safely pass any constructor parameters along in case there was an intervening base class that wanted them. However that was changed (presumably after this code was written) and now you have to be a bit more careful with your initialisation parameters. This would be better in general, though if there is actually any code depending on xsize,ysize being passed up to a base class it will still need changing at the call site: def __init__(self, xsize=1200, ysize=800, *args, **kw): super(Container, self).__init__(*args, **kw) That way any xsize and ysize arguments are removed but any additional arguments for other base classes are passed through. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Portable locale usage
Why are you trying to force a specific locale to your program anyway? Because I wish to be able to correctly sort Croatian names. Well, all right. If you want to sort Croatian names from a program that runs on an English (or whatever) system, then you will have to check the platform and use a locale that is supported by the platform. (But again, this is not Python's limitation. Python doesn't know what encodings are supported, in advance, and you cannot use a locale that is not supported...) I fully agree. I commented that, if a proper locale is installed, the following should work on any system: locale.setlocale(locale.LC_ALL, ('hr', locale.getpreferredencoding())) Currently the above does not work on Windows, and that is because the locale_alias for 'hr' is bound to 'hr_HR.ISO8859-2'. Check the source: .../Python-3.2.2/Lib/locale.py, line 537 I was arguing that, on a Windows system, the locale_alias for 'hr' should be bound to 'Croatian_Croatia.1250'. Looks like you have found a bug! :-) Why don't you post a bug report? L -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: object.__init__() takes no parameters
Am 09.09.2011 10:33 schrieb Steven D'Aprano: Not nonsense. Merely a backward-incompatible change: [1] In Python 2.2, the default object constructor accepts, and ignores, any parameters. In Python 2.3 on up, that becomes an error. Thanks, I wasn't aware of that. My first contact with Python was with 2.3... Thomas [1] Another example why backward-incompatible change are bad. Why was it necessary in this case? :-( -- http://mail.python.org/mailman/listinfo/python-list
Re: killing a script
Cameron Simpson wrote: > On 30Aug2011 14:13, Steven D'Aprano > wrote: > | On Tue, 30 Aug 2011 08:53 am Arnaud Delobelle wrote: > | >> Yes, but if I am not mistaken, that will require me to put a line or > | >> two after each os.system call. That's almost like whack-a-mole at the > | >> code level rather than the Control-C level. OK, not a huge deal for > | >> one script, but I was hoping for something simpler. I was hoping I > | >> could put one line at the top of the script and be done with it. > | > > | > Write a function! That's what they're for after all :) > | > | I'm not sure that this is actually as simple as that, especially using > | os.system. > | > | As I understand it, the scenario is this: > | > | The main script looks something like this: > | > | for x in whatever: > | os.system('something.py x') > | > | Each time through the loop, a new Python process is started. Each > | process runs in the foreground, capturing standard input, and so hitting > | Ctrl-C kills *that* process, not the main script. Unless, by chance, the > | Ctrl-C happens after the system call returns, but before the next one > | starts, it is completely invisible to the parent process (the main > | script). Wrapping os.system in a function does nothing to fix that. > > Presuming you're talking about UNIX, this is not correct. > > Ctrl-C at the terminal delivers SIGINT to _every_ process in the > controlling process group for the terminal. It also has _nothing_ to do > with the standard input. There may be something to what you say, but the behaviour experienced by the Original Poster still needs explaining. See below. > When you run a script, yea even a Python script, thus: > > myscript ... > > then job control capable shells (all of them, these days) put the python > process running "myscript" in its own process group as the leader > (being, initially, the only process in the group). If myscript forks > other processes, as happens in os.system(), they are _also_ in that > process group. _ALL_ of them receive the SIGINT from your Ctrl-C. I can replicate to OP's problem with these two simple Python scripts: [steve@sylar ~]$ cat script.py #!/usr/bin/python print "inside script.py" print "type Ctrl-C to exit" while True: pass [steve@sylar ~]$ cat test.py import os print "calling script.py with os.system" for i in range(3): os.system('./script.py') And now run them: [steve@sylar ~]$ python test.py calling script.py with os.system inside script.py type Ctrl-C to exit Traceback (most recent call last): File "./script.py", line 4, in while True: KeyboardInterrupt inside script.py type Ctrl-C to exit Traceback (most recent call last): File "./script.py", line 5, in pass KeyboardInterrupt inside script.py type Ctrl-C to exit Traceback (most recent call last): File "./script.py", line 4, in while True: KeyboardInterrupt Sure enough, I now have to hit Ctrl-C repeatedly, once per invocation of script.py. While script.py is running, it receives the Ctrl-C, the calling process does not. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: object.__init__() takes no parameters
Thomas Rachel wrote: > Am 09.09.2011 07:47 schrieb Oliver: >> class Container(object): >> """Container to store a number of non-overlapping rectangles.""" >> def __init__(self, xsize=1200, ysize=800): >> super(Container, self).__init__(xsize, ysize) > > And this is the nonsense: Container derives from object and tries to > call its superclass's constructor with 2 parameters - which won't work. Not nonsense. Merely a backward-incompatible change: [steve@sylar ~]$ python2.2 Python 2.2.3 (#1, Aug 12 2010, 01:08:27) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> object("two", "parameters") In Python 2.2, the default object constructor accepts, and ignores, any parameters. In Python 2.3 on up, that becomes an error. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Django or web2py
On Sep 9, 3:29 am, Paul Watson wrote: > I have read some of the talk around these two frameworks. > > Would you say that web2py is more geared toward the enterprise? > > Which one do you believe will be on Python 3 more quickly? Both Django & web2py are good frameworks. I have tried both of them + others & then chosen a hybrid of web2py + DABO bizobj for my work. (DABO is a desktop app framework; so I have chosen only the BizObj layer from it, which can do its job in any other python web or desktop framework). Typically, my apps are data-centric business apps. web2py wins in simplicity, flexibility, no install, no dependencies, good docs & community, low learning curve, etc. DABO BizObj excels in managing the business logic aspect. With DABO bizobj layer, apart from the business logic, managing multiple tables insert/update/delete, rollback, before-insert, after- save, etc. is very handy... the list is quite long) (I know you will say that every framework has got its own DAL. It's true. But most of them are designed for basic database functions.) Some useful links--- http://web2py.com www.web2pyclices.com http://thewinecellarbook.com/daboDocTestAlt/dabo.lib.datanav.Bizobj.B... http://dabodev.com/ Also, there are threads in stackoverflow.com which discuss in-depth the +1 & -1 for these frameworks. Contributors to these threads include the lead developers including Massimo himself. Hope this helps. ---Vineet -- http://mail.python.org/mailman/listinfo/python-list
Unittesting SocketServer.StreamRequestHandler subclasses
Hi, Is there a recommended way for writing unittests of SocketServer.StreamRequestHandler subclasses? I've tried making a server stub class and a connection stub class with a recv() method that immediately raises socket.error(errno.ECONNRESET, ). This works OK, but it means that whatever unittests I run always happens after the handler's handle() method has already been called. Is there a way to avoid this? Thanks Neilen -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: object.__init__() takes no parameters
Am 09.09.2011 07:47 schrieb Oliver: class Container(object): """Container to store a number of non-overlapping rectangles.""" def __init__(self, xsize=1200, ysize=800): super(Container, self).__init__(xsize, ysize) And this is the nonsense: Container derives from object and tries to call its superclass's constructor with 2 parameters - which won't work. Write this as super(Container, self).__init__(). HTH, Thomas -- http://mail.python.org/mailman/listinfo/python-list