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 |
|---|---|---|---|---|---|---|---|---|---|
Convert datetime fields in Chrome history file (sqlite) to readable format | 2,141,537 | <p>Working on a script to collect users browser history with time stamps ( educational setting).
Firefox 3 history is kept in a sqlite file, and stamps are in UNIX epoch time... getting them and converting to readable format via a SQL command in python is pretty straightforward:</p>
<pre><code>sql_select = """ SELECT ... | 9 | 2010-01-26T18:08:46Z | 4,112,026 | <p>Try this:</p>
<pre><code>sql_select = """ SELECT datetime(last_visit_time/1000000-11644473600,'unixepoch','localtime'),
url
FROM urls
ORDER BY last_visit_time DESC
"""
get_hist = list(cursor.execute (sql_select))
</code></pre>
<p>Or something ... | 13 | 2010-11-06T05:15:02Z | [
"python",
"datetime",
"sqlite3"
] |
python gstreamer for windows | 2,141,569 | <p>I want to use Python bindings for GStreamer on windows. But looking at the INSTALL file, the gstreamer does it in the unix way. (make make install) . I don't want to install cygwin or other windowsunix environments. </p>
<p>Is there a GPL binary distribution of GStreamer available somewhere? (or a script that can j... | 4 | 2010-01-26T18:14:36Z | 2,141,597 | <p><a href="http://gstreamer.freedesktop.org/pkg/windows/releases/gst-python/" rel="nofollow">http://gstreamer.freedesktop.org/pkg/windows/releases/gst-python/</a> ?</p>
| 0 | 2010-01-26T18:20:32Z | [
"python",
"audio",
"gstreamer"
] |
python gstreamer for windows | 2,141,569 | <p>I want to use Python bindings for GStreamer on windows. But looking at the INSTALL file, the gstreamer does it in the unix way. (make make install) . I don't want to install cygwin or other windowsunix environments. </p>
<p>Is there a GPL binary distribution of GStreamer available somewhere? (or a script that can j... | 4 | 2010-01-26T18:14:36Z | 2,141,778 | <p>I will answer my own question. </p>
<p>Found this link GStreamer WinBuilds that has a binary available for Python Gestreamer ( Python2.6) <a href="http://www.gstreamer-winbuild.ylatuya.es/doku.php?id=download#developers_files" rel="nofollow">http://www.gstreamer-winbuild.ylatuya.es/doku.php?id=download#developers_f... | 3 | 2010-01-26T18:52:14Z | [
"python",
"audio",
"gstreamer"
] |
Stored Procedures in Python for PostgreSQL | 2,141,589 | <p>we are still pretty new to Postgres and came from Microsoft Sql Server.</p>
<p>We are wanting to write some stored procedures now. Well, after struggling to get something more complicated than a <code>hello world</code> to work in pl/pgsql, we decided it's better if we are going to learn a new language we might as ... | 9 | 2010-01-26T18:19:45Z | 2,142,128 | <ol>
<li>Depends on what operations you're doing.</li>
<li>Well, combine that with a general Python documentation, and that's about what you have.</li>
<li>No. Again, depends on what you're doing. If you're only going to run a query once, no point in preparing it separately.</li>
<li>If you are using persistent connect... | 8 | 2010-01-26T19:48:55Z | [
"python",
"postgresql",
"stored-procedures",
"plpgsql"
] |
Pymedia installation on Windows with Python 2.6 | 2,141,701 | <p>I am trying to install latest version of Pymedia from sources. I have Python2.6 and there is no binary available. </p>
<p>Started with:</p>
<pre><code>python setup.py build
</code></pre>
<p>and got the following messages:</p>
<pre><code>Using WINDOWS configuration...
Path for OGG not found.
Path for VORBIS no... | 6 | 2010-01-26T18:38:43Z | 2,141,758 | <p>You need to install all of those modules separately, in a similar fashion (<code>python setup.py install</code>).</p>
<p>Those other modules are just prerequisites to pymedia, and need to be installed prior to installing pymedia.
It's kind of a pain with some libraries, and <a href="http://pypi.python.org/pypi/setu... | 1 | 2010-01-26T18:49:16Z | [
"python"
] |
Pymedia installation on Windows with Python 2.6 | 2,141,701 | <p>I am trying to install latest version of Pymedia from sources. I have Python2.6 and there is no binary available. </p>
<p>Started with:</p>
<pre><code>python setup.py build
</code></pre>
<p>and got the following messages:</p>
<pre><code>Using WINDOWS configuration...
Path for OGG not found.
Path for VORBIS no... | 6 | 2010-01-26T18:38:43Z | 3,670,423 | <p>Somebody has done it, if you're just after pymedia for python2.6 on windows:</p>
<p>Have a look here:</p>
<p><a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/">http://www.lfd.uci.edu/~gohlke/pythonlibs/</a></p>
<p>There's also a version for python2.7</p>
| 8 | 2010-09-08T17:34:47Z | [
"python"
] |
Python: Prevent argument array being globally modified | 2,141,739 | <p>I have a problem with python here. If I pass an array through a recursive function that adds something to the array each time it is called, the array is modified in each instance </p>
<p><strong>Code:</strong></p>
<pre><code>def test(n,myList):
if n>0:
myList.append("Test")
print ( "BEFORE C... | 1 | 2010-01-26T18:46:58Z | 2,141,761 | <p>Your attempted solution does not actually copy the array. It assigns a new name to the same array. If you want to create a new array, try this:</p>
<pre><code>my_new_list = my_list[:]
</code></pre>
<p>That creates a list containing a slice of the old list, where the slice starts at the beginning, and ends at the... | 5 | 2010-01-26T18:50:08Z | [
"python"
] |
Python: Prevent argument array being globally modified | 2,141,739 | <p>I have a problem with python here. If I pass an array through a recursive function that adds something to the array each time it is called, the array is modified in each instance </p>
<p><strong>Code:</strong></p>
<pre><code>def test(n,myList):
if n>0:
myList.append("Test")
print ( "BEFORE C... | 1 | 2010-01-26T18:46:58Z | 4,559,384 | <p>You can use <code>copy.deepcopy()</code> to return a non-linked list. This also works for nested lists and dicts.</p>
| 1 | 2010-12-30T01:41:48Z | [
"python"
] |
Fastest Way to Update a bunch of records in queryset in Django | 2,141,769 | <p>I have a queryset with a few million records. I need to update a Boolean Value, fundamentally toggle it, so that in the database table the values are reset. What's the fastest way to do that?</p>
<p>I tried traversing the queryset and updating and saving each record, that obviously takes ages? We need to do this ve... | 5 | 2010-01-26T18:50:50Z | 2,141,791 | <p>See the <a href="http://docs.djangoproject.com/en/1.1/topics/db/queries/#updating-multiple-objects-at-once" rel="nofollow">documentation</a>: </p>
<pre><code>Entry.objects.all().update(value= not F('value'))
</code></pre>
| 4 | 2010-01-26T18:53:56Z | [
"python",
"database",
"django",
"django-queryset"
] |
Fastest Way to Update a bunch of records in queryset in Django | 2,141,769 | <p>I have a queryset with a few million records. I need to update a Boolean Value, fundamentally toggle it, so that in the database table the values are reset. What's the fastest way to do that?</p>
<p>I tried traversing the queryset and updating and saving each record, that obviously takes ages? We need to do this ve... | 5 | 2010-01-26T18:50:50Z | 4,230,081 | <p>Actually, that didn't work out for me.</p>
<p>The following did:</p>
<p><code>Entry.objects.all().update(value=(F('value')==False))</code></p>
| 0 | 2010-11-19T22:49:31Z | [
"python",
"database",
"django",
"django-queryset"
] |
Retrieving text from password field [python][pyqt4] | 2,141,808 | <pre><code>def welcomeStage (self):
self.test = QtGui.QLineEdit (self)
self.test.move (50, 150)
QtCore.QObject.connect (self.test, QtCore.SIGNAL ('returnPressed()'), self.passwordStage)
def passwordStage (self):
self.email = self.test.text()
self.test.clear()
self.test.setEchoMode (QtG... | 2 | 2010-01-26T18:56:25Z | 2,141,924 | <p>I can't offer a fix for using a <code>QLineEdit</code>, but you can get passwords in a <code>QInputDialog</code> by specifying <strong>mode</strong> in the <code>getText()</code> method. Like this:</p>
<pre><code>diag = QtGui.QInputDialog
s = None
while s is None:
qstring, ok = diag.getText(self, QtCore.QString... | 0 | 2010-01-26T19:16:38Z | [
"python",
"user-interface",
"passwords",
"pyqt4"
] |
Using Python to program MS Office macros? | 2,141,967 | <p>I've recently taken it as a project to teach myself how to program in Python. Overall, I must say that I'm impressed with it.</p>
<p>In the past I've typically stuck to programming in VBA mostly for MS Excel (but also a bit in MS Access and Word) and have struggled to find ways to make it do things that Python can... | 23 | 2010-01-26T19:23:23Z | 2,141,981 | <p>Yes, absolutely. You want to use <code>win32com</code> module, which is part of pywin32 (<a href="http://sourceforge.net/projects/pywin32/">get it here</a>).</p>
<p>I've found you can really simplify Python integration by writing a macro in VBA for Python to use, and then just have Python call the macro. It will lo... | 18 | 2010-01-26T19:26:33Z | [
"python",
"excel",
"vba",
"ms-office"
] |
Using Python to program MS Office macros? | 2,141,967 | <p>I've recently taken it as a project to teach myself how to program in Python. Overall, I must say that I'm impressed with it.</p>
<p>In the past I've typically stuck to programming in VBA mostly for MS Excel (but also a bit in MS Access and Word) and have struggled to find ways to make it do things that Python can... | 23 | 2010-01-26T19:23:23Z | 2,142,695 | <p>Or have a look at IronPython. IPy is a native .NET implementation of Python 2.6, you can find it at <a href="http://www.codeplex.com/ironpython">http://www.codeplex.com/ironpython</a>. </p>
<p>We have used it for several projects. You can use it "from the outside" using COM or - as we do - write a Excel AddIn with... | 7 | 2010-01-26T21:14:10Z | [
"python",
"excel",
"vba",
"ms-office"
] |
Using Python to program MS Office macros? | 2,141,967 | <p>I've recently taken it as a project to teach myself how to program in Python. Overall, I must say that I'm impressed with it.</p>
<p>In the past I've typically stuck to programming in VBA mostly for MS Excel (but also a bit in MS Access and Word) and have struggled to find ways to make it do things that Python can... | 23 | 2010-01-26T19:23:23Z | 2,142,749 | <p>There is a set of cross platform Python utilities - called xlrd, xlwt, and xlutils - for reading & writing Excel files. There are some limitations (e.g. I don't think they can process macros), but they do allow you to work with Excel files on non-Windows platforms, if that's of use to you. See: <a href="http:... | 7 | 2010-01-26T21:23:50Z | [
"python",
"excel",
"vba",
"ms-office"
] |
Using Python to program MS Office macros? | 2,141,967 | <p>I've recently taken it as a project to teach myself how to program in Python. Overall, I must say that I'm impressed with it.</p>
<p>In the past I've typically stuck to programming in VBA mostly for MS Excel (but also a bit in MS Access and Word) and have struggled to find ways to make it do things that Python can... | 23 | 2010-01-26T19:23:23Z | 7,558,637 | <p>The xlrd, xlwt, and xlutils packages mentioned above can only read and write .xls files which have size limitations of 65,000 rows and 256 columns. Aside from that it is a good tool.</p>
<p>But I have moved on to another python-excel package, OpenPyXL, which can read and write .xlsx files. Also I find it easy to us... | 4 | 2011-09-26T17:10:29Z | [
"python",
"excel",
"vba",
"ms-office"
] |
Using Python to program MS Office macros? | 2,141,967 | <p>I've recently taken it as a project to teach myself how to program in Python. Overall, I must say that I'm impressed with it.</p>
<p>In the past I've typically stuck to programming in VBA mostly for MS Excel (but also a bit in MS Access and Word) and have struggled to find ways to make it do things that Python can... | 23 | 2010-01-26T19:23:23Z | 19,346,444 | <p>here is a useful link:</p>
<p><a href="http://continuum.io/using-excel" rel="nofollow">http://continuum.io/using-excel</a></p>
<ol>
<li><p>Try Pyvot â A Python to/from Excel Connector from Microsoft:</p></li>
</ol>
<p><a href="http://pytools.codeplex.com/wikipage?title=Pyvot" rel="nofollow">http://pytools.codep... | 2 | 2013-10-13T14:43:11Z | [
"python",
"excel",
"vba",
"ms-office"
] |
Using Python to program MS Office macros? | 2,141,967 | <p>I've recently taken it as a project to teach myself how to program in Python. Overall, I must say that I'm impressed with it.</p>
<p>In the past I've typically stuck to programming in VBA mostly for MS Excel (but also a bit in MS Access and Word) and have struggled to find ways to make it do things that Python can... | 23 | 2010-01-26T19:23:23Z | 29,500,419 | <p>This is a question from a long time ago, but I'm putting it here so others can point to it in their search.</p>
<p>One option not discussed here, which I use all the time, is to create a COM server from Python and call it from VBA in any Office application. There is a good tutorial of doing COM server with Python a... | 1 | 2015-04-07T20:11:44Z | [
"python",
"excel",
"vba",
"ms-office"
] |
Ranking within Django ORM or SQL? | 2,141,978 | <p><strong>I have a huge list ranked by various values</strong> (eg. scores)</p>
<p>So I grab the list ordered by these values:</p>
<pre><code>players = Player.objects.order_by('-score', '-karma')
</code></pre>
<hr>
<p>I would like to:</p>
<ul>
<li>Grab a player and get the <strong>neighbouring players</strong></l... | 3 | 2010-01-26T19:25:55Z | 2,142,264 | <p>These sorts of things are always very difficult to do. You'll need multiple queries for each one.</p>
<p>So, to get the players just before and after your position when ordered by score, first you'll need to work out what that position is. (Note that this assumes that you can't have more than one person with the sa... | 8 | 2010-01-26T20:09:21Z | [
"python",
"sql",
"django",
"django-models",
"django-orm"
] |
Ranking within Django ORM or SQL? | 2,141,978 | <p><strong>I have a huge list ranked by various values</strong> (eg. scores)</p>
<p>So I grab the list ordered by these values:</p>
<pre><code>players = Player.objects.order_by('-score', '-karma')
</code></pre>
<hr>
<p>I would like to:</p>
<ul>
<li>Grab a player and get the <strong>neighbouring players</strong></l... | 3 | 2010-01-26T19:25:55Z | 2,142,516 | <p>To get the ranking of the user:</p>
<pre><code>(SELECT * FROM (
SELECT
RANK() OVER (ORDER BY Score desc ,Karma desc) AS ranking,
Id,
Username,
Score, karma
FROM Players
) AS players_ranked_by_score
where Id = id_of_user
</code></pre>
<p>Where id_of_user is the parameter containing the id of t... | 1 | 2010-01-26T20:48:30Z | [
"python",
"sql",
"django",
"django-models",
"django-orm"
] |
Ranking within Django ORM or SQL? | 2,141,978 | <p><strong>I have a huge list ranked by various values</strong> (eg. scores)</p>
<p>So I grab the list ordered by these values:</p>
<pre><code>players = Player.objects.order_by('-score', '-karma')
</code></pre>
<hr>
<p>I would like to:</p>
<ul>
<li>Grab a player and get the <strong>neighbouring players</strong></l... | 3 | 2010-01-26T19:25:55Z | 30,982,177 | <p>I did this with 3 queries with ORM, but I think less count of queries would be better:</p>
<pre><code>user_rank = Score.objects.filter(high_score__gt=user_score.high_score).count() + 1
neighbour_scores = Score.objects.filter(game_id=gme,~Q(user_id = usr),high_score__gte=user_score.high_score).order_by('high_score'... | 0 | 2015-06-22T14:13:23Z | [
"python",
"sql",
"django",
"django-models",
"django-orm"
] |
Django: Best way to implement "status" field in modules | 2,142,055 | <p>I have a field in my module that is used to hold the status of the object.
So far I have used:</p>
<pre><code>ORDER_STATUS = ((0, 'Started'), (1, 'Done'), (2, 'Error'))
status = models.SmallIntegerField(choices=ORDER_STATUS)
</code></pre>
<p>Its easy to convert one way:</p>
<pre><code>def status_str(self): return... | 22 | 2010-01-26T19:39:59Z | 2,142,245 | <p>you can try enum package:
<a href="http://pypi.python.org/pypi/enum/" rel="nofollow">http://pypi.python.org/pypi/enum/</a></p>
| 2 | 2010-01-26T20:05:54Z | [
"python",
"django"
] |
Django: Best way to implement "status" field in modules | 2,142,055 | <p>I have a field in my module that is used to hold the status of the object.
So far I have used:</p>
<pre><code>ORDER_STATUS = ((0, 'Started'), (1, 'Done'), (2, 'Error'))
status = models.SmallIntegerField(choices=ORDER_STATUS)
</code></pre>
<p>Its easy to convert one way:</p>
<pre><code>def status_str(self): return... | 22 | 2010-01-26T19:39:59Z | 2,142,268 | <p>Maybe this question helps you: <a href="http://stackoverflow.com/questions/1117564/set-django-integerfield-by-choices-name">Set Django IntegerField by choices=⦠name</a>.<br>
I quote from the accepted answer (with adjustments ;)):<br>
Put this into your class (<code>STATUS_CHOICES</code> will be the list that is h... | 24 | 2010-01-26T20:09:50Z | [
"python",
"django"
] |
Django: Best way to implement "status" field in modules | 2,142,055 | <p>I have a field in my module that is used to hold the status of the object.
So far I have used:</p>
<pre><code>ORDER_STATUS = ((0, 'Started'), (1, 'Done'), (2, 'Error'))
status = models.SmallIntegerField(choices=ORDER_STATUS)
</code></pre>
<p>Its easy to convert one way:</p>
<pre><code>def status_str(self): return... | 22 | 2010-01-26T19:39:59Z | 2,142,292 | <p>You don't need your <code>status_str</code> method - Django automatically provides a <code>get_status_display()</code> which does exactly the same thing.</p>
<p>To reverse, you could use this:</p>
<pre><code>def set_order_status(self, val):
status_dict = dict(ORDER_STATUS)
self.status = status_dict[val][0]... | 2 | 2010-01-26T20:13:50Z | [
"python",
"django"
] |
Django: Best way to implement "status" field in modules | 2,142,055 | <p>I have a field in my module that is used to hold the status of the object.
So far I have used:</p>
<pre><code>ORDER_STATUS = ((0, 'Started'), (1, 'Done'), (2, 'Error'))
status = models.SmallIntegerField(choices=ORDER_STATUS)
</code></pre>
<p>Its easy to convert one way:</p>
<pre><code>def status_str(self): return... | 22 | 2010-01-26T19:39:59Z | 2,142,310 | <p>what I usually do for this situation is:</p>
<p>models.py</p>
<pre><code>from static import ORDER_STATUS
status = models.PositiveSmallIntegerField(choices=ORDER_STATUS)
</code></pre>
<p>static.py</p>
<pre><code>ORDER_STATUS = ((0, 'Started'), (1, 'Done'), (2, 'Error'))
ORDER_STATUS_DICT = dict((v, k) for k, ... | 6 | 2010-01-26T20:15:50Z | [
"python",
"django"
] |
Django: Best way to implement "status" field in modules | 2,142,055 | <p>I have a field in my module that is used to hold the status of the object.
So far I have used:</p>
<pre><code>ORDER_STATUS = ((0, 'Started'), (1, 'Done'), (2, 'Error'))
status = models.SmallIntegerField(choices=ORDER_STATUS)
</code></pre>
<p>Its easy to convert one way:</p>
<pre><code>def status_str(self): return... | 22 | 2010-01-26T19:39:59Z | 2,142,314 | <p>Maybe stick a method on the model, like:</p>
<pre><code>def status_code(self, text):
return [n for (n, t) in self.ORDER_STATUS if t == text][0]
</code></pre>
<p>Then youâd do:</p>
<pre><code>order.status = order.status_code('Error')
</code></pre>
| 0 | 2010-01-26T20:16:14Z | [
"python",
"django"
] |
Django: Best way to implement "status" field in modules | 2,142,055 | <p>I have a field in my module that is used to hold the status of the object.
So far I have used:</p>
<pre><code>ORDER_STATUS = ((0, 'Started'), (1, 'Done'), (2, 'Error'))
status = models.SmallIntegerField(choices=ORDER_STATUS)
</code></pre>
<p>Its easy to convert one way:</p>
<pre><code>def status_str(self): return... | 22 | 2010-01-26T19:39:59Z | 26,009,906 | <p>This is a very late answer, however for completeness I should mention that django-model-utils already contains a <a href="https://django-model-utils.readthedocs.org/en/latest/fields.html#statusfield" rel="nofollow">StatusField</a> and even better a <a href="https://django-model-utils.readthedocs.org/en/latest/models... | 4 | 2014-09-24T06:21:22Z | [
"python",
"django"
] |
Django: Best way to implement "status" field in modules | 2,142,055 | <p>I have a field in my module that is used to hold the status of the object.
So far I have used:</p>
<pre><code>ORDER_STATUS = ((0, 'Started'), (1, 'Done'), (2, 'Error'))
status = models.SmallIntegerField(choices=ORDER_STATUS)
</code></pre>
<p>Its easy to convert one way:</p>
<pre><code>def status_str(self): return... | 22 | 2010-01-26T19:39:59Z | 38,281,013 | <p>don't do all those things.just make change in views.py as follows</p>
<pre><code> context['value'] = Model_name.objects.order_by('-choice')
</code></pre>
<p>where </p>
<pre><code> choice = ('pending','solved','closed')
</code></pre>
| 0 | 2016-07-09T10:49:25Z | [
"python",
"django"
] |
Strip whitespace in generated HTML using pure Python code | 2,142,108 | <p>I am using Jinja2 to generate HTML files which are typically very huge in size. I noticed that the generated HTML had a lot of whitespace. Is there a pure-Python tool that I can use to minimize this HTML? When I say "minimize", I mean remove unnecessary whitespace from the HTML (much like Google does -- look at the ... | 8 | 2010-01-26T19:46:59Z | 2,142,154 | <p>If you just want to get rid of excess whitespace, you can use:</p>
<pre><code>>>> import re
>>> html_string = re.sub(r'\s\s+', ' ', html_string)
</code></pre>
<p>or:</p>
<pre><code>>>> html_string = ' '.join(html_string.split())
</code></pre>
<p>If you want to do something more complic... | 2 | 2010-01-26T19:52:36Z | [
"python",
"html",
"whitespace",
"strip",
"jinja2"
] |
Strip whitespace in generated HTML using pure Python code | 2,142,108 | <p>I am using Jinja2 to generate HTML files which are typically very huge in size. I noticed that the generated HTML had a lot of whitespace. Is there a pure-Python tool that I can use to minimize this HTML? When I say "minimize", I mean remove unnecessary whitespace from the HTML (much like Google does -- look at the ... | 8 | 2010-01-26T19:46:59Z | 2,142,194 | <p>You might also investigate <a href="http://jinja.pocoo.org/2/documentation/templates#whitespace-control">Jinja's built-in whitespace control</a>, which might alleviate some of the need for manually removing whitespace after your templates have been rendered.</p>
<p>Quoting <a href="http://jinja.pocoo.org/2/document... | 8 | 2010-01-26T19:58:12Z | [
"python",
"html",
"whitespace",
"strip",
"jinja2"
] |
Strip whitespace in generated HTML using pure Python code | 2,142,108 | <p>I am using Jinja2 to generate HTML files which are typically very huge in size. I noticed that the generated HTML had a lot of whitespace. Is there a pure-Python tool that I can use to minimize this HTML? When I say "minimize", I mean remove unnecessary whitespace from the HTML (much like Google does -- look at the ... | 8 | 2010-01-26T19:46:59Z | 16,868,601 | <p>I found <a href="https://pypi.python.org/pypi/slimmer/" rel="nofollow">python slimmer</a> library, perfect for what you need to do.</p>
<pre><code>from slimmer import html_slimmer # or xhtml_slimmer, css_slimmer
html = html_slimmer(html)
</code></pre>
| 4 | 2013-06-01T02:46:08Z | [
"python",
"html",
"whitespace",
"strip",
"jinja2"
] |
Implementation of an async method in Python DBus | 2,142,115 | <p>How do I implement an async method in Python DBus? An Example below:</p>
<pre><code>class LastfmApi(dbus.service.Object):
def __init__(self):
bus_name = dbus.service.BusName('fm.lastfm.api', bus=dbus.SessionBus())
dbus.service.Object.__init__(self, bus_name, '/')
@dbus.service.method('fm.la... | 5 | 2010-01-26T19:47:41Z | 2,142,503 | <p>I haven't tried this, but reading the documentation for <code>dbus.service.method</code> reveals the <code>async_callbacks</code> parameter. It sounds like one uses this parameter to provide an asynchronous result. For example:</p>
<pre><code>@dbus.service.method('fm.last.api.account', out_signature="s",
... | 6 | 2010-01-26T20:47:01Z | [
"python",
"twisted",
"asynchronous",
"dbus"
] |
Handle 404 throw by code in appengine | 2,142,198 | <p>I manage the "real" 404 errors in this way:</p>
<pre><code>application = webapp.WSGIApplication([
('/', MainPage),
#Some others urls
('/.*',Trow404) #I got the 404 page
],debug=False)
</code></pre>
<p>But in some parts of my code i throw a 404 error</p>
<pre><code>self.error(404)
</code></pre>
... | 5 | 2010-01-26T19:58:47Z | 2,143,594 | <p>Piggy backing on Derek Dahmer's answer (I don't have the karma to leave comments), you can then add this to Throw404 to send the proper header:</p>
<pre><code>class Throw404(webapp.RequestHandler):
def get(self):
self.error(404)
# your 404 handler goes here
</code></pre>
| 0 | 2010-01-26T23:50:48Z | [
"python",
"google-app-engine",
"http-status-code-404"
] |
Handle 404 throw by code in appengine | 2,142,198 | <p>I manage the "real" 404 errors in this way:</p>
<pre><code>application = webapp.WSGIApplication([
('/', MainPage),
#Some others urls
('/.*',Trow404) #I got the 404 page
],debug=False)
</code></pre>
<p>But in some parts of my code i throw a 404 error</p>
<pre><code>self.error(404)
</code></pre>
... | 5 | 2010-01-26T19:58:47Z | 2,153,398 | <p>The easiest way to do this is to override the error() method on your base handler (presuming you have one) to generate the 404 page, and call that from your regular handlers and your 404 handler. For example:</p>
<pre><code>class BaseHandler(webapp.RequestHandler):
def error(self, code):
super(BaseHandler, se... | 9 | 2010-01-28T09:19:58Z | [
"python",
"google-app-engine",
"http-status-code-404"
] |
What are acceptable use-cases for python's `assert` statement? | 2,142,202 | <p>I often use python's assert statement to check user input and fail-fast if we're in a corrupt state. I'm aware that assert gets removed when python with the <code>-o</code>(optimized) flag. I personally don't run any of my apps in optimized mode, but it feels like I should stay away from assert just in-case.</p>
<p... | 22 | 2010-01-26T19:58:59Z | 2,142,233 | <p><strong>If being graceful is impossible, be dramatic</strong></p>
<p>Here is the correct version of your code:</p>
<pre><code>if filename.endswith('.jpg'):
# convert it to the PNG we want
try:
filename = convert_jpg_to_png_tmpfile(filename)
except PNGCreateError:
# Tell the user their j... | 16 | 2010-01-26T20:03:57Z | [
"python",
"assert"
] |
What are acceptable use-cases for python's `assert` statement? | 2,142,202 | <p>I often use python's assert statement to check user input and fail-fast if we're in a corrupt state. I'm aware that assert gets removed when python with the <code>-o</code>(optimized) flag. I personally don't run any of my apps in optimized mode, but it feels like I should stay away from assert just in-case.</p>
<p... | 22 | 2010-01-26T19:58:59Z | 2,142,249 | <p>Personally, I use <code>assert</code> for unexpected errors, or things you don't expect to happen in real world usage. Exceptions should be used whenever dealing with input from a user or file, as they can be caught and you can tell the user "Hey, I was expecting a .jpg file!!"</p>
| 4 | 2010-01-26T20:06:16Z | [
"python",
"assert"
] |
What are acceptable use-cases for python's `assert` statement? | 2,142,202 | <p>I often use python's assert statement to check user input and fail-fast if we're in a corrupt state. I'm aware that assert gets removed when python with the <code>-o</code>(optimized) flag. I personally don't run any of my apps in optimized mode, but it feels like I should stay away from assert just in-case.</p>
<p... | 22 | 2010-01-26T19:58:59Z | 2,142,354 | <p><code>assert</code> is best used for code that should be active during testing when you are surely going to run without <code>-o</code></p>
<p>You may personally never run with <code>-o</code> but what happens if your code ends up in a larger system and the admin wants to run it with <code>-o</code>? </p>
<p>It's... | 7 | 2010-01-26T20:23:26Z | [
"python",
"assert"
] |
What are acceptable use-cases for python's `assert` statement? | 2,142,202 | <p>I often use python's assert statement to check user input and fail-fast if we're in a corrupt state. I'm aware that assert gets removed when python with the <code>-o</code>(optimized) flag. I personally don't run any of my apps in optimized mode, but it feels like I should stay away from assert just in-case.</p>
<p... | 22 | 2010-01-26T19:58:59Z | 2,142,358 | <p>Assertions should be used for expressing <strong>invariants</strong>, or <strong>preconditions</strong>.<br>
In your example, you are using them for checking unexpected input - and that's a completely different <em>class</em> of exceptions.</p>
<p>Depending on the requirements, it may be perfectly OK to raise an ex... | 23 | 2010-01-26T20:23:51Z | [
"python",
"assert"
] |
What are acceptable use-cases for python's `assert` statement? | 2,142,202 | <p>I often use python's assert statement to check user input and fail-fast if we're in a corrupt state. I'm aware that assert gets removed when python with the <code>-o</code>(optimized) flag. I personally don't run any of my apps in optimized mode, but it feels like I should stay away from assert just in-case.</p>
<p... | 22 | 2010-01-26T19:58:59Z | 2,142,394 | <p>Totally valid. The assertion is a formal claim about the state of your program.</p>
<p>You should use them for things which can't be proven. However, they're handy for things you <em>think</em> you can prove as a check on your logic.</p>
<p>Another example.</p>
<pre><code>def fastExp( a, b ):
assert isinsta... | 9 | 2010-01-26T20:26:59Z | [
"python",
"assert"
] |
What are acceptable use-cases for python's `assert` statement? | 2,142,202 | <p>I often use python's assert statement to check user input and fail-fast if we're in a corrupt state. I'm aware that assert gets removed when python with the <code>-o</code>(optimized) flag. I personally don't run any of my apps in optimized mode, but it feels like I should stay away from assert just in-case.</p>
<p... | 22 | 2010-01-26T19:58:59Z | 19,184,762 | <p>The Python Wiki has a <a href="https://wiki.python.org/moin/UsingAssertionsEffectively" rel="nofollow">great guide</a> on using Assertion effectively.</p>
<p>The answers above don't necessary clarify the -O objection when running Python.
The quote the above page: </p>
<blockquote>
<p>If Python is started with th... | 1 | 2013-10-04T15:12:28Z | [
"python",
"assert"
] |
What are acceptable use-cases for python's `assert` statement? | 2,142,202 | <p>I often use python's assert statement to check user input and fail-fast if we're in a corrupt state. I'm aware that assert gets removed when python with the <code>-o</code>(optimized) flag. I personally don't run any of my apps in optimized mode, but it feels like I should stay away from assert just in-case.</p>
<p... | 22 | 2010-01-26T19:58:59Z | 19,185,709 | <p>S.Lott's answer is the best one. But this was too long to just add to a comment on his, so I put it here. Anyways, it's how I think about assert, which is basically that it's just a shorthand way to do #ifdef DEBUG.</p>
<p>Anyways, there are two schools of thought about input checking. You can do it at the target, ... | 1 | 2013-10-04T16:00:12Z | [
"python",
"assert"
] |
Python: Analysis on CSV files 100,000 lines x 40 columns | 2,142,415 | <p>I have about a 100 csv files each 100,000 x 40 <strike>rows</strike> columns. I'd like to do some statistical analysis on it, pull out some sample data, plot general trends, do variance and R-square analysis, and plot some spectra diagrams. For now, I'm considering numpy for the analysis.</p>
<p>I was wondering wha... | 11 | 2010-01-26T20:30:30Z | 2,142,469 | <p>I've found that Python + CSV is probably the fastest, and simplest way to do some kinds of statistical processing. </p>
<p>We do a fair amount of reformatting and correcting for odd data errors, so Python helps us.</p>
<p>The availability of Python's functional programming features makes this particularly simple.... | 12 | 2010-01-26T20:40:41Z | [
"python",
"numpy"
] |
Python: Analysis on CSV files 100,000 lines x 40 columns | 2,142,415 | <p>I have about a 100 csv files each 100,000 x 40 <strike>rows</strike> columns. I'd like to do some statistical analysis on it, pull out some sample data, plot general trends, do variance and R-square analysis, and plot some spectra diagrams. For now, I'm considering numpy for the analysis.</p>
<p>I was wondering wha... | 11 | 2010-01-26T20:30:30Z | 2,142,663 | <p>Python is very nice for such kind of data processing, especially if your samples are "rows" and you can process each such row independently:</p>
<pre><code> row1
row2
row3
etc.
</code></pre>
<p>In fact your program can have very small memory footprint, thanks to generators and generator expressions, about which... | 1 | 2010-01-26T21:09:57Z | [
"python",
"numpy"
] |
Python: Analysis on CSV files 100,000 lines x 40 columns | 2,142,415 | <p>I have about a 100 csv files each 100,000 x 40 <strike>rows</strike> columns. I'd like to do some statistical analysis on it, pull out some sample data, plot general trends, do variance and R-square analysis, and plot some spectra diagrams. For now, I'm considering numpy for the analysis.</p>
<p>I was wondering wha... | 11 | 2010-01-26T20:30:30Z | 2,142,794 | <p>I've been having great success using Python and CSV file reading and generation. Using a modest Core 2 Duo laptop I have been able to store close to the same amount of data as you and process it in memory in a few minutes. My main advice in doing this is to split up your jobs so that you can do things in separate st... | 1 | 2010-01-26T21:31:03Z | [
"python",
"numpy"
] |
Python: Analysis on CSV files 100,000 lines x 40 columns | 2,142,415 | <p>I have about a 100 csv files each 100,000 x 40 <strike>rows</strike> columns. I'd like to do some statistical analysis on it, pull out some sample data, plot general trends, do variance and R-square analysis, and plot some spectra diagrams. For now, I'm considering numpy for the analysis.</p>
<p>I was wondering wha... | 11 | 2010-01-26T20:30:30Z | 2,142,928 | <p>In general, don't worry too much about the size. If your files get bigger by a factor of 2-3, you <em>might</em> start running out of memory on a 32-bit system. I figure that if each <em>field</em> of the table is 100 bytes, i.e., each row is 4000 bytes, you'll be using roughly 400 MB of RAM to store the data in mem... | 1 | 2010-01-26T21:53:34Z | [
"python",
"numpy"
] |
Python: Analysis on CSV files 100,000 lines x 40 columns | 2,142,415 | <p>I have about a 100 csv files each 100,000 x 40 <strike>rows</strike> columns. I'd like to do some statistical analysis on it, pull out some sample data, plot general trends, do variance and R-square analysis, and plot some spectra diagrams. For now, I'm considering numpy for the analysis.</p>
<p>I was wondering wha... | 11 | 2010-01-26T20:30:30Z | 2,170,045 | <p>For massive datasets you might be interested in <a href="http://root.cern.ch" rel="nofollow">ROOT</a>. It can be used to analyze and very effectively store petabytes of data. It also come with some basic and <a href="http://roofit.sourceforge.net/" rel="nofollow">more</a> <a href="http://tmva.sourceforge.net/" rel="... | 1 | 2010-01-31T00:14:51Z | [
"python",
"numpy"
] |
getting list without k'th element efficiently and non-destructively | 2,142,453 | <p>I have a list in python and I'd like to iterate through it, and selectively construct a list that contains all the elements except the current k'th element. one way I can do it is this:</p>
<pre><code>l = [('a', 1), ('b', 2), ('c', 3)]
for num, elt in enumerate(l):
# construct list without current element
l_wit... | 17 | 2010-01-26T20:36:56Z | 2,142,467 | <pre><code>l = [('a', 1), ('b', 2), ('c', 3)]
k = 1
l_without_num = l[:k] + l[(k + 1):]
</code></pre>
<p>Is this what you want?</p>
| 46 | 2010-01-26T20:40:17Z | [
"python",
"list",
"copying"
] |
getting list without k'th element efficiently and non-destructively | 2,142,453 | <p>I have a list in python and I'd like to iterate through it, and selectively construct a list that contains all the elements except the current k'th element. one way I can do it is this:</p>
<pre><code>l = [('a', 1), ('b', 2), ('c', 3)]
for num, elt in enumerate(l):
# construct list without current element
l_wit... | 17 | 2010-01-26T20:36:56Z | 2,142,488 | <p>It would help if you explained more how you wanted to use it. But you can do the same with list comprehension.</p>
<pre><code>l = [('a', 1), ('b', 2), ('c', 3)]
k = 1
l_without_num = [elt for num, elt in enumerate(l) if not num == k]
</code></pre>
<p>This is also more memory efficient to iterate over if you don't ... | 8 | 2010-01-26T20:45:09Z | [
"python",
"list",
"copying"
] |
getting list without k'th element efficiently and non-destructively | 2,142,453 | <p>I have a list in python and I'd like to iterate through it, and selectively construct a list that contains all the elements except the current k'th element. one way I can do it is this:</p>
<pre><code>l = [('a', 1), ('b', 2), ('c', 3)]
for num, elt in enumerate(l):
# construct list without current element
l_wit... | 17 | 2010-01-26T20:36:56Z | 2,142,519 | <p>Probably not the most efficient, but the functional programmer in me would probably write this.</p>
<pre><code>import operator
from itertools import *
def inits(list):
for i in range(0, len(list)):
yield list[:i]
def tails(list):
for i in range(0, len(list)):
yield list[i+1:]
def withouts(li... | 0 | 2010-01-26T20:48:48Z | [
"python",
"list",
"copying"
] |
getting list without k'th element efficiently and non-destructively | 2,142,453 | <p>I have a list in python and I'd like to iterate through it, and selectively construct a list that contains all the elements except the current k'th element. one way I can do it is this:</p>
<pre><code>l = [('a', 1), ('b', 2), ('c', 3)]
for num, elt in enumerate(l):
# construct list without current element
l_wit... | 17 | 2010-01-26T20:36:56Z | 2,142,557 | <pre><code>l=[('a', 1), ('b', 2), ('c', 3)]
k=1
l_without_num=l[:] # or list(l) if you prefer
l_without_num.pop(k)
</code></pre>
| 2 | 2010-01-26T20:53:27Z | [
"python",
"list",
"copying"
] |
getting list without k'th element efficiently and non-destructively | 2,142,453 | <p>I have a list in python and I'd like to iterate through it, and selectively construct a list that contains all the elements except the current k'th element. one way I can do it is this:</p>
<pre><code>l = [('a', 1), ('b', 2), ('c', 3)]
for num, elt in enumerate(l):
# construct list without current element
l_wit... | 17 | 2010-01-26T20:36:56Z | 2,142,628 | <pre><code>new = [l[i] for i in range(len(l)) if i != k]
</code></pre>
| 1 | 2010-01-26T21:05:00Z | [
"python",
"list",
"copying"
] |
getting list without k'th element efficiently and non-destructively | 2,142,453 | <p>I have a list in python and I'd like to iterate through it, and selectively construct a list that contains all the elements except the current k'th element. one way I can do it is this:</p>
<pre><code>l = [('a', 1), ('b', 2), ('c', 3)]
for num, elt in enumerate(l):
# construct list without current element
l_wit... | 17 | 2010-01-26T20:36:56Z | 13,480,201 | <pre><code>#!/bin/bash
`python -c "'\n'.join(mylist[:])" 2>NULL | sed '/mybadelement/d'`
</code></pre>
<p>lol</p>
| 2 | 2012-11-20T18:59:33Z | [
"python",
"list",
"copying"
] |
getting list without k'th element efficiently and non-destructively | 2,142,453 | <p>I have a list in python and I'd like to iterate through it, and selectively construct a list that contains all the elements except the current k'th element. one way I can do it is this:</p>
<pre><code>l = [('a', 1), ('b', 2), ('c', 3)]
for num, elt in enumerate(l):
# construct list without current element
l_wit... | 17 | 2010-01-26T20:36:56Z | 31,845,308 | <p>Using difference operator on sets: </p>
<pre><code>list(set(l).difference([l[k]])
l=[('a', 1), ('b', 2), ('c', 3)]
list(set(l).difference([l[1]]))
[('a', 1), ('c', 3)]
</code></pre>
| 0 | 2015-08-06T01:20:24Z | [
"python",
"list",
"copying"
] |
pylint seems to not handle "from . import foo" style imports | 2,142,810 | <p>If I do:</p>
<pre><code>from . import foo
</code></pre>
<p>In a script and run pylint over it, I get:</p>
<blockquote>
<pre><code>F: 1: Unable to import %r
</code></pre>
</blockquote>
<p>Is there a way a work around for getting pylint to understand this syntax?</p>
| 1 | 2010-01-26T21:34:30Z | 2,143,498 | <p>Update to at least <a href="http://lists.logilab.org/pipermail/python-projects/2009-August/002012.html" rel="nofollow">pylint 0.18.1 / logilab-astng 0.19.1</a>?</p>
| 0 | 2010-01-26T23:27:30Z | [
"python",
"pylint",
"import"
] |
pylint seems to not handle "from . import foo" style imports | 2,142,810 | <p>If I do:</p>
<pre><code>from . import foo
</code></pre>
<p>In a script and run pylint over it, I get:</p>
<blockquote>
<pre><code>F: 1: Unable to import %r
</code></pre>
</blockquote>
<p>Is there a way a work around for getting pylint to understand this syntax?</p>
| 1 | 2010-01-26T21:34:30Z | 2,336,373 | <p>Note that the "from . import smthg" is only allowed in a Python package. </p>
<p>I've tested this with </p>
<pre><code>pylint --version
No config file found, using default configuration
pylint 0.19.0,
astng 0.19.1, common 0.46.0
Python 2.5.5 (r255:77872, Feb 1 2010, 19:53:42)
[GCC 4.4.3]
</code></pre>
<p>and w... | 0 | 2010-02-25T17:59:39Z | [
"python",
"pylint",
"import"
] |
What's the best way to add a GUI to a Pygame application? | 2,142,912 | <p>Are there any good GUIs that support Pygame surfaces as a widget within the application?</p>
<p>If this isn't possible or practical, what GUI toolkit has the best graphics component? I'm looking to keep the speedy rendering made possible by a SDL wrapper.</p>
| 8 | 2010-01-26T21:50:50Z | 2,143,001 | <p><a href="http://wiki.wxpython.org/IntegratingPyGame" rel="nofollow">Here</a> you have an explanation on how to integrate and make interact <code>wxPython</code> and <code>Pygame</code>.</p>
<p>Best GUI toolkit in my opinions is <a href="http://www.wxpython.org/" rel="nofollow">wxPython</a> (a binding for wxWidgets)... | 0 | 2010-01-26T22:03:20Z | [
"python",
"user-interface",
"graphics",
"pygame"
] |
What's the best way to add a GUI to a Pygame application? | 2,142,912 | <p>Are there any good GUIs that support Pygame surfaces as a widget within the application?</p>
<p>If this isn't possible or practical, what GUI toolkit has the best graphics component? I'm looking to keep the speedy rendering made possible by a SDL wrapper.</p>
| 8 | 2010-01-26T21:50:50Z | 2,143,018 | <p>Take a look at <a href="http://www.cosc.canterbury.ac.nz/greg.ewing/python/Albow/" rel="nofollow">Albow</a>, <a href="http://code.google.com/p/pgu/" rel="nofollow">PGU</a> or <a href="http://ocemp.sourceforge.net/gui.html" rel="nofollow">Ocemp</a>.</p>
| 4 | 2010-01-26T22:07:13Z | [
"python",
"user-interface",
"graphics",
"pygame"
] |
What's the best way to add a GUI to a Pygame application? | 2,142,912 | <p>Are there any good GUIs that support Pygame surfaces as a widget within the application?</p>
<p>If this isn't possible or practical, what GUI toolkit has the best graphics component? I'm looking to keep the speedy rendering made possible by a SDL wrapper.</p>
| 8 | 2010-01-26T21:50:50Z | 2,146,629 | <p>Dont use wxPython, its very hard to get to work well with Pygame, as described over at the <a href="http://www.pygame.org/wiki/gui">GUI section</a> of the Pygame wiki.</p>
<blockquote>
<p>First of all, pygame relies on the
SDL, which means that it can only have
one window at a time. Thus, trying to
implemen... | 8 | 2010-01-27T12:01:54Z | [
"python",
"user-interface",
"graphics",
"pygame"
] |
What's the best way to add a GUI to a Pygame application? | 2,142,912 | <p>Are there any good GUIs that support Pygame surfaces as a widget within the application?</p>
<p>If this isn't possible or practical, what GUI toolkit has the best graphics component? I'm looking to keep the speedy rendering made possible by a SDL wrapper.</p>
| 8 | 2010-01-26T21:50:50Z | 4,716,002 | <p>Albow and Ocemp are not being actively maintained. PGU is now being maintained by Peter Rogers, and Victor Kam has converted most of it to Python 3.</p>
<p>There are 5 pygame GUI toolkits which I've tried to get running under Python 3: Albow, GooeyPy, PGU, pqGUI, and sgc. (I didn't get GooeyPy to work with Python... | 3 | 2011-01-17T17:28:40Z | [
"python",
"user-interface",
"graphics",
"pygame"
] |
How do I get the "Interests" of a facebook user uing Facebook Connect? (I'm using Django/python and pyFacebook middleware) | 2,143,148 | <pre><code>def index(request):
fbdata = []
if request.facebook.check_session(request):
fbdata = request.facebook.users.getInfo(request.facebook.uid, ['name', 'pic'])
print fbdata
</code></pre>
<p>This works! I am able to get the user's picture and name.
However...I'd like to get the interests of t... | 2 | 2010-01-26T22:26:15Z | 2,143,383 | <p>Add "interests" in the fields you want to fetch, like this:</p>
<pre><code>fbdata = request.facebook.users.getInfo(request.facebook.uid,
['name', 'pic', 'interests'])
</code></pre>
| 2 | 2010-01-26T23:05:34Z | [
"python",
"django",
"facebook"
] |
Open a PyGTK program but do not activate it | 2,143,152 | <p>I have a PyGTK program which is hidden most of the time, but with a keypress it shall come up as a popup. Therefore I want the program not to be activated when its opened. I tried several options to to that, with no success:</p>
<blockquote>
<p>self.window.show() </p>
<p>self.window.set_focus(None)</p>
</blo... | 2 | 2010-01-26T22:26:47Z | 2,145,696 | <p>Build the window but don't call <code>show()</code> on it until it is ready to be activated. Then use <a href="http://www.pygtk.org/docs/pygtk/class-gtkwindow.html#method-gtkwindow--present" rel="nofollow"><code>self.window.present()</code></a>.</p>
<p><strong>EDIT:</strong>
If you never want the window to be activ... | 1 | 2010-01-27T09:28:01Z | [
"python",
"gtk",
"pygtk"
] |
Open a PyGTK program but do not activate it | 2,143,152 | <p>I have a PyGTK program which is hidden most of the time, but with a keypress it shall come up as a popup. Therefore I want the program not to be activated when its opened. I tried several options to to that, with no success:</p>
<blockquote>
<p>self.window.show() </p>
<p>self.window.set_focus(None)</p>
</blo... | 2 | 2010-01-26T22:26:47Z | 2,147,800 | <pre><code>I figured out how to do it. See the example below:
</code></pre>
<hr>
<pre><code>#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import gobject
class HelloWorld:
window=None
def hello(self, widget, data=None, data2=None):
HelloWorld.window.set_accept_focus(True)
HelloWo... | 1 | 2010-01-27T14:54:10Z | [
"python",
"gtk",
"pygtk"
] |
Convert google search results into json in python 3.1 | 2,143,206 | <p>I am writing a Python program that feeds a search term to google using the google search API and downloads the first 10 results. I was able to do this in Python 2.6 as follows:</p>
<pre><code>query = urllib.parse.urlencode({'q' : 'searchterm','start' : k},doseq=false)
url = 'http://ajax.googleapis.com/ajax/services... | 2 | 2010-01-26T22:35:12Z | 2,143,228 | <p>You'll need to decode the byte object if you want to use it with <code>json.loads</code></p>
<pre><code>resultjson = json.loads(results.read().decode())
</code></pre>
<p><a href="http://docs.python.org/3.1/library/json.html#json.loads" rel="nofollow">docs also suggest</a> to pass encoding parameter to the <code>l... | 2 | 2010-01-26T22:39:24Z | [
"python",
"json",
"httpresponse",
"google-search-api"
] |
Convert google search results into json in python 3.1 | 2,143,206 | <p>I am writing a Python program that feeds a search term to google using the google search API and downloads the first 10 results. I was able to do this in Python 2.6 as follows:</p>
<pre><code>query = urllib.parse.urlencode({'q' : 'searchterm','start' : k},doseq=false)
url = 'http://ajax.googleapis.com/ajax/services... | 2 | 2010-01-26T22:35:12Z | 2,143,299 | <p>The object returned by urlopen <em>is</em> file like, you are wrong there. But you use json.loads(), which expects a string. json.load() expects a file like object.</p>
<p>However, json.load() expects the result of the read() method to be a string, while of course the read you get will be bytes, so you need to deco... | 1 | 2010-01-26T22:50:21Z | [
"python",
"json",
"httpresponse",
"google-search-api"
] |
How to write a regular expression to match a string literal where the escape is a doubling of the quote character? | 2,143,235 | <p>I am writing a parser using <a href="http://www.dabeaz.com/ply/">ply</a> that needs to identify FORTRAN string literals. These are quoted with single quotes with the escape character being doubled single quotes. i.e.</p>
<p><code>'I don''t understand what you mean'</code></p>
<p>is a valid escaped FORTRAN string.<... | 6 | 2010-01-26T22:40:45Z | 2,143,267 | <p>A string literal is:</p>
<ol>
<li>An open single-quote, followed by:</li>
<li>Any number of doubled-single-quotes and non-single-quotes, then</li>
<li>A close single quote.</li>
</ol>
<p>Thus, our regex is:</p>
<pre><code>r"'(''|[^'])*'"
</code></pre>
| 17 | 2010-01-26T22:45:04Z | [
"python",
"regex",
"fortran",
"ply"
] |
How to write a regular expression to match a string literal where the escape is a doubling of the quote character? | 2,143,235 | <p>I am writing a parser using <a href="http://www.dabeaz.com/ply/">ply</a> that needs to identify FORTRAN string literals. These are quoted with single quotes with the escape character being doubled single quotes. i.e.</p>
<p><code>'I don''t understand what you mean'</code></p>
<p>is a valid escaped FORTRAN string.<... | 6 | 2010-01-26T22:40:45Z | 2,143,271 | <p>You want something like this:</p>
<pre><code>r"'([^']|'')*'"
</code></pre>
<p>This says that inside of the single quotes you can have either double quotes or a non-quote character.</p>
<p>The brackets define a character class, in which you list the characters that may or may not match. It doesn't allow anything m... | 4 | 2010-01-26T22:45:58Z | [
"python",
"regex",
"fortran",
"ply"
] |
How to write a regular expression to match a string literal where the escape is a doubling of the quote character? | 2,143,235 | <p>I am writing a parser using <a href="http://www.dabeaz.com/ply/">ply</a> that needs to identify FORTRAN string literals. These are quoted with single quotes with the escape character being doubled single quotes. i.e.</p>
<p><code>'I don''t understand what you mean'</code></p>
<p>is a valid escaped FORTRAN string.<... | 6 | 2010-01-26T22:40:45Z | 5,222,833 | <p>It's usually easy to get something quick-and-dirty for parsing particular string literals that are giving you problems, but for a general solution you can get a very powerful and complete regex for string literals from the <a href="http://pypi.python.org/pypi/pyparsing/" rel="nofollow">pyparsing module</a>:</p>
<pr... | 0 | 2011-03-07T17:19:54Z | [
"python",
"regex",
"fortran",
"ply"
] |
How to write a regular expression to match a string literal where the escape is a doubling of the quote character? | 2,143,235 | <p>I am writing a parser using <a href="http://www.dabeaz.com/ply/">ply</a> that needs to identify FORTRAN string literals. These are quoted with single quotes with the escape character being doubled single quotes. i.e.</p>
<p><code>'I don''t understand what you mean'</code></p>
<p>is a valid escaped FORTRAN string.<... | 6 | 2010-01-26T22:40:45Z | 5,223,595 | <pre><code>import re
ch ="'I don''t understand what you mean' and you' ?"
print re.search("'.*?'",ch).group()
print re.search("'.*?(?<!')'(?!')",ch).group()
</code></pre>
<p>result</p>
<pre><code>'I don'
'I don''t understand what you mean'
</code></pre>
| 0 | 2011-03-07T18:28:55Z | [
"python",
"regex",
"fortran",
"ply"
] |
Python indentation issue? | 2,143,291 | <p>I'm pretty new to python. This is my first time working with classes in python. When I try to run this script, I get </p>
<blockquote>
<p>IndentationError: expected an indented
block</p>
</blockquote>
<p>What is wrong with this?</p>
<pre><code>import random
class Individual:
alleles = (0,1)
length ... | 4 | 2010-01-26T22:48:49Z | 2,143,301 | <p>All of those methods that consist of just a comment.</p>
<p>To fix it, for example, do this</p>
<pre><code>def twoPointCrossover(self, partner):
#at two random(?) points, crossover.
pass
</code></pre>
<p>The comments don't count as compilable statements, so you have a bunch of empty blocks. That i... | 10 | 2010-01-26T22:50:50Z | [
"python"
] |
Python indentation issue? | 2,143,291 | <p>I'm pretty new to python. This is my first time working with classes in python. When I try to run this script, I get </p>
<blockquote>
<p>IndentationError: expected an indented
block</p>
</blockquote>
<p>What is wrong with this?</p>
<pre><code>import random
class Individual:
alleles = (0,1)
length ... | 4 | 2010-01-26T22:48:49Z | 2,143,302 | <p>If you use something that ends in <code>:</code> expecting an indented block and you don't have anything that you want to put there (other than a comment) then you need to use <code>pass</code>.</p>
<p>E.g.</p>
<pre><code>def doNothing(self):
pass
</code></pre>
| 4 | 2010-01-26T22:50:50Z | [
"python"
] |
Python indentation issue? | 2,143,291 | <p>I'm pretty new to python. This is my first time working with classes in python. When I try to run this script, I get </p>
<blockquote>
<p>IndentationError: expected an indented
block</p>
</blockquote>
<p>What is wrong with this?</p>
<pre><code>import random
class Individual:
alleles = (0,1)
length ... | 4 | 2010-01-26T22:48:49Z | 2,143,304 | <p>Change:</p>
<pre><code>class World:
def __init__(self):
#stuff.
</code></pre>
<p>To:</p>
<pre><code>class World:
def __init__(self):
#stuff
pass
</code></pre>
<p>and so on for all the methods.</p>
| 2 | 2010-01-26T22:50:58Z | [
"python"
] |
Python indentation issue? | 2,143,291 | <p>I'm pretty new to python. This is my first time working with classes in python. When I try to run this script, I get </p>
<blockquote>
<p>IndentationError: expected an indented
block</p>
</blockquote>
<p>What is wrong with this?</p>
<pre><code>import random
class Individual:
alleles = (0,1)
length ... | 4 | 2010-01-26T22:48:49Z | 2,143,309 | <p>Unless you're abbreviating your code for this post, you'll need <code>pass</code> after all of those functions that don't have any code.</p>
| 2 | 2010-01-26T22:51:17Z | [
"python"
] |
Python indentation issue? | 2,143,291 | <p>I'm pretty new to python. This is my first time working with classes in python. When I try to run this script, I get </p>
<blockquote>
<p>IndentationError: expected an indented
block</p>
</blockquote>
<p>What is wrong with this?</p>
<pre><code>import random
class Individual:
alleles = (0,1)
length ... | 4 | 2010-01-26T22:48:49Z | 2,143,310 | <pre><code>def __init__(self):
#stuff.
</code></pre>
<p>That looks wrong at first glance. Try changing it to this:</p>
<pre><code>def __init__(self):
#stuff.
pass
</code></pre>
| 2 | 2010-01-26T22:51:36Z | [
"python"
] |
Python indentation issue? | 2,143,291 | <p>I'm pretty new to python. This is my first time working with classes in python. When I try to run this script, I get </p>
<blockquote>
<p>IndentationError: expected an indented
block</p>
</blockquote>
<p>What is wrong with this?</p>
<pre><code>import random
class Individual:
alleles = (0,1)
length ... | 4 | 2010-01-26T22:48:49Z | 2,143,312 | <p>When you're just outlining your classes and have a bunch of methods which do nothing, you need to insert the <code>pass</code> statement to indicate that nothing is happening. </p>
<p>Like so: </p>
<pre><code>class Individual:
alleles = (0,1)
length = 5
string = ""
def __init__(self):
#som... | 3 | 2010-01-26T22:51:42Z | [
"python"
] |
Python indentation issue? | 2,143,291 | <p>I'm pretty new to python. This is my first time working with classes in python. When I try to run this script, I get </p>
<blockquote>
<p>IndentationError: expected an indented
block</p>
</blockquote>
<p>What is wrong with this?</p>
<pre><code>import random
class Individual:
alleles = (0,1)
length ... | 4 | 2010-01-26T22:48:49Z | 2,143,314 | <p>Double check the tabs and spaces in all the code, make sure you are not mixing them. A line with several spaces may the same as a line with a single tab.</p>
| 2 | 2010-01-26T22:52:22Z | [
"python"
] |
Python indentation issue? | 2,143,291 | <p>I'm pretty new to python. This is my first time working with classes in python. When I try to run this script, I get </p>
<blockquote>
<p>IndentationError: expected an indented
block</p>
</blockquote>
<p>What is wrong with this?</p>
<pre><code>import random
class Individual:
alleles = (0,1)
length ... | 4 | 2010-01-26T22:48:49Z | 2,143,481 | <p>Others have covered <code>pass</code>, so I will just add that for beginning python programmers, it can take some getting used to the importance of whitespace.</p>
<p>Until you get used to it you might want to get in the habit of converting tabs to spaces or spaces to tabs when you save a file. Personally I prefer... | 0 | 2010-01-26T23:24:45Z | [
"python"
] |
csv.reader turning commas into periods throwing errors | 2,143,371 | <p>Here is a sample of the first row:</p>
<pre><code>link,Title,Description,Keywords
</code></pre>
<p>It is made from an excel workbook, I tried saving in all CSV formats (window, ms-dos, and comma delimited list) I even tried saving in 2 txt file formats (window, ms-dos) </p>
<p>k...
here is the code:</p>
<pre><co... | 1 | 2010-01-26T23:03:16Z | 2,143,519 | <p>Dalkes comment above dropped the coin for me:</p>
<p>You are reading from a CSV file, and taking that data and inserting in an SQL database, evidently, although you did not say so. You have a syntax error in your SQL-statement.</p>
<p>Note that most SQL databases have CSV imports, so you don't need to write them.
... | 3 | 2010-01-26T23:32:45Z | [
"python",
"csv",
"syntax-error",
"period"
] |
csv.reader turning commas into periods throwing errors | 2,143,371 | <p>Here is a sample of the first row:</p>
<pre><code>link,Title,Description,Keywords
</code></pre>
<p>It is made from an excel workbook, I tried saving in all CSV formats (window, ms-dos, and comma delimited list) I even tried saving in 2 txt file formats (window, ms-dos) </p>
<p>k...
here is the code:</p>
<pre><co... | 1 | 2010-01-26T23:03:16Z | 2,143,529 | <p>The <code>csv.reader</code> is not responsible for constructing the SQL statement whose fragment is being shown in the error message you posted -- some other part of your code must be the one that constructs this statement, and it's doing that in the wrong way. So don't think about <code>csv.reader</code>, but abou... | 0 | 2010-01-26T23:35:11Z | [
"python",
"csv",
"syntax-error",
"period"
] |
csv.reader turning commas into periods throwing errors | 2,143,371 | <p>Here is a sample of the first row:</p>
<pre><code>link,Title,Description,Keywords
</code></pre>
<p>It is made from an excel workbook, I tried saving in all CSV formats (window, ms-dos, and comma delimited list) I even tried saving in 2 txt file formats (window, ms-dos) </p>
<p>k...
here is the code:</p>
<pre><co... | 1 | 2010-01-26T23:03:16Z | 2,147,440 | <p>it is the values statement! geez, but I did a log.debug and didn't see it output which was before the sql ...but that is most def what it is. I wasn't trying to import the first row, I plugged that in there purposely to not show actual data. Sorry for the inconvenience. I didn't think the code was making it past tha... | 1 | 2010-01-27T14:09:18Z | [
"python",
"csv",
"syntax-error",
"period"
] |
What's the easiest way to reproduce a randomly generated level in Python? | 2,143,463 | <p>I'm making a game which uses procedurally generated levels, and when I'm testing I'll often want to reproduce a level. Right now I haven't made any way to save the levels, but I thought a simpler solution would be to just reuse the seed used by Python's random module. However I've tried using both <code>random.seed(... | 2 | 2010-01-26T23:19:45Z | 2,143,487 | <p><code>random.seed</code> should work ok, but remember that it is not thread safe - if random numbers are being used elsewhere at the same time you may get different results between runs. </p>
<p>In that case you should use an instance of <code>random.Random()</code> to get a private random number generator </p>
<p... | 7 | 2010-01-26T23:25:45Z | [
"python",
"random",
"pygame"
] |
What's the easiest way to reproduce a randomly generated level in Python? | 2,143,463 | <p>I'm making a game which uses procedurally generated levels, and when I'm testing I'll often want to reproduce a level. Right now I haven't made any way to save the levels, but I thought a simpler solution would be to just reuse the seed used by Python's random module. However I've tried using both <code>random.seed(... | 2 | 2010-01-26T23:19:45Z | 2,143,490 | <p>Best would be to create a levelRandom class with a data slot for every randomly produced result when generating a level. Then separate the random-generation code from the level-construction code. When you want a new level, first generate a new levelRandom object, then hand that object to the level-generator to produ... | 1 | 2010-01-26T23:26:09Z | [
"python",
"random",
"pygame"
] |
What's the easiest way to reproduce a randomly generated level in Python? | 2,143,463 | <p>I'm making a game which uses procedurally generated levels, and when I'm testing I'll often want to reproduce a level. Right now I haven't made any way to save the levels, but I thought a simpler solution would be to just reuse the seed used by Python's random module. However I've tried using both <code>random.seed(... | 2 | 2010-01-26T23:19:45Z | 2,143,541 | <p>The numbers generated by a random function are deterministic. Thus, seed with known value and save it. Create a level from the following random numbers. To load the level, simply seed again with the same known value and use the "random" numbers again, which will be reoccurring in the same sequence. This is language ... | 1 | 2010-01-26T23:37:34Z | [
"python",
"random",
"pygame"
] |
Undefined variable from import when using wxPython in pydev | 2,143,549 | <p>I just downloaded wxPython, and was running some of the sample programs from <a href="http://wiki.wxpython.org/Getting%20Started#First_steps">here</a>. However, on every line that uses a variable from wx.*, I get a "Undefined variable from import error"</p>
<p>For example, the following program generates five error... | 18 | 2010-01-26T23:40:20Z | 2,143,555 | <p>Some of the newer versions of pydev <strong><em>(circa January 2010)</em></strong> have a hard time tracking down imported names. It's probably nothing.</p>
<p>If this is <em>still</em> occurring, report the bug to <strike>aptana</strike> <a href="http://pydev.org/" rel="nofollow">appcelerator</a>, though no doubt ... | 3 | 2010-01-26T23:42:01Z | [
"python",
"eclipse",
"wxpython",
"pydev"
] |
Undefined variable from import when using wxPython in pydev | 2,143,549 | <p>I just downloaded wxPython, and was running some of the sample programs from <a href="http://wiki.wxpython.org/Getting%20Started#First_steps">here</a>. However, on every line that uses a variable from wx.*, I get a "Undefined variable from import error"</p>
<p>For example, the following program generates five error... | 18 | 2010-01-26T23:40:20Z | 2,662,274 | <p>Use <code>CTRL+1</code> key combination on error text and add <code>#@UndefinedVariable</code> or <code>#@UnresolvedImport</code> in the end of corresponding lines with errors, it will remove these warnings temporary. See this answer: <a href="http://stackoverflow.com/questions/2112715/how-do-i-fix-pydev-undefined-v... | 3 | 2010-04-18T12:48:31Z | [
"python",
"eclipse",
"wxpython",
"pydev"
] |
Undefined variable from import when using wxPython in pydev | 2,143,549 | <p>I just downloaded wxPython, and was running some of the sample programs from <a href="http://wiki.wxpython.org/Getting%20Started#First_steps">here</a>. However, on every line that uses a variable from wx.*, I get a "Undefined variable from import error"</p>
<p>For example, the following program generates five error... | 18 | 2010-01-26T23:40:20Z | 3,447,910 | <p>Try</p>
<p>wx = wx</p>
<p>Don't ask why. This approach (that I found when trying to break the problem in smaller parts) just seems to remove the wx undefined variables problem.</p>
| 3 | 2010-08-10T10:17:40Z | [
"python",
"eclipse",
"wxpython",
"pydev"
] |
Undefined variable from import when using wxPython in pydev | 2,143,549 | <p>I just downloaded wxPython, and was running some of the sample programs from <a href="http://wiki.wxpython.org/Getting%20Started#First_steps">here</a>. However, on every line that uses a variable from wx.*, I get a "Undefined variable from import error"</p>
<p>For example, the following program generates five error... | 18 | 2010-01-26T23:40:20Z | 3,590,738 | <pre><code>#import wx
from wx import wx #@UnresolvedImport
</code></pre>
<p>will fix.</p>
| 3 | 2010-08-28T12:25:38Z | [
"python",
"eclipse",
"wxpython",
"pydev"
] |
Undefined variable from import when using wxPython in pydev | 2,143,549 | <p>I just downloaded wxPython, and was running some of the sample programs from <a href="http://wiki.wxpython.org/Getting%20Started#First_steps">here</a>. However, on every line that uses a variable from wx.*, I get a "Undefined variable from import error"</p>
<p>For example, the following program generates five error... | 18 | 2010-01-26T23:40:20Z | 3,743,861 | <p>This happened to me. I had installed PyDev and configured it and went on my merry way. A few months later, I installed wxPython and had this same problem. An easy way to fix is in eclipse:</p>
<p>Window -> Preferences -> Pydev -> Interpreter - Python</p>
<p>Just remove the default interpreter and add a new one ... | 39 | 2010-09-18T22:59:21Z | [
"python",
"eclipse",
"wxpython",
"pydev"
] |
Undefined variable from import when using wxPython in pydev | 2,143,549 | <p>I just downloaded wxPython, and was running some of the sample programs from <a href="http://wiki.wxpython.org/Getting%20Started#First_steps">here</a>. However, on every line that uses a variable from wx.*, I get a "Undefined variable from import error"</p>
<p>For example, the following program generates five error... | 18 | 2010-01-26T23:40:20Z | 3,945,589 | <p>PyDev finds the references when you setup the interpreter in </p>
<blockquote>
<pre><code>Window -> Preferences -> Pydev -> Interpreter - Python
</code></pre>
</blockquote>
<p>If wxPython was not in your site-packages directory when you first setup the interpreter, then the references to the wx objects an... | 7 | 2010-10-15T19:48:58Z | [
"python",
"eclipse",
"wxpython",
"pydev"
] |
How do I get a content-type of a file in Python? (with url..) | 2,143,674 | <p>Suppose I haev a video file:</p>
<p><a href="http://mydomain.com/thevideofile.mp4">http://mydomain.com/thevideofile.mp4</a></p>
<p>How do I get the header and the content-type of this file? With Python. But , I don't want to download the entire file.
i want it to return:</p>
<pre><code>video/mp4
</code></pre>
<p... | 6 | 2010-01-27T00:08:59Z | 2,143,704 | <p>Like so:</p>
<pre><code>>>> import httplib
>>> conn = httplib.HTTPConnection("mydomain.com")
>>> conn.request("HEAD", "/thevideofile.mp4")
>>> res = conn.getresponse()
>>> print res.getheaders()
</code></pre>
<p>That will only download and print the headers because it i... | 12 | 2010-01-27T00:16:56Z | [
"python",
"http",
"url",
"content-type"
] |
How do I get a content-type of a file in Python? (with url..) | 2,143,674 | <p>Suppose I haev a video file:</p>
<p><a href="http://mydomain.com/thevideofile.mp4">http://mydomain.com/thevideofile.mp4</a></p>
<p>How do I get the header and the content-type of this file? With Python. But , I don't want to download the entire file.
i want it to return:</p>
<pre><code>video/mp4
</code></pre>
<p... | 6 | 2010-01-27T00:08:59Z | 2,143,730 | <p>This is a higher level answer than Brian's. Using the urllib machinery has the usual advantages such as handling redirects automatically and so on.</p>
<pre><code>import urllib2
class HeadRequest(urllib2.Request):
def get_method(self):
return "HEAD"
url = "http://mydomain.com/thevideofile.mp4"
head = ... | 4 | 2010-01-27T00:22:10Z | [
"python",
"http",
"url",
"content-type"
] |
How do I get a content-type of a file in Python? (with url..) | 2,143,674 | <p>Suppose I haev a video file:</p>
<p><a href="http://mydomain.com/thevideofile.mp4">http://mydomain.com/thevideofile.mp4</a></p>
<p>How do I get the header and the content-type of this file? With Python. But , I don't want to download the entire file.
i want it to return:</p>
<pre><code>video/mp4
</code></pre>
<p... | 6 | 2010-01-27T00:08:59Z | 2,143,855 | <p>you can get the video type using the info() method or the headers dict</p>
<pre><code>f=urllib2.urlopen(url)
print f.headers['Content-Type']
print f.info()
</code></pre>
<p>A test run with an randomly selected avi file googled on the net that is more than 600Mb</p>
<pre><code>$ cat test.py
#!/usr/bin/env python
i... | 0 | 2010-01-27T00:56:03Z | [
"python",
"http",
"url",
"content-type"
] |
Database for web crawler in python? | 2,143,702 | <p>Hi im writing a web crawler in python to extract news articles from news websites like nytimes.com. i want to know what would be a good db to use as a backend for this project?</p>
<p>Thanks in advance!</p>
| 1 | 2010-01-27T00:16:35Z | 2,143,722 | <p>Personally, I love <a href="http://www.postgresql.org/" rel="nofollow">PostGreSQL</a> -- but other free DBs such as <a href="http://www.mysql.com/" rel="nofollow">MySql</a> (or, if you have reasonably small amounts of data -- a few GB at most -- even the <a href="http://docs.python.org/library/sqlite3.html" rel="nof... | 3 | 2010-01-27T00:20:40Z | [
"python",
"database",
"web-crawler"
] |
Database for web crawler in python? | 2,143,702 | <p>Hi im writing a web crawler in python to extract news articles from news websites like nytimes.com. i want to know what would be a good db to use as a backend for this project?</p>
<p>Thanks in advance!</p>
| 1 | 2010-01-27T00:16:35Z | 2,143,737 | <p>I think the database itself will probably be one of the easier aspects of a web crawler like this.</p>
<p>If expect high load reading or writing the database (for example if you intend to run many crawlers at the same time) then you will want to steer in the direction of MySql, otherwise something like <a href="htt... | 1 | 2010-01-27T00:23:40Z | [
"python",
"database",
"web-crawler"
] |
Database for web crawler in python? | 2,143,702 | <p>Hi im writing a web crawler in python to extract news articles from news websites like nytimes.com. i want to know what would be a good db to use as a backend for this project?</p>
<p>Thanks in advance!</p>
| 1 | 2010-01-27T00:16:35Z | 2,144,187 | <p>This could be a great project to use a document database like CouchDB, MongoDB, or SimpleDB.</p>
<p>MongoDB has a hosted solution: <a href="http://mongohq.com" rel="nofollow">http://mongohq.com</a>. There is also <a href="http://api.mongodb.org/python/" rel="nofollow">a binding for Python (Pymongo)</a>.</p>
<p>Sim... | 6 | 2010-01-27T02:26:10Z | [
"python",
"database",
"web-crawler"
] |
Database for web crawler in python? | 2,143,702 | <p>Hi im writing a web crawler in python to extract news articles from news websites like nytimes.com. i want to know what would be a good db to use as a backend for this project?</p>
<p>Thanks in advance!</p>
| 1 | 2010-01-27T00:16:35Z | 2,150,152 | <p>You can take a look at <a href="http://www.Firebirdsql.org" rel="nofollow">Firebird</a></p>
<p>Firebird <a href="http://www.firebirdsql.org/index.php?op=devel&sub=python" rel="nofollow">python driver</a> are developped by the core team</p>
| 0 | 2010-01-27T20:51:19Z | [
"python",
"database",
"web-crawler"
] |
Python DBUS SESSION_BUS - X11 dependency | 2,143,785 | <p>I've got running sample python code which is fine in Ubuntu desktop:</p>
<pre><code>import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
from dbus.mainloop.glib import threads_init
import subprocess
from subprocess import call
gobject.threads_init()
threads_init()
dbus.mainloop.glib.DBusGMainLoop( set... | 1 | 2010-01-27T00:36:41Z | 2,143,973 | <p>The problem is that you're running the <code>export</code> calls in separate shells. You need to capture the output of <code>dbus-launch</code>, parse the values, and use <code>os.environ</code> to write them to the environment:</p>
<pre><code>p = subprocess.Popen('dbus-launch', shell=True, stdout=subprocess.PIPE, ... | 2 | 2010-01-27T01:29:09Z | [
"python",
"x11",
"dbus"
] |
How do I use Trac wiki formatting in a Django/Python web application? | 2,143,805 | <p>I have a Python web application (Django, specifically). I'm reading in some data from a Trac database (where the descriptions use <a href="http://trac.edgewall.org/wiki/WikiFormatting" rel="nofollow">wiki formatting</a>) and displaying it as HTML. I considered the markdown module, but realised that Trac wiki formatt... | 5 | 2010-01-27T00:40:55Z | 2,143,885 | <p>The below links shows a snippet which imports trac markup and makes a django template filter from it</p>
<p><a href="http://www.djangosnippets.org/snippets/1047/">http://www.djangosnippets.org/snippets/1047/</a></p>
| 5 | 2010-01-27T01:06:37Z | [
"python",
"django",
"trac"
] |
How do I use Trac wiki formatting in a Django/Python web application? | 2,143,805 | <p>I have a Python web application (Django, specifically). I'm reading in some data from a Trac database (where the descriptions use <a href="http://trac.edgewall.org/wiki/WikiFormatting" rel="nofollow">wiki formatting</a>) and displaying it as HTML. I considered the markdown module, but realised that Trac wiki formatt... | 5 | 2010-01-27T00:40:55Z | 9,243,896 | <p>I have made a plugin for Django-CMS which support Trac wiki syntax, with macros and everything else you expect from Trac:</p>
<p><a href="https://bitbucket.org/mitar/cmsplugin-markup-tracwiki" rel="nofollow">https://bitbucket.org/mitar/cmsplugin-markup-tracwiki</a></p>
| 0 | 2012-02-11T20:42:42Z | [
"python",
"django",
"trac"
] |
Read the first line of batch file from the same batch file? | 2,143,897 | <p>I have a batch file that tries to run the program specified in its first line. Similar to Unix's <a href="http://en.wikipedia.org/wiki/Shebang_%28Unix%29" rel="nofollow">shebang</a>:</p>
<pre><code>C:\> more foo.bat
#!C:\Python27\python.exe
%PYTHON% foo-script.py
C:\>
</code></pre>
<p>What I want to know is:... | 2 | 2010-01-27T01:09:16Z | 2,143,946 | <p>Firstly , on windows, there is no need for shebang. Its best to include the path of the Python interpreter to the PATH environment variable of the user who is running the script. That said, to get the first line in batch, you can use set</p>
<pre><code>set /p var=<file
</code></pre>
<p>since you have multiple v... | 4 | 2010-01-27T01:20:58Z | [
"python",
"windows",
"batch-file",
"shebang"
] |
Read the first line of batch file from the same batch file? | 2,143,897 | <p>I have a batch file that tries to run the program specified in its first line. Similar to Unix's <a href="http://en.wikipedia.org/wiki/Shebang_%28Unix%29" rel="nofollow">shebang</a>:</p>
<pre><code>C:\> more foo.bat
#!C:\Python27\python.exe
%PYTHON% foo-script.py
C:\>
</code></pre>
<p>What I want to know is:... | 2 | 2010-01-27T01:09:16Z | 2,143,994 | <p>Shebangs are only native to the filesystems of Unix/Linux/BSD variants, due to their design and layout, the filesystem knows that when a file begins with a shebang, the filesystem triggers the user's terminal process to invoke the shell based on the shebang, usually <code>/bin/sh</code>. This can be confirmed by bro... | 0 | 2010-01-27T01:36:32Z | [
"python",
"windows",
"batch-file",
"shebang"
] |
psp (python server pages) code under mod_wsgi? | 2,143,915 | <p>Is there some way to run .psp (python server pages) code under apache + mod_wsgi? While we are moving towards newer wsgi based frameworks we still have some legacy code written in psp which runs under mod_python.</p>
<p>We'd like to be able to run it on the same server that hosts other wsgi based python code. In s... | 2 | 2010-01-27T01:14:19Z | 2,144,002 | <p>No, there is no port of mod_python PSP for mod_wsgi.</p>
<p>Yes, you can run mod_python and mod_wsgi on same server so long as both use same version of Python and both link dynamically with Python library. See:</p>
<p><a href="http://code.google.com/p/modwsgi/wiki/InstallationIssues" rel="nofollow">http://code.goo... | 1 | 2010-01-27T01:38:16Z | [
"python",
"wsgi",
"mod-python",
"python-server-pages"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.