Obtaining the attributes and properties of a folder recursively.
Hello all, Is there any way to list out all the properties (name, type, size) and attributes( Accesstime, mod time, archived or readonly etc) of a folder and its contents recursively. Should I need ot go inside each and every directory to list them? This has to be for Windows. I have to obtain the following attriubtes of all the files recursively in a directory: NAME\ FILE CREATION TIME \ MODIFICATION TIME \ ACCESS TIME \ ATTRIBUTES \ ACLs \ File SIze \ Thank you, Venu Madhav -- http://mail.python.org/mailman/listinfo/python-list
parser module and doc
I'm reading the docs for the parser module and I'm confused. http://docs.python.org/library/parser.html The doc make a number of references to the file "example.py", and says: "All source files mentioned here which are not part of the Python installation are located in the Demo/parser/ directory of the distribution." http://docs.python.org/library/parser.html#information-discovery What distribution? What does this actually mean? The page also talks about "public classes" ClassInfo, FunctionInfo and ModuleInfo, but they don't exist: >>> parser.ModuleInfo Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'ModuleInfo' Where are these public classes? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Regarding the lxml import error only in a web-request
I'm trying to run Django from Apache using FastCGI in a shared hosting environment on DH. I've installed python 2.5.2 onto my home environment. And all the necessary libraries including lxml 2.1.3, libxml2, libxslt, flup, etc. I'm facing a strange issue with lxml, which occurs only when it is used from the webrequests. I'm getting the following error: Exception Type: ImportError Exception Value:~/opt/lib/python2.5/site-packages/lxml-2.1.3- py2.5-linux-x86_64.egg/lxml/etree.so: undefined symbol:xmlSchematronSetValidStructuredErrors it basically comes when i'm trying to do this in my Django views.py from lxml import etree But the same is running perfectly well in my python console. Even with the following command it works well python -c "from lxml import etree" I've almost checked every installation and library paths.. not able to figure out what exactly would be the issue. Please help me. Nagraj. -- http://mail.python.org/mailman/listinfo/python-list
Re: How complex is complex?
Aahz" a...@pyft.com wrote: 8< > .. Because the name "Python" is derived from the > comedy TV show "Monty Python", stupid jokes are common in the Python > community.) Sacrilege! A joke based on the Monty Python series is BY DEFINITION not stupid! :-) - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Parallel processing on shared data structures
wrote: > I'm filing 160 million data points into a set of bins based on their > position. At the moment, this takes just over an hour using interval So why do you not make four sets of bins - one for each core of your quad, and split the points into quarters, and run four processes, and merge the results later? This assumes that it is the actual filing process that is the bottle neck, and that the bins are just sets, where position, etc does not matter. If it takes an hour just to read the input, then nothing you can do will make it better. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: parser module and doc
On Mar 20, 7:26 am, Steven D'Aprano wrote: > "All source files mentioned here which are not part of the Python > installation are located in the Demo/parser/ directory of the > distribution." > > http://docs.python.org/library/parser.html#information-discovery > > What distribution? What does this actually mean? The source distribution, as obtained by downloading and unpacking one of the source tarballs from (e.g., for Python 2.6): http://www.python.org/download/releases/2.6.1/ > The page also talks about "public classes" ClassInfo, FunctionInfo and > ModuleInfo, but they don't exist: I think they're defined in the Demo/parser/example.py file. Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Heuristically processing documents
"MRAB" wrote: BJörn Lindqvist wrote: 8< --- >> For example, to find the email you can use a simple regexp. If there >> is a match you can be certain that that is the authors email. But what >> algorithms can you use to figure out the other information? >> >Tricky! :-) > >How would _you_ recognise them? Have a look at the documents and see if >you can see a pattern. For example, names and address often consist of a >sequence of words in title case, eg "Björn Lindqvist", which might help >you narrow down the list of possibilities. What do telephone numbers >look like, etc? It may help you to think about the problem if you imagine yourself having to extract the information from documents written in a language that you do not understand. An address may be identified by a number in a line (street address or PO box) that is followed some lines later by another number (zip code). But this hardly qualifies as an "algorithm". A "mailto:"; and/or a set of "angle brackets" is a strong clue too... Don't have a clue about the name, though. - plain title case might work for "John Brown" but it fails with "Koos van der Merwe". If there is an email addy in the doc, then it might serve as a clue to where to look - based on the theory that the contact information would be grouped together. Another clue might be to look for the word "Author" or its equivalent in a bunch of languages. "Tricky" is an understatement. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
How to use self-inspection to check for try-block
Hi everyone, is there a sufficiently easy possibility for a Python function to find out whether it has been called from a try-block or not? try: print "Calling foo" foo() except: print "Got exception" In the example above, foo() should be able to 'see' that it was called from a try block, allowing it to behave differently. Can this information be obtained from the traceback/frame/code objects, or is that too difficult? Many thanks for your help, Elmar -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use self-inspection to check for try-block
On Fri, Mar 20, 2009 at 1:32 AM, wrote: > Hi everyone, > > is there a sufficiently easy possibility for a Python function to find > out whether it has been called from a try-block or not? > > try: > print "Calling foo" > foo() > except: > print "Got exception" > > In the example above, foo() should be able to 'see' that it was called > from a try block, allowing it to behave differently. > > Can this information be obtained from the traceback/frame/code > objects, or is that too difficult? It might be possible, but it seems like there ought to be a better way to accomplish your goal. Could you explain why you want to do this in the first place? Perhaps a better alternative can be found. Cheers, Chris -- I have a blog: http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Obtaining the attributes and properties of a folder recursively.
venutaurus...@gmail.com wrote: Hello all, Is there any way to list out all the properties (name, type, size) and attributes( Accesstime, mod time, archived or readonly etc) of a folder and its contents recursively. Should I need ot go inside each and every directory to list them? This has to be for Windows. I have to obtain the following attriubtes of all the files recursively in a directory: NAME\ FILE CREATION TIME \ MODIFICATION TIME \ ACCESS TIME \ ATTRIBUTES \ ACLs \ File SIze \ Just some hints you might want to check: os.walk >>> help(os.walk) and os.stat please see the example for os.walk - this would work on every platform supported by python. for acls, a little more work would be needed if you want something filesystem specific but posix style information is included with stat() Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: multiprocessing and Tk GUI program (won't work under Linux)
On Mar 20, 4:36 am, akineko wrote: > Hello everyone, > > I have started using multiprocessing module, which is now available > with Python 2.6. > It definitely opens up new possibilities. > > Now, I developed a small GUI package, which is to be used from other > programs. > It uses multiprocessing and Pipes are used to pump image data/command > to the GUI process. > (I used multiprocessing because I got stack size problem if I used > threading) > > It works great under Solaris environment, which is my primary > development environment. > > When I tried the program under Linux (CentOS5), the program didn't > work (it hung). > My other programs that use multiprocessing work flawlessly under both > Solaris and Linux. > > To investigate this problem, I create a much simpler test program. The > test program uses only basic necessary codes, nothing else. But my > simple test program still exhibits the same problem. > > My test program display a GUI Button using three possible approaches: > > (1) multiprocessing (Solaris - okay, Linux - hung) > (2) threading (Solaris - okay, Linux - okay) > (3) none (main thread) (Solaris - okay, Linux - okay) > > Is this a bug in a multiprocessing package? Or, I overlooked > something? > > Any comments on resolving this problem will be greatly appreciated. > > The attached is my test program (sorry for posting a long program). > > Thank you! > Aki Niimura > > #!/usr/bin/env python > > import sys, os > import time > import threading > import multiprocessing > > from Tkinter import * > > ### > ### class Panel > ### > > class Panel: > > def __init__(self, subp='multip'): > if subp == 'multip': > print 'multiprocessing module to handle' > # GUI process > self.process1 = multiprocessing.Process(target=self.draw) > self.process1.start() > elif subp == 'thread': > print 'threading module to handle' > # GUI thread > self.thread1 = threading.Thread(target=self.draw) > self.thread1.start() > # self.thread1.setDaemon(1) > else: > print 'main thread to handle' > pass > > def draw(self): > self.root = Tk() > w = Button(self.root, text='Exit', command=self.root.quit) > w.pack() > self.root.mainloop() > > ### > ### Main routine > ### > > def main(): > subp = 'multip' > if len(sys.argv) >= 2: > if not sys.argv[1] in ['multip', 'thread', 'none',]: > print 'Invalid option: %s' % sys.argv[1] > print "Valid options are 'multip', 'thread', 'none'" > sys.exit(1) > else: > subp = sys.argv[1] > panel = Panel(subp) > if subp == 'none': > panel.draw() > while 1: > time.sleep(1) > pass > > if __name__ == '__main__': > main() It is just a guess, but did you try making 'draw' a function and not a method? I read that parameters to the subprocess function shall be pickable; in your test program, 'draw' as 'self' as parameter, which is a Tkinter.Panel, and I read somewhere that Tkinter objects are not pickable ... Ciao FB -- http://mail.python.org/mailman/listinfo/python-list
Re: How complex is complex?
2009/3/20 Hendrik van Rooyen : > A joke based on the Monty Python series is BY DEFINITION not stupid! But may get /too/ silly. -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
Re: How complex is complex?
Tim Roberts wrote: > bearophileh...@lycos.com wrote: >> >>In Python 3 those lines become shorter: >> >>for k, v in a.items(): >>{k: v+1 for k, v in a.items()} > > That's a syntax I have not seen in the 2-to-3 difference docs, so I'm not > familiar with it. How does that cause "a" to be updated? I think he would write >>> a = { 'a': 4, 'c': 6, 'b': 5 } >>> a = { k:v+1 for k, v in a.items() } >>> a {'a': 5, 'c': 7, 'b': 6} -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use self-inspection to check for try-block
On Fri, Mar 20, 2009 at 2:09 AM, wrote: > On Mar 20, 9:44 am, Chris Rebert wrote: >> On Fri, Mar 20, 2009 at 1:32 AM, wrote: >> > Hi everyone, >> >> > is there a sufficiently easy possibility for a Python function to find >> > out whether it has been called from a try-block or not? >> >> > try: >> > print "Calling foo" >> > foo() >> > except: >> > print "Got exception" >> >> > In the example above, foo() should be able to 'see' that it was called >> > from a try block, allowing it to behave differently. >> >> > Can this information be obtained from the traceback/frame/code >> > objects, or is that too difficult? >> >> It might be possible, but it seems like there ought to be a better way >> to accomplish your goal. Could you explain why you want to do this in >> the first place? Perhaps a better alternative can be found. > > Well, foo() communicates with another application using sockets, and > an exception might occur in the other application. For performance > reasons, foo() normally returns before the other application has > finished execution, unless foo() is forced to wait for the result. > This can for example be achieved by using foo()'s return value (foo() > uses self-inspection to see if its return value is discarded or not). > > I also want foo() to wait in case it's in a try block, so that the > user can catch exceptions that occur in the other application. Is there any reason you can't just add a parameter (e.g. 'wait') to foo() to tell it whether to wait for the exception or not? It's certainly less magical than detecting `try` in the caller. Cheers, Chris -- I have a blog: http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
"Bruce C. Miller" writes: > On Mar 7, 6:52 pm, Xah Lee wrote: >> Of interest: >> >> • Why Can't You Be Normal? > > Though I doubt this will do any good, I'll offer some advice that > hasn't been mentioned here and solved a lot of the problems I've had > early in life with resistance to overly-emotional negative reactions > to my opinions. > > Say a person spends a great deal of time and energy researching some > topic and, based upon the evidence uncovered, comes to a conclusion > about it that is contrary to the established position within a > community, like, that RMS is a crackpot, as a simple example, which is > something I happen to agree with but that won't win many friends in > #emacs. Now, you could go in #emacs and declare your discovery of this > important fact (and, if true, it is important, since RMS is > influential), but what do you suppose will happen? People will think about it a lot and decide that our society could greatly benefit from increasing the number of crackpots. The non-crackpots come and go without leaving much of a trace. However, being a crackpot is not sufficient in itself (this probably being more of a side effect rather than the main gist), so the message might not actually be helpful. So what is there to gain? -- David Kastrup -- http://mail.python.org/mailman/listinfo/python-list
PEP 3143: Standard daemon process library (was: Writing a well-behaved daemon)
Ben Finney writes: > Writing a Python program to become a Unix daemon is relatively > well-documented: there's a recipe for detaching the process and > running in its own process group. However, there's much more to a > Unix daemon than simply detaching. […] > My searches for such functionality haven't borne much fruit though. > Apart from scattered recipes, none of which cover all the essentials > (let alone the optional features) of 'daemon', I can't find anything > that could be relied upon. This is surprising, since I'd expect this > in Python's standard library. I've submitted PEP 3143 http://www.python.org/dev/peps/pep-3143/> to meet this need, and have re-worked an existing library into a new ‘python-daemon’ http://pypi.python.org/pypi/python-daemon/> library, the reference implementation. Now I need wider testing and scrutiny of the implementation and specification. One point to note: This is only intended to address the task of a program transforming *itself* into a daemon process. If you want to spawn off *extra* processes and manage them through a “service” channel, you want something this spec was never meant to cover. You may be interested in discussing that further on a separate thread at http://mail.python.org/pipermail/python-ideas/2009-January/002606.html>. If you want to turn your program into a well-behaved daemon process, I'd like to know how well PEP 3143 works for you. Please try it out for your daemon programs and discuss! -- \“The whole area of [treating source code as intellectual | `\property] is almost assuring a customer that you are not going | _o__) to do any innovation in the future.” —Gary Barnett | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Use of HTMLparser to change language
Greetings All, I have huge number of HTML files, all in english. I also have their counterpart files in Spanish. The non english files have their look and feel a little different than their english counterpart. My task is to make sure that the English HTML files contain the Spanish text, with retaining the English look and feel. The most obvious and stupid way is to open the English and Spanish files in some HTML Editor. Look for the english text, see its counterpart in spanish and then replace it. (I don't know spanish, but as i said the look and feel is only little different, so i can easily guess which text is what + google translate). I am sure there is a python way of solving this problem. Can anyone help me out with some solution. Thanks, Pranny -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of HTMLparser to change language
On Fri, Mar 20, 2009 at 9:59 AM, pranav wrote: > Greetings All, > > I have huge number of HTML files, all in english. I also have their > counterpart files in Spanish. The non english files have their look > and feel a little different than their english counterpart. > > My task is to make sure that the English HTML files contain the > Spanish text, with retaining the English look and feel. > > The most obvious and stupid way is to open the English and Spanish > files in some HTML Editor. Look for the english text, see its > counterpart in spanish and then replace it. (I don't know spanish, but > as i said the look and feel is only little different, so i can easily > guess which text is what + google translate). > > I am sure there is a python way of solving this problem. > > Can anyone help me out with some solution. > > Thanks, > > Pranny > -- > http://mail.python.org/mailman/listinfo/python-list > If you have things like unique div ids for where the text is (and the ids are the same, or you can make them the same), you could use something like BeautifulSoup to replace the english stuff programatically. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need guidelines to show results of a process
On Mar 20, 1:00 am, Vizcayno wrote: > Hi: > I wrote a Python program which, during execution, shows me messages on > console indicating at every moment the time and steps being performed > so I can have a 'log online' and guess remaining time for termination, > I used many 'print' instructions to show those messages, i.e. print > "I am in step 4 at "+giveTime() print "I am in step 5 at > "+giveTime(), etc. > Now I need to execute the same program but from a GUI application. I > must show the same messages but on a "text field". > As you can guess, it implies the changing of my program or make a copy > and replace the print instructions by textField += "I am in step 4 > at "+giveTime() then textField += "I am in step 5 at "+giveTime(), > etc. > I wanted to do the next: > if output == "GUI": > textField += "I am in step 4 at "+giveTime() > force_output() > else: > print "I am in step 4 at "+giveTime() > But it is not smart, elegant, clean ... isn't it? > Any ideas please? > Regards. If you have many sparse print and you don't want to change all by hand, you can try redirecting sys.stdout (and maybe sys.stderr) to something that collects the output and make it available for display however you like it. The only requirement is that your sys.output replacement shall have a 'write' method wich accept a string parameter. I did it once I needed to quickly add a GUI (Tkinter) to a console- based program, and it worked well. IIRC the wxPython toolkit does that by default, unless you tell it differently, and displays any output/error in a default dialog window. Ciao FB -- http://mail.python.org/mailman/listinfo/python-list
Re: Obtaining the attributes and properties of a folder recursively.
On Mar 20, 1:58 pm, Tino Wildenhain wrote: > venutaurus...@gmail.com wrote: > > Hello all, > > Is there any way to list out all the properties (name, > > type, size) and attributes( Accesstime, mod time, archived or readonly > > etc) of a folder and its contents recursively. Should I need ot go > > inside each and every directory to list them? This has to be for > > Windows. > > I have to obtain the following attriubtes of all the files > > recursively in a directory: > > > NAME\ FILE CREATION TIME \ MODIFICATION TIME \ ACCESS TIME \ > > ATTRIBUTES \ ACLs \ File SIze \ > > Just some hints you might want to check: > > os.walk > > >>> help(os.walk) > > and os.stat > > please see the example for os.walk - this > would work on every platform supported by > python. > > for acls, a little more work would be needed > if you want something filesystem specific but > posix style information is included with stat() > > Regards > Tino > > smime.p7s > 4KViewDownload Thanks for your suggestion. By the way the attachment which have added has some unknown file extension. May I know how can I view it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Obtaining the attributes and properties of a folder recursively.
venutaurus...@gmail.com wrote: Hello all, Is there any way to list out all the properties (name, type, size) and attributes( Accesstime, mod time, archived or readonly etc) of a folder and its contents recursively. Should I need ot go inside each and every directory to list them? This has to be for Windows. I have to obtain the following attriubtes of all the files recursively in a directory: NAME\ FILE CREATION TIME \ MODIFICATION TIME \ ACCESS TIME \ ATTRIBUTES \ ACLs \ File SIze \ If you feel like living dangerously, try my in-progress-but-already-working Winsys package: http://timgolden.me.uk/python/downloads/WinSys-0.3dev.win32.exe and do the following: from winsys import fs for f in fs.flat ("c:/temp"): f.dump () TJG -- http://mail.python.org/mailman/listinfo/python-list
distutils compiler flags for extension modules
Hoi, as I got no answers with the previous question (subject: disabling compiler flags in distutils), I thought I should ask the question in a different way: Is there an option to set the compiler flags for a C/C++ extension in distutils? There is the extra_compile_args-option in the Extension class, yet this offers only to give additional flags, but I'd like to have 'total' control about the compile args. Any hint? Thanks Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use self-inspection to check for try-block
On Mar 20, 9:44 am, Chris Rebert wrote: > On Fri, Mar 20, 2009 at 1:32 AM, wrote: > > Hi everyone, > > > is there a sufficiently easy possibility for a Python function to find > > out whether it has been called from a try-block or not? > > > try: > > print "Calling foo" > > foo() > > except: > > print "Got exception" > > > In the example above, foo() should be able to 'see' that it was called > > from a try block, allowing it to behave differently. > > > Can this information be obtained from the traceback/frame/code > > objects, or is that too difficult? > > It might be possible, but it seems like there ought to be a better way > to accomplish your goal. Could you explain why you want to do this in > the first place? Perhaps a better alternative can be found. Well, foo() communicates with another application using sockets, and an exception might occur in the other application. For performance reasons, foo() normally returns before the other application has finished execution, unless foo() is forced to wait for the result. This can for example be achieved by using foo()'s return value (foo() uses self-inspection to see if its return value is discarded or not). I also want foo() to wait in case it's in a try block, so that the user can catch exceptions that occur in the other application. Thanks, Elmar -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 3143: Standard daemon process library
Ben Finney writes: > I've submitted PEP 3143 http://www.python.org/dev/peps/pep-3143/> > to meet this need, and have re-worked an existing library into a new > ‘python-daemon’ http://pypi.python.org/pypi/python-daemon/> > library, the reference implementation. > > Now I need wider testing and scrutiny of the implementation and > specification. PEP: 3143 Title: Standard daemon process library Version: $Revision: 1.1 $ Last-Modified: $Date: 2009-03-19 12:51 $ Author:Ben Finney Status:Draft Type: Standards Track Content-Type: text/x-rst Created: 2009-01-26 Python-Version:3.2 Post-History: Abstract Writing a program to become a well-behaved Unix daemon is somewhat complex and tricky to get right, yet the steps are largely similar for any daemon regardless of what else the program may need to do. This PEP introduces a package to the Python standard library that provides a simple interface to the task of becoming a daemon process. .. contents:: .. Table of Contents: Abstract Specification Example usage Interface ``DaemonContext`` objects Motivation Rationale Correct daemon behaviour A daemon is not a service Reference Implementation Other daemon implementations References Copyright = Specification = Example usage = Simple example of direct `DaemonContext` usage:: import daemon from spam import do_main_program with daemon.DaemonContext() as daemon_context: do_main_program() More complex example usage:: import os import grp import signal import daemon import lockfile from spam import ( initial_program_setup, do_main_program, program_cleanup, reload_program_config, ) context = daemon.DaemonContext( working_directory='/var/lib/foo', umask=0o002, pidfile=lockfile.FileLock('/var/run/spam.pid'), ) context.signal_map = { signal.SIGTERM: program_cleanup, signal.SIGHUP: 'terminate', signal.SIGUSR1: reload_program_config, } mail_gid = grp.getgrnam('mail').gr_gid context.gid = mail_gid important_file = open('spam.data', 'w') interesting_file = open('eggs.data', 'w') context.files_preserve = [important_file, interesting_file] initial_program_setup() with context: do_main_program() Interface = A new package, `daemon`, is added to the standard library. A class, `DaemonContext`, is defined to represent the settings and process context for the program running as a daemon process. ``DaemonContext`` objects = A `DaemonContext` instance represents the behaviour settings and process context for the program when it becomes a daemon. The behaviour and environment is customised by setting options on the instance, before calling the `open` method. Each option can be passed as a keyword argument to the `DaemonContext` constructor, or subsequently altered by assigning to an attribute on the instance at any time prior to calling `open`. That is, for options named `wibble` and `wubble`, the following invocation:: foo = daemon.DaemonContext(wibble=bar, wubble=baz) foo.open() is equivalent to:: foo = daemon.DaemonContext() foo.wibble = bar foo.wubble = baz foo.open() The following options are defined. `files_preserve` :Default: ``None`` List of files that should *not* be closed when starting the daemon. If ``None``, all open file descriptors will be closed. Elements of the list are file descriptors (as returned by a file object's `fileno()` method) or Python `file` objects. Each specifies a file that is not to be closed during daemon start. `chroot_directory` :Default: ``None`` Full path to a directory to set as the effective root directory of the process. If ``None``, specifies that the root directory is not to be changed. `working_directory` :Default: ``'/'`` Full path of the working directory to which the process should change on daemon start. Since a filesystem cannot be unmounted if a process has its current working directory on that filesystem, this should either be left at default or set to a directory that is a sensible “home directory” for the daemon while it is running. `umask` :Default: ``0`` File access creation mask (“umask”) to set for the process on daemon start. Since a process inherits its umask from its parent process, starting the daemon will reset the umask to this value so that files are created by the daemon with access modes as it expects. `pidfile` :Default: ``None`` Context manager for a PID lock file. When the daemon context opens and closes, it enters and exits the `pidfile` context manager. `detach_pr
locate items in matrix (index of lists of lists)
Hello there, let's suppose I have the following matrix: mat = [[1,2,3], [3,2,4], [7,8,9], [6,2,9]] where [.. , .. , ..] are the rows. I am interested into getting the "row index" of all the matrix rows where a certain number occurs. For example for 9 I should get 2 and 3 (starting from 0). For 10 I should get an error msg (item not found) and handle it. How to get the"row indexes" of found items? In practice I am looking for an equivalent to "list.index(x)" for the case "lists of lists" Many Thanks! Alex PS: this is just a simplified example, but I have actually to deal with large matrices [~50 * 4] -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use Jython to create a javabean ???
qq13234...@gmail.com schrieb: I want to make a bean with Jython and how to make it via Jython ? By subclassing a java interface. That's all you need. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: locate items in matrix (index of lists of lists)
On Fri, Mar 20, 2009 at 3:50 AM, Alexzive wrote: > Hello there, > > let's suppose I have the following matrix: > > mat = [[1,2,3], [3,2,4], [7,8,9], [6,2,9]] > > where [.. , .. , ..] are the rows. > > I am interested into getting the "row index" of all the matrix rows > where a certain number occurs. > For example for 9 I should get 2 and 3 (starting from 0). > For 10 I should get an error msg (item not found) and handle it. > > How to get the"row indexes" of found items? indices = [i for i, row in enumerate(mat) if item in row] where item is 9, 10, or whatever you're looking for. If the item is not present in any of the sublists, indices will be empty. Also, if you're doing lots of matrix work, you might want to look into using numpy (google it). Cheers, Chris -- I have a blog: http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: locate items in matrix (index of lists of lists)
Alexzive wrote: Hello there, let's suppose I have the following matrix: mat = [[1,2,3], [3,2,4], [7,8,9], [6,2,9]] where [.. , .. , ..] are the rows. I am interested into getting the "row index" of all the matrix rows where a certain number occurs. For example for 9 I should get 2 and 3 (starting from 0). For 10 I should get an error msg (item not found) and handle it. How to get the"row indexes" of found items? In practice I am looking for an equivalent to "list.index(x)" for the case "lists of lists" Actually you are not ;) list.index(x) gives you the index of the first occurence of the item. So what you seem to want is a list of indexes to the lists where your item is contained. Something like: x=9 [idx for idx,row in enumerate(mat) if x in row] should do. PS: this is just a simplified example, but I have actually to deal with large matrices [~50 * 4] This is something I'd consider either reordering your data (for example into dictionary) or look at scipy/numpy. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode problem in ucs4
On Mar 20, 11:03 am, "Martin v. Löwis" wrote: > > Any idea on why this is happening? > > Can you provide a complete example? Your code looks correct, and should > just work. > > How do you know the result contains only 't' (i.e. how do you know it > does not contain 'e', 's', 't')? > > Regards, > Martin Hi Martin, Here is the code: unicodeTest.c #include static PyObject *unicode_helper(PyObject *self,PyObject *args){ PyObject *sampleObj = NULL; Py_UNICODE *sample = NULL; if (!PyArg_ParseTuple(args, "O", &sampleObj)){ return NULL; } // Explicitly convert it to unicode and get Py_UNICODE value sampleObj = PyUnicode_FromObject(sampleObj); sample = PyUnicode_AS_UNICODE(sampleObj); wprintf(L"database value after unicode conversion is : %s\n", sample); return Py_BuildValue(""); } static PyMethodDef funcs[]={{"unicodeTest",(PyCFunction) unicode_helper,METH_VARARGS,"test ucs2, ucs4"},{NULL}}; void initunicodeTest(void){ Py_InitModule3("unicodeTest",funcs,""); } When i install this unicodeTest on python ucs2 wprintf prints whatever is passed eg import unicodeTest unicodeTest.unicodeTest("hello world") database value after unicode conversion is : hello world but it prints the following on ucs4 configured python: database value after unicode conversion is : h Regards, Abhigyan -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of HTMLparser to change language
pranav wrote: I am sure there is a python way of solving this problem. The common sense approach (nothing to do with python) would be to rewrite everything to be dynamically generated with a template language - in python those would be TAL, mako, genshi, jinja, whatever ... anything is better than the current solution. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use self-inspection to check for try-block
On Mar 20, 10:16 am, Chris Rebert wrote: > On Fri, Mar 20, 2009 at 2:09 AM, wrote: > > On Mar 20, 9:44 am, Chris Rebert wrote: > >> On Fri, Mar 20, 2009 at 1:32 AM, wrote: > >> > Hi everyone, > > >> > is there a sufficiently easy possibility for a Python function to find > >> > out whether it has been called from a try-block or not? > > >> > try: > >> > print "Calling foo" > >> > foo() > >> > except: > >> > print "Got exception" > > >> > In the example above, foo() should be able to 'see' that it was called > >> > from a try block, allowing it to behave differently. > > >> > Can this information be obtained from the traceback/frame/code > >> > objects, or is that too difficult? > > >> It might be possible, but it seems like there ought to be a better way > >> to accomplish your goal. Could you explain why you want to do this in > >> the first place? Perhaps a better alternative can be found. > > > Well, foo() communicates with another application using sockets, and > > an exception might occur in the other application. For performance > > reasons, foo() normally returns before the other application has > > finished execution, unless foo() is forced to wait for the result. > > This can for example be achieved by using foo()'s return value (foo() > > uses self-inspection to see if its return value is discarded or not). > > > I also want foo() to wait in case it's in a try block, so that the > > user can catch exceptions that occur in the other application. > > Is there any reason you can't just add a parameter (e.g. 'wait') to > foo() to tell it whether to wait for the exception or not? It's > certainly less magical than detecting `try` in the caller. > The system is used by people who don't know about these technical details, and the goal is to hide the complexity from the user, without having to explain when to add a 'wait' parameter etc. Anyway, thanks for your time. I'll dig something out... Ciao, Elmar -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use self-inspection to check for try-block
el...@cmbi.ru.nl schrieb: On Mar 20, 10:16 am, Chris Rebert wrote: On Fri, Mar 20, 2009 at 2:09 AM, wrote: On Mar 20, 9:44 am, Chris Rebert wrote: On Fri, Mar 20, 2009 at 1:32 AM, wrote: Hi everyone, is there a sufficiently easy possibility for a Python function to find out whether it has been called from a try-block or not? try: print "Calling foo" foo() except: print "Got exception" In the example above, foo() should be able to 'see' that it was called from a try block, allowing it to behave differently. Can this information be obtained from the traceback/frame/code objects, or is that too difficult? It might be possible, but it seems like there ought to be a better way to accomplish your goal. Could you explain why you want to do this in the first place? Perhaps a better alternative can be found. Well, foo() communicates with another application using sockets, and an exception might occur in the other application. For performance reasons, foo() normally returns before the other application has finished execution, unless foo() is forced to wait for the result. This can for example be achieved by using foo()'s return value (foo() uses self-inspection to see if its return value is discarded or not). I also want foo() to wait in case it's in a try block, so that the user can catch exceptions that occur in the other application. Is there any reason you can't just add a parameter (e.g. 'wait') to foo() to tell it whether to wait for the exception or not? It's certainly less magical than detecting `try` in the caller. The system is used by people who don't know about these technical details, and the goal is to hide the complexity from the user, without having to explain when to add a 'wait' parameter etc. Anyway, thanks for your time. I'll dig something out... They can't be bothered with parameters (or a second function, name "foo_wait" that passes the wait-parameter to the first one), but they know about exception handling? Interesting people... Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Ordered Sets
Aahz wrote: In article <9a5d59e1-2798-4864-a938-9b39792c5...@s9g2000prg.googlegroups.com>, Raymond Hettinger wrote: Here's a new, fun recipe for you guys: http://code.activestate.com/recipes/576694/ That is *sick* and perverted. I'm not sure why. Would it be less sick if it had been called "UniqueList" ? n -- http://mail.python.org/mailman/listinfo/python-list
Re: locate items in matrix (index of lists of lists)
Many Thanks guys! and what if I need to look ONLY into the second and third columns, excluding the first item of each rows? for example if x = 3 I need to get [0] and not [0,1] many thanks, Alex 2009/3/20 Tino Wildenhain : > Alexzive wrote: >> >> Hello there, >> >> let's suppose I have the following matrix: >> >> mat = [[1,2,3], [3,2,4], [7,8,9], [6,2,9]] >> >> where [.. , .. , ..] are the rows. >> >> I am interested into getting the "row index" of all the matrix rows >> where a certain number occurs. >> For example for 9 I should get 2 and 3 (starting from 0). >> For 10 I should get an error msg (item not found) and handle it. >> >> How to get the"row indexes" of found items? >> >> In practice I am looking for an equivalent to "list.index(x)" for the >> case "lists of lists" > > Actually you are not ;) list.index(x) gives you the index of the > first occurence of the item. > > So what you seem to want is a list of indexes to the lists where > your item is contained. > > Something like: > > x=9 > > [idx for idx,row in enumerate(mat) if x in row] > > should do. > >> >> >> PS: this is just a simplified example, but I have actually to deal >> with large matrices [~50 * 4] > > This is something I'd consider either reordering your data (for example > into dictionary) or look at scipy/numpy. > > Regards > Tino > -- = Alessandro Zivelonghi Ziller Max-Planck-Institut für Plasmaphysik, Garching, DE Middle-Age Fusion Engineer === http://www.tecnopolis.eu skype: alexzive " I'm sure that in 1985 plutonium is available in every corner drug store, but in 1955 it's a little hard to come by" Dr. D.Brown -- http://mail.python.org/mailman/listinfo/python-list
file.read() doesn't read the whole file
Sreejith K wrote: > Hi, > > >>> snapdir = './mango.txt_snaps' > >>> snap_cnt = 1 > >>> block = 0 > >>> import os > >>> os.chdir('/mnt/gfs_local') > >>> snap = open(snapdir + '/snap%s/%s' % (repr(snap_cnt), repr(block)),'r') > >>> snap.read() > 'dfdfdgagdfgdf\ngdgfadgagadg\nagafg\n\nfs\nf\nsadf\n\nsdfsdfsadf\n' > >>> snapdir + '/snap%s/%s' % (repr(snap_cnt), repr(block)) > './mango.txt_snaps/snap1/0' > > The above code works fine and it reads the whole file till EOF. But > when this method is used in a different scenario the file is not read > completely. I'll post the code that read only some part of the file... > > self.snap = open(self.snapdir + '/snap%d/%d' % (self.snap_cnt, > block),'r') ## opens /mnt/gfs_local/mango.txt_snaps/snap1/0 > self.snap.seek(off%4096) ## seeks to 0 in this case > bend = 4096-(off%4096) ## 4096 in this case > if length-bend <= 0:## true in this case as length is 4096 > tf.writelines("returned \n") > data = self.snap.read(length) > self.snap.close() > break > > the output data is supposed to read the whole fie but it only reads a > part of it. Why is it encountering an early EOF ? It's not. In the second case you told it to read only 4096 bytes. You might want to read the docs for the 'read' method, paying particular attention to the optional argument and its meaning. -- R. David Murray http://www.bitdance.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of HTMLparser to change language
On Mar 20, 3:53 pm, Marco Mariani wrote: > pranav wrote: > > I am sure there is a python way of solving this problem. > > The common sense approach (nothing to do with python) would be to > rewrite everything to be dynamically generated with a template language > - in python those would be TAL, mako, genshi, jinja, whatever ... > anything is better than the current solution. Hmm ya, that is THE best thing, if this were an application. These are plain HTML files and needs to be shipped with CDs. Also, it is not in the design to use anything executable. -- http://mail.python.org/mailman/listinfo/python-list
Re: locate items in matrix (index of lists of lists)
On Fri, Mar 20, 2009 at 4:34 AM, Alessandro Zivelonghi wrote: > Many Thanks guys! > > and what if I need to look ONLY into the second and third columns, > excluding the first item of each rows? > > for example if x = 3 I need to get [0] and not [0,1] indices = [i for i, row in enumerate(mat) if 1<= i <= 2 and 3 in row[1:]] Cheers, Chris -- I have a blog: http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Preparing teaching materials
I am considering teaching a beginning programming course using Python. I would like to prepare my class handouts in such a way that I can import the Python code from real ".py" files directly into the documents. This way I can run real unit tests on the code to confirm that they work as expected. I am considering using LaTeX to write the handouts and then converting them to PDF files. I will probably use a Makefile to convert the LaTeX with embedded Python code into the PDF files using pdflatex. I will probably organize my directory structure into sub-directories py-src, py-test, doc-src, and doc-dist. I will be starting out using Windows Vista/cygwin and hopefully switch to a Macbook this summer. Any thoughts? -- http://mail.python.org/mailman/listinfo/python-list
Re: Obtaining the attributes and properties of a folder recursively.
Tim Golden wrote: ... and do the following: from winsys import fs for f in fs.flat ("c:/temp"): f.dump () ^ eeek! But btw, what extra information would it give? Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Obtaining the attributes and properties of a folder recursively.
venutaurus...@gmail.com wrote: On Mar 20, 1:58 pm, Tino Wildenhain wrote: venutaurus...@gmail.com wrote: Hello all, ... smime.p7s 4KViewDownload Thanks for your suggestion. By the way the attachment which have added has some unknown file extension. May I know how can I view it? This is something your mail user agent should correctly handle for you, its nothing to view really, its my electronic signature for the message. You can learn more about it here: http://www.thawte.com/secure-email/personal-email-certificates/ HTH Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Obtaining the attributes and properties of a folder recursively.
Tino Wildenhain wrote: Tim Golden wrote: ... and do the following: from winsys import fs for f in fs.flat ("c:/temp"): f.dump () ^ eeek! Was the k! for the space before the bracket (which, for some unaccountable reason disturbs some people)? Or for the idea of dumping data out? This is what it looks like for one (random) file: Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC Type "help", "copyright", "credits" or "license" for from winsys import fs fs.file ("c:/temp/t.py").dump () { c:\temp\t.py { c:\temp\t.py parts: [u'?\\c:\\', u'temp', u't.py'] root: \\?\c:\ dirname: \temp path: \\?\c:\\temp filename: t.py parent: \\?\c:\temp } readable: True id: 260191347677670224354611 n_links: 1 created_at: 2008-10-27 09:45:09 accessed_at: 2009-03-20 08:57:25 written_at: 2009-03-20 08:57:25 uncompressed_size: 1170 size: 1170 Attributes: { ARCHIVE => True COMPRESSED => False DIRECTORY => False ENCRYPTED => False HIDDEN => False NORMAL => False NOT_CONTENT_INDEXES => False OFFLINE => False READONLY => False REPARSE_POINT => False SPARSE_FILE => False SYSTEM => False TEMPORARY => False VIRTUAL => False } Security: control: { DACL_AUTO_INHERITED SELF_RELATIVE DACL_PRESENT } owner: VOUK\goldent dacl: { inherited: True { trustee: VOUK\goldent access: 1000 type: ACCESS_ALLOWED } { trustee: BUILTIN\Administrators access: 1000 type: ACCESS_ALLOWED flags: { INHERITED } } { trustee: NT AUTHORITY\SYSTEM access: 1000 type: ACCESS_ALLOWED flags: { INHERITED } } { trustee: VOUK\goldent access: 1000 type: ACCESS_ALLOWED flags: { INHERITED } } { trustee: BUILTIN\Users access: 100101010100 type: ACCESS_ALLOWED flags: { INHERITED } } } } TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
On Mar 7, 6:52 pm, Xah Lee wrote: > Of interest: > > • Why Can't You Be Normal? Though I doubt this will do any good, I'll offer some advice that hasn't been mentioned here and solved a lot of the problems I've had early in life with resistance to overly-emotional negative reactions to my opinions. Say a person spends a great deal of time and energy researching some topic and, based upon the evidence uncovered, comes to a conclusion about it that is contrary to the established position within a community, like, that RMS is a crackpot, as a simple example, which is something I happen to agree with but that won't win many friends in #emacs. Now, you could go in #emacs and declare your discovery of this important fact (and, if true, it is important, since RMS is influential), but what do you suppose will happen? Will your message's recipients, upon hearing this news, examine your evidence, spend a few days questioning their own beliefs, then thank you for aligning their thoughts more closely with reality? It's possible, but chances are you'll just be greeted with a bunch of knee-jerk defensive reactions. So, let me offer to you a notion that maybe you haven't considered: who cares what other people think? Sure, it's a noble cause to spread your ideas or at least get them out there in the public discourse, even if they're wrong, but have some realistic expectations as to your opinion's impact. I happen to think that the "common wisdom" about most things is typically anything but wise, and often completely incorrect, but I don't view it as my duty on Earth to convince the world that MS bashing, socialism, religion, etc are stupid. If asked, I'll offer my opinion and reasoning for it, but if the other person remains unconvinced, it's his loss. All this said, as someone that hangs out in some of the IRC channels you've been banned from, and having read the logs that resulted in your banning, it's pretty obvious you've got other problems on top of this. As often cited, your propensity for monologuing, for one. IRC, Usenet, and such are conversational mediums, while you fail to make the distinction between them and writing on your website. If you just want to make declarations and honestly have nothing to learn from others, then these are the wrong outlets for you. Your awkward grasp of the English language doesn't help either. If you want to communicate ideas, it can only help to master the language in which these ideas are encoded (think about some of the things you have said yourself about the importance of standard protocols). And, most importantly, while I don't think you're an idiot by any means, you are obviously very lacking in the realm of emotional maturity. The spectacle you've made of yourself with this thread is proof enough of this. You are a grown man, take whatever time you need to stare at yourself in the mirror until you realize this and become determined to act like one. -- http://mail.python.org/mailman/listinfo/python-list
Re: Lambda forms and scoping
Benjamin Peterson wrote: > Márcio Faustino gmail.com> writes: > > > > Executing the example below doesn't produce the expected behavior, but > > using the commented code does. Is this normal, or is it a problem with > > Python? I've tested it with version 2.6.1 on Windows XP. > > > > Thanks, > > > > -- > > > > from abc import * > > from types import * > > import re > > > > class Base (ObjectType): > > __metaclass__ = ABCMeta > > > > def __init__(self): > > for option in self.get_options().keys(): > > method = 'get_%s_option' % re.sub(' ', '_', option.lower > > ()) > > setattr(self.__class__, method, lambda self: > > self.get_option(option)) > > This is because the closure over option is changed when it is reassigned in > the > for loop. For example: > > >>> def f(): > ... return [lambda: num for num in xrange(2)] > ... > >>> f() > [ at 0x83f30>, at 0x83e70>] > >>> f()[0] > at 0x83ef0> > >>> g = f() > >>> g[0]() > 1 > >>> g[1]() > 1 Here's the way I find it useful to think about this: When your lambda is created in your for loop inside your __init__ method, it acquires a pointer to __init__'s local namespace. (That's how I understand what "closure" means in this case, though I imagine "closure" probably means something slightly different in computer-science-ese :) So, when any of those lambdas is executed, they all have a pointer to the exact same namespace, that of __init__. And when they are called, __init__'s namespace is in whatever state it was left in when __init__ ended. In this case, that means that 'option' is pointing to the value it had at the _end_ of the for loop. Hope this helps. I find that thinking in terms of namespaces helps me understand how Python works better than any other mental model I've come across. -- R. David Murray http://www.bitdance.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't this work ? For loop variable scoping ?
En Thu, 19 Mar 2009 19:33:36 -0300, Ryan Kelly escribió: newCylinderTempertature = newCylinderTemperature + deltaTemp Take a careful look at the variable name here: "Tempertature". Python's dynamic nature provides a lot of wonderful benefits, but you've just hit one of the drawbacks - you don't get any protection from typos in variable names. There are some tools that mitigate the problem: pylint and pychecker would emit a warning in this case ("name is used only once" or similar), and the autocompletion feature -present in most IDE / specialized editors- avoids one to re-type the name over and over. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of HTMLparser to change language
pranav wrote: On Mar 20, 3:53 pm, Marco Mariani wrote: pranav wrote: I am sure there is a python way of solving this problem. The common sense approach (nothing to do with python) would be to rewrite everything to be dynamically generated with a template language - in python those would be TAL, mako, genshi, jinja, whatever ... anything is better than the current solution. Hmm ya, that is THE best thing, if this were an application. These are plain HTML files and needs to be shipped with CDs. Also, it is not in the design to use anything executable. No need, you can use the executable on your end to generate the static files using the templates. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of HTMLparser to change language
2009/3/20 pranav : > Greetings All, > > I have huge number of HTML files, all in english. I also have their > counterpart files in Spanish. The non english files have their look > and feel a little different than their english counterpart. > > My task is to make sure that the English HTML files contain the > Spanish text, with retaining the English look and feel. > ... > > Pranny > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, I guess, this task can probably not be solved fully automatically unless there is some exact structure of the HTML, but it doesn't seem likely. If you would prefer to work with static sources, you can try to identify the differences in the markup of english and spanish pages. e.g. using BeautifulSoup http://www.crummy.com/software/BeautifulSoup/ or at least approximately with regular expressions, e.g.: tags_only_source = re.findall(r"<[^>]+>", html_source) should return the tags source for simple code (neglecting nesting, commented code, strings containing tags source ...) the difflib library then could help in identifying the differences in code, cf: http://docs.python.org/library/difflib.html >>> for difference in difflib.ndiff("abcadefsdf", "abQcadsdfAA"): print >>> difference ... a b + Q c a d - e - f s d f + A + A (sample strings used here as arguments for ndiff can also be lists of strings returned by findall() above.) If you are lucky and the differences are rather small and regular, you can then try to modify the markup in the spanish pages to be more similar to the english ones; again possibly using BeautifulSoup or even re.sub(...) (of course, saving the modified sources as new files in some other directory) (The opposite - taking the english markup and feeding it with english text - would be more tricky, I guess.) However, all that is likely to help only with the part of the task, which will almost certainly require, more or less "manual" work. Someone more experienced can probably propose a more effective approach... hth, vbr -- http://mail.python.org/mailman/listinfo/python-list
Re: Preparing teaching materials
Michele Simionato wrote: On Mar 20, 12:58 pm, grkunt...@gmail.com wrote: I am considering teaching a beginning programming course using Python. I would like to prepare my class handouts in such a way that I can import the Python code from real ".py" files directly into the documents. This way I can run real unit tests on the code to confirm that they work as expected. I am considering using LaTeX to write the handouts and then converting them to PDF files. I will probably use a Makefile to convert the LaTeX with embedded Python code into the PDF files using pdflatex. I will probably organize my directory structure into sub-directories py-src, py-test, doc-src, and doc-dist. I will be starting out using Windows Vista/cygwin and hopefully switch to a Macbook this summer. Any thoughts? One word: Sphinx. And the second word(s): .. literalinclude:: example.py TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Lambda forms and scoping
On Mar 19, 10:52 pm, Márcio Faustino wrote: > Hi, > > Executing the example below doesn't produce the expected behavior, but > using the commented code does. Is this normal, or is it a problem with > Python? It is a common gotcha. Notice that it has nothing to do with lambda functions, you would get the same issue with regular functions. This post http://www.artima.com/forums/flat.jsp?forum=106&thread=251156 and especially the comments below should share some light on why it is the way it is (short answer: for loops are implemented by mutating the loop variable at each iteration). -- http://mail.python.org/mailman/listinfo/python-list
speech recognition help
hi all.. I want* to add speech recognition *to my application for *disabled persons*. (running in python 2.6 with wxpython 2.8.9..) *problem:* actually i have some buttons scanned one by one.. button name is 'add' and if i tell 'add' then add button click event must be performed.. For that i need the conversion of *speech to text.* Tell me the right advice and necessary links to implement this... Advanced thanks...! -- http://mail.python.org/mailman/listinfo/python-list
Re: Lambda forms and scoping
So simple :) thanks! -- http://mail.python.org/mailman/listinfo/python-list
How to use Jython to create a javabean ???
I want to make a bean with Jython and how to make it via Jython ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode problem in ucs4
On 2009-03-20 12:13, abhi wrote: > On Mar 20, 11:03 am, "Martin v. Löwis" wrote: >>> Any idea on why this is happening? >> Can you provide a complete example? Your code looks correct, and should >> just work. >> >> How do you know the result contains only 't' (i.e. how do you know it >> does not contain 'e', 's', 't')? >> >> Regards, >> Martin > > Hi Martin, > Here is the code: > unicodeTest.c > > #include > > static PyObject *unicode_helper(PyObject *self,PyObject *args){ > PyObject *sampleObj = NULL; > Py_UNICODE *sample = NULL; > > if (!PyArg_ParseTuple(args, "O", &sampleObj)){ > return NULL; > } > >// Explicitly convert it to unicode and get Py_UNICODE value > sampleObj = PyUnicode_FromObject(sampleObj); > sample = PyUnicode_AS_UNICODE(sampleObj); > wprintf(L"database value after unicode conversion is : %s\n", > sample); You have to use PyUnicode_AsWideChar() to convert a Python Unicode object to a wchar_t representation. Please don't make any assumptions on what Py_UNICODE maps to and always use the the Unicode API for this. It is designed to provide a portable interface and will not do more conversion work than necessary. > return Py_BuildValue(""); > } > > static PyMethodDef funcs[]={{"unicodeTest",(PyCFunction) > unicode_helper,METH_VARARGS,"test ucs2, ucs4"},{NULL}}; > > void initunicodeTest(void){ > Py_InitModule3("unicodeTest",funcs,""); > } > > When i install this unicodeTest on python ucs2 wprintf prints whatever > is passed eg > > import unicodeTest > unicodeTest.unicodeTest("hello world") > database value after unicode conversion is : hello world > > but it prints the following on ucs4 configured python: > database value after unicode conversion is : h > > Regards, > Abhigyan > -- > http://mail.python.org/mailman/listinfo/python-list -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Mar 20 2009) >>> Python/Zope Consulting and Support ...http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Can I rely on...
alex23 wrote: > On Mar 20, 1:42 am, "Emanuele D'Arrigo" wrote: > > I just had a bit of a shiver for something I'm doing often in my code > > but that might be based on a wrong assumption on my part. Take the > > following code: > > > > pattern = "aPattern" > > > > compiledPatterns = [ ] > > compiledPatterns.append(re.compile(pattern)) > > > > if(re.compile(pattern) in compiledPatterns): > > print("The compiled pattern is stored.") > > Others have discussed the problem with relying on the compiled RE > objects being the same, but one option may be to use a dict instead of > a list and matching on the pattern string itself: > > compiledPatterns = { } > if pattern not in compiledPatterns: > compiledPatterns[pattern] = re.compile(pattern) > else: > print("The compiled pattern is stored.") FYI this is almost exactly the approach the re module takes to caching the expressions. (The difference is re adds a type token to the front of the key.) -- R. David Murray http://www.bitdance.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Preparing teaching materials
On Mar 20, 12:58 pm, grkunt...@gmail.com wrote: > I am considering teaching a beginning programming course using Python. > I would like to prepare my class handouts in such a way that I can > import the Python code from real ".py" files directly into the > documents. This way I can run real unit tests on the code to confirm > that they work as expected. > > I am considering using LaTeX to write the handouts and then converting > them to PDF files. I will probably use a Makefile to convert the LaTeX > with embedded Python code into the PDF files using pdflatex. > > I will probably organize my directory structure into sub-directories > py-src, py-test, doc-src, and doc-dist. > > I will be starting out using Windows Vista/cygwin and hopefully switch > to a Macbook this summer. > > Any thoughts? One word: Sphinx. -- http://mail.python.org/mailman/listinfo/python-list
Re: Preparing teaching materials
On Mar 20, 1:44 pm, Tim Golden wrote: > Michele Simionato wrote: > > One word: Sphinx. > > And the second word(s): > > .. literalinclude:: example.py > > TJG The interesting thing is that Sphinx uses pygments and can highlight any code fragment, not only Python code. For instance, last week I did some experiment with Sphinx to convert my "Adventures of a Pythonista in Schemeland" (which contains Scheme code) to PDF and it worked out quite well. I have yet to fix the images, but the result after a next-to-zero effort is the following: http://www.phyast.pitt.edu/~micheles/scheme/TheAdventuresofaPythonistainSchemeland.pdf (I think the OP may be interested in how the PDF output of Sphinx-generated documents may look like). Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 3143: Standard daemon process library (was: Writing a well-behaved daemon)
On Fri, 20 Mar 2009 20:58:58 +1100, Ben Finney wrote: Ben Finney writes: Writing a Python program to become a Unix daemon is relatively well-documented: there's a recipe for detaching the process and running in its own process group. However, there's much more to a Unix daemon than simply detaching. […] My searches for such functionality haven't borne much fruit though. Apart from scattered recipes, none of which cover all the essentials (let alone the optional features) of 'daemon', I can't find anything that could be relied upon. This is surprising, since I'd expect this in Python's standard library. I've submitted PEP 3143 http://www.python.org/dev/peps/pep-3143/> to meet this need, and have re-worked an existing library into a new ‘python-daemon’ http://pypi.python.org/pypi/python-daemon/> library, the reference implementation. Now I need wider testing and scrutiny of the implementation and specification. The biggest shortcoming seems to be a complete lack of unit tests. A quick skim of the code suggests that part of it don't even work at all and have never been tested, even interactively, since they must surely fail. For example, uid/gid setting is broken. I'd recommend adding an automated test suite, fixing all the issues that come up during that process, and then asking for scrutiny again. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Lambda forms and scoping
En Fri, 20 Mar 2009 09:28:08 -0300, R. David Murray escribió: Benjamin Peterson wrote: Márcio Faustino gmail.com> writes: > > Executing the example below doesn't produce the expected behavior, but > using the commented code does. Is this normal, or is it a problem with > Python? I've tested it with version 2.6.1 on Windows XP. Here's the way I find it useful to think about this: When your lambda is created in your for loop inside your __init__ method, it acquires a pointer to __init__'s local namespace. (That's how I understand what "closure" means in this case, though I imagine "closure" probably means something slightly different in computer-science-ese :) Well, some people would say that the function "closes over" part of its environment, but that's the idea. So, when any of those lambdas is executed, they all have a pointer to the exact same namespace, that of __init__. And when they are called, __init__'s namespace is in whatever state it was left in when __init__ ended. In this case, that means that 'option' is pointing to the value it had at the _end_ of the for loop. That's a pretty good explanation -- I would just substitute "pointer" by "reference". Hope this helps. I find that thinking in terms of namespaces helps me understand how Python works better than any other mental model I've come across. Good to know! The Python execution model *is* based on namespaces - any other mental model won't be accurate past certain point (although some people insist...) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Can I rely on...
Emanuele D'Arrigo a écrit : Hi everybody, I just had a bit of a shiver for something I'm doing often in my code but that might be based on a wrong assumption on my part. Do not assume. Either check or use another solution. My 2 cents... Take the following code: pattern = "aPattern" compiledPatterns = [ ] compiledPatterns.append(re.compile(pattern)) if(re.compile(pattern) in compiledPatterns): you don't need the parens around the test. print("The compiled pattern is stored.") As you can see I'm effectively assuming that every time re.compile() is called with the same input pattern it will return the exact same object rather than a second, identical, object. In interactive tests via python shell this seems to be the case but... can I rely on it - always- being the case? Or is it one of those implementation-specific issues? I can't tell - I'm not willing to write a serious test for it. IIRC, the re module maintains a cache of already seen patterns, but I didn't bother reading the implementation. Anyway: why don't you use a dict instead, using the "source (ie : string representation) of the pattern as key ? ie: pattern = "aPattern" compiled_patterns = {} compiled_patterns[pattern] = re.compile(pattern) # ... if pattern in compiled_patterns: print("The compiled pattern is stored.") And what about any other function or class/method? Is there a way to discriminate between methods and functions that when invoked twice with the same arguments will return the same object and those that in the same circumstances will return two identical objects? Except reading the source code (hey, this is OSS, isn't it), I don't see any reliable way to know this - unless it is clearly documented of course. If the answer is no, am I right to state the in the case portrayed above the only way to be safe is to use the following code instead? for item in compiledPatterns: if(item.pattern == pattern): Once again, using a dict will be *way* more efficient. -- http://mail.python.org/mailman/listinfo/python-list
Unable to compile pyprocessing module on SUN solaris
I am trying to build package "pyprocessing" for python 2.5 I am using sun machine with Solaris 5.8 drok...@himalaya:~/modules_python/processing-0.52 (Deepak:)uname -a SunOS himalaya 5.8 Generic_117350-35 sun4u sparc SUNW,Sun-Fire While building the package I get below warnings. (Deepak:)python setup.py build Macros: HAVE_FD_TRANSFER = 1 HAVE_SEM_OPEN = 1 HAVE_SEM_TIMEDWAIT = 1 Libraries: ['rt'] running build running build_py running build_ext building 'processing._processing' extension gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_SEM_OPEN=1 -DHAVE_FD_TRANSFER=1 -DHAVE_SEM_TIMEDWAIT=1 -I/home/drokade/ess_temp/56_release/ess/3rdparty/python/solaris/include/python2.5 -c src/processing.c -o build/temp.solaris-2.8-sun4u-2.5/src/processing.o src/processing.c: In function `processing_sendfd': *src/processing.c:158: warning: implicit declaration of function `CMSG_SPACE' src/processing.c:175: warning: implicit declaration of function `CMSG_LEN' *gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_SEM_OPEN=1 -DHAVE_FD_TRANSFER=1 -DHAVE_SEM_TIMEDWAIT=1 -I/home/drokade/ess_temp/56_release/ess/3rdparty/python/solaris/include/python2.5 -c src/socket_connection.c -o build/temp.solaris-2.8-sun4u-2.5/src/socket_connection.o gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_SEM_OPEN=1 -DHAVE_FD_TRANSFER=1 -DHAVE_SEM_TIMEDWAIT=1 -I/home/drokade/ess_temp/56_release/ess/3rdparty/python/solaris/include/python2.5 -c src/semaphore.c -o build/temp.solaris-2.8-sun4u-2.5/src/semaphore.o src/semaphore.c: In function `SemLock_acquire': *src/semaphore.c:296: warning: implicit declaration of function `sem_timedwait' src/semaphore.c: In function `SemLock_new': src/semaphore.c:416: warning: int format, pid_t arg (arg 4) *gcc -shared build/temp.solaris-2.8-sun4u-2.5/src/processing.o build/temp.solaris-2.8-sun4u-2.5/src/socket_connection.o build/temp.solaris-2.8-sun4u-2.5/src/semaphore.o -lrt -o build/lib.solaris-2.8-sun4u-2.5/processing/_processing.so Though shared libraries were created, after I installed it in my python (2.5.1) I get below message while importing module 'processing" drok...@himalaya:~/modules_python/processing-0.52 (Deepak:)python Python 2.5.1 (r251:54863, Nov 27 2007, 18:27:50) [GCC 3.4.6] on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> import processing Traceback (most recent call last): File "", line 1, in File "/home/drokade/ess_temp/56_release/ess/3rdparty/python/solaris/lib/python2.5/site-packages/processing/__init__.py", line 62, in import _processing ImportError: ld.so.1: python2.5: fatal: relocation error: file /home/drokade/ess_temp/56_release/ess/3rdparty/python/solaris/lib/python2.5/site-packages/processing/_processing.so: symbol CMSG_SPACE: referenced symbol not found >>> ^D How can I get rid of this ? Is this package not available for sun solaris ? -- Thanx & Regards, Deepak Rokade -- http://mail.python.org/mailman/listinfo/python-list
Re: speech recognition help
I want* to add speech recognition *to my application for *disabled persons*. (running in python 2.6 with wxpython 2.8.9..) *problem:* too many asterisks? ;-) actually i have some buttons scanned one by one.. button name is 'add' and if i tell 'add' then add button click event must be performed.. For that i need the conversion of *speech to text.* Tell me the right advice and necessary links to implement this... Usually this is relegated to utility software -- Dragon Naturally Speaking[1] is one of the most popular. They tend to do more reliably (higher recognition rates) with fixed vocabularies for issuing commands than in free-form dictation. There's the open-source CMU Sphinx project[2] which may allow you to more easily interact with it programatically via an API. On my Debian box, it's just an apt-get away[3]. Note that this is *different* from the python-sphinx documentation package just mentioned in a nearby thread on c.l.p There's documentation[4] on connecting Python + Sphinx2 that may be of assistance. -tkc [1] http://www.nuance.com/naturallyspeaking/ [2] http://cmusphinx.org/ [3] apt-cache search sphinx2 [4] http://sphinx.subwiki.com/sphinx/index.php/Sphinx3_python_quickstart -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of HTMLparser to change language
pranav wrote: I am sure there is a python way of solving this problem. The common sense approach (nothing to do with python) would be to rewrite everything to be dynamically generated with a template language - in python those would be TAL, mako, genshi, jinja, whatever ... anything is better than the current solution. Hmm ya, that is THE best thing, if this were an application. These are plain HTML files and needs to be shipped with CDs. So what? Template engines are perfectly able to generate files instead of sending them off the net. Also, it is not in the design to use anything executable. Do you mean "put executable in the CDs", but I'm not proposing that. Anyway, I would probably start by looping all of the files with 'tidy' - to have the same formatting and hopefully attribute order, examining a few them with something like 'vimdiff' and see if I could come up with some rules to implement with BeautifulSoup. False positives (i.e. files that should be equal but aren't) are ok because they can give new rules to implement. With the same retro-engineered rules I could create the templates from the static files. -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to compile pyprocessing module on SUN solaris
Deepak Rokade wrote: > How can I get rid of this ? > Is this package not available for sun solaris ? Apparently Solaris doesn't support sem_timedwait(). You have to disable the feature in setup.py:: HAVE_SEM_TIMEDWAIT=0 Why are you using pyprocessing instead of multiprocessing? Christian -- http://mail.python.org/mailman/listinfo/python-list
Is there any way for a program to choose between 32 bit or 64-bit python dynamically?
Hi, Is thera any way for a program to choose between 32-bit or 64-bit dynamically? Thanks, Srini Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Obtaining the attributes and properties of a folder recursively.
On Mar 20, 5:09 pm, Tim Golden wrote: > Tino Wildenhain wrote: > > Tim Golden wrote: > > ... > >> and do the following: > > >> > >> from winsys import fs > > >> for f in fs.flat ("c:/temp"): > >> f.dump () > > ^ eeek! > > Was the k! for the space before the bracket > (which, for some unaccountable reason disturbs > some people)? Or for the idea of dumping data > out? > > This is what it looks like for one (random) file: > > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC > Type "help", "copyright", "credits" or "license" for>>> from winsys import fs > >>> fs.file ("c:/temp/t.py").dump () > > { > c:\temp\t.py > { > c:\temp\t.py > parts: [u'?\\c:\\', u'temp', u't.py'] > root: \\?\c:\ > dirname: \temp > path: \\?\c:\\temp > filename: t.py > parent: \\?\c:\temp > } > readable: True > id: 260191347677670224354611 > n_links: 1 > created_at: 2008-10-27 09:45:09 > accessed_at: 2009-03-20 08:57:25 > written_at: 2009-03-20 08:57:25 > uncompressed_size: 1170 > size: 1170 > Attributes: > { > ARCHIVE => True > COMPRESSED => False > DIRECTORY => False > ENCRYPTED => False > HIDDEN => False > NORMAL => False > NOT_CONTENT_INDEXES => False > OFFLINE => False > READONLY => False > REPARSE_POINT => False > SPARSE_FILE => False > SYSTEM => False > TEMPORARY => False > VIRTUAL => False > } > Security: > control: > { > DACL_AUTO_INHERITED > SELF_RELATIVE > DACL_PRESENT > } > owner: VOUK\goldent > dacl: > { > inherited: True > { > trustee: VOUK\goldent > access: 1000 > type: ACCESS_ALLOWED > } > { > trustee: BUILTIN\Administrators > access: 1000 > type: ACCESS_ALLOWED > flags: > { > INHERITED > } > } > { > trustee: NT AUTHORITY\SYSTEM > access: 1000 > type: ACCESS_ALLOWED > flags: > { > INHERITED > } > } > { > trustee: VOUK\goldent > access: 1000 > type: ACCESS_ALLOWED > flags: > { > INHERITED > } > } > { > trustee: BUILTIN\Users > access: 100101010100 > type: ACCESS_ALLOWED > flags: > { > INHERITED > } > } > }} > > > > TJG Thank you for your suggestion but.. I'll have around 1000 such files in the whole directory and it becomes hard to manage such output because again I've to take this snapshot before backing up the data and have to do the same and compare both when the data gets restored, just to verify whether the restore happened successfully or not. Thank you, Venu Madhav -- http://mail.python.org/mailman/listinfo/python-list
Re: improve this newbie code/nested functions in Python?
Hi! On Mar 20, 1:06 am, Terry Reedy wrote: > > What you wrote are two nested classes, not functions. Ooops .. yes of course .. simple mistake (it was late .. :) > In my opinion, > neither should be nested. Nothing is gained and something is lost. > Neither are used by client; indeed both use client. I nested them because I see them as components of the client which keeps track of the connection parameters and makes the initial connection and then hands the info off to the two threads for processing, and then also helps the two threads communicate with each other. This seemed like a good choice to me, can you (or someone else) elaborate why this is not a good design? The idea was to encapsulate all the client info/code in one place. > I would rename '_parent' (misleading) as 'client' or 'user'. good suggestion .. I chose parent or could have chosen "outer" since I was looking for a way for the nested classes to access the outer class The series of assignments in __init__ in client was to store the connection parameters as instance variables in the outer client class. the __keepGoing__ variable is used to help the two threads communicate with each other and know when to shut down. This feedback is exactly the sort of thing I was looking for, thanks, I'm looking forward to more suggestions. Esmail -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 3143: Standard daemon process library
On Fri, 20 Mar 2009 21:47:00 +1100, Ben Finney wrote: [snip] Somewhat by accident I noticed this other part of the PEP: Other Python daemon implementations that differ from this PEP: [snip] * Twisted [twisted]_ includes, perhaps unsurprisingly, an implementation of a process daemonisation API that is integrated with the rest of the Twisted framework; it differs significantly from the API in this PEP. What do you mean be "integrated"? Twisted's daemonization code is in a free function which depends only on the os module. It's basically as un-integrated as could be (it's also only 14 lines long). Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to compile pyprocessing module on SUN solaris
This did not wok. I continued to get those warning and Import Error. I wanr through documentation of multiprocessing and it looks almost similar to processing module. Any advantages of multiprocessing module ? On Fri, Mar 20, 2009 at 6:53 PM, Christian Heimes wrote: > Deepak Rokade wrote: > > How can I get rid of this ? > > Is this package not available for sun solaris ? > > Apparently Solaris doesn't support sem_timedwait(). You have to disable > the feature in setup.py:: > > HAVE_SEM_TIMEDWAIT=0 > > Why are you using pyprocessing instead of multiprocessing? > > Christian > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Thanx & Regards, Deepak Rokade Do what u Enjoy & Enjoy what u Do... -- http://mail.python.org/mailman/listinfo/python-list
Compiling modules in OSX, eg PyUSB?
Hi, I am using Leopard and MacPython, and I would like to access a USB device. I have installed libusb, and now I have tried to compile PyUSB from: http://sourceforge.net/projects/pyusb/ But when I compile I get lots of errors, ie: pcfr147:pyusb-0.4.1 david$ python setup.py install running install running build running build_ext building 'usb' extension gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk - fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd - fno-common -dynamic -DNDEBUG -g -O3 -I/Library/Frameworks/ Python.framework/Versions/4.1.30101/include/python2.5 -c pyusb.c -o build/temp.macosx-10.3-i386-2.5/pyusb.o In file included from pyusb.c:11: pyusb.h:6:17: error: usb.h: No such file or directory In file included from pyusb.c:11: pyusb.h:120: error: syntax error before 'usb_dev_handle' pyusb.h:120: warning: no semicolon at end of struct or union pyusb.h:122: error: syntax error before '}' token pyusb.h:122: warning: data definition has no type or storage class pyusb.h:131: warning: 'struct usb_endpoint_descriptor' declared inside parameter list pyusb.h:131: warning: its scope is only this definition or declaration, which is probably not what you want ... ... pyusb.c:2083: error: dereferencing pointer to incomplete type pyusb.c:2084: warning: passing argument 1 of 'new_Bus' from incompatible pointer type lipo: can't figure out the architecture type of: /var/folders/xt/ xtY5vvWXEUyZv0KZrwtRzTI/-Tmp-//ccYg0qka.out error: command 'gcc' failed with exit status 1 A long time googling found this similar problem: http://ubuntuforums.org/archive/index.php/t-325241.html The suggested answer was to first do: sudo apt-get install python-dev But that was for a debian machine. I dont use fink, and I prefer to use a standard osx python install if possible. I am still a python novice, and I'm not sure if I am using the "python setup.py install" command wrongly, or if I need this python-dev package, or something completely different. Has anyone had this problem, or know a solution? Thanks in Advance! -- http://mail.python.org/mailman/listinfo/python-list
Re: Obtaining the attributes and properties of a folder recursively.
venutaurus...@gmail.com wrote: Thank you for your suggestion but.. I'll have around 1000 such files in the whole directory and it becomes hard to manage such output because again I've to take this snapshot before backing up the data and have to do the same and compare both when the data gets restored, just to verify whether the restore happened successfully or not. The .dump is simply a way of seeing quickly what the data is. If you want to store is somewhere (.csv or whatever), you can just select the attributes you want. Note, though, that ACLs are tricky to compare. Something like the following might do what you want, perhaps? import os import csv from winsys import fs with open ("info.csv", "wb") as f: writer = csv.writer (f) for f in fs.flat ("c:/temp/cabsdk"): print f writer.writerow ([ f, f.created_at, f.written_at, f.attributes, f.security (), f.size ]) os.startfile ("info.csv") This uses the security's SDDL representation, which while opaque does at least give you a before-and-after check. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to compile pyprocessing module on SUN solaris
Deepak Rokade wrote: > This did not wok. > I continued to get those warning and Import Error. > > I wanr through documentation of multiprocessing and it looks almost similar > to processing module. > Any advantages of multiprocessing module ? You may have to disable more features and recompile everything until it works. Have you removed the entire build directory before you recompiled the package again? rm -r build && python2.5 setup.py build The CMSG_* functions are used by the fd transer feature. Maybe solaris doesn't support it, too? Please HAVE_FD_TRANSFER=0 and try it again. pyprocessing was added to Python 2.6 and 3.0 under the new name multiprocessing. The multiprocessing package contains several fixes and minor API changes. I'm maintaining a backport to Python 2.4 and 2.5. multiprocessing is a back port of the Python 2.6/3.0 multiprocessing package. The multiprocessing package itself is a renamed and updated version of R Oudkerk's pyprocessing package. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Ordered Sets
In article , Nigel Rantor wrote: >Aahz wrote: >> In article >> <9a5d59e1-2798-4864-a938-9b39792c5...@s9g2000prg.googlegroups.com>, >> Raymond Hettinger wrote: >>> >>> Here's a new, fun recipe for you guys: >>> >>> http://code.activestate.com/recipes/576694/ >> >> That is *sick* and perverted. > >I'm not sure why. > >Would it be less sick if it had been called "UniqueList" ? The doubly-linked list part is what's sick and perverted. -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "Programming language design is not a rational science. Most reasoning about it is at best rationalization of gut feelings, and at worst plain wrong." --GvR, python-ideas, 2009-3-1 -- http://mail.python.org/mailman/listinfo/python-list
Re: file.read() doesn't read the whole file
On Mar 20, 4:43 pm, "R. David Murray" wrote: > Sreejith K wrote: > > Hi, > > > >>> snapdir = './mango.txt_snaps' > > >>> snap_cnt = 1 > > >>> block = 0 > > >>> import os > > >>> os.chdir('/mnt/gfs_local') > > >>> snap = open(snapdir + '/snap%s/%s' % (repr(snap_cnt), repr(block)),'r') > > >>> snap.read() > > 'dfdfdgagdfgdf\ngdgfadgagadg\nagafg\n\nfs\nf\nsadf\n\nsdfsdfsadf\n' > > >>> snapdir + '/snap%s/%s' % (repr(snap_cnt), repr(block)) > > './mango.txt_snaps/snap1/0' > > > The above code works fine and it reads the whole file till EOF. But > > when this method is used in a different scenario the file is not read > > completely. I'll post the code that read only some part of the file... > > > self.snap = open(self.snapdir + '/snap%d/%d' % (self.snap_cnt, > > block),'r') ## opens /mnt/gfs_local/mango.txt_snaps/snap1/0 > > self.snap.seek(off%4096) ## seeks to 0 in this case > > bend = 4096-(off%4096) ## 4096 in this case > > if length-bend <= 0: ## true in this case as length is 4096 > > tf.writelines("returned \n") > > data = self.snap.read(length) > > self.snap.close() > > break > > > the output data is supposed to read the whole fie but it only reads a > > part of it. Why is it encountering an early EOF ? > > It's not. In the second case you told it to read only 4096 bytes. You > might want to read the docs for the 'read' method, paying particular > attention to the optional argument and its meaning. > > -- > R. David Murray http://www.bitdance.com I'm using the above codes in a pthon-fuse's file class's read function. The offset and length are 0 and 4096 respectively for my test inputs. When I open a file and read the 4096 bytes from offset, only a few lines are printed, not the whole file. Actually the file is only a few bytes. But when I tried reading from the Interactive mode of python it gave the whole file. Is there any problem using read() method in fuse-python ? Also statements like break and continue behaves weirdly in fuse functions. Any help is appreciated -- http://mail.python.org/mailman/listinfo/python-list
Re: Preparing teaching materials
Michele Simionato wrote: The interesting thing is that Sphinx uses pygments and can highlight any code fragment, not only Python code. For instance, last week I did some experiment with Sphinx to convert my "Adventures of a Pythonista in Schemeland" (which contains Scheme code) to PDF and it worked out quite well. I have yet to fix the images, but the result after a next-to-zero effort is the following: http://www.phyast.pitt.edu/~micheles/scheme/TheAdventuresofaPythonistainSchemeland.pdf (I think the OP may be interested in how the PDF output of Sphinx-generated documents may look like). That looks really snappy. Do you have the HTML output to compare? TJG -- http://mail.python.org/mailman/listinfo/python-list
nested classes
Hello all, I am curious why nested classes don't seem to be used much in Python. I see them as a great way to encapsulate related information, which is a good thing. In my other post "improve this newbie code/nested functions in Python?" (I accidentally referred to nested functions rather nested classes - it was late) I asked something similar in the context of a specific example where I think the use of nested classes makes sense. But perhaps not? Esmail -- http://mail.python.org/mailman/listinfo/python-list
Re: Compiling modules in OSX, eg PyUSB?
On Mar 20, 2009, at 9:48 AM, Dr Mephesto wrote: Hi, I am using Leopard and MacPython, and I would like to access a USB device. I have installed libusb, and now I have tried to compile PyUSB from: http://sourceforge.net/projects/pyusb/ But when I compile I get lots of errors, ie: Hi Dr. M., The first error you get is that the compiler can't find usb.h: pyusb.h:6:17: error: usb.h: No such file or directory It's not surprising that a compile produces lots of errors when it can't find a header file. This project is looking for a header file that's not on your system because PyUSB is Linux-specific. That doesn't mean it can't be made to run on OS X, but the amount of effort required to make that happen might range anywhere from trivial to difficult. PyUSB deals with hardware, and I wouldn't be surprised to find that a hardware interface varies from OS to OS. Since an entire header file is missing here, my guess is that making it work on OS X would be closer to difficult than trivial. It's also possible (likely?) that the author doesn't even have a Mac or access to one, and so can't experiment under OS X. You need to contact the package author to ask if he has considered OS X support. If not, you'll need to find another package. Google for something like this: python usb "os x" That should help you to find packages that will work under OS X. Be aware that there might not be such a package. :-/ Hope this helps Philip -- http://mail.python.org/mailman/listinfo/python-list
Re: Read a content file from a P7M
On 11/03/09 - 05:05, Luca wrote: > There is standard or sugested way in python to read the content of a P7M file? > > I don't need no feature like verify sign, or sign using a certificate. > I only need to extract the content file of the p7m (a doc, a pdf, ...) For PDF files you can just remove the P7M content before %PDF and after %%EOF. The following snippet converts /tmp/test.p7m into PDF, saving the resulting document into /tmp/test.pdf: import re from gzip import GzipFile contents = GzipFile('/tmp/test.p7m').read() contents_re = re.compile('%PDF-.*%%EOF', re.MULTILINE | re.DOTALL) contents = contents_re.search(contents).group() open('/tmp/test.pdf', 'w').write(contents) HTH. ciao, ema -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to compile pyprocessing module on SUN solaris
Great ! It worked. I set HAVE_FD_TRANSFER = 0 and now that is working. I guess this feature should be for distributing task to remote machines... I do not require it as of now but any idea when this will be supported in multiprocessing ? Is this code not considered to support sun Solaris environment. On Fri, Mar 20, 2009 at 7:28 PM, Christian Heimes wrote: > Deepak Rokade wrote: > > This did not wok. > > I continued to get those warning and Import Error. > > > > I wanr through documentation of multiprocessing and it looks almost > similar > > to processing module. > > Any advantages of multiprocessing module ? > > You may have to disable more features and recompile everything until it > works. Have you removed the entire build directory before you recompiled > the package again? > > rm -r build && python2.5 setup.py build > > > The CMSG_* functions are used by the fd transer feature. Maybe solaris > doesn't support it, too? Please HAVE_FD_TRANSFER=0 and try it again. > > pyprocessing was added to Python 2.6 and 3.0 under the new name > multiprocessing. The multiprocessing package contains several fixes and > minor API changes. I'm maintaining a backport to Python 2.4 and 2.5. > > multiprocessing is a back port of the Python 2.6/3.0 > multiprocessing package. The multiprocessing package itself > is a renamed and updated version of R Oudkerk's pyprocessing > package. > > Christian > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Thanx & Regards, Deepak Rokade Do what u Enjoy & Enjoy what u Do... -- http://mail.python.org/mailman/listinfo/python-list
get rid of duplicate elements in list without set
Hello there, I'd like to get the same result of set() but getting an indexable object. How to get this in an efficient way? Example using set A = [1, 2, 2 ,2 , 3 ,4] B= set(A) B = ([1, 2, 3, 4]) B[2] TypeError: unindexable object Many thanks, alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Preparing teaching materials
On Mar 20, 3:05 pm, Tim Golden wrote: > Michele Simionato wrote: > > >http://www.phyast.pitt.edu/~micheles/scheme/TheAdventuresofaPythonist... > > > (I think the OP may be interested in how the PDF output of > > Sphinx-generated documents may look like). > > That looks really snappy. Do you have the HTML output to compare? > > TJG Just generated: http://www.phyast.pitt.edu/~micheles/scheme/aps/ -- http://mail.python.org/mailman/listinfo/python-list
Re: blocked on futex
[posted and e-mailed, please respond to newsgroup] In article <2961e0af-d99b-4d5e-a280-f521ce7fa...@e10g2000vbe.googlegroups.com>, msoulier wrote: > >I'm using the Python packaged with CentOS 4.7, which is a patched >2.3.4. Yes, ancient but I can't do anything about it. That's not ancient -- maybe middle-aged. ;-) >The problem is that my long-running process, which talks to PostgreSQL >via Django models, does a lot of reading and writing to and from the >disk and writes to a Unix domain socket is randomly locking up. I have >not found a consistent place in my code where this lock-up occurs, but >every time it does, an strace shows that it is sitting at an futex() >call, apparently waiting forever. > >My first guess is that futex() is being used by pthread_mutex_lock() >for thread-safety. I'm not using threads but the interpreter was built >with threaded support AFAIK. How many processes do you have running? What kind of guarantee do you have that there's only one process if you think there should be only one? What's on the other side of the socket? If there's no consistent place, is it always the same object type involved or function/method call? I'm not at all familiar with Django, but it might be using threads internally. Have you tried dumping core and using gdb to find out more about the process state? -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "Programming language design is not a rational science. Most reasoning about it is at best rationalization of gut feelings, and at worst plain wrong." --GvR, python-ideas, 2009-3-1 -- http://mail.python.org/mailman/listinfo/python-list
Re: locate items in matrix (index of lists of lists)
Chris Rebert wrote: On Fri, Mar 20, 2009 at 4:34 AM, Alessandro Zivelonghi wrote: Many Thanks guys! and what if I need to look ONLY into the second and third columns, excluding the first item of each rows? for example if x = 3 I need to get [0] and not [0,1] indices = [i for i, row in enumerate(mat) if 1<= i <= 2 and 3 in row[1:]] If he wants to look in only the second and third columns, but still all the rows, surely that's: indices = [i for i, row in enumerate(mat) if x in row[1 : 3]] -- http://mail.python.org/mailman/listinfo/python-list
Re: get rid of duplicate elements in list without set
On Fri, 2009-03-20 at 07:16 -0700, Alexzive wrote: > Hello there, > > I'd like to get the same result of set() but getting an indexable > object. > How to get this in an efficient way? > > Example using set > > A = [1, 2, 2 ,2 , 3 ,4] > B= set(A) > B = ([1, 2, 3, 4]) > > B[2] > TypeError: unindexable object >>> A = [1, 2, 2 ,2 , 3, 4] >>> B = list(set(A)) >>> B[2] 3 However, as sets are unordered, there is no guarantee that B will have the same ordering as A. -- http://mail.python.org/mailman/listinfo/python-list
meta question - how to read comp.lang.python w/o usenet feed/google interface?
Hi all, I've been reading/posting to usenet since the 80s with a variety of tools (vn, and most recently Thunderbird) but since my ISP (TimeWarner) no longer provides usenet feeds I'm stuck. I am not crazy about the web interface via google groups, is there another way to read/post this in a nice threaded way, possibly with some sort of preview? I'm also worried about missing posts in specific threads (such as the ones I start :-) If you are reading/posting to comp.lang.python with something other than the regular web interface provided by google and you are happy with it, would you share it? Thanks. Esmail ps: primarily in Windows these days, though I have Ubuntu on a VM available too frequently. pps: I realize this is somewhat OT, but since this is what I'm interested in reading, and didn't know where else to post, the message ended up here. -- http://mail.python.org/mailman/listinfo/python-list
Re: meta question - how to read comp.lang.python w/o usenet feed/google interface?
I'd almost like to think there are a bunch of nice python programs out there that to this :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: meta question - how to read comp.lang.python w/o usenet feed/google interface?
On Fri, 2009-03-20 at 07:42 -0700, Esmail wrote: > Hi all, > > I've been reading/posting to usenet since the 80s with a variety of > tools (vn, and most recently Thunderbird) but since my ISP > (TimeWarner) no longer provides usenet feeds I'm stuck. > > I am not crazy about the web interface via google groups, is > there another way to read/post this in a nice threaded way, > possibly with some sort of preview? I'm also worried about > missing posts in specific threads (such as the ones I start :-) > > If you are reading/posting to comp.lang.python with something > other than the regular web interface provided by google and > you are happy with it, would you share it? > > Thanks. > > Esmail > ps: primarily in Windows these days, though I have Ubuntu on > a VM available too frequently. > pps: I realize this is somewhat OT, but since this is what I'm >interested in reading, and didn't know where else to post, >the message ended up here. > -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Organize large DNA txt files
Dear Fellow programmers, I'm using Python scripts too organize some rather large datasets describing DNA variation. Information is read, processed and written too a file in a sequential order, like this 1+ 1- 2+ 2- etc.. The files that i created contain positional information (nucleotide position) and some other info, like this: file 1+: 1 73 0 1 0 0 1 76 1 0 0 0 1 77 0 1 0 0 file 1- 1 74 0 0 6 0 1 78 0 0 4 0 1 89 0 0 0 2 Now the trick is that i want this: File 1+ AND File 1- 1 73 0 1 0 0 1 74 0 0 6 0 1 76 1 0 0 0 1 77 0 1 0 0 1 78 0 0 4 0 1 89 0 0 0 2 --- So the information should be sorted onto position. Right now I've written some very complicated scripts that read a number of lines from file 1- and 1+ and then combine this output. The problem is of course that the running number of file 1- can be lower then 1+, resulting in a incorrect order. Since both files are too large to input in a dictionary at once (both are 100 MB+) I need some sort of a alternative that can quickly sort everything without crashing my pc.. Your thoughts are appreciated.. Kind regards, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: meta question - how to read comp.lang.python w/o usenet feed/google interface?
"Esmail" wrote in message news:03081704-17b5-4c7d-82db-8efb7ebce...@q11g2000yqh.googlegroups.com... Hi all, I've been reading/posting to usenet since the 80s with a variety of tools (vn, and most recently Thunderbird) but since my ISP (TimeWarner) no longer provides usenet feeds I'm stuck. I am not crazy about the web interface via google groups, is there another way to read/post this in a nice threaded way, possibly with some sort of preview? I'm also worried about missing posts in specific threads (such as the ones I start :-) If you are reading/posting to comp.lang.python with something other than the regular web interface provided by google and you are happy with it, would you share it? I use the news.gmane.org usenet feeds. -Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: pylab plot_date problem
On Mar 19, 2:02 am, Shah Sultan Alam wrote: > Hi , > I am using following code to create a graph > def plot_plot(): > ax = pylab.subplot(111) > for count in range(len(yaxes_values)): > pylab.subplots_adjust(left=0.13, bottom=0.21, > right=0.90, top=0.90,wspace=0.20, hspace=0.20) > > ax.plot_date(id_dates,yaxes_values[count],fmt='o-',label=titleList[count]) > pylab.xlabel('Time Stamp') > pylab.ylabel('Values') > > ax.xaxis.set_major_locator(pylab.MinuteLocator(interval=Interval)) > ax.xaxis.set_major_formatter(formatter) > labels = ax.get_xticklabels() > pylab.setp(labels, rotation=90, fontsize=8) > ax.set_title(choice) > pylab.grid() > font= FontProperties(size='x-small'); > pylab.legend(loc=0, prop=font) > > each time I am re-initilliziing the "titleList" before calling the > plot_plot , This works fine for one graph, > But if I call it more then once the label keep appending .. > How to get rid of this ? > > Regds > Shah Alam Just a random thought, though I don't have experience with the module pylab and the function titleList, it sounds like you need to initialize the titleList inside the same plot_plot() function, rather than from outside. I would say try: >ax.plot_date(id_dates,yaxes_values[count],fmt='o-',label=titleList[count]) > pylab.xlabel('Time Stamp') > pylab.ylabel('Values') >titleList[count]='' #or [] if it is a multivalued variable. Hope it helps, Omar -- http://mail.python.org/mailman/listinfo/python-list
Re: get rid of duplicate elements in list without set
You could use: B=list(set(A)).sort() Hope that helps. T -- http://mail.python.org/mailman/listinfo/python-list
Holy hand grenade!
http://www.telegraph.co.uk/news/newstopics/howaboutthat/5018294/Pub-evacuated-after-Monty-Python-prop-mistaken-for-grenade.html -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "Programming language design is not a rational science. Most reasoning about it is at best rationalization of gut feelings, and at worst plain wrong." --GvR, python-ideas, 2009-3-1 -- http://mail.python.org/mailman/listinfo/python-list
Re: get rid of duplicate elements in list without set
On Fri, 2009-03-20 at 07:54 -0700, thomasvang...@gmail.com wrote: > You could use: > B=list(set(A)).sort() > Hope that helps. Which will assign None to B. sorted(list(... or B.sort() is probably what you meant. -- http://mail.python.org/mailman/listinfo/python-list
Re: get rid of duplicate elements in list without set
thomasvang...@gmail.com wrote: You could use: B=list(set(A)).sort() Hope that helps. That would leave a B with value None :-) B=list(sorted(set(A)) could work. smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: file.read() doesn't read the whole file
On Fri, 20 Mar 2009 at 07:09, Sreejith K wrote: On Mar 20, 4:43?pm, "R. David Murray" wrote: Sreejith K wrote: Hi, snapdir = './mango.txt_snaps' snap_cnt = 1 block = 0 import os os.chdir('/mnt/gfs_local') snap = open(snapdir + '/snap%s/%s' % (repr(snap_cnt), repr(block)),'r') snap.read() 'dfdfdgagdfgdf\ngdgfadgagadg\nagafg\n\nfs\nf\nsadf\n\nsdfsdfsadf\n' snapdir + '/snap%s/%s' % (repr(snap_cnt), repr(block)) './mango.txt_snaps/snap1/0' The above code works fine and it reads the wholefiletill EOF. But when this method is used in a different scenario thefileis notread completely. I'll post the code thatreadonly some part of thefile... self.snap = open(self.snapdir + '/snap%d/%d' % (self.snap_cnt, block),'r') ## opens /mnt/gfs_local/mango.txt_snaps/snap1/0 self.snap.seek(off%4096) ## seeks to 0 in this case bend = 4096-(off%4096) ## 4096 in this case if length-bend <= 0: ? ?## true in this case as length is 4096 ? ?tf.writelines("returned \n") ? ?data = self.snap.read(length) ? ?self.snap.close() ? ?break the output data is supposed toreadthe whole fie but it only reads a part of it. Why is it encountering an early EOF ? It's not. ?In the second case you told it toreadonly 4096 bytes. ?You might want toreadthe docs for the 'read' method, paying particular attention to the optional argument and its meaning. -- R. David Murray ? ? ? ? ?http://www.bitdance.com Thanks for the reply, Actually the file is only few bytes and file.read() and file.read (4096) will give the same result, i.e the whole file. But in my case its not happening (using it in python-fuse file class).. Any other ideas ? Not offhand. If it were me I'd start playing with parameters and moving things around, trying to find additional clues. See if calling read without the argument in the second case works, start stripping the second case down until it starts working (even if wrongly for the ultimate goal), and things like that. -- R. David Murray http://www.bitdance.com-- http://mail.python.org/mailman/listinfo/python-list
Re: get rid of duplicate elements in list without set
Tino Wildenhain wrote: thomasvang...@gmail.com wrote: You could use: B=list(set(A)).sort() Hope that helps. That would leave a B with value None :-) B=list(sorted(set(A)) could work. sorted() accepts an iterable, eg a set, and returns a list: B = sorted(set(A)) -- http://mail.python.org/mailman/listinfo/python-list
Re: distutils compiler flags for extension modules
On Mar 20, 9:48 am, Christian Meesters wrote: > as I got no answers with the previous question (subject: disabling > compiler flags in distutils), I thought I should ask the question in a > different way: Is there an option to set the compiler flags for a C/C++ > extension in distutils? There is the extra_compile_args-option in the > Extension class, yet this offers only to give additional flags, but I'd > like to have 'total' control about the compile args. Any hint? You can subclass the build_ext class and overwrite .finalize_options() to do something like: for ext in self.extensions: build_ext.finalize_options() # fiddle with ext.extra_compile_args And if that isn't enough you can modify the compiler (with some flags) by overwriting .build_extension() and modify self.compiler using it's .set_executables() method (file:///usr/share/doc/python2.5/html/ dist/module-distutils.ccompiler.html#l2h-37) before calling build_ext.build_extension(). Regards Floris -- http://mail.python.org/mailman/listinfo/python-list
Re: get rid of duplicate elements in list without set
On Mar 20, 9:54 am, "thomasvang...@gmail.com" wrote: > You could use: > B=list(set(A)).sort() > Hope that helps. > T That may hurt more than help, sort() only works in-place, and does *not* return the sorted list. For that you want the global built-in sorted: >>> data = map(int,"6 1 3 2 5 2 5 4 2 0".split()) >>> print sorted(list(set(data))) [0, 1, 2, 3, 4, 5, 6] To retain the original order, use the key argument, passing it a function - simplest is to pass the index of the value in the original list: >>> print sorted(list(set(data)), key=data.index) [6, 1, 3, 2, 5, 4, 0] If data is long, all of those calls to data.index may get expensive. You may want to build a lookup dict first: >>> lookup = dict((v,k) for k,v in list(enumerate(data))[::-1]) >>> print sorted(list(set(data)), key=lookup.__getitem__) [6, 1, 3, 2, 5, 4, 0] -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Organize large DNA txt files
thomasvang...@gmail.com wrote: Dear Fellow programmers, I'm using Python scripts too organize some rather large datasets describing DNA variation. Information is read, processed and written too a file in a sequential order, like this 1+ 1- 2+ 2- etc.. The files that i created contain positional information (nucleotide position) and some other info, like this: file 1+: 1 73 0 1 0 0 1 76 1 0 0 0 1 77 0 1 0 0 file 1- 1 74 0 0 6 0 1 78 0 0 4 0 1 89 0 0 0 2 Now the trick is that i want this: File 1+ AND File 1- 1 73 0 1 0 0 1 74 0 0 6 0 1 76 1 0 0 0 1 77 0 1 0 0 1 78 0 0 4 0 1 89 0 0 0 2 --- So the information should be sorted onto position. Right now I've written some very complicated scripts that read a number of lines from file 1- and 1+ and then combine this output. The problem is of course that the running number of file 1- can be lower then 1+, resulting in a incorrect order. Since both files are too large to input in a dictionary at once (both are 100 MB+) I need some sort of a alternative that can quickly sort everything without crashing my pc.. Here's my attempt: line_1 = input_1.readline() line_2 = input_2.readline() while line_1 and line_2: pos_1 = int(line_1.split(None, 2)[1]) pos_2 = int(line_2.split(None, 2)[1]) if pos_1 < pos_2: output.write(line_1) line_1 = input_1.readline() else: output.write(line_2) line_2 = input_2.readline() while line_1: output.write(line_1) line_1 = input_1.readline() while line_2: output.write(line_2) line_2 = input_2.readline() -- http://mail.python.org/mailman/listinfo/python-list
Re: Compiling modules in OSX, eg PyUSB?
Thanks. I found some more info that might help, if I understood it :)From the main PyUSB page, at http://pyusb.berlios.de/ , its says: "PyUSB uses the libusb to do its work, so, any system which has Python and libusb should work for PyUSB." I have installed the OSX version of libusb, and it puts the missing file "usb.h" in the directory: usr/local/include/usb.h In the instruction for installing PyUSB on windows, it says: "2) libusb-win32: a Windows version of the libusb C library available from http://libusb-win32.sourceforge.net. >From within a Cygwin terminal, copy the libusb.a file from the libusb-win32 lib/ directory to $(CYGWINDIR)/usr/lib/, and copy the usb.h file from the libusb-win32 include/ directory to $(CYGWINDIR)/usr/include/. You can build and install PyUSB with the command: python setup.py install" As I have the required usb.h file, is there some way to let the compiler know where is it when I run python setup.py install? I already tried copying the "usb.h" file from usr/local/include/ to /usr/ iinclude, but it still didnt find it. Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 3143: Standard daemon process library (was: Writing a well-behaved daemon)
On Mar 20, 9:58 am, Ben Finney wrote: > Ben Finney writes: > > Writing a Python program to become a Unix daemon is relatively > > well-documented: there's a recipe for detaching the process and > > running in its own process group. However, there's much more to a > > Unix daemon than simply detaching. > > […] > > > My searches for such functionality haven't borne much fruit though. > > Apart from scattered recipes, none of which cover all the essentials > > (let alone the optional features) of 'daemon', I can't find anything > > that could be relied upon. This is surprising, since I'd expect this > > in Python's standard library. > > I've submitted PEP 3143 http://www.python.org/dev/peps/pep-3143/> > to meet this need, and have re-worked an existing library into a new > ‘python-daemon’ http://pypi.python.org/pypi/python-daemon/> > library, the reference implementation. > > Now I need wider testing and scrutiny of the implementation and > specification. Had a quick look at the PEP and it looks very nice IMHO. One of the things that might be interesting is keeping file descriptors from the logging module open by default. So that you can setup your loggers before you daemonise --I do this so that I can complain on stdout if that gives trouble-- and are still able to use them once you've daemonised. I haven't looked at how feasable this is yet so it might be difficult, but useful anyway. Regards Floris -- http://mail.python.org/mailman/listinfo/python-list
Re: Read a content file from a P7M
Emanuele Rocca wrote: > On 11/03/09 - 05:05, Luca wrote: >> There is standard or sugested way in python to read the content of a P7M >> file? >> >> I don't need no feature like verify sign, or sign using a certificate. >> I only need to extract the content file of the p7m (a doc, a pdf, ...) > > For PDF files you can just remove the P7M content before %PDF and after > %%EOF. If the .p7m is a S/MIME message then it might be encrypted. So you have to decrypt it. It could also be a opaque-signed S/MIME message. But still I'd use a decent S/MIME module to extract the stuff therein. Ciao, Michael. -- http://mail.python.org/mailman/listinfo/python-list