Re: Inner workings of this Python feature: Can a Python data structure reference itself?
On Sunday, May 3, 2015 at 4:48:11 AM UTC+5:30, Terry Reedy wrote: On 5/2/2015 4:02 PM, vasudevram wrote: Hi group, Please refer to this blog post about code showing that a Python data structure can be self-referential: http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html Gotten a couple of comments on it already, but interested in hearing thoughts of Python core dev team members or others who can comment on the internals of how this feature operates, why, etc. Please correct the following: g (a list) contains itself as a list item (of g). g is a dict, as you yourself later said. Case 2) But if the evaluation works in a different order, i.e. the globals() function is first called (before the variable g is created), then at this point its return value (the dict) should not contain the item with key 'g' (and value g), and it is this dict that should get assigned to the variable g. Hence when we print g, we should not see g again within it. This seems like you are presenting this as a statement of fact, but you then admit it is false. The lead in sentence should more carefully state that what follows are possible hypotheses. one is true and the other (mostly) not. The key point is the meaning of the globals() function returns a dict representing the current global symbol table, Global symbol table is an abstraction. In CPython, the implementation is a dict and globals returns that dict, not a copy. Python generally does not copy objects unless requested. Similarly, locals() returns a dict representing the current local symbol table. In a CPython class statement, the local symbol table is implemented with a dict, and locals() is that dict. In a CPython def statement, the local symbol table is implemented as a C array (of pointers to PyObjects). Locals() is a dict (created just once) updated from local names in the code object and the objects in the array *at the time of the call* def f(a): g = locals() print(id(g), g) g = locals() print(id(g), g) f(3) 56288136 {'a': 3} 56288136 {'a': 3, 'g': {...}} 'Case 2 applies for the first locals() call, but only for the first. I believe that there was a time when printing a recursive structure hit the recursion limit like your flatten did. But I will not reload 1.5 to check. -- Terry Jan Reedy Terry Reedy: Thanks for the detailed answer. I have corrected the list vs. dict mistake in a comment to my original post on my blog. Don't want to edit the post itself since some readers will get it twice via feed readers. Re. statement of fact vs. hypotheses. While I'm not sure of your exact meaning in that paragraph, I understand the concept, and yes, I was not clear enough in phrasing that part. It should have read like something along these lines: Observations - One or more hypotheses - deductions - one or more alternative conclusions. I mixed that up a bit. Thanks. - Vasudev -- https://mail.python.org/mailman/listinfo/python-list
Re: Inner workings of this Python feature: Can a Python data structure reference itself?
On Sunday, May 3, 2015 at 1:32:14 AM UTC+5:30, vasudevram wrote: Hi group, Please refer to this blog post about code showing that a Python data structure can be self-referential: http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html Gotten a couple of comments on it already, but interested in hearing thoughts of Python core dev team members or others who can comment on the internals of how this feature operates, why, etc. Thanks Vasudev Ram Site: www.dancingbison.com Python posts: jugad2.blogspot.com/search/label/python Thanks again to all who answered. I will reply separately today to individual answers that need a reply. - Vasudev -- https://mail.python.org/mailman/listinfo/python-list
Re: Inner workings of this Python feature: Can a Python data structure reference itself?
On Sunday, May 3, 2015 at 6:30:16 PM UTC+5:30, vasudevram wrote: On Sunday, May 3, 2015 at 4:48:11 AM UTC+5:30, Terry Reedy wrote: On 5/2/2015 4:02 PM, vasudevram wrote: Hi group, Please refer to this blog post about code showing that a Python data structure can be self-referential: http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html Gotten a couple of comments on it already, but interested in hearing thoughts of Python core dev team members or others who can comment on the internals of how this feature operates, why, etc. Please correct the following: g (a list) contains itself as a list item (of g). g is a dict, as you yourself later said. Case 2) But if the evaluation works in a different order, i.e. the globals() function is first called (before the variable g is created), then at this point its return value (the dict) should not contain the item with key 'g' (and value g), and it is this dict that should get assigned to the variable g. Hence when we print g, we should not see g again within it. This seems like you are presenting this as a statement of fact, but you then admit it is false. The lead in sentence should more carefully state that what follows are possible hypotheses. one is true and the other (mostly) not. The key point is the meaning of the globals() function returns a dict representing the current global symbol table, Global symbol table is an abstraction. In CPython, the implementation is a dict and globals returns that dict, not a copy. Python generally does not copy objects unless requested. Similarly, locals() returns a dict representing the current local symbol table. In a CPython class statement, the local symbol table is implemented with a dict, and locals() is that dict. In a CPython def statement, the local symbol table is implemented as a C array (of pointers to PyObjects). Locals() is a dict (created just once) updated from local names in the code object and the objects in the array *at the time of the call* def f(a): g = locals() print(id(g), g) g = locals() print(id(g), g) f(3) 56288136 {'a': 3} 56288136 {'a': 3, 'g': {...}} 'Case 2 applies for the first locals() call, but only for the first. I believe that there was a time when printing a recursive structure hit the recursion limit like your flatten did. But I will not reload 1.5 to check. -- Terry Jan Reedy Terry Reedy: Thanks for the detailed answer. I have corrected the list vs. dict mistake in a comment to my original post on my blog. Don't want to edit the post itself since some readers will get it twice via feed readers. Re. statement of fact vs. hypotheses. While I'm not sure of your exact meaning in that paragraph, I understand the concept, and yes, I was not clear enough in phrasing that part. It should have read like something along these lines: Observations - One or more hypotheses - deductions - one or more alternative conclusions. I mixed that up a bit. Thanks. - Vasudev I may have needed to put the experiments step in there as well :) See: http://en.wikipedia.org/wiki/Scientific_method -- https://mail.python.org/mailman/listinfo/python-list
Re: Inner workings of this Python feature: Can a Python data structure reference itself?
On Sunday, May 3, 2015 at 6:38:28 PM UTC+5:30, Chris Angelico wrote: On Sun, May 3, 2015 at 10:59 PM, vasudevram vasudev...@gmail.com wrote: Re. statement of fact vs. hypotheses. While I'm not sure of your exact meaning in that paragraph, I understand the concept, and yes, I was not clear enough in phrasing that part. It should have read like something along these lines: Observations - One or more hypotheses - deductions - one or more alternative conclusions. I just took a glance at your blog post, and it's reasonably clear now. (Though I tend to try to avoid making substantive edits to blog posts once they've been published and read; a codicil, or at very least an italicized comment saying (Edit: Actually, blah blah blah.), is clearer. Of course, trivial edits like typos can be corrected - nobody would be bothered by those unexpectedly changing.) Posts to the newsgroup/mailing list basically can't be edited, so the normal way to acknowledge an error or correction is simply a follow-up post. ChrisA Good points, thanks. -- https://mail.python.org/mailman/listinfo/python-list
Re: Inner workings of this Python feature: Can a Python data structure reference itself?
On Sunday, May 3, 2015 at 1:47:04 AM UTC+5:30, Tim Chase wrote: [dangit, had Control down when I hit enter and it sent prematurely] On 2015-05-02 13:02, vasudevram wrote: http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html https://docs.python.org/2/reference/datamodel.html and saw this excerpt: [ CPython implementation detail: CPython currently uses a reference-counting scheme with (optional) delayed detection of cyclically linked garbage, which collects most objects as soon as they become unreachable, but is not guaranteed to collect garbage containing circular references. ] Not sure whether it is relevant to the topic at hand, since, on the one hand, it uses the words cyclically linked, but on the other, it says garbage collection. The gotcha happens in a case where you do something like this: lst = [] lst.append(lst) # create a cycle del lst This creates a cycle, then makes it unreachable, but the list is still referenced by itself, so the reference count never drops to zero (where it would get GC'd), and thus that item lingers around in memory. If you know that you're creating such cyclical structures, it's best to manually unlink them before freeing them: lst = [] lst.append(lst) # create the cycle lst[:] = [] # break the cycle # or lst.remove(lst) # though this takes more care del lst -tkc Thanks for the reply. Will check that out. -- https://mail.python.org/mailman/listinfo/python-list
Inner workings of this Python feature: Can a Python data structure reference itself?
Hi group, Please refer to this blog post about code showing that a Python data structure can be self-referential: http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html Gotten a couple of comments on it already, but interested in hearing thoughts of Python core dev team members or others who can comment on the internals of how this feature operates, why, etc. Thanks Vasudev Ram Site: www.dancingbison.com Python posts: jugad2.blogspot.com/search/label/python -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)
Thanks to all those who answered. - Vasudev -- https://mail.python.org/mailman/listinfo/python-list
Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)
Hi list, Can anyone - maybe one of the Python language core team, or someone with knowledge of the internals of Python - can explain why this code works, and whether the different occurrences of the name x in the expression, are in different scopes or not? : x = [[1,2], [3,4], [5,6]] [x for x in x for x in x] I saw this on a Hacker News thread about Python, and here is a post I wrote that gives more details about it, including relevant links, how I found that it can be extended to a triply-nested list, and my thoughts about the scope issue: http://jugad2.blogspot.in/2014/03/flatten-list-of-lists-with-list.html A few people commented about it, both on my blog, and on the Python Reddit where I also submitted my post, but I'm not sure I'm convinced of their reasoning or understand it, hence posting the question here. Thanks, Vasudev Ram www.dancingbison.com jugad2.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)
On Saturday, March 22, 2014 2:24:00 AM UTC+5:30, Rustom Mody wrote: Lets try without comprehending comprehensions :-) x=[[1,2],[3,4]] for x in x: ... for x in x: ... print x ... 1 2 3 4 Nice and all, thanks, but doesn't answer the question. -- https://mail.python.org/mailman/listinfo/python-list
Domino, a Python PaaS for data science
Hi list, This may be of interest: Domino, a Python PaaS for data science: http://jugad2.blogspot.in/2013/12/domino-paas-for-data-science.html - Vasudev Ram Software training and consulting Python, Linux, C, open source, databases ... www.dancingbison.com jugad2.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Approach to creating a Boolean expression parser in Python?
Hi list, I'm working on an app in which longish text chunks (could be up to a few MB in size, and stored either in flat text files or in fields of database records - TBD) need to be searched for the presence of a combination of string constants, where the string constants can be combined with boolean operators (in the user input given in a web form, for the search). The DB is MongoDB, accessed from Python using the PyMongo driver / client. The text chunks are associated with structured fields of database records, of users (say, suppliers), so the end result wanted is that the app user should be able to specify a search using boolean operators and the app should search across all the text chunks belonging to all users (users to text chunks is a one-to-many relationship, whether the chunks are stored as long varchar in the DB or as flat files, with a field of a database record containing the filename of the text file containing the chunk). Then the app should return both the user names and the corresponding text chunks, for chunks that matched the boolean expression. Example return value: user2 filename1.txt filename4.txt user5 filename3.txt user7 filename6.txt (where the filenames.txt could instead be the chunks of text, if the chunks are stored in the DB instead of the file system). The boolean expressions can be like these: apple and orange apple or pear apple and (pear or mango) (apple and pear) or mango not orange apple or not (pear and orange) etc. What are some good approaches to doing this using Python? I'm first looking at pure Python code approaches, though have considered using search tools like Solr (via PySolr), ElasticSearch, etc. Right now the app is in the prototype stage so I first want to establish the feasibility and a simple approach to doing the search, though later, if the app needs to scale, may investigate the tools like PySolr or ES. I think I may need to use one of the parsing libraries for Python such as PLY and others mentioned here: https://wiki.python.org/moin/LanguageParsing Let's say a parse tree is built up by whichever approach is used. A related question would be how to use this parse tree to search in the text chunks. I realize that it is a somewhat complex questiom, so am not looking for complete solutions, but for suggestions on how to go about it. Thanks for any suggestions. -- Vasudev Ram www.dancingbison.com jugad2.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
xtopdf, a Python toolkit for PDF creation from other file formats
Hi list, xtopdf is not new. I first created it some years ago. And have been updating it with new features and capabilities now and then. But I realized that there was no central place where its features and uses were described. So I created an online presentation about xtopdf, using http://slid.es, a cool online presentation service that I saw recently. Here is a blog post about the online presentation about xtopdf: http://jugad2.blogspot.in/2013/10/xtopdf-online-presentation.html Enjoy. - Vasudev Ram Dancing Bison Enterprises Software training and consulting (Python, C, Linux, databases, open source, ...) http://www.dancingbison.com http://jugad2.blogspot.com https://mobile.twitter.com/vasudevram -- https://mail.python.org/mailman/listinfo/python-list
Convert Microsoft Word files to PDF with DOCXtoPDF
Hi list, I hope some people may find this useful. This post by me shows how to use DOCXtoPDF (a program I wrote recently) to convert the text in Microsoft Word files (that are in DOCX format) to PDF: Convert Microsoft Word files to PDF with DOCXtoPDF http://jugad2.blogspot.in/2013/10/convert-microsoft-word-files-to-pdf.html The prerequisites are also mentioned. They are: Python, Reportlab, my xtopdf toolkit and python-docx. --- - Vasudev Ram Dancing Bison Enterprises Software training and consulting - Python, Linux, databases, open source ... http://www.dancingbison.com http://jugad2.blogspot.com --- -- https://mail.python.org/mailman/listinfo/python-list
New way of writing socket servers in #Linux kernel 3.9 (and in #Python too)
This may be of interest to readers of this newsgroup: Original article: http://lnkd.in/taAFNt Content (without links): A new way of writing socket servers has been introduced with the Linux kernel 3.9. It involves the ability to bind multiple listening sockets to the same port on the same host, by unrelated processes or threads. The socket option is called SO_REUSEPORT. Article about SO_REUSEPORT. The above article includes a demo of how to use the feature in Python, using the example of a simple echo server and netcat. Another article about SO_REUSEPORT on LWN.net by Michael Kerrisk. Hacker News thread about SO_REUSEPORT. About Michael Kerrisk. He has worked at DEC (Digital Equipment Corporation) and Google in the past. Coincidentally, I happened to have come across Michael Kerrisk's Unix and Linux work some months earlier and had emailed him with a few questions about it, which he was kind enough to answer. Kerrisk is the author of the book The Linux Programming Interface, which seems like an interesting and useful book. From the web site for the The Linux Programming Interface book: [ The Linux Programming Interface (published in October 2010, No Starch Press, ISBN 978-1-59327-220-3) is a detailed guide and reference for Linux and UNIX system programming. With 1552 pages, 115 diagrams, 88 tables, nearly 200 example programs, and over 200 exercises, TLPI is the most comprehensive description of Linux and UNIX system programming available. The author, Michael Kerrisk, is the maintainer of the Linux man-pages project, which documents the Linux kernel and glibc APIs. He has long been active in the documentation, testing, and design review of Linux kernel-userspace interfaces. ] And if you want to write command-line programs in Linux using C (an area closely related to the topic of the TLPI book), you may wish to check out my article on the subject, written for IBM developerWorks: Developing a Linux command-line utility. I have not yet tried out the SO_REUSEPORT option, because I need to get Linux kernel 3.9 first, but it seems like a useful technique for increasing performance of socket servers. Note that there are various other issues involved, so you may not get increased performance just by using this option in your code. As always with performance tuning, you have to profile your code, identify hotspots, and then only work on improving certain parts of it that seem to be the bottlenecks. And in this case, even before all that, you may need to evaluate whether this socket option is relevant to your application at all. So, caveat lector :-) - Vasudev Ram - Dancing Bison Enterprises -- http://mail.python.org/mailman/listinfo/python-list
Python, meet Turtle
http://jugad2.blogspot.com/2013/07/python-meet-turtle.html -- http://mail.python.org/mailman/listinfo/python-list
XMLtoPDFBook v1.1 released: Create simple PDF books from XML text content
XMLtoPDFBook v1.1 released: XMLtoPDFBook is a program that lets you create simple PDF books from XML text content, including support for chapter numbers and names, headers and footers, automatic pagination, and page numbers. Please see this blog post about XMLtoPDFBook: XMLtoPDFBook now supports chapter numbers and names: http://jugad2.blogspot.in/2013/06/xmltopdfbook-now-supports-chapter.html XMLtoPDFBook is not separately released as a stand-alone product; I've added it as one of the components of my larger xtopdf project. But you can use it as a separate product, once you install the prerequisites, which include 1) v1.21 of the open source version of the ReportLab toolkit for PDF creation, and 2) xtopdf itself. The blog post linked above, has links to download xtopdf (and hence, XMLtoPDFBook). The same post (which also links to a previous post about XMLtoPDFBook), also shows how to use XMLtoPDFBook to generate simple PDF ebooks from the text content in XML files that are created in a specific format. The format is simple: the top-level element should be a book element, and the inner elements should be chapter elements. Chapter elements can have an optional attribute like this: chapter name=chapter_name Using this attribute will result in the specific chapter name being displayed in the header for the pages comprising that chapter (in the PDF output). Here is a guide to installing and using xtopdf: http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html Enjoy, and give feedback, if any. - Vasudev Ram Dancing Bison Enterprises Python, Linux and open source training and consulting http://dancingbison.com http://jugad2.blogspot.com https://twitter.com/vasudevram -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
XML to PDF book with ElementTree and xtopdf
Hi list, This may be of interest - a program to create simple PDF books from XML text content: Create PDF books with XMLtoPDFBook: http://jugad2.blogspot.in/2013/06/create-pdf-books-with-xmltopdfbook.html XMLtoPDFBook.py requires ElementTree (which is in the standard Python library), xtopdf, ReportLab and Python. Relevant download links for xtopdf and ReportLab are in the post linked above. Here is a guide to installing xtopdf: http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html - Vasudev Ram Python, Linux and open source consulting and training Site: http://dancingbison.com Blog: http://jugad2.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
PDF in a Bottle - creating PDF using xtopdf, ReportLab, Bottle and Python
Hi list, Might be of interest: PDF in a Bottle - creating PDF using xtopdf, ReportLab, Bottle and Python http://jugad2.blogspot.in/2013/05/pdf-in-bottle-creating-pdf-using-xtopdf.html - Vasudev Ram Python, Linux and open source training and development www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Riemann and Bernhard, a distributed systems monitor and Python client
This may be of interest to the group: Riemann and Bernhard, a distributed systems monitor and Python client http://jugad2.blogspot.in/2013/06/riemann-and-bernhard-distributed.html - Vasudev Ram dancingbison.com Python training and consulting -- http://mail.python.org/mailman/listinfo/python-list
Multiple Python one-liners
http://jugad2.blogspot.com/2013/06/multiple-python-one-liners.html Some interesting and useful one-liners there ... -- http://mail.python.org/mailman/listinfo/python-list
ANN: Using xtopdf and pypyodbc to publish MS Access database data to PDF
Wrote a program that lets you publish your MS Access database data to PDF, using Python, ReportLab, xtopdf and pypyodbc. (This code will go into my xtopdf toolkit (a Python toolkit for PDF creation) after cleanup, in a while.) Link: http://jugad2.blogspot.in/2013/04/using-xtopdf-and-pypyodbc-to-publish-ms.html Note: Saw some comments about my blog post on the Python Reddit, which made me realize that I had not explained that similar code can be used to publish data from any ODBC database (for which you have an ODBC driver, and which is supported by pypyodbc), to PDF. All you have to do is change the connection string in the code, and maybe a few other small tweaks for differences between SQL dialects of different RDBMS's. Enjoy. - Vasudev Ram www.dancingbison.com jugad2.blogspot.com bitbucket.org/vasudevram/xtopdf -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
PDF in a Bottle - creating PDF using xtopdf, ReportLab, Bottle and Python
pdf_bottle.py is a program I wrote that allows you to create a PDF file from text, over the web, by entering your text into a form and submitting it. Here is the post about it: http://jugad2.blogspot.in/2013/05/pdf-in-bottle-creating-pdf-using-xtopdf.html - Vasudev Ram dancingbison.com jugad2.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What is the reason for defining classes within classes in Python?
On Wednesday, April 24, 2013 6:20:36 AM UTC+5:30, alex23 wrote: On Apr 24, 9:13 am, vasudevram vasudev...@gmail.com wrote: On Wednesday, April 24, 2013 3:52:57 AM UTC+5:30, Ian wrote: On Tue, Apr 23, 2013 at 3:50 PM, vasudevram wrote: I saw an example of defining a class within another class In what way is this useful? In that particular case they're just using it as a namespace. Not clear. An example or more explanation might help, if you can. Thanks. Namespaces are used to allow for the same label to be applied to different concepts without the labels conflicting with each other. If I was writing a program that dealt with the mathematics of morality, I might want to use the sine function and refer to it in the standard way as 'sin', and I might also want to store a value representing your lack of goodness as 'sin'. As you can't use the same label in the same scope to refer to two different objects, one way of dealing with this that lets you still use what you feel are the most appropriate names is to put them into a namespace. So you could express this as: class Math(object): sin = function() class Morality(object): sin = True Then in your code you can clearly distinguish between the two by using Math.sin and Morality.sin. Modules packages are also namespaces, so in this example we'd replace the Math class with `import math`, which has a sin function defined within it. A nested class definition will be defined as an attribute of the class its defined within: class Outer(object): ... foo = 'FOO' ... class Inner(object): ... bar = 'BAR' ... Outer.Inner class '__main__.Inner' Outer.Inner.bar 'BAR' With peewee, the Model class looks for a Meta attribute and uses attributes on it to perform some tasks, like where to retrieve/store the model data. This allows for a way of distinguishing between attributes used to define fields, and attributes needed for those tasks. It also means your Models can use field names that the class would otherwise reserve for its own internal purposes: class DatabaseDetails(Model): # these attributes are fields database = CharField() owner = CharField() # ...but the Meta attribute isn't class Meta: # these attributes are used by the Model class database = db Here, database as a field is a text string that could contain a database name, while DatabaseDetails.Meta.database contains a reference to an actual database where the DatabaseDetails record would be stored. Actually, I did know what namespaces are in general. What I didn't get was how the inner class Meta in the peewee example was being used as a namespace. Your explanation makes things very clear. Thank you. Just one other doubt: Outer.Inner class '__main__.Inner' In the above output, I would have thought Python would print __main__.Outer.Inner or Outer.Inner instead of __main__.Inner, since Inner is an attribute of Outer? -- http://mail.python.org/mailman/listinfo/python-list
Re: What is the reason for defining classes within classes in Python?
Interesting. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
What is the reason for defining classes within classes in Python?
Hi list, I saw an example of defining a class within another class, here, in the docs for peewee, a simple ORM for Python: http://peewee.readthedocs.org/en/latest/peewee/quickstart.html In what way is this useful? Thanks, Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: What is the reason for defining classes within classes in Python?
On Wednesday, April 24, 2013 3:52:57 AM UTC+5:30, Ian wrote: On Tue, Apr 23, 2013 at 3:50 PM, vasudevram wrote: Hi list, I saw an example of defining a class within another class, here, in the docs for peewee, a simple ORM for Python: http://peewee.readthedocs.org/en/latest/peewee/quickstart.html In what way is this useful? In that particular case they're just using it as a namespace. Django does the same thing. Not clear. An example or more explanation might help, if you can. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Using xtopdf and pypyodbc to publish MS Access database data to PDF
Wrote a program that lets you publish your MS Access database data to PDF, using Python, ReportLab, xtopdf (my toolkit) and pypyodbc. Sharing it here. Link: http://jugad2.blogspot.in/2013/04/using-xtopdf-and-pypyodbc-to-publish-ms.html Note: Saw some comments about my blog post on the Python Reddit, which made me realize that I had not explained that similar code can be used to publish data from any ODBC database (for which you have an ODBC driver, and which is supported by pypyodbc), to PDF. All you have to do is change the connection string in the code, and maybe a few other small tweaks for differences between SQL dialects of different RDBMS's. Enjoy. - Vasudev Ram www.dancingbison.com jugad2.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
youtube-dl, a YouTube downloader in Python
Folks may find this of interest, both from a programming and from an end-user point of view: youtube-dl, a YouTube downloader in Python: http://jugad2.blogspot.in/2013/03/youtube-dl-yourube-downloader-in-python.html I tried it out and it worked well. Downloaded a few videos using it. (The rube in the URL was a typo, I would have had to delete and re-enter the post to fix it - see the post for the details :) - Vasudev Ram www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Curl and python httplib?
On Tuesday, April 2, 2013 1:03:58 AM UTC+5:30, Mark Lawrence wrote: On 30/03/2013 05:08, СѧPHP wrote: Guys, I take a project that need send request to Hadoop by curl. But now, the curl and pycurl can't satisfy my project. So i need use the powerful httplib. But failed. *my curl request:* curl -i -X PUT http://localhost:50070/webhdfs/v1/levi/7?op=CREATE; *my return:* HTTP/1.1 307 TEMPORARY_REDIRECT Content-Type: application/octet-stream Location: http://58.53.211.47:50075/webhdfs/v1/levi/7?op=CREATEoverwrite=false Content-Length: 0 Server: Jetty(6.1.26) *Now, i change the curl request to httplib:* import httplib import urllib params=urllib.urlencode({@op:CREATE,@user.name:levi}) headers={Content-type: application/x-www-form-urlencoded,Accept: text/plain} conn=httplib.HTTPConnection(localhost:50070) conn.request(PUT,/webhdfs/v1/levi/7.txt,params,headers) response=conn.getresponse() print response.status, response.reason data=response.read() print data conn.close() *But it failed:* #print response.status, response.reason 500 Internal Server Error #print data '{RemoteException:{exception:WebApplicationException,javaClassName:javax.ws.rs.WebApplicationException,message:null}}' Who knows why? It's OK when i use curl, so where is the problem in httplib method? Or some other reasons? Who can help me change the curl request to httplib edition? TIA Levi Try the requests module https://pypi.python.org/pypi/requests/ as if I can successfuly use it anybody can :) -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence Or try httplib2 GIYF -- http://mail.python.org/mailman/listinfo/python-list
PDFBuilder can now take multiple input files from command line
Here is the blog post about it: http://jugad2.blogspot.in/2012/11/pdfbuilder-can-now-take-multiple-input.html In short: removed the temporary hard-coding, refactored the code some. PDFBuilder can now use multiple input files (of type .csv / .tdv), specified on the command-line, to create a composite PDF from those inputs. .tdv = Tab Delimited Values, such as commonly used in UNIX tools like sed / grep / awk and friends. - Vasudev Ram www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
PDFBuilder can create composite PDFs
PDFBuilder is a tool to create composite PDFs, i.e. PDFs comprising of data from multiple different input data formats (any number of files, in any order). It is a new component of my xtopdf toolkit for PDF generation. A blog post about PDFBuilder gives more information, an example, and a download link: http://jugad2.blogspot.in/2012/11/pdfbuilderpy-can-create-composite-pdfs.html - Vasudev Ram http://www.dancingbison.com http://jugad2.blogspot.com http://twitter.com/vasudevram -- http://mail.python.org/mailman/listinfo/python-list
ANN: v0.3 of pipe_controller released; supports swapping pipe components at run time
I've released v0.3 of pipe_controller (*), my experimental tool to simulate pipes in Python: https://bitbucket.org/vasudevram/pipe_controller (*) I had earlier been calling it PipeController, but that is the name of the main class in the package. From now on I'm referring to it as pipe_controller (the Python module name). Changes in v0.3: - you can now swap components of a pipe_controller pipe at run time, and it can separately save the results of running the pipe, before and after a component swap, to separate output files; the test program test_pipe_controller_04.py in the download package shows how to do this. That is, you can do something like this (using UNIX syntax, though pipe_controller is in Python and works differently): foo | bar | baz # with output going to file 1 then swap the positions of foo and baz, then run the pipe again: baz | bar | foo # with output going to file 2 and so on - any number of times, all in the same program run. This feature lets you experiment with, and validate, your pipeline logic, to make sure that it does what you intended, e.g. you can check the output both before and after swapping components of the pipe, to decide which order you really need - or which order is optimal - see next paragraph. The feature can also be used to time the execution of two or more different versions of the pipeline (with vs. without swapping of components), to see which runs faster, for cases where changing the order of those components makes no difference to the output, e.g. if those two components are commutative, in the mathematical sense (like a + b = b + a). Blog post about swapping pipe components at run time with pipe_controller: http://jugad2.blogspot.in/2012/10/swapping-pipe-components-at-runtime.html pipe_controller v0.3 can be downloaded here: https://bitbucket.org/vasudevram/pipe_controller/downloads (Click on the Branches tab on that page) - Vasudev Ram www.dancingbison.com jugad2.blogspot.com twitter.com/vasudevram -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Using pipe_controller to swap pipe components at runtime
I added a couple of methods / functions to my pipe_controller Python module, the Python tool to experiment with pipelined functions within a program. With these additions, it is now possible to swap the components of a pipe_controller 'pipe' programmatically, at runtime (*), and then run the pipe again (all within the same program), with differing results (from before and after the swap). (*) Instead of having to edit the source code to change the order in which the functions in the pipe are called, that change of order can be done programmatically, via a swap_processors() method. Blog post about it: http://jugad2.blogspot.in/2012/10/swapping-pipe-components-at-runtime.html The post includes snippets of the added methods / functions, and a sample run of a test program that demonstrates the new component-swapping feature. The latest code with the above changes is on Bitbucket at: https://bitbucket.org/vasudevram/pipe_controller - Vasudev Ram www.dancingbison.com jugad2.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: fmap(), inverse of Python map() function
On Saturday, October 6, 2012 5:01:40 AM UTC+5:30, Devin Jeanpierre wrote: On Fri, Oct 5, 2012 at 7:24 PM, Ian Kelly wrote: I realize that. My point is that the function *feels* more like a variant of reduce than of map. If it's meant as a complaint, it's a poor one. It's not. Fair enough all around. Sorry for misunderstanding. -- Devin Thanks to all who replied. Always good to learn something new. - Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: fmap(), inverse of Python map() function
Thanks to all who replied. Always good to learn something new. P.S. A reader posted a good comment with Scala as well as Python code for a compose function (basically same functionality as fmap, or more - the compose once, run many times thing). It's the 4th comment on my blog post. - Vasudev -- http://mail.python.org/mailman/listinfo/python-list
fmap(), inverse of Python map() function
http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function.html - Vasudev Ram www.dancingbison.com jugad2.blogspot.com twitter.com/vasudevram -- http://mail.python.org/mailman/listinfo/python-list
ANN: v0.2 of PipeController released; now supports running pipes incrementally
I've released v0.2 of PipeController, my experimental tool to simulate pipes in Python. It can be downloaded here: http://dancingbison.com/pipe_controller-v0.2.zip Changes in v0.2: - module name changed to avoid clashes with pipes module in the standard Python library; the module is now called pipe_controller.py instead of pipes.py; - you can now pass input and output filename arguments on the command in your program that calls PipeController, instead of having to use I/O redirection; - you can now import class PipeController from the module, with: from pipe_controller import PipeController - you can now run a PipeController pipe incrementally, i.e., run the pipe in a loop, adding a pipe component (a Python function) in each iteration, and it can save the intermediate outputs resulting from each iteration, to separate output files; the program test_pipe_controller_03.py in the download package shows how to do this. This feature can be useful to debug your pipe's logic, and also to save the intermediate computation results in case they are of use in their own right. Blog post about using PipeController v0.2 to run a pipe incrementally: http://jugad2.blogspot.in/2012/09/using-pipecontroller-to-run-pipe.html - Vasudev Ram www.dancingbison.com jugad2.blogspot.com twitter.com/vasudevram -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Using PipeController (v0.2) to run a pipe incrementally
I've released v0.2 of PipeController, my experimental tool to simulate pipes in Python. It can be downloaded here: http://dancingbison.com/pipe_controller-v0.2.zip Changes in v0.2: - module name changed to avoid clashes with pipes module in the standard Python library; the module is now called pipe_controller.py instead of pipes.py; - you can now pass input and output filename arguments on the command in your program that calls PipeController, instead of having to use I/O redirection; - you can now import class PipeController from the module, with: from pipe_controller import PipeController - you can now run a PipeController pipe incrementally, i.e., run the pipe in a loop, adding a pipe component (a Python function) in each iteration, and it can save the intermediate outputs resulting from each iteration, to separate output files; the program test_pipe_controller_03.py in the download package shows how to do this. This feature can be useful to debug your pipe's logic, and also to save the intermediate computation results in case they are of use in their own right. Blog post about using PipeController v0.2 to run a pipe incrementally: http://jugad2.blogspot.in/2012/09/using-pipecontroller-to-run-pipe.html - Vasudev Ram www.dancingbison.com jugad2.blogspot.com twitter.com/vasudevram -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for an IPC solution
On Saturday, September 1, 2012 6:25:36 PM UTC+5:30, Wolfgang Keller wrote: There are just so many IPC modules out there. I'm looking for a solution for developing a new a multi-tier application. The core application will be running on a single computer, so the IPC should be using shared memory (or mmap) and have very short response times. Probably the fastest I/RPC implementation for Python should be OmniOrbpy: http://omniorb.sourceforge.net/ It's cross-platform, language-independent and standard-(Corba-) compliant. I have seen a stand alone cross platform IPC server before that could serve channels, and send/receive messages using these channels. But I don't remember its name and now I cannot find it. Can somebody please help? If it's just for messaging, Spread should be interesting: http://www.spread.org/ Also cross-platform language-independent. Sincerely, Wolfgang Though I'm not the OP, thanks for the info. Will put Spread on my stack to check out ... -- http://mail.python.org/mailman/listinfo/python-list
Re: PipeController v0.1 - experimental tool to simulate simple UNIX-style pipes in Python
On Saturday, September 1, 2012 9:02:33 PM UTC+5:30, Ramchandra Apte wrote: On Friday, 31 August 2012 03:27:54 UTC+5:30, vasudevram wrote: I wrote PipeController recently to experiment with doing UNIX-style pipes in Python. Doesn't the pipes module already do this? Yes. As Ian Kelly points out here: http://www.mail-archive.com/python-list@python.org/msg335943.html the pipes module of Python does deal with actual UNIX pipes. But I had mentioned this - Python's pipes module - in my first post, some months ago, about doing UNIX-pipes in Python ( on my blog, here: http://jugad2.blogspot.in/2011/09/some-ways-of-doing-unix-style-pipes-in.html ), and that first post was in turn linked to, in the current post under discussion ( i.e. this one: http://jugad2.blogspot.in/2012/08/pipecontroller-v01-released-simulating.html ). To Ian Kelly: No, that deals with actual Unix pipes. This appears to be about pipelined processing within a single program and not IPC; the description Unix-like is a bit misleading, IMO. I guess it can be interpreted as a bit misleading, but it was not intentionally so. The way I meant it was that PipeController tries to achieve _roughly_ similar functionality, of composing a program out of components, as UNIX pipes do. (That too, only a small subset, as I mention in my blog post). In the case of UNIX the components are commands, in the case of my Python approach the components are functions. Also, I used the term UNIX-style pipes, not UNIX pipes, to stress that it was the overall concept of a pipeline that was being simulated, not the exact design / implementation details, and you can also notice that my first post has links to many different third-party ways of simulating UNIX-pipes in Python, some of which are not like actual UNIX pipes at all, in their implementation. But I agree that your description of PipeController as pipelined processing within a single program is more accurate. I could have used a better choice of words but there was no intention to mislead. - Vasudev Ram www.dancingbison.com jugad2.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: PipeController v0.1 - experimental tool to simulate simple UNIX-style pipes in Python
On Monday, September 3, 2012 1:05:03 AM UTC+5:30, vasudevram wrote: To Ian Kelly: No, that deals with actual Unix pipes. This appears to be about pipelined processing within a single program and not IPC; the description Unix-like is a bit misleading, IMO. I guess it can be interpreted as a bit misleading, but it was not intentionally so. The way I meant it was that PipeController tries to achieve _roughly_ similar functionality, of composing a program out of components, as UNIX pipes do. To Ian again: Also, I used the word synchronous somewhat deliberately (see in my blog post: PipeController is a tool to experiment with a simple, sequential, synchronous simulation of UNIX-style pipes in Python.). I used the word synchronous to indicate that my PipeController implementation runs the functions one after another (for each item in the input), in contrast to actual Unix pipes, where the different commands in a pipeline can, and IIRC, do, run in parallel / asynchronously, with their IPC being coordinated / managed by the kernel and shell. -- http://mail.python.org/mailman/listinfo/python-list
ANN: PipeController v0.1 released: Python tool to experiment with simulating UNIX-style pipes
PipeController is a tool that I wrote to experiment with simulating simple, sequential, synchronous UNIX-style pipes in Python. It is the first release - v0.1. Blog post about PipeController: http://jugad2.blogspot.in/2012/08/pipecontroller-v01-released-simulating.html The blog post gives some information about the design of PipeController and an example of how to use it. Download PipeController: http://dancingbison.com/unix-pipes.zip I have not put any license information in the PipeController source code, but will be doing that, and it will be released under the New BSD license. - Vasudev Ram www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
PipeController v0.1 - experimental tool to simulate simple UNIX-style pipes in Python
I wrote PipeController recently to experiment with doing UNIX-style pipes in Python. Blog post about it: http://jugad2.blogspot.in/2012/08/pipecontroller-v01-released-simulating.html The blog post has a link to the downloadable PipeController source code. It will be released under the New BSD License, which means you can use it for any purpose, commercial or otherwise, subject to the terms of the license. - Vasudev Ram www.dancingbison.com jugad2.blogspot.com twitter.com/vasudevram -- http://mail.python.org/mailman/listinfo/python-list
PySiteCreator v0.1 released
Hi group, I've released a tool for creating HTML pages or Web sites by writing them in Python - PySiteCreator v0.1. Description of PySiteCreator: PySiteCreator is a tool that allows the user to create Web (HTML) sites by writing them entirely in Python. A user creates one or more Python source files in each of which they import a PySiteCreator helper module, and then call helper functions defined in that module, in order to emit HTML elements and associated content. They can then run the PySiteCreator program to process all those Python files; processing each Python file will result in the creation of a corresponding HTML file with the desired HTML elements and content. Some more details and the download link are available here on my blog: http://jugad2.blogspot.com/2009/11/early-release-of-pysitecreator-v01.html I appreciate any feedback on PySiteCreator. Thanks, Vasudev Ram Biz: www.dancingbison.com Products: www.dancingbison.com/products.html Blog on software innovation: jugad2.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
PDFXMLRPC v1.0: Client and server for PDF creation from text
I'm happy to announce the release of v1.0 of PDFXMLRPC, a client- server application that lets users create PDF content from text, over the Internet or their intranet, using Reportlab, xtopdf, XML-RPC and Python. Usage example for PDFXMLRPC: You can run the server on one computer which is connected to the Internet. You can run the client on another computer which is connected to the Internet. When you run the client, it sends text content to the server. The server then converts this text to PDF, and sends that PDF content back to the client over the Internet. The client then writes that PDF content to a local PDF file, which the user can then open / print / etc. (But also see the part about callability (i.e., programmability) of both the client and server below.) The announcement of PDFXMLRPC is here on my blog: http://jugad2.blogspot.com/2009/10/client-server-pdf-creation-with-xtopdf.html That blog post has a link to a zip file that you can download, which contains the PDFXMLRPC package. The zip file contains the following files: - PDFXMLRPCServer.py - the server - PDFXMLRPCClient.py - the client - README.txt - documentation of the prerequisites needed (*), the URLs to get them from, the steps to install PDFXMLRPC, and steps to run the server and the client. - License.txt - the license file (PDFXMLRPC is released under the BSD License) (*) The prerequisites are: - xtopdf v1.0, Reportlab v1.x and Python 2.x or higher for the server - Python 2.x or higher for the client (XML-RPC is required for both the client and the server, but since it is included in the standard Python library, I don't treat it as a separate prerequisite). Although both the server and the client programs contain main() functions, and therefore both can be run as standalone programs, they are also both callable. There is one top-level class in each of the server and the client - PDFXMLRPCServer and PDFXMLRPCClient respectively. The main() functions in the server and client, act as examples of how to call those classes. Since the classes are callable, you can incorporate the functionality of the server and the client, into your own larger programs, to get the functionality of client/server PDF creation over the Net, in your own applications. I welcome any feedback on this software. You can contact me via my contact page: http://www.dancingbison.com/contact.html . Finally, thanks a lot to the Reportlab team and all the users who've helped improve Reportlab, for their work. And thanks a lot to the Python team and users as well. Thanks, Vasudev Ram --- Dancing Bison Enterprises Biz: www.dancingbison.com Google Profile: http://is.gd/tWe3 Blog: jugad2.blogspot.com xtopdf: fast and easy PDF creation: www.dancingbison.com/products.html Twitter: @vasudevram -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Client-server PDF creation with xtopdf, XML-RPC, ReportLab and Python
Hi group, I've released a software package named PDFXMLRPC. It consists of a server and a client. Using them, you can do client-server PDF creation from text, over the Internet or your intranet. It runs over XML-RPC and uses HTTP as the transport. It can work with any available port, including the standard HTTP port 80, or any other allowed and available one. The server is written in Python and uses xtopdf (also written by me), XML-RPC (from the standard Python library), ReportLab (the open source version) and Python. The client is written in Python and uses XML-RPC. PDFXMLRPC can be downloaded from here: http://www.dancingbison.com/PDFXMLRPC.zip That zip file contains the server, the client, a README.txt file and the license. (NOTE: The README.txt file contains a line saying to download the PDFXMLRPC package from http://www.dancingbison.com/PDFXMLRPCClientAndServer.zip - that line is a mistake, left over from an earlier unreleased version. If you have the README.txt file, it means that you have already downloaded and extracted the correct file - which is PDFXMLRPC.zip, so just ignore that wrong line. I'll update the README.txt file to correct that error soon.) The README.txt file gives details on how to install the software needed, and how to run it. PDFXMLRPC is released under the BSD license. I welcome any feedback on it. I would like to thank the Python and ReportLab guys for creating great software. Thanks, Vasudev Ram Dancing Bison Enterprises http://www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Client-server PDF creation with xtopdf, XML-RPC, ReportLab and Python
On Oct 4, 7:38 pm, vasudevram vasudev...@gmail.com wrote: Hi group, snip/ I'll update the README.txt file to correct that error soon.) Done. Corrected README.txt uploaded (as part of updated zip file). I forgot to mention, in the original post above, that both the client and the server programs have top-level classes that encapsulate all of their functionality, and those classes are callable / programmable. Which means that you can call those classes (or rather their methods) in your own larger applications, to get that functionality of client- server creation of PDF from text, in your apps. Take a look at the main () functions of the client and the server (in files PDFXMLRPCClient.py and PDFXMLRPCServer.py) - the code is simple and self-explanatory, since those two main functions themselves are instances of code that calls the methods of the classes mentioned above. - Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: XML(JSON?)-over-HTTP: How to define API?
On Jul 3, 1:11 pm, Diez B. Roggisch de...@nospam.web.de wrote: Allen Fowler schrieb: I have an (in-development) python system that needs to shuttle events / requests around over the network to other parts of itself. It will also need to cooperate with a .net application running on yet a different machine. So, naturally I figured some sort of HTTP event / RPC type of would be a good idea? Are there any modules I should know about, or guidelines I could read, that could aid me in the design of the API? To clarify: Each message would be 1KB of data total, and consist of some structured object containing strings, numbers, dates, etc. For instance there would be an add user request that would contain one or more User objects each having a number of properties like: - Full Name - Username - Password - Email addresses (a variable length array) - Street Address line1 - Street Address line1 - Street Address line1 - City - State - Zip - Sign Up Date and so on. Since I need to work with other platforms, pickle is out... what are the alternatives? XML? JSON? How should I formally define each of the valid messages and objects? Thank you, Use XMLRPC. Implementations for both languages are available. There is no need for formal spec - which is a good thing. You just call the server, and it works. Diez I second the suggestion of Diez to use XML-RPC. Very simple to learn and use. Supports structs (as method arguments and method return values) which can consist of other data types bundled together, also supports arrays. Just check whether .NET supports XML-RPC. -- http://mail.python.org/mailman/listinfo/python-list
Re: file transfer in python
On Jun 26, 5:07 pm, Francesco Bochicchio bieff...@gmail.com wrote: On 26 Giu, 13:38, jayesh bhardwaj bhardwajjay...@gmail.com wrote: i am trying to find something useful in python to transfer html files from one terminal to other. Can this be done with some module or shall i start coding my own module using low level socket interface. If u know about some books on this topic or any online help then plz help. In the standard library there is ftplib, which allows your program to act as a FTP client. Of course the receiver end should have an FTP server installing and running. I don't tink it can handle SFTP protocol, so if you are concerned with security you should opt for someting else, or protect your connection somehow (e.g. SSH tunneling). Or, if you have ssh (client and server) installed, you could simply spawn a subprocess ( see the subprocess module for that ) which execute one or more 'scp' commands. Ciao FB There are many ways to do it; each may have it's own pros and cons. The low level sockets approach is feasible, as you said, and not too difficult, either. Read from each file and write the data to a socket from one end; read the data from the other end, and write it to a file. For the FTP approach, as Francesco said, the Python standard library has ftplib, which can help you with the client side, i.e. the sending side. If you don't have an FTP server on the receiving side, you could try using pyftpdlib to implement your own FTP server in Python: http://code.google.com/p/pyftpdlib/ Quoting from that URL: Python FTP server library provides a high-level portable interface to easily write asynchronous FTP servers with Python. pyftpdlib is currently the most complete RFC-959 FTP server implementation available for Python programming language. It is used in projects like Google Chromium and Bazaar and included in Linux Fedora and FreeBSD package repositories. Of course all that could be too much overhead; also, you would need permission to install your FTP daemon program written using pyftpdlib, on the receiving computer. As Francesco said, you could use the subprocess module and spawn a process that runs instances of scp. Another fairly easy way could be to write an XML-RPC client and server. The client, on the sending side, can send the data of each file to the server via an XML-RPC method call (in chunks, if needed, if the file is large); the server, on the receiving side, can read that data, and write it to a file on the file system. The client could send the file name of each file first, via a separate method call, before the data of each file, so the server would know under what name to save the file on its file system. By using the Binary data type supported by XML-RPC, you could send any type of file, whether text or binary, and irrespective of the operating system of the sender or receiver, whether Windows or UNIX. I've done this in some code of mine, so I know it works. You might have to take care about newline conversions (LF to CR + LF or vice versa), though, if one side is UNIX and the other is Windows, and do that conversion only for files that are text files. (For binary files, you actually have to make sure that you DO NOT do that conversion, or you will corrupt the data.) And do a similar conversion if one side is Mac and the other is Windows or Linux. On Mac, line endings are marked with a CR. LF = Line Feed (ASCII 10) CR = Carriage Return (ASCII 13) The subprocess + scp method may be slower than the XML-RPC method, since it will have to spawn a new scp process for each file sent, unless you use wildcards and transfer all or many files in one call. One the other hand, the XML-RPC method may be slower, since it transfers the data over HTTP (which rides on TCP which rides on IP), whereas scp probably uses a lower level protocol such as TCP packets directly, or something similar to what FTP uses - those protocols may have less overhead per unit of data sent. Which approach is best depends on your needs, whether it is a one-off job, or whether you need to repeat the job regularly, etc., how much time you have to write the code, etc. HTH, Vasudev --- Vasudev Ram Biz: www.dancingbison.com xtopdf: fast and easy PDF creation from other file formats: www.dancingbison.com/products.html Blog (on software innovation): jugad2.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Books for programmers
On Jun 5, 3:09 am, [EMAIL PROTECTED] (Michael H. Goldwasser) wrote: Dick Moores [EMAIL PROTECTED] writes: Do not neglect the 2008 book, Object-Oriented Programming in Python, by Goldwasser and Letscher. http://www.prenhall.com/goldwasser/ http://www.bestbookdeal.com/book/compare/0136150314/ Dick Moores I'll note that our book is designed as a CS1 text, and thus intended primarly for beginners. So its probably not a match for the original poster who wants a more advanced Python book. That said, I think its a great book for those with less experience. +--- | Michael Goldwasser | Associate Professor | Dept. Mathematics and Computer Science | Saint Louis University | 220 North Grand Blvd. | St. Louis, MO 63103-2007 Yes, Python in a Nutshell (also by Alex Martelli) and Programming Python (by Mark Lutz) are also quite good, as others have said above. - Vasudev Ram http://www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Books for programmers
On Jun 3, 6:42 pm, Mike Driscoll [EMAIL PROTECTED] wrote: On Jun 3, 5:45 am, V [EMAIL PROTECTED] wrote: Hi Matt, and thank you very much for your answer. Hm, depends of course, how good your programming skills are in the languages you knwo already, but I rely on the book Beginning Python - From Novice to Professional by Magnus Lie Hetland, published by Apress. I think that I'm interested in a more advance book, ideally one that talk of the Python gotchas, traps, pitfall, idioms, performance, stile, and so on. I really like the style used from Scott Meyers in his Effective C++ series, or from Herb Sutter's Exceptional C++, but after a quick look I did not find anything similar for Python... Best regards. I agree with Rick. Core Python Programming by Chun is pretty good. However, Lutz's Programming Python is also very good and has a few big example programs to walk through. You might also find the Python Cookbooks handy. There's also Python Power! by Matt Telles, which is more of a reference book although not quite as dry as Python Essential Reference was. Mike The Python Cookbook - printed version - I've read it - is a very good book on the lines of what you're looking for, IMO. If you go by its title, it might not sound like a book in the Effective Series (I've read Effective C++ too and agree that its excellent), but it actually is something quite like Effective C++, since its contributors include many very good Python developers, including Alex Martelli, David Ascher, Tim Peters, Raymond Hettinger, to name just a few. Though the explicit goal of the book is not to be a book about idiomatic Python, the point is that it ends up being a lot like that, since most of the contributors write idiomatic Python. For example, one idiom that's mentioned a lot in the book, is about one of Python's greatest strengths - smooth signature-based polymorphism - with good examples to substantiate it. Though not a book, you may also find the Python articles by David Mertz on IBM developerWorks very useful. Go to http://www.ibm.com/developerworks and search for either Charming Python - the name of his Python column there - or his name - to get the articles. HTH Vasudev --- Vasudev Ram Biz site: http://www.dancingbison.com Quick PDF creation toolkit (in Python, open source): http://www.dancingbison.com/products.html -- http://mail.python.org/mailman/listinfo/python-list
Re: how to generate html table from table data?
[EMAIL PROTECTED] a écrit : Hi group, I would like to convert the output of the SQL query, or more generally I would like to convert any table data to the html table. I would like to set some rules to format cells, columns or rows (font, colour etc.) of the html table, according to the values in the specific cells. Why not try writing your own code for this first? If nothing else, it'll help you learn more, and may also help you understand better, the other options. Vasudev Ram --- Dancing Bison Enterprises Software consulting and training Biz site: http://www.dancingbison.com Blog (on software innovation): http://jugad.livejournal.com Quick and easy PDF creation toolkit: http://www.dancingbison.com/products.html -- http://mail.python.org/mailman/listinfo/python-list
Re: View XMLRPC Requests/Responses?
On Oct 15, 8:10 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: xkenneth wrote: Hi, I'm working on developing an XML-RPC interface from LabVIEW to python and I would really like to see how python is forming it's XML- RPC requests/responses. Is there any way I can force these to a log or print them to the screen? Thanks. I've utilized the apache axis tcpmon for that, as proxy. See http://docs.pushtotest.com/axisdocs/user-guide.html#tcpmon Diez I haven't used apache axis tcpmon - so don't know how easy or difficult it is to use that approach - but if its non-trivial or awkward, there's another easy way - since the xmlrpc lib source is available - and it is, its part of the Python Standard library - just root around in the source and modify it to log to a file or to the screen. Will be pretty straightforward to do it. Its a hack, though, I know - because your changes would need to be carried around everywhere you want to use them (but then so does your code), and also because they would get clobbered when you upgraded to the next Python release. So a better way might be to inherit from an appropriate class of xmlrpclib client or server, use that class in your code instead, and modify the inherited class to log as needed, by getting hold of some output stream of the parent class - if it is exposed. a href=http://www.dancingbison.com;Vasudev Ram/a -- http://mail.python.org/mailman/listinfo/python-list
Re: View XMLRPC Requests/Responses?
On Oct 15, 8:49 pm, vasudevram [EMAIL PROTECTED] wrote: On Oct 15, 8:10 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: xkenneth wrote: Hi, I'm working on developing an XML-RPC interface from LabVIEW to python and I would really like to see how python is forming it's XML- RPC requests/responses. Is there any way I can force these to a log or print them to the screen? Thanks. I've utilized the apache axis tcpmon for that, as proxy. See http://docs.pushtotest.com/axisdocs/user-guide.html#tcpmon Diez I haven't used apache axis tcpmon - so don't know how easy or difficult it is to use that approach - but if its non-trivial or awkward, there's another easy way - since the xmlrpc lib source is available - and it is, its part of the Python Standard library - just root around in the source and modify it to log to a file or to the screen. Will be pretty straightforward to do it. Its a hack, though, I know - because your changes would need to be carried around everywhere you want to use them (but then so does your code), and also because they would get clobbered when you upgraded to the next Python release. So a better way might be to inherit from an appropriate class of xmlrpclib client or server, use that class in your code instead, and modify the inherited class to log as needed, by getting hold of some output stream of the parent class - if it is exposed. a href=http://www.dancingbison.com;Vasudev Ram/a I sort of had a need for this myself recently when writing some Python XML-RPC code, but didn't do it because I could manage to debug my code without it - but I remember noticing that my XML-RPC server was logging the requests to stdout, by default (without any code by me to do it). So I think the approach I mention above should work - just look around in the server source code for where it does that, and modify it as per need. - Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: Joining Big Files
On Aug 27, 12:43 am, mcl [EMAIL PROTECTED] wrote: All, Thank you very much. As my background is much smaller memory machines than today's giants - 64k being abigmachine and 640k being gigantic. I get very worried about crashing machines when copying or editingbigfiles, especially in a multi-user environment. Mr Knuth - that brings back memories. I rememeber implementing some of his sort routines on a mainframe with 24 tape units and an 8k drum and almost eliminating one shift per day of computer operator time. Thanks again Richard I can imagine ... though I don't go back that far. Cool ... Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: Joining Big Files
On Aug 26, 6:48 am, Paul McGuire [EMAIL PROTECTED] wrote: On Aug 25, 8:15 pm, Paul McGuire [EMAIL PROTECTED] wrote: On Aug 25, 4:57 am, mosscliffe [EMAIL PROTECTED] wrote: I have 4 text files each approx 50mb. yawn 50mb? Really? Did you actually try this and find out it was a problem? Try this: import time start = time.clock() outname = temp.dat outfile = file(outname,w) for inname in ['file1.dat', 'file2.dat', 'file3.dat', 'file4.dat']: infile = file(inname) outfile.write( infile.read() ) infile.close() outfile.close() end = time.clock() print end-start,seconds For 4 30Mb files, this takes just over 1.3 seconds on my system. (You may need to open files in binary mode, depending on the contents, but I was in a hurry.) -- Paul My bad, my test file was not a text file, but a binary file. Retesting with a 50Mb text file took 24.6 seconds on my machine. Still in your working range? If not, then you will need to pursue more exotic approaches. But 25 seconds on an infrequent basis does not sound too bad, especially since I don't think you will really get any substantial boost from them (to benchmark this, I timed a raw copy command at the OS level of the resulting 200Mb file, and this took about 20 seconds). Keep it simple. -- Paul There are (at least) another couple of approaches possible, each with some possible tradeoffs or requirements: Approach 1. (Least amount of code to write - not that the others are large :) Just use os.system() and the UNIX cat command - the requirement here is that: a) your web site is hosted on *nix (ok, you can do it if on Windows too - use copy instead of cat, you might have to add a cmd /c prefix in front of the copy command, and you have to use the right copy command syntax for concatenating multiple input files into one output file). b) your hosting plan allows you to execute OS level commands like cat, and cat is in your OS PATH (not PYTHONPATH). (Similar comments apply for Windows hosts). import os os.system(cat file1.txt file2.txt file3.txt file4.txt file_out.txt) cat will take care of buffering, etc. transparently to you. Approach 2: Read (in a loop, as you originally thought of doing) each line of each of the 4 input files and write it to the output file: (Reusing Paul McGuire's code above:) outname = temp.dat outfile = file(outname,w) for inname in ['file1.dat', 'file2.dat', 'file3.dat', 'file4.dat']: infile = file(inname) for lin in infile: outfile.write(lin) infile.close() outfile.close() end = time.clock() print end-start,seconds # You may need to check that newlines are not removed in the above code, in the output file. Can't remember right now. If they are, just add one back with: outfile.write(lin + \n) instead of outfile.write(lin) . ( Code not tested, test it locally first, though looks ok to me. ) The reason why this _may_ not be much slower than manually coded buffering approaches, is that: a) Python's standard library is written in C (which is fast), including use of stdio (the C Standard IO library, which already does intelligent buffering) b) OS's do I/O buffering anyway, so do hard disk controllers c) from some recent Python version, I think it was 2.2, that idiom for lin in infile has been (based on somethng I read in the Python Cookbook) stated to be pretty efficient anyway (and yet (slightly) more readable that earlier followed approaches of reading a text file). Given all the above facts, it probably isn't worth your while to try and optimize the code unless and until you find (by measurements) that it's too slow - which is a good practice anyway: http://en.wikipedia.org/wiki/Optimization_(computer_science) Excerpt from the above page (its long but worth reading, IMO): Donald Knuth said, paraphrasing Hoare[1], We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. (Knuth, Donald. Structured Programming with go to Statements, ACM Journal Computing Surveys, Vol 6, No. 4, Dec. 1974. p.268.) Charles Cook commented, I agree with this. It's usually not worth spending a lot of time micro-optimizing code before it's obvious where the performance bottlenecks are. But, conversely, when designing software at a system level, performance issues should always be considered from the beginning. A good software developer will do this automatically, having developed a feel for where performance issues will cause problems. An inexperienced developer will not bother, misguidedly believing that a bit of fine tuning at a later stage will fix any problems. [2] HTH Vasudev - Vasudev Ram http://www.dancingbison.com http://jugad.livejournal.com http://sourceforge.net/projects/xtopdf - -- http://mail.python.org/mailman/listinfo/python-list
Re: How would I compile a Python file to a exe
On Aug 24, 2:11 am, Charlie [EMAIL PROTECTED] wrote: Quoting Lamonte Harris [EMAIL PROTECTED]: Been a while and I'm wondering how I would go about doing it. py2exe seems to be a fairly good option for this, at least in the world of Windows. Yes, py2exe looks good. I've tried it out. Make sure to test for the cases you'll need, though. - Vasudev - Vasudev Ram http://www.dancingbison.com http://jugad.livejournal.com http://sourceforge.net/projects/xtopdf - -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Book Recommendations
On Aug 15, 8:34 pm, [EMAIL PROTECTED] wrote: On Aug 15, 10:30 am, Azazello [EMAIL PROTECTED] wrote: On Aug 15, 7:47 am, Shawn Milochik [EMAIL PROTECTED] wrote: If I could have only one book, I would buy Core Python, Second Edition, by Wesley Chun. For the record, I own: Core Python, Second Edition (great) wxPython in Action (haven't used yet) Beginning Python (barely used) Python in a Nutshell (use as a reference, although interactive python dir() is more useful) Dive into Python (great book) Python Cookbook (great book) Python Pocket Reference (not very useful) Python Phrasebook (I love the Phrasebook series, but this isn't a necessary book) I would like to add: Foundations of Python Network Programming I also use the Python Essential Reference. (although all of the information is probably online it's nice to have a solid paper reference) Depending on what you're doing, a book can actually be faster than Google! Of course, a lot of these books don't cover any 3rd party modules, so Google is still very handy. Mike I second some of those recommendations - for the books I own / have read: Python Cookbook - excellent Python in a Nutshell - excellent Though interactive dir() is good, it doesn't give you a lot of things that Python in a Nutshell and the official Python docs do - rules of the language, info on new-style classes, etc. Also, Google for Guide to Python Introspection - a good online article that shows a lot more about that topic, over and above use of dir(). Also: Programming Python - excellent. Didn't know about the Python Network programming book - thanks, will check it out. Vasudev Ram http://www.dancingbison.com http://jugad.livejournal.com http://sourceforge.net/projects/xtopdf -- http://mail.python.org/mailman/listinfo/python-list
Re: Python MAPI
On Jul 23, 6:07 pm, [EMAIL PROTECTED] wrote: Well, I ran Process Monitor with some filters enabled to only watch Thunderbird and MS Word. Unfortunately, that didn't give me any of the registry edits, so I disabled my filters and ran it without. Now I have a log file with 28,000 entries. It's amazing to see all the stuff that happens in just a few moments, but how am I supposed to parse this mess? Explorer.exe and outlook express do thousands of the registry calls and the paths they manipulate vary wildly. Oh well, I'll be off the clock in about 15 minutes so it can wait until Monday. Thanks for your help. I'll post if I figure out anything...hopefully you'll do the same. --- Sorry for not replying earlier ... I searched this list for the topic (Python MAPI) a few times but couldn't find it - not sure why - maybe Google Groups's indexing gets messed up sometimes ... Yes, so many entries would be a problem to parse manually ... That's why I suggested using a grep for Windows - or, preferably, an egrep - which is a more powerful version of grep; e.g. basic grep only allows you to use one regexp at a time - while egrep allows you to use extended regular expressions, such as pattern1|pattern2, also patt(e|u)rn(1|2) which looks in parallel for pattern1, patturn1, pattern2 and patturn2 - I used a made-up example where the spelling of pattern could be wrong, but it works for any other cases of alternative patterns and subpatterns as well. Not sure if there is any egrep for Windows - try Googling. If not, and the problem is important enough, you might want to install Cygwin (its a big download, so first check if it _does_ have egrep in it). Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: Web based Reporting tool for Python
Madhu Alagu wrote: Hi I am looking template based report tools for python.It has the ability to deliver rich content onto the screen, to the printer or into PDF, HTML, XLS, CSV and XML files. Thanks, Madhu Alagu I don't know if there's a _single_ tool that can do all you want (there may be, just that I don't know of one), but there are many tools that can each do some part of it. Here are some, off the top of my head - Googling should get you more for each category. For templating - Cheetah, others. For PDF - ReportLab. PDFLib has Python bindings too, but its paid for commercial use, IIRC. For HTML - Python standard library itself has some stuff, there must be others. For XLS/CSV - CSV output is easy enough to roll your own. Then import the CSV into Excel. If this isn't good enough (and it may not be, depending on your needs, as it requires manual (ok, it is possible to sort of automate that too using COM) import of the CSV into Excel. Google for a Python lib for direct XLS generation. For XML - like CSV, for simple XML, can be written by you (its just outputting XML tags, attributes and content from your code). There might be issues with encodings, etc. - in which case use a lib. Python has many XML libs - do some research. David Mertz and Uche Ogbuji, among others, have written a lot of articles on Python and XML, many of them are about reviewing and comparing various libs like ElementTree, Gnosis XML utilities and others. Many of those and other articles are on IBM developerWorks and XML.com. Vasudev Ram http://www.dancingbison.com http://jugad.livejournal.com http://sourceforge.net/projects/xtopdf -- http://mail.python.org/mailman/listinfo/python-list
Re: the one python book
On Aug 4, 7:23 am, dhr [EMAIL PROTECTED] wrote: newbie question: Is there a 'KR type of Python book? The book that you'd better have on your shelf if you are going into Python? Python in a Nutshell, the Python Cookbook and Programming Python are all very good, IMO. Programming Python comes with a CD of all the source code in the book (at least the 2nd edition did, as well as Python language - this can save you some time keying in the examples. Of course, many of the O'Reilly books (and all 3 of these are from O'Reilly) have links to downloadable source code from them. Just Google for the name of the book, then in the results, hit the appropriate link to the O'Reilly site for the book, and look down the page for the link to the examples' source. Or (for Programming Python): http://www.oreilly.com/catalog/python2/ http://www.oreilly.com/catalog/python3/ Vasudev 1 person in 100 understand binary. The other 11 don't. Vasudev Ram Biz site: http://www.dancingbison.com Blog: http://jugad.livejournal.com PDF creation/construction toolkit: http://sourceforge.net/projects/xtopdf -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross platform Python app deployment
On Jul 30, 4:42 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: Will McGugan wrote: Hi, Is there some reference regarding how to package a Python application for the various platforms? I'm familiar with Windows deployment - I use Py2Exe InnoSetup - but I would like more information on deploying on Mac and Linux. On mac, there is py2app that allows to create application-bundles you can then install. Either including a python interpreter, or using an installed one. Diez You could also try PyInstaller - see http://pyinstaller.hpcf.upr.edu/cgi-bin/trac.cgi The site says it works on Windows, Linux and IRIX, so no Mac ... Vasudev Ram Biz site: http://www.dancingbison.com Blog (on software innovation): http://jugad.livejournal.com PDF creation/construction toolkit: http://sourceforge.net/projects/xtopdf -- http://mail.python.org/mailman/listinfo/python-list
Re: wxGlade: Who knows how to drive this application?
Steve Holden wrote: I've been trying to use wxGlade recently and I am finding it something of a challenge. Is there any user who finds the user interface satisfactory and the operation of the program predictable? Good (for me) that you posted this question, as I got to know about wxGlade (also the others mentioned like Dabo, which I'm gonna check out) - I might not have heard of it otherwise :-) Tried it out (wxGlade) yesterday after reading your post. Results: I could get it to run, no problem. Tried Alberto's tutorial that builds the GUI for a tabbed notebook with a menu. Worked mostly fine. One problem I had was that it is an SDI app (Single Document Interface - Windows term) and, maybe due to that, the (preview of the) frame you're designing sometimes gets hidden under the other windows (the main wxGlade window, the Properties window, the GUI widgets tree, etc.) so I sometimes had to fiddle around with the mouse to uncover it. Or it could have been due to my monitor's resolution. I have wxPython 2.6 installed on my (Windows) machine, so had to change the default code generation from 2.8 to 2.6. After that I could run the generated code. I used the option to generate each class in a separate file. The generated code was quite readable - I could understand it easily. Having the tree of widgets shown in one window is a plus point - it helps you to visualize the structure / nesting of the widgets in your app. Another slight problem was that, though I had sized the main frame to occupy the whole screen (while in design mode), when I ran the generated code, the main frame was partially outside the screen. Possibly this again was due to my monitor - getting GUI apps to display correctly on differing target monitors is challenging ... That was all I've tried so far, but I think even that much is of some help, at least - it should save some time with designing one's GUI. I plan to try it out some more. My 2 cents ... Vasudev Ram http://www.dancingbison.com http://sourceforge.net/projects/xtopdf http://jugad.livejournal.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Generating PDF reports
On 2007-07-26, marcpp [EMAIL PROTECTED] wrote: Hi i'm introducing to do reports from python, any recomendation? Yes, ReportLab is quite a good PDF library for Python. I used it as the main underlying component in my xtopdf toolkit - see: http://www.dancingbison.com/products.html For most general uses, ReportLab is good choice. You might want to check out xtopdf if your needs are somewhat simple, mainly needing to convert text (from any source - plain text files, CSV, DBF, TDV, XLS (limited support), or other sources) to PDF - as it provides a slightly easier to use API for people who are not familiar with ReportLab. This article should help you use xtopdf for the above-mentioned purposes: http://www.packtpub.com/article/Using_xtopdf xtopdf doesn't support images as of now, nor any sophisticated formatting - you'll have to use ReportLab if you need that. Both ReportLab (the open source version) and xtopdf are released under the BSD license - so you can use them for any purpose you want. Good luck! Vasudev Ram http://www.dancingbison.com http://jugad.livejournal.com http://sourceforge.net/projects/xtopdf -- http://mail.python.org/mailman/listinfo/python-list
Re: Technology solutions for Ruby?
Bruno Desthuilliers wrote: s/some/great/g Both Ruby and Python are known for this. Thanks for the info. (I don't know much about metaprogramming etc. in either languages - just started exploring those topics recently.) I'd say that - wrt/ advanced programming tricks - *most* of what you can do with one can be done with the other - but usually in a *very* different way. While Ruby and Python have similar features and may look very similar at first sight, their respective object models are totally different. Can you briefly explain what you mean by their respective object models are totally different? Do you refer to how the object- orientation (classes, objects, etc.) is implemented in the two languages? Thanks Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: Python MAPI
On Jul 20, 10:57 pm, [EMAIL PROTECTED] wrote: Hi, I've been googling all over and can't find any good answers about this problem. I would like to create some kind of MAPI interface with Python such that when I open Microsoft Word (or another Office program) and click File, Send To, Mail Recipient it opens a program I wrote in Python and uses it to send the email rather than Outlook. The closest I've come is finding the registry key HKLM\Software\Clients \Mail which seems to control the default email client. I did figure out how to redirect mailto directives on websites to my program successfully, but this is a whole 'nother ballgame. Any suggestions are welcome. I am considering writing some VBA hooks in Office Apps in question, but would prefer to avoid that. Thanks! Mike P.S. Currently using Python 2.4, wxPython 2.8.3 (for GUI) on Windows XP Pro. Hi, 1: I don't know much about Windows APIs, but am currently reading the Windows Internals book. Got this idea from it: Go to http://www.microsoft.com/technet/sysinternals/default.mspx and check out the SysInternals utilities there. The book says that you can use some of them to spy on what an app is doing - what registry keys it is reading/writing, lots of other OS-level calls it makes as it runs. Digging around and using some of these utilities to check out what an Office app does when you use it to send mail, might help you figure out a way to do what you want. 2. Try looking for registry entries specific to Office Apps, and look under those subtrees for likely email-related entries to modify (if you haven't tried that already). I guess you already know that fiddling with the registry can be risky and can crash your system, so take backups, etc. Using COM via Python may also help - again, some digging required. You probably already have the PyWin32 Python extensions for Windows COM (earlier called win32all - see http://wiki.python.org/moin/Win32All) - if not, its available here: http://www.python.org/download/releases/2.4.4/ (scroll down the page for the link) Vasudev Ram www.dancingbison.com jugad.livejournal.com sourceforge.net/projects/xtopdf -- http://mail.python.org/mailman/listinfo/python-list
Re: Python MAPI
On Jul 21, 12:28 am, [EMAIL PROTECTED] wrote: On Jul 20, 1:48 pm, vasudevram [EMAIL PROTECTED] wrote: On Jul 20, 10:57 pm, [EMAIL PROTECTED] wrote: Hi, I've been googling all over and can't find any good answers about this problem. I would like to create some kind of MAPI interface with Python such that when I open Microsoft Word (or another Office program) and click File, Send To, Mail Recipient it opens a program I wrote in Python and uses it to send the email rather than Outlook. The closest I've come is finding the registry key HKLM\Software\Clients \Mail which seems to control the default email client. I did figure out how to redirect mailto directives on websites to my program successfully, but this is a whole 'nother ballgame. Any suggestions are welcome. I am considering writing some VBA hooks in Office Apps in question, but would prefer to avoid that. Thanks! Mike P.S. Currently using Python 2.4, wxPython 2.8.3 (for GUI) on Windows XP Pro. Hi, 1: I don't know much about Windows APIs, but am currently reading the Windows Internals book. Got this idea from it: Go tohttp://www.microsoft.com/technet/sysinternals/default.mspx and check out the SysInternals utilities there. The book says that you can use some of them to spy on what an app is doing - what registry keys it is reading/writing, lots of other OS-level calls it makes as it runs. Digging around and using some of these utilities to check out what an Office app does when you use it to send mail, might help you figure out a way to do what you want. 2. Try looking for registry entries specific to Office Apps, and look under those subtrees for likely email-related entries to modify (if you haven't tried that already). I guess you already know that fiddling with the registry can be risky and can crash your system, so take backups, etc. Using COM via Python may also help - again, some digging required. You probably already have the PyWin32 Python extensions for Windows COM (earlier called win32all - seehttp://wiki.python.org/moin/Win32All) - if not, its available here: http://www.python.org/download/releases/2.4.4/ (scroll down the page for the link) Vasudev Ramwww.dancingbison.com jugad.livejournal.com sourceforge.net/projects/xtopdf Thanks for the ideas...I am already monitoring the registry to see what happens when I switch between two email clients. In this case, I am switching between Outlook 2003 and Thunderbird 2. The pertinent registry files are as follows: # changes which email client to use [HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail] # obviously changes the .eml file association [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.eml] # haven't the fogiest idea what this does, if anything [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{29F458BE-8866-11D5- A3DD-00B0D0F3BAA7}] # change mailto functionality [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\mailto\DefaultIcon] @=C:\\Program Files\\Mozilla Thunderbird\\thunderbird.exe,0 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\mailto\shell\open\command] @=\C:\\Program Files\\Mozilla Thunderbird\\thunderbird.exe\ -osint - compose \%1\ I assume you're referring to Process Monitor, which is a really cool tool. Maybe it'll help, but I usually can't get it to filter out enough of the noise to make the output useful. I'll give it a go nonethless. I am running all my tests in a VM, so I really don't care if the registry gets hosed at this point. Thanks again, Mike- Hide quoted text - - Show quoted text - You're welcome :) If Process Monitor has an option to save its output as text files / CSV files (some of the other SysInternals tools do), you might want to try using (a Windows version) of grep or awk to filter out the noise .. Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: Technology solutions for Ruby?
[ Though the OP posted his message to comp.lang.ruby, I'm cross- posting it to comp.lang.python, since he mentions Python as a possible alternative he's looking at, and also because I've recommended Python for his stated needs. Also, interested to see what other Pythonistas have to say in response to my reply. - Vasudev] On Jul 16, 2007, at 2:21 AM, Michael Reiland wrote: At the heart of the issue is the fact that I refuse to use Java for this project, I prefer not to use .Net because of the portability issues, and I'd like to get away from C++ for obvious reasons. To me this means Ruby, Python, or, as mentioned above, Perl. If anyone can tell me of a way to meet the above requirements in either Python or Perl, I'm all ears (I just prefer Ruby). Yes, I think it would be really great for the Ruby community and for the growth of the language if wxRuby was more mature as a GUI toolkit. (Not knocking the wxRuby developers at all, its great that they've even done what they have - I know that creating other language (like Ruby) bindings to a C++ lib is a non-trivial task). My suggestion: Python + wxPython + Python DBI + (Py2Exe + InnoSetup) *might* meet all your needs. (As with any decision about what software technologies to use, you'll have to evaluate the suggested options to see if they fit your needs.) Note: I've used and like both Ruby and Python (saying this after using many, though not all, language features and libraries of both languages), and am not trying to discourage you from using Ruby for your needs; its just that, based on your needs as described, it looks to me as if Python meets them better than Ruby at present: 1. GUI - Native Look and Feel. According to wxRuby the bindings aren't mature enough for production use. Does anyone have any experience with this and/or can you offer alternatives that provide a native look and feel (I I don't know enough about wxRuby to comment. wxPython has this (Native Look and Feel), I think (used it some, a while ago), not 100% sure, you can check on the site - http:/ www.wxpython.org - to make sure. The site does say that it is cross-platform: wxPython is a cross-platform toolkit. This means that the same program will run on multiple platforms without modification. Currently supported platforms are 32-bit Microsoft Windows, most Unix or unix- like systems, and Macintosh OS X. but that doesn't necessarily mean that it will have native look and feel on all supported platforms. (The two are not the same thing.) That's why you will need to check. wxPython pros: Its fairly easy to learn, at least for simple GUI apps (e.g. a few widgets / controls and a file dialog or two). I was able to build these simple ones - see the code, article and screenshots available here (or from links from here): http://www.packtpub.com/article/Using_xtopdf - in quite a short time, starting from zero knowledge of wxPython (I did know some Python from before), just by looking at the sample apps, and some reading of the docs. See the quotes about wxPython: http://www.wxpython.org/quotes.php 2. Databases - contemplating using ActiveRecord, but I would like to use ODBC to support multiple types of DB's in a uniform way (if you know of alternatives to ODBC or ActiveRecord, please let me know). I think, but again, not sure, that Python DBI + appropriate database drivers, may meet this need. Basically Python DBI is similar to ODBC (roughly), and to Perl DBI + DBD, as I understand. There's also ODBC support in the Win32 extensions package for Python - IIRC, Google for 'win32all' to get it. Its also available as a link from the Python for Win32 MSI installer on python.org. I've used Python ODBC some, it works and is easy to use. See this for a simple example: http://jugad.livejournal.com/2006/07/07/ (See the second post at that page, titled Publishing ODBC database content as PDF . The code shown in the post is not indented as per proper the Python syntax (LiveJournal messed up the indentation), sorry about that, but its trivial to correct if you know Python indenting rules). Also read the Python ODBC docs and examples, of course. 3. Binary - Are there any utilities for compiling Ruby into a binary executable? The issue is twofold, speed, and not handing the customer the source :) For Python, there is py2exe (for Windows only). I used py2exe recently and it works well enough for the simple cases that I tried. (I tried building EXEs for a simple Python hello-world program, and for a simple wxPython GUI app based on my xtopdf toolkit. Both worked ok.) For cross-platform (Windows and Linux, IIRC), there is PyInstaller (Google for it), haven't tried it out yet, just downloaded it recently. I don't think you'll gain much speed by this compiling step, though (over and above what Python gives you itself, when it compiles your .py files to .pyc files). The purpose of py2exe is more to hide the source code than to speed it up, as I understand (could be wrong). Note:
Re: Technology solutions for Ruby?
On Jul 16, 10:25 pm, vasudevram [EMAIL PROTECTED] wrote: [ Though the OP posted his message to comp.lang.ruby, I'm cross- posting it to comp.lang.python, since he mentions Python as a possible alternative he's looking at, and also because I've recommended Python for his stated needs. Also, interested to see what other Pythonistas have to say in response to my reply. - Vasudev] On Jul 16, 2007, at 2:21 AM, Michael Reiland wrote: At the heart of the issue is the fact that I refuse to use Java for this project, I prefer not to use .Net because of the portability issues, and I'd like to get away from C++ for obvious reasons. To me this means Ruby, Python, or, as mentioned above, Perl. If anyone can tell me of a way to meet the above requirements in either Python or Perl, I'm all ears (I just prefer Ruby). Yes, I think it would be really great for the Ruby community and for the growth of the language if wxRuby was more mature as a GUI toolkit. (Not knocking the wxRuby developers at all, its great that they've even done what they have - I know that creating other language (like Ruby) bindings to a C++ lib is a non-trivial task). My suggestion: Python + wxPython + Python DBI + (Py2Exe + InnoSetup) *might* meet all your needs. (As with any decision about what software technologies to use, you'll have to evaluate the suggested options to see if they fit your needs.) Note: I've used and like both Ruby and Python (saying this after using many, though not all, language features and libraries of both languages), and am not trying to discourage you from using Ruby for your needs; its just that, based on your needs as described, it looks to me as if Python meets them better than Ruby at present: 1. GUI - Native Look and Feel. According to wxRuby the bindings aren't mature enough for production use. Does anyone have any experience with this and/or can you offer alternatives that provide a native look and feel (I I don't know enough about wxRuby to comment. wxPython has this (Native Look and Feel), I think (used it some, a while ago), not 100% sure, you can check on the site - http:/www.wxpython.org - to make sure. The site does say that it is cross-platform: wxPython is a cross-platform toolkit. This means that the same program will run on multiple platforms without modification. Currently supported platforms are 32-bit Microsoft Windows, most Unix or unix- like systems, and Macintosh OS X. but that doesn't necessarily mean that it will have native look and feel on all supported platforms. (The two are not the same thing.) That's why you will need to check. wxPython pros: Its fairly easy to learn, at least for simple GUI apps (e.g. a few widgets / controls and a file dialog or two). I was able to build these simple ones - see the code, article and screenshots available here (or from links from here): http://www.packtpub.com/article/Using_xtopdf - in quite a short time, starting from zero knowledge of wxPython (I did know some Python from before), just by looking at the sample apps, and some reading of the docs. See the quotes about wxPython:http://www.wxpython.org/quotes.php 2. Databases - contemplating using ActiveRecord, but I would like to use ODBC to support multiple types of DB's in a uniform way (if you know of alternatives to ODBC or ActiveRecord, please let me know). I think, but again, not sure, that Python DBI + appropriate database drivers, may meet this need. Basically Python DBI is similar to ODBC (roughly), and to Perl DBI + DBD, as I understand. There's also ODBC support in the Win32 extensions package for Python - IIRC, Google for 'win32all' to get it. Its also available as a link from the Python for Win32 MSI installer on python.org. I've used Python ODBC some, it works and is easy to use. See this for a simple example: http://jugad.livejournal.com/2006/07/07/ (See the second post at that page, titled Publishing ODBC database content as PDF . The code shown in the post is not indented as per proper the Python syntax (LiveJournal messed up the indentation), sorry about that, but its trivial to correct if you know Python indenting rules). Also read the Python ODBC docs and examples, of course. 3. Binary - Are there any utilities for compiling Ruby into a binary executable? The issue is twofold, speed, and not handing the customer the source :) For Python, there is py2exe (for Windows only). I used py2exe recently and it works well enough for the simple cases that I tried. (I tried building EXEs for a simple Python hello-world program, and for a simple wxPython GUI app based on my xtopdf toolkit. Both worked ok.) For cross-platform (Windows and Linux, IIRC), there is PyInstaller (Google for it), haven't tried it out yet, just downloaded it recently. I don't think you'll gain much speed by this compiling step, though (over and above what Python gives you itself, when it compiles your
Re: execute script in certain directory
On Jul 9, 8:31 pm, brad [EMAIL PROTECTED] wrote: When I use idle or a shell to execute a python script, the script executes in the directory it is currently in (in this case, my desktop). However, when using GNOME and right clicking the py script and selecting 'open with python', the execution occurs in my home directory, not my desktop. Is there a way to force py scripts to always run within the directory that they reside in? Thanks Brad /home/brad/Desktop/output - python from shell /home/brad/Desktop/output - python from idle /home/brad/output - python from Gnome 'right click' open with menu Any program that runs has a concept of a current directory. All its work is done relative to that, unless you open files with absolute paths. Don't know if there's a generic way to do what you want. (There may be, just can't think of it right now). But there are specific ways - script-specific, that is: Add these lines to the top of your script: import os os.chdir(rundir) # Replace rundir above with the absolute path (in quotes) of whatever directory you want the script to have as its current directory when it runs. Looks like GNOME is doing a chdir to your home directory (probably for convenience or security reasons) before running your script, thats why you see that behaviour. This is why I say there may not be an easy generic way to do it - because it would involve modifying all possible execution environments from which your script could be launched. E.g.: even if you modify GNOME to do what you want, how about if tomorrow someone else wants to run your script from KDE or some other window manager? these could do things differently. HTH Vasudev Ram http://www.dancingbison.com http://jugad.livejournal.com http://sourceforge.net/projects/xtopdf -- http://mail.python.org/mailman/listinfo/python-list
Re: How to Machine A python script execute Machine B python script?
On Jul 9, 1:30 pm, Nick Craig-Wood [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Jul 8, 6:45 pm, johnny [EMAIL PROTECTED] wrote: Anyone know how I can make Machine A python script execute a python script on Machine B ? xmlrpc will work. Or pyro http://pyro.sourceforge.net/ Pyro is short for PYthon Remote Objects. It is an advanced and powerful Distributed Object Technology system written entirely in Python, that is designed to be very easy to use. Never worry about writing network communication code again, when using Pyro you just write your Python objects like you would normally. With only a few lines of extra code, Pyro takes care of the network communication between your objects once you split them over different machines on the network. All the gory socket programming details are taken care of, you just call a method on a remote object as if it were a local object! -- Nick Craig-Wood [EMAIL PROTECTED] --http://www.craig-wood.com/nick xmlrpc will work. Right. Pretty easy to use. Go to the xml-rpc.com site to read about it. Python has it included in the standard library, so you don't need to get anything extra to use XML-RPC. And it works as advertised, more or less - I recently wrote some simple servers and clients using Python and XML-RPC. Or SOAP (Google for Python SOAP). But not sure if SOAP is actively supported for Python nowadays. Or ICE - see www.zeroc.com. Haven't tried it out yet, but appears interesting. But it seems ICE has more overhead to setup (your ICE code, I mean, not to install the software itself) than XML-RPC or Pyro. (It looks like a lighter version of CORBA - some of the key people who created it are ex-CORBA experts). Could possibly give better performance or have more features, though ... Also, XML-RPC, SOAP, and ICE are all interoperable with different languages - meaning your server and client can be in different languages; at least, XML-RPC and SOAP have support in many languages, while ICE has it for at least for C++, C#, Java, Python, Ruby, PHP, and Visual Basic (some of these have only support for clients, when I last checked). Vasudev Ram http://www.dancingbison.com http://jugad.livejournal.com http://sourceforge.net/projects/xtopdf -- http://mail.python.org/mailman/listinfo/python-list
How does py2exe work?
Hi, I recently checked out py2exe (on Windows). Looks good. Was able to build an EXE out of one of my Python apps. Wondering how it works? Does it actually compile the Python source of your script into machine language, or does it do something more like bundling the Python interpreter, the Python libraries and the script itself, into a file? Will look at the source code but would like to get some ideas ... Thanks ... Vasudev Ram Dancing Bison Enterprises Biz site: http://www.dancingbison.com Blog on software innovation: http://jugad.livejournal.com xtopdf: PDF creation/construction toolkit: http://www.dancingbison.com/products.html -- http://mail.python.org/mailman/listinfo/python-list
Re: How does py2exe work?
On Jul 2, 12:43 am, Wildemar Wildenburger [EMAIL PROTECTED] wrote: Thomas Jollans wrote: On Sunday 01 July 2007, vasudevram wrote: Wondering how it works? Does it actually compile the Python source of your script into machine language, or does it do something more like bundling the Python interpreter, the Python libraries and the script itself, into a file? essentially, that's what it does. Q: A or B? A: Yes. *nudgenudge* /W He should have said the 2nd way but thanks, I did guess what he meant :-) - Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: Do eval() and exec not accept a function definition? (like 'def foo: pass) ?
On Jun 24, 6:28 am, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On Sun, 24 Jun 2007 11:17:40 +1000, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sat, 23 Jun 2007 19:58:32 +, vasudevram wrote: Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? eval() is a function, and it only evaluates EXPRESSIONS, not code blocks. Actually, that's not exactly true: x = compile('def foo():\n\tprint hi\n', 'stdin', 'exec') l = {} eval(x, l) l['foo']() hi Jean-Paul Thanks, all. Will check out the replies given. - Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: automatical pdf generating
On Jun 24, 10:03 pm, Grant Edwards [EMAIL PROTECTED] wrote: On 2007-06-24, Jackie [EMAIL PROTECTED] wrote: For each folder, I want to print the 4 pictures into a single-paged pdf file (letter sized; print horizontally). All together, I want to get 50 pdf files with names: 01.pdf,02.pdf,...,50.pdf. Is it possible to use Python to realized the above process? Yes. I know there is a module named reportlab. Is there any easy command in the module to do my job? Yes. http://www.reportlab.org/rl_toolkit.htmlhttp://www.reportlab.com/docs/userguide.pdf -- Grant Edwards grante Yow! You mean you don't at want to watch WRESTLING visi.comfrom ATLANTA? There are many different ways to do what you want, as the other replies say. 1. If you're not a programmer, the OpenOffice suggestion is good. 2.1 If you're a programmer, read up on the ReportLab docs shown in a previous reply by Grant Edwards, and try it out. Equivalently, you could use Ruby and PDF::Writer. Both ReportLab and PDF::Writer have support for creating PDFs with images, and both Python and Ruby can automate the part of iterating over the multiple files and directories. 2.2 Also you could try another approach - use some scripting language like Python (or Perl or Ruby) together with one of the free PDF creation / conversion tools that you can easily find on the Internet by a Google search (using suitable keywords like HTML to PDF, PDF conversion, etc. Make sure to try out various combinations / variations of keywords if you don't get a solution at once - this is fundamental to Web searching. And ... if you're not a programmer, consider becoming one :-) It's good fun, and will help you do a lot of things ... Vasudev Ram http://www.dancingbison.com http://jugad.livejournal.com http://sourceforge.net/projects/xtopdf -- http://mail.python.org/mailman/listinfo/python-list
Do eval() and exec not accept a function definition? (like 'def foo: pass) ?
Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? I wrote a function to generate other functions using something like eval(def foo: ) but it gave a syntax error (Invalid syntax) with caret pointing to the 'd' of the def keyword. Details (sorry for the slight long post but thought it better to give more details in this case - wording is pretty clear, though, I think, so shouldn't take long to read): While working on a personal project for creating a server for a certain protocol (which I may make into an open source project later if it turns out to be any good), I wrote some simple functions to generate HTML start and end tags like html, body, /html, / body, etc. - just to simplify/shorten my code a little. (I'm aware that there are HTML generation libraries out there, but don't think I need the overhead, since my needs are very simple, and anyway wanted to roll my own just for fun. For a bigger/more serious project I would probably use the existing libraries after doing a proper evaluation). So, this question is not about HTML generation but about Python's eval() function and exec statement. Started by writing functions like this: def start_html(): return 'html\r\n' def end_html(): return '/html\r\n' ... and similarly for the 'body', 'p', etc. HTML tags. (I used '\r\n' at the end because the server will send this output to the browser over HTTP, so that my code conforms to Internet protocols, and also so that while debugging, my output would have only one tag per line, for readability. Not showing the '\r\n in the rest of the code below) Then I realized that all these functions are very similar - only differ in the return value of the tag. So (being interested in metaprogramming of late), thought of writing a function that would generate these functions, when passed the appropriate tag name argument. [ Digression: I could of course have used another simple approach such as this: def start_tag(tag_name): return '' + tag_name + '' # called like this: # print start_tag('html') # print start_tag('body') # and def end_tag(tag_name): return '/' + tag_name + '' # called like this: # print end_tag('body') # print end_tag('html') # and called similarly for the other HTML tags. While the above would work, it still would involve a bit more typing than I'd like to do, since I'[d have to pass in the tag name as an argument each time. I'd prefer having functions that I could call like this: print start_html() # which would print html print start_body() # which would print body # and so on ... just to make the code a little shorter and more readable. End of Digression] So, I wrote this code generation function: # import string def generate_html_tag_function(tag_name, start_or_end): start_or_end.lower() assert(start_or_end in ('start', 'end')) if start_or_end == 'start': func_def = def start_ + tag_name + :()\n + \ return '' + tag_name + '' else: func_def = def end_ + tag_name + :()\n + \ return '/' + tag_name + '' function = eval(func_def) return function # meant to be called like this: start_html = generate_html_tag_function('html', 'start') start_body = generate_html_tag_function('body', 'start') end_html = generate_html_tag_function('html', 'end') end_body = generate_html_tag_function('body', 'end') # and the generated functions would be called like this: print start_html() print start_body() print end_body() print end_html() # # giving the output: html body /body /html But when I ran the above code (between the lines marked # and #), I got an error Invalid syntax with the caret pointing at the d of the def statement. I had used eval a few times earlier for somewhat similar uses, so thought this would work. I then looked up the Python Language Reference help, and saw that eval is used to evaluate Python expressions, not statements, and def is a statement. So looked up the exec statement of Python and saw that its syntax seemed to allow what I wanted. So replaced the line containing eval in the above with: exec(func_def) But that too gave the same error (I think so - I tried this yesterday and forgot to save the error messages, sorry about that, so can't be sure, but do think this was the case - if not, I'll save the exact code and output/errors later and repost here - not at my PC right now.) Thanks for any suggestions, Vasudev Ram Bize site: http://www.dancingbison.com PDF creation / conversion toolkit: http://sourceforge.net/projects/xtopdf Blog on software innovation: http://jugad.livejournal.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Do eval() and exec not accept a function definition? (like 'def foo: pass) ?
On Jun 24, 1:20 am, Eduardo Dobay [EMAIL PROTECTED] wrote: Hey, I think you could use lambda functions for that matter (Ever heard of them?). You could write something like: def generate_html_tag_function(tag_name, start_or_end): start_or_end.lower() assert(start_or_end in ('start', 'end')) if start_or_end == 'start': function = lambda: '' + tag_name + '' else: function = lambda: '/' + tag_name + '' return function Then you would create the functions using the same code you had written before: start_html = generate_html_tag_function('html', 'start') start_body = generate_html_tag_function('body', 'start') end_html = generate_html_tag_function('html', 'end') end_body = generate_html_tag_function('body', 'end') That seems to do what you want. Eduardo Thanks to all the repliers. @Eduardo: Yep, I had heard of lambdas, but didn't think to use them here. Will try this out - thanks! - Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: python unix install, sqlite3
On May 29, 11:40 pm, Simon [EMAIL PROTECTED] wrote: On May 29, 7:05 am, vasudevram [EMAIL PROTECTED] wrote: On May 29, 5:52 pm, Simon [EMAIL PROTECTED] wrote: I installed the source code on unix for python 2.5.1. The install went mainly okay, except for some failures regarding: _ssl, _hashlib, _curses, _curses_panel. No errors regarding sqlite3. However, when I start python and do an import sqlite3 I get: /ptmp/bin/ python Python 2.5.1 (r251:54863, May 29 2007, 05:19:30) [GCC 3.3.2] on sunos5 Type help, copyright, credits or license for more information. import sqlite3 Traceback (most recent call last): File stdin, line 1, in module File /ptmp/Python-2.5.1/lib/python2.5/sqlite3/__init__.py, line 24, in module from dbapi2 import * File /ptmp/Python-2.5.1/lib/python2.5/sqlite3/dbapi2.py, line 27, in module from _sqlite3 import * ImportError: No module named _sqlite3 Some ideas: I don't know if sqlite3 comes bundled with the standard Python source bundle. My guess is not. If not, that's the cause of the error - you need to install sqlite3 (and probably pysqlite3 (not sure of the name (whether it has a trailing 3) which, if I remember, is the Python binding/wrapper for sqlite3 (which is a C library, I think). Other possible cause of the error (if sqlite3 _is_ bundled with Python and no Python binding/wrapper is needed, is that sqlite3 depends on one of those other libraries you mention (such as _hashlib) for which you got errors while installing Python from source. HTH VasudevRam Dancing Bison Enterpriseswww.dancingbison.com-Hide quoted text - - Show quoted text - Vasudev, Thanks so much for the reply. I went to their website and your guess was correct. Python 2.5 has included support for sqlite but it only includes the PySqlite interface module (now called sqlite3). It does not include sqlite3 with the source distribution. Simon You're welcome, Simon. Good to hear that it worked :-) Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: Periodic tasks.
Steve Howell wrote: Thanks. Here are two links, not sure those are exactly what are being referenced here, but look in the ballpark: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413137 http://docs.python.org/lib/module-sched.html You're welcome. The ActiveState recipe you mention above is not the one I meant, although it uses sched. I saw the recipe that I mentioned, in the print version of the Python Cookbook, when reading it a few days ago. The second link above you mention is right, its about the sched library. Also just found these other recipes in the online Python Cookbook, may or may not be of help to you: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496800 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/114644 Vasudev Ram www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Periodic tasks.
On May 29, 4:39 pm, Steve Holden [EMAIL PROTECTED] wrote: Alternatively, the user could make use of the already-existing sched module from the standard library. With a little threading that would do the job fine. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden -- Asciimercial - Yes. Also, there's an example in the Python Cookbook (print edition) which is exactly about this - using sched. The recipe before that also shows how to do it without using the sched library. Both those recipes are purely in Python. Vasudev Ram Dancing Bison Enterprises www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: python unix install, sqlite3
On May 29, 5:52 pm, Simon [EMAIL PROTECTED] wrote: I installed the source code on unix for python 2.5.1. The install went mainly okay, except for some failures regarding: _ssl, _hashlib, _curses, _curses_panel. No errors regarding sqlite3. However, when I start python and do an import sqlite3 I get: /ptmp/bin/ python Python 2.5.1 (r251:54863, May 29 2007, 05:19:30) [GCC 3.3.2] on sunos5 Type help, copyright, credits or license for more information. import sqlite3 Traceback (most recent call last): File stdin, line 1, in module File /ptmp/Python-2.5.1/lib/python2.5/sqlite3/__init__.py, line 24, in module from dbapi2 import * File /ptmp/Python-2.5.1/lib/python2.5/sqlite3/dbapi2.py, line 27, in module from _sqlite3 import * ImportError: No module named _sqlite3 Some ideas: I don't know if sqlite3 comes bundled with the standard Python source bundle. My guess is not. If not, that's the cause of the error - you need to install sqlite3 (and probably pysqlite3 (not sure of the name (whether it has a trailing 3) which, if I remember, is the Python binding/wrapper for sqlite3 (which is a C library, I think). Other possible cause of the error (if sqlite3 _is_ bundled with Python and no Python binding/wrapper is needed, is that sqlite3 depends on one of those other libraries you mention (such as _hashlib) for which you got errors while installing Python from source. HTH Vasudev Ram Dancing Bison Enterprises www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get started as a xhtml python mysql freelancer ?
On May 26, 5:55 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On May 25, 7:55 pm, gert [EMAIL PROTECTED] wrote: On May 26, 2:09 am, Paul McNett [EMAIL PROTECTED] wrote: gert wrote: I made something that i was hoping it could make people happy enough so i could make a living by providing support for commercial use of http://sourceforge.net/projects/dfo/ But in reality i am a lousy sales men and was wondering how you people sell stuff as a developer ? Some suggestions: - give more details on the front page of the sourceforge site, on what your product is about and its benefits. Consider creating a web site for it. -write articles about it / post on appropriate newsgroups about your product, giving code examples of how it can be used, and the benefits. - if you haven't already, create a personal web site - its better to get your own paid one than to use a free one, and put (objective) info there on your skills, your past experience, your open source work, your writings, etc. Give your contact info too. I've done this myself and it has resulted in getting leads for contracting work. Be patient though - work leads may not come in a hurry. - join sites like Elance.com or ODesk.com for getting work. Vasudev Ram Dancing Bison Enterprises http://www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I time a method of a class in python using Timeit
On May 24, 8:36 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I am using timeit to time a global function like this t = timeit.Timer(timeTest(),from __main__ import timeTest) result = t.timeit(); But how can i use timeit to time a function in a class? class FetchUrlThread(threading.Thread): def aFunction(self): # do something def run(self): # how can I time how long does aFunction() take here? aFunction(); Thank you. Try this: def run(self): import time t1 = time.clock() aFunction(); t2 = time.clock() print aFunction took %d seconds % int(t2 - t1 + 1) (Code is not tested as I'm not at my PC right now). The int() is to round it off to an integer, and the +1 is to give a more accurate result - may not work in all cases, experiment, and check for a ceil/floor type function in Python. Vasudev Ram Dancing Bison Enterprises www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Help required with Python App
On May 21, 8:11 pm, Trevor Hennion [EMAIL PROTECTED] wrote: Hi, I am producing a Web based database application for a customer and could do with some help producing pdf documents from the data. The project uses Apache. Postgresql and Python CGI scripts on a Linux server for a company with 20-25 users. I have been looking at thehttp://www.reportlab.org- ReportLab Toolkit, but am rather busy with the other parts of the project, so if any one located in the UK - Reading/Basingstoke area has the right skills and time available now, please contact me. I have a small budget available for this work. Regards Trevor PS UK/Reading/Basingstoke area is essential. I don't have the time right now, though I'd be free for some work after a week or two; but I'm not in your area. ReportLab is quite good and has many features. I used it to build my xtopdf toolkit, a toolkit for conversion of other file formats to PDF. You could try using it (ReportLab) directly from the Python scripts in your app. If your needs are only for text to PDF conversion (of the textual data - numbers, strings and dates from the database), then you might want to take a look at xtopdf - see http://www.dancingbison.com/products.html. It may be a bit easier to use than ReportLab itself (it has a small and simple to use API), but only for text to PDF conversion - it doesn't support images as of now. It's released under the same license as ReportLab, the BSD license. xtopdf has sample programs that show you how to use it. It supports setting the font (anywhere in the output, but only one font at a time, headers and footers for each page, and automatic pagination). You can also read this article about it: http://www.packtpub.com/article/Using_xtopdf The article above shows how to use xtopdf to create PDF from various input formats - CSV, text, TDV, XLS, etc. All done very simply with just a few lines of code. You could try using either Reportlab or xtopdf or getting someone to help with using one of them. HTH Vasudev Ram Dancing Bison Enterprises http://www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Help required with Python App
On May 21, 8:11 pm, Trevor Hennion [EMAIL PROTECTED] wrote: Hi, I am producing a Web based database application for a customer and could do with some help producing pdf documents from the data. The project uses Apache. Postgresql and Python CGI scripts on a Linux server for a company with 20-25 users. I have been looking at thehttp://www.reportlab.org- ReportLab Toolkit, but am rather busy with the other parts of the project, so if any one located in the UK - Reading/Basingstoke area has the right skills and time available now, please contact me. I have a small budget available for this work. Regards Trevor PS UK/Reading/Basingstoke area is essential. I don't have the time right now, though I'd be free for some work after a week or two; but I'm not in your area. ReportLab is quite good and has many features. I used it to build my xtopdf toolkit, a toolkit for conversion of other file formats to PDF. You could try using it (ReportLab) directly from the Python scripts in your app. If your needs are only for text to PDF conversion (of the textual data - numbers, strings and dates from the database), then you might want to take a look at xtopdf - see http://www.dancingbison.com/products.html. It may be a bit easier to use than ReportLab itself (it has a small and simple to use API), but only for text to PDF conversion - it doesn't support images as of now. It's released under the same license as ReportLab, the BSD license. xtopdf has sample programs that show you how to use it. It supports setting the font (anywhere in the output, but only one font at a time, headers and footers for each page, and automatic pagination). You can also read this article about it: http://www.packtpub.com/article/Using_xtopdf The article above shows how to use xtopdf to create PDF from various input formats - CSV, text, TDV, XLS, etc. All done very simply with just a few lines of code. You could try using either Reportlab or xtopdf or getting someone to help with using one of them. HTH Vasudev Ram Dancing Bison Enterprises http://www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI tutorial
On May 13, 10:51 pm, John K Masters [EMAIL PROTECTED] wrote: Can someone point me in the direction of a good tutorial on programming python with a GUI? I'm just starting out with python and have written a few scripts successfully but would like to add a graphical front end to them to make it easier for my work colleagues, most of whom have never used a command line, to use. Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) That depends on which GUI toolkit you want to use. There are at least one or two good online tutorials on the Web for Tkinter (the Python interface to the Tk toolkit). One is by Fredrik Lundh (a.k.a the effbot, a leading Python contributor). Google for suitable keywords, e.g. Tkinter tutorial. Tkinter comes with Python by default on Windows, so that helps. But wxPython is not a bad toolkit either. (You'll have to download and install it, also the demos (see below) are often a separate download.) I've used it some, and like it. I don't know of any tutorials for it, though there may be some - again, Google for info. But if you already have some GUI programming background, its not too difficult to pick up it up. It comes with a big set of demos with source code, and I was able to learn enough wxPython to write some simple apps just by looking at the demos source code and reading some of the reference documentation. Those apps are here: http://www.packtpub.com/article/Using_xtopdf Check the last part of the article for links to the source code. PyQt is another option, recommended by some people. Haven't tried it myself but have used Qt (the C++ GUI toolkit to which PyQt is a binding) a little, and like it a lot. Qt again is supposed to be of very high quality, according to some people. I am currently reading a book Programming Qt and found most of it pretty straightforward (though not simple :-) to understand (you do need to understand the concept of signals and slots, as that is fundamental to Qt programming). HTH Vasudev Ram Dancing Bison Enterprises http://www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: db access
king kikapu wrote: On Dec 29, 12:12 am, johnf [EMAIL PROTECTED] wrote: king kikapu wrote: Hi to all, is there a way to use an RDBMS (in my case, SQL Server) from Python by using some built-in module of the language (v. 2.5) and through ODBC ?? I saw some samples that use statements like import dbi or import odbc but neither modules (dbi, odbc) are present on my system... Any hint(s) ?? Its not really related to your question, but if you also want to publish your database data to PDF, here's one way: http://mail.python.org/pipermail/python-list/2006-July/392099.html Vasudev ~~ Vasudev Ram Dancing Bison Enterprises Software training and consulting http://www.dancingbison.com http://www.dancingbison.com/products.html ~~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Elliptic Curve Library
Jaap Spies wrote: Mike Tammerman wrote: I need an elliptic curve library that can be used by python. I googled but couldn't find a one. I'll appreciate, if you could show me. You could look at http://sage.scipy.org/sage/ http://sage.scipy.org/sage/features.html Jaap Sorry, don't know about those areas. Hope the other reply is of help. Vasudev www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Connection python with C
Fredrik Lundh wrote: Χρυσάνθη Αϊναλή wrote: I want to connect a script in python with a source code in C. Any ideas about it? http://docs.python.org/lib/module-ctypes.html http://docs.python.org/ext/ext.html http://effbot.org/pyfaq/extending-index.htm /F Just a suggestion: another way could be to use XML-RPC. It's a lightweight distributed computing technology. Python standard library has an XML-RPC module. I'm not sure, but I think there may be a similar module for C. I'm almost certain there is one for C++. Try xmlrpc.com or xml-rpc.com and also Google for appropriate patterns, e.g. XML-RPC library for C. Try a few variations on the pattern, that helps. Yet another way - might be suitable only if your Python script and your C program can both read/write standard input/output, and one is a producer and the other is the related consumer. In this case you can just use: $ python my_python_script | my_C_binary or the other way around, as per need. HTH Vasudev ~ Vasudev Ram Dancing Bison Enterprises http://www.dancingbison.com Check out the cool Snap.com link preview feature on my site. Free sign-up at www.snap.com I'm not affiliated with Snap.com ~ -- http://mail.python.org/mailman/listinfo/python-list
Saw a possibly interesting Python PDF library - pyPDF
Saw a possibly interesting Python PDF library - pyPDF. For merging/splitting PDFs and related operations. It's at http://pybrary.net/pyPdf/ HTH Vasudev ~ Vasudev Ram Dancing Bison Enterprises http://www.dancingbison.com Check out the cool Snap.com link preview feature on my site. Free sign-up at www.snap.com I'm not affiliated with Snap.com ~ -- http://mail.python.org/mailman/listinfo/python-list
Re: How a script can know if it has been called with the -i command line option?
Peter Wang wrote: Michele Simionato wrote: The subject says it all, I would like a script to act differently when called as $ python script.py and when called as $ python -i script.py. I looked at the sys module but I don't see a way to retrieve the command line flags, where should I look? I realize this is quite a hack, but the entire command line is preserved in the process's entry in the OS's process table. if you do ps -ax you will see that the interpreter was invoked with -i. I didn't test this under windows, but it works on Mac and Linux. That hack might not work - at least, as described, and on Linux or Mac OS if the UNIX-based one, i.e. OS X). Because there could be other users who ran python command lines with or without the -i option. As described, there's no way for this user to know which python invocation is his/hers, and which are of other users. There might be a way, though, if we can get this user's python instance's process id and then grep for a line containing that id (in the appropriate column) in the ps output. Vasudev Ram ~~ Dancing Bison Enterprises http://www.dancingbison.com http://dancingbison.blogspot.com ~~ Check out the cool Snap.com preview feature on my web site. Free signup for anyone at www.snap.com I'm not affiliated with it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Elliptic Curve Library
Mike Tammerman wrote: Hi, I need an elliptic curve library that can be used by python. I googled but couldn't find a one. I'll appreciate, if you could show me. Mike What is the library you need supposed to do? Vasudev Ram Dancing Bison Enterprises www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How a script can know if it has been called with the -i command line option?
vasudevram wrote: Peter Wang wrote: Michele Simionato wrote: The subject says it all, I would like a script to act differently when called as $ python script.py and when called as $ python -i script.py. I looked at the sys module but I don't see a way to retrieve the command line flags, where should I look? I realize this is quite a hack, but the entire command line is preserved in the process's entry in the OS's process table. if you do ps -ax you will see that the interpreter was invoked with -i. I didn't test this under windows, but it works on Mac and Linux. That hack might not work - at least, as described, and on Linux or Mac OS if the UNIX-based one, i.e. OS X). Because there could be other users who ran python command lines with or without the -i option. As described, there's no way for this user to know which python invocation is his/hers, and which are of other users. There might be a way, though, if we can get this user's python instance's process id and then grep for a line containing that id (in the appropriate column) in the ps output. Vasudev Ram ~~ Dancing Bison Enterprises http://www.dancingbison.com http://dancingbison.blogspot.com ~~ Check out the cool Snap.com preview feature on my web site. Free signup for anyone at www.snap.com I'm not affiliated with it. Just realized: getting the python process's process id is possible from the Python program itself, using os.getpid(). Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: removing the header from a gzip'd string
Fredrik Lundh wrote: Gabriel Genellina wrote: Using the default options (deflate, default compression level, no custom dictionary) will make those first two bytes 0x78 0x9c. If you want to encrypt a compressed text, you must remove redundant information first. encryption? didn't the OP say that he *didn't* plan to decompress the resulting data stream? Knowing part of the clear message is a security hole. well, knowing the algorithm used to convert from the original clear text to the text that's actually encrypted also gives an attacker plenty of clues (especially if the original is regular in some way, such as always an XML file or always a record having this format). sounds to me like trying to address this potential hole by stripping off 16 bits from the payload won't really solve that problem... /F Yes, I'm also interested to know why the OP wants to remove the header. Though I'm not an expert on the zip format, my understanding is that most binary formats are not of much use in pieces (though some composite formats might be, e.g. you might be able to meaningfully extract a piece, such as an image embedded in a Word file). I somehow don't think a compressed zip file would be of use in pieces (except possibly for the header itself). But I could be wrong of course. Vasudev Ram http://www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Sybase module 0.38pre1 released
Sébastien Sablé wrote: By the way, I forgot to say that new releases can now be downloaded from this page: https://sourceforge.net/project/showfiles.php?group_id=184050 regards -- Sébastien Sablé Thanks. Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: Sybase module 0.38pre1 released
Sébastien Sablé wrote: WHAT IS IT: The Sybase module provides a Python interface to the Sybase relational database system. It supports all of the Python Database API, version 2.0 with extensions. MAJOR CHANGES SINCE 0.37: * This release works with python 2.5 * It also works with sybase 15 * It works with 64bits clients * It can be configured to return native python datetime objects * The bug This routine cannot be called because another command structure has results pending. which appears in various cases has been corrected * It includes a unitary test suite based on the dbapi2.0 compliance test suite Hi, Where can we get it? Thanks Vasudev -- Vasudev Ram Dancing Bison Enterprises Software consulting and training http://www.dancingbison.com http://dancingbison.blogspot.com http://jugad.livejournal.com -- http://mail.python.org/mailman/listinfo/python-list
Re: SOAP Server with WSDL?
Ravi Teja wrote: tobiah wrote: Actually, do I have to make a WSDL? Do people hand write these, or are there tools? I don't really need to publish an interface. I just want some in house apps to communicate. Java and .NET based tools can auto-generate WSDL from code. Python does not have such because function definitions do not contain the type information required for such a tool. However , you can grab a free Java (Netbeans with Enterprise pack) or .NET (Visual Studio Express) IDE (or just the respective SDK if you don't mind reading through the docs), create a stub function, mark it as a WebMethod, let it generate the WSDL and pass it to wsdl2py that comes with ZSI. This is a twisted approach. But you state that you don't need to publish an interface. If that is the case, it can be as simple as this. import SOAPpy def hello(): return Hello World server = SOAP.SOAPServer((localhost, 8080)) server.registerFunction(hello) server.serve_forever() Pasted from http://pywebsvcs.sourceforge.net/soappy.txt I can't figure out if I want SOAP, or CORBA, or would it just be easier if I just starting opening sockets and firing data around directly. Ideally, I'd like to share complex objects. That's why I thought that I needed one of the above standards. I posted a few days ago a simple guide to choosing a remoting framework. http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/f53221adfca5c819/58057e83c0ad7c27?rnum=1hl=enq=webraviteja_done=%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2Ff53221adfca5c819%2F3f056c5c87279aca%3Flnk%3Dgst%26q%3Dwebraviteja%26rnum%3D4%26hl%3Den%26#doc_3f056c5c87279aca For *complex* objects, you need a stateful remoting mechanism. The choice is Pyro if both the server and all the clients are written in Python. Else, use CORBA or ICE with DMI. All of these are simple to use for simple remote object invocations although distributed computing in general does have a learning curve. Ravi Teja. -- http://mail.python.org/mailman/listinfo/python-list
Re: Book recommendations
Can someone recommend a Python book for a newbie and perhaps you have a used one for sale? Thank you. A Byte of Python is supposed to be good for beginners too. See http://www.byteofpython.info/ Its also a recommended book on the main Python site www.python.org From the preface: This book serves as a guide or tutorial to the Python programming language. It is mainly targeted at newbies (those who are new to computers). It is also useful for experienced programmers who are new to Python. The aim is: If all you know about computers is how to open and save text files, then you should be able to learn Python from this book. If you have previous programming experience, then this book should be useful to get you up to speed on Python. HTH Vasudev ~~~ Vasudev Ram Software consulting and training Dancing Bison Enterprises http://www.dancingbison.com http://jugad.livejournal.com http://dancingbison.blogspot.com ~~~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python work in UK
Hi, A few suggestions, you may have tried them already: Search for UK Python jobs on major job sites like Monster, Dice, etc. Some (like Monster) have country-specific sites, I think. I know Monster has an India-specific site, it probably also has one for the UK. Have you considered the option of being a freelancer and working via Net job sites like eLance, Guru.com, oDesk? Also check out the Python job board at http://www.python.org/community/jobs/ HTH Vasudev --- Site: http://www.dancingbison.com Blogs: http://jugad.livejournal.com http://dancingbison.blogspot.com Open source project: http://www.dancingbison.com/products.html --- Will McGugan wrote: Hi, I'd love to work in Python, for the sake of my blood pressure, but there doesnt seem to be that many jobs that look for Python as the main skill. I use Python at work from time to time, and occasionaly get to spend several days on a Python project but the majority of the time I use C++. How can I make that leap to working with Python? There doesn't seem to be many UK positions on the jobs section of Python.org or the usual jobs sites. Any recommended jobs sites or tips? (I have googled) In the off chance that a potential empolyer is reading this, I'm looking for something in web development, applications, graphics or other interesting field. Here is a copy of my CV. http://www.willmcgugan.com/cvwillmcgugan.pdf Regards, Will McGugan -- http://www.willmcgugan.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Has anyone generated Open Office Calc XML files from python
vj wrote: Isn't generating CSV output suitable to your needs? Python's CSV module makes that very simple - unless you want to include images, etc. in the XLS file? You cannot create multiple worksheets using this method, or apply any other form of formatting. VJ Ok, got it. -- http://mail.python.org/mailman/listinfo/python-list