Python equivalent of script(1)
Is there anything like script(1) for python interactive sessions. From script(1) manpage: Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1). If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is saved in the file typescript. In my case I wouldn't like to use it as a proof of anything, but I want to get a script accessing a library system in my school -- it means many attempts to play with urllib. I would prefer to do it in an interactive session, but then I would love to have a record of all what I've done, so I can edit this record into final script. Thanks for any hint, Matej Cepl -- http://mail.python.org/mailman/listinfo/python-list
Re: Python equivalent of script(1)
Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
Re: jython lacks working xml processing modules?
On 17/07/12 10:35, [email protected] wrote: > I'm trying to parse an xml file with jython (not through java parsers > like xerces). https://code.google.com/p/jython-elementtree/ ??? -- http://mail.python.org/mailman/listinfo/python-list
Re: jython lacks working xml processing modules?
On 18/07/12 05:12, [email protected] wrote: However,there is one project implemented by Python used PyXML and now my Jython project has to depend on it ,so I am afraid that if Jython doesn't support PyXML,then my jython project can not depend on the original Python project ,then my jython project maybe can not move on unless I find another project to take place of the original Python project. I think, if possible, such project should switch out of PyXML anyway. If you make them nice patch to port them to standard ElementTree (and as a side-effect make the project working with Jython), they will like you. I guess. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: dbf.py 0.94
On 21/07/12 05:26, Ethan Furman wrote: dbf (also known as python dbase) is a module for reading/writing dBase III, FP, VFP, and soon Clipper, .dbf database files. It's an ancient format that still finds lots of use. Other than the caring for the ancient legacy data, it is still widely used in GIS, because shapefiles (http://en.wikipedia.org/wiki/Shapefile) are based on it. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: VPS For Python
On 26/08/12 09:41, coldfire wrote: I will really appreciate if someone type the address of any of the following for use with python If you can live just with PaaS (i.e., no shell account in the strict sense of the word, although you have ssh access) then my employer is introducing OpenShift (http://openshift.redhat.com) and I have a very great experience with playing with it. Use #openshift on Freenode for further support. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: submit jobs on multi-core
On 13/09/12 03:59, Jason Friedman wrote: Or if Python 3.2 is an option, the concurrent.futures module would be very well suited for this task. Also available as an external download for Python 2.* ... http://pypi.python.org/pypi/futures/ Matěj -- http://mail.python.org/mailman/listinfo/python-list
pyOpenSSL -> m2crypto conversion?
Hi, gajim (http://gajim.org, Jabber/XMPP instatnt messenger written in PyGtk) uses for crypto mix of some functions from the standard library, pyOpenSSL for SSL communication, and python-crypto for E2E (encryption of the messages ... uses RSA and AES; see https://trac.gajim.org/ticket/5294 for more details). Now I would like to unify external crypto libraries just to m2crypto (a) I think using two crypto libraries is suspicious, b) I would like to eliminate use python-crypto to minimize general number of crypto libraries), for which I would like to first of all port pyOpenSSL-using code to m2crypto. Is there some HOWTO/blogpost/examples of doing so, or is there some help in m2crypto for that? Both libraries are bindings over OpenSSL, so I hope it wouldn't be that difficult. https://bugs.launchpad.net/pyopenssl/+bug/236170/comments/22 seems to suggest that there might be some pyOpenSSL compatibility wrapper for m2crypto ... do I understand it correctly? Any suggestoins, help is highly welcomed. Thank you in advance, Matěj Cepl -- http://mail.python.org/mailman/listinfo/python-list
Re: Editing Inkscape SVG files with Python?
On 24/09/12 00:53, Steven D'Aprano wrote: Googling for "python inkscape" comes up with too many hits for Inkscape's plugin system to be much help to me. Aside from suggesting lxml, I would ask "So why not to follow the stream and create Inkscape plugin"? I have in similar situation created a plugin (https://gitorious.org/inkscape-ungroup-deep/) and I have to say it wasn't that difficult and results are pretty satisfactory. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: Article on the future of Python
On 26/09/12 15:30, Kevin Walzer wrote: > Apart from IronPython, what constituency do these alternative and Jython ... that is widely used in the Java server world > implementations of Python have that would raise them above the level of > interesting experiments? Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: "#!/usr/bin/env python" vs. "#!/usr/bin/python"?
On 28/09/12 12:57, Roy Smith wrote: > But, you might as well get into the habit of > using the /usr/bin/env flavor because it's more flexible. In the same manner as one's freedom-fighter is another's fundamentalist terrorist, what's flexible could be also dangerous. E.g., #!/usr/bin/env python is forbidden in the core Fedora packages (https://fedoraproject.org/wiki/Features/SystemPythonExecutablesUseSystemPython), because nobody is willing to risk that by some random python binary in /usr/local/bin some core infrastructure of Fedora installations (e.g., yum) could be broken. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: Where are documentation for Gnome
On Sat, 13 Oct 2012 20:14:50 +0200, Kwpolska wrote: > https://live.gnome.org/EyeOfGnome/Plugins#Python > > That is all the documentation in existence for Python plugins. > > Examples: > http://git.gnome.org/browse/eog-plugins/tree/plugins/slideshowshuffle > http://git.gnome.org/browse/eog-plugins/tree/plugins/pythonconsole > > The C code may be of use: > > http://ftp.acc.umu.se/pub/GNOME/sources/eog/3.6/eog-3.6.0.tar.xz > > Have fun— oh wait. You can’t, because PyGTK is an unreadable mess. > And you are working with undocumented stuff. Also, it is irrelevant ... Gnome3 doesn't use PyGTK, you want PyGIO (for example https://live.gnome.org/PyGObject/IntrospectionPorting and other links to PyGIO). Hint: if you install gobject-introsepction-devel (or whatever is the name of the package in your distro), you will get in devhelp quite a nice documentation, and also a lot of stuff to read in / usr/share/gir-*/. Best, Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: PyPI - how do you pronounce it?
On 28.1.2012 17:06, Miki Tebeka wrote: cheeseshop :) +1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading Adobe PDF File
On 29.1.2012 06:52, Shrewd Investor wrote: Or do I need to find a way to convert a PDF file into a text file? If so how? http://en.wikipedia.org/wiki/Pdftotext ? -- http://mail.python.org/mailman/listinfo/python-list
Re: SnakeScript? (CoffeeScript for Python)
On 3.2.2012 02:19, Ian Kelly wrote: Then how are you going to maintain the code? Maintain the compiled code or the source? As with all compiled software, you maintain the input, not the output. I don't think that's what was the question. CoffeeScript is a hopeless hack in the hopeless situation of Javascript world where no language development is available (meaning, time between filing a bug to the moment the change is useful in The Real World™ is many many years). Ask anybody developing in CoffeeScript/Vala how much they love debugging when they have to go through different styles of errors, bugs in the intermediate processes, etc. In the end all these languages IMHO either develop a new frontend for gcc/clang/PyPy (or fork of CPython) or die, because the former is not that much more difficult than writing your preprocessor, I believe. Best, Matěj -- http://mail.python.org/mailman/listinfo/python-list
Python and TAP
I have just finished listening to the FLOSS Weekly podcast #200 (http://twit.tv/show/floss-weekly/200) on autotest, where I've learned about the existence of TAP (http://testanything.org/). A standardization of testing seems to be so obviously The Right Thing™, that it is strange that I don't see much related movement in the Python world (I know only about http://git.codesimply.com/?p=PyTAP.git;a=summary or git://git.codesimply.com/PyTAP.git, which seems to be very very simple and only producer). What am I missing? Why nobody seems to care about joining TAP standard? Best, Matěj -- http://mail.python.org/mailman/listinfo/python-list
difference between random module in python 2.6 and 3.2?
Hi,
I have this working function:
def as_xml(self):
out = etree.Element("or")
for k in sorted(self.keys()):
out.append(etree.Element("hostname",
attrib={'op': '=', 'value': random.choice(self[k])}))
# ... return somehow string representing XML
and this unit test
def test_XML_print(self):
random.seed(1)
expected = ... # expected XML
observed = self.data.as_xml()
self.assertEqual(observed, expected,
"Verbose print (including PCI IDs)")
Strange thing is that this unit tests correctly with python3, but fails
with python2. The problem is that apparently python3 random.choice picks
different element of self[k] than the one python2 (at least, both of
them are constant in their choice).
Is it known that there is this difference? Is there a way how to make
both random.choice select the same?
Best,
Matěj
--
http://mail.python.org/mailman/listinfo/python-list
Re: difference between random module in python 2.6 and 3.2?
On 6.2.2012 09:05, Steven D'Aprano wrote: You have persuaded me that the doc should be more explicit that while the basic random.random sequence will be kept repeatable with seed set (except perhaps after a changeover of several releases), the convenience transformations can be changed if improvements are needed or thought sufficiently desirable. A more explicit note will help, but the basic problem applies: how do you write deterministic tests given that the random.methods (apart from random.random itself) can be changed without warning? Also, how could I write a re-implementation of random.choice which would work same on python 2.6 and python 3.2? It is not only matter of unit tests, but I would really welcome if the results on both versions produce the same results. Could we get some hint in the release notes? Thanks for the help, Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between random module in python 2.6 and 3.2?
On 6.2.2012 09:45, Matej Cepl wrote: Also, how could I write a re-implementation of random.choice which would work same on python 2.6 and python 3.2? It is not only matter of unit tests, but I would really welcome if the results on both versions produce the same results. Silly, of course, the solution is obvious ... I have just embedded random.choice from 2.6 to my code. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and TAP
On 6.2.2012 21:51, Terry Reedy wrote: The 'TAP standard' is what the Perl TAP module does. There is a pre-draft for an IETF standard. You could ask why Perl people don't care about joining the unittest 'standard'. I don't think it is fair: http://en.wikipedia.org/wiki/Test_Anything_Protocol#External_links (or http://testanything.org/wiki/index.php/TAP_Producers and http://testanything.org/wiki/index.php/TAP_Consumers) shows a lot of producers and consumers in various programming languages. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between random module in python 2.6 and 3.2?
On 6.2.2012 20:26, Tim Chase wrote: In an ideal world, the code wouldn't have broken backwards compat. However, given the conditions, if Matej is willing to forgo bug-fixes, it's a reasonable solution. The alternate might be to try moving the recent/fixed version into the old project and updating tests/data to work with it. I have some 2.4 production code in which I've pulled 2.6's zipfile module in to give access to the iterator access (rather than the .read() method which tries to read in umpteen gigs of data that I just want to spool out to a file on disk). Given I really don't care that much about distribution of my choice, this function def _choice(self, seq): """Choose a random element from a non-empty sequence. Embedding random.choice from 2.6 in order to get an uniform results between 2.6 and 3.2, where random module has been changed because of http://bugs.python.org/issue9025. See also http://groups.google.com/group/comp.lang.python\ /browse_thread/thread/2b000b8ca8c5e98e Raises IndexError if seq is empty """ return seq[int(random.random() * len(seq))] doesn't seem like something so terrible (and maintenance intense). :) Thanks for the help though Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and TAP
On 7.2.2012 04:24, alex23 wrote: Experience? Are you seriously advocating something for which you've done nothing more than watch a podcast? No, I am not. If you reread my original post, you may find that I was asking exactly for experience and explanation why something which seems to me obvious is not done. I guess there must be some hook somewhere, right? Which is what I was asking for. One hook I've got (YAMLish is really ... well, let's keep this group G rated), others may yet to follow. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: Python usage numbers
On 12.2.2012 03:23, Steven D'Aprano wrote: The use-case given is: "I have a file containing text. I can open it in an editor and see it's nearly all ASCII text, except for a few weird and bizarre characters like £ © ± or ö. In Python 2, I can read that file fine. In Python 3 I get an error. What should I do that requires no thought?" Obvious answers: - Try decoding with UTF8 or Latin1. Even if you don't get the right characters, you'll get *something*. - Use open(filename, encoding='ascii', errors='surrogateescape') (Or possibly errors='ignore'.) These are not good answer, IMHO. The only answer I can think of, really, is: - pack you luggage, your submarine waits on you to peel onions in it (with reference to the Joel's article). Meaning, really, you should learn your craft and pull up your head from the sand. There is a wider world around you. (and yes, I am a Czech, so I need at least latin-2 for my language). Best, Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: Python usage numbers
On 12.2.2012 09:14, Matej Cepl wrote: Obvious answers: - Try decoding with UTF8 or Latin1. Even if you don't get the right characters, you'll get *something*. - Use open(filename, encoding='ascii', errors='surrogateescape') (Or possibly errors='ignore'.) These are not good answer, IMHO. The only answer I can think of, really, is: Slightly less flameish answer to the question “What should I do, really?” is a tough one: all these suggested answers are bad because they don’t deal with the fact, that your input data are obviously broken. The rest is just pure GIGO … without fixing (and I mean, really, fixing, not ignoring the problem, which is what the previous answers suggest) your input, you’ll get garbage on output. And you should be thankful to py3k that it shown the issue to you. BTW, can you display the following line? Příliš žluťoučký kůň úpěl ďábelské ódy. Best, Matěj -- http://mail.python.org/mailman/listinfo/python-list
XSLT to Python script conversion?
Hi, I am getting more and more discouraged from using XSLT for a transformation from one XML scheme to another one. Does anybody could share any experience with porting moderately complicated XSLT stylesheet (https://gitorious.org/sword/czekms-csp_bible/blobs/master/CEP2OSIS.xsl) into a Python script using ElementTree's interparse or perhaps xml.sax? Any tools for this? Speed differences (currently I am using xsltproc)? Any thoughts? Thank you, Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: XSLT to Python script conversion?
On 15.2.2012 18:48, Tim Arnold wrote: Just a note to encourage you to stick with XSLT. I also use lxml for creating and postprocessing my DocBook documents and it is great. But I use the DocBook XSL stylesheets to convert to html; if you're like me, you got discouraged at the strangeness of the XSLT language. No, the strangness is not that bad (well, it is bad ... almost anything feels bad comparing to Python, to be honest, but not the reason I would give up; after all I spent couple of years with Javascript). The terrible debugging is one thing, and even worse, I just still cannot get over rules around spaces: whitespace just jumps at me randomly in random places and is erased in others. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: [semi OT]: Smartphones and Python?
On 16.2.2012 16:22, Michael Torrie wrote: Android simply isn't going to run the JVM anytime soon. In reality yes, but just technically speaking there is the project IcedRobot (http://www.icedrobot.org/), which is a fork of Android over OpenJDK. Best, Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT]: Smartphones and Python?
For one I don't know of any sun-compatible JVM that has been ported to ARM. http://www.senecass.com/projects/OpenJDK-ARM/ "This work has been completed, and is now in OpenJDK HEAD. This page is now mostly for historical documentation." Also, http://openjdk.java.net/projects/zero/ (I know my colleagues from Red Hat are involved, because we are very interested in supporting more than just Intel chips well). Best, Matěj -- http://mail.python.org/mailman/listinfo/python-list
ANN: yamlish 0.8 released
yamlish 0.8 is now available at http://pypi.python.org/pypi/yamlish yamlish is a module for generating (and parsing) YAMLish (http://testanything.org/wiki/index.php/YAMLish). Release notes: -- * Don't leak tempfiles * setup.py test actually runs tests * add requires to setup.py * generate compact multiline strings (don't add empty lines) Links: -- * homepage http://pypi.python.org/pypi/yamlish * code repository https://gitorious.org/yamlish/yamlish * bug reports and enhancement requests to mcepl_at_redhat_dot_com or to https://luther.ceplovi.cz/bugzilla/ (product TAP) -- http://mail.python.org/mailman/listinfo/python-list
ANN: bayeux 0.2 released
Bayeux 0.2 is now available at http://pypi.python.org/pypi/bayeux bayeux is a module for generating TAP (http://testanything.org/). Version 0.2 is an initial version registered in the Cheesshop. Release notes: -- * module tap.py for programatic writing of TAP stream * clone of unittest2 generating TAP stream instead of the normal unittest output. * example script for generating TAP stream from JSON results of piglit test suite. Links: -- * homepage http://pypi.python.org/pypi/bayeux * code repository https://gitorious.org/bayeux/bayeux * bug reports and enhancement requests to mcepl_at_redhat_dot_com or to https://luther.ceplovi.cz/bugzilla/ (product TAP) -- http://mail.python.org/mailman/listinfo/python-list
ANN: bayeux 0.2 released
Bayeux 0.2 is now available at http://pypi.python.org/pypi/bayeux bayeux is a module for generating TAP (http://testanything.org/). Version 0.2 is an initial version registered in the Cheesshop. Release notes: -- * module tap.py for programatic writing of TAP stream * clone of unittest2 generating TAP stream instead of the normal unittest output. * example script for generating TAP stream from JSON results of piglit test suite. Links: -- * homepage http://pypi.python.org/pypi/bayeux * code repository https://gitorious.org/bayeux/bayeux * bug reports and enhancement requests to mcepl_at_redhat_dot_com or to https://luther.ceplovi.cz/bugzilla/ (product TAP) -- http://mail.python.org/mailman/listinfo/python-list
Re: Whither paramiko?
On 15.4.2012 15:42, Bryan wrote: Paramiko is a Python library for SSH (Secure Shell). Over about the last year, I've grown dependent upon it. Its home page is still easy to search up, but the links to its mailing list and repository don't work. Paramiko depends on PyCrypto, and not so long ago that dependency was the stated reason why paramiko did not yet play with Python 3. Even more recently, PyCrypto has gone green on the Python 3 Wall of Shame. Well, if anybody ports paramiko to use some reasonable SSL bindings (i.e., m2crypto, python-nss) then I will buy him a cup of tea, coffee or other beverage of his choice ;). Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: ucs2 and ucs4 python
On 16.5.2012 10:36, zayatzz wrote: /opt/bin/python^M: bad interpreter: No such file or directory Your script has CRLF end-of-lines. Change it to plain Unix LF. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: usenet reading
On 03/06/12 13:59, Colin Higwell wrote: Google Groups is an abomination IMHO, and I find it much easier to read mailing lists via a newsreader. I highly recommend Pan, by the way. I am still surprised how good experience I have with reading news with Thunderbird. Yes, Pan is better, but it used to have some rough edges (e.g., it's offline qualities were a bit elusive), but of course generally it is quite more powerful as a NNTP reader. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: which one do you prefer? python with C# or java?
On 10/06/12 00:44, Yesterday Paid wrote: I'm planning to learn one more language with my python. Just my personal experience, but after passively learning many many languages, I came to the conclusion that I (and I suppose many others) am able to learn only one platform well. The point is that you are never interested in learning *a language*, everybody who has at least some touch with programming can learn most languages in one session in the afternoon. But nobody is interested in you knowing a language, you need to know the platform with all libraries, standards, style, and culture. And *that* demands you focus on one language completely. Yes, of course, you will know couple of other languages and be able to write a thing in it (everybody needs to know a bit of JavaScript these days, and if you are on Unix/Linux,Mac OS X, you need to know a bit of shell scripting), but that's different from "Zen & Writing" (that's my personal homage to recently deceased Ray Bradbury and his essay http://www.worldcat.org/search?qt=wikipedia&q=isbn%3A1877741094). The language in which you write those 100 lines of code per day (that's my rough estimate of an equivalent for Bradbury's daily portion of prose to be written) should be IMHO only the one. I think the similarity with story writing makes a lot of sense. Yes, many people speak and write more than one language (me included, English is not my first language), but that's not the same as writing stories professionally. At the moment, I can think only about one successful famous writer how changed his main language (Kundera), but I don't recall ATM any writer who would be writing in multiple languages at one time. (yes, switches between main programming languages is more possible, because programming languages are endlessly less complicated than natural ones) Just my 0.02CZK Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: which one do you prefer? python with C# or java?
On 10/06/12 18:32, Paul Rubin wrote: Really, that's only if the new language is pretty much the same as the old ones, in which case you haven't really learned much of anything. Languages that use interesting new concepts are challenges in their own right. Well, I could at least passively read many languages (starting with Pascal, C, and unsuccessful attempt to learn Prolog, so even statically typed languages are not that mysterious to me), so learning new ones is not that problem. And yes, to be completely honest, functional languages are my weakest part (although I have used Emacs for some time, I still haven't learned writing in any Lisp properly). Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: which one do you prefer? python with C# or java?
On 10/06/12 22:40, Paul Rubin wrote: You might start with Abelson and Sussman's classic book: http://mitpress.mit.edu/sicp I know that, and it lies on my badtable for some time already, but I just never got enough excited about the idea yet. Python is just much more fun. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: which one do you prefer? python with C# or java?
On 11/06/12 06:20, rusi wrote: Hi Matěj! If this question is politically incorrect please forgive me. Do you speak only one (natural) language -- English? And if this set is plural is your power of expression identical in each language? I have written about that later ... no, I am a native Czech, but I have passive Russian, and active English. But there is a difference ... I can read and enjoy beautiful texts in Russian or English (couple of months read Eugen Onegin in Russian and that's just a beauty! or C.S.Lewis ... oh my!) but I will never be able to write professionally in these languages. I can write (as evidenced by this message) somehow in English, but I cannot imagine that I would be ever professional art writer or (even worse) poet. I could imagine (if spent couple of thousands of days working on it) that I would be a Czech professional writer though. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: [newbie] Equivalent to PHP?
On 12/06/12 11:39, Gilles wrote: I notice that Python-based solutions are usually built as long-running processes with their own web server (or can run in the back with eg. Nginx and be reached through eg. FastCGI/WSGI ) while PHP is simply a language to write scripts and requires a web server (short running processes). I don't think it is a proper description of the situation (please, somebody correct my mistakes, I am not 100% sure about it myself). WSGI applications (which is basically all web applications in Python) could run in the hosted servers (using for example mod_wsgi for Apache), and I would expect that it is the situation with most production uses. From the programmer's point of view WSGI application (read http://en.wikipedia.org/wiki/Wsgi) is just one script which takes HTTP request on input and generates HTTP Response on output, so it is actually quite simple. And actually quite similar to what JSGI, PSGI, and Rake do (I am not sure who was first whether WSGI or Rake). anyway... why did Python solutions go for long-running processes while PHP was built from the start as short-running processes? It is all about caching ... I am not sure how it is done exactly, but I would expect for example mod_wsgi to cache parsed Python script in memory as well. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: Asynchronous processing is more efficient -- surely not?
On 2018-04-04, 07:27 GMT, Steven D'Aprano wrote: > I'm no expert, but it seems to me that this has surely got to > be crazy talk. Whatever task you're doing, processing it > asynchronously doesn't reduce the amount of work. For example, > if you want to download ten files, you still have to download > all ten files, and they're not any smaller or the network > connection any faster because you're using async. I agree that the formulation is unfortunate, but your argument seems to lie only on semantics. Anyway, this https://hackernoon.com/asynchronous-python-45df84b82434 seems to be a better explanation of cooperative green threads and eventually also asyncio. Best, Matěj -- https://matej.ceplovi.cz/blog/, Jabber: [email protected] GPG Finger: 3C76 A027 CA45 AD70 98B5 BC1D 7920 5802 880B C9D8 [...] sleep is no substitute for caffeine. -- Robert Storey in review of Debian (when describing re-compilation of kernel :-) pgpRacL75wPhc.pgp Description: PGP signature -- https://mail.python.org/mailman/listinfo/python-list
Seekable output from ClientForm?
Hi,
using python 2.3, ClientForm, and ClientCookie and I have this code:
opener = ClientCookie.build_opener(ClientCookie.HTTPRefererProcessor,
ClientCookie.HTTPRefreshProcessor,
ClientCookie.SeekableProcessor)
response = opener.open(lxURL)
forms = ClientForm.ParseResponse(response)
form = forms[0]
response.seek(0)
form['extpatid'] = MyNEUlogin
form['extpatpw'] = MyNEUpassword
formopener = form.click()
response2 = ClientCookie.urlopen(formopener)
guidednews = re.compile("s_guidednews.html")
response2.seek(0)
h = htmllib.HTMLParser(formatter.NullFormatter())
h.feed(response2.read())
print h.anchorlist
Unfortunately, it doesn't work, because response2 was created by
ClientForm and it is not seekable (apparently, I get "AttributeError:
addinfourl instance has no attribute 'seek'").
How to make output of ClientForm seekable, please?
Thanks a lot,
Matej
--
http://mail.python.org/mailman/listinfo/python-list
PyKDE inside vim-python
Hi,
did anybody tried %subj%? I have created really stupidly simple dialog-box
in Qt-designer (it is available on
<http://www.ceplovi.cz/matej/tmp/KDE-dialog.tar.gz>) and I would like to
run it from vim-script in kvim (soon to be obsoleted and replaced by
Gnome-vim; oh, well, I liked kvim). Of course I can do something like
:let cat = system("categorySet.py")
but I thought that running the script directly from vim (with Python
scripting enabled) could make this script faster. Can anybody help me,
whether it is possible to do something like this?
Thanks,
Matěj
--
Matej Cepl, http://www.ceplovi.cz/matej
GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC
138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488
Scouts are saving aluminum cans, bottles and other items to be
recycled. Proceeds will be used to cripple children.
-- from a church bulletin
--
http://mail.python.org/mailman/listinfo/python-list
[ANN] gg_scrapper -- scrapping of the Google Groups
Did you try to archive email list hosted on the Google Groups? Were you endlessly frustrated by the black hole which is Google Groups, conscpicious by its absence on the Data Liberation Front website? Yes, I was too_ So, I have created a script webscrapping a google group and created gg_scrapper_ . Thanks to `Sean Hogan`_ for the first inspiration for the script. Any comments would be welcome via email (I am sure you can find my addresses somewhere on the Web). Best, Matěj .. _too: http://matej.ceplovi.cz/blog/2013/09/we-should-stop-even-pretending-google-is-trying-to-do-the-right-thing/ .. _gg_scrapper: https://pypi.python.org/pypi/gg_scrapper .. _`Sean Hogan`: http://matej.ceplovi.cz/blog/2013/09/we-should-stop-even-pretending-google-is-trying-to-do-the-right-thing/#comment-482 -- http://www.ceplovi.cz/matej/, Jabber: mceplceplovi.cz GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC <"}}}>< pgpoyMd0BbZNw.pgp Description: PGP signature -- https://mail.python.org/mailman/listinfo/python-list
Is email.parser a good replacement for formail?
Hi, I have a script (https://github.com/mcepl/gg_scraper) where I need to read possibly malformed mbox messages. I use subprocess.Popen() and /usr/bin/formail to clean up them to be correct mbox messages (with correct leading From line etc.). Now I try to run tests for my script on Travis-CI, where I don't have installed formail. Actually, I learned now that I can run apt-get install procmail in .travis.yml. But still, I started to think whether I couldn’t fix my script to be purely Pythonic. I know that msg = email.message_from_string(original_msg) print(msg.as_string(unixfrom=True)) works as a poor-man’s replacement for `formail -d`. Now, I would like to know how reliable replacement it is. Does anybody have (or know about) a corpus of poorly formatted messages which can be fixed by formail to test upon it? Thanks a lot for any reply, Matěj -- http://www.ceplovi.cz/matej/, Jabber: [email protected] GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC Less is more or less more. -- Y_Plentyn on #LinuxGER (from fortunes -- I cannot resist :-) signature.asc Description: OpenPGP digital signature -- https://mail.python.org/mailman/listinfo/python-list
Re: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 2014-01-11, 08:07 GMT, you wrote: > Hi, I've just begun to learn programming, I have an open question for the > group: > Is the Python language an all in one computer language which could replace C, > C++, Java etc.. I only ask becuase I am starting off with python and I want > to learn everything in basic and advanced programming with python itself...So > any advice and suggestions would be more than welcome. - From one side this answer is probably as meaningful as the one from the Alice in Wonderland (http://www.gutenberg.org/files/19033/19033-h/19033-h.htm, page 35): “Why is a raven like a writing-desk?” These are just different programming languages each designed for different purpose. On the other hand what people said about Turing complete langauges is true as well. So, yes it is true that any Turing complete language you can write anything you wrote in another Turing complete language. It doesn’t mean however that it would be as easy or as efficient tool for doing so. Some languages are specialized for high-power low-level specialist programming of low-level stuff (e.g., almost all serious operating systems are written in C), some are better suited for writing enormous complicated projects consisting of thousands of modules (Java, C++, Ada), some are designed to be very easy to write (that doesn’t mean primitive) although the speed and processing power of the result may suffer a little bit (JavaScript, Python, Perl, Ruby). If you ask for the language to start to learn programming as such, then Python was oriiginally intended exactly for that purpose (fortunately, it was written so well, it is now used en masse for “serious” large programming projects as well). FOr the list of resources take a look at https://wiki.python.org/moin/BeginnersGuide/NonProgrammers . Particularly, I’ve heard a lot of good things about “How to Think Like a Computer Scientist”. You won’t hurt yourself if you start there. Best, Matěj -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.22 (GNU/Linux) iD8DBQFS0fGP4J/vJdlkhKwRAu6TAKCCdGP9b3z2M+NJlIY4HnqZFi+v3gCfYgE0 69QHLyfyG//dFhb9pcjdoNk= =y2k/ -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: How to write this as a list comprehension?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 2014-01-17, 23:19 GMT, you wrote: > But defining the auxfunc takes away the elegance of a list > comprehension. Au contraire! Remember, that brevity is the sister of talent. I would definitively vote for labels = [make_label(then, name) for then, name in mylist] (always use descriptive names of functions and variables; auxfunc is a short way to the hell) Beauty of the list comprehensions is that they show nicely what list is being processed, how it is filtered (if at all), and what we do with each element of the generated list. Anything you add to this simplicity is wrong. Whenever you start to feel you are missing some methods how to stuff more commands into a comprehension (or for example multiple embedded ones), you should start new function. The same rule applies here as with any other lambda function (because these are in fact lambda functions): the best way how to write lambda is to write algorithm somewhere on the side, describe what this function does in one word, then add `def` in front of that name, and use so created named function instead. Best, Matěj -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.22 (GNU/Linux) iD8DBQFS2l4X4J/vJdlkhKwRAjEgAJ4n1OuANYlVFzlgBZ0f1uMhO/t36gCfdFjE VmYDJ+F7aN0khzvlY50i0iA= =Trcc -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 2014-01-24, 11:18 GMT, you wrote: > Write your rendering engine as a few simple helper functions, > and then put all the rest in as code instead of XML. The > easiest way to go about it is to write three forms, from > scratch, and then look at the common parts and figure out > which bits can go into helper functions. Perhaps what's missing is full acknowledgment that Python has dual-inheritance and thus it can have mixin classes (which seems to me to be the only useful use of dual inheritance). You know you can have mixins in Python, right? Also, I wrote my share of XML parsing/writing code, but more and more I am persuaded that if the answer is “XML” then there is some wrong with the question. Python is a way more expressive language than XML, so it is almost always more useful to write in Python, than to pass any problems to XML. Matěj -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.22 (GNU/Linux) iD8DBQFS4pS54J/vJdlkhKwRApdcAJ48PRgDz6ccnq1YFD9zx8EDDH3JjgCghU2x 3CV+D0LvquzgYRux2GslZ0E= =Y3/F -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
[This message has also been posted to gmane.comp.python.general.] -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 2014-01-25, 07:18 GMT, Frank Millman wrote: > I have stated that my objective is to express as little as > possible in Python code. Yes, and I believe that it is very wrong. But anyway, if you are so passionate about GUI-via-XML, what’s wrong with Glade (http://www.pygtk.org/pygtk2reference/class-gladexml.html)? You have editors for that XML etc. Matěj -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.22 (GNU/Linux) iD8DBQFS457O4J/vJdlkhKwRAlA7AJ9nTl4v+FoiNZb3NLaSsIZMd2HO5wCeNYwe EVLDNqlw3YaQtloF1RGWP8Y= =AloI -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
urllib2: correct way how to add a header to the *initial* request?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, this is probably a dumb question but I just cannot find a way how to create AuthHandler which would add Authorization header to the FIRST request. The only thing I see in urllib2.py are various http_error handler which add Authorization header to the ADDITIONAL request which handles the error. However, when looking at http://www.ietf.org/rfc/rfc2617.txt, section 2, I see this: A client MAY preemptively send the corresponding Authorization header with requests for resources in that space without receipt of another challenge from the server. And really many servers (e.g., api.github.com) expect the Authorization header to be sent with the initial request, and actually they broken (http://developer.github.com/v3/auth/#basic-authentication) so instead of 401 they send 404 status code. Anybody has any idea how to subclass *AuthHandler so that it would add the header on the initial request? Best, Matěj -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.22 (GNU/Linux) iD8DBQFS9kui4J/vJdlkhKwRAqH1AJ9884WT6pjdu/U54khpHUUVWRcFkgCdEQn9 TNtb2lcc4Nrf1zmftn5u8Zg= =4R/2 -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
urllib2: correct way how to add a header to the *initial* request?
Hi, this is probably a dumb question but I just cannot find a way how to create AuthHandler which would add Authorization header to the FIRST request. The only thing I see in urllib2.py are various http_error handler which add Authorization header to the ADDITIONAL request which handles the error. However, when looking at http://www.ietf.org/rfc/rfc2617.txt, section 2, I see this: A client MAY preemptively send the corresponding Authorization header with requests for resources in that space without receipt of another challenge from the server. And really many servers (e.g., api.github.com) expect the Authorization header to be sent with the initial request, and actually they broken (http://developer.github.com/v3/auth/#basic-authentication) so instead of 401 they send 404 status code. Anybody has any idea how to subclass *AuthHandler so that it would add the header on the initial request? Best, Matěj pgphzgMT4PY0G.pgp Description: PGP signature -- https://mail.python.org/mailman/listinfo/python-list
BDD behave support for vim
Hi, I know that vim has native support for cucumber (the original BDD framework for Ruby). I have also found https://github.com/veloce/vim-behat for BDD with PHP (frightening idea!), but I haven't found a module supporting BDD with vim and Python. Especially I envy to our Ruby friends ability to jump from the particular line in the .feature file to the definition of step in the appropriate Ruby file. Does anybody know about any project which would do the same with behave what vim does for Ruby? Thank you, Matěj -- https://mail.python.org/mailman/listinfo/python-list
Re: help
On Oct 8, 2:51 pm, X1 wrote: easy_install does not exist on Fedora. That's a pure lie. mitmanek:~ $ sudo repoquery -qf /usr/bin/easy_install python-setuptools-0:0.6.10-3.el6.noarch mitmanek:~ $ Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: help
Dne 22.10.2011 17:02, Steven D'Aprano napsal(a): Rather than assume malice, we should give X1 the benefit of the doubt and assume he genuinely believed what he wrote but was merely mistaken. Sure, I didn't want to assume malice (sorry, English is my second language and sometimes it shows; would "libel" or "slander" fit the bill better?). I just wanted to slip in the information about repoquery which is an awesome tool, but not many people know about it. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: Presenting recursive dict (json_diff)
Dne 27.10.2011 21:49, Terry Reedy napsal(a): Use '_append', etc, much like namedtuple does, for the same reason. Right, done. What about the presentation issue? Any ideas? Best, Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: How to undo a Python setuptools --prefix path blunder
Dne 6.11.2011 14:18, Kev napsal(a): Again the wrong path is being used to create the symbolic link to where virtualenv is installed: http://packages.python.org/distribute/easy_install.html#administrator-installation for list of additional configuration files which might go wrong (namely *.pth and distutils.cfg). Is that it? Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: getting command line in python
Dne 8.11.2011 23:36, MrSmile napsal(a): Thank you all, that was it that I was searching for you. Except that most likely it wasn't the right answer. Take a look at http://docs.python.org/library/argparse.html (or optparse, if you are on Python < 2.7). Best, Matěj -- http://mail.python.org/mailman/listinfo/python-list
Multilevel dicts/arrays v. tuples as keys? [Was: Re: Get keys from a dicionary]
Dne 11.11.2011 14:31, macm napsal(a): def Dicty( dict[k1][k2] ): When looking at this I returned to the question which currently rolls in my mind: What's difference/advantage-disadvantage betweeng doing multi-level dicts/arrays like this and using tuple as a key? I.e., is it more Pythonic to have dict[k1,k2] instead? Best, Matěj -- http://mail.python.org/mailman/listinfo/python-list
[ANN] json_diff 0.9.2 released - JSON files comparator
I released json_diff 0.9.2.
http://pypi.python.org/pypi/json_diff
json_diff is an utility comparing two JSON files and generating diff in
form of another JSON file with differences for each level of the object
in a dict
{
"_append": {},
"_remove": {},
"_update": {}
}
This is the first public release, working my way towards 1.0 release.
Development repository is at https://gitorious.org/json_diff, patches
and pull requests welcome!
--
http://www.ceplovi.cz/matej/, Jabber: mceplceplovi.cz
GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC
Basically, the only “intuitive” interface is the nipple. After
that, it's all learned.
-- Bruce Ediger when discussing intuivity of Mac OS
http://groups.google.com/group/comp.sys.next.advocacy\
/msg/7fa8c580900353d0
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python Newbie
On 2013-02-23, 15:51 GMT, Chris Angelico wrote: > When you learn your first language, you think you're learning to > program, but that's not really accurate. Once you've learned half a > dozen, you begin to understand something of the art of coding as > distinct from any particular language; after that, you can learn any > language fairly easily. And then you find out that to be REALLY good in one language, you have to focus on one language, because otherwise you are writing in some kind of mishmash. The point is that you don’t need to know any language but to at home in the whole universe of libraries, idioms, patterns, etc. and if you can manage to be REALLY at home in more than one (or let’s say two) universes, you are better than most (professional programmers) I know. Shakespeare wasn’t good in writing German poetry, as far as I know. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: webbrowser.open("./documentation/help.html")-- No Go in Windows
On 2013-02-25, 03:37 GMT, llanitedave wrote: > url_link = "file:///" + fullpath Isn't this too many slashes. On Linux I get URI file:usr/share/doc/whatever.html which is just too many slashes (it should be three, two for the protocol, one for the root directory). Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Newbie
On 2013-02-23, 18:44 GMT, jmfauth wrote: > Very easy to explain: wrong, incorrect, naive unicode > handling. PLONK! -- http://mail.python.org/mailman/listinfo/python-list
Re: Small program ideas
On 2013-02-26, 03:48 GMT, eli m wrote: > On Friday, February 15, 2013 7:22:41 PM UTC-8, eli m wrote: >> Any small program ideas? I would prefer to stick to command line >> ones. Thanks. > > Thank you guys for the suggestions. Any more? 1) Clone git repository from https://github.com/mcepl/html2text 2) Switch to fix_tests branch 3) Fix all tests running the testsuite with python3.3 You will help a good thing, contribute to the Aaron Swartz memory (yes, *that* Aaron Swartz is the original author of the module), and learn about python more than by any silly simple demos (hint: pdb is your friend). It is not difficult, just time consuming. Best, Matěj -- http://mail.python.org/mailman/listinfo/python-list
Difference in RE between 3.2 and 3.3 (or Aaron Swartz memorial)
Hi, as my method to commemorate Aaron Swartz, I have decided to port his html2text to work fully with the latest python 3.3. After some time dealing with various bugs, I have now in my repo https://github.com/mcepl/html2text (branch python3) working solution which works all the way to python 3.2 (inclusive; https://travis-ci.org/mcepl/html2text). However, the last problem remains. This Run this command: ls -l *.html ? should lead to * Run this command: ls -l *.html * ? but it doesn’t. It leads to this (with python 3.3 only) * Run this command: ls -l *.html * ? Does anybody know about something which changed in modules re or html.parser between 3.2 and 3.3, which could influence this script? Thanks, Matěj Cepl -- http://mail.python.org/mailman/listinfo/python-list
Re: IMAP4_SSL and OpenSSL compatibility
On 2013-02-26, 16:57 GMT, W. Martin Borgert wrote: > 1. Is there any plan to backport this Python >= 3.3 feature to > Python 2? No, development of Python 2 ceased to exist (only important bugfixes or security fix will happen, IIRC) If you need advanced use of SSL, use pyOpenSSL (it has been ported to Python 3 already, so you won't loose any compatibility). Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: Difference in RE between 3.2 and 3.3 (or Aaron Swartz memorial)
On 2013-02-26, 16:25 GMT, Terry Reedy wrote: > On 2/21/2013 4:22 PM, Matej Cepl wrote: >> as my method to commemorate Aaron Swartz, I have decided to port his >> html2text to work fully with the latest python 3.3. After some time >> dealing with various bugs, I have now in my repo >> https://github.com/mcepl/html2text (branch python3) working solution >> which works all the way to python 3.2 (inclusive; >> https://travis-ci.org/mcepl/html2text). However, the last problem >> remains. This >> >> Run this command: >> ls -l *.html >> ? >> >> should lead to >> >>* Run this command: >> >> ls -l *.html >> >>* ? >> >> but it doesn’t. It leads to this (with python 3.3 only) >> >> * Run this command: >>ls -l *.html >> >> * ? >> >> Does anybody know about something which changed in modules re or >> http://docs.python.org/3.3/whatsnew/changelog.html between 3.2 and >> 3.3, which could influence this script? > > Search the changelob or 3.3 misc/News for items affecting those two > modules. There are at least 4. > http://docs.python.org/3.3/whatsnew/changelog.html > > It is faintly possible that the switch from narrow/wide builds to > unified builds somehow affected that. Have you tested with 2.7/3.2 on > both narrow and wide unicode builds? So, in the end, I have went the long way and bisected cpython to find the commit which broke my tests, and it seems that the culprit is http://hg.python.org/cpython/rev/123f2dc08b3e so it is clearly something Unicode related. Unfortunately, it really doesn't tell me what exactly is broken (is it a known regression) and if there is known workaround. Could anybody suggest a way how to find bugs on http://bugs.python.org related to some particular commit (plain search for 123f2dc0 didn’t find anything). Any thoughts? Matěj P.S.: Crossposting to python-devel in hope there would be somebody understanding more about that particular commit. For that I have also intentionally not trim the original messages to preserve context. -- http://mail.python.org/mailman/listinfo/python-list
unsynchronized text streams in OGG (lyrics)
Hi, I heard somewhere that OGG container format is capable of storing arbitrary long text streams inside OGG container. I would love to use it for storing lyrics inside the .ogg files. Is it true? Could anybody provide more information how to do it? Is there any Python code for doing this? Thanks, Matej Cepl -- http://mail.python.org/mailman/listinfo/python-list
email modul with writing to mboxes (and locking) for python 2.4.*?
Is there somewhere support for the extension of email module, which would support writing to (and creating new) mbox folders (with all bells and whistles, like locking)? It seems to me that current (Python 2.4.*, I even tried email package 4.0.2 from python.org email SIG) implementation is read-only, am I right? Thanks for any reply, Matej Cepl -- http://mail.python.org/mailman/listinfo/python-list
Re: email modul with writing to mboxes (and locking) for python 2.4.*?
On 2007-05-25, 18:28 GMT, John J. Lee wrote: > Not sure whether you know this already, but module mailbox in > Python 2.5 supports writing mbox folders. If it's not 2.4 > compatible, it's fairly likely to be an easy backport. Cool! Thanks a lot. One more reason why to upgrade to Fedora Core 7 as soon as it is available, I suppose. Thanks again, Matej -- http://mail.python.org/mailman/listinfo/python-list
sqlite3 adaptors mystery
Hi,
I am in the process of creating a small script for filling the
sqlite3 database with data from rather large XML-RPC query (list
of many bugs from the Red Hat Bugzilla) and I would love to use
adaptors and converters for some data types which I am missing.
I have this test script (made hopefully pretty faithfully from the
documentation):
#!/usr/bin/python
import sqlite3
def adapt_boolean(bol):
if bol:
return "True"
else:
return "False"
def convert_boolean(bolStr):
if str(bolStr) == "True":
return bool(True)
elif str(bolStr) == "False":
return bool(False)
else:
raise ValueError, "Unknown value of bool attribute '%s'" \
% bolStr
sqlite3.register_adapter(bool,adapt_boolean)
sqlite3.register_converter("boolean",convert_boolean)
db = sqlite3.connect("test.db")
cur=db.cursor()
cur.execute("create table test(p boolean)")
p=False
cur.execute("insert into test(p) values (?)", (p,))
p=True
cur.execute("insert into test(p) values (?)", (p,))
cur.execute("select p from test")
print cur.fetchall()
And I would expect to print on output representation of bool values, i.e.,
something like
[False,True]
However, when running this program it seems converter doesn’t seem to work,
because I get:
[EMAIL PROTECTED] dumpBugzilla]$ rm test.db ; python testAdaptors.py
[(u'False',), (u'True',)]
[EMAIL PROTECTED] dumpBugzilla]$
There is probably something quite obvious what I do incorrectly, but I just
don't see it. Could somebody kick me in the right direction, please?
Thanks a lot,
Matěj Cepl
--
http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 adaptors mystery
On 2008-03-01, 23:41 GMT, Mel wrote:
> There's nothing much wrong. cur.fetchall is returning a list
> of all the selected rows, and each row is a tuple of fields.
> Each tuple is being converted for display by repr, so the
> strings are shown as unicode, which is what they are
> internally. Change the print to
>
> for (field,) in cur.fetchall():
> print field
>
> and you'll see your plain-text strings.
Thanks for your help, but plain-text strings is not what
I wanted. The boolean variables was what I was after. See this
modified version of the script:
#!/usr/bin/python
import sqlite3
def adapt_boolean(bol):
if bol:
return "True"
else:
return "False"
def convert_boolean(bolStr):
if str(bolStr) == "True":
return bool(True)
elif str(bolStr) == "False":
return bool(False)
else:
raise ValueError, "Unknown value of bool attribute
'%s'" % bolStr
sqlite3.register_adapter(bool,adapt_boolean)
sqlite3.register_converter("boolean",convert_boolean)
db = sqlite3.connect(":memory:")
cur=db.cursor()
cur.execute("create table test(p boolean)")
p=False
cur.execute("insert into test(p) values (?)", (p,))
p=True
cur.execute("insert into test(p) values (?)", (p,))
cur.execute("select p from test")
for (field,) in cur.fetchall():
print field,type(field)
The output here is:
[EMAIL PROTECTED] dumpBugzilla]$ python testAdaptors.py False
True
[EMAIL PROTECTED] dumpBugzilla]$
I thought that converter is there for just exactly this -- that
I would get back bool values not strings.
Sorry for not being clear in the first run.
Matej
--
http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 adaptors mystery
On 2008-03-02, 08:16 GMT, Matej Cepl wrote: > Thanks for your help, but plain-text strings is not what > I wanted. The boolean variables was what I was after. See this > modified version of the script: OK, I got it -- I was missing detect_types parameter of the connect method. Matěj -- http://mail.python.org/mailman/listinfo/python-list
Re: Edit MP4 and/or WMV file metadata?
On 2008-03-04, 18:53 GMT, allen.fowler wrote: > 1) Is there a python module I can use to edit the metadata in > MP4 > files? I am not sure whether taglib supports MP4, but take a look at http://developer.kde.org/~wheeler/taglib.html and http://developer.berlios.de/project/showfiles.php?group_id=2066 or http://news.tiker.net/software/tagpy > 2) Failing that, is there a python module I can use to edit the > metadata in the WMV files, and hope the data makes it through the > conversion? You may also be able to do something with gst-launch (on Linux). Matěj -- http://mail.python.org/mailman/listinfo/python-list
textwrap.fill algorithm? (Difference with vim)
Hi, I have a gedit Python plugin which should do line wrap using textwrap.fill() function. However, even when I have set the length of line to the same number as in vim (65), the result is substantially different (textwrap.fill paragraphs are significantly narrower). See for example this diff (removed lines are wrapped by vim, added by textwrap.fill-based plugin). Why cannot textwrap.fill get those words “grown so” to the first line of the wrapped text? Any ideas about the difference in the algorithms for line-wrapping in vim and in textwrapper.fill? Thank you for any suggestions, Matěj Cepl ~$ git diff -- mind.rst diff --git a/mind.rst b/mind.rst index a9523c2..e55c56b 100644 --- a/mind.rst +++ b/mind.rst @@ -63,16 +63,18 @@ personal religious belief. It is a commentary, in the light of specialised knowledge, on a particular set of statements made in the Christian creeds and their claim to be statements of fact. -It is necessary to issue this caution, for the popular mind has grown so -confused that it is no longer able to receive any statement of fact -except as an expression of personal feeling. Some time ago, the present -writer, pardonably irritated by a very prevalent ignorance concerning -the essentials of Christian doctrine, published a brief article in which -those essentials were plainly set down in words that a child could -understand. Every clause was preceded by some such phrase as: “the -Church maintains”, “the Church teaches”, “if the Church is right”, and -so forth. The only personal opinion expressed was that, though the -doctrine might be false, it could not very well be called dull. +It is necessary to issue this caution, for the popular mind has +grown so confused that it is no longer able to receive any +statement of fact except as an expression of personal feeling. +Some time ago, the present writer, pardonably irritated by a very +prevalent ignorance concerning the essentials of Christian +doctrine, published a brief article in which those essentials +were plainly set down in words that a child could understand. +Every clause was preceded by some such phrase as: “the Church +maintains”, “the Church teaches”, “if the Church is +right”, and so forth. The only personal opinion expressed was +that, though the doctrine might be false, it could not very well +be called dull. Every newspaper that reviewed this article accepted it without question as a profession of faith-some (Heaven knows why) called it “a courageous ~$ -- https://mail.python.org/mailman/listinfo/python-list
Re: textwrap.fill algorithm? (Difference with vim)
On 2017-04-21, 21:54 GMT, Peter Otten wrote: > It's not the algorithm, it's the width. Try > textwrap.fill(text, 72). I don’t understand. Why 72? I have set tw=65 in vim. Matěj -- https://matej.ceplovi.cz/blog/, Jabber: [email protected] GPG Finger: 3C76 A027 CA45 AD70 98B5 BC1D 7920 5802 880B C9D8 Of course I'm respectable. I'm old. Politicians, ugly buildings, and whores all get respectable if they last long enough. --John Huston in "Chinatown." -- https://mail.python.org/mailman/listinfo/python-list
Re: textwrap.fill algorithm? (Difference with vim)
On 2017-04-22, 01:01 GMT, Gregory Ewing wrote: > I don't know what vim is doing, but if you tell Python you > want lines no longer than 65 characters, it takes you at > your word. Oh, I’ve got it. textwrap.fill() (only in Python 2.*?) completely sucks with bytes, because of course it counts every byte as separate character for purpose of counting. All the text must be converted into unicode. It would be probably nice, if the textwrap documentation mentioned it. Best, Matěj -- https://matej.ceplovi.cz/blog/, Jabber: [email protected] GPG Finger: 3C76 A027 CA45 AD70 98B5 BC1D 7920 5802 880B C9D8 Of course I'm respectable. I'm old. Politicians, ugly buildings, and whores all get respectable if they last long enough. --John Huston in "Chinatown." -- https://mail.python.org/mailman/listinfo/python-list
Re: textwrap.fill algorithm? (Difference with vim)
On 2017-04-22, 18:33 GMT, Peter Otten wrote: > Yes, the documentation should warn about the limitations of > textwrap's notion of width -- but still, the line you > complained about Perhaps, I have screwed up somewhere, but I am glad we were able to figure it out. Thank you for your patience, Matěj -- https://matej.ceplovi.cz/blog/, Jabber: [email protected] GPG Finger: 3C76 A027 CA45 AD70 98B5 BC1D 7920 5802 880B C9D8 Of course I'm respectable. I'm old. Politicians, ugly buildings, and whores all get respectable if they last long enough. --John Huston in "Chinatown." -- https://mail.python.org/mailman/listinfo/python-list
