ANN: SfePy 2009.2
I am pleased to announce the release of SfePy 2009.2. SfePy (simple finite elements in Python) is a software, distributed under the BSD license, for solving systems of coupled partial differential equations by the finite element method. The code is based on NumPy and SciPy packages. Mailing lists, issue tracking, git repository: http://sfepy.org Home page: http://sfepy.kme.zcu.cz For more information on this release, see http://sfepy.googlecode.com/svn/web/releases/2009.2_RELEASE_NOTES.txt Best regards, Robert Cimrman -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN Chicago Python User Group May Meeting This Thursday
Chicago Python User Group = Calling all Python Programmers in (or near enough) the Windy City!!! (and JAVA Programmers, and those into REST, too) We are having the highest meeting yet!! 25th floor! May 14, 2009 at ThoughtWorks Inc. 200 E Randolph St 25th Floor Chicago, IL RSVP: jcroneme (at) thoughtworks.com Topics: * REST with Jython (45 min) -- Tal Liron * icon-to-speech (10 min) and wsgi-servlet adaptor (10 min) -- Steve Githens * PyMite Lightening Talks (10 min each until infinity, or until they kick us out) -- Various Artists About ChiPy --- ChiPy is a group of Chicago Python Programmers, l33t, and n00bs. Meetings are held monthly at various locations around Chicago. Also, ChiPy is a proud sponsor of many Open Source and Educational efforts in Chicago. Stay tuned to the mailing list for more info. ChiPy website: http://chipy.org ChiPy Mailing List: http://mail.python.org/mailman/listinfo/chicago ChiPy Announcement *ONLY* Mailing List: http://mail.python.org/mailman/listinfo/chipy-announce Python website: http://python.org -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Regular Toronto Python Users' Group (PyGTA) meeting Tuesday 19th, 7:15pm
We will be having our regular PyGTA meeting at our regular time (7:15 on the 19th) and place (Linux Caffe) this month. Please note that *next* month (June 2009) we'll be meeting on the 17th (a Wednesday) as our speaker for June is not available on Tuesdays. Linux Caffe is at the corner of Grace and Harbord streets, 1 block South of Christie subway station. Tuesday, May 19th: Software Liability Round Table (Open Discussion) Proposals are afoot in the EU to make companies liable for the software they write. What would you need to accept liability for the software you write? Would you be willing to contribute software to an Open Source project if you could be sued when someone else broke it? What level of warranty would you be willing to give for your software (Money Back or Damages or Damages and Loss of Bussiness)? Is liability even a good idea? Would it stifle innovation? Would it be workable for your business? What benefits would you get out of warranties? Is there a service or testing methodology you feel would let you provide warranties better/cheaper/faster than others? Would an exception raised to the user constitute a money back event? Or would you have to fail to repair the software? Does repairing include making your software work with changing dependencies? What contracts or requirements would you need to be comfortable being a contract software developer? Wednesday, June 17th: Behdad Esfahbod will be presenting on how to use the Cairo rendering library from Python. Cairo is a vector graphics library that allows for targetting multiple graphical back-ends including OpenGL, X-windows, OSX Quartz, Win32, PDF, PNG etceteras. It is used in the Firefox and WebKit engines as well as the GTK library. Note the change in day-of-week! Tuesday, July 21st (tentative): Robert Jackiewicz of the Toronto Plone User's group will be presenting the zc.buildout package. Buildout is a tool for creating redistributable Python applications which is used extensively by the Zope and Plone communities. It is a recipe based engine for reproducing a set of modules and application code onto a number of machines. http://www.pygta.org/ Enjoy yourselves, Mike -- Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: py2exe + win32com + DAO
On Tue, 12 May 2009 22:06:42 -0700 (PDT), Trevor trevor.la...@gmail.com wrote: I do not believe your assertion applies to the following line of code: daoEngine = win32com.client.Dispatch(r'DAO.DBEngine.36') It doesn't. I'm simply suggesting that it is possible you are opening the database in Access or something in Administrator/dba mode. That could be causing an exclusive lock on the database so that no sub task can then open it. i have seen this on old versions of Access. To provide excellent performance, microsoft used to load the whole database into memory if it could. And just operate mostly from there. is it possible to obtain more verbose error output from Python modules? The error message in the original post was generated from: print sys.exc_info()[0] possibly but i'm not sure how... David -- http://mail.python.org/mailman/listinfo/python-list
Updates to enviironment variables and ctypes
I was hoping I could update LD_LIBRARY_PATH at runtime and load a library through ctypes from there, but I haven't been able to. I've tried all of these. os.environ['LD_LIBRARY_PATH'] = ./lib os.putenv('LD_LIBRARY_PATH', ./lib) os.system(export LD_LIBRARY_PATH=./lib) lib = CDLL(libevaluator.so) Traceback (most recent call last): File Evaluator.py, line 9, in module lib = CDLL(libevaluator.so) File /usr/lib/python2.5/ctypes/__init__.py, line 348, in __init__ self._handle = _dlopen(self._name, mode) OSError: libevaluator.so: cannot open shared object file: No such file or directory The only thing that works is to set the variable before starting Python. I'm assuming that's just how it's going to be. Is this a bug or is it meant to be? -- http://mail.python.org/mailman/listinfo/python-list
Re: Representing a Tree in Python
On May 13, 11:54 am, CTO debat...@gmail.com wrote: On May 13, 12:10 am, godshorse chinthak...@gmail.com wrote: Hello, I want to find out the shortest path tree from a root to several nodes in a graph data structure. I found a Dijkstra code from internet that finds shortest path between only two nodes. How can i extend it to a tree?. And what is the best way to represent a tree in Python?. Thank you, Well, I'm biased, but I like URL:http://graphine.org. As an example, to build a five node tree: from graph.base import Graph g = Graph() for i in range(5): ... g.add_node(i) ... g.add_edge(0, 1) g.add_edge(0, 2) g.add_edge(1, 3) g.add_edge(1, 4) And to find the shortest path between, say, node 0 and node 4: start = g[0] end = g[4] distance, edges = g.get_shortest_paths(start)[end] distance 2 edges [Edge(name=(0,1)), Edge(name=(1,4))] Let me know what you think if you decide to use it- I'm looking for feedback. Geremy Condra Thanks very much for your reply Geremy. That site was interesting. Actually the Graph building part is already completed now. I used a dictionary for that and it works fine. for Dijkstra shortest path problem your suggestion can be used. But let me clear the my problem again. I have a graph. and I want to find 'shortest path tree' from a root node to several nodes. as a example if we have a graph of 5 nodes from 1 to 5, I need to build the shortest path tree from node 1 to nodes 2,3,5. So my question is instead of keeping separate lists for each destination node's shortest path. How can I represent and store them in a tree structure using python. Then I can easily find out what are the common nodes in the path to each destination. Thanks once again. -- http://mail.python.org/mailman/listinfo/python-list
Re: New to python, can i ask for a little help?
On May 13, 12:18 pm, warhammer1...@gmail.com warhammer1...@gmail.com wrote: I loaded python 3.1 I can use the gui and i see the following: Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] on win32 Type copyright, credits or license() for more information. It would seem that this is working correctly and there is no path problem. I am running windows vista. When i put in a test string i see this: Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] on win32 Type copyright, credits or license() for more information. print hello world! SyntaxError: invalid syntax (pyshell#0, line 1) Can anyone tell me what is wrong? I didnt expect that error Andrew print is a function. So you should do it this way: print(hello world!) -- http://mail.python.org/mailman/listinfo/python-list
Re: Representing a Tree in Python
But let me clear the my problem again. I have a graph. and I want to find 'shortest path tree' from a root node to several nodes. as a example if we have a graph of 5 nodes from 1 to 5, I need to build the shortest path tree from node 1 to nodes 2,3,5. So my question is instead of keeping separate lists for each destination node's shortest path. How can I represent and store them in a tree structure using python. Then I can easily find out what are the common nodes in the path to each destination. A tree is just a connected acyclic rooted graph, so however you're representing graphs should be a perfectly natural representation for your shortest paths tree. In effect, you just treat the shortest paths operation as an subgraph operation which only preserves the edges that are part of a shortest path. Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Help needed to resolve ImportError
Hi, We currently use VC6.0 and Python 2.2 for our project. As part of porting our project to VC2005 when i try to compile our application, it gives the following error Traceback (most recent call last): File v:\Component\DS\scripts\messagebuilder\IL_Messagebuilder\test\test_IL_setget.py, line 20, in module import IL_setget File \Component\DS\scripts\messagebuilder\IL_messagebuilder\IL_setget.py, line 22, in module import IL_IEbuilder File \Component\DS\scripts\messagebuilder\IL_messagebuilder\IL_IEbuilder.py, line 11, in module from MessageDictionary import * File \Component\LS\LSPythonFiles\MessageDictionary.py, line 3, in module import ScriptInterpreter ImportError: No module named ScriptInterpreter Basically, we are trying to import a VC compiled DLL into python script which generates another Python file. This issue doesnt occur in VC6.0 setup I have tried setting path variables and options like copying scriptInterpreter.dll to python installation path and so on. HOwever it doesnt work. Are there any compatibility issues between VC2005 and python 2.2? HOw can i resolve this. Your help is highly appreciated. Best Regards Venkat _ Drag n’ drop—Get easy photo sharing with Windows Live™ Photos. http://www.microsoft.com/india/windows/windowslive/photos.aspx-- http://mail.python.org/mailman/listinfo/python-list
Re: How to build Python 2.6.2 on HP-UX Itanium with thread support?
New info: The problem is not related to the specific program - it is definitely a build problem, as the following test shows: Python 2.6.2 (r262:71600, Apr 28 2009, 17:38:15) [GCC 4.2.3] on hp-ux11 Type help, copyright, credits or license for more information. import threading threading._test() Traceback (most recent call last): File stdin, line 1, in module File /usr/local/lib/python2.6/threading.py, line 952, in _test t.start() File /usr/local/lib/python2.6/threading.py, line 471, in start _start_new_thread(self.__bootstrap, ()) thread.error: can't start new thread The compiler I used was GCC 4.2.3 -- http://mail.python.org/mailman/listinfo/python-list
python script as service
Hi all, could any one tell how to run a python script as a scheduled service(say every one minute). I tried out the windows registration method but encountered an error . The error reads: The 'script name' on local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service Regards Prakash -- http://mail.python.org/mailman/listinfo/python-list
Re: Representing a Tree in Python
Dijkstra's algorithm computes shortest paths between a node and _ALL_ other nodes in the graph. It is usually stopped once computing the shortest path to the target node is done, but that's simply for efficiency, not a limitation of the algorithm. So you should be able to tweak the code you are using so that it provides you with all you are looking for. I'd be surprised if graphine (which, by the way, looks great, CTO) or any other graph package didn't implement it, so switching to that may be the most efficient thing to do. On the other hand, if you want to post your code and links to the Dijkstra code you are using it may be possible to help you with the tweaking... Jaime On Wed, May 13, 2009 at 8:31 AM, godshorse chinthak...@gmail.com wrote: On May 13, 11:54 am, CTO debat...@gmail.com wrote: On May 13, 12:10 am, godshorse chinthak...@gmail.com wrote: Hello, I want to find out the shortest path tree from a root to several nodes in a graph data structure. I found a Dijkstra code from internet that finds shortest path between only two nodes. How can i extend it to a tree?. And what is the best way to represent a tree in Python?. Thank you, Well, I'm biased, but I like URL:http://graphine.org. As an example, to build a five node tree: from graph.base import Graph g = Graph() for i in range(5): ... g.add_node(i) ... g.add_edge(0, 1) g.add_edge(0, 2) g.add_edge(1, 3) g.add_edge(1, 4) And to find the shortest path between, say, node 0 and node 4: start = g[0] end = g[4] distance, edges = g.get_shortest_paths(start)[end] distance 2 edges [Edge(name=(0,1)), Edge(name=(1,4))] Let me know what you think if you decide to use it- I'm looking for feedback. Geremy Condra Thanks very much for your reply Geremy. That site was interesting. Actually the Graph building part is already completed now. I used a dictionary for that and it works fine. for Dijkstra shortest path problem your suggestion can be used. But let me clear the my problem again. I have a graph. and I want to find 'shortest path tree' from a root node to several nodes. as a example if we have a graph of 5 nodes from 1 to 5, I need to build the shortest path tree from node 1 to nodes 2,3,5. So my question is instead of keeping separate lists for each destination node's shortest path. How can I represent and store them in a tree structure using python. Then I can easily find out what are the common nodes in the path to each destination. Thanks once again. -- http://mail.python.org/mailman/listinfo/python-list -- (\__/) ( O.o) ( ) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes de dominación mundial. -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the use of the else in try/except/else?
In message pan.2009.05.12.09.35...@remove.this.cybersource.com.au, Steven D'Aprano wrote: On Tue, 12 May 2009 09:20:36 +, Steven D'Aprano wrote: It seems pretty straightforward to me. Except of course such a pattern won't work ... I rest my case. -- http://mail.python.org/mailman/listinfo/python-list
Re: Nimrod programming language
On Tue, May 12, 2009 at 3:10 PM, rump...@web.de wrote: You can certainly have a string type that uses byte arrays in UTF-8 encoding internally, but your string functions should be aware of that and treat it as a unicode string. The len function and index operators should count characters, not bytes. Add a byte array data type for byte arrays instead. It's not easy. I think Python3's byte arrays have an upper method (and a string literal syntax babc) which is quite alarming to me that they chose the wrong default. I suppose that is to make it possible to use the 'bytes' data type for text strings if you really want to (and for backwards-compatibility). Default text strings should use Unicode (as in Python 3), and that should be supported by the language. Eventually the rope data structure (that the compiler uses heavily) will become a proper part of the library: By rope I mean an immutable string implemented as a tree, so concatenation is O(1). For immutable strings there is no ``[]=`` operation, so using UTF-8 and converting it to a 32bit char works better. Consider a string class that keeps track of its own encoding and can change it on the fly as needed. -- mar...@librador.com http://www.librador.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Representing a Tree in Python
On May 13, 3:19 pm, Jaime Fernandez del Rio jaime.f...@gmail.com wrote: Dijkstra's algorithm computes shortest paths between a node and _ALL_ other nodes in the graph. It is usually stopped once computing the shortest path to the target node is done, but that's simply for efficiency, not a limitation of the algorithm. So you should be able to tweak the code you are using so that it provides you with all you are looking for. I'd be surprised if graphine (which, by the way, looks great, CTO) or any other graph package didn't implement it, so switching to that may be the most efficient thing to do. On the other hand, if you want to post your code and links to the Dijkstra code you are using it may be possible to help you with the tweaking... Jaime On Wed, May 13, 2009 at 8:31 AM, godshorse chinthak...@gmail.com wrote: On May 13, 11:54 am, CTO debat...@gmail.com wrote: On May 13, 12:10 am, godshorse chinthak...@gmail.com wrote: Hello, I want to find out the shortest path tree from a root to several nodes in a graph data structure. I found a Dijkstra code from internet that finds shortest path between only two nodes. How can i extend it to a tree?. And what is the best way to represent a tree in Python?. Thank you, Well, I'm biased, but I like URL:http://graphine.org. As an example, to build a five node tree: from graph.base import Graph g = Graph() for i in range(5): ... g.add_node(i) ... g.add_edge(0, 1) g.add_edge(0, 2) g.add_edge(1, 3) g.add_edge(1, 4) And to find the shortest path between, say, node 0 and node 4: start = g[0] end = g[4] distance, edges = g.get_shortest_paths(start)[end] distance 2 edges [Edge(name=(0,1)), Edge(name=(1,4))] Let me know what you think if you decide to use it- I'm looking for feedback. Geremy Condra Thanks very much for your reply Geremy. That site was interesting. Actually the Graph building part is already completed now. I used a dictionary for that and it works fine. for Dijkstra shortest path problem your suggestion can be used. But let me clear the my problem again. I have a graph. and I want to find 'shortest path tree' from a root node to several nodes. as a example if we have a graph of 5 nodes from 1 to 5, I need to build the shortest path tree from node 1 to nodes 2,3,5. So my question is instead of keeping separate lists for each destination node's shortest path. How can I represent and store them in a tree structure using python. Then I can easily find out what are the common nodes in the path to each destination. Thanks once again. -- http://mail.python.org/mailman/listinfo/python-list -- (\__/) ( O.o) ( ) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes de dominación mundial. Hello Jaime, Thanks for the reply. This is the link to the code that I am using. http://code.activestate.com/recipes/119466/ What I do in my code is just looping through the destination nodes and find the shortest path to each node. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert UNIX formated text files to DOS formated?
On Tue, May 12, 2009 at 11:47 PM, walterbyrd walterb...@iname.com wrote: On May 12, 6:15 pm, norseman norse...@hughes.net wrote: Subject line says UNIX to DOS I hope that means you are using a UNIX machine. I should have mentioned, I am working in an environment that is very restrictive about what I can put on my XP desktop. I can not put python, or even notepad++, on my desktop. But, I do have cygwin. As you probably know, cygwin formats to UNIX. -- http://mail.python.org/mailman/listinfo/python-list cygwin has u2d and d2u -- http://mail.python.org/mailman/listinfo/python-list
(Winows) Finding out which process has locked a file.
Hi all, Does anyone know how I can programatically find out which process (resolved to human friendly string, i.e. executable) has a lock on a file. I have a script running which occassionally fails because it is trying to delete a file in use by another process. When this happens I want it to log which process has the lock. Since it tends to happen when I am never near the computer to catch it! :( Cheers, Shaun -- http://mail.python.org/mailman/listinfo/python-list
Re: python script as service
On XP, go to Start Menu/All Programs/Accessories/System Tools/Scheduled Tasks Add your program in with the scheduled task wizard... On Wed, 13 May 2009 13:10:25 +0530, prakash jp prakash.st...@gmail.com wrote: Hi all, could any one tell how to run a python script as a scheduled service(say every one minute). I tried out the windows registration method but encountered an error . The error reads: The 'script name' on local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service Regards Prakash -- http://mail.python.org/mailman/listinfo/python-list
PythonCard - My app stuck when button clicked
Hi there, I'm newbie in pythonCard. I have an application with 2 buttons : START , STOP Start execute a while(1) loop that execute my calculations. Stop suppose to raise a flag that will end that loop. Whenever I pish the START button my GUI is stuck. the calculation executes but I can't push the STOP button. I added thread that START start a thread that execute my calculations. I also added a Global variable that will hold the indication if the loop should continue. The problem now is that the thread ignore that variable and loop forever. Is there a simple way to make sure that the GUI won't stuck (without threads)? And if there isn't such way I would appriciet it very much if anyone could post an example of how to make my thread read that variable Thanks Dave -- http://mail.python.org/mailman/listinfo/python-list
about Python doc reader
Hi , I am currently working on Information retrieval from semi structured Documents in which there is a need to read data from Resumes. Could anyone tell me is there any python API to read Word doc? Thanks and regards, Shailja =-=-= Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you -- http://mail.python.org/mailman/listinfo/python-list
json vs. simplejson
Python 2.6 contains the json module, which I thought was the renamed (and improved?) simplejson module that also works on older Python versions. However, it seems the json is a lot slower than simplejson. This little test, run on Python 2.6.2 and WinXP shows a dramatic difference: C:\py26 -m timeit -s from json import dumps, loads loads(dumps(range(32))) 1000 loops, best of 3: 618 usec per loop C:\py26 -m timeit -s from simplejson import dumps, loads loads(dumps(range(32))) 1 loops, best of 3: 31 usec per loop Does anyone have an explanation for that? Thanks, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Re: Unable to install Pywin32 for Python 2.6.2
David Lyon schrieb: On Wed, 13 May 2009 05:32:16 +0200, Martin v. Löwis mar...@v.loewis.de wrote: I think this was a case of obscure misconfiguration of the system. It is always possible to configure a system in such a way that even the most resilient installation procedure will break. Technically, you are right.. but imho.. windows installers are overkill and shouldn't be used for this sort of thing. That is, installing libraries. And not the fault of the package authors either... Well, if you don't like the windows installer than you can always install from the sources. Please go ahead and try it out. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: json vs. simplejson
Thomas Heller wrote: Python 2.6 contains the json module, which I thought was the renamed (and improved?) simplejson module that also works on older Python versions. However, it seems the json is a lot slower than simplejson. This little test, run on Python 2.6.2 and WinXP shows a dramatic difference: C:\py26 -m timeit -s from json import dumps, loads loads(dumps(range(32))) 1000 loops, best of 3: 618 usec per loop C:\py26 -m timeit -s from simplejson import dumps, loads loads(dumps(range(32))) 1 loops, best of 3: 31 usec per loop Does anyone have an explanation for that? Dunno about json, but simplejson comes with an (optional) C-based speedup-module. Maybe this isn't part of the standard distribution? Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Representing a Tree in Python
godshorse, you may use the shortestPaths method of this graph class of mine: http://sourceforge.net/projects/pynetwork/ (It uses the same Dijkstra code by Eppstein). (Once you have all distances from a node to the other ones, it's not too much difficult to find the tree you talk about). Also see the Minimum spanning tree: http://en.wikipedia.org/wiki/Minimum_spanning_tree Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: json vs. simplejson
Diez B. Roggisch schrieb: Thomas Heller wrote: Python 2.6 contains the json module, which I thought was the renamed (and improved?) simplejson module that also works on older Python versions. However, it seems the json is a lot slower than simplejson. This little test, run on Python 2.6.2 and WinXP shows a dramatic difference: C:\py26 -m timeit -s from json import dumps, loads loads(dumps(range(32))) 1000 loops, best of 3: 618 usec per loop C:\py26 -m timeit -s from simplejson import dumps, loads loads(dumps(range(32))) 1 loops, best of 3: 31 usec per loop Does anyone have an explanation for that? Dunno about json, but simplejson comes with an (optional) C-based speedup-module. Maybe this isn't part of the standard distribution? json has it's own _json speedup module. And funny, on Linux, json WITH _json is still somewhat slower (~10%) than simplejson WITHOUT the _speedups module. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: about Python doc reader
On Wed, May 13, 2009 at 4:28 PM, Shailja Gulati shailja.gul...@tcs.com wrote: Hi , I am currently working on Information retrieval from semi structured Documents in which there is a need to read data from Resumes. Could anyone tell me is there any python API to read Word doc? If you're using Windows, you can use COM APIs to read Word documents. Or you can use OpenOffice.org using uno. You can find examples of either by googling. -- kushal -- http://mail.python.org/mailman/listinfo/python-list
urllib2 slow for multiple requests
Hello everybody, really new to python, so bear with me. I am trying to do some very basic scraping tool. Bascally it just grabs a page xy times and tells me how long it took. When I do this once, it is blazingly fast, but when I increase the number of repetitions, it is slowing down considerably (1 is like 3 ms, 100 takes 6 seconds). I have done implementations in couple more languages (php, ruby) and none of them seems to suffer from a similar problem and it seems, that it behaves linearly. Maybe it is a known issue in urllib2, or I am simply using it badly. I am using python 2.4.3, machine has CentOS, below is the sc. Thanks in advance import urllib2 from datetime import datetime def application(): start = datetime.now() req = urllib2.Request(http://127.0.0.1/gdc/about;, None, {'Accept': 'application/json'}) for number in range(100): response = urllib2.urlopen(req) end = datetime.now() output = end - start print output application() -- http://mail.python.org/mailman/listinfo/python-list
Re: about Python doc reader
Shailja Gulati wrote: Hi , I am currently working on Information retrieval from semi structured Documents in which there is a need to read data from Resumes. Could anyone tell me is there any python API to read Word doc? If you haven't already, get hold of the pywin32 extensions: http://pywin32.sf.net code import win32com.client doc = win32com.client.GetObject (c:/temp/temp.doc) text = doc.Range ().Text /code Note that this will give you a unicode object with \r line-delimiters. You could read para by para if that were more useful: code import win32com.client doc = win32com.client.GetObject (c:/temp/temp.doc) lines = [p.Range () for p in doc.Paragraphs] /code TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Updates to enviironment variables and ctypes
Scott Flynn wrote: I was hoping I could update LD_LIBRARY_PATH at runtime and load a library through ctypes from there, but I haven't been able to. I've tried all of these. os.environ['LD_LIBRARY_PATH'] = ./lib os.putenv('LD_LIBRARY_PATH', ./lib) os.system(export LD_LIBRARY_PATH=./lib) lib = CDLL(libevaluator.so) Traceback (most recent call last): File Evaluator.py, line 9, in module lib = CDLL(libevaluator.so) File /usr/lib/python2.5/ctypes/__init__.py, line 348, in __init__ self._handle = _dlopen(self._name, mode) OSError: libevaluator.so: cannot open shared object file: No such file or directory The only thing that works is to set the variable before starting Python. I'm assuming that's just how it's going to be. Is this a bug or is it meant to be? (You should mention that you're using Unix, and probably what version of Python you're using. It might make a difference.) Doesn't ctypes.LoadLibrary() accept a pathname as argument? That's what the Python 2.6 docs say. I haven't experimented, but it'd be worth a try. In this case, I'd make it an absolute path, just to convince it not to look through the directories in the LD_LIBRARY_PATH. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Re: Unable to install Pywin32 for Python 2.6.2
On Wed, 13 May 2009 13:54:49 +0200, Thomas Heller thel...@python.net Well, if you don't like the windows installer than you can always install from the sources. Please go ahead and try it out. Thanks for the offer... but aren't python .eggs supposed to remove the need for doing that ? Regards David -- http://mail.python.org/mailman/listinfo/python-list
Re: (Winows) Finding out which process has locked a file.
On 5/13/2009 2:20 AM CinnamonDonkey said... Hi all, Does anyone know how I can programatically find out which process (resolved to human friendly string, i.e. executable) has a lock on a file. I have a script running which occassionally fails because it is trying to delete a file in use by another process. When this happens I want it to log which process has the lock. You might take a look at http://ccollomb.free.fr/unlocker/ -- I've not used the command line options although they are available... Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: (Winows) Finding out which process has locked a file.
CinnamonDonkey wrote: Hi all, Does anyone know how I can programatically find out which process (resolved to human friendly string, i.e. executable) has a lock on a file. I have a script running which occassionally fails because it is trying to delete a file in use by another process. When this happens I want it to log which process has the lock. Since it tends to happen when I am never near the computer to catch it! :( Usual place to look for these things is sysinternals (now part of Microsoft). In particular, the handle util: http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx To get the same programatically you have to delve quite deep into the NT low-level API. Not tried it myself. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: How to build Python 2.6.2 on HP-UX Itanium with thread support?
In article 51d1dd3f-322d-47fa-9d44-75b92c6ef...@e20g2000vbc.googlegroups.com, henning.vonbar...@arcor.de wrote: New info: The problem is not related to the specific program - it is definitely a build problem, as the following test shows: Python 2.6.2 (r262:71600, Apr 28 2009, 17:38:15) [GCC 4.2.3] on hp-ux11 Type help, copyright, credits or license for more information. import threading threading._test() Traceback (most recent call last): File stdin, line 1, in module File /usr/local/lib/python2.6/threading.py, line 952, in _test t.start() File /usr/local/lib/python2.6/threading.py, line 471, in start _start_new_thread(self.__bootstrap, ()) thread.error: can't start new thread The compiler I used was GCC 4.2.3 You probably want to start by figuring out which threading library is being used -- Python normally wants Posix threads, but IIRC, that's not the default on HP-UX, and you may need to fix the build process to use Posix. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ It is easier to optimize correct code than to correct optimized code. --Bill Harlan -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert UNIX formated text files to DOS formated?
On May 13, 3:21 am, David Robinow drobi...@gmail.com wrote: cygwin has u2d and d2u- Hide quoted text - Thank you, I did not know about those utilities, until now. -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard - My app stuck when button clicked
I second this. I am very interested in PyCard having just discovered it in your message here. I know I'll run in to this same problem in my application that will run test routines that must have a mechanism to abort. Sorry for the lack of any help here... -Adam daved170 daved...@gmail.com wrote in message news:e7a3e095-974f-4239-8812-44f304f5f...@n21g2000vba.googlegroups.com... Hi there, I'm newbie in pythonCard. I have an application with 2 buttons : START , STOP Start execute a while(1) loop that execute my calculations. Stop suppose to raise a flag that will end that loop. -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib2 slow for multiple requests
Bascally it just grabs a page xy times and tells me how long it took. you aren't doing a read(), so technically you are just connecting to the web server and sending the request but never reading the content back from the socket. So your timing wouldn't be accurate. try this instead: response = urllib2.urlopen(req).read() But that is not the problem you are describing... when I increase the number of repetitions, it is slowing down considerably (1 is like 3 ms, 100 takes 6 seconds). Maybe it is a known issue in urllib2 I ran your code and can not reproduce that behavior. No matter how many repetitions, I still get a similar response time per transaction. any more details or code samples you can provide? -Corey Goldberg -- http://mail.python.org/mailman/listinfo/python-list
spam
spam -- http://mail.python.org/mailman/listinfo/python-list
Re: Call Web Service using proxy and http authentication
On May 12, 12:51 pm, wdveloper tot...@gmail.com wrote: On May 12, 8:38 pm, Steve Howell showel...@yahoo.com wrote: On May 12, 8:59 am, wdveloper tot...@gmail.com wrote: Hi everyone, I am trying to call a webservice which requires an http authentication. To reach the ws, I must pass from a proxy http. So in the whole I need go through two authentications before getting the ws working. I am using SOAPpy and I'm getting quite crazy. I am able to arrange this problem with simple http calls using urllib2 but for the ws i dont see any way out. Does anyone knows how I can manage this stuff? Is there any better solution or example code? Your high level description of the problem is good, but I think you'll get more help if you provide a little more detail. For something like this you may want to try to do more at the HTTP level, where you have a little more control over the authentication, and then find a way to hook into SOAPpy just to build and parse the payloads. How good is your understanding of HTTP? Do you know the basics of how headers work? You might want to brush up a little on HTTP just to help understand what's going on; it will almost certainly be valuable for future projects as well. To understand how the proxy works in particular, if you can use the proxy to access a normal html-serving website, you can use the Live HTTP Headers tool under Firefox to see what's going on. But before all that, I would maybe just post a little more detail on the problem. Maybe show code you've written so far, and any error messages/tracebacks, to better indicate where you are stuck. Thank you very much Steve, I do have a good understanding of http and its headers rules, and of course I can work on that. On the other hand, I am new to python and SOAPpy toolkit and I dont have much of an experience working with ws in general. When it comes of working with simple call to WS, everything is successfull; problems start cause I dont know how to use the toolkit to compose the http request. I should code it in the way that it connects to my proper proxy and it gets authenticated in the server exposing the service. What I have is something like: from SOAPpy import WSDL wsdl = 'http://myws?wsdl' my_http_proxy = '10.x.x.x:8080' proxy = WSDL.Proxy(wsdl, http_proxy=my_http_proxy) res = proxy.myService( myparam='...' ) What I get is that connection reaches timeout since the server doesnt see me coming from the right proxy. First problem, I can't see where I can put my proxy authentication username and password. Second, when I will be able to pass through the right proxy, I need to authenticate on the server via http through my credential. Have you looked at the URLopener class? -- http://mail.python.org/mailman/listinfo/python-list
Can't run PyQt apps with MacPython
I recently got a new MacBook Pro with Leopard, and would like to develop using Python and PyQt. I installed the latest Qt SDK, updated MacPython to V 2.5.4 and then proceeded to install SIP and PyQt as described in Mark Summerfield's book on PyQt Programming. Everything went fine and none of the scripts complained. However when I want to run a demo app, I get the error message Fatal Python error: Interpreter not initialized (version mismatch?) / Abort Trap. Anybody can help? -- http://mail.python.org/mailman/listinfo/python-list
DOM implementation
Hi everybody, I just spent the past hour or so trying to have a better understanding of how the various DOM-supporting libraries (xml.dom, xml.dom.minidom) work. I've used etree and lxml successfully before but I wanted to understand how close I can get to the W3C DOM standards. Ok, I think more or less I got it all. A few questions emerged: 1) classes in xml.dom.minidom (i.e. Element) seem to be old style classes. Is there a good reason they are kept that way or simply nobody had the time/will to update the library to use new-style classes? 2) for a lightweight implementation xml.dom.minidom comes with a lot of methods that aren't part of the W3C standards. I'm referring to toxml, toprettyxml, writxml and the _get_* family. Would it be better if there was a package offering W3C-faithful classes only, on top of which convenience and compatibility methods are added by another package (or two!) through subclassing? Manu -- http://mail.python.org/mailman/listinfo/python-list
Re: php to python code converter
i designed php to python converter a few monthos ago, to translate some of my ready made code snippets to python. i was experienced with php and was learning python. as stated on project home, it is only intended for translating small code snippets or small functions to python. whole applications, cannot be converted using that... only an idea, a very beta/alpha package, since there are huge amount of php applications, files, codes all around web, this would be a good tool if developed and used properly... -- http://mail.python.org/mailman/listinfo/python-list
n00b question: Possible to pass lists to a Template class?
Is it possible to pass a list to the Template.substitute method and use that in the template, like so.. g = string.Template(gametemplate) print g.substitute(recap = none, winner = game[winner], loser = game[loser]) Then in the template... bwinner.team Where winner.team would be the value of game[winner][team]. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: n00b question: Possible to pass lists to a Template class?
On May 13, 11:14 am, Wells we...@submute.net wrote: Is it possible to pass a list to the Template.substitute method and use that in the template, like so.. g = string.Template(gametemplate) print g.substitute(recap = none, winner = game[winner], loser = game[loser]) Then in the template... bwinner.team Where winner.team would be the value of game[winner][team]. Thanks! Sorry, I meant dicts, not lists. Like I said, n00b question. -- http://mail.python.org/mailman/listinfo/python-list
Re: (Winows) Finding out which process has locked a file.
CinnamonDonkey wrote: Hi all, Does anyone know how I can programatically find out which process (resolved to human friendly string, i.e. executable) has a lock on a file. I have a script running which occassionally fails because it is trying to delete a file in use by another process. When this happens I want it to log which process has the lock. Since it tends to happen when I am never near the computer to catch it! :( Cheers, Shaun This may depend on what version of Windows you're using, as the API's changed in Windows 2000, and again in XP SP2, and probably again in Vista. I don't know an API for what you want, but filemon, from http://technet.microsoft.com/en-us/sysinternals/bb896642.aspx can build a log of file activity, which you can examine later. If you do find an API that works on XP and better, please let us know. Even if you only know a function name, I'd be willing to play with it some, to see what it might do. I'd like to find out, and would share what I did figure out. -- http://mail.python.org/mailman/listinfo/python-list
Re: DOM implementation
On 13 Mai, 18:08, Emanuele D'Arrigo man...@gmail.com wrote: I just spent the past hour or so trying to have a better understanding of how the various DOM-supporting libraries (xml.dom, xml.dom.minidom) work. I've used etree and lxml successfully before but I wanted to understand how close I can get to the W3C DOM standards. You might want to look at pxdom if you want a high level of compliance with W3C DOM standards: http://www.doxdesk.com/software/py/pxdom.html Ok, I think more or less I got it all. A few questions emerged: 1) classes in xml.dom.minidom (i.e. Element) seem to be old style classes. Is there a good reason they are kept that way or simply nobody had the time/will to update the library to use new-style classes? I imagine that no-one bothered to update the code. The built-in modules like minidom do get maintenance, but not much further development. (PyXML, which seemed to accumulate code from 4Suite, possibly contributed code to the standard library, but it doesn't seem to be actively maintained or developed any more.) 2) for a lightweight implementation xml.dom.minidom comes with a lot of methods that aren't part of the W3C standards. I'm referring to toxml, toprettyxml, writxml and the _get_* family. Would it be better if there was a package offering W3C-faithful classes only, on top of which convenience and compatibility methods are added by another package (or two!) through subclassing? Those methods probably don't add that much weight, considering the weight that the W3C facilities already necessitate. I attempted to make a somewhat W3C-compliant implementation with the libxml2dom package (http://pypi.python.org/pypi/libxml2dom), although I felt that providing PyXML-like conveniences (similar to those you describe) was beneficial: some of the W3C APIs for parsing and serialisation are baroque, and although I've tried to implement some of those, too, I feel that it isn't a good use of my time. Paul -- http://mail.python.org/mailman/listinfo/python-list
How to see the code definiton in the shell ?
Hi, I am new to Python. I tried searching this but could not find an answer. In the interactive shell, I write a new function and I want to be able to see all the code that I wrote at a later time. Just typing the function name only shows allmethods function allmethods at 0x822b0 How do I see the actual code ? thanks mohan -- http://mail.python.org/mailman/listinfo/python-list
Re: How to see the code definiton in the shell ?
Mohan Parthasarathy escribió: Hi, I am new to Python. I tried searching this but could not find an answer. In the interactive shell, I write a new function and I want to be able to see all the code that I wrote at a later time. Just typing the function name only shows allmethods function allmethods at 0x822b0 How do I see the actual code ? thanks mohan I think that is not possible (at least, not with the default python console and without doing introspection). Anyway, why you need to do that? Why not write down the script in a text file and run it? If you need to run a console inside a function so that you can inspect variables, maybe you can use: import pdb;pdb.set_trace() And that will start a debug session when gets executed. Hope that helps. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to see the code definiton in the shell ?
On Wed, 2009-05-13 at 09:40 -0700, Mohan Parthasarathy wrote: Hi, I am new to Python. I tried searching this but could not find an answer. In the interactive shell, I write a new function and I want to be able to see all the code that I wrote at a later time. Just typing the function name only shows allmethods function allmethods at 0x822b0 How do I see the actual code ? thanks mohan The function definition itself has been compiled down to bytecode. You can see the bytecode as follows: def one(): ... return 1 ... print one.func_code.co_code # not very readable 'd\x01\x00S' import dis # python disassembler dis.dis(one.func_code.co_code) 0 LOAD_CONST 1 (1) 3 RETURN_VALUE or just run dis.dis on the function itself def two(): ... import math ... return (math.e ** (0+1J*math.pi)) + 3 ... two() (2+1.2246063538223773e-16j) two.func_code.co_code 'd\x01\x00d\x00\x00k\x00\x00}\x00\x00|\x00\x00i\x01\x00d\x02\x00d\x03 \x00|\x00\x00i\x02\x00\x14\x17\x13d\x04\x00\x17S' dis.dis(two) 2 0 LOAD_CONST 1 (-1) 3 LOAD_CONST 0 (None) 6 IMPORT_NAME 0 (math) 9 STORE_FAST 0 (math) 3 12 LOAD_FAST0 (math) 15 LOAD_ATTR1 (e) 18 LOAD_CONST 2 (0) 21 LOAD_CONST 3 (1j) 24 LOAD_FAST0 (math) 27 LOAD_ATTR2 (pi) 30 BINARY_MULTIPLY 31 BINARY_ADD 32 BINARY_POWER 33 LOAD_CONST 4 (3) 36 BINARY_ADD 37 RETURN_VALUE -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard - My app stuck when button clicked
daved170 wrote: Hi there, I'm newbie in pythonCard. I have an application with 2 buttons : START , STOP Start execute a while(1) loop that execute my calculations. Stop suppose to raise a flag that will end that loop. Whenever I pish the START button my GUI is stuck. the calculation executes but I can't push the STOP button. I added thread that START start a thread that execute my calculations. I also added a Global variable that will hold the indication if the loop should continue. The problem now is that the thread ignore that variable and loop forever. Is there a simple way to make sure that the GUI won't stuck (without threads)? And if there isn't such way I would appriciet it very much if anyone could post an example of how to make my thread read that variable Thanks Dave I don't know PythonCard, but most GUI's are similar enough that the concepts will work, even though the details differ. I'll assume that PythonCard has a traditional event loop, from which all events are dispatched. If your loop is fairly small, then you should keep it to one thread. Debugging it will usually be much easier. The trick is to break the task into pieces (each piece might be once around what is now a loop), and invoke one piece each time the event loop empties. I can't tell you how to do that without seeing your loop, but it's not usually very hard. Now, there is some way of POSTing an event to the event loop. That puts the event *after* all the events that are already there, but returns control immediately. So create a custom event, and POST it from the START button's button-pressed event. That will fire off one loop of the special task, in other words, make one function call to your new function. Then at the end of the function, POST it again, unless the STOP button has been pressed in the meantime. An optimization for this is to use coroutines, which are usually done with a generator. It's much trickier to describe, but much easier to accomplish. Roughly, you'd take your existing loop, and put a yield statement in it at appropriate place(s). Then the custom event is simply a call to the .next() function of that generator. Now, threading isn't that tough either, depending on how much data is being shared between the thread and the main program. You say that sharing a global flag isn't working, but it should. So how about if you show us some code, and somebody'll spot the trouble. For example, is the thread defined in the same module as the App? Global only shares between a single module. Another reason globals might seem to fail is if you tried to do mutual imports between two or more modules. (A imports B, which imports A). Sometimes that fails in mysterious ways. Make a simple (stripped) example of what you're trying, and we'll try to find the problem. Without concrete code, we end up with ambiguities like the above usage of two different meanings for the loop. -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the use of the else in try/except/else?
greg wrote: kj wrote: Wow. As rationales for syntax constructs go, this has got to be the most subtle one I've ever seen... It's to avoid masking bugs. Suppose you accidentally wrote try: v = mumble.field sys.warming('field was actually there?') except AttributeError: pass Then you could easily fail to notice that you had written 'warming' instead of 'warning'. Well, if you look, you'll discover that warning is not in the sys module at all, but in the logging module. So the original example already demonstrated the problem. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: json vs. simplejson
In article 76vs9tf1f6c5...@mid.individual.net, Thomas Heller thel...@python.net wrote: Diez B. Roggisch schrieb: Thomas Heller wrote: Python 2.6 contains the json module, which I thought was the renamed (and improved?) simplejson module that also works on older Python versions. However, it seems the json is a lot slower than simplejson. This little test, run on Python 2.6.2 and WinXP shows a dramatic difference: C:\py26 -m timeit -s from json import dumps, loads loads(dumps(range(32))) 1000 loops, best of 3: 618 usec per loop C:\py26 -m timeit -s from simplejson import dumps, loads loads(dumps(range(32))) 1 loops, best of 3: 31 usec per loop Does anyone have an explanation for that? Dunno about json, but simplejson comes with an (optional) C-based speedup-module. Maybe this isn't part of the standard distribution? json has it's own _json speedup module. And funny, on Linux, json WITH _json is still somewhat slower (~10%) than simplejson WITHOUT the _speedups module. According to the svn history in 2.6, the json module was a copy of simplejson 1.9. The current version of simplejson is 2.0.9 and, according to its CHANGES.txt, there have been a number of performance improvements in the various releases since 1.9. Looks like the trunk (2.7) version of json has been updated to the latest simplejson. -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Representing a Tree in Python
godshorse chinthak...@gmail.com (g) wrote: g Hello, g I want to find out the shortest path tree from a root to several nodes g in a graph data structure. I found a Dijkstra code from internet that g finds shortest path between only two nodes. How can i extend it to a g tree?. And what is the best way to represent a tree in Python?. http://networkx.lanl.gov/ has all kinds of Dijkstra's algorithms. -- Piet van Oostrum p...@cs.uu.nl URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list
get detail about latest computer
its for you get about latest computer laptop free more visit www.glu007.blog.com -- http://mail.python.org/mailman/listinfo/python-list
Re: json vs. simplejson
Ned Deily schrieb: In article 76vs9tf1f6c5...@mid.individual.net, Thomas Heller thel...@python.net wrote: Diez B. Roggisch schrieb: Thomas Heller wrote: Python 2.6 contains the json module, which I thought was the renamed (and improved?) simplejson module that also works on older Python versions. However, it seems the json is a lot slower than simplejson. This little test, run on Python 2.6.2 and WinXP shows a dramatic difference: C:\py26 -m timeit -s from json import dumps, loads loads(dumps(range(32))) 1000 loops, best of 3: 618 usec per loop C:\py26 -m timeit -s from simplejson import dumps, loads loads(dumps(range(32))) 1 loops, best of 3: 31 usec per loop Does anyone have an explanation for that? Dunno about json, but simplejson comes with an (optional) C-based speedup-module. Maybe this isn't part of the standard distribution? json has it's own _json speedup module. And funny, on Linux, json WITH _json is still somewhat slower (~10%) than simplejson WITHOUT the _speedups module. According to the svn history in 2.6, the json module was a copy of simplejson 1.9. The current version of simplejson is 2.0.9 and, according to its CHANGES.txt, there have been a number of performance improvements in the various releases since 1.9. Looks like the trunk (2.7) version of json has been updated to the latest simplejson. Ok, thanks. I've submitted a bug for python2.6, but it seems they will not upgrade to a newer version. http://bugs.python.org/issue6013 Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Representing a Tree in Python
On May 13, 8:19 am, bearophileh...@lycos.com wrote: godshorse, you may use the shortestPaths method of this graph class of mine:http://sourceforge.net/projects/pynetwork/ (It uses the same Dijkstra code by Eppstein). (Once you have all distances from a node to the other ones, it's not too much difficult to find the tree you talk about). Also see the Minimum spanning tree:http://en.wikipedia.org/wiki/Minimum_spanning_tree Bye, bearophile Let me add a caution to what bearophile says here- a minimum spanning tree minimizes the weight of the *whole tree*, not the individual paths in that tree, which seems to be what you're going after. Those can be pretty different things. Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Re: How to build Python 2.6.2 on HP-UX Itanium with thread support?
henning.vonbar wrote: Traceback (most recent call last): File stdin, line 1, in module File /usr/local/lib/python2.6/threading.py, line 952, in _test t.start() File /usr/local/lib/python2.6/threading.py, line 471, in start _start_new_thread(self.__bootstrap, ()) thread.error: can't start new thread What do you get with: import thread thread.start_new_thread(int, ('1',2)) ? Daniel -- http://mail.python.org/mailman/listinfo/python-list
x.abc vs x['abc']
Presuming it is very common to have objects created on the fly using some sort of external data definitions, is there an obvious common standard way to take a dict object and create an object whose attribute names are the keys from the dict? I realize I can do something like: d = {hello: world} x = type(, (object,), d)() x.hello world but that seems like an arcane way to do something which would ideally be transparent... if there is a function in the standard library, that would be good, even if I have to import it. I guess there is collections.namedtuple... that would not look much prettier... but the main thing to me is for it to be the same way everybody else does it. I do not prefer the new object be a dict, but it would be ok. -- http://mail.python.org/mailman/listinfo/python-list
Re: x.abc vs x['abc']
Gunter Henriksen wrote: but that seems like an arcane way to do something which would ideally be transparent... if there is a function in the standard library, that would be good, even if I have to import it. I guess there is collections.namedtuple... that would not look much prettier... but the main thing to me is for it to be the same way everybody else does it. I do not prefer the new object be a dict, but it would be ok. Most objects have an attribute called '__dict__' that acts as a container for the attributes of an object. class Container(object): ... pass ... container = Container() d = {hello: world} container.__dict__.update(d) container.hello 'world' You can also implemenet __getattr__() like: def __getattr__(self, name): try: return self.data[name] except KeyError: raise AttributeError(name) HTH Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: x.abc vs x['abc']
On Wed, May 13, 2009 at 1:00 PM, Christian Heimes li...@cheimes.de wrote: Gunter Henriksen wrote: but that seems like an arcane way to do something which would ideally be transparent... if there is a function in the standard library, that would be good, even if I have to import it. I guess there is collections.namedtuple... that would not look much prettier... but the main thing to me is for it to be the same way everybody else does it. I do not prefer the new object be a dict, but it would be ok. Most objects have an attribute called '__dict__' that acts as a container for the attributes of an object. class Container(object): ... pass ... container = Container() d = {hello: world} container.__dict__.update(d) container.hello 'world' You can also implemenet __getattr__() like: def __getattr__(self, name): try: return self.data[name] except KeyError: raise AttributeError(name) See also the `namedtuple` type in the `collections` module: http://docs.python.org/library/collections.html#collections.namedtuple Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: about Python doc reader
Kushal Kumaran wrote: On Wed, May 13, 2009 at 4:28 PM, Shailja Gulati shailja.gul...@tcs.com wrote: Hi , I am currently working on Information retrieval from semi structured Documents in which there is a need to read data from Resumes. Could anyone tell me is there any python API to read Word doc? If you're using Windows, you can use COM APIs to read Word documents. Or you can use OpenOffice.org using uno. You can find examples of either by googling. One problem that I keep getting with OOo an UNO and python. When asked to output a .txt file it comes out sorta pk-zipped. Same for .csv files it outputs. If you can, I suggest you work with Microsoft's COM. I have had better luck there. Not much, but better. Usually get a real .txt For what it is worth, in OOo I did have some progress by creating a macro to write out text in it and setting it to run on EVERY file it opens and ten close OOo after the write. Then batched the OOo file.doc process with a: files2process.sh#files2process.bat in window$ swriter file1.doc swriter file2.doc . . not very elegant, but it worked for me. To be honest - I just give those to a clerk and let them point and click until done these days. Less frustrating. Documentation bad for each. Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: New to python, can i ask for a little help?
On Wed, May 13, 2009 at 12:22 PM, warhammer1...@gmail.com warhammer1...@gmail.com wrote: On May 12, 9:27 pm, Chris Rebert c...@rebertia.com wrote: On Tue, May 12, 2009 at 9:18 PM, warhammer1...@gmail.com warhammer1...@gmail.com wrote: I loaded python 3.1 I can use the gui and i see the following: Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] on win32 Type copyright, credits or license() for more information. It would seem that this is working correctly and there is no path problem. I am running windows vista. When i put in a test string i see this: Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] on win32 Type copyright, credits or license() for more information. print hello world! SyntaxError: invalid syntax (pyshell#0, line 1) Can anyone tell me what is wrong? I didnt expect that error The print-statement was removed in Python 3.0. Now it's just a function. You'll have to use: print(hello world!) instead. Please also read the 3.0 transition docs:http://docs.python.org/3.0/whatsnew/3.0.html Note that Python 3.0 differs significantly from Python 2.x Cheers, Chris --http://blog.rebertia.com Hi Chris, Thank you for the pointer! that sure helped alot. Do you think i should be using a different version of python? I dont normally do much programming. I used to do some C along time ago. I want to get into something again and python seems to be popular. You should probably use Python v2.6 instead for the time being; most libraries have yet to be ported to Python 3.0, so 2.6 has many more libraries available for it currently. Python 3.0 is also mostly the same as 2.6, so learning 2.6 won't be a waste of time and will help you when the full transition to 3.0 is eventually made. Could you also tell me who uses python in IT areas? I see alot of python and Mysql. And i see python developer jobs as standalone too. See http://www.python.org/about/apps/ and http://www.python.org/about/success/ Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: about Python doc reader
Tim Golden wrote: Shailja Gulati wrote: Hi , I am currently working on Information retrieval from semi structured Documents in which there is a need to read data from Resumes. Could anyone tell me is there any python API to read Word doc? If you haven't already, get hold of the pywin32 extensions: http://pywin32.sf.net code import win32com.client doc = win32com.client.GetObject (c:/temp/temp.doc) text = doc.Range ().Text /code Note that this will give you a unicode object with \r line-delimiters. You could read para by para if that were more useful: code import win32com.client doc = win32com.client.GetObject (c:/temp/temp.doc) lines = [p.Range () for p in doc.Paragraphs] /code TJG === I saw this right after responding to Kushal's 5:37AM today posting. Thank you for the tip. I'll try these first chance I get. Word, swriter, whatever - I'm not partial when it comes to automating. Today is: 20090513 Steve -- http://mail.python.org/mailman/listinfo/python-list
Odd list behavior
I'm working on a simple file processing utility, and I encountered a weird error. If I try to get the first element of a list I'm splitting from a string, I get an error: key = string.split()[0] Error! However, I can slice the list like normal, but that gives me a one-element-long list: key = string.split()[:1] Success! Finally, the operation works perfectly if I initialize the list beforehand: list = string.split() key = list[0] Success! Why does this happen? -- | Evan Kroske Welcome2Obscurity.Blogspot.com http://welcome2obscurity.blogspot.com Glory is fleeting, but obscurity is forever. — some French guy | -- http://mail.python.org/mailman/listinfo/python-list
How to get all named args in a dict?
Suppose I have the following: def foo(x=None, y=None, z=None): d = {x: x, y: y, z: z} return bar(d) I.e. foo takes a whole bunch of named arguments and ends up calling a function bar that takes a single dictionary as argument, and this dictionary has the same keys as in foo's signature, so to speak. Is there some builtin variable that would be the same as the variable d, and would thus obviate the need to explicitly bind d? Thanks! kynn -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get all named args in a dict?
On Wed, May 13, 2009 at 2:50 PM, kj so...@987jk.com.invalid wrote: Suppose I have the following: def foo(x=None, y=None, z=None): d = {x: x, y: y, z: z} return bar(d) I.e. foo takes a whole bunch of named arguments and ends up calling a function bar that takes a single dictionary as argument, and this dictionary has the same keys as in foo's signature, so to speak. Is there some builtin variable that would be the same as the variable d, and would thus obviate the need to explicitly bind d? def foo(**kwargs): return bar(kwargs) I would suggest you read the Python tutorial. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: about Python doc reader
norseman wrote: Tim Golden wrote: Shailja Gulati wrote: Hi , I am currently working on Information retrieval from semi structured Documents in which there is a need to read data from Resumes. Could anyone tell me is there any python API to read Word doc? If you haven't already, get hold of the pywin32 extensions: http://pywin32.sf.net code import win32com.client doc = win32com.client.GetObject (c:/temp/temp.doc) text = doc.Range ().Text /code Note that this will give you a unicode object with \r line-delimiters. You could read para by para if that were more useful: code import win32com.client doc = win32com.client.GetObject (c:/temp/temp.doc) lines = [p.Range () for p in doc.Paragraphs] /code TJG === I saw this right after responding to Kushal's 5:37AM today posting. Thank you for the tip. I'll try these first chance I get. Word, swriter, whatever - I'm not partial when it comes to automating. Today is: 20090513 Steve Interesting: I did try these. Doc at once: outputs two x'0D' and the file. Then it appends x'0D' x'0D' x'0A' x'0D' x'0A' to end of file even though source file itself has no EOL. ( EOL is EndOfLine aka newline ) That's cr cr There are two blank lines at begining. cr cr lf cr lfThere is no EOL in source Any idea what those are about? One crlf is probably from python's print text, but the other? The lines= appends [u'\r', u'\r', u to begining of output and \r]x'0D'x'0A' to the end even though there is no EOL in source. output is understood:u'\r' is Apple EOL the crlf is probably from print lines. Programmers searching for specifics take note. The output is cooked. I don't have any weird things in the test file. (no font changes, no subscripts, etc) Might be best to take a real good look at a test file before assuming anything. But, having an idea of what the extras are makes it somewhat easier to allow for. Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd list behavior
On Wed, May 13, 2009 at 2:51 PM, Evan Kroske e.kro...@gmail.com wrote: I'm working on a simple file processing utility, and I encountered a weird error. If I try to get the first element of a list I'm splitting from a string, I get an error: key = string.split()[0] Error! However, I can slice the list like normal, but that gives me a one-element-long list: key = string.split()[:1] Success! Finally, the operation works perfectly if I initialize the list beforehand: list = string.split() key = list[0] Success! Why does this happen? Please include the actual error messages and Tracebacks in the future. Error! and Success! aren't much to go on; and answering your question without further information is just a guessing game at best. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd list behavior
Evan Kroske wrote: I'm working on a simple file processing utility, and I encountered a weird error. If I try to get the first element of a list I'm splitting from a string, I get an error: key = string.split()[0] Error! However, I can slice the list like normal, but that gives me a one-element-long list: key = string.split()[:1] Success! Finally, the operation works perfectly if I initialize the list beforehand: list = string.split() key = list[0] Success! Why does this happen? -- | Evan Kroske Welcome2Obscurity.Blogspot.com http://welcome2obscurity.blogspot.com Glory is fleeting, but obscurity is forever. — some French guy | == Take a look at the split() command. I think you will find you need one var on the left side for each piece on the right. a=x y b,c= a.split() b x c y Maybe??? Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: n00b question: Possible to pass lists to a Template class?
On Wed, 13 May 2009 17:22:32 +0100, Wells we...@submute.net wrote: On May 13, 11:14 am, Wells we...@submute.net wrote: Is it possible to pass a list to the Template.substitute method and use that in the template, like so.. g = string.Template(gametemplate) print g.substitute(recap = none, winner = game[winner], loser = game[loser]) Then in the template... bwinner.team Where winner.team would be the value of game[winner][team]. Thanks! Sorry, I meant dicts, not lists. Like I said, n00b question. Basically, no. Substituted values are effectively put into the template with '%s' substitution, so you'll just get a string representation of your dictionary. You could play around with defining your own custom Template class, but it's probably not worth the effort. -- Rhodri James *-* Wildebeeste Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd list behavior
On Wed, 13 May 2009 23:08:26 +0100, norseman norse...@hughes.net wrote: Evan Kroske wrote: I'm working on a simple file processing utility, and I encountered a weird error. If I try to get the first element of a list I'm splitting from a string, I get an error: key = string.split()[0] Error! However, I can slice the list like normal, but that gives me a one-element-long list: key = string.split()[:1] Success! Finally, the operation works perfectly if I initialize the list beforehand: list = string.split() key = list[0] Success! Why does this happen? == Take a look at the split() command. I think you will find you need one var on the left side for each piece on the right. Given that he's immediately indexing the split results, that's irrelevant. There's no point in even guessing with out the traceback. -- Rhodri James *-* Wildebeeste Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd list behavior
On 5/13/2009 2:51 PM Evan Kroske said... I'm working on a simple file processing utility, and I encountered a weird error. If I try to get the first element of a list I'm splitting from a string, What value of string gives these results? Emile I get an error: key = string.split()[0] Error! However, I can slice the list like normal, but that gives me a one-element-long list: key = string.split()[:1] Success! Finally, the operation works perfectly if I initialize the list beforehand: list = string.split() key = list[0] Success! Why does this happen? -- | Evan Kroske Welcome2Obscurity.Blogspot.com http://welcome2obscurity.blogspot.com Glory is fleeting, but obscurity is forever. — some French guy | -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd list behavior
Evan Kroske wrote: I'm working on a simple file processing utility, and I encountered a weird error. If I try to get the first element of a list I'm splitting from a string, I get an error: key = string.split()[0] Error! When string contains only whitespace string.split() returns an empty list an then [][0] Traceback (most recent call last): File stdin, line 1, in module IndexError: list index out of range However, I can slice the list like normal, but that gives me a one-element-long list: key = string.split()[:1] Success! The slice length may be shorter than specified: [][:1] [] Finally, the operation works perfectly if I initialize the list beforehand: list = string.split() key = list[0] Success! Not with the same string as in your previous examples. Peter -- http://mail.python.org/mailman/listinfo/python-list
When *don't* I use 'self' in classes?
I am a bit confused as too when, if ever, it is not appropriate to prepend 'self' to objects in a class. All of the examples of how to use 'self' that I find seem to be short and very simple (as examples tent to be). I appologize if I am asking an ignorant question here, but I want to get off on the right foot. Here's an example of what I mean: import serial class foo: def __init(self, comport): self.comport = comport self.baudrate = 9600 #default self.ser = serial try: self.ser.Serial() self.ser.baudrate = self.baudrate self.ser.open() except: print 'Serial port could not be opened' === OR === import serial class foo: def __init(self, comport): self.comport = comport self.baudrate = 9600 #default try: ser = serial.Serial() ser.baudrate = self.baudrate ser.open() except: print 'Serial port could not be opened' There may be a typo in here, this is just a random example similar to something I'm working with, but which one of these are more 'proper'? If I am importing a library do I still prepend it's object with self when I use it in my class? I suppose my question is just basically... when do you NOT prepent an object in a class with 'self'? I'm not even sure I'm using the term 'object' correctly here. Feel free to set me straight, but I hope my example makes it clear what I am asking. Thanks a lot, this ng has already been super helpful as I take my crash-course in to python! :P -- http://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Re: Unable to install Pywin32 for Python 2.6.2
On 13/05/2009 2:18 PM, David Lyon wrote: On Wed, 13 May 2009 05:32:16 +0200, Martin v. Löwismar...@v.loewis.de wrote: I think this was a case of obscure misconfiguration of the system. It is always possible to configure a system in such a way that even the most resilient installation procedure will break. Technically, you are right.. but imho.. windows installers are overkill and shouldn't be used for this sort of thing. That is, installing libraries. And not the fault of the package authors either... But if PYTHONPATH was set incorrectly it really doesn't matter how Python was installed, it would still fail. The installer didn't set PYTHONPATH, a human did. Cheers, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get all named args in a dict?
kj wrote: Suppose I have the following: def foo(x=None, y=None, z=None): d = {x: x, y: y, z: z} return bar(d) I.e. foo takes a whole bunch of named arguments and ends up calling a function bar that takes a single dictionary as argument, and this dictionary has the same keys as in foo's signature, so to speak. Is there some builtin variable that would be the same as the variable d, and would thus obviate the need to explicitly bind d? Use the built-in function locals() def f(a,b): x=locals() print(x) f(1,2) {'a': 1, 'b': 2} -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite single transaction without foreign key or triggers
John Machin wrote in news:b722bd36-c8f1-4cdf-8625-2550cee21511 @i28g2000prd.googlegroups.com in comp.lang.python: On May 13, 11:46 am, a...@pythoncraft.com (Aahz) wrote: In article xns9c09513903e8frtwfreenetremovec...@216.196.109.145, Rob Williscroft r...@freenet.co.uk wrote: Aahz wrote innews:guao50$1j...@panix3.panix.comin comp.lang.python: In article xns9c08e179b66d8rtwfreenetremovec...@216.196.109.145, Rob Williscroft r...@freenet.co.uk wrote: db.execute( ''' update sessions set uid = ? where uid = ? and exists( select * from users where uid = ? ) ''', (v['uid'],s.SID, v['uid']) ) This will be more efficient if you do select uid from users. What will be more efficient ? Do you mean the select * ... or do you want to take the exists sub-query out and put it in a python if ? select uid will be more efficient than select *, although I suppose I could be wrong about that given how little I know about current query optimizers. It seems the usual advice about premeture optimisation should apply, namely write clear code (*), then optimise the bottlenecks when you actualy find you need to. *) for some definition of clear code. My take is that it won't matter what you select if the optimiser is smart enough; something that requires minimal resources to produce is indicated in case the optimiser is dumb: ... exists (select 1 from ... ) I have to maintain some code writen by someone who thinks replacing * in queries with 1 is always a good idea (you know just in case), he wrote: select count(1) from ... of course it didn't do what he thought it did. Rob. -- http://www.victim-prime.dsl.pipex.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: When *don't* I use 'self' in classes?
On Wed, 13 May 2009 23:36:07 +0100, Adam Gaskins agaskins...@kelleramerica.com wrote: I am a bit confused as too when, if ever, it is not appropriate to prepend 'self' to objects in a class. All of the examples of how to use 'self' that I find seem to be short and very simple (as examples tent to be). I appologize if I am asking an ignorant question here, but I want to get off on the right foot. Here's an example of what I mean: import serial class foo: def __init(self, comport): self.comport = comport self.baudrate = 9600 #default self.ser = serial try: self.ser.Serial() self.ser.baudrate = self.baudrate self.ser.open() except: print 'Serial port could not be opened' === OR === import serial class foo: def __init(self, comport): self.comport = comport self.baudrate = 9600 #default try: ser = serial.Serial() ser.baudrate = self.baudrate ser.open() except: print 'Serial port could not be opened' There may be a typo in here, this is just a random example similar to something I'm working with, but which one of these are more 'proper'? If I am importing a library do I still prepend it's object with self when I use it in my class? I suppose my question is just basically... when do you NOT prepent an object in a class with 'self'? I'm not even sure I'm using the term 'object' correctly here. Feel free to set me straight, but I hope my example makes it clear what I am asking. Prepending self to an identifier means that what you are using is an attribute of the class instance that you're dealing with; i.e. you're attaching the object to the instance. Whether or not you want to do that depends entirely on whether you expect to use that object ever again, or whether you're using it once and tossing it away. For the example you give, you're most likely to want to do neither of the above. The first version gives you access to the entire namespace of the serial module as an attribute of instances of the class foo, which is unlikely to be what you want. The second, on the other hand, creates and opens a serial port, then throws it away. It's more likely that you'll want something like this: import serial class foo: def __init__(self, comport): self.comport = comport self.baudrate = 9600 try: self.ser = serial.Serial() self.ser.baudrate = self.baudrate self.ser.open() except: print 'Serial port could not be opened' def send_data(self, data): self.ser.write(data) (except that a bare 'except' like that is a very bad idea (you'll catch keyboard interrupts and the like), but let's assume that you're doing something more detailed for the purposes of this example.) As you can see, making the serial port itself an attribute allows you to use it in other methods. If you had just used ser as in your second example, it would be a local variable to the method foo.__init__(), so it would vanish when __init__ returned just like any other local variable. Making it an attribute keeps it around (attached to just that one instance of the class) so that you can use it later. In general, don't make something an attribute if you know you're never going to reuse it. -- Rhodri James *-* Wildebeeste Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list
Re: n00b question: Possible to pass lists to a Template class?
Rhodri James wrote: On Wed, 13 May 2009 17:22:32 +0100, Wells we...@submute.net wrote: On May 13, 11:14 am, Wells we...@submute.net wrote: Is it possible to pass a list to the Template.substitute method and use that in the template, like so.. g = string.Template(gametemplate) print g.substitute(recap = none, winner = game[winner], loser = game[loser]) Then in the template... bwinner.team Where winner.team would be the value of game[winner][team]. Thanks! Sorry, I meant dicts, not lists. Like I said, n00b question. Basically, no. Substituted values are effectively put into the template with '%s' substitution, so you'll just get a string representation of your dictionary. You could play around with defining your own custom Template class, but it's probably not worth the effort. The closest you can get is to pass a dict: import string s = string.Template(winner is $winner, loser is $loser) s.substitute(winner=w, loser=l) 'winner is w, loser is l' d = {winner: w, loser: l} s.substitute(d) 'winner is w, loser is l' -- http://mail.python.org/mailman/listinfo/python-list
Re: When *don't* I use 'self' in classes?
Adam Gaskins wrote: I am a bit confused as too when, if ever, it is not appropriate to prepend 'self' to objects in a class. All of the examples of how to use 'self' that I find seem to be short and very simple (as examples tent to be). I appologize if I am asking an ignorant question here, but I want to get off on the right foot. Here's an example of what I mean: import serial class foo: def __init(self, comport): ^^ Should be '__init__'. self.comport = comport self.baudrate = 9600 #default self.ser = serial try: self.ser.Serial() self.ser.baudrate = self.baudrate self.ser.open() except: print 'Serial port could not be opened' === OR === import serial class foo: def __init(self, comport): self.comport = comport self.baudrate = 9600 #default try: ser = serial.Serial() ser.baudrate = self.baudrate ser.open() except: print 'Serial port could not be opened' There may be a typo in here, this is just a random example similar to something I'm working with, but which one of these are more 'proper'? If I am importing a library do I still prepend it's object with self when I use it in my class? I suppose my question is just basically... when do you NOT prepent an object in a class with 'self'? I'm not even sure I'm using the term 'object' correctly here. Feel free to set me straight, but I hope my example makes it clear what I am asking. Thanks a lot, this ng has already been super helpful as I take my crash-course in to python! :P In the second example 'ser' is just a local variable within '__init__'. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to see the code definiton in the shell ?
On May 13, 1:26 pm, J. Cliff Dyer j...@sdf.lonestar.org wrote: On Wed, 2009-05-13 at 09:40 -0700, Mohan Parthasarathy wrote: Hi, I am new to Python. I tried searching this but could not find an answer. In the interactive shell, I write a new function and I want to be able to see all the code that I wrote at a later time. Just typing the function name only shows allmethods function allmethods at 0x822b0 How do I see the actual code ? thanks mohan If you save your function to a file you can. Saying you have the following file: #! /usr/bin/env python3 def f(x, y): return x**y saved as f.py, you can go into the interpreter and do: import inspect from f import f inspect.getsource(f) 'def f(x, y):\n\treturn x**y\n' However, trying this on a function written in the interpreter will bail on you. Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't run PyQt apps with MacPython
On Wednesday 13 May 2009 17:53, Morad wrote: I recently got a new MacBook Pro with Leopard, and would like to develop using Python and PyQt. I installed the latest Qt SDK, updated MacPython to V 2.5.4 and then proceeded to install SIP and PyQt as described in Mark Summerfield's book on PyQt Programming. Everything went fine and none of the scripts complained. However when I want to run a demo app, I get the error message Fatal Python error: Interpreter not initialized (version mismatch?) / Abort Trap. Anybody can help? This page suggests a possible conflict between installed Python interpreters: http://aralbalkan.com/1675/comment-page-1 A post to the PyQt mailing list talks about the correct way to build from source, but it may not be relevant in this case: http://www.riverbankcomputing.com/pipermail/pyqt/2006-July/013766.html It may just be worth checking that SIP and PyQt were built and installed for the interpreter you expected. Failing that, you might want to ask this again on the PyQt mailing list: http://www.riverbankcomputing.com/pipermail/pyqt/ David -- http://mail.python.org/mailman/listinfo/python-list
Re: When *don't* I use 'self' in classes?
Adam Gaskins wrote: I am a bit confused as too when, if ever, it is not appropriate to prepend 'self' to objects in a class. All of the examples of how to use 'self' that I find seem to be short and very simple (as examples tent to be). I appologize if I am asking an ignorant question here, but I want to get off on the right foot. Here's an example of what I mean: import serial class foo: def __init(self, comport): self.comport = comport self.baudrate = 9600 #default self.ser = serial try: self.ser.Serial() self.ser.baudrate = self.baudrate self.ser.open() except: print 'Serial port could not be opened' === OR === import serial class foo: def __init(self, comport): self.comport = comport self.baudrate = 9600 #default try: ser = serial.Serial() ser.baudrate = self.baudrate ser.open() except: print 'Serial port could not be opened' There may be a typo in here, Like __init instead of __init__? :) am importing a library do I still prepend it's object with self when I use it in my class? I suppose my question is just basically... when do you NOT prepent an object in a class with 'self'? Use self.attribute when you want the resulting ser object to live beyond the __init__ call. Easily seen in this example: class Foo: def __init__(self): self.abc = 42 xyz = 3.141 # xyz now falls out of scope def test_me(self): print self.abc # succeeds and prints 42 print xyz # fails because xyz doesn't exist # within this scope f = Foo() print dir(f) # has an abc but not an xyz f.test_me() So in your case, unless you *need* to keep the comport/baudrate around, I'd just use -tim DEFAULT_BAUD = 9600 class Foo: def __init__(self, comport): self.comport = comport try: self.ser = Serial() self.ser.baudrate = DEFAULT_BAUD self.ser.open() except SomeSpecificException: print Fail! so that the .ser object is available in other method-calls. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite single transaction without foreign key or triggers
On 14/05/2009 8:21 AM, Rob Williscroft wrote in private e-mail (presumably by mistake): On 13 May 2009, you wrote in comp.lang.python: On May 13, 11:46燼m, a...@pythoncraft.com (Aahz) wrote: In article xns9c09513903e8frtwfreenetremovec...@216.196.109.145, Rob Williscroft r...@freenet.co.uk wrote: Aahz wrote innews:guao50$1j...@panix3.panix.comin comp.lang.python: In article xns9c08e179b66d8rtwfreenetremovec...@216.196.109.145, Rob Williscroft r...@freenet.co.uk wrote: db.execute( ''' update sessions set uid = ? where uid = ? and exists( 爏elect * from users where uid = ? ) ''', (v['uid'],s.SID, v['uid']) ) This will be more efficient if you do select uid from users. What will be more efficient ? Do you mean the select * ... or do you want to take the exists sub-query out and put it in a python if ? select uid will be more efficient than select *, although I suppose I could be wrong about that given how little I know about current query optimizers. It seems the usual advice about premeture optimisation should apply, namely write clear code (*), then optimise the bottlenecks when you actualy find you need to. _Deliberately_ writing * instead of some constant is premature potential pessimisation and thus an utter nonsense. If you think 1 is obscure, then * is likewise obscure; write e.g. 'any_old_constant' instead. *) for some definition of clear code. My take is that it won't matter what you select if the optimiser is smart enough; something that requires minimal resources to produce is indicated in case the optimiser is dumb: ... exists (select 1 from ... ) I have to maintain some code writen by someone who thinks replacing * in queries with 1 is always a good idea (you know just in case), he wrote: select count(1) from ... of course it didn't do what he thought it did. If you really have to maintain code that's been written by weird people and not subsequently tested, you have my sympathy. However this is not relevant. I am certainly not advocating bulk unthinking replacement of * by 1 anywhere in a query. Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the use of the else in try/except/else?
On Wed, 13 May 2009 20:44:27 +1200, Lawrence D'Oliveiro wrote: In message pan.2009.05.12.09.35...@remove.this.cybersource.com.au, Steven D'Aprano wrote: On Tue, 12 May 2009 09:20:36 +, Steven D'Aprano wrote: It seems pretty straightforward to me. Except of course such a pattern won't work ... I rest my case. Gosh, with such shallowness of analysis and out-of-context quoting, how could I possibly disagree? You've convinced me utterly. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python and xml.dom.minidom
On May 12, 1:59 am, dpapathanasiou denis.papathanas...@gmail.com wrote: For the record, and in case anyone else runs into this particular problem, here's how resolved it. My original xml_utils.py was written this way: from xml.dom import minidom def parse_item_attribute (item, attribute_name): item_doc = minidom.parseString(item) ... That version worked under the python interpreter, but failed under both mod_python andmod_wsgiapache modules with an error (Parent module 'xml.dom' not loaded). I found that changing the import statement and the minidom reference within the function resolved the problem. I.e., after rewriting xml_utils.py this way, it works under both apache modules as well as in the python interpreter: import xml.dom.minidom def parse_item_attribute (item, attribute_name): item_doc = xml.dom.minidom.parseString(item) ... FWIW, have just seen someone else raising an issue where something caused problems unless a full package path was used. In that case it was the 'email' package. The common thing between these two packages is that they do funny stuff with sys.modules as part of import. For 'email' package it is implementing some sort of lazy loader and aliasing thing to support old names. For 'xml.dom' it seems to replace the current module with a C extension variant on the fly if the C extension exists. Were you getting this issue with xml.dom showing on first request all the time, or only occasionally occurring? If the latter, were you running things in a multithreaded configuration and was the server being loaded with lots of concurrent requests? For your particular Python installation, does the '_xmlplus' module exist? Ie., can you import it as '_xmlplus' or 'xml.doc._xmlplus'? Graham -- http://mail.python.org/mailman/listinfo/python-list
Extract EPS info?
Just curious if Python has a built-in module for pulling data out of an EPS file? For example, I'd like to pull the text out of an EPS as well as the font names of the characters of the text. I believe I can pull all the font names from the header area, but was hoping Python might have something more robust. Thanks. Jay -- http://mail.python.org/mailman/listinfo/python-list
Proposal to Add New Method to List Object: Mutable Sequence Types
Hi All, This is my first mail to python-list. I just want to propose the idea of introducing a new method for the List Object in similar lines of Dictionary Object has_key method. See my below code, It always produces the ValueError, if I want to check whether an item is present or not, then they is no method in the List Object (do a dir(list)). So., Is it not good, to have a method in List Object, may be something like has_item to check whether a item is present or not? #== CODE == partsOfMyName = ['Python', 'Perl', 'PHP', 'MySQL']; ## strSearchKey = 'Perl'; strSearchKey = 'Prl'; indexofKey = partsOfMyName.index(strSearchKey); print 'Index of search key: %s: %d'%(strSearchKey, indexofKey); Thanks Venkata Rama Krishna Boddu Explore and discover exciting holidays and getaways with Yahoo! India Travel http://in.travel.yahoo.com/-- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal to Add New Method to List Object: Mutable Sequence Types
On Wed, May 13, 2009 at 1:55 AM, VenkataRamaKrishna Boddu bvrkchowd...@yahoo.co.in wrote: Hi All, This is my first mail to python-list. I just want to propose the idea of introducing a new method for the List Object in similar lines of Dictionary Object has_key method. has_key has been removed in Python 3.0; just use the `in` operator instead. The `in` operator also works on lists. Example use: z = [a, b, c] print(b in z) #== True print(d in z) #== False See my below code, It always produces the ValueError, if I want to check whether an item is present or not, then they is no method in the List Object (do a dir(list)). You were looking for __contains__; it's called by the `in` operator. Cheers, Chris -- http://blog.rebertia.com So., Is it not good, to have a method in List Object, may be something like has_item to check whether a item is present or not? #== CODE == partsOfMyName = ['Python', 'Perl', 'PHP', 'MySQL']; ## strSearchKey = 'Perl'; strSearchKey = 'Prl'; indexofKey = partsOfMyName.index(strSearchKey); print 'Index of search key: %s: %d'%(strSearchKey, indexofKey); Thanks Venkata Rama Krishna Boddu Explore and discover exciting holidays and getaways with Yahoo! India Travel Click here! -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
please help with python program
I am trying to use Album Cover Art Downloader, software someone recommended to me. It works fine on my work computer, but not at home. When I try to save the cover art, I get this error: Traceback (most recent call last): File lib/albumart\albumart_dialog.py, line 623, in setCoverForItems File lib/albumart\albumart.py, line 194, in setCover File lib/albumart\albumart_target_windows.py, line 56, in setCover File C:\Python24\lib\site-packages\PIL\Image.py, line 1399, in save IOError: [Errno 13] Permission denied: u'D:/My Music/Ani DiFranco/ Canon/Disc 1\\folder.jpg' I have removed the read-only attribute on the folder, and added Everyone with full control for security. Not sure what else to do. I would really like to get this working so any help would be appreciated. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: please help with python program
On Wed, 13 May 2009 20:39:04 -0700, chedderslam wrote: IOError: [Errno 13] Permission denied: u'D:/My Music/Ani DiFranco/ Canon/Disc 1\\folder.jpg' I have removed the read-only attribute on the folder, and added Everyone with full control for security. Not sure what else to do. I would really like to get this working so any help would be appreciated. What about permissions on the file itself? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: When *don't* I use 'self' in classes?
On May 13, 6:36 pm, Adam Gaskins agaskins...@kelleramerica.com wrote: I am a bit confused as too when, if ever, it is not appropriate to prepend 'self' to objects in a class. All of the examples of how to use 'self' that I find seem to be short and very simple (as examples tent to be). I appologize if I am asking an ignorant question here, but I want to get off on the right foot. Here's an example of what I mean: import serial class foo: def __init(self, comport): self.comport = comport self.baudrate = 9600 #default self.ser = serial try: self.ser.Serial() self.ser.baudrate = self.baudrate self.ser.open() except: print 'Serial port could not be opened' === OR === import serial class foo: def __init(self, comport): self.comport = comport self.baudrate = 9600 #default try: ser = serial.Serial() ser.baudrate = self.baudrate ser.open() except: print 'Serial port could not be opened' There may be a typo in here, this is just a random example similar to something I'm working with, but which one of these are more 'proper'? If I am importing a library do I still prepend it's object with self when I use it in my class? I suppose my question is just basically... when do you NOT prepent an object in a class with 'self'? I'm not even sure I'm using the term 'object' correctly here. Feel free to set me straight, but I hope my example makes it clear what I am asking. Thanks a lot, this ng has already been super helpful as I take my crash-course in to python! :P Others have said something like use self prepended to an object if you are going to use it again. I'd prefer to think of it more like use self prepended to an object if you'd like other functions to be able to know about that object.. Is say this because you can have functions called over and over, and their contents used again, but you still might not mind if their objects are local only to that function. I just think of it that if I am going to need this object to be generally available to the whole class, I throw a self. on. If not, I might not bother. -- http://mail.python.org/mailman/listinfo/python-list
Distributed locking
Hey all, I'm looking for suggestions on how to tackle distributed locking across several Python programs on several different machines. - the objects to be locked are uniquely identified by an integer - I need one at a time semantics for the lock: zero or one read- writer at any point - the operations to be performed on the objects are strictly limited in duration (no more than 10 seconds) As the operations have a maximum duration, my ideal solution would be to lock the objects, and have them automatically unlock after some time period even if the original lock-holder doesn't release them. I'm currently playing with memcached as a locking mechanism as it's simplicity and timeout fit my requirements well. There is a check-and-set operation which atomically writes new data iff the existing value hasn't been changed since we last looked. However, their CAS operation doesn't handle the case of a non-existent key.. Does anyone have suggestions on how I can do distributed locking to take advantage of the time limit on operations? Many thanks, James -- http://mail.python.org/mailman/listinfo/python-list
Assigning multiple variables to a list a la php's list()
Can you take a list and have it exploded into variables w/ one command? Something like.. list = ['foo', 'bar'] [a, b] = list Then 'a' would be foo and 'b' 'bar'. Like list($a,$b) = $list in PHP. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Assigning multiple variables to a list a la php's list()
On Wed, May 13, 2009 at 9:17 PM, Wells we...@submute.net wrote: Can you take a list and have it exploded into variables w/ one command? Something like.. list = ['foo', 'bar'] [a, b] = list Then 'a' would be foo and 'b' 'bar'. Did you think to try it at the interpreter? That exact syntax works, though we usually write it without the brackets, like: a, b = list Also, don't use list as a variable name since it clashes with the builtin type. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the use of the else in try/except/else?
A really great use for try/except/else would be if an object is implementing its own __getitem__ method, so you would have something like this: class SomeObj(object): def __getitem__(self, key): try: #sometype of assertion here based on key type except AssertionError, e: raise TypeError, e #invalid type else: #continue processing, etc.. return some index, which will auto throw #an index error if you have some type of indexable datastructure -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the use of the else in try/except/else?
On Thu, 14 May 2009 00:39:35 -0400, ma wrote: A really great use for try/except/else would be if an object is implementing its own __getitem__ method, so you would have something like this: class SomeObj(object): def __getitem__(self, key): try: #sometype of assertion here based on key type except AssertionError, e: raise TypeError, e #invalid type Why raise AssertionError only to catch it and raise TypeError? Why not just raise TypeError in the first place? If you're thinking of writing this: assert isinstance(key, whatever) you should be aware that when Python is run with the -O flag (optimize), all asserts are disabled, and so your error checking code will not run and your program will crash and burn in a horrible flaming mess. [st...@wow-wow ~]$ python -O Python 2.5 (r25:51908, Nov 6 2007, 16:54:01) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Type help, copyright, credits or license for more information. assert None is 2 The assert statement is not for runtime error checking. assert is for checking your program logic and invariants. If you've ever written a comment like: # When we get here, then x will always be greater than 3. (or something like that), that's a great candidate for an assertion: assert x 3, x is unexpectedly less than or equal to three For error checking, you should do something like this: if not isinstance(key, whatever): raise ValueError rather than: try: if not isinstance(key, whatever): raise AssertionError except AssertionError: raise ValueError -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Re: Unable to install Pywin32 for Python 2.6.2
On Thu, 14 May 2009 08:33:12 +1000, Mark Hammond skippy.hamm...@gmail.com wrote: But if PYTHONPATH was set incorrectly it really doesn't matter how Python was installed, it would still fail. The installer didn't set PYTHONPATH, a human did. Hi Mark, Well I am just trying to write a package manager for python because I felt spoiled on my last platform, perl. When I came to python I found a bit primitive in python under windows in comparison. I felt like starting to write something that might be useful.. I've personally used your packages at work and find them useful. At the same time it is a very interesting learning process about python and how it works.. Best Regards David -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the use of the else in try/except/else?
That's great to know! Thanks for that explanation, I am refactoring something and I was going to make ample use of assertion as I thought it was the same as C's assertion without the NDEBUG flag. On Thu, May 14, 2009 at 1:03 AM, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: On Thu, 14 May 2009 00:39:35 -0400, ma wrote: A really great use for try/except/else would be if an object is implementing its own __getitem__ method, so you would have something like this: class SomeObj(object): def __getitem__(self, key): try: #sometype of assertion here based on key type except AssertionError, e: raise TypeError, e #invalid type Why raise AssertionError only to catch it and raise TypeError? Why not just raise TypeError in the first place? If you're thinking of writing this: assert isinstance(key, whatever) you should be aware that when Python is run with the -O flag (optimize), all asserts are disabled, and so your error checking code will not run and your program will crash and burn in a horrible flaming mess. [st...@wow-wow ~]$ python -O Python 2.5 (r25:51908, Nov 6 2007, 16:54:01) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Type help, copyright, credits or license for more information. assert None is 2 The assert statement is not for runtime error checking. assert is for checking your program logic and invariants. If you've ever written a comment like: # When we get here, then x will always be greater than 3. (or something like that), that's a great candidate for an assertion: assert x 3, x is unexpectedly less than or equal to three For error checking, you should do something like this: if not isinstance(key, whatever): raise ValueError rather than: try: if not isinstance(key, whatever): raise AssertionError except AssertionError: raise ValueError -- Steven -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
[issue4660] multiprocessing.JoinableQueue task_done() issue
Changes by Alvaro al...@ifca.unican.es: -- nosy: +aloga ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4660 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2813] No float formatting in PyString_FromFormat
Mark Dickinson dicki...@gmail.com added the comment: I also think it would be good to use PyOS_double_to_string here. That does make it impossible to format long doubles, though, except by doing a possibly lossy conversion to double first. As far as I can see, Python doesn't use long double anywhere outside the ctypes module, so I'm not sure that long double support really matters right now. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2813 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com