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 |
|---|---|---|---|---|---|---|---|---|---|
Reading a binary file in Python: takes a very long time to read certain bytes | 2,265,930 | <p>This is very odd</p>
<p>I'm reading some (admittedly very large: ~2GB each) binary files using numpy libraries in Python.
I'm using the:</p>
<pre><code>thingy = np.fromfile(fileObject, np.int16, 1)
</code></pre>
<p>method.
This is right in the middle of a nested loop - I'm doing this loop 4096 times per 'channe... | 0 | 2010-02-15T12:40:25Z | 2,266,731 | <p>Where are you storing the results? When lists/dicts/whatever get very large there can be a noticeable delay when they need to be reallocated and resized.</p>
| 2 | 2010-02-15T15:00:05Z | [
"python",
"binary",
"numpy",
"binaryfiles"
] |
Reading a binary file in Python: takes a very long time to read certain bytes | 2,265,930 | <p>This is very odd</p>
<p>I'm reading some (admittedly very large: ~2GB each) binary files using numpy libraries in Python.
I'm using the:</p>
<pre><code>thingy = np.fromfile(fileObject, np.int16, 1)
</code></pre>
<p>method.
This is right in the middle of a nested loop - I'm doing this loop 4096 times per 'channe... | 0 | 2010-02-15T12:40:25Z | 2,267,927 | <p>Could it be that <a href="http://docs.python.org/library/gc.html" rel="nofollow">garbage collection</a> is kicking in for the lists ?</p>
<p>Added: is it funny data, or blockno ? What happens if you read the blocks in random order, along the lines</p>
<pre><code>r = range(4096)
random.shuffle(r) # inplace
for blo... | 1 | 2010-02-15T18:03:32Z | [
"python",
"binary",
"numpy",
"binaryfiles"
] |
Python, generating PDF using ReportLab.Platypus SimpleDocTemplate, date/time in header | 2,265,976 | <p>I'm working on a project in Python/Django which uses ReportLab's SimpleDocTemplate to generate PDF documents.</p>
<p>All the documents generated have the current date/time printed in the top right corner. I can't see that it's being done anywhere in my code, is this a default behaviour in the SimpleDocTemplate obj... | 0 | 2010-02-15T12:47:30Z | 2,266,245 | <p>I've just tried to reproduce the behavior you described, but unfortunately I cant. So I don't think it's a default behavior. Maybe it would be a good idea if you post a small example where the production date/time in the header is visible.</p>
<p>But if it's any help to you, here is what I've done: I used the follo... | 2 | 2010-02-15T13:36:21Z | [
"python",
"django",
"pdf-generation",
"reportlab",
"platypus"
] |
XMPPPY have function to manage invitation in client side? | 2,266,040 | <p>I'm coding by python about Gtalk I use XMPPPY.</p>
<p>But I can chat with GTalk client but the problem is I can't accept invitation.</p>
<p>Is XMPPY can do ?</p>
| 0 | 2010-02-15T13:00:19Z | 2,281,390 | <p>Looks like you want to "authorize" the request. I'm assuming you've received the request at the client. In the roster class (xmpp.roster) there is an "Authorize" method. It sends the "subscribed" packet to accept the roster request. This is what the method looks like:</p>
<pre><code>def Authorize(self,jid):
""... | 0 | 2010-02-17T14:25:49Z | [
"python",
"chat",
"xmpp",
"google-talk"
] |
Can we do a smart-copy in Python? | 2,266,234 | <p>I'm a python newbie, and I'm writing a script to copy compiled files from one location to another. What I have is quite simple at the moment, something like this:</p>
<pre><code>import os
import shutil
shutil.copy2 (src, dst)
#... many more shutil.copy commands
#src is a filename string
#dst is the directory where... | 4 | 2010-02-15T13:34:14Z | 2,266,254 | <p>you could give this python implementation of rsync a try</p>
<p><a href="http://freshmeat.net/projects/pysync/" rel="nofollow">http://freshmeat.net/projects/pysync/</a></p>
| 4 | 2010-02-15T13:39:10Z | [
"python"
] |
Can we do a smart-copy in Python? | 2,266,234 | <p>I'm a python newbie, and I'm writing a script to copy compiled files from one location to another. What I have is quite simple at the moment, something like this:</p>
<pre><code>import os
import shutil
shutil.copy2 (src, dst)
#... many more shutil.copy commands
#src is a filename string
#dst is the directory where... | 4 | 2010-02-15T13:34:14Z | 2,266,269 | <p>You could make use of the file modification time, if that's enough for you:</p>
<pre><code># If more than 1 second difference
if os.stat(src).st_mtime - os.stat(dest).st_mtime > 1:
shutil.copy2 (src, dst)
</code></pre>
<p>Or call a synchronization tool like rsync.</p>
| 7 | 2010-02-15T13:41:40Z | [
"python"
] |
Can we do a smart-copy in Python? | 2,266,234 | <p>I'm a python newbie, and I'm writing a script to copy compiled files from one location to another. What I have is quite simple at the moment, something like this:</p>
<pre><code>import os
import shutil
shutil.copy2 (src, dst)
#... many more shutil.copy commands
#src is a filename string
#dst is the directory where... | 4 | 2010-02-15T13:34:14Z | 2,266,273 | <p>If you don't have a definite reason for needing to code this yourself in python, I'd suggest using rsync. From it's man-page:</p>
<blockquote>
<p>Rsync is a fast and extraordinarily
versatile file copying tool. It is
famous for its delta-transfer
algorithm, which reduces the amount of
data sent over the ... | 4 | 2010-02-15T13:41:58Z | [
"python"
] |
Can we do a smart-copy in Python? | 2,266,234 | <p>I'm a python newbie, and I'm writing a script to copy compiled files from one location to another. What I have is quite simple at the moment, something like this:</p>
<pre><code>import os
import shutil
shutil.copy2 (src, dst)
#... many more shutil.copy commands
#src is a filename string
#dst is the directory where... | 4 | 2010-02-15T13:34:14Z | 2,266,274 | <p>How would you like to look for changed files? You can just use os.path.getmtime(path) on the src and check whether that's newer than some stored timestamp (the last time you copied for instance) or use a filecmp.cmp(f1, f2[, shallow]) to check whether a file is newer. </p>
<p>Watch out with filecmp.cmp, you also co... | 1 | 2010-02-15T13:41:59Z | [
"python"
] |
Can we do a smart-copy in Python? | 2,266,234 | <p>I'm a python newbie, and I'm writing a script to copy compiled files from one location to another. What I have is quite simple at the moment, something like this:</p>
<pre><code>import os
import shutil
shutil.copy2 (src, dst)
#... many more shutil.copy commands
#src is a filename string
#dst is the directory where... | 4 | 2010-02-15T13:34:14Z | 9,050,820 | <p>From AndiDog's answer:</p>
<pre><code>os.stat(dst).st_mtime - os.stat(src).st_mtime
</code></pre>
<p>is a negative value if 'src' file is newer, so it should be:</p>
<pre><code>if os.stat(src).st_mtime - os.stat(dst).st_mtime > 1:
</code></pre>
| 1 | 2012-01-29T04:03:13Z | [
"python"
] |
Can we do a smart-copy in Python? | 2,266,234 | <p>I'm a python newbie, and I'm writing a script to copy compiled files from one location to another. What I have is quite simple at the moment, something like this:</p>
<pre><code>import os
import shutil
shutil.copy2 (src, dst)
#... many more shutil.copy commands
#src is a filename string
#dst is the directory where... | 4 | 2010-02-15T13:34:14Z | 30,480,949 | <p>You can do a smart copy using <a href="https://docs.python.org/2/distutils/apiref.html#module-distutils.file_util" rel="nofollow">distutils.file_util.copy_file</a> by setting the optional argument: <code>update=1</code>.</p>
| 0 | 2015-05-27T11:18:50Z | [
"python"
] |
Django test FileField using test fixtures | 2,266,503 | <p>I'm trying to build tests for some models that have a FileField. The model looks like this:</p>
<pre><code>class SolutionFile(models.Model):
'''
A file from a solution.
'''
solution = models.ForeignKey(Solution)
file = models.FileField(upload_to=make_solution_file_path)
</code></pre>
<p>I have ... | 19 | 2010-02-15T14:23:06Z | 2,269,295 | <p>I've written unit tests for an entire gallery app before, and what worked well for me was using the python tempfile and shutil modules to create copies of the test files in temporary directories and then delete them all afterwards.</p>
<p>The following example is not working/complete, but should get you on the righ... | 3 | 2010-02-15T22:14:23Z | [
"python",
"django",
"unit-testing",
"django-testing",
"filefield"
] |
Django test FileField using test fixtures | 2,266,503 | <p>I'm trying to build tests for some models that have a FileField. The model looks like this:</p>
<pre><code>class SolutionFile(models.Model):
'''
A file from a solution.
'''
solution = models.ForeignKey(Solution)
file = models.FileField(upload_to=make_solution_file_path)
</code></pre>
<p>I have ... | 19 | 2010-02-15T14:23:06Z | 10,455,507 | <p>This is what I did for my test. After uploading the file it should end up in the photo property of my organization model object:</p>
<pre><code> import tempfile
filename = tempfile.mkstemp()[1]
f = open(filename, 'w')
f.write('These are the file contents')
f.close()
f = open(filename, 'r')
... | 0 | 2012-05-04T20:12:29Z | [
"python",
"django",
"unit-testing",
"django-testing",
"filefield"
] |
Django test FileField using test fixtures | 2,266,503 | <p>I'm trying to build tests for some models that have a FileField. The model looks like this:</p>
<pre><code>class SolutionFile(models.Model):
'''
A file from a solution.
'''
solution = models.ForeignKey(Solution)
file = models.FileField(upload_to=make_solution_file_path)
</code></pre>
<p>I have ... | 19 | 2010-02-15T14:23:06Z | 20,508,664 | <p>Django provides a great way to write tests on FileFields without mucking about in the real filesystem - use a SimpleUploadedFile.</p>
<pre><code>from django.core.files.uploadedfile import SimpleUploadedFile
my_model.file_field = SimpleUploadedFile('best_file_eva.txt', 'these are the file contents!')
</code></pre>
... | 12 | 2013-12-11T01:10:01Z | [
"python",
"django",
"unit-testing",
"django-testing",
"filefield"
] |
Django test FileField using test fixtures | 2,266,503 | <p>I'm trying to build tests for some models that have a FileField. The model looks like this:</p>
<pre><code>class SolutionFile(models.Model):
'''
A file from a solution.
'''
solution = models.ForeignKey(Solution)
file = models.FileField(upload_to=make_solution_file_path)
</code></pre>
<p>I have ... | 19 | 2010-02-15T14:23:06Z | 21,036,980 | <p>You can override the MEDIA_ROOT setting for your tests like this:</p>
<pre><code>@override_settings(MEDIA_ROOT='/tmp/django_test')
def test_post_solution_file(self):
# your code here
</code></pre>
| 3 | 2014-01-10T05:44:49Z | [
"python",
"django",
"unit-testing",
"django-testing",
"filefield"
] |
Django Loading Templates with Inheritance from Specific Directory | 2,266,530 | <p>In our project, we have a bunch of different templates that clients to choose from (for their webstore). The file layout is something like this:</p>
<pre><code>templates
cart.html
closed.html
head.html
standard
bishop
default
indiana
marley
mocca
nihil... | 1 | 2010-02-15T14:27:08Z | 2,268,170 | <p>In your templates/standard/bishop/browse.html template you're doing the following:</p>
<pre><code>{% extends "base.html" %}
</code></pre>
<p>This refers to <strong>templates/base.html</strong> and not <strong>templates/standard/bishop/base.html</strong>. By default Django will check your installed applications as ... | 4 | 2010-02-15T18:44:25Z | [
"python",
"django",
"templates"
] |
Paginating the results of a Django forms POST request | 2,266,554 | <p>I'm using Django Forms to do a filtered/faceted search via POST, and I would like to Django's paginator class to organize the results. How do I preserve the original request when passing the client between the various pages? In other words, it seems that I lose the POST data as soon as I pass the GET request for a... | 15 | 2010-02-15T14:31:25Z | 2,266,571 | <p>You can ask request object if it's ajax, simply <code>request.is_ajax</code>. This way you can detect, whether it's first post request or further questions about the next pages.</p>
| 0 | 2010-02-15T14:34:23Z | [
"python",
"django",
"django-forms",
"pagination"
] |
Paginating the results of a Django forms POST request | 2,266,554 | <p>I'm using Django Forms to do a filtered/faceted search via POST, and I would like to Django's paginator class to organize the results. How do I preserve the original request when passing the client between the various pages? In other words, it seems that I lose the POST data as soon as I pass the GET request for a... | 15 | 2010-02-15T14:31:25Z | 2,266,950 | <p>If you want to access the store data in later request, you would have to store it somewhere. Django provides several ways to archive this:</p>
<p><strong>1) You can use <a href="http://docs.djangoproject.com/en/dev/topics/http/sessions/">sessions</a> to store the query:</strong> Every visitor who visits your site w... | 19 | 2010-02-15T15:30:09Z | [
"python",
"django",
"django-forms",
"pagination"
] |
Paginating the results of a Django forms POST request | 2,266,554 | <p>I'm using Django Forms to do a filtered/faceted search via POST, and I would like to Django's paginator class to organize the results. How do I preserve the original request when passing the client between the various pages? In other words, it seems that I lose the POST data as soon as I pass the GET request for a... | 15 | 2010-02-15T14:31:25Z | 3,170,694 | <p>Have the search form and the results display on one single django template. Initially, use css to hide the results display area. On POSTing the form, you could check to see if the search returned any results and hide the search form with css if results exist. If results do not exist, use css to hide the results disp... | 0 | 2010-07-03T07:30:28Z | [
"python",
"django",
"django-forms",
"pagination"
] |
Paginating the results of a Django forms POST request | 2,266,554 | <p>I'm using Django Forms to do a filtered/faceted search via POST, and I would like to Django's paginator class to organize the results. How do I preserve the original request when passing the client between the various pages? In other words, it seems that I lose the POST data as soon as I pass the GET request for a... | 15 | 2010-02-15T14:31:25Z | 18,106,904 | <p>Reading the very nice answer from tux21b I decided to implement the first option, i.e., to use the session to store the query. This is an application that searches real estate databases. Here is the view code (using django 1.5):</p>
<pre><code>def main_search(request):
search_form = UserSearchForm()
return ... | 3 | 2013-08-07T15:02:12Z | [
"python",
"django",
"django-forms",
"pagination"
] |
Paginating the results of a Django forms POST request | 2,266,554 | <p>I'm using Django Forms to do a filtered/faceted search via POST, and I would like to Django's paginator class to organize the results. How do I preserve the original request when passing the client between the various pages? In other words, it seems that I lose the POST data as soon as I pass the GET request for a... | 15 | 2010-02-15T14:31:25Z | 25,934,635 | <p>As @rvnovaes, a way to use session to solve the matter.</p>
<p>The drawback of his solution is that if there are many search fields you have to write many lines of code, and also if you show the search form in the result page, all the fields will be blank, while they should keep their values. </p>
<p>So I'd rather... | 3 | 2014-09-19T13:05:47Z | [
"python",
"django",
"django-forms",
"pagination"
] |
How to I disable and re-enable console logging in Python? | 2,266,646 | <p>I am using python <a href="http://docs.python.org/library/logging.html">logging</a> module and I want to disable the console logging for some time but it doesn't work.</p>
<pre><code>
#!/usr/bin/python
import logging
logger = logging.getLogger() # this gets the root logger
# ... here I add my own handlers ... | 68 | 2010-02-15T14:48:06Z | 2,266,786 | <p>I don't know the logging module very well, but I'm using it in the way that I usually want to disable only debug (or info) messages. You can use <code>Handler.setLevel()</code> to set the logging level to CRITICAL or higher.</p>
<p>Also, you could replace sys.stderr and sys.stdout by a file open for writing. See <a... | 1 | 2010-02-15T15:07:19Z | [
"python",
"logging",
"console",
"stdout"
] |
How to I disable and re-enable console logging in Python? | 2,266,646 | <p>I am using python <a href="http://docs.python.org/library/logging.html">logging</a> module and I want to disable the console logging for some time but it doesn't work.</p>
<pre><code>
#!/usr/bin/python
import logging
logger = logging.getLogger() # this gets the root logger
# ... here I add my own handlers ... | 68 | 2010-02-15T14:48:06Z | 2,267,162 | <p>No need to divert stdout. Here is better way to do it:</p>
<pre><code>import logging
class MyLogHandler(logging.Handler):
def emit(self, record):
pass
logging.getLogger().addHandler(MyLogHandler())
</code></pre>
<p>An even simpler way is:</p>
<pre><code>logging.getLogger().setLevel(100)
</code></pre>... | 7 | 2010-02-15T16:05:17Z | [
"python",
"logging",
"console",
"stdout"
] |
How to I disable and re-enable console logging in Python? | 2,266,646 | <p>I am using python <a href="http://docs.python.org/library/logging.html">logging</a> module and I want to disable the console logging for some time but it doesn't work.</p>
<pre><code>
#!/usr/bin/python
import logging
logger = logging.getLogger() # this gets the root logger
# ... here I add my own handlers ... | 68 | 2010-02-15T14:48:06Z | 2,267,304 | <p>You can use:</p>
<pre><code>logging.basicConfig(level=your_level)
</code></pre>
<p>where <strong>your_level</strong> is one of those:</p>
<pre><code> 'debug': logging.DEBUG,
'info': logging.INFO,
'warning': logging.WARNING,
'error': logging.ERROR,
'critical': logging.CRITICAL
</code><... | 42 | 2010-02-15T16:25:52Z | [
"python",
"logging",
"console",
"stdout"
] |
How to I disable and re-enable console logging in Python? | 2,266,646 | <p>I am using python <a href="http://docs.python.org/library/logging.html">logging</a> module and I want to disable the console logging for some time but it doesn't work.</p>
<pre><code>
#!/usr/bin/python
import logging
logger = logging.getLogger() # this gets the root logger
# ... here I add my own handlers ... | 68 | 2010-02-15T14:48:06Z | 2,267,567 | <p>I found a solution for this:</p>
<pre><code>logger = logging.getLogger('my-logger')
logger.propagate = False
# now if you use logger it will not log to console.
</code></pre>
<p>This will prevent logging from being send to the upper logger that includes the console logging.</p>
| 106 | 2010-02-15T17:04:33Z | [
"python",
"logging",
"console",
"stdout"
] |
How to I disable and re-enable console logging in Python? | 2,266,646 | <p>I am using python <a href="http://docs.python.org/library/logging.html">logging</a> module and I want to disable the console logging for some time but it doesn't work.</p>
<pre><code>
#!/usr/bin/python
import logging
logger = logging.getLogger() # this gets the root logger
# ... here I add my own handlers ... | 68 | 2010-02-15T14:48:06Z | 3,116,067 | <p>I use:</p>
<pre><code>logger = logging.getLogger()
logger.disabled = True
... whatever you want ...
logger.disabled = False
</code></pre>
| 38 | 2010-06-25T06:42:24Z | [
"python",
"logging",
"console",
"stdout"
] |
How to I disable and re-enable console logging in Python? | 2,266,646 | <p>I am using python <a href="http://docs.python.org/library/logging.html">logging</a> module and I want to disable the console logging for some time but it doesn't work.</p>
<pre><code>
#!/usr/bin/python
import logging
logger = logging.getLogger() # this gets the root logger
# ... here I add my own handlers ... | 68 | 2010-02-15T14:48:06Z | 6,459,613 | <p>(long dead question, but for future searchers)</p>
<p>Closer to the original poster's code/intent, this works for me under python 2.6</p>
<pre><code>#!/usr/bin/python
import logging
logger = logging.getLogger() # this gets the root logger
lhStdout = logger.handlers[0] # stdout is the only handler initially
# .... | 24 | 2011-06-23T19:31:31Z | [
"python",
"logging",
"console",
"stdout"
] |
How to I disable and re-enable console logging in Python? | 2,266,646 | <p>I am using python <a href="http://docs.python.org/library/logging.html">logging</a> module and I want to disable the console logging for some time but it doesn't work.</p>
<pre><code>
#!/usr/bin/python
import logging
logger = logging.getLogger() # this gets the root logger
# ... here I add my own handlers ... | 68 | 2010-02-15T14:48:06Z | 8,495,374 | <p>There are some really nice answers here, but apparently the simplest is not taken too much in consideration (only from infinito).</p>
<pre><code>root_logger = logging.getLogger()
root_logger.disabled = True
</code></pre>
<p>This disables the root logger, and thus all the other loggers.
I haven't really tested but ... | 18 | 2011-12-13T19:59:21Z | [
"python",
"logging",
"console",
"stdout"
] |
How to I disable and re-enable console logging in Python? | 2,266,646 | <p>I am using python <a href="http://docs.python.org/library/logging.html">logging</a> module and I want to disable the console logging for some time but it doesn't work.</p>
<pre><code>
#!/usr/bin/python
import logging
logger = logging.getLogger() # this gets the root logger
# ... here I add my own handlers ... | 68 | 2010-02-15T14:48:06Z | 20,251,235 | <p>Context manager</p>
<pre><code>import logging
class DisableLogger():
def __enter__(self):
logging.disable(logging.CRITICAL)
def __exit__(self, a, b, c):
logging.disable(logging.NOTSET)
</code></pre>
<p>Example of use:</p>
<pre><code>with DisableLogger():
do_something()
</code></pre>
| 19 | 2013-11-27T19:19:44Z | [
"python",
"logging",
"console",
"stdout"
] |
How to I disable and re-enable console logging in Python? | 2,266,646 | <p>I am using python <a href="http://docs.python.org/library/logging.html">logging</a> module and I want to disable the console logging for some time but it doesn't work.</p>
<pre><code>
#!/usr/bin/python
import logging
logger = logging.getLogger() # this gets the root logger
# ... here I add my own handlers ... | 68 | 2010-02-15T14:48:06Z | 28,986,845 | <p>You could also:</p>
<pre><code>handlers = app.logger.handlers
# detach console handler
app.logger.handlers = []
# attach
app.logger.handlers = handlers
</code></pre>
| 1 | 2015-03-11T12:38:36Z | [
"python",
"logging",
"console",
"stdout"
] |
How to break the following line of python | 2,266,659 | <p>I have come upon a couple of lines of code similar to this one, but I'm unsure how I should break it:</p>
<pre><code>blueprint = Blueprint(self.blueprint_map[str(self.ui.blueprint_combo.currentText())], runs=self.ui.runs_spin.text(), me=self.ui.me_spin.text(), pe=self.ui.pe_skill_combo.currentIndex())
</code></pre>... | 2 | 2010-02-15T14:50:05Z | 2,266,684 | <p>Anywhere within the brackets should work, such as:</p>
<pre><code>blueprint = Blueprint(self.blueprint_map[str(self.ui.blueprint_combo.currentText())],
runs=self.ui.runs_spin.text(), me=self.ui.me_spin.text(),
pe=self.ui.pe_skill_combo.currentIndex())
</code></pre>
| 0 | 2010-02-15T14:53:04Z | [
"python",
"pep8"
] |
How to break the following line of python | 2,266,659 | <p>I have come upon a couple of lines of code similar to this one, but I'm unsure how I should break it:</p>
<pre><code>blueprint = Blueprint(self.blueprint_map[str(self.ui.blueprint_combo.currentText())], runs=self.ui.runs_spin.text(), me=self.ui.me_spin.text(), pe=self.ui.pe_skill_combo.currentIndex())
</code></pre>... | 2 | 2010-02-15T14:50:05Z | 2,266,687 | <pre><code>blueprint = Blueprint(
self.blueprint_map[str(self.ui.blueprint_combo.currentText())],
runs=self.ui.runs_spin.text(),
me=self.ui.me_spin.text(),
pe=self.ui.pe_skill_combo.currentIndex(),
)
</code></pre>
| 14 | 2010-02-15T14:53:39Z | [
"python",
"pep8"
] |
How to break the following line of python | 2,266,659 | <p>I have come upon a couple of lines of code similar to this one, but I'm unsure how I should break it:</p>
<pre><code>blueprint = Blueprint(self.blueprint_map[str(self.ui.blueprint_combo.currentText())], runs=self.ui.runs_spin.text(), me=self.ui.me_spin.text(), pe=self.ui.pe_skill_combo.currentIndex())
</code></pre>... | 2 | 2010-02-15T14:50:05Z | 2,266,688 | <pre><code>blueprint = Blueprint(self.blueprint_map[str(self.ui.blueprint_combo.currentText())],
runs=self.ui.runs_spin.text(), me=self.ui.me_spin.text(),
pe=self.ui.pe_skill_combo.currentIndex())
</code></pre>
| 0 | 2010-02-15T14:53:50Z | [
"python",
"pep8"
] |
How to break the following line of python | 2,266,659 | <p>I have come upon a couple of lines of code similar to this one, but I'm unsure how I should break it:</p>
<pre><code>blueprint = Blueprint(self.blueprint_map[str(self.ui.blueprint_combo.currentText())], runs=self.ui.runs_spin.text(), me=self.ui.me_spin.text(), pe=self.ui.pe_skill_combo.currentIndex())
</code></pre>... | 2 | 2010-02-15T14:50:05Z | 2,266,689 | <p>I'd do it this way:</p>
<pre><code>blueprint = Blueprint(
self.blueprint_map[str(self.ui.blueprint_combo.currentText())],
runs=self.ui.runs_spin.text(),
me=self.ui.me_spin.text(),
pe=self.ui.pe_skill_combo.currentIndex())
</code></pre>
| 4 | 2010-02-15T14:53:50Z | [
"python",
"pep8"
] |
How to break the following line of python | 2,266,659 | <p>I have come upon a couple of lines of code similar to this one, but I'm unsure how I should break it:</p>
<pre><code>blueprint = Blueprint(self.blueprint_map[str(self.ui.blueprint_combo.currentText())], runs=self.ui.runs_spin.text(), me=self.ui.me_spin.text(), pe=self.ui.pe_skill_combo.currentIndex())
</code></pre>... | 2 | 2010-02-15T14:50:05Z | 2,266,691 | <p>How about this</p>
<pre><code>blueprint_item = self.blueprint_map[str(self.ui.blueprint_combo.currentText())]
blueprint = Blueprint(blueprint_item,
runs=self.ui.runs_spin.text(),
me=self.ui.me_spin.text(),
pe=self.ui.pe_skill_combo.currentIndex())
</... | 5 | 2010-02-15T14:53:54Z | [
"python",
"pep8"
] |
Making super() work in Python's urllib2.Request | 2,267,016 | <p>This afternoon I spent several hours trying to find a bug in my custom extension to <code>urllib2.Request</code>. The problem was, as I found out, the usage of <code>super(ExtendedRequest, self)</code>, since <code>urllib2.Request</code> is (I'm on Python 2.5) still an old style class, where the use of <code>super()... | 1 | 2010-02-15T15:43:11Z | 2,267,043 | <p>This should work fine since the hierarchy is simple</p>
<pre><code>class ExtendedRequest(urllib2.Request):
def __init__(self,...):
urllib2.Request.__init__(self,...)
</code></pre>
| 1 | 2010-02-15T15:46:41Z | [
"python",
"request",
"urllib2",
"super",
"new-style-class"
] |
Making super() work in Python's urllib2.Request | 2,267,016 | <p>This afternoon I spent several hours trying to find a bug in my custom extension to <code>urllib2.Request</code>. The problem was, as I found out, the usage of <code>super(ExtendedRequest, self)</code>, since <code>urllib2.Request</code> is (I'm on Python 2.5) still an old style class, where the use of <code>super()... | 1 | 2010-02-15T15:43:11Z | 2,267,059 | <p>I think you missed to pass the self parameter to definition of <strong>init</strong> in your sample.
Try this one:</p>
<pre><code>class ExtendedRequest(object, urllib2.Request):
def __init__(self):
super(ExtendedRequest, self).__init__(self)
</code></pre>
<p>I tested it and it seems to work okey:</p>
... | 0 | 2010-02-15T15:50:07Z | [
"python",
"request",
"urllib2",
"super",
"new-style-class"
] |
Making super() work in Python's urllib2.Request | 2,267,016 | <p>This afternoon I spent several hours trying to find a bug in my custom extension to <code>urllib2.Request</code>. The problem was, as I found out, the usage of <code>super(ExtendedRequest, self)</code>, since <code>urllib2.Request</code> is (I'm on Python 2.5) still an old style class, where the use of <code>super()... | 1 | 2010-02-15T15:43:11Z | 2,268,782 | <p>Using super may not always be the best-practice. There are many difficulties with using super. Read James Knight's <a href="http://fuhm.org/super-harmful/" rel="nofollow">http://fuhm.org/super-harmful/</a> for examples.</p>
<p>That link shows (among other issues) that </p>
<p><OL>
<LI> Superclasses must use super ... | 1 | 2010-02-15T20:46:37Z | [
"python",
"request",
"urllib2",
"super",
"new-style-class"
] |
Django legacy database encoding | 2,267,242 | <p>I'm sure this question is not specific to django, but since I couldn't find any solution for my problem in other questions about python and encodings, I'm going to ask this.
I need to add new features to existing website which is written in PHP using MySQL as backend. I inspected the database and created models for ... | 0 | 2010-02-15T16:17:23Z | 2,269,333 | <p>Check your mysql connection parameters. Also, You can specify DATABASE_OPTIONS:</p>
<pre><code>DATABASE_OPTIONS = {
"charset": "utf8",
"init_command": "SET storage_engine=InnoDB",
}
</code></pre>
<p>But check out if it's really utf-8. Also note that connection and server encoding must be in sync. </p>
| 1 | 2010-02-15T22:19:36Z | [
"python",
"django",
"encoding"
] |
Django legacy database encoding | 2,267,242 | <p>I'm sure this question is not specific to django, but since I couldn't find any solution for my problem in other questions about python and encodings, I'm going to ask this.
I need to add new features to existing website which is written in PHP using MySQL as backend. I inspected the database and created models for ... | 0 | 2010-02-15T16:17:23Z | 2,276,145 | <p>Actually this problem was the database's previous character set and collation- it was latin1, but data was inserted using utf-8 charset. It was solved by exporting data using latin1 charset, replacing all occurences of latin1 with utf8 and importing data again. This answer shows how to do this: <a href="http://stack... | 1 | 2010-02-16T20:38:02Z | [
"python",
"django",
"encoding"
] |
Is there a Django ModelField that allows for multiple choices, aside from ManyToMany? | 2,267,332 | <p>I'd like the user to be able to make multiple selections via the admin interface, and store the result as a list of comma-separated values. A select-multiple or a list of checkboxes would be great. However, I don't need the items in this list of values to refer to any models in particular... I just want a text list ... | 12 | 2010-02-15T16:29:20Z | 2,267,379 | <p>There is a django snippet which does just this: <a href="http://www.djangosnippets.org/snippets/1200/">multiple choice model field</a>. It says:</p>
<blockquote>
<p>Usually you want to store multiple
choices as a manytomany link to
another table. Sometimes however it is
useful to store them in the model
i... | 9 | 2010-02-15T16:34:38Z | [
"python",
"django",
"forms"
] |
Is there a Django ModelField that allows for multiple choices, aside from ManyToMany? | 2,267,332 | <p>I'd like the user to be able to make multiple selections via the admin interface, and store the result as a list of comma-separated values. A select-multiple or a list of checkboxes would be great. However, I don't need the items in this list of values to refer to any models in particular... I just want a text list ... | 12 | 2010-02-15T16:29:20Z | 4,373,542 | <p>This django snippet accomplishes the same with a much smaller footprint.</p>
<p><a href="http://djangosnippets.org/snippets/23/" rel="nofollow">http://djangosnippets.org/snippets/23/</a></p>
<p>make sure to update those imports since they are pre version 1.0</p>
| 0 | 2010-12-07T04:58:27Z | [
"python",
"django",
"forms"
] |
Is there a Django ModelField that allows for multiple choices, aside from ManyToMany? | 2,267,332 | <p>I'd like the user to be able to make multiple selections via the admin interface, and store the result as a list of comma-separated values. A select-multiple or a list of checkboxes would be great. However, I don't need the items in this list of values to refer to any models in particular... I just want a text list ... | 12 | 2010-02-15T16:29:20Z | 20,485,990 | <p>Django-multiselectfield does what you require:</p>
<p><a href="https://github.com/goinnn/django-multiselectfield" rel="nofollow">https://github.com/goinnn/django-multiselectfield</a></p>
<p>It's inspired by the snippet that Alexander mentioned.</p>
| 3 | 2013-12-10T04:17:46Z | [
"python",
"django",
"forms"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 2,267,404 | <p>Python doesn't have a built-in function for printing an integer in an arbitrary base. You'll have to write your own if you want to.</p>
| 9 | 2010-02-15T16:39:09Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 2,267,411 | <p><a href="http://code.activestate.com/recipes/65212/" rel="nofollow">http://code.activestate.com/recipes/65212/</a></p>
<pre><code>def base10toN(num,n):
"""Change a to a base-n number.
Up to base-36 is supported without special notation."""
num_rep={10:'a',
11:'b',
12:'c',
13:... | 4 | 2010-02-15T16:40:00Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 2,267,428 | <pre><code>def baseN(num,b,numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
return ((num == 0) and numerals[0]) or (baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b])
</code></pre>
<p>ref:
<a href="http://code.activestate.com/recipes/65212/">http://code.activestate.com/recipes/65212/</a></p>
| 67 | 2010-02-15T16:41:46Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 2,267,446 | <p>If you need compatibility with ancient versions of Python, you can either use <a href="https://github.com/aleaxit/gmpy">gmpy</a> (which does include a fast, completely general int-to-string conversion function, and can be built for such ancient versions -- you may need to try older releases since the recent ones hav... | 52 | 2010-02-15T16:44:10Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 2,267,453 | <pre><code>>>> import string
>>> def int2base(integer, base):
if not integer: return '0'
sign = 1 if integer > 0 else -1
alphanum = string.digits + string.ascii_lowercase
nums = alphanum[:base]
res = ''
integer *= sign
while integer:
... | 1 | 2010-02-15T16:45:34Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 2,267,721 | <p>Great answers!
I guess the answer to my question was "no" I was not missing some obvious solution.
Here is the function I will use that condenses the good ideas expressed in the answers.</p>
<ul>
<li>allow caller-supplied mapping of characters (allows base64 encode)</li>
<li>checks for negative and zero</li>
<li>m... | 16 | 2010-02-15T17:28:27Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 3,647,418 | <pre><code>"{0:b}".format(100) # bin: 1100100
"{0:x}".format(100) # hex: 64
"{0:o}".format(100) # oct: 144
</code></pre>
| 41 | 2010-09-05T19:23:40Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 12,590,717 | <p>You could use baseconv.py: <a href="https://github.com/semente/python-baseconv" rel="nofollow">https://github.com/semente/python-baseconv</a></p>
<p>Sample usage:</p>
<pre><code>>>> from baseconv import BaseConverter
>>> base20 = BaseConverter('0123456789abcdefghij')
>>> base20.encode(12... | 8 | 2012-09-25T20:42:40Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 26,188,870 | <pre><code>def base(decimal ,base) :
list = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
other_base = ""
while decimal != 0 :
other_base = list[decimal % base] + other_base
decimal = decimal / base
return other_base
print base(31 ,16)
</code></pre>
<p>output:</p>
<blockquote>
<p>"1F"</... | 1 | 2014-10-04T01:53:01Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 28,171,255 | <p>A recursive solution for those interested. Of course, this will not work with negative binary values. You would need to implement Two's Complement.</p>
<pre><code>def generateBase36Alphabet():
return ''.join([str(i) for i in range(10)]+[chr(i+65) for i in range(26)])
def generateAlphabet(base):
return gene... | 0 | 2015-01-27T13:05:30Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 28,666,223 | <p>Surprisingly, people were giving only solutions that convert to small bases (smaller then the length of the English alphabet). There was no attempt to give a solution which converts to any arbitrary base from 2 to infinity.</p>
<p>So here is a super simple solution:</p>
<pre><code>def numberToBase(n, b):
if n ... | 32 | 2015-02-23T02:48:46Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 30,479,693 | <p>I'm working on making a pip package for this.</p>
<p>I recommend you use my bases.py <a href="https://github.com/kamijoutouma/bases.py" rel="nofollow">https://github.com/kamijoutouma/bases.py</a> which was inspired by bases.js</p>
<pre><code>from bases import Bases
bases = Bases()
bases.toBase16(200) ... | 1 | 2015-05-27T10:21:54Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 31,929,915 | <pre><code>def dec_to_radix(input, to_radix=2, power=None):
if not isinstance(input, int):
raise TypeError('Not an integer!')
elif power is None:
power = 1
if input == 0:
return 0
else:
remainder = input % to_radix**power
digit = str(int(remainder/to_radix**(powe... | 0 | 2015-08-10T22:01:40Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 34,968,601 | <p>def baseConverter(x, b):</p>
<pre><code>s = ""
d = string.printable.upper()
while x > 0:
s += d[x%b]
x = x / b
return s[::-1]
</code></pre>
| 0 | 2016-01-23T20:41:17Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 35,015,687 | <p>Another short one (and easier to understand imo):</p>
<pre><code>def int_to_str(n, b, symbols='0123456789abcdefghijklmnopqrstuvwxyz'):
return (int_to_str(n/b, b, symbols) if n >= b else "") + symbols[n%b]
</code></pre>
<p>And with proper exception handling:</p>
<pre><code>def int_to_str(n, b, symbols='0123... | 0 | 2016-01-26T14:05:44Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 36,822,890 | <pre><code>def int2base(a, base, numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
baseit = lambda a=a, b=base: (not a) and numerals[0] or baseit(a-a%b,b*base)+numerals[a%b%(base-1) or (a%b) and (base-1)]
return baseit()
</code></pre>
<hr>
<h2>explanation</h2>
<p>In any base every number is equal to <code>a... | 0 | 2016-04-24T12:07:24Z | [
"python",
"base",
"radix"
] |
convert integer to a string in a given numeric base in python | 2,267,362 | <p>Python allows easy creation of an integer from a string of a given base via </p>
<pre><code>int(str,base).
</code></pre>
<p>I want to perform the inverse: creation of a string from an integer.
i.e. I want some function int2base(num,base)<br>
such that:</p>
<pre><code>int( int2base( X , BASE ) , BASE ) == X
</c... | 103 | 2010-02-15T16:33:01Z | 37,330,025 | <p>Another solution, works with base 2 to 10, needs modification for higher bases:</p>
<pre><code>def n2b(n, b):
if n == 0:
return 0
d = []
while n:
d.append(int(n % b))
n /= b
return ''.join(map(str,d[::-1]))
</code></pre>
<p>Example:</p>
<pre><code>n2b(10,2) => '10100'
in... | 0 | 2016-05-19T17:17:45Z | [
"python",
"base",
"radix"
] |
overloading augmented arithmetic assignments in python | 2,267,466 | <p>I'm new to Python so apologies in advance if this is a stupid question.</p>
<p>For an assignment I need to overload augmented arithmetic assignments(+=, -=, /=, <em>=, *</em>=, %=) for a class myInt. I checked the Python documentation and this is what I came up with:</p>
<pre><code>def __iadd__(self, other):
... | 6 | 2010-02-15T16:46:30Z | 2,267,486 | <p>You need to add <code>return self</code> to your method. Explanation:</p>
<p>The semantics of <code>a += b</code>, when <code>type(a)</code> has a special method <code>__iadd__</code>, are defined to be:</p>
<pre><code> a = a.__iadd__(b)
</code></pre>
<p>so if <code>__iadd__</code> returns something different t... | 13 | 2010-02-15T16:50:04Z | [
"python",
"operators",
"operator-overloading"
] |
overloading augmented arithmetic assignments in python | 2,267,466 | <p>I'm new to Python so apologies in advance if this is a stupid question.</p>
<p>For an assignment I need to overload augmented arithmetic assignments(+=, -=, /=, <em>=, *</em>=, %=) for a class myInt. I checked the Python documentation and this is what I came up with:</p>
<pre><code>def __iadd__(self, other):
... | 6 | 2010-02-15T16:46:30Z | 2,267,503 | <p>Yes, you need "return self", it will look like this:</p>
<pre><code>def __iadd__(self, other):
if isinstance(other, myInt):
self.a += other.a
return self
elif type(other) == int:
self.a += other
return self
else:
raise Exception("invalid argument")
</code></pre>
| 1 | 2010-02-15T16:52:20Z | [
"python",
"operators",
"operator-overloading"
] |
overloading augmented arithmetic assignments in python | 2,267,466 | <p>I'm new to Python so apologies in advance if this is a stupid question.</p>
<p>For an assignment I need to overload augmented arithmetic assignments(+=, -=, /=, <em>=, *</em>=, %=) for a class myInt. I checked the Python documentation and this is what I came up with:</p>
<pre><code>def __iadd__(self, other):
... | 6 | 2010-02-15T16:46:30Z | 2,267,669 | <p>Augmented operators in Python have to return the final value to be assigned to the name they are called on, usually (and in your case) <code>self</code>. Like all Python methods, missing a return statement implies returning <code>None</code>.</p>
<p>Also,</p>
<ul>
<li>Never ever ever raise <code>Exception</code>, ... | 7 | 2010-02-15T17:17:52Z | [
"python",
"operators",
"operator-overloading"
] |
How do I get the content-type from return of urlopen(url) in python2.x? | 2,267,568 | <p>Are theere any functions in 3.x using the http.client.HTTPMessage().get_content_type() ?</p>
| 1 | 2010-02-15T17:04:51Z | 2,267,630 | <p><a href="http://docs.python.org/library/urllib2.html#urllib2.urlopen" rel="nofollow"><code>urllib2.urlopen()</code></a> returns an <code>addinfourl</code> with <code>headers</code>:</p>
<pre><code>>>> import urllib2
>>> f = urllib2.urlopen('http://www.python.org/')
>>> f.headers['content-... | 3 | 2010-02-15T17:12:20Z | [
"python"
] |
Python .flv media file conversion | 2,267,952 | <p>I'm looking for a library similar to FFDshow to help me convert .flv to .avi format and possibly do more. I understand that I can do this via VLC player, but I'd rather do it manually with Python (and in bulk).</p>
<p>Similar to:<br>
<a href="http://stackoverflow.com/questions/1233685/media-conversion-library-plugi... | 3 | 2010-02-15T18:08:31Z | 2,270,006 | <p><a href="http://gstreamer.freedesktop.org/modules/gst-python.html" rel="nofollow"><code>pygst</code></a> with the right plugins can read .flv files (and write other formats).</p>
| 2 | 2010-02-16T01:02:28Z | [
"python",
"flv",
"multimedia",
"bulk"
] |
Python .flv media file conversion | 2,267,952 | <p>I'm looking for a library similar to FFDshow to help me convert .flv to .avi format and possibly do more. I understand that I can do this via VLC player, but I'd rather do it manually with Python (and in bulk).</p>
<p>Similar to:<br>
<a href="http://stackoverflow.com/questions/1233685/media-conversion-library-plugi... | 3 | 2010-02-15T18:08:31Z | 2,270,022 | <p>Use <code>ffmpeg</code>. You can invoke it from python, if you want to.</p>
<pre><code>ffmpeg -i in.flv -f avi -vcodec mpeg4 -acodec libmp3lame out.avi
</code></pre>
<p>Full ducumentation for converting files with ffmpeg can be found <a href="http://www.ffmpeg.org/ffmpeg-doc.html#SEC5" rel="nofollow">here</a>.</p>... | 1 | 2010-02-16T01:07:27Z | [
"python",
"flv",
"multimedia",
"bulk"
] |
Dynamic class loading in Python 2.6: RuntimeWarning: Parent module 'plugins' not found while handling absolute import | 2,267,984 | <p>I am working on a plugin system where plugin modules are loaded like this: </p>
<pre><code>def load_plugins():
plugins=glob.glob("plugins/*.py")
instances=[]
for p in plugins:
try:
name=p.split("/")[-1]
name=name.split(".py")[0]
log.debug("Possible plugin: %s", name)
... | 20 | 2010-02-15T18:13:26Z | 2,268,003 | <p>If the plugins directory does not have an <code>__init__.py</code>, it isn't a package, so when you create <code>plugins.whatever</code>, Python warns you that such a thing shouldn't really exist. (It couldn't be created by "<code>import plugins.whatever</code>" no matter what your path is.)</p>
<p>Also,</p>
<ul>
... | 13 | 2010-02-15T18:16:31Z | [
"python",
"plugins",
"import",
"dynamic-class-loaders"
] |
Dynamic class loading in Python 2.6: RuntimeWarning: Parent module 'plugins' not found while handling absolute import | 2,267,984 | <p>I am working on a plugin system where plugin modules are loaded like this: </p>
<pre><code>def load_plugins():
plugins=glob.glob("plugins/*.py")
instances=[]
for p in plugins:
try:
name=p.split("/")[-1]
name=name.split(".py")[0]
log.debug("Possible plugin: %s", name)
... | 20 | 2010-02-15T18:13:26Z | 2,268,226 | <p>If the directory <code>plugins</code> were a real package (contained <code>__init__.py</code> fine), you could easily use pkgutils to enumerate its plugin files and load them.</p>
<pre><code>import pkgutil
# import our package
import plugins
list(pkgutil.iter_modules(plugins.__path__))
</code></pre>
<p>However, it... | 12 | 2010-02-15T18:54:37Z | [
"python",
"plugins",
"import",
"dynamic-class-loaders"
] |
Dynamic class loading in Python 2.6: RuntimeWarning: Parent module 'plugins' not found while handling absolute import | 2,267,984 | <p>I am working on a plugin system where plugin modules are loaded like this: </p>
<pre><code>def load_plugins():
plugins=glob.glob("plugins/*.py")
instances=[]
for p in plugins:
try:
name=p.split("/")[-1]
name=name.split(".py")[0]
log.debug("Possible plugin: %s", name)
... | 20 | 2010-02-15T18:13:26Z | 26,437,636 | <p>The problem here is with the dot ('.') in the module name:</p>
<p><code>imp.load_module('plugins.'+name, f, file, desc)</code></p>
<p>Don't include a '.' after 'plugins', or Python will think it's a module path.</p>
| 2 | 2014-10-18T08:08:08Z | [
"python",
"plugins",
"import",
"dynamic-class-loaders"
] |
Dynamic class loading in Python 2.6: RuntimeWarning: Parent module 'plugins' not found while handling absolute import | 2,267,984 | <p>I am working on a plugin system where plugin modules are loaded like this: </p>
<pre><code>def load_plugins():
plugins=glob.glob("plugins/*.py")
instances=[]
for p in plugins:
try:
name=p.split("/")[-1]
name=name.split(".py")[0]
log.debug("Possible plugin: %s", name)
... | 20 | 2010-02-15T18:13:26Z | 39,635,562 | <p>The Python <a href="https://docs.python.org/2/library/imp.html" rel="nofollow"><code>imp</code></a> documentation has been updated since this was answered. It now addresses this issue specifically in the <a href="https://docs.python.org/2/library/imp.html#imp.find_module" rel="nofollow"><code>find_module()</code></a... | 0 | 2016-09-22T09:42:00Z | [
"python",
"plugins",
"import",
"dynamic-class-loaders"
] |
How can I use a large wxCursor? | 2,267,986 | <p>The <a href="http://docs.wxwidgets.org/2.8/wx_wxcursor.html" rel="nofollow">wx.Cursor</a> class automatically scales the image I give it to 32x32 and I need to use a cursor that is larger than that.</p>
<p>On <a href="http://support.microsoft.com/kb/307213" rel="nofollow">http://support.microsoft.com/kb/307213</a> ... | 0 | 2010-02-15T18:13:57Z | 2,272,600 | <p>It turns out wx doesn't do anything to support non standard sized cursors.</p>
<p><a href="http://groups.google.com/group/wxpython-users/browse_thread/thread/326aea0d740b85dd/277483ad5df77539" rel="nofollow">http://groups.google.com/group/wxpython-users/browse_thread/thread/326aea0d740b85dd/277483ad5df77539</a></p>... | 0 | 2010-02-16T11:49:13Z | [
"python",
"windows",
"wxpython"
] |
How to convert from IEEE Python float to Microsoft Basic float | 2,268,191 | <p>I got Python float value and I need to convert it in to Microsoft Basic Float (MBF) format.
Luckily, Got some code from internet that does the reverse.</p>
<pre><code>def fmsbin2ieee(self,bytes):
"""Convert an array of 4 bytes containing Microsoft Binary floating point
number to IEEE floating point format (... | 3 | 2010-02-15T18:47:40Z | 2,268,360 | <p>If you're going to perform these conversions while running under Windows, faster might be to download and install <a href="http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20245266.html" rel="nofollow">mbf2ieee.exe</a> and call the <code>CVS</code> function offered by the resulting <code>Mbf2iee... | 4 | 2010-02-15T19:21:11Z | [
"python",
"mbf"
] |
How to convert from IEEE Python float to Microsoft Basic float | 2,268,191 | <p>I got Python float value and I need to convert it in to Microsoft Basic Float (MBF) format.
Luckily, Got some code from internet that does the reverse.</p>
<pre><code>def fmsbin2ieee(self,bytes):
"""Convert an array of 4 bytes containing Microsoft Binary floating point
number to IEEE floating point format (... | 3 | 2010-02-15T18:47:40Z | 3,441,442 | <p>Well, I tried <code>float2mbf4byte()</code> and made 2 modifications: </p>
<ol>
<li>converting negative values is now working,</li>
<li>for Python 2, ieee should be list of int's, not string</li>
</ol>
<p>The snippet:</p>
<pre><code>def float2mbf4byte(f):
ieee = [ord(s) for s in struct.pack('f', f)]
msbin... | 0 | 2010-08-09T15:12:58Z | [
"python",
"mbf"
] |
Can you auto hide frames/dialogs using wxPython? | 2,268,315 | <p>I would like to create an application that has 3-4 frames (or windows) where each frame is attached/positioned to a side of the screen (like a task bar). When a frame is inactive I would like it to auto hide (just like the Windows task bar does; or the dock in OSX). When I move my mouse pointer to the position on th... | 1 | 2010-02-15T19:11:23Z | 2,269,311 | <p>As far as I know, there's nothing built in for this.</p>
<p>When the window is hidden, do you want it completely invisible or can a border of a few pixels be showing? That would be an easy way to get a mouse hover event. Otherwise you might have to use something like <a href="http://pyhook.sourceforge.net/" rel="... | 1 | 2010-02-15T22:16:50Z | [
"python",
"animation",
"wxpython",
"mouseevent"
] |
Can you auto hide frames/dialogs using wxPython? | 2,268,315 | <p>I would like to create an application that has 3-4 frames (or windows) where each frame is attached/positioned to a side of the screen (like a task bar). When a frame is inactive I would like it to auto hide (just like the Windows task bar does; or the dock in OSX). When I move my mouse pointer to the position on th... | 1 | 2010-02-15T19:11:23Z | 9,066,380 | <p>Personally, I would combine the EVT_ENTER_WINDOW and EVT_LEAVE_WINDOW that FogleBird mentioned with a wx.Timer. Then whenever it the frame or dialog is inactive for x seconds, you would just call its Hide() method. </p>
| 0 | 2012-01-30T15:34:47Z | [
"python",
"animation",
"wxpython",
"mouseevent"
] |
Expire a view-cache in Django? | 2,268,417 | <p>The <code>@cache_page decorator</code> is awesome. But for my blog I would like to keep a page in cache until someone comments on a post. This sounds like a great idea as people rarely comment so keeping the pages in memcached while nobody comments would be great. I'm thinking that someone must have had this problem... | 30 | 2010-02-15T19:33:39Z | 2,268,583 | <p>The cache_page decorator will use CacheMiddleware in the end which will generate a cache key based on the request (look at <code>django.utils.cache.get_cache_key</code>) and the key_prefix ("blog" in your case). Note that "blog" is only a prefix, not the whole cache key.</p>
<p>You can get notified via <a href="htt... | 2 | 2010-02-15T20:05:32Z | [
"python",
"django",
"caching"
] |
Expire a view-cache in Django? | 2,268,417 | <p>The <code>@cache_page decorator</code> is awesome. But for my blog I would like to keep a page in cache until someone comments on a post. This sounds like a great idea as people rarely comment so keeping the pages in memcached while nobody comments would be great. I'm thinking that someone must have had this problem... | 30 | 2010-02-15T19:33:39Z | 2,269,095 | <p>Instead of using the cache page decorator, you could manually cache the blog post object (or similar) if there are no comments, and then when there's a first comment, <em>re-cache</em> the blog post object so that it's up to date (assuming the object has attributes that reference any comments), but then just let tha... | 2 | 2010-02-15T21:34:19Z | [
"python",
"django",
"caching"
] |
Expire a view-cache in Django? | 2,268,417 | <p>The <code>@cache_page decorator</code> is awesome. But for my blog I would like to keep a page in cache until someone comments on a post. This sounds like a great idea as people rarely comment so keeping the pages in memcached while nobody comments would be great. I'm thinking that someone must have had this problem... | 30 | 2010-02-15T19:33:39Z | 2,363,690 | <p>Here's a solution I wrote to do just what you're talking about on some of my own projects:</p>
<pre><code>def expire_view_cache(view_name, args=[], namespace=None, key_prefix=None):
"""
This function allows you to invalidate any view-level cache.
view_name: view function you wish to invalidate or i... | 35 | 2010-03-02T14:17:47Z | [
"python",
"django",
"caching"
] |
Expire a view-cache in Django? | 2,268,417 | <p>The <code>@cache_page decorator</code> is awesome. But for my blog I would like to keep a page in cache until someone comments on a post. This sounds like a great idea as people rarely comment so keeping the pages in memcached while nobody comments would be great. I'm thinking that someone must have had this problem... | 30 | 2010-02-15T19:33:39Z | 5,890,333 | <p>I wrote <a href="http://syfou.bitbucket.org/django-groupcache/">Django-groupcache</a> for this kind of situations (you can <a href="https://bitbucket.org/syfou/django-groupcache">download the code here</a>). In your case, you could write:</p>
<pre><code>from groupcache.decorators import cache_tagged_page
@cache_ta... | 9 | 2011-05-04T21:55:58Z | [
"python",
"django",
"caching"
] |
Expire a view-cache in Django? | 2,268,417 | <p>The <code>@cache_page decorator</code> is awesome. But for my blog I would like to keep a page in cache until someone comments on a post. This sounds like a great idea as people rarely comment so keeping the pages in memcached while nobody comments would be great. I'm thinking that someone must have had this problem... | 30 | 2010-02-15T19:33:39Z | 7,455,114 | <p>FWIW I had to modify mazelife's solution to get it working:</p>
<pre><code>def expire_view_cache(view_name, args=[], namespace=None, key_prefix=None, method="GET"):
"""
This function allows you to invalidate any view-level cache.
view_name: view function you wish to invalidate or it's named url pat... | 2 | 2011-09-17T13:28:44Z | [
"python",
"django",
"caching"
] |
Expire a view-cache in Django? | 2,268,417 | <p>The <code>@cache_page decorator</code> is awesome. But for my blog I would like to keep a page in cache until someone comments on a post. This sounds like a great idea as people rarely comment so keeping the pages in memcached while nobody comments would be great. I'm thinking that someone must have had this problem... | 30 | 2010-02-15T19:33:39Z | 26,403,585 | <p>This won't work on django 1.7; as you can see here <a href="https://docs.djangoproject.com/en/dev/releases/1.7/#cache-keys-are-now-generated-from-the-request-s-absolute-url" rel="nofollow">https://docs.djangoproject.com/en/dev/releases/1.7/#cache-keys-are-now-generated-from-the-request-s-absolute-url</a> the new cac... | 4 | 2014-10-16T11:46:49Z | [
"python",
"django",
"caching"
] |
Expire a view-cache in Django? | 2,268,417 | <p>The <code>@cache_page decorator</code> is awesome. But for my blog I would like to keep a page in cache until someone comments on a post. This sounds like a great idea as people rarely comment so keeping the pages in memcached while nobody comments would be great. I'm thinking that someone must have had this problem... | 30 | 2010-02-15T19:33:39Z | 35,692,654 | <p>Instead of explicit cache expiration you could probably use new "key_prefix" every time somebody comment the post. E.g. it might be datetime of the last post's comment (you could even combine this value with the <code>Last-Modified</code> header).</p>
<p>Unfortunately Django (including <code>cache_page()</code>) do... | 0 | 2016-02-29T05:38:10Z | [
"python",
"django",
"caching"
] |
Expire a view-cache in Django? | 2,268,417 | <p>The <code>@cache_page decorator</code> is awesome. But for my blog I would like to keep a page in cache until someone comments on a post. This sounds like a great idea as people rarely comment so keeping the pages in memcached while nobody comments would be great. I'm thinking that someone must have had this problem... | 30 | 2010-02-15T19:33:39Z | 36,845,722 | <p>Django view cache invalidation for v1.7 and above. Tested on Django 1.9.</p>
<pre><code>def invalidate_cache(path=''):
''' this function uses Django's caching function get_cache_key(). Since 1.7,
Django has used more variables from the request object (scheme, host,
path, and query string) in o... | 0 | 2016-04-25T16:09:04Z | [
"python",
"django",
"caching"
] |
Expire a view-cache in Django? | 2,268,417 | <p>The <code>@cache_page decorator</code> is awesome. But for my blog I would like to keep a page in cache until someone comments on a post. This sounds like a great idea as people rarely comment so keeping the pages in memcached while nobody comments would be great. I'm thinking that someone must have had this problem... | 30 | 2010-02-15T19:33:39Z | 36,953,230 | <p>The solution is simple, and do not require any additional work.</p>
<h2>Example</h2>
<pre><code>@cache_page(60 * 10)
def our_team(request, sorting=None):
...
</code></pre>
<p>This will set the response to cache with the default key.</p>
<h2>Expire a view cache</h2>
<pre><code>from django.utils.cache import ... | -1 | 2016-04-30T09:37:55Z | [
"python",
"django",
"caching"
] |
Expire a view-cache in Django? | 2,268,417 | <p>The <code>@cache_page decorator</code> is awesome. But for my blog I would like to keep a page in cache until someone comments on a post. This sounds like a great idea as people rarely comment so keeping the pages in memcached while nobody comments would be great. I'm thinking that someone must have had this problem... | 30 | 2010-02-15T19:33:39Z | 37,284,892 | <p>Duncan's answer works well with Django 1.9. But if we need invalidate url with GET-parameter we have to make a little changes in request.
Eg for .../?mykey=myvalue</p>
<pre><code>request.META = {'SERVER_NAME':'127.0.0.1','SERVER_PORT':8000, 'REQUEST_METHOD':'GET', 'QUERY_STRING': 'mykey=myvalue'}
request.GET.__set... | 0 | 2016-05-17T19:38:03Z | [
"python",
"django",
"caching"
] |
Grab a line's whitespace/indention with Python | 2,268,532 | <p>Basically, if I have a line of text which starts with indention, what's the best way to grab that indention and put it into a variable in Python? For example, if the line is:</p>
<pre><code>\t\tthis line has two tabs of indention
</code></pre>
<p>Then it would return '\t\t'. Or, if the line was:</p>
<pre><code> ... | 8 | 2010-02-15T19:55:59Z | 2,268,555 | <p>How about using the <a href="http://docs.python.org/library/re.html" rel="nofollow">regex</a> <code>\s*</code> which matches any whitespace characters. You only want the whitespace at the beginning of the line so either <code>search</code> with the regex <code>^\s*</code> or simply <code>match</code> with <code>\s*<... | -1 | 2010-02-15T20:00:29Z | [
"python",
"whitespace",
"indentation"
] |
Grab a line's whitespace/indention with Python | 2,268,532 | <p>Basically, if I have a line of text which starts with indention, what's the best way to grab that indention and put it into a variable in Python? For example, if the line is:</p>
<pre><code>\t\tthis line has two tabs of indention
</code></pre>
<p>Then it would return '\t\t'. Or, if the line was:</p>
<pre><code> ... | 8 | 2010-02-15T19:55:59Z | 2,268,559 | <pre><code>import re
s = "\t\tthis line has two tabs of indention"
re.match(r"\s*", s).group()
// "\t\t"
s = " this line has four spaces of indention"
re.match(r"\s*", s).group()
// " "
</code></pre>
<p>And to strip leading spaces, use <a href="http://docs.python.org/library/stdtypes.html#str.lstrip">lstrip</a>.... | 23 | 2010-02-15T20:01:07Z | [
"python",
"whitespace",
"indentation"
] |
Grab a line's whitespace/indention with Python | 2,268,532 | <p>Basically, if I have a line of text which starts with indention, what's the best way to grab that indention and put it into a variable in Python? For example, if the line is:</p>
<pre><code>\t\tthis line has two tabs of indention
</code></pre>
<p>Then it would return '\t\t'. Or, if the line was:</p>
<pre><code> ... | 8 | 2010-02-15T19:55:59Z | 2,268,565 | <p>If you're interested in using regular expressions you can use that. <code>/\s/</code> usually matches one whitespace character, so <code>/^\s+/</code> would match the whitespace starting a line.</p>
| -1 | 2010-02-15T20:02:29Z | [
"python",
"whitespace",
"indentation"
] |
Grab a line's whitespace/indention with Python | 2,268,532 | <p>Basically, if I have a line of text which starts with indention, what's the best way to grab that indention and put it into a variable in Python? For example, if the line is:</p>
<pre><code>\t\tthis line has two tabs of indention
</code></pre>
<p>Then it would return '\t\t'. Or, if the line was:</p>
<pre><code> ... | 8 | 2010-02-15T19:55:59Z | 2,268,588 | <p>A sneaky way: abuse <code>lstrip</code>!</p>
<pre><code>fullstr = "\t\tthis line has two tabs of indentation"
startwhites = fullstr[:len(fullstr)-len(fullstr.lstrip())]
</code></pre>
<p>This way you don't have to work through all the details of whitespace!</p>
<p>(Thanks Adam for the correction)</p>
| 10 | 2010-02-15T20:06:32Z | [
"python",
"whitespace",
"indentation"
] |
Grab a line's whitespace/indention with Python | 2,268,532 | <p>Basically, if I have a line of text which starts with indention, what's the best way to grab that indention and put it into a variable in Python? For example, if the line is:</p>
<pre><code>\t\tthis line has two tabs of indention
</code></pre>
<p>Then it would return '\t\t'. Or, if the line was:</p>
<pre><code> ... | 8 | 2010-02-15T19:55:59Z | 2,268,627 | <p>This can also be done with <code>str.isspace</code> and <code>itertools.takewhile</code> instead of regex. </p>
<pre><code>import itertools
tests=['\t\tthis line has two tabs of indention',
' this line has four spaces of indention']
def indention(astr):
# Using itertools.takewhile is efficient -- th... | 3 | 2010-02-15T20:12:08Z | [
"python",
"whitespace",
"indentation"
] |
Grab a line's whitespace/indention with Python | 2,268,532 | <p>Basically, if I have a line of text which starts with indention, what's the best way to grab that indention and put it into a variable in Python? For example, if the line is:</p>
<pre><code>\t\tthis line has two tabs of indention
</code></pre>
<p>Then it would return '\t\t'. Or, if the line was:</p>
<pre><code> ... | 8 | 2010-02-15T19:55:59Z | 2,268,628 | <pre><code>def whites(a):
return a[0:a.find(a.strip())]
</code></pre>
<p>Basically, the my idea is:</p>
<ol>
<li>Find a strip of starting line</li>
<li>Find a difference between starting line and stripped one</li>
</ol>
| -1 | 2010-02-15T20:12:08Z | [
"python",
"whitespace",
"indentation"
] |
Convert http headers (string) to a python dictionary | 2,268,724 | <p>Is there a standard function that will convert http headers into a python dictionary, and one to convert back?</p>
<p>They would need to support header folding, of course.</p>
| 5 | 2010-02-15T20:36:11Z | 2,268,792 | <p>I'm not entirely sure, but <a href="http://www.python.org/doc/2.5.2/lib/node562.html" rel="nofollow">this</a> seems to be along the lines of what you are looking for</p>
<p>Hope this helps</p>
| 1 | 2010-02-15T20:48:44Z | [
"python",
"http",
"header"
] |
Convert http headers (string) to a python dictionary | 2,268,724 | <p>Is there a standard function that will convert http headers into a python dictionary, and one to convert back?</p>
<p>They would need to support header folding, of course.</p>
| 5 | 2010-02-15T20:36:11Z | 2,268,901 | <p>In case you don't find any library solving the problem, here's a naive, untested solution:</p>
<pre><code>def fold(header):
line = "%s: %s" % (header[0], header[1])
if len(line) < 998:
return line
else: #fold
lines = [line]
while len(lines[-1]) > 998:
split_this = lines[-1]
#fin... | 2 | 2010-02-15T21:07:28Z | [
"python",
"http",
"header"
] |
Convert http headers (string) to a python dictionary | 2,268,724 | <p>Is there a standard function that will convert http headers into a python dictionary, and one to convert back?</p>
<p>They would need to support header folding, of course.</p>
| 5 | 2010-02-15T20:36:11Z | 2,272,948 | <p>Rather than build your own using sockets etc I would use <a href="http://docs.python.org/library/httplib.html" rel="nofollow">httplib</a> Thus would get the data from the http server and parse the headers into a dictionary
e.g.</p>
<pre><code>import httplib
conn = httplib.HTTPConnection("www.python.org")
conn.requ... | 5 | 2010-02-16T12:51:43Z | [
"python",
"http",
"header"
] |
Convert http headers (string) to a python dictionary | 2,268,724 | <p>Is there a standard function that will convert http headers into a python dictionary, and one to convert back?</p>
<p>They would need to support header folding, of course.</p>
| 5 | 2010-02-15T20:36:11Z | 3,995,291 | <p>And this is my version without for iteration:</p>
<pre><code>import re
req_line = re.compile(r'(?P<method>GET|POST)\s+(?P<resource>.+?)\s+(?P<version>HTTP/1.1)')
field_line = re.compile(r'\s*(?P<key>.+\S)\s*:\s+(?P<value>.+\S)\s*')
def parse(http_post):
first_line_end = http_post.... | 0 | 2010-10-22T08:58:11Z | [
"python",
"http",
"header"
] |
Convert http headers (string) to a python dictionary | 2,268,724 | <p>Is there a standard function that will convert http headers into a python dictionary, and one to convert back?</p>
<p>They would need to support header folding, of course.</p>
| 5 | 2010-02-15T20:36:11Z | 6,180,938 | <p>I realize this post is from 2010, but I thought it best to speak up. I agree with <a href="http://stackoverflow.com/questions/2268724/convert-http-headers-string-to-a-python-dictionary/2272948#2272948">Mark's Post</a> up until the dict is assigned.</p>
<p>Since <code>getheaders</code> returns a list of tuples and t... | 1 | 2011-05-30T21:33:45Z | [
"python",
"http",
"header"
] |
QtDesigner or doing all of the Qt boilerplate by hand? | 2,268,853 | <p>When starting up a new project, as a beginner, which would you use? </p>
<p>For example, in my situation. I'm going to have a program running on an infinite loop, constantly updating values. I need these values to be represented as a bar graph as they're updating. At the same time, the GUI has to be responsive ... | 2 | 2010-02-15T20:58:37Z | 2,269,180 | <p>Your right threading is your answer. Use the QT threads they work very well. </p>
<p>Where I work when people start out using QT a lot of them start with designer but eventually end up hand coding it. I think you will end up hand coding it but if you are someone who really likes GUIs you may want to start with D... | 0 | 2010-02-15T21:51:37Z | [
"python",
"user-interface",
"pyqt"
] |
QtDesigner or doing all of the Qt boilerplate by hand? | 2,268,853 | <p>When starting up a new project, as a beginner, which would you use? </p>
<p>For example, in my situation. I'm going to have a program running on an infinite loop, constantly updating values. I need these values to be represented as a bar graph as they're updating. At the same time, the GUI has to be responsive ... | 2 | 2010-02-15T20:58:37Z | 2,269,317 | <p>First of all, the requirements that you've mentioned don't (or shouldn't) have much affect on this decision.</p>
<p>Either way, you're going to have to learn something. You might as well investigate both options, and make the decision yourself. Write a couple of "Hello, World!" apps, then start adding some extra ... | 0 | 2010-02-15T22:17:40Z | [
"python",
"user-interface",
"pyqt"
] |
QtDesigner or doing all of the Qt boilerplate by hand? | 2,268,853 | <p>When starting up a new project, as a beginner, which would you use? </p>
<p>For example, in my situation. I'm going to have a program running on an infinite loop, constantly updating values. I need these values to be represented as a bar graph as they're updating. At the same time, the GUI has to be responsive ... | 2 | 2010-02-15T20:58:37Z | 2,271,799 | <p>If I understood your question correctly, updating the GUI has a little to do with the way you programmed it.</p>
<p>From my experience, it's easier to design a main window (or whatever your top level object is) in Designer, and add some dynamically updated content in a widget(s) created in your code. In most cases,... | 1 | 2010-02-16T09:38:35Z | [
"python",
"user-interface",
"pyqt"
] |
python glib main loop: delaying until loop is entered | 2,268,946 | <p>Is there a way to schedule the execution of a callable until the glib main loop is entered?</p>
<p>Alternatively, is there a signal I can subscribe to that will indicate that the main loop is entered?</p>
| 2 | 2010-02-15T21:13:10Z | 2,268,978 | <p>You can use <a href="http://www.pygtk.org/pygtk2reference/gobject-functions.html#function-gobject--idle-add" rel="nofollow">gobject.idle_add</a> which will schedule a callable to be executed when the main loop is idle. <a href="http://www.pygtk.org/pygtk2reference/gobject-functions.html#function-gobject--timeout-add... | 2 | 2010-02-15T21:17:32Z | [
"python",
"glib"
] |
Python UTF-16 WAVY DASH encoding question / issue | 2,269,171 | <p>I was doing some work today, and came across an issue where something "looked funny". I had been interpreting some string data as utf-8, and checking the encoded form. The data was coming from ldap (Specifically, Active Directory) via python-ldap. No surprises there.</p>
<p>So I came upon the byte sequence '\xe3\x8... | 4 | 2010-02-15T21:48:30Z | 2,269,202 | <p>This seems to be the correct behaviour. The character u'\u3030' when encoded in UTF-16 is the same as the encoding of '00' in UTF-8. It looks strange, but it's correct.</p>
<p>The '\xff\xfe' you can see is just a <a href="http://en.wikipedia.org/wiki/Byte_order_mark" rel="nofollow">Byte Order Mark</a>.</p>
<p>Are ... | 2 | 2010-02-15T21:56:19Z | [
"python",
"unicode",
"encoding",
"utf-8",
"utf-16"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.