title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Is there a HAML implementation for use with Python and Django | 519,671 | <p>I happened to stumble across <a href="http://haml-lang.com/">HAML</a>, an interesting and beautiful way to mark up contents and write templates for HTML.</p>
<p>Since I use Python and Django for my web developing need, I would like to see if there is a Python implementation of HAML (or some similar concepts -- need... | 68 | 2009-02-06T09:30:01Z | 3,497,256 | <p>I just made this <a href="http://github.com/fitoria/django-haml" rel="nofollow">http://github.com/fitoria/django-haml</a> it's still in very early stage but it works.</p>
| 2 | 2010-08-16T20:55:55Z | [
"python",
"django",
"django-templates",
"haml"
] |
Is there a HAML implementation for use with Python and Django | 519,671 | <p>I happened to stumble across <a href="http://haml-lang.com/">HAML</a>, an interesting and beautiful way to mark up contents and write templates for HTML.</p>
<p>Since I use Python and Django for my web developing need, I would like to see if there is a Python implementation of HAML (or some similar concepts -- need... | 68 | 2009-02-06T09:30:01Z | 5,171,915 | <p>Daniel Skinner's project (mentioned above) seems to have been renamed to DMSL. It seems very powerful, emulates HAML but allows you to use python functions, lambdas, comprehensions etc in it's syntax: <a href="https://github.com/dasacc22/dmsl" rel="nofollow">https://github.com/dasacc22/dmsl</a></p>
| 2 | 2011-03-02T18:46:17Z | [
"python",
"django",
"django-templates",
"haml"
] |
Is there a HAML implementation for use with Python and Django | 519,671 | <p>I happened to stumble across <a href="http://haml-lang.com/">HAML</a>, an interesting and beautiful way to mark up contents and write templates for HTML.</p>
<p>Since I use Python and Django for my web developing need, I would like to see if there is a Python implementation of HAML (or some similar concepts -- need... | 68 | 2009-02-06T09:30:01Z | 10,713,234 | <p>My project, <a href="https://github.com/mikeboers/PyHAML" rel="nofollow">PyHAML</a>, is a Mako preprocessor that gives you very HAML-like syntax. Some of the Ruby doesn't translate very well to Python, so there are some differences, but the spirit is the same.</p>
| 3 | 2012-05-23T03:57:01Z | [
"python",
"django",
"django-templates",
"haml"
] |
Is there a HAML implementation for use with Python and Django | 519,671 | <p>I happened to stumble across <a href="http://haml-lang.com/">HAML</a>, an interesting and beautiful way to mark up contents and write templates for HTML.</p>
<p>Since I use Python and Django for my web developing need, I would like to see if there is a Python implementation of HAML (or some similar concepts -- need... | 68 | 2009-02-06T09:30:01Z | 16,259,000 | <p>I ran across jade doing some node.js work and when returning to Django was looking for something similar. I found <a href="https://github.com/SyrusAkbary/pyjade" rel="nofollow" title="PyJade">Pyjade</a> and while it's nearly exactly what I'm looking for it handles errors and debugging rather poorly within Django.</p... | 3 | 2013-04-28T02:41:06Z | [
"python",
"django",
"django-templates",
"haml"
] |
Is there a HAML implementation for use with Python and Django | 519,671 | <p>I happened to stumble across <a href="http://haml-lang.com/">HAML</a>, an interesting and beautiful way to mark up contents and write templates for HTML.</p>
<p>Since I use Python and Django for my web developing need, I would like to see if there is a Python implementation of HAML (or some similar concepts -- need... | 68 | 2009-02-06T09:30:01Z | 17,970,159 | <p>You may be interested in <a href="https://github.com/2nd/Plim">Plim</a>. It's a mature python port of <a href="http://slim-lang.com/">Slim</a>.</p>
| 5 | 2013-07-31T12:16:42Z | [
"python",
"django",
"django-templates",
"haml"
] |
Good Sound processing/Analysis/Capturing Modules | 519,851 | <p>We are working on Sound processing and Analysis where we need to extract frequencies, pitches, octaves and other parameters of sound including dBPowerSpectrum Analysis. </p>
<p>We also need to do this irrespective of the file formats or do the conversion between quite a file format(though conversion is not a very c... | 1 | 2009-02-06T10:48:24Z | 519,908 | <p>See <a href="http://www.csounds.com/node/188" rel="nofollow">http://www.csounds.com/node/188</a> for a package that does much of this.</p>
| 2 | 2009-02-06T11:09:36Z | [
"python",
"audio",
"music"
] |
Good Sound processing/Analysis/Capturing Modules | 519,851 | <p>We are working on Sound processing and Analysis where we need to extract frequencies, pitches, octaves and other parameters of sound including dBPowerSpectrum Analysis. </p>
<p>We also need to do this irrespective of the file formats or do the conversion between quite a file format(though conversion is not a very c... | 1 | 2009-02-06T10:48:24Z | 1,390,270 | <p>You can use <a href="http://cournape.github.com/audiolab/" rel="nofollow">scikits audiolab</a> to read in any file supported by <a href="http://www.mega-nerd.com/libsndfile/" rel="nofollow">libsndfile</a>, and then use <a href="http://www.scipy.org/PyLab" rel="nofollow">PyLab</a> (<a href="http://www.scipy.org/" rel... | 1 | 2009-09-07T17:20:31Z | [
"python",
"audio",
"music"
] |
Good Sound processing/Analysis/Capturing Modules | 519,851 | <p>We are working on Sound processing and Analysis where we need to extract frequencies, pitches, octaves and other parameters of sound including dBPowerSpectrum Analysis. </p>
<p>We also need to do this irrespective of the file formats or do the conversion between quite a file format(though conversion is not a very c... | 1 | 2009-02-06T10:48:24Z | 2,463,496 | <p>For audio capture and playback I've liked <a href="http://people.csail.mit.edu/hubert/pyaudio/" rel="nofollow">PyAudio</a>. It's cross-platform and pretty easy to use.</p>
| 2 | 2010-03-17T15:22:02Z | [
"python",
"audio",
"music"
] |
Cross-platform gui toolkit for deploying Python applications | 520,015 | <p>Building on:
<a href="http://www.reddit.com/r/Python/comments/7v5ra/whats_your_favorite_gui_toolkit_and_why/">http://www.reddit.com/r/Python/comments/7v5ra/whats_your_favorite_gui_toolkit_and_why/</a></p>
<h1>Merits:</h1>
<p>1 - ease of design / integration - learning curve</p>
<p>2 - support / availability for *... | 45 | 2009-02-06T11:43:30Z | 520,055 | <p>Please don't hesitate to expand this answer.</p>
<h1><a href="http://wiki.python.org/moin/TkInter">Tkinter</a></h1>
<p>Tkinter is the toolkit that comes with python. That means you already have everything you need to write a GUI. What that also means is that if you choose to distribute your program, most likely ev... | 42 | 2009-02-06T12:06:10Z | [
"python",
"user-interface",
"cross-platform"
] |
Cross-platform gui toolkit for deploying Python applications | 520,015 | <p>Building on:
<a href="http://www.reddit.com/r/Python/comments/7v5ra/whats_your_favorite_gui_toolkit_and_why/">http://www.reddit.com/r/Python/comments/7v5ra/whats_your_favorite_gui_toolkit_and_why/</a></p>
<h1>Merits:</h1>
<p>1 - ease of design / integration - learning curve</p>
<p>2 - support / availability for *... | 45 | 2009-02-06T11:43:30Z | 520,961 | <p>Pro wxPython</p>
<ul>
<li>Lots of tutorials</li>
<li>wxGlade as an Editor: not perfect yet, but usable.</li>
</ul>
| 0 | 2009-02-06T16:21:04Z | [
"python",
"user-interface",
"cross-platform"
] |
Cross-platform gui toolkit for deploying Python applications | 520,015 | <p>Building on:
<a href="http://www.reddit.com/r/Python/comments/7v5ra/whats_your_favorite_gui_toolkit_and_why/">http://www.reddit.com/r/Python/comments/7v5ra/whats_your_favorite_gui_toolkit_and_why/</a></p>
<h1>Merits:</h1>
<p>1 - ease of design / integration - learning curve</p>
<p>2 - support / availability for *... | 45 | 2009-02-06T11:43:30Z | 694,187 | <p>I would definitely appreciate it if anyone knows of something better than what's commonly discussed; I see to have headaches finding something appropriate...</p>
<p>Qt is great, but PyQt doesn't seem to have the same development resources. It seems to have some clever way to generate bindings, but isn't complete (e... | 5 | 2009-03-29T06:03:47Z | [
"python",
"user-interface",
"cross-platform"
] |
Cross-platform gui toolkit for deploying Python applications | 520,015 | <p>Building on:
<a href="http://www.reddit.com/r/Python/comments/7v5ra/whats_your_favorite_gui_toolkit_and_why/">http://www.reddit.com/r/Python/comments/7v5ra/whats_your_favorite_gui_toolkit_and_why/</a></p>
<h1>Merits:</h1>
<p>1 - ease of design / integration - learning curve</p>
<p>2 - support / availability for *... | 45 | 2009-02-06T11:43:30Z | 881,659 | <p><a href="http://www.jython.org/Project/" rel="nofollow">Jython</a>.</p>
<blockquote>
<p>Jython is an implementation of the
high-level, dynamic, object-oriented
language Python written in 100% Pure
Java, and seamlessly integrated with
the Java platform. It thus allows you
to run Python on any Java platfo... | 5 | 2009-05-19T08:55:42Z | [
"python",
"user-interface",
"cross-platform"
] |
Cross-platform gui toolkit for deploying Python applications | 520,015 | <p>Building on:
<a href="http://www.reddit.com/r/Python/comments/7v5ra/whats_your_favorite_gui_toolkit_and_why/">http://www.reddit.com/r/Python/comments/7v5ra/whats_your_favorite_gui_toolkit_and_why/</a></p>
<h1>Merits:</h1>
<p>1 - ease of design / integration - learning curve</p>
<p>2 - support / availability for *... | 45 | 2009-02-06T11:43:30Z | 881,684 | <p>I'm just weighing in to say that TKinter sucks. It sadly seems that it is packed with Python because of backwards compatibility. </p>
<p>The documentation is horrible. It looks horrible. I have run into some bizarre bugs that will actually crash Python.</p>
| 4 | 2009-05-19T09:01:32Z | [
"python",
"user-interface",
"cross-platform"
] |
What's the cleanest way to extract URLs from a string using Python? | 520,031 | <p>Although I know I could use some hugeass regex such as the one posted <a href="http://geekswithblogs.net/casualjim/archive/2005/12/01/61722.aspx">here</a> I'm wondering if there is some tweaky as hell way to do this either with a standard module or perhaps some third-party add-on?</p>
<p>Simple question, but nothin... | 18 | 2009-02-06T11:51:57Z | 520,036 | <p>Use a regular expression.</p>
<p>Reply to comment from the OP: I know this is not helpful. I am telling you the correct way to solve the problem as you stated it is to use a regular expression.</p>
| 8 | 2009-02-06T11:54:44Z | [
"python",
"regex",
"url"
] |
What's the cleanest way to extract URLs from a string using Python? | 520,031 | <p>Although I know I could use some hugeass regex such as the one posted <a href="http://geekswithblogs.net/casualjim/archive/2005/12/01/61722.aspx">here</a> I'm wondering if there is some tweaky as hell way to do this either with a standard module or perhaps some third-party add-on?</p>
<p>Simple question, but nothin... | 18 | 2009-02-06T11:51:57Z | 520,056 | <p>if you know that there is a URL following a space in the string you can do something like this:</p>
<p>s is the string containg the url</p>
<pre><code>>>> t = s[s.find("http://"):]
>>> t = t[:t.find(" ")]
</code></pre>
<p>otherwise you need to check if find returns -1 or not.</p>
| 5 | 2009-02-06T12:06:16Z | [
"python",
"regex",
"url"
] |
What's the cleanest way to extract URLs from a string using Python? | 520,031 | <p>Although I know I could use some hugeass regex such as the one posted <a href="http://geekswithblogs.net/casualjim/archive/2005/12/01/61722.aspx">here</a> I'm wondering if there is some tweaky as hell way to do this either with a standard module or perhaps some third-party add-on?</p>
<p>Simple question, but nothin... | 18 | 2009-02-06T11:51:57Z | 520,078 | <p>You can use <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a>.</p>
<pre><code>def extractlinks(html):
soup = BeautifulSoup(html)
anchors = soup.findAll('a')
links = []
for a in anchors:
links.append(a['href'])
return links
</code></pre>
<p>Note tha... | 4 | 2009-02-06T12:12:58Z | [
"python",
"regex",
"url"
] |
What's the cleanest way to extract URLs from a string using Python? | 520,031 | <p>Although I know I could use some hugeass regex such as the one posted <a href="http://geekswithblogs.net/casualjim/archive/2005/12/01/61722.aspx">here</a> I'm wondering if there is some tweaky as hell way to do this either with a standard module or perhaps some third-party add-on?</p>
<p>Simple question, but nothin... | 18 | 2009-02-06T11:51:57Z | 1,855,891 | <p>Look at Django's approach here: <a href="https://github.com/django/django/blob/98c5370ef673bc83deaf24c197e0bb22a75071e3/django/utils/html.py#L257" rel="nofollow"><code>django.utils.urlize()</code></a>. Regexps are too limited for the job and you have to use heuristics to get results that are mostly right.</p>
| 10 | 2009-12-06T17:03:32Z | [
"python",
"regex",
"url"
] |
What's the cleanest way to extract URLs from a string using Python? | 520,031 | <p>Although I know I could use some hugeass regex such as the one posted <a href="http://geekswithblogs.net/casualjim/archive/2005/12/01/61722.aspx">here</a> I'm wondering if there is some tweaky as hell way to do this either with a standard module or perhaps some third-party add-on?</p>
<p>Simple question, but nothin... | 18 | 2009-02-06T11:51:57Z | 14,055,143 | <p>You can use this library I wrote:</p>
<p><a href="https://github.com/imranghory/urlextractor">https://github.com/imranghory/urlextractor</a></p>
<p>It's extremely hacky, but it doesn't rely upon "http://" like many other techniques, rather it uses the Mozilla TLD list (via the tldextract library) to search for TLD... | 5 | 2012-12-27T12:59:34Z | [
"python",
"regex",
"url"
] |
What's the cleanest way to extract URLs from a string using Python? | 520,031 | <p>Although I know I could use some hugeass regex such as the one posted <a href="http://geekswithblogs.net/casualjim/archive/2005/12/01/61722.aspx">here</a> I'm wondering if there is some tweaky as hell way to do this either with a standard module or perhaps some third-party add-on?</p>
<p>Simple question, but nothin... | 18 | 2009-02-06T11:51:57Z | 28,552,670 | <p>I know that it's exactly what you do not want but here's a file with a huge regex:</p>
<pre><code>#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
the web url matching regex used by markdown
http://daringfireball.net/2010/07/improved_regex_for_matching_urls
https://gist.github.com/gruber/8891611
"""
URL_REGEX = r"""(?... | 6 | 2015-02-17T00:20:26Z | [
"python",
"regex",
"url"
] |
What's the cleanest way to extract URLs from a string using Python? | 520,031 | <p>Although I know I could use some hugeass regex such as the one posted <a href="http://geekswithblogs.net/casualjim/archive/2005/12/01/61722.aspx">here</a> I'm wondering if there is some tweaky as hell way to do this either with a standard module or perhaps some third-party add-on?</p>
<p>Simple question, but nothin... | 18 | 2009-02-06T11:51:57Z | 30,408,189 | <h2>There is an excellent comparison of 13 different regex approaches</h2>
<p>...which can be found at this page: <a href="https://mathiasbynens.be/demo/url-regex"><strong>In search of the perfect URL validation regex</strong></a>. </p>
<p>The Diego Perini regex, which passed all the tests, is <strong>very</strong> l... | 6 | 2015-05-23T02:08:49Z | [
"python",
"regex",
"url"
] |
Python "property object has no attribute" Exception | 520,152 | <pre><code>confirmation = property(_get_confirmation, _set_confirmation)
confirmation.short_description = "Confirmation"
</code></pre>
<p>When I try the above I get an Exception I don't quite understand:</p>
<pre><code>AttributeError: 'property' object has no attribute 'short_description'
</code></pre>
<p>This was a... | 4 | 2009-02-06T12:45:09Z | 520,180 | <p>The result of property() is an object where you can't add new fields or methods. It's immutable which is why you get the error.</p>
<p><a href="http://adam.gomaa.us/blog/2008/aug/11/the-python-property-builtin/" rel="nofollow">Example how to use property()</a>.</p>
<p>[EDIT] As for the <a href="http://stackoverflo... | 3 | 2009-02-06T13:01:53Z | [
"python",
"django",
"properties"
] |
Where is Python used? I read about it a lot on Reddit | 520,210 | <p>I have downloaded the Pyscripter and learning Python. But I have no Idea if it has any job value , especially in India. I am learning Python as a Hobby. But it would be comforting to know if Python programmers are in demand in India.</p>
| 8 | 2009-02-06T13:08:13Z | 520,230 | <p>Everywhere. It's used <a href="http://panela.blog-city.com/python_at_google_greg_stein__sdforum.htm">extensively by google</a> for one.</p>
<p>See <a href="http://en.wikipedia.org/wiki/Python_software">list of python software</a> for more info, and also <a href="http://www.python.org/doc/essays/ppt/www8-py-www/sld0... | 17 | 2009-02-06T13:12:56Z | [
"python"
] |
Where is Python used? I read about it a lot on Reddit | 520,210 | <p>I have downloaded the Pyscripter and learning Python. But I have no Idea if it has any job value , especially in India. I am learning Python as a Hobby. But it would be comforting to know if Python programmers are in demand in India.</p>
| 8 | 2009-02-06T13:08:13Z | 520,233 | <p>Not sure about India, but you can get a decent overview of available Python jobs on the python.org jobs page <a href="http://www.python.org/community/jobs/" rel="nofollow">here</a>. </p>
| 1 | 2009-02-06T13:13:10Z | [
"python"
] |
Where is Python used? I read about it a lot on Reddit | 520,210 | <p>I have downloaded the Pyscripter and learning Python. But I have no Idea if it has any job value , especially in India. I am learning Python as a Hobby. But it would be comforting to know if Python programmers are in demand in India.</p>
| 8 | 2009-02-06T13:08:13Z | 520,239 | <p>It definitely has job value. For instance Google requires it. Have a look at <a href="http://www.google.co.in/support/jobs/bin/topic.py?dep_id=1054&loc_id=1100&topic=1054" rel="nofollow">Google openings in India</a>:</p>
<blockquote>
<p>Excellent programming skills in at
least one of the following langu... | 4 | 2009-02-06T13:14:47Z | [
"python"
] |
Where is Python used? I read about it a lot on Reddit | 520,210 | <p>I have downloaded the Pyscripter and learning Python. But I have no Idea if it has any job value , especially in India. I am learning Python as a Hobby. But it would be comforting to know if Python programmers are in demand in India.</p>
| 8 | 2009-02-06T13:08:13Z | 520,246 | <p>Try looking at Mark Pilgrim's excellent book "<a href="http://www.diveintopython.org/" rel="nofollow">Dive Into Python</a>" which is available for download under GNU Free Documentation License.</p>
<p>HTH</p>
<p>cheers,</p>
<p>Rob</p>
| 1 | 2009-02-06T13:16:35Z | [
"python"
] |
Where is Python used? I read about it a lot on Reddit | 520,210 | <p>I have downloaded the Pyscripter and learning Python. But I have no Idea if it has any job value , especially in India. I am learning Python as a Hobby. But it would be comforting to know if Python programmers are in demand in India.</p>
| 8 | 2009-02-06T13:08:13Z | 520,247 | <p>In many large companies it is a primary scripting language.
Google is using it along with Java and C++ and almost nothing else.
Also many web pages are built on top of python and Django.
Another place is game development. Many games have their engines written in C++ but all the logic in Python.</p>
<p>In other wor... | 10 | 2009-02-06T13:16:37Z | [
"python"
] |
Where is Python used? I read about it a lot on Reddit | 520,210 | <p>I have downloaded the Pyscripter and learning Python. But I have no Idea if it has any job value , especially in India. I am learning Python as a Hobby. But it would be comforting to know if Python programmers are in demand in India.</p>
| 8 | 2009-02-06T13:08:13Z | 520,257 | <p>In 10 years of web development I've had 1 client have me write an email parsing app with it. Not that it doesn't get used, but I've seen Ruby/php/.net way more often in the wild.</p>
<p>Edit:
From the other posts if you plan on working at Google, it sounds like the language to learn - LOL!</p>
| 1 | 2009-02-06T13:20:40Z | [
"python"
] |
Where is Python used? I read about it a lot on Reddit | 520,210 | <p>I have downloaded the Pyscripter and learning Python. But I have no Idea if it has any job value , especially in India. I am learning Python as a Hobby. But it would be comforting to know if Python programmers are in demand in India.</p>
| 8 | 2009-02-06T13:08:13Z | 520,369 | <p>It's juste one example but I know it is widely used in large scientific institutions with high tech machinery where non-programmers (typically physicists) need quick prototypes or tools to cover their data collection/processing needs. The easy-to access scripting language aspect clearly plays its role here. So I don... | 1 | 2009-02-06T13:58:54Z | [
"python"
] |
Where is Python used? I read about it a lot on Reddit | 520,210 | <p>I have downloaded the Pyscripter and learning Python. But I have no Idea if it has any job value , especially in India. I am learning Python as a Hobby. But it would be comforting to know if Python programmers are in demand in India.</p>
| 8 | 2009-02-06T13:08:13Z | 1,380,233 | <p>The google app engine lets you use python (or Java). I HIGHLY recommend that you check it out. If you want to have a FREE website with a database (actually a datastore but it works much like a database) using python, THIS IS IT. It scales up too. If you start to get enough traffic you would have to start paying ... | 0 | 2009-09-04T16:18:16Z | [
"python"
] |
Search Files& Dirs on Website | 520,362 | <p>Hi im coding to code a Tool that searchs for Dirs and files.</p>
<p>have done so the tool searchs for dirs, but need help to make it search for files on websites.</p>
<p>Any idea how it can be in python?</p>
| 0 | 2009-02-06T13:55:31Z | 520,373 | <p>Is this tool scanning the directories of your own website (in which the tool is running), or external sites?</p>
| 1 | 2009-02-06T14:00:58Z | [
"python"
] |
Search Files& Dirs on Website | 520,362 | <p>Hi im coding to code a Tool that searchs for Dirs and files.</p>
<p>have done so the tool searchs for dirs, but need help to make it search for files on websites.</p>
<p>Any idea how it can be in python?</p>
| 0 | 2009-02-06T13:55:31Z | 520,397 | <p>You can only do this if you have permission to browse directories on the site and no default page exists.</p>
| 1 | 2009-02-06T14:10:02Z | [
"python"
] |
Search Files& Dirs on Website | 520,362 | <p>Hi im coding to code a Tool that searchs for Dirs and files.</p>
<p>have done so the tool searchs for dirs, but need help to make it search for files on websites.</p>
<p>Any idea how it can be in python?</p>
| 0 | 2009-02-06T13:55:31Z | 520,423 | <p>You cannot get a directory listing on a website.</p>
<p>Pedantically, HTTP has no notion of directory.</p>
<p>Pratically, WebDAV provides a directory listing verb, so you can use that if WebDAV is enabled.</p>
<p>Otherwise, the closest thing you can do is similar to what recursive wget does: get a page, parse the... | 1 | 2009-02-06T14:17:46Z | [
"python"
] |
Search Files& Dirs on Website | 520,362 | <p>Hi im coding to code a Tool that searchs for Dirs and files.</p>
<p>have done so the tool searchs for dirs, but need help to make it search for files on websites.</p>
<p>Any idea how it can be in python?</p>
| 0 | 2009-02-06T13:55:31Z | 520,575 | <p>If you're getting information on your own website for presentation in your own web application, you should use os.walk.</p>
<p>See <a href="http://www.python.org/doc/2.5.2/lib/os-file-dir.html" rel="nofollow">http://www.python.org/doc/2.5.2/lib/os-file-dir.html</a> for more information.</p>
| 0 | 2009-02-06T14:55:31Z | [
"python"
] |
Event handling with Jython & Swing | 520,615 | <p>I'm making a GUI by using Swing from Jython. Event handling seems to be particularly elegant from Jython, just set</p>
<pre><code>JButton("Push me", actionPerformed = nameOfFunctionToCall)
</code></pre>
<p>However, trying same thing inside a class gets difficult. Naively trying</p>
<pre><code>JButton("Push me", a... | 8 | 2009-02-06T15:09:13Z | 523,456 | <pre><code>JButton("Push me", actionPerformed=self.nameOfMethodToCall)
</code></pre>
<p>Here's a modified example from the article you cited:</p>
<pre><code>from javax.swing import JButton, JFrame
class MyFrame(JFrame):
def __init__(self):
JFrame.__init__(self, "Hello Jython")
button = JButton("H... | 11 | 2009-02-07T08:35:51Z | [
"java",
"python",
"user-interface",
"swing",
"jython"
] |
Has anyone installed MySQLdb for Python on Cygwin? | 520,865 | <p>I'm trying to install MySQLdb for python on Cygwin. Unfortunately, when I run <code>python setup.py build</code>, I get the following error:</p>
<pre><code>$ python setup.py build
/bin/sh: /usr/local/bin/mysql_config: No such file or directory
Traceback (most recent call last):
File "setup.py", line 16, in <mo... | 10 | 2009-02-06T16:01:35Z | 521,081 | <p>You'll need mysql-devel, if it's available for cygwin, or you'll need to build mysql from source.</p>
<p>Your best bet is probably to just compile the MySQL client yourself in order to get the necessary headers to compile MySQLdb. See <a href="http://cpansearch.perl.org/src/CAPTTOFU/DBD-mysql-3.0000/INSTALL.html#wi... | 2 | 2009-02-06T16:48:26Z | [
"python",
"mysql",
"cygwin"
] |
Has anyone installed MySQLdb for Python on Cygwin? | 520,865 | <p>I'm trying to install MySQLdb for python on Cygwin. Unfortunately, when I run <code>python setup.py build</code>, I get the following error:</p>
<pre><code>$ python setup.py build
/bin/sh: /usr/local/bin/mysql_config: No such file or directory
Traceback (most recent call last):
File "setup.py", line 16, in <mo... | 10 | 2009-02-06T16:01:35Z | 1,785,355 | <p>I followed the directions on <a href="http://phaseshiftllc.com/archives/2008/10/26/installing-mysql-gem-on-windows-cygwin-for-rails#comment-86" rel="nofollow">this comment</a> to get MySQL installed on Cygwin. I had to use version 5.1.35, which can be downloaded from <a href="http://downloads.mysql.com/archives.php... | 1 | 2009-11-23T19:19:45Z | [
"python",
"mysql",
"cygwin"
] |
Has anyone installed MySQLdb for Python on Cygwin? | 520,865 | <p>I'm trying to install MySQLdb for python on Cygwin. Unfortunately, when I run <code>python setup.py build</code>, I get the following error:</p>
<pre><code>$ python setup.py build
/bin/sh: /usr/local/bin/mysql_config: No such file or directory
Traceback (most recent call last):
File "setup.py", line 16, in <mo... | 10 | 2009-02-06T16:01:35Z | 8,440,154 | <p>After building MySQL using the instructions above, you'll need to do the following to build and install MySQLdb:</p>
<ol>
<li>Download the Python 'setuptools' package <a href="http://pypi.python.org/pypi/setuptools#files" rel="nofollow">here</a> (example: setuptools-0.6c11-py2.6.egg). You'll need this to run setup.... | 2 | 2011-12-09T01:52:00Z | [
"python",
"mysql",
"cygwin"
] |
Has anyone installed MySQLdb for Python on Cygwin? | 520,865 | <p>I'm trying to install MySQLdb for python on Cygwin. Unfortunately, when I run <code>python setup.py build</code>, I get the following error:</p>
<pre><code>$ python setup.py build
/bin/sh: /usr/local/bin/mysql_config: No such file or directory
Traceback (most recent call last):
File "setup.py", line 16, in <mo... | 10 | 2009-02-06T16:01:35Z | 17,468,646 | <p>How I did it:</p>
<p>First I installed <a href="https://github.com/transcode-open/apt-cyg" rel="nofollow"><code>apt-cyg</code></a>. With that:</p>
<pre><code># apt-cyg install gcc # older name
apt-cyg install gcc-core # as of 2015
apt-cyg install python-setuptools
easy_install pip
pip install -U... | 3 | 2013-07-04T11:03:46Z | [
"python",
"mysql",
"cygwin"
] |
Has anyone installed MySQLdb for Python on Cygwin? | 520,865 | <p>I'm trying to install MySQLdb for python on Cygwin. Unfortunately, when I run <code>python setup.py build</code>, I get the following error:</p>
<pre><code>$ python setup.py build
/bin/sh: /usr/local/bin/mysql_config: No such file or directory
Traceback (most recent call last):
File "setup.py", line 16, in <mo... | 10 | 2009-02-06T16:01:35Z | 19,615,174 | <p>Got the same error after trying <code>pip install mysql-python</code>. I have Win7 x64 + Cygwin x86 2.830 + Django 1.5.5 + Python 2.7.</p>
<p>So I ran Cygwin setup and downloaded the <code>libmysqlclient-devel</code>: MySQL database client library (development) and that did it!!</p>
| 2 | 2013-10-27T06:06:41Z | [
"python",
"mysql",
"cygwin"
] |
Has anyone installed MySQLdb for Python on Cygwin? | 520,865 | <p>I'm trying to install MySQLdb for python on Cygwin. Unfortunately, when I run <code>python setup.py build</code>, I get the following error:</p>
<pre><code>$ python setup.py build
/bin/sh: /usr/local/bin/mysql_config: No such file or directory
Traceback (most recent call last):
File "setup.py", line 16, in <mo... | 10 | 2009-02-06T16:01:35Z | 30,419,348 | <p>First, install apt-cyg:</p>
<pre><code>lynx -source rawgit.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg`
install apt-cyg /bin
</code></pre>
<p>Now, use apt-cyg to install mysql-devel:</p>
<pre><code>apt-cyg install libmysqlclient-devel
</code></pre>
| 2 | 2015-05-24T01:54:37Z | [
"python",
"mysql",
"cygwin"
] |
How to convert a list of number to html in Python? | 520,881 | <p>hey guys, my last problem ^^ say i have a string which contains html, like</p>
<pre><code>html = '<td class="p11_666699"><strong>100</strong></td>'
</code></pre>
<p>and a list like</p>
<pre><code>numbers = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 1... | 0 | 2009-02-06T16:05:16Z | 520,923 | <p>Are you looking for a way to join a list of numbers into a string? This will work:</p>
<pre><code>' '.join(map(str, [10, 20, 30]))
</code></pre>
<p>Resulting in:</p>
<pre><code>'10 20 30'
</code></pre>
<p>The second argument of <code>map</code> is a list, so you can place your 'numbers' list there.</p>
<p>This ... | 1 | 2009-02-06T16:14:01Z | [
"python"
] |
How to convert a list of number to html in Python? | 520,881 | <p>hey guys, my last problem ^^ say i have a string which contains html, like</p>
<pre><code>html = '<td class="p11_666699"><strong>100</strong></td>'
</code></pre>
<p>and a list like</p>
<pre><code>numbers = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 1... | 0 | 2009-02-06T16:05:16Z | 520,936 | <p>I think you either want this:</p>
<pre><code>numbers = [100, 101, 102, 103]
output = "<td>" + ", ".join(map(str, numbers)) + "</td>"
</code></pre>
<p>or</p>
<pre><code>output = ""
for number in numbers:
output += "<td>" + str(number) + "</td>"
</code></pre>
| 2 | 2009-02-06T16:16:28Z | [
"python"
] |
How to convert a list of number to html in Python? | 520,881 | <p>hey guys, my last problem ^^ say i have a string which contains html, like</p>
<pre><code>html = '<td class="p11_666699"><strong>100</strong></td>'
</code></pre>
<p>and a list like</p>
<pre><code>numbers = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 1... | 0 | 2009-02-06T16:05:16Z | 520,938 | <p>As pointed out in the comments, it's really hard to understand your question... but if you want to generate a bunch of table cells, each containing one of the numbers, use something like this:</p>
<pre><code>html = ''.join('<td>%d</td>' % n for n in numbers)
</code></pre>
<p>Of course you can add in a ... | 4 | 2009-02-06T16:17:03Z | [
"python"
] |
How to convert a list of number to html in Python? | 520,881 | <p>hey guys, my last problem ^^ say i have a string which contains html, like</p>
<pre><code>html = '<td class="p11_666699"><strong>100</strong></td>'
</code></pre>
<p>and a list like</p>
<pre><code>numbers = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 1... | 0 | 2009-02-06T16:05:16Z | 520,947 | <pre><code>html = ['<td class="p11_666699"><strong>%d</strong></td>' % number for number in numbers]
</code></pre>
<p>And I see David just suggested this (but joined). </p>
| 1 | 2009-02-06T16:18:40Z | [
"python"
] |
pagination with the python cmd module | 520,963 | <p>I'm prototyping a Python app with the <a href="http://docs.python.org/library/cmd.html">cmd</a> module.</p>
<p>Some messages to the user will be quite long and I'd like to paginate them.
The first 10 (or a configurable number) lines of the message would appear, and pressing the SPACE bar would display the next page... | 8 | 2009-02-06T16:21:16Z | 521,054 | <p>The simple thing would just be to pipe your script through "less" or a similar command at runtime.</p>
<p>Here's a simple method that does approximately what you want, though:</p>
<pre><code>def print_and_wait(some_long_message):
lines = some_long_message.split('\n')
i=0
while i < len(lines):
... | 4 | 2009-02-06T16:42:32Z | [
"python",
"pagination",
"cmd"
] |
pagination with the python cmd module | 520,963 | <p>I'm prototyping a Python app with the <a href="http://docs.python.org/library/cmd.html">cmd</a> module.</p>
<p>Some messages to the user will be quite long and I'd like to paginate them.
The first 10 (or a configurable number) lines of the message would appear, and pressing the SPACE bar would display the next page... | 8 | 2009-02-06T16:21:16Z | 699,021 | <p>As Yoni said above the right way to do this is to provide a print method that pages automatically inside your running cmd instance. The constructor of Cmd takes stdin and stdout arguments. So simple provide an object that works like stdout and supports your paging print method.</p>
<pre><code>class PagingStdOut(obj... | 3 | 2009-03-30T21:07:16Z | [
"python",
"pagination",
"cmd"
] |
pagination with the python cmd module | 520,963 | <p>I'm prototyping a Python app with the <a href="http://docs.python.org/library/cmd.html">cmd</a> module.</p>
<p>Some messages to the user will be quite long and I'd like to paginate them.
The first 10 (or a configurable number) lines of the message would appear, and pressing the SPACE bar would display the next page... | 8 | 2009-02-06T16:21:16Z | 708,681 | <p>Paging subroutines can be found in the <a href="http://bazaar.launchpad.net/~ipython-dev/ipython/trunk/annotate/head%3A/IPython/genutils.py" rel="nofollow">genutils.py</a> file of <a href="http://ipython.scipy.org/" rel="nofollow">IPython</a> (see <code>page</code>, or <code>page_dumb</code> for a simpler one). The ... | 0 | 2009-04-02T07:37:36Z | [
"python",
"pagination",
"cmd"
] |
pagination with the python cmd module | 520,963 | <p>I'm prototyping a Python app with the <a href="http://docs.python.org/library/cmd.html">cmd</a> module.</p>
<p>Some messages to the user will be quite long and I'd like to paginate them.
The first 10 (or a configurable number) lines of the message would appear, and pressing the SPACE bar would display the next page... | 8 | 2009-02-06T16:21:16Z | 1,380,570 | <p>I had the same question. There is a pager built in to the <a href="http://docs.python.org/library/pydoc" rel="nofollow"><strong>pydoc</strong> module</a>. I incorporated it thusly (which I find hackish and unsatisfying... I'm open to better ideas though).</p>
<p>I like the idea that it would autopage if there are... | 1 | 2009-09-04T17:31:11Z | [
"python",
"pagination",
"cmd"
] |
Further Processing of Output of Undefined Methods (Python) | 521,111 | <p>How do I write a Python class that handles calls on undefined methods by first, getting the output of a function of the same name from a given module, and then, doing something further with that output?</p>
<p>For example, given add(x, y), doublerInstance.add(1, 1) should return 4.</p>
<p>I know _ _ getattr _ _() ... | 2 | 2009-02-06T16:55:56Z | 521,194 | <p><code>__getattr__</code> has to return the function - not the result from calling it:</p>
<pre><code>class Doubler:
def __init__(self, source):
self.source = source
def __getattr__(self, attrname):
fnc = getattr(self.source, attrname)
return lambda x,y : fnc(x,y) * 2
</code></pre>
<p>This uses a l... | 2 | 2009-02-06T17:14:28Z | [
"python"
] |
Further Processing of Output of Undefined Methods (Python) | 521,111 | <p>How do I write a Python class that handles calls on undefined methods by first, getting the output of a function of the same name from a given module, and then, doing something further with that output?</p>
<p>For example, given add(x, y), doublerInstance.add(1, 1) should return 4.</p>
<p>I know _ _ getattr _ _() ... | 2 | 2009-02-06T16:55:56Z | 521,197 | <p>When you call <code>doublerInstance.add(1, 2)</code>, you're getting an attribute <code>add</code> from it, and then you're <em>calling</em> it. But inside your getattr, you're returning a value. You have to return a function.</p>
<p>Anyway, for this particular case to work, you need this:</p>
<pre><code>def __get... | 2 | 2009-02-06T17:15:11Z | [
"python"
] |
Further Processing of Output of Undefined Methods (Python) | 521,111 | <p>How do I write a Python class that handles calls on undefined methods by first, getting the output of a function of the same name from a given module, and then, doing something further with that output?</p>
<p>For example, given add(x, y), doublerInstance.add(1, 1) should return 4.</p>
<p>I know _ _ getattr _ _() ... | 2 | 2009-02-06T16:55:56Z | 521,208 | <p>Try this:</p>
<pre><code>class Doubler:
def __init__(self, source):
self.source = source
def __getattr__(self, attrname):
def tmp_func(*args):
fnc = getattr(self.source, attrname)
return fnc(*args) * 2
return tmp_func
</code></pre>
<p>Hint:
<strong>getattr</strong> must return a functi... | 0 | 2009-02-06T17:17:45Z | [
"python"
] |
Python loops with multiple lists? | 521,321 | <p><strong><edit></strong>
Thanks to everyone who has answered so far. The zip and os.path.join are really helpful. Any suggestions on ways to list the counter in front, without doing something like this:</p>
<pre><code>zip(range(len(files)), files, directories)
</code></pre>
<p><strong></edit></strong></p>
<p... | 15 | 2009-02-06T17:42:27Z | 521,345 | <p>Try this:</p>
<pre><code>directories = ['directory_0', 'directory_1', 'directory_2']
files = ['file_a', 'file_b', 'file_c']
for file, dir in zip(files, directories):
print dir + '/' + file
</code></pre>
<p>To explain, the <code>zip()</code> function takes lists as input and returns a list of "zipped" tuples. ... | 10 | 2009-02-06T17:46:38Z | [
"python",
"arrays",
"loops",
"list"
] |
Python loops with multiple lists? | 521,321 | <p><strong><edit></strong>
Thanks to everyone who has answered so far. The zip and os.path.join are really helpful. Any suggestions on ways to list the counter in front, without doing something like this:</p>
<pre><code>zip(range(len(files)), files, directories)
</code></pre>
<p><strong></edit></strong></p>
<p... | 15 | 2009-02-06T17:42:27Z | 521,361 | <pre><code>import os.path
for dir, file in zip(directories, files):
print(os.path.join(dir, file)) # for directories, files
</code></pre>
<p>you can have it as a list comprehension as well, creating list of string with print going after that]</p>
<p>with counter:</p>
<pre><code>for i, (dir, ... | 35 | 2009-02-06T17:49:07Z | [
"python",
"arrays",
"loops",
"list"
] |
Python loops with multiple lists? | 521,321 | <p><strong><edit></strong>
Thanks to everyone who has answered so far. The zip and os.path.join are really helpful. Any suggestions on ways to list the counter in front, without doing something like this:</p>
<pre><code>zip(range(len(files)), files, directories)
</code></pre>
<p><strong></edit></strong></p>
<p... | 15 | 2009-02-06T17:42:27Z | 521,380 | <p>Building on Ryan's answer, you can do:</p>
<pre><code>for fileDir in [dir + '/' + file for dir in directories for file in files]:
print(fileDir)
</code></pre>
| -1 | 2009-02-06T17:51:54Z | [
"python",
"arrays",
"loops",
"list"
] |
Python loops with multiple lists? | 521,321 | <p><strong><edit></strong>
Thanks to everyone who has answered so far. The zip and os.path.join are really helpful. Any suggestions on ways to list the counter in front, without doing something like this:</p>
<pre><code>zip(range(len(files)), files, directories)
</code></pre>
<p><strong></edit></strong></p>
<p... | 15 | 2009-02-06T17:42:27Z | 1,626,201 | <p>If you want to add a counter to any for loop in Python you can use the enumerate() function:</p>
<pre><code>listA = ["A", "B", "C", "D", "E"]
listB = ["a", "b", "c", "d", "e"]
for i, (a, b) in enumerate(zip(listA, listB)):
print "%d) %s, %s" % (i, a, b)
</code></pre>
<p>gives the output:</p>
<pre><code>0) A, ... | 0 | 2009-10-26T17:37:45Z | [
"python",
"arrays",
"loops",
"list"
] |
How does one parse simple inline markup (i.e. *bold*), in Python? | 521,326 | <p>How does one implement a parser (in Python) for a subset of wikitext that modifies text, namely:</p>
<pre><code>*bold*, /italics/, _underline_
</code></pre>
<p>I'm converting it to LaTeX, so the conversion is from:</p>
<pre><code>Hello, *world*! Let's /go/.
</code></pre>
<p>to:</p>
<pre><code>Hello \textbf{worl... | 3 | 2009-02-06T17:43:21Z | 521,367 | <p>If your language is small, regular expressions might be the least painful solution:</p>
<pre><code>>>> import re
>>> str = "Hello, *world*! Let's /go/."
>>> str = re.sub(r"\*([^\*]*)\*", r"\textbf{\1}", str)
>>> str = re.sub(r"/([^/]*)/", r"\textit{\1}", str)
>>> str
"... | 4 | 2009-02-06T17:50:33Z | [
"python",
"parsing",
"wikitext",
"creole"
] |
Why True/False is capitalized in Python? | 521,476 | <p>All members are camel case, right? Why True/False but not true/false, which is more relaxed?</p>
| 34 | 2009-02-06T18:13:04Z | 521,508 | <p>From <a href="http://www.python.org/dev/peps/pep-0285/">Pep 285</a>:</p>
<blockquote>
<p>Should the constants be called 'True'
and 'False' (similar to
None) or 'true' and 'false' (as in C++, Java and C99)?</p>
<p>=> True and False.</p>
<p>Most reviewers agree that consistency within Python is... | 49 | 2009-02-06T18:20:10Z | [
"python",
"camelcasing"
] |
Why True/False is capitalized in Python? | 521,476 | <p>All members are camel case, right? Why True/False but not true/false, which is more relaxed?</p>
| 34 | 2009-02-06T18:13:04Z | 521,509 | <p>Here's a <a href="http://mail.python.org/pipermail/python-list/2007-May/440165.html" rel="nofollow">possible explaination</a>:</p>
<blockquote>
<blockquote>
<p>I see that naming conventions are such that classes usually get named
CamelCase. So why are the built-in types named all lowercase (like
list,... | 3 | 2009-02-06T18:20:14Z | [
"python",
"camelcasing"
] |
Why True/False is capitalized in Python? | 521,476 | <p>All members are camel case, right? Why True/False but not true/false, which is more relaxed?</p>
| 34 | 2009-02-06T18:13:04Z | 521,515 | <p>All of python's <a href="http://docs.python.org/library/constants.html">built-in constants</a> are capitalized or [upper] CamelCase:</p>
| 10 | 2009-02-06T18:21:40Z | [
"python",
"camelcasing"
] |
Why True/False is capitalized in Python? | 521,476 | <p>All members are camel case, right? Why True/False but not true/false, which is more relaxed?</p>
| 34 | 2009-02-06T18:13:04Z | 718,323 | <p><code>True</code> and <code>False</code> are capitalized in Haskell, the other language which uses indentation as syntax.</p>
| -6 | 2009-04-05T04:11:42Z | [
"python",
"camelcasing"
] |
Why True/False is capitalized in Python? | 521,476 | <p>All members are camel case, right? Why True/False but not true/false, which is more relaxed?</p>
| 34 | 2009-02-06T18:13:04Z | 1,656,406 | <p>I'd say that they're called <code>True</code> and <code>False</code> because they're singletons.</p>
| 0 | 2009-11-01T04:38:33Z | [
"python",
"camelcasing"
] |
Comparison function in Python using Lambdas | 521,505 | <p>I am trying to understand lambdas and I get the idea but how do I define multiple conditions for a Point2 [x,y] comparison, so something like:</p>
<pre><code>if x1 < x2: -1
if x1 == x2: 0
if x1 > x2: 1
</code></pre>
| 1 | 2009-02-06T18:19:26Z | 521,517 | <p>EDIT: Updated to be real Python according to <a href="http://www.python.org/dev/peps/pep-0308/" rel="nofollow">PEP308</a> :) Note that the PEP has interesting information about how this should be parenthesized depending on which version of Python you're using. I won't attempt to reproduce it here - just read the PEP... | 3 | 2009-02-06T18:22:11Z | [
"python",
"sorting",
"lambda"
] |
Comparison function in Python using Lambdas | 521,505 | <p>I am trying to understand lambdas and I get the idea but how do I define multiple conditions for a Point2 [x,y] comparison, so something like:</p>
<pre><code>if x1 < x2: -1
if x1 == x2: 0
if x1 > x2: 1
</code></pre>
| 1 | 2009-02-06T18:19:26Z | 521,529 | <p>The code above is equivalent to:</p>
<pre><code>cmp(x1,x2)
</code></pre>
<p>or in a (ugly) lambda expression:</p>
<pre><code>lambda x1,x2: 1 if x1>x2 else (0 if x1==x2 else -1)
</code></pre>
<p>(works only in Python 2.6 and above).</p>
<p>Normally you should use lambda expressions only for functions like</p>... | 5 | 2009-02-06T18:25:40Z | [
"python",
"sorting",
"lambda"
] |
Comparison function in Python using Lambdas | 521,505 | <p>I am trying to understand lambdas and I get the idea but how do I define multiple conditions for a Point2 [x,y] comparison, so something like:</p>
<pre><code>if x1 < x2: -1
if x1 == x2: 0
if x1 > x2: 1
</code></pre>
| 1 | 2009-02-06T18:19:26Z | 521,539 | <pre><code>my_compare = lambda x1,x2 : cmp(x1, x2)
my_compare( -100, 100 )
</code></pre>
| 4 | 2009-02-06T18:27:04Z | [
"python",
"sorting",
"lambda"
] |
Comparison function in Python using Lambdas | 521,505 | <p>I am trying to understand lambdas and I get the idea but how do I define multiple conditions for a Point2 [x,y] comparison, so something like:</p>
<pre><code>if x1 < x2: -1
if x1 == x2: 0
if x1 > x2: 1
</code></pre>
| 1 | 2009-02-06T18:19:26Z | 521,541 | <p>In such a case, lambda expressions aren't usually the best thing. As Jon Skeet mentioned, you're gonna end with multiple if-else expressions:</p>
<pre><code>lambda x1, x2: -1 if x1 < x2 else (0 if x1 == x2 else -1)
</code></pre>
<p>For your specific problem:</p>
<pre><code>lambda x1, x2: cmp(x1, x2)
</code></p... | 4 | 2009-02-06T18:27:22Z | [
"python",
"sorting",
"lambda"
] |
How do i get python's pprint to return a string instead of printing? | 521,532 | <p>In other words, what's the sprintf equivalent to pprint? </p>
| 76 | 2009-02-06T18:25:53Z | 521,545 | <p>The <a href="http://docs.python.org/library/pprint.html">pprint</a> module has a command named <a href="http://docs.python.org/library/pprint.html#pprint.pformat">pformat</a>, for just that purpose.</p>
<p>From the documentation:</p>
<blockquote>
<p>Return the formatted representation of object as a string. inde... | 123 | 2009-02-06T18:28:30Z | [
"python"
] |
How do i get python's pprint to return a string instead of printing? | 521,532 | <p>In other words, what's the sprintf equivalent to pprint? </p>
| 76 | 2009-02-06T18:25:53Z | 521,546 | <p>Are you looking for <code>pprint.pformat</code>?</p>
| 7 | 2009-02-06T18:29:14Z | [
"python"
] |
How do i get python's pprint to return a string instead of printing? | 521,532 | <p>In other words, what's the sprintf equivalent to pprint? </p>
| 76 | 2009-02-06T18:25:53Z | 521,550 | <p>Assuming you really do mean <code>pprint</code> from the <a href="http://docs.python.org/library/pprint.html">pretty-print library</a>, then you want
the <code>pprint.pformat</code> method.</p>
<p>If you just mean <code>print</code>, then you want <code>str()</code></p>
| 10 | 2009-02-06T18:29:47Z | [
"python"
] |
How do i get python's pprint to return a string instead of printing? | 521,532 | <p>In other words, what's the sprintf equivalent to pprint? </p>
| 76 | 2009-02-06T18:25:53Z | 521,553 | <p>Something like this:</p>
<pre><code>import pprint, StringIO
s = StringIO.StringIO()
pprint.pprint(some_object, s)
print s.getvalue() # displays the string
</code></pre>
| 0 | 2009-02-06T18:30:04Z | [
"python"
] |
How do i get python's pprint to return a string instead of printing? | 521,532 | <p>In other words, what's the sprintf equivalent to pprint? </p>
| 76 | 2009-02-06T18:25:53Z | 6,472,848 | <pre><code>>>> import pprint
>>> pprint.pformat({'key1':'val1', 'key2':[1,2]})
"{'key1': 'val1', 'key2': [1, 2]}"
>>>
</code></pre>
| 8 | 2011-06-24T19:30:38Z | [
"python"
] |
How can I get only class variables? | 521,710 | <p>I have this class definition:</p>
<pre><code>class cols:
name = 'name'
size = 'size'
date = 'date'
@classmethod
def foo(cls):
print "This is a class method"
</code></pre>
<p>With __dict__ I get all class attributes (members and variables). Also there are the "Internal attributes" too (l... | 4 | 2009-02-06T19:06:37Z | 521,728 | <pre><code>import inspect
inspect.getmembers(cols)
</code></pre>
<p>There are a lot if things you can do with the inspect module: <a href="http://lfw.org/python/inspect.html" rel="nofollow">http://lfw.org/python/inspect.html</a></p>
| 1 | 2009-02-06T19:11:10Z | [
"python"
] |
How can I get only class variables? | 521,710 | <p>I have this class definition:</p>
<pre><code>class cols:
name = 'name'
size = 'size'
date = 'date'
@classmethod
def foo(cls):
print "This is a class method"
</code></pre>
<p>With __dict__ I get all class attributes (members and variables). Also there are the "Internal attributes" too (l... | 4 | 2009-02-06T19:06:37Z | 521,772 | <p>I wouldn't know a straightforward way, especially since from the interpreter's POV, there is not that much of a difference between a method of a class and any other variable (methods have descriptors, but that's it...).</p>
<p>So when you only want non-callable class members, you have to fiddle around a little:</p>... | 5 | 2009-02-06T19:20:51Z | [
"python"
] |
Is there a way to decode numerical COM error-codes in pywin32 | 521,759 | <p>Here is part of a stack-trace from a recent run of an unreliable application written in Python which controls another application written in Excel:</p>
<pre><code>pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146788248), None)
</code></pre>
<p>Obviously something has gone wr... | 24 | 2009-02-06T19:18:01Z | 521,814 | <p>Yes try the win32api module:</p>
<pre><code>import win32api
e_msg = win32api.FormatMessage(-2147352567)
</code></pre>
<p>You can grab any codes returned from the exception and pass them to FormatMessage. Your example had 2 error codes.</p>
| 5 | 2009-02-06T19:31:24Z | [
"python",
"windows",
"excel",
"com",
"pywin32"
] |
Is there a way to decode numerical COM error-codes in pywin32 | 521,759 | <p>Here is part of a stack-trace from a recent run of an unreliable application written in Python which controls another application written in Excel:</p>
<pre><code>pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146788248), None)
</code></pre>
<p>Obviously something has gone wr... | 24 | 2009-02-06T19:18:01Z | 531,105 | <p>You are not doing anything wrong. The first item in your stack trace (the number) is the error code returned by the COM object. The second item is the description associated with the error code which in this case is "Exception Occurred". pywintypes.com_error already called the equivalent of win32api.FormatMessage(er... | 33 | 2009-02-10T05:01:04Z | [
"python",
"windows",
"excel",
"com",
"pywin32"
] |
Is there a way to decode numerical COM error-codes in pywin32 | 521,759 | <p>Here is part of a stack-trace from a recent run of an unreliable application written in Python which controls another application written in Excel:</p>
<pre><code>pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146788248), None)
</code></pre>
<p>Obviously something has gone wr... | 24 | 2009-02-06T19:18:01Z | 5,326,994 | <p>Do it like this:</p>
<pre><code>try:
[whatever code]
except pythoncom.com_error as error:
print(win32api.FormatMessage(error.excepinfo[5]))
</code></pre>
<p>More information on digesting the pythoncom.com_error object here: <a href="http://docs.activestate.com/activepython/3.2/pywin32/com_error.html" rel="... | 5 | 2011-03-16T14:49:34Z | [
"python",
"windows",
"excel",
"com",
"pywin32"
] |
Is there a way to decode numerical COM error-codes in pywin32 | 521,759 | <p>Here is part of a stack-trace from a recent run of an unreliable application written in Python which controls another application written in Excel:</p>
<pre><code>pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146788248), None)
</code></pre>
<p>Obviously something has gone wr... | 24 | 2009-02-06T19:18:01Z | 10,641,263 | <p>Specifically for pythoncom, the errors codes that result are more than cryptic. This is because pythoncom represents them internally as a 32bit signed integer, when the correct representation is a 32bit <em>unsigned</em> integer. As a result, the conversion that you end up seeing in the stack trace is incorrect.</p>... | 0 | 2012-05-17T18:15:44Z | [
"python",
"windows",
"excel",
"com",
"pywin32"
] |
Is there a way to decode numerical COM error-codes in pywin32 | 521,759 | <p>Here is part of a stack-trace from a recent run of an unreliable application written in Python which controls another application written in Excel:</p>
<pre><code>pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146788248), None)
</code></pre>
<p>Obviously something has gone wr... | 24 | 2009-02-06T19:18:01Z | 29,101,263 | <p>No-one has yet mentioned the <code>strerror</code> attribute of the <a href="http://timgolden.me.uk/pywin32-docs/com_error.html" rel="nofollow"><code>pywintypes.com_error</code> Exception</a>. This returns the result of <code>FormatMessage</code> for the error code. So instead of doing it yourself like this</p>
<pr... | 1 | 2015-03-17T14:09:05Z | [
"python",
"windows",
"excel",
"com",
"pywin32"
] |
How to use storeHtmlSource in python code (Selenium RC) | 522,229 | <p>I found storeHtmlSource method description in <a href="http://seleniumhq.org/projects/core/reference.html" rel="nofollow">Selenium reference</a>, but can't figure out how to use it in python code I generated by exporting recording of my actions from the Selenium IDE.</p>
<p>I need to pass the html source code of th... | 0 | 2009-02-06T21:23:49Z | 557,371 | <p>I can't speak for Python, but check out the getHtmlSource method for the Java API of the <a href="http://release.seleniumhq.org/selenium-remote-control/1.0-beta-2/doc/java/com/thoughtworks/selenium/Selenium.html" rel="nofollow">Selenium interface</a>. It explains what it does pretty clearly.</p>
| 1 | 2009-02-17T15:29:53Z | [
"python",
"html",
"selenium"
] |
Finding first and last index of some value in a list in Python | 522,372 | <p>Is there any built-in methods that are part of lists that would give me the first and last index of some value, like:</p>
<pre><code>verts.IndexOf(12.345)
verts.LastIndexOf(12.345)
</code></pre>
| 23 | 2009-02-06T22:00:00Z | 522,401 | <p>Sequences have a method <code>index(value)</code> which returns index of first occurrence.<br>
You can run it on <code>verts[::-1]</code> to find out the last index.</p>
| 39 | 2009-02-06T22:05:06Z | [
"python",
"list",
"search"
] |
Finding first and last index of some value in a list in Python | 522,372 | <p>Is there any built-in methods that are part of lists that would give me the first and last index of some value, like:</p>
<pre><code>verts.IndexOf(12.345)
verts.LastIndexOf(12.345)
</code></pre>
| 23 | 2009-02-06T22:00:00Z | 6,194,807 | <p>Use <code>i1 = yourlist.index(yourvalue)</code> and <code>i2 = yourlist.rindex(yourvalue).</code> </p>
| 10 | 2011-05-31T23:48:50Z | [
"python",
"list",
"search"
] |
Finding first and last index of some value in a list in Python | 522,372 | <p>Is there any built-in methods that are part of lists that would give me the first and last index of some value, like:</p>
<pre><code>verts.IndexOf(12.345)
verts.LastIndexOf(12.345)
</code></pre>
| 23 | 2009-02-06T22:00:00Z | 18,157,104 | <p>if you are searching for the index of the last occurance of myvalue in mylist:</p>
<pre><code>len(mylist) - mylist[::-1].index(myvalue) - 1
</code></pre>
| 7 | 2013-08-09T23:23:39Z | [
"python",
"list",
"search"
] |
Finding first and last index of some value in a list in Python | 522,372 | <p>Is there any built-in methods that are part of lists that would give me the first and last index of some value, like:</p>
<pre><code>verts.IndexOf(12.345)
verts.LastIndexOf(12.345)
</code></pre>
| 23 | 2009-02-06T22:00:00Z | 29,525,218 | <p>As a small helper function:</p>
<pre><code>def rindex(mylist, myvalue):
return len(mylist) - mylist[::-1].index(myvalue) - 1
</code></pre>
| 4 | 2015-04-08T20:57:56Z | [
"python",
"list",
"search"
] |
Is there a way to loop through a sub section of a list in Python | 522,430 | <p>So for a list that has 1000 elements, I want to loop from 400 to 500. How do you do it?</p>
<p>I don't see a way by using the for each and for range techniques.</p>
| 3 | 2009-02-06T22:15:20Z | 522,439 | <pre><code>for element in allElements[400:501]:
# do something
</code></pre>
<p>These are <a href="http://docs.python.org/reference/expressions.html#id8" rel="nofollow">slices</a> and generate a sublist of the whole list. They are one of the main elements of Python.</p>
| 7 | 2009-02-06T22:16:58Z | [
"python",
"loops",
"list"
] |
Is there a way to loop through a sub section of a list in Python | 522,430 | <p>So for a list that has 1000 elements, I want to loop from 400 to 500. How do you do it?</p>
<p>I don't see a way by using the for each and for range techniques.</p>
| 3 | 2009-02-06T22:15:20Z | 522,442 | <pre><code>for x in thousand[400:500]:
pass
</code></pre>
<p>If you are working with an iterable instead of a list, you should use <a href="http://docs.python.org/library/itertools">itertools</a>:</p>
<pre><code>import itertools
for x in itertools.islice(thousand, 400, 500):
pass
</code></pre>
<p>If you need... | 22 | 2009-02-06T22:17:21Z | [
"python",
"loops",
"list"
] |
Is there a way to loop through a sub section of a list in Python | 522,430 | <p>So for a list that has 1000 elements, I want to loop from 400 to 500. How do you do it?</p>
<p>I don't see a way by using the for each and for range techniques.</p>
| 3 | 2009-02-06T22:15:20Z | 524,254 | <p>Using </p>
<pre><code>for element in allElements[400:501]:
doSomething(element)
</code></pre>
<p>makes Python create new object, and might have some impact on memory usage.</p>
<p>Instead I'd use:</p>
<pre><code>for index in xrange(400, 501):
doSomething(allElements[index])
</code></pre>
<p>This way als... | 2 | 2009-02-07T18:08:58Z | [
"python",
"loops",
"list"
] |
Accessing the index in Python 'for' loops | 522,563 | <p>How do I access the index itself for a list like the following?</p>
<pre><code>ints = [8, 23, 45, 12, 78]
</code></pre>
<p>When I loop through it using a <code>for</code> loop, how do I access the loop index, from 1 to 5 in this case?</p>
| 1,512 | 2009-02-06T22:47:54Z | 522,569 | <pre><code>for i in range(len(ints)):
print i, ints[i]
</code></pre>
| 37 | 2009-02-06T22:49:23Z | [
"python",
"loops",
"list"
] |
Accessing the index in Python 'for' loops | 522,563 | <p>How do I access the index itself for a list like the following?</p>
<pre><code>ints = [8, 23, 45, 12, 78]
</code></pre>
<p>When I loop through it using a <code>for</code> loop, how do I access the loop index, from 1 to 5 in this case?</p>
| 1,512 | 2009-02-06T22:47:54Z | 522,576 | <p>Old fashioned way:</p>
<pre><code>for ix in range(len(ints)):
print ints[ix]
</code></pre>
<p>List comprehension:</p>
<pre><code>[ (ix, ints[ix]) for ix in range(len(ints))]
>>> ints
[1, 2, 3, 4, 5]
>>> for ix in range(len(ints)): print ints[ix]
...
1
2
3
4
5
>>> [ (ix, ints[ix]) ... | 6 | 2009-02-06T22:52:06Z | [
"python",
"loops",
"list"
] |
Accessing the index in Python 'for' loops | 522,563 | <p>How do I access the index itself for a list like the following?</p>
<pre><code>ints = [8, 23, 45, 12, 78]
</code></pre>
<p>When I loop through it using a <code>for</code> loop, how do I access the loop index, from 1 to 5 in this case?</p>
| 1,512 | 2009-02-06T22:47:54Z | 522,578 | <p>Using an additional state variable, such as an index variable (which you would normally use in languages such as C or PHP), is considered non-pythonic.</p>
<p>The better option is to use the built-in function <a href="https://docs.python.org/3/library/functions.html#enumerate"><code>enumerate()</code></a>, availabl... | 2,666 | 2009-02-06T22:52:36Z | [
"python",
"loops",
"list"
] |
Accessing the index in Python 'for' loops | 522,563 | <p>How do I access the index itself for a list like the following?</p>
<pre><code>ints = [8, 23, 45, 12, 78]
</code></pre>
<p>When I loop through it using a <code>for</code> loop, how do I access the loop index, from 1 to 5 in this case?</p>
| 1,512 | 2009-02-06T22:47:54Z | 10,459,739 | <p>According to this discussion: <a href="http://bytes.com/topic/python/answers/464012-objects-list-index">http://bytes.com/topic/python/answers/464012-objects-list-index</a></p>
<p>Loop counter iteration</p>
<p>The current idiom for looping over the indices makes use of the built-in 'range' function:</p>
<pre><code... | 5 | 2012-05-05T07:10:07Z | [
"python",
"loops",
"list"
] |
Accessing the index in Python 'for' loops | 522,563 | <p>How do I access the index itself for a list like the following?</p>
<pre><code>ints = [8, 23, 45, 12, 78]
</code></pre>
<p>When I loop through it using a <code>for</code> loop, how do I access the loop index, from 1 to 5 in this case?</p>
| 1,512 | 2009-02-06T22:47:54Z | 19,642,174 | <p>I don't know if the following is pythonic or not, but it uses the Python function <code>enumerate</code> and prints the enumerator and the value.</p>
<pre><code>int_list = [8, 23, 45, 12, 78]
for index in enumerate(int_list):
print index
(0, 8)
(1, 23)
(2, 45)
(3, 12)
(4, 78)
</code></pre>
| 5 | 2013-10-28T18:17:06Z | [
"python",
"loops",
"list"
] |
Accessing the index in Python 'for' loops | 522,563 | <p>How do I access the index itself for a list like the following?</p>
<pre><code>ints = [8, 23, 45, 12, 78]
</code></pre>
<p>When I loop through it using a <code>for</code> loop, how do I access the loop index, from 1 to 5 in this case?</p>
| 1,512 | 2009-02-06T22:47:54Z | 23,886,515 | <p>It's pretty simple to start it from <code>1</code> other than <code>0</code>:</p>
<pre><code>for index in enumerate(iterable, start=1):
print index
</code></pre>
<h2>Note</h2>
<p>Important hint, though a little misleading, since <code>index</code> will be a <code>tuple</code> <code>(idx, item)</code> here.
Goo... | 64 | 2014-05-27T10:04:52Z | [
"python",
"loops",
"list"
] |
Accessing the index in Python 'for' loops | 522,563 | <p>How do I access the index itself for a list like the following?</p>
<pre><code>ints = [8, 23, 45, 12, 78]
</code></pre>
<p>When I loop through it using a <code>for</code> loop, how do I access the loop index, from 1 to 5 in this case?</p>
| 1,512 | 2009-02-06T22:47:54Z | 26,350,953 | <p>The better way to get the index of each element of the sequence:</p>
<pre><code>for indx , value in enumerate(arraySquence):
print (indx , value )
</code></pre>
| -6 | 2014-10-14T00:32:03Z | [
"python",
"loops",
"list"
] |
Accessing the index in Python 'for' loops | 522,563 | <p>How do I access the index itself for a list like the following?</p>
<pre><code>ints = [8, 23, 45, 12, 78]
</code></pre>
<p>When I loop through it using a <code>for</code> loop, how do I access the loop index, from 1 to 5 in this case?</p>
| 1,512 | 2009-02-06T22:47:54Z | 28,072,982 | <blockquote>
<h1>Using a for loop, how do I access the loop index, from 1 to 5 in this case?</h1>
</blockquote>
<p>Use <code>enumerate</code>:</p>
<pre><code>for index, item in enumerate(items):
print(index, item)
</code></pre>
<p>And note that indexes start at zero, so you would get 0 to 4 with this. If you w... | 155 | 2015-01-21T17:11:49Z | [
"python",
"loops",
"list"
] |
Accessing the index in Python 'for' loops | 522,563 | <p>How do I access the index itself for a list like the following?</p>
<pre><code>ints = [8, 23, 45, 12, 78]
</code></pre>
<p>When I loop through it using a <code>for</code> loop, how do I access the loop index, from 1 to 5 in this case?</p>
| 1,512 | 2009-02-06T22:47:54Z | 28,350,332 | <pre><code>ints = [9, 23, 45, 12, 78]
ints.extend([1,2,3,4,5,6,7,8])
for idx, val in enumerate(ints):
print(idx,val)
</code></pre>
<p>This way you can extend a list. Extend means you can add multiple values at a time.</p>
<p>To append this list you have to write the code given below:</p>
<pre><code>ints = [9, 23... | 6 | 2015-02-05T17:28:25Z | [
"python",
"loops",
"list"
] |
Accessing the index in Python 'for' loops | 522,563 | <p>How do I access the index itself for a list like the following?</p>
<pre><code>ints = [8, 23, 45, 12, 78]
</code></pre>
<p>When I loop through it using a <code>for</code> loop, how do I access the loop index, from 1 to 5 in this case?</p>
| 1,512 | 2009-02-06T22:47:54Z | 30,441,272 | <p>First of all, the indexes will be from 0 to 4. Programming languages start counting from 0; don't forget that or you will come across an index out of bounds exception. All you need in the for loop is a variable counting from 0 to 4 like so:</p>
<pre><code>for x in range(0, 5):
</code></pre>
<p>Keep in mind that I ... | 4 | 2015-05-25T15:08:34Z | [
"python",
"loops",
"list"
] |
Accessing the index in Python 'for' loops | 522,563 | <p>How do I access the index itself for a list like the following?</p>
<pre><code>ints = [8, 23, 45, 12, 78]
</code></pre>
<p>When I loop through it using a <code>for</code> loop, how do I access the loop index, from 1 to 5 in this case?</p>
| 1,512 | 2009-02-06T22:47:54Z | 30,441,543 | <p>You can do it with this code:</p>
<pre><code>ints = [8, 23, 45, 12, 78]
index = 0
for value in (ints):
index +=1
print index, value
</code></pre>
<p>Use this code if you need to reset the index value at the end of the loop:</p>
<pre><code>ints = [8, 23, 45, 12, 78]
index = 0
for value in (ints):
ind... | 1 | 2015-05-25T15:26:58Z | [
"python",
"loops",
"list"
] |
Accessing the index in Python 'for' loops | 522,563 | <p>How do I access the index itself for a list like the following?</p>
<pre><code>ints = [8, 23, 45, 12, 78]
</code></pre>
<p>When I loop through it using a <code>for</code> loop, how do I access the loop index, from 1 to 5 in this case?</p>
| 1,512 | 2009-02-06T22:47:54Z | 33,332,541 | <p>May be cleaner sometimes:</p>
<pre><code>index_i = 0
for i in R
...
index_i += 1
</code></pre>
| -2 | 2015-10-25T17:12:47Z | [
"python",
"loops",
"list"
] |
Accessing the index in Python 'for' loops | 522,563 | <p>How do I access the index itself for a list like the following?</p>
<pre><code>ints = [8, 23, 45, 12, 78]
</code></pre>
<p>When I loop through it using a <code>for</code> loop, how do I access the loop index, from 1 to 5 in this case?</p>
| 1,512 | 2009-02-06T22:47:54Z | 38,764,000 | <p>The fastest way to access indexes of list within loop in <strong>Python 2.7</strong> is to use the <a href="https://docs.python.org/2/library/functions.html#range" rel="nofollow">range method</a> for small lists and <a href="https://docs.python.org/2/library/functions.html#enumerate" rel="nofollow">enumerate method<... | 4 | 2016-08-04T09:49:50Z | [
"python",
"loops",
"list"
] |
AppEngine: Maintaining DataStore Consistency When Creating Records | 522,586 | <p>I've hit a small dilemma! I have a handler called vote; when it is invoked it sets a user's vote to whatever they have picked. To remember what options they previously picked, I store a VoteRecord options which details what their current vote is set to.</p>
<p>Of course, the first time they vote, I have to create t... | 3 | 2009-02-06T22:55:04Z | 523,057 | <p>The issue is this part: </p>
<pre><code>if vote.count(1) == 0:
obj = VoteRecord()
obj.user = user
obj.option = option
obj.put()
</code></pre>
<p>Without a transaction, your code could run in this order in two interpreter instances:</p>
<pre><code>if vote.count(1) == 0:
obj = VoteRecord()
o... | 1 | 2009-02-07T03:19:59Z | [
"python",
"google-app-engine",
"gae-datastore",
"consistency",
"gae-ds-transactions"
] |
AppEngine: Maintaining DataStore Consistency When Creating Records | 522,586 | <p>I've hit a small dilemma! I have a handler called vote; when it is invoked it sets a user's vote to whatever they have picked. To remember what options they previously picked, I store a VoteRecord options which details what their current vote is set to.</p>
<p>Of course, the first time they vote, I have to create t... | 3 | 2009-02-06T22:55:04Z | 932,242 | <p>The easiest way to do this is to use key names for your vote objects, and use Model.get_or_insert. First, come up with a naming scheme for your key names - naming it after the poll is a good idea - and then do a get_or_insert to fetch or create the relevant entity:</p>
<pre><code>vote = VoteRecord.get_or_insert(pol... | 3 | 2009-05-31T15:29:25Z | [
"python",
"google-app-engine",
"gae-datastore",
"consistency",
"gae-ds-transactions"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.