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
listlengths
1
5
Creating a doctype with lxml's etree
991,864
<p>I want to add doctypes to my XML documents that I'm generating with LXML's etree. </p> <p>However I cannot figure out how to add a doctype. Hardcoding and concating the string is not an option. </p> <p>I was expecting something along the lines of how PI's are added in etree:</p> <pre><code>pi = etree.PI(...) doc....
10
2009-06-14T00:41:05Z
1,099,484
<p>You can create your document with a doctype to begin with:</p> <pre><code># Adapted from example on http://codespeak.net/lxml/tutorial.html import lxml.etree as et import StringIO s = """&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!DOCTYPE root SYSTEM "test" [ &lt;!ENTITY tasty "cheese"&gt; &lt;!ENTITY eacute...
9
2009-07-08T17:33:40Z
[ "python", "doctype", "lxml", "elementtree" ]
Creating a doctype with lxml's etree
991,864
<p>I want to add doctypes to my XML documents that I'm generating with LXML's etree. </p> <p>However I cannot figure out how to add a doctype. Hardcoding and concating the string is not an option. </p> <p>I was expecting something along the lines of how PI's are added in etree:</p> <pre><code>pi = etree.PI(...) doc....
10
2009-06-14T00:41:05Z
2,858,690
<p>The PI is actually added as a previous element from "doc". Thus, it's not a child of "doc". You must use "doc.getroottree()"</p> <p>Here is an example:</p> <pre><code>&gt;&gt;&gt; root = etree.Element("root") &gt;&gt;&gt; a = etree.SubElement(root, "a") &gt;&gt;&gt; b = etree.SubElement(root, "b") &gt;&gt;&gt; ro...
4
2010-05-18T15:28:42Z
[ "python", "doctype", "lxml", "elementtree" ]
Creating a doctype with lxml's etree
991,864
<p>I want to add doctypes to my XML documents that I'm generating with LXML's etree. </p> <p>However I cannot figure out how to add a doctype. Hardcoding and concating the string is not an option. </p> <p>I was expecting something along the lines of how PI's are added in etree:</p> <pre><code>pi = etree.PI(...) doc....
10
2009-06-14T00:41:05Z
11,298,809
<p>This worked for me:</p> <p><code>print etree.tostring(tree, pretty_print=True, xml_declaration=True, encoding="UTF-8", doctype="&lt;!DOCTYPE TEST_FILE&gt;")</code></p>
20
2012-07-02T18:02:36Z
[ "python", "doctype", "lxml", "elementtree" ]
Why is there no GIL in the Java Virtual Machine? Why does Python need one so bad?
991,904
<p>I'm hoping someone can provide some insight as to what's fundamentally different about the Java Virtual Machine that allows it to implement threads nicely without the need for a Global Interpreter Lock (GIL), while Python necessitates such an evil.</p>
158
2009-06-14T01:12:55Z
991,917
<p>Python (the language) doesn't need a GIL (which is why it can perfectly be implemented on JVM [Jython] and .NET [IronPython], and those implementations multithread freely). CPython (the popular implementation) has always used a GIL for ease of coding (esp. the coding of the garbage collection mechanisms) and of inte...
212
2009-06-14T01:20:55Z
[ "java", "python", "multithreading", "jvm", "gil" ]
Why is there no GIL in the Java Virtual Machine? Why does Python need one so bad?
991,904
<p>I'm hoping someone can provide some insight as to what's fundamentally different about the Java Virtual Machine that allows it to implement threads nicely without the need for a Global Interpreter Lock (GIL), while Python necessitates such an evil.</p>
158
2009-06-14T01:12:55Z
1,162,596
<p>The JVM (at least hotspot) does have a similar concept to the "GIL", it's just much finer in its lock granularity, most of this comes from the GC's in hotspot which are more advanced.</p> <p>In CPython it's one big lock (probably not that true, but good enough for arguments sake), in the JVM it's more spread about ...
41
2009-07-22T01:27:17Z
[ "java", "python", "multithreading", "jvm", "gil" ]
Why is there no GIL in the Java Virtual Machine? Why does Python need one so bad?
991,904
<p>I'm hoping someone can provide some insight as to what's fundamentally different about the Java Virtual Machine that allows it to implement threads nicely without the need for a Global Interpreter Lock (GIL), while Python necessitates such an evil.</p>
158
2009-06-14T01:12:55Z
2,625,688
<p>There is a comment down below in this blog post <a href="http://www.grouplens.org/node/244">http://www.grouplens.org/node/244</a> that hints at the reason why it was so easy dispense with a GIL for IronPython or Jython, it is that CPython uses reference counting whereas the other 2 VMs have garbage collectors.</p> ...
6
2010-04-12T21:45:10Z
[ "java", "python", "multithreading", "jvm", "gil" ]
Why is there no GIL in the Java Virtual Machine? Why does Python need one so bad?
991,904
<p>I'm hoping someone can provide some insight as to what's fundamentally different about the Java Virtual Machine that allows it to implement threads nicely without the need for a Global Interpreter Lock (GIL), while Python necessitates such an evil.</p>
158
2009-06-14T01:12:55Z
37,918,400
<p>Python lacks jit/aot and the time frame it was written at multithreaded processors didn't exist. Alternatively you could recompile everything in Julia lang which lacks GIL and gain some speed boost on your Python code. Also Jython kind of sucks it's slower than Cpython and Java. If you want to stick to Python consid...
0
2016-06-20T09:00:57Z
[ "java", "python", "multithreading", "jvm", "gil" ]
Custom Filter in Django Admin on Django 1.3 or below
991,926
<p>How can I add a custom filter to django admin (the filters that appear on the right side of a model dashboard)? I know its easy to include a filter based on a field of that model, but what about a "calculated" field like this:</p> <pre><code>class NewsItem(models.Model): headline = models.CharField(max_length=...
66
2009-06-14T01:25:39Z
992,427
<p>You can't, unfortunately. Currently non-field items can not be used as list_filter entries.</p> <p>Note that your admin class wouldn't have worked even if it was a field, as a single-item tuple needs a comma: <code>('is_live',)</code></p>
3
2009-06-14T08:17:59Z
[ "python", "django", "django-admin" ]
Custom Filter in Django Admin on Django 1.3 or below
991,926
<p>How can I add a custom filter to django admin (the filters that appear on the right side of a model dashboard)? I know its easy to include a filter based on a field of that model, but what about a "calculated" field like this:</p> <pre><code>class NewsItem(models.Model): headline = models.CharField(max_length=...
66
2009-06-14T01:25:39Z
1,260,346
<p>you have to write a custom FilterSpec (not documentend anywhere). Look here for an example:</p> <p><a href="http://www.djangosnippets.org/snippets/1051/">http://www.djangosnippets.org/snippets/1051/</a></p>
22
2009-08-11T13:25:48Z
[ "python", "django", "django-admin" ]
Custom Filter in Django Admin on Django 1.3 or below
991,926
<p>How can I add a custom filter to django admin (the filters that appear on the right side of a model dashboard)? I know its easy to include a filter based on a field of that model, but what about a "calculated" field like this:</p> <pre><code>class NewsItem(models.Model): headline = models.CharField(max_length=...
66
2009-06-14T01:25:39Z
1,294,952
<p>Thanks to gpilotino for giving me the push into the right direction for implementing this.</p> <p>I noticed the question's code is using a datetime to figure out when its live . So I used the DateFieldFilterSpec and subclassed it.</p> <pre><code>from django.db import models from django.contrib.admin.filterspecs im...
55
2009-08-18T16:19:35Z
[ "python", "django", "django-admin" ]
Custom Filter in Django Admin on Django 1.3 or below
991,926
<p>How can I add a custom filter to django admin (the filters that appear on the right side of a model dashboard)? I know its easy to include a filter based on a field of that model, but what about a "calculated" field like this:</p> <pre><code>class NewsItem(models.Model): headline = models.CharField(max_length=...
66
2009-06-14T01:25:39Z
6,355,234
<p>In current django development version there is the support for custom filters: <a href="https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter" rel="nofollow">https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter</a></p>
9
2011-06-15T08:52:52Z
[ "python", "django", "django-admin" ]
Custom Filter in Django Admin on Django 1.3 or below
991,926
<p>How can I add a custom filter to django admin (the filters that appear on the right side of a model dashboard)? I know its easy to include a filter based on a field of that model, but what about a "calculated" field like this:</p> <pre><code>class NewsItem(models.Model): headline = models.CharField(max_length=...
66
2009-06-14T01:25:39Z
7,712,970
<p>The user supplies goods to some countries postage free. I wanted to filter those countries: </p> <p><strong>All</strong> - all countries, <strong>Yes</strong> - postage free, <strong>No</strong> - charged postage.</p> <p>The main answer for this question did not work for me (Django 1.3) I think because there was n...
2
2011-10-10T12:47:17Z
[ "python", "django", "django-admin" ]
Custom Filter in Django Admin on Django 1.3 or below
991,926
<p>How can I add a custom filter to django admin (the filters that appear on the right side of a model dashboard)? I know its easy to include a filter based on a field of that model, but what about a "calculated" field like this:</p> <pre><code>class NewsItem(models.Model): headline = models.CharField(max_length=...
66
2009-06-14T01:25:39Z
20,678,242
<p>Just a sidenote: You can use the deafult ticks on Django admin more easily like this:</p> <pre><code>def is_live(self): if self.when_to_publish is not None: if ( self.when_to_publish &lt; datetime.now() ): return True else: return False is_live.boolean = True </code></pre>
1
2013-12-19T09:49:29Z
[ "python", "django", "django-admin" ]
Custom Filter in Django Admin on Django 1.3 or below
991,926
<p>How can I add a custom filter to django admin (the filters that appear on the right side of a model dashboard)? I know its easy to include a filter based on a field of that model, but what about a "calculated" field like this:</p> <pre><code>class NewsItem(models.Model): headline = models.CharField(max_length=...
66
2009-06-14T01:25:39Z
25,359,657
<p>Not an optimal way (CPU-wise) but simple and will work, so I do it this way (for my small database). My Django version is 1.6.</p> <p>In admin.py:</p> <pre><code>class IsLiveFilter(admin.SimpleListFilter): title = 'Live' parameter_name = 'islive' def lookups(self, request, model_admin): return ...
2
2014-08-18T09:04:39Z
[ "python", "django", "django-admin" ]
What is this function doing in Python involving urllib2 and BeautifulSoup?
991,967
<p>So I asked a question earlier about retrieving high scores form an html page and another user gave me the following code to help. I am new to python and beautifulsoup so I'm trying to go through some other codes piece by piece. I understand most of it but I dont get what this piece of code is and what its function i...
1
2009-06-14T02:04:19Z
991,980
<p><code>el.findAll(text=True)</code> returns all the text contained within an element and its sub-elements. By text I mean everything not inside a tag; so in <code>&lt;b&gt;hello&lt;/b&gt;</code> then "hello" would be the text but <code>&lt;b&gt;</code> and <code>&lt;/b&gt;</code> would not.</p> <p>That function the...
3
2009-06-14T02:13:37Z
[ "python", "urllib2" ]
Why are 008 and 009 invalid keys for Python dicts?
991,978
<p>Why is it that I can't have 008 or 009 be keys for a Python dict, but 001-007 are fine? Example:</p> <pre><code>some_dict = { 001: "spam", 002: "eggs", 003: "foo", 004: "bar", 008: "anything", # Throws a SyntaxError 009: "nothing" # Throws a SyntaxError } </code></pre> <p><strong>Upda...
13
2009-06-14T02:12:20Z
991,983
<p>Python takes 008 and 009 as octal numbers, therefore...invalid.</p> <p>You can only go up to 007, then the next number would be 010 (8) then 011 (9). Try it in a Python interpreter, and you'll see what I mean.</p>
10
2009-06-14T02:16:19Z
[ "python", "dictionary", "python-2.x" ]
Why are 008 and 009 invalid keys for Python dicts?
991,978
<p>Why is it that I can't have 008 or 009 be keys for a Python dict, but 001-007 are fine? Example:</p> <pre><code>some_dict = { 001: "spam", 002: "eggs", 003: "foo", 004: "bar", 008: "anything", # Throws a SyntaxError 009: "nothing" # Throws a SyntaxError } </code></pre> <p><strong>Upda...
13
2009-06-14T02:12:20Z
991,984
<p>In Python (and many other languages), starting a number with <strong>a leading "0"</strong> indicates an <strong>octal number</strong> (base 8). Using this leading-zero notation is called an <strong>octal literal</strong>. Octal numbers go 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, etc. So <strong>08 (in octal) is invalid</str...
8
2009-06-14T02:16:33Z
[ "python", "dictionary", "python-2.x" ]
Why are 008 and 009 invalid keys for Python dicts?
991,978
<p>Why is it that I can't have 008 or 009 be keys for a Python dict, but 001-007 are fine? Example:</p> <pre><code>some_dict = { 001: "spam", 002: "eggs", 003: "foo", 004: "bar", 008: "anything", # Throws a SyntaxError 009: "nothing" # Throws a SyntaxError } </code></pre> <p><strong>Upda...
13
2009-06-14T02:12:20Z
991,985
<p>In python and some other languages, if you start a number with a 0, the number is interpreted as being in octal (base 8), where only 0-7 are valid digits. You'll have to change your code to this:</p> <pre><code>some_dict = { 1: "spam", 2: "eggs", 3: "foo", 4: "bar", 8: "anything", 9: "noth...
28
2009-06-14T02:16:52Z
[ "python", "dictionary", "python-2.x" ]
Why are 008 and 009 invalid keys for Python dicts?
991,978
<p>Why is it that I can't have 008 or 009 be keys for a Python dict, but 001-007 are fine? Example:</p> <pre><code>some_dict = { 001: "spam", 002: "eggs", 003: "foo", 004: "bar", 008: "anything", # Throws a SyntaxError 009: "nothing" # Throws a SyntaxError } </code></pre> <p><strong>Upda...
13
2009-06-14T02:12:20Z
991,986
<p>@<a href="#991983" rel="nofollow">DoxaLogos</a> is right. It's not that they're invalid keys - they're invalid literals. If you tried to use them in any other context, you'd get the same error.</p>
7
2009-06-14T02:17:12Z
[ "python", "dictionary", "python-2.x" ]
Why are 008 and 009 invalid keys for Python dicts?
991,978
<p>Why is it that I can't have 008 or 009 be keys for a Python dict, but 001-007 are fine? Example:</p> <pre><code>some_dict = { 001: "spam", 002: "eggs", 003: "foo", 004: "bar", 008: "anything", # Throws a SyntaxError 009: "nothing" # Throws a SyntaxError } </code></pre> <p><strong>Upda...
13
2009-06-14T02:12:20Z
991,988
<p>That is because, when you start a number with a <code>0</code>, it is interpreted as an octal number. Since <code>008</code> and <code>009</code> are not octal numbers, it fails.</p> <p>A <code>0</code> precedes an octal number so that you do not have to write <code>(127)₈</code>. From the <a href="http://en.wiki...
2
2009-06-14T02:17:38Z
[ "python", "dictionary", "python-2.x" ]
Can client side python use threads?
992,008
<p>I have never programed in Python before, so excuse my code. I have this script that will run in a terminal but I can't get it to run client side. I am running this in Appcelerator's Titanium application. Anyway, I have been troubleshooting it and it seems that it isn't running the threads at all. Is this a limitatio...
0
2009-06-14T02:29:04Z
1,020,770
<p>The answer, currently (Friday, June 19th, 2009) is yes, it can run threads, but the nothing but the main thread can access JavaScript objects, this includes the DOM. so if you are planning on updating the UI with a threading app, this is not possible... YET. Until the Appcelerator team creates some sort of queue to ...
2
2009-06-20T02:19:48Z
[ "python", "multithreading", "client-side", "titanium", "appcelerator" ]
Building a Python shared object binding with cmake, which depends upon external libraries
992,068
<p>We have a c file called dbookpy.c, which will provide a Python binding some C functions.</p> <p>Next we decided to build a proper .so with cmake, but it seems we are doing something wrong with regards to linking the external library 'libdbook' in the binding:</p> <p>The CMakeLists.txt is as follows:</p> <pre><cod...
5
2009-06-14T03:22:59Z
994,760
<p>You need to link dbookpy against dbook:</p> <pre><code>target_link_libraries(dbookpy dbook) </code></pre> <p>Adding that just after the line <code>ADD_LIBRARY(dbookpy dbookpy)</code> should do it.</p> <p>I see you are using IMPORTED - the help for <code>IMPORTED_LINK_INTERFACE_LIBRARIES</code> reads:</p> <pre><c...
3
2009-06-15T06:44:20Z
[ "python", "c", "unix", "linker", "cmake" ]
Building a Python shared object binding with cmake, which depends upon external libraries
992,068
<p>We have a c file called dbookpy.c, which will provide a Python binding some C functions.</p> <p>Next we decided to build a proper .so with cmake, but it seems we are doing something wrong with regards to linking the external library 'libdbook' in the binding:</p> <p>The CMakeLists.txt is as follows:</p> <pre><cod...
5
2009-06-14T03:22:59Z
997,615
<p>Thanks for your help.</p> <p>You are correct to say that IMPORTED is probably not needed. Adding LINK_LIBRARIES(dbookpy dbook) indeed adds -ldbook to the gcc execution, so thats great.</p> <p>However cmake appears to ignore LINK_DIRECTORIES, and so never finds -ldbook:</p> <pre><code>/usr/bin/gcc -fPIC -share...
2
2009-06-15T18:33:50Z
[ "python", "c", "unix", "linker", "cmake" ]
Transform game pseudo code into python
992,076
<p>Make the computer guess a number that the user chooses between 1 and 1000 in no more than 10 guesses.This assignment uses an algorithm called a binary search. After each guess, the algorithm cuts the number of possible answers to search in half. Pseudocode for the complete program is given below; your task is to tur...
1
2009-06-14T03:28:29Z
992,092
<p>You're obviously very new to programming, and I guess that is one of the reasons for a delayed response from the community. It's tough to decide where to start and how to guide you through this whole exercise.</p> <p>So, before you get a good answer here that includes making you understand what's happening there, a...
4
2009-06-14T03:37:02Z
[ "python", "pseudocode" ]
Transform game pseudo code into python
992,076
<p>Make the computer guess a number that the user chooses between 1 and 1000 in no more than 10 guesses.This assignment uses an algorithm called a binary search. After each guess, the algorithm cuts the number of possible answers to search in half. Pseudocode for the complete program is given below; your task is to tur...
1
2009-06-14T03:28:29Z
992,098
<p>Okay, the nice part about using Python is that it's almost pseudocode anyway.</p> <p>Now, let's think about the individual steps:</p> <ol> <li><p>How do you get the average between high and low?</p></li> <li><p>How do you ask the user if the answerr is correct</p></li> <li><p>What do "if" statements look like in P...
1
2009-06-14T03:42:48Z
[ "python", "pseudocode" ]
Transform game pseudo code into python
992,076
<p>Make the computer guess a number that the user chooses between 1 and 1000 in no more than 10 guesses.This assignment uses an algorithm called a binary search. After each guess, the algorithm cuts the number of possible answers to search in half. Pseudocode for the complete program is given below; your task is to tur...
1
2009-06-14T03:28:29Z
992,100
<blockquote> <p>I don't understand any of this stuff at all!</p> </blockquote> <p>That's pretty problematic, but, fine, let's do one step at a time! Your homework assignment begins:</p> <blockquote> <p>Print instructions to the user</p> </blockquote> <p>So you don't understand ANY of the stuff, you say, so that...
11
2009-06-14T03:43:10Z
[ "python", "pseudocode" ]
Transform game pseudo code into python
992,076
<p>Make the computer guess a number that the user chooses between 1 and 1000 in no more than 10 guesses.This assignment uses an algorithm called a binary search. After each guess, the algorithm cuts the number of possible answers to search in half. Pseudocode for the complete program is given below; your task is to tur...
1
2009-06-14T03:28:29Z
992,153
<p>Before thinking about how to implement this in python (or any language) lets look at the pseudocode, which looks like a pretty good plan to solve the problem. </p> <p>I would guess that one thing you might be getting stuck on is the way the pseudocode references <strong>variables</strong>, like <code>high</code> a...
14
2009-06-14T04:17:12Z
[ "python", "pseudocode" ]
Transform game pseudo code into python
992,076
<p>Make the computer guess a number that the user chooses between 1 and 1000 in no more than 10 guesses.This assignment uses an algorithm called a binary search. After each guess, the algorithm cuts the number of possible answers to search in half. Pseudocode for the complete program is given below; your task is to tur...
1
2009-06-14T03:28:29Z
992,161
<p>Here's a few hints to get you started:</p> <p>Average = Value + Value + Value [...] / Number of Values; (for instance, ((2 + 5 + 3) / (3))</p> <p>Many programming languages use different operator precedence. When I am programming, I always use parentheses when I am unsure about operator precedence. In my example a...
0
2009-06-14T04:24:41Z
[ "python", "pseudocode" ]
Transform game pseudo code into python
992,076
<p>Make the computer guess a number that the user chooses between 1 and 1000 in no more than 10 guesses.This assignment uses an algorithm called a binary search. After each guess, the algorithm cuts the number of possible answers to search in half. Pseudocode for the complete program is given below; your task is to tur...
1
2009-06-14T03:28:29Z
992,278
<p>Welcome to Stack Overflow!</p> <p>The trick here is to realize that your Python program should look almost like the pseudocode.</p> <p>First let's try to understand exactly what the pseudocode is doing. If we had to interact with the program described by the pseudocode, it would look something like this:</p> <pre...
1
2009-06-14T05:59:19Z
[ "python", "pseudocode" ]
Transform game pseudo code into python
992,076
<p>Make the computer guess a number that the user chooses between 1 and 1000 in no more than 10 guesses.This assignment uses an algorithm called a binary search. After each guess, the algorithm cuts the number of possible answers to search in half. Pseudocode for the complete program is given below; your task is to tur...
1
2009-06-14T03:28:29Z
3,795,131
<p>Doesn't match the psudocode exactly but it works. lol ;)</p> <p>I know this is a wicked old post but this is the same assignment I got also. Here is what I ended up with:</p> <pre><code>high = 1000 low = 1 print "Pick a number between 1 and 1000." print "I will guess your number in 10 tries or less." print "Or ...
2
2010-09-25T19:02:28Z
[ "python", "pseudocode" ]
Does running separate python processes avoid the GIL?
992,136
<p>I'm curious in how the Global Interpreter Lock in python actually works. If I have a c++ application launch four separate instances of a python script will they run in parallel on separate cores, or does the GIL go even deeper then just the single process that was launched and control all python process's regardless...
8
2009-06-14T04:07:08Z
992,141
<p>The GIL only affects threads within a single process. The <code>multiprocessing</code> module is in fact an alternative to <code>threading</code> that lets Python programs use multiple cores &amp;c. Your scenario will easily allow use of multiple cores, too.</p>
16
2009-06-14T04:09:11Z
[ "python" ]
Does running separate python processes avoid the GIL?
992,136
<p>I'm curious in how the Global Interpreter Lock in python actually works. If I have a c++ application launch four separate instances of a python script will they run in parallel on separate cores, or does the GIL go even deeper then just the single process that was launched and control all python process's regardless...
8
2009-06-14T04:07:08Z
993,191
<p>As Alex Martelli points out you can indeed avoid the GIL by running multiple processes, I just want to add and point out that the GIL is a limitation of the implementation (CPython) and not of Python in general, it's possible to implement Python without this limitation. <a href="http://www.stackless.com/" rel="nofol...
1
2009-06-14T16:49:48Z
[ "python" ]
Which reactor should i use for qt4?
992,169
<p>I am using twisted and now i want to make some pretty ui using qt</p>
3
2009-06-14T04:31:19Z
992,199
<p>You need a <code>qt4reactor</code>, for example <a href="http://twistedmatrix.com/trac/browser/sandbox/therve/qt4reactor.py?rev=22736" rel="nofollow">this one</a> (but that's a sandbox and thus <strong>not</strong> good for production use -- tx @Glyph for clarifying this!).</p> <p>As @Glyph says, the proper one to ...
4
2009-06-14T04:49:01Z
[ "python", "qt4", "twisted" ]
Which reactor should i use for qt4?
992,169
<p>I am using twisted and now i want to make some pretty ui using qt</p>
3
2009-06-14T04:31:19Z
996,006
<p>You want to use Glen Tarbox's <a href="https://launchpad.net/qt4reactor">qt4reactor</a>.</p>
5
2009-06-15T13:06:39Z
[ "python", "qt4", "twisted" ]
Why am I getting "'ResultSet' has no attribute 'findAll'" using BeautifulSoup in Python?
992,183
<p>So I am learning Python slowly, and am trying to make a simple function that will draw data from the high scores page of an online game. This is someone else's code that i rewrote into one function (which might be the problem), but I am getting this error. Here is the code:</p> <pre><code>&gt;&gt;&gt; from urllib2 ...
7
2009-06-14T04:41:27Z
992,291
<p>Wow. Triptych provided a <a href="http://stackoverflow.com/questions/989872/how-do-i-draw-out-specific-data-from-an-opened-url-in-python-using-urllib2/989920#989920"><em>great</em> answer</a> to a related question.</p> <p>We can see, <a href="http://code.google.com/p/google-blog-converters-appengine/source/browse/t...
18
2009-06-14T06:17:16Z
[ "python", "urllib2", "beautifulsoup" ]
django for loop counter break
992,230
<p>This is hopefully a quick/easy one. I know a way to work around this via a custom template tag, but I was curious if there were other methods I was over looking. I've created a gallery function of sorts for my blog, and I have a gallery list page that paginates all my galleries. Now, I don't want to show all the pho...
25
2009-06-14T05:15:53Z
992,243
<p>Use:</p> <pre><code>{% for photos in gallery.photo_set|slice:":3" %} </code></pre>
64
2009-06-14T05:32:19Z
[ "python", "django", "for-loop" ]
django for loop counter break
992,230
<p>This is hopefully a quick/easy one. I know a way to work around this via a custom template tag, but I was curious if there were other methods I was over looking. I've created a gallery function of sorts for my blog, and I have a gallery list page that paginates all my galleries. Now, I don't want to show all the pho...
25
2009-06-14T05:15:53Z
992,548
<p>This is better done in the <code>gallery.photo_set</code> collection. The hard-coded "3" in the template is a bad idea in the long run.</p> <pre><code>class Gallery( object ): def photo_subset( self ): return Photo.objects.filter( gallery_id = self.id )[:3] </code></pre> <p>In your view function, you ca...
1
2009-06-14T09:53:24Z
[ "python", "django", "for-loop" ]
Determining Letter Frequency Of Cipher Text
992,408
<p>I am trying to make a tool that finds the frequencies of letters in some type of cipher text. Lets suppose it is all lowercase a-z no numbers. The encoded message is in a txt file</p> <p>I am trying to build a script to help in cracking of substitution or possibly transposition ciphers.</p> <p>Code so far:</p> <...
4
2009-06-14T08:07:04Z
992,417
<pre><code>import collections d = collections.defaultdict(int) for c in 'test': d[c] += 1 print d # defaultdict(&lt;type 'int'&gt;, {'s': 1, 'e': 1, 't': 2}) </code></pre> <p>From a file:</p> <pre><code>myfile = open('test.txt') for line in myfile: line = line.rstrip('\n') for c in line: d[c] +=...
17
2009-06-14T08:12:00Z
[ "python", "encryption", "cryptography" ]
Determining Letter Frequency Of Cipher Text
992,408
<p>I am trying to make a tool that finds the frequencies of letters in some type of cipher text. Lets suppose it is all lowercase a-z no numbers. The encoded message is in a txt file</p> <p>I am trying to build a script to help in cracking of substitution or possibly transposition ciphers.</p> <p>Code so far:</p> <...
4
2009-06-14T08:07:04Z
992,463
<p>If you want to know the <a href="http://en.wikipedia.org/wiki/Relative%5Ffrequency" rel="nofollow">relative frequency</a> of a letter c, you would have to divide number of occurrences of c by the length of the input.</p> <p>For instance, taking Adam's example:</p> <pre><code>s = "andnowforsomethingcompletelydiffer...
2
2009-06-14T08:50:10Z
[ "python", "encryption", "cryptography" ]
Determining Letter Frequency Of Cipher Text
992,408
<p>I am trying to make a tool that finds the frequencies of letters in some type of cipher text. Lets suppose it is all lowercase a-z no numbers. The encoded message is in a txt file</p> <p>I am trying to build a script to help in cracking of substitution or possibly transposition ciphers.</p> <p>Code so far:</p> <...
4
2009-06-14T08:07:04Z
25,826,941
<p>The modern way:</p> <pre><code>from collections import Counter string = "ihavesometextbutidontmindsharing" Counter(string) #&gt;&gt;&gt; Counter({'i': 4, 't': 4, 'e': 3, 'n': 3, 's': 2, 'h': 2, 'm': 2, 'o': 2, 'a': 2, 'd': 2, 'x': 1, 'r': 1, 'u': 1, 'b': 1, 'v': 1, 'g': 1}) </code></pre>
6
2014-09-13T19:38:28Z
[ "python", "encryption", "cryptography" ]
Create zip archive for instant download
992,621
<p>In a web app I am working on, the user can create a zip archive of a folder full of files. Here here's the code:</p> <pre><code>files = torrent[0].files zipfile = z.ZipFile(zipname, 'w') output = "" for f in files: zipfile.write(settings.PYRAT_TRANSMISSION_DOWNLOAD_DIR + "/" + f.name, f.name) downloadurl = s...
5
2009-06-14T10:42:32Z
992,628
<p>Check this <a href="http://stackoverflow.com/questions/67454/serving-dynamically-generated-zip-archives-in-django">Serving dynamically generated ZIP archives in Django</a></p>
11
2009-06-14T10:47:16Z
[ "python", "django", "zip", "archive" ]
Create zip archive for instant download
992,621
<p>In a web app I am working on, the user can create a zip archive of a folder full of files. Here here's the code:</p> <pre><code>files = torrent[0].files zipfile = z.ZipFile(zipname, 'w') output = "" for f in files: zipfile.write(settings.PYRAT_TRANSMISSION_DOWNLOAD_DIR + "/" + f.name, f.name) downloadurl = s...
5
2009-06-14T10:42:32Z
992,637
<p>Does the zip library you are using allow for output to a stream. You could stream directly to the user instead of temporarily writing to a zip file THEN streaming to the user.</p>
2
2009-06-14T10:57:08Z
[ "python", "django", "zip", "archive" ]
Create zip archive for instant download
992,621
<p>In a web app I am working on, the user can create a zip archive of a folder full of files. Here here's the code:</p> <pre><code>files = torrent[0].files zipfile = z.ZipFile(zipname, 'w') output = "" for f in files: zipfile.write(settings.PYRAT_TRANSMISSION_DOWNLOAD_DIR + "/" + f.name, f.name) downloadurl = s...
5
2009-06-14T10:42:32Z
1,080,707
<p>Here's a simple Django view function which zips up (as an example) any readable files in <code>/tmp</code> and returns the zip file.</p> <pre><code>from django.http import HttpResponse import zipfile import os from cStringIO import StringIO # caveats for Python 3.0 apply def somezip(request): file = StringIO()...
4
2009-07-03T20:16:18Z
[ "python", "django", "zip", "archive" ]
Create zip archive for instant download
992,621
<p>In a web app I am working on, the user can create a zip archive of a folder full of files. Here here's the code:</p> <pre><code>files = torrent[0].files zipfile = z.ZipFile(zipname, 'w') output = "" for f in files: zipfile.write(settings.PYRAT_TRANSMISSION_DOWNLOAD_DIR + "/" + f.name, f.name) downloadurl = s...
5
2009-06-14T10:42:32Z
1,103,491
<p>It is possible to pass an iterator to the constructor of a HttpResponse <a href="http://docs.djangoproject.com/en/dev/ref/request-response/?from=olddocs#passing-iterators" rel="nofollow">(see docs)</a>. That would allow you to create a custom iterator that generates data as it is being requested. However I don't thi...
0
2009-07-09T12:19:50Z
[ "python", "django", "zip", "archive" ]
Create zip archive for instant download
992,621
<p>In a web app I am working on, the user can create a zip archive of a folder full of files. Here here's the code:</p> <pre><code>files = torrent[0].files zipfile = z.ZipFile(zipname, 'w') output = "" for f in files: zipfile.write(settings.PYRAT_TRANSMISSION_DOWNLOAD_DIR + "/" + f.name, f.name) downloadurl = s...
5
2009-06-14T10:42:32Z
9,829,044
<p>As mandrake says, constructor of HttpResponse accepts iterable objects. </p> <p>Luckily, ZIP format is such that archive can be created in single pass, central directory record is located at the very end of file:</p> <p><img src="http://i.stack.imgur.com/sQMBQ.jpg" alt="enter image description here"></p> <p>(Pict...
7
2012-03-22T19:19:18Z
[ "python", "django", "zip", "archive" ]
How to setup twill for python 2.6 on Windows?
992,638
<p>I have already downloaded twill 0.9. Also, I have installed easy_install for python 2.6. Now I'm stuck with twill installation. Could you help me to settle the problem? </p>
0
2009-06-14T10:57:27Z
992,642
<p>Something like:</p> <pre><code>easy_install twill </code></pre> <p>It assumes you have easy_install in your PATH, which is the case on unix, but not on windows. On windows, the easy_install script can be found in C:\Python25\Scripts</p>
2
2009-06-14T11:00:26Z
[ "python" ]
How to setup twill for python 2.6 on Windows?
992,638
<p>I have already downloaded twill 0.9. Also, I have installed easy_install for python 2.6. Now I'm stuck with twill installation. Could you help me to settle the problem? </p>
0
2009-06-14T10:57:27Z
992,645
<p>easiest way is to just unzip the twill and keep it somewhere in PYTHONPATH e.g. in your project and just import twill</p> <p>else copy twill folder directly to D:\Python26\Lib\site-packages</p>
1
2009-06-14T11:03:37Z
[ "python" ]
Writing text with diacritic ("nikud", vocalization marks) using PIL (Python Imaging Library)
993,265
<p>Writing simple text on an image using PIL is easy.</p> <pre><code>draw = ImageDraw.Draw(img) draw.text((10, y), text2, font=font, fill=forecolor ) </code></pre> <p>However, when I try to write Hebrew punctuation marks (called "nikud" or ניקוד), the characters do not overlap as they should. (I would guess this...
4
2009-06-14T17:28:14Z
994,091
<p>Looks to me that the case is quite simple. You can use True Type fonts and use</p> <p>Here's the example:<a href="http://www.leancrew.com/all-this/2008/11/truetype-fonts-for-the-python-imaging-library/" rel="nofollow">True type fonts for PIL</a></p> <p>Here you can find Hebrew True Type fonts: <a href="http://www....
0
2009-06-15T00:10:06Z
[ "python", "unicode", "fonts", "python-imaging-library", "hebrew" ]
Writing text with diacritic ("nikud", vocalization marks) using PIL (Python Imaging Library)
993,265
<p>Writing simple text on an image using PIL is easy.</p> <pre><code>draw = ImageDraw.Draw(img) draw.text((10, y), text2, font=font, fill=forecolor ) </code></pre> <p>However, when I try to write Hebrew punctuation marks (called "nikud" or ניקוד), the characters do not overlap as they should. (I would guess this...
4
2009-06-14T17:28:14Z
1,020,099
<p>What system are you working on? It works for me on my Gentoo system; the order of the letters is reversed (I just copy-pasted from your question), which seems correct to me although I don't know much about RTL languages.</p> <pre><code>Python 2.5.4 (r254:67916, May 31 2009, 16:56:01) [GCC 4.3.3] on linux2 Type "hel...
2
2009-06-19T21:26:31Z
[ "python", "unicode", "fonts", "python-imaging-library", "hebrew" ]
Writing text with diacritic ("nikud", vocalization marks) using PIL (Python Imaging Library)
993,265
<p>Writing simple text on an image using PIL is easy.</p> <pre><code>draw = ImageDraw.Draw(img) draw.text((10, y), text2, font=font, fill=forecolor ) </code></pre> <p>However, when I try to write Hebrew punctuation marks (called "nikud" or ניקוד), the characters do not overlap as they should. (I would guess this...
4
2009-06-14T17:28:14Z
25,727,238
<p>As for <strong>Arabic</strong> diacritics : Python +<strong>Wand</strong>(Python Lib) +arabic_reshaper(Python Lib) +bidi.algorithme(Python Lib). The same applies to <strong>PIL/Pillow</strong>, you need to use the <code>arabic_reshaper</code> and <code>bidi.algorithm</code> and pass the generated text to <code>draw....
3
2014-09-08T14:59:38Z
[ "python", "unicode", "fonts", "python-imaging-library", "hebrew" ]
Writing text with diacritic ("nikud", vocalization marks) using PIL (Python Imaging Library)
993,265
<p>Writing simple text on an image using PIL is easy.</p> <pre><code>draw = ImageDraw.Draw(img) draw.text((10, y), text2, font=font, fill=forecolor ) </code></pre> <p>However, when I try to write Hebrew punctuation marks (called "nikud" or ניקוד), the characters do not overlap as they should. (I would guess this...
4
2009-06-14T17:28:14Z
25,751,321
<p>funny, after 5 years, and with great help fron @Nasser Al-Wohaibi, I realized how to do it:</p> <p>Reversing the text with a BIDI algorithm was needed.</p> <pre><code># -*- coding: utf-8 -*- from bidi.algorithm import get_display import PIL.Image, PIL.ImageFont, PIL.ImageDraw img= PIL.Image.new("L", (400, 200)) dr...
0
2014-09-09T18:22:34Z
[ "python", "unicode", "fonts", "python-imaging-library", "hebrew" ]
Error while I use math.atan in Python!
993,274
<p>When I do <code>1/2</code> in Python why does it give me zero? Even if I coerce it with <code>float(1/2)</code> still I get zero. Why? And how can I get around it?</p> <p>When I give <code>arctan(1/2)</code> I get 0 as answer, but when I give <code>arctan(.5)</code> I get the correct answer!</p>
0
2009-06-14T17:34:19Z
993,275
<pre><code>float(1)/float(2) </code></pre> <p>If you divide int / int you get an int, so float(0) still gives you 0.0</p>
2
2009-06-14T17:36:09Z
[ "python" ]
Error while I use math.atan in Python!
993,274
<p>When I do <code>1/2</code> in Python why does it give me zero? Even if I coerce it with <code>float(1/2)</code> still I get zero. Why? And how can I get around it?</p> <p>When I give <code>arctan(1/2)</code> I get 0 as answer, but when I give <code>arctan(.5)</code> I get the correct answer!</p>
0
2009-06-14T17:34:19Z
993,276
<pre><code>atan(float(1)/2) </code></pre> <p>If you do: </p> <pre><code>atan(float(1/2)) </code></pre> <p>in Python 2.x, but without:</p> <pre><code>from __future__ import division </code></pre> <p>the 1/2 is evaluated first as 0, then 0 is converted to a float, then atan(0.0) is called. This changes in Python 3, ...
3
2009-06-14T17:36:51Z
[ "python" ]
Error while I use math.atan in Python!
993,274
<p>When I do <code>1/2</code> in Python why does it give me zero? Even if I coerce it with <code>float(1/2)</code> still I get zero. Why? And how can I get around it?</p> <p>When I give <code>arctan(1/2)</code> I get 0 as answer, but when I give <code>arctan(.5)</code> I get the correct answer!</p>
0
2009-06-14T17:34:19Z
993,281
<p>From the standard:</p> <p>The / (division) and // (floor division) operators yield the quotient of their arguments. The numeric arguments are first converted to a common type. Plain or long integer division yields an integer of the same type; the result is that of mathematical division with the ‘floor’ function...
2
2009-06-14T17:38:13Z
[ "python" ]
Error while I use math.atan in Python!
993,274
<p>When I do <code>1/2</code> in Python why does it give me zero? Even if I coerce it with <code>float(1/2)</code> still I get zero. Why? And how can I get around it?</p> <p>When I give <code>arctan(1/2)</code> I get 0 as answer, but when I give <code>arctan(.5)</code> I get the correct answer!</p>
0
2009-06-14T17:34:19Z
993,283
<p>Because Python 2.x uses integer division for integers, so:</p> <pre><code>1/2 == 0 </code></pre> <p>evaluates to True.</p> <p>You want to do:</p> <pre><code>1.0/2 </code></pre> <p>or do a</p> <pre><code>from __future__ import division </code></pre>
7
2009-06-14T17:38:55Z
[ "python" ]
Error while I use math.atan in Python!
993,274
<p>When I do <code>1/2</code> in Python why does it give me zero? Even if I coerce it with <code>float(1/2)</code> still I get zero. Why? And how can I get around it?</p> <p>When I give <code>arctan(1/2)</code> I get 0 as answer, but when I give <code>arctan(.5)</code> I get the correct answer!</p>
0
2009-06-14T17:34:19Z
993,284
<p>As these answers are implying, 1/2 doesn't return what you are expecting. It returns zero, because 1 and 2 are integers (integer division causes numbers to round down). Python 3 changes this behavior, by the way.</p>
1
2009-06-14T17:38:56Z
[ "python" ]
Error while I use math.atan in Python!
993,274
<p>When I do <code>1/2</code> in Python why does it give me zero? Even if I coerce it with <code>float(1/2)</code> still I get zero. Why? And how can I get around it?</p> <p>When I give <code>arctan(1/2)</code> I get 0 as answer, but when I give <code>arctan(.5)</code> I get the correct answer!</p>
0
2009-06-14T17:34:19Z
993,285
<p>Your coercing doesn't stand a chance because the answer is already zero before you hand it to float.</p> <p>Try 1./2</p>
1
2009-06-14T17:39:00Z
[ "python" ]
Error while I use math.atan in Python!
993,274
<p>When I do <code>1/2</code> in Python why does it give me zero? Even if I coerce it with <code>float(1/2)</code> still I get zero. Why? And how can I get around it?</p> <p>When I give <code>arctan(1/2)</code> I get 0 as answer, but when I give <code>arctan(.5)</code> I get the correct answer!</p>
0
2009-06-14T17:34:19Z
993,288
<p>In Python, dividing integers yields an integer -- 0 in this case.</p> <p>There are two possible solutions. One is to force them into floats: 1/2. (note the trailing dot) or float(1)/2.</p> <p>Another is to use "from <strong>future</strong> import division" at the top of your code, and use the behavior you need.</p...
1
2009-06-14T17:39:20Z
[ "python" ]
Error while I use math.atan in Python!
993,274
<p>When I do <code>1/2</code> in Python why does it give me zero? Even if I coerce it with <code>float(1/2)</code> still I get zero. Why? And how can I get around it?</p> <p>When I give <code>arctan(1/2)</code> I get 0 as answer, but when I give <code>arctan(.5)</code> I get the correct answer!</p>
0
2009-06-14T17:34:19Z
993,293
<p>If 1/2 == 0 then float(1/2) will be 0.0. If you coerce it to float after it's been truncated it'll still be truncated.</p> <p>There are a few options:</p> <ul> <li>Add the following import: <code>from __future__ import division</code>. This will make the / operator divide "correctly" in that module. You can use //...
1
2009-06-14T17:41:00Z
[ "python" ]
Error while I use math.atan in Python!
993,274
<p>When I do <code>1/2</code> in Python why does it give me zero? Even if I coerce it with <code>float(1/2)</code> still I get zero. Why? And how can I get around it?</p> <p>When I give <code>arctan(1/2)</code> I get 0 as answer, but when I give <code>arctan(.5)</code> I get the correct answer!</p>
0
2009-06-14T17:34:19Z
993,343
<p>First, <code>1/2</code> is integer division. Until Python 3.0.</p> <pre><code>&gt;&gt;&gt; 1/2 0 &gt;&gt;&gt; 1.0/2.0 0.5 &gt;&gt;&gt; </code></pre> <p>Second, use <code>math.atan2</code> for this kind of thing.</p> <pre><code>&gt;&gt;&gt; math.atan2(1,2) 0.46364760900080609 &gt;&gt;&gt; math.atan(.5) 0.4636476...
6
2009-06-14T17:59:05Z
[ "python" ]
Creating a range of dates in Python
993,358
<p>I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?</p> <pre><code>import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - dat...
125
2009-06-14T18:03:59Z
993,367
<p>Marginally better...</p> <pre><code>base = datetime.datetime.today() date_list = [base - datetime.timedelta(days=x) for x in range(0, numdays)] </code></pre>
188
2009-06-14T18:06:32Z
[ "python", "datetime", "date" ]
Creating a range of dates in Python
993,358
<p>I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?</p> <pre><code>import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - dat...
125
2009-06-14T18:03:59Z
993,369
<p>You can write a generator function that returns date objects starting from today:</p> <pre><code>import datetime def date_generator(): from_date = datetime.datetime.today() while True: yield from_date from_date = from_date - datetime.timedelta(days=1) </code></pre> <p>This generator returns dates star...
24
2009-06-14T18:06:57Z
[ "python", "datetime", "date" ]
Creating a range of dates in Python
993,358
<p>I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?</p> <pre><code>import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - dat...
125
2009-06-14T18:03:59Z
6,046,264
<p>A bit of a late answer I know, but I just had the same problem and decided that Python's internal range function was a bit lacking in this respect so I've overridden it in a util module of mine.</p> <pre><code>from __builtin__ import range as _range from datetime import datetime, timedelta def range(*args): if...
4
2011-05-18T14:21:15Z
[ "python", "datetime", "date" ]
Creating a range of dates in Python
993,358
<p>I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?</p> <pre><code>import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - dat...
125
2009-06-14T18:03:59Z
9,984,132
<p>Here is gist I created, from my own code, this might help. (I know the question is too old, but others can use it)</p> <p><a href="https://gist.github.com/2287345" rel="nofollow">https://gist.github.com/2287345</a></p> <p>(same thing below)</p> <pre><code>import datetime from time import mktime def convert_date_...
2
2012-04-02T21:31:09Z
[ "python", "datetime", "date" ]
Creating a range of dates in Python
993,358
<p>I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?</p> <pre><code>import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - dat...
125
2009-06-14T18:03:59Z
11,324,695
<p>yeah, reinvent the wheel.... just search the forum and you'll get something like this: </p> <pre><code>from dateutil import rrule from datetime import datetime list(rrule.rrule(rrule.DAILY,count=100,dtstart=datetime.now())) </code></pre>
16
2012-07-04T07:52:08Z
[ "python", "datetime", "date" ]
Creating a range of dates in Python
993,358
<p>I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?</p> <pre><code>import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - dat...
125
2009-06-14T18:03:59Z
23,190,286
<p>Pandas is great for time series in general, and has direct support for date ranges.</p> <pre><code>import pandas as pd datelist = pd.date_range(pd.datetime.today(), periods=100).tolist() </code></pre> <p>It also has lots of options to make life easier. For example if you only wanted weekdays, you would just swap i...
57
2014-04-21T03:16:13Z
[ "python", "datetime", "date" ]
Creating a range of dates in Python
993,358
<p>I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?</p> <pre><code>import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - dat...
125
2009-06-14T18:03:59Z
24,637,447
<p>Get range of dates between specified start and end date (Optimized for time &amp; space complexity):</p> <pre><code>import datetime start = datetime.datetime.strptime("21-06-2014", "%d-%m-%Y") end = datetime.datetime.strptime("07-07-2014", "%d-%m-%Y") date_generated = [start + datetime.timedelta(days=x) for x in r...
20
2014-07-08T16:50:27Z
[ "python", "datetime", "date" ]
Creating a range of dates in Python
993,358
<p>I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?</p> <pre><code>import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - dat...
125
2009-06-14T18:03:59Z
29,480,840
<p>Matplotlib related</p> <pre><code>from matplotlib.dates import drange import datetime base = datetime.date.today() end = base + datetime.timedelta(days=100) delta = datetime.timedelta(days=1) l = drange(base, end, delta) </code></pre>
1
2015-04-06T22:38:32Z
[ "python", "datetime", "date" ]
Creating a range of dates in Python
993,358
<p>I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?</p> <pre><code>import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - dat...
125
2009-06-14T18:03:59Z
31,452,467
<pre><code>import datetime def date_generator(): cur = base = datetime.date.today() end = base + datetime.timedelta(days=100) delta = datetime.timedelta(days=1) while(end&gt;base): base = base+delta print base date_generator() </code></pre>
-1
2015-07-16T11:07:55Z
[ "python", "datetime", "date" ]
Creating a range of dates in Python
993,358
<p>I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?</p> <pre><code>import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - dat...
125
2009-06-14T18:03:59Z
32,616,832
<p>You can also use the day ordinal to make it simpler:</p> <pre><code>def daterange(start_date, end_date): for ordinal in range(start_date.toordinal(), end_date.toordinal()): yield datetime.date.fromordinal(ordinal) </code></pre>
13
2015-09-16T19:12:49Z
[ "python", "datetime", "date" ]
Creating a range of dates in Python
993,358
<p>I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?</p> <pre><code>import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - dat...
125
2009-06-14T18:03:59Z
34,533,517
<p>Here's a one liner for bash scripts to get a list of weekdays, this is python 3. Easily modified for whatever, the int at the end is the number of days in the past you want. </p> <pre><code>python -c "import sys,datetime; print('\n'.join([(datetime.datetime.today() - datetime.timedelta(days=x)).strftime(\"%Y/%m/%d\...
3
2015-12-30T16:43:35Z
[ "python", "datetime", "date" ]
Creating a range of dates in Python
993,358
<p>I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?</p> <pre><code>import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - dat...
125
2009-06-14T18:03:59Z
36,637,717
<pre><code>from datetime import datetime, timedelta from dateutil import parser def getDateRange(begin, end): """ """ beginDate = parser.parse(begin) endDate = parser.parse(end) delta = endDate-beginDate numdays = delta.days + 1 dayList = [datetime.strftime(beginDate + timedelta(days=x), '%Y%m...
0
2016-04-15T03:23:29Z
[ "python", "datetime", "date" ]
Creating a range of dates in Python
993,358
<p>I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this?</p> <pre><code>import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - dat...
125
2009-06-14T18:03:59Z
36,651,311
<p>From the title of this question I was expecting to find something like <code>range()</code>, that would let me specify two dates and create a list with all the dates in between. That way one does not need to calculate the number of days between those two dates, if one does not know it beforehand.</p> <p>So with the...
1
2016-04-15T15:33:19Z
[ "python", "datetime", "date" ]
User Authentication And Text Parsing in Python
993,619
<p>Well I am working on a multistage program... I am having trouble getting the first stage done.. What I want to do is log on to Twitter.com, and then read all the direct messages on the user's page.</p> <p>Eventually I am going to be reading all the direct messages looking for certain thing, but that shouldn't be ha...
1
2009-06-14T19:55:10Z
993,643
<p>Twitter does not use HTTP Basic Authentication to authenticate its users. It would be better, in this case, to use the Twitter API. </p> <p>A tutorial for using Python with the Twitter API is here: <a href="http://www.webmonkey.com/tutorial/Get%5FStarted%5FWith%5Fthe%5FTwitter%5FAPI%28"><code>http://www.webmonkey....
5
2009-06-14T20:05:58Z
[ "python", "http", "authentication", "urllib2" ]
User Authentication And Text Parsing in Python
993,619
<p>Well I am working on a multistage program... I am having trouble getting the first stage done.. What I want to do is log on to Twitter.com, and then read all the direct messages on the user's page.</p> <p>Eventually I am going to be reading all the direct messages looking for certain thing, but that shouldn't be ha...
1
2009-06-14T19:55:10Z
993,651
<p>The regular web interface of Twitter does not use basic authentication, so requesting pages from the web interface using this method won't work.</p> <p>According to <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-direct%5Fmessages" rel="nofollow">the Twitter API docs</a>, you can retrieve private mes...
3
2009-06-14T20:11:32Z
[ "python", "http", "authentication", "urllib2" ]
How do I wait for an image to load after an ajax call using jquery?
993,712
<p>I have a Python script that is doing some manipulation on a JPEG image. I pass some parameters to this script and call it from my HTML page. The script returns an img src="newimage.jpg tag.</p> <p>I know how to wait for the reply from the script but I don't know how to tell when the image is fully loaded (when it i...
1
2009-06-14T20:40:07Z
993,720
<p><a href="http://jqueryfordesigners.com/demo/image-load-demo.php" rel="nofollow">Image Loading</a></p> <p><a href="http://www.rodsdot.com/ee/ajaxCallChangeImage.asp" rel="nofollow">Wait for ajaxRequest</a></p>
2
2009-06-14T20:46:03Z
[ "jquery", "python", "ajax" ]
How do I wait for an image to load after an ajax call using jquery?
993,712
<p>I have a Python script that is doing some manipulation on a JPEG image. I pass some parameters to this script and call it from my HTML page. The script returns an img src="newimage.jpg tag.</p> <p>I know how to wait for the reply from the script but I don't know how to tell when the image is fully loaded (when it i...
1
2009-06-14T20:40:07Z
993,806
<p>You can dynamically create a new image, bind something to its load event, and set the source:</p> <pre><code>$('&lt;img&gt;').bind('load', function() { $(this).appendTo('body'); }).attr('src', image_source); </code></pre>
4
2009-06-14T21:32:47Z
[ "jquery", "python", "ajax" ]
How do I wait for an image to load after an ajax call using jquery?
993,712
<p>I have a Python script that is doing some manipulation on a JPEG image. I pass some parameters to this script and call it from my HTML page. The script returns an img src="newimage.jpg tag.</p> <p>I know how to wait for the reply from the script but I don't know how to tell when the image is fully loaded (when it i...
1
2009-06-14T20:40:07Z
993,819
<p>The other answers have mentioned how to do so with jQuery, but regardless of library that you use, ultimately you will be tying into the load event of the image.</p> <p>Without a library, you could do something like this:</p> <pre><code>var el = document.getElementById('ImgLocation'); var img = document.createEle...
0
2009-06-14T21:40:22Z
[ "jquery", "python", "ajax" ]
How to tell a panel that it is being resized when using wx.aui
993,923
<p>I'm using wx.aui to build my user interface. I'm defining a class that inherits from wx.Panel and I need to change the content of that panel when its window pane is resized.</p> <p>I'm using code very similar to the code below (which is a modified version of sample code found <a href="http://stackoverflow.com/quest...
2
2009-06-14T22:27:56Z
993,947
<p>According to the wx.Panel docs, wx.Panel.Layout is called "automatically by the default EVT_SIZE handler when the window is resized."</p> <p>EDIT: However, the above doesn't work as I would expect, so try manually binding EVT_SIZE:</p> <pre><code>class ControlPanel(wx.Panel): def __init__(self, *args, **kwargs...
3
2009-06-14T22:45:49Z
[ "python", "wxpython" ]
Python regular expression with [:numeric:]
994,178
<p>I am having some trouble with Python giving me a result I do not expect. Here is a sample code :</p> <pre><code>number = re.search(" [0-9] ", "test test2 test_ 2 333") print number.groups() number = re.search(" [[:digit:]] ", "test test2 test_ 2 333") print number.groups() </code></pre> <p>In the first block I ge...
2
2009-06-15T01:05:18Z
994,196
<p>Is this what you're looking for?</p> <pre><code>&gt;&gt;&gt; re.findall(r'([0-9])', "test test2 test_ 2 333") ['2', '2', '3', '3', '3'] </code></pre>
1
2009-06-15T01:13:32Z
[ "python", "regex", "bash" ]
Python regular expression with [:numeric:]
994,178
<p>I am having some trouble with Python giving me a result I do not expect. Here is a sample code :</p> <pre><code>number = re.search(" [0-9] ", "test test2 test_ 2 333") print number.groups() number = re.search(" [[:digit:]] ", "test test2 test_ 2 333") print number.groups() </code></pre> <p>In the first block I ge...
2
2009-06-15T01:05:18Z
994,205
<p>You are missing the () which capture the contents for use with the groups() (and other) function(s).</p> <pre><code>number = re.search(" ([0-9]) ", "test test2 test_ 2 333") print number.groups() </code></pre> <p>This however won't work because python does not support the [[:number:]] notation</p> <pre><code>numb...
2
2009-06-15T01:17:40Z
[ "python", "regex", "bash" ]
Python regular expression with [:numeric:]
994,178
<p>I am having some trouble with Python giving me a result I do not expect. Here is a sample code :</p> <pre><code>number = re.search(" [0-9] ", "test test2 test_ 2 333") print number.groups() number = re.search(" [[:digit:]] ", "test test2 test_ 2 333") print number.groups() </code></pre> <p>In the first block I ge...
2
2009-06-15T01:05:18Z
994,212
<pre><code>number = re.search(" [0-9] ", "test test2 test_ 2 333") print number.group(0) </code></pre> <p>groups() only returns groups 1 and up (a bit odd if you're used to other languages).</p>
1
2009-06-15T01:19:50Z
[ "python", "regex", "bash" ]
Python regular expression with [:numeric:]
994,178
<p>I am having some trouble with Python giving me a result I do not expect. Here is a sample code :</p> <pre><code>number = re.search(" [0-9] ", "test test2 test_ 2 333") print number.groups() number = re.search(" [[:digit:]] ", "test test2 test_ 2 333") print number.groups() </code></pre> <p>In the first block I ge...
2
2009-06-15T01:05:18Z
994,217
<p>.groups() returns values inside of matched parentheses. This regex doesn't have any regions defined by parens so groups returns nothing. You want:</p> <blockquote> <blockquote> <blockquote> <p>m = re.search(" ([0-9]) ", "test test2 test_ 2 333") m.groups() ('2',)</p> </blockquote> </...
0
2009-06-15T01:23:04Z
[ "python", "regex", "bash" ]
Python regular expression with [:numeric:]
994,178
<p>I am having some trouble with Python giving me a result I do not expect. Here is a sample code :</p> <pre><code>number = re.search(" [0-9] ", "test test2 test_ 2 333") print number.groups() number = re.search(" [[:digit:]] ", "test test2 test_ 2 333") print number.groups() </code></pre> <p>In the first block I ge...
2
2009-06-15T01:05:18Z
994,218
<p>The groups() method returns the capture groups. It does <em>not</em> return group 0, in case that's what you were expecting. Use parens to indicate capture groups. eg:</p> <pre><code>&gt;&gt;&gt; number = re.search(" ([0-9]) ", "test test2 test_ 2 333") &gt;&gt;&gt; print number.groups() ('2',) </code></pre> <p>Fo...
3
2009-06-15T01:23:07Z
[ "python", "regex", "bash" ]
How can I explicitly disable compilation of _tkinter.c when compiling Python 2.4.3 on CentOS 5?
994,278
<p>I'm trying to explicitly disable the compilation of the _tkinter module when compiling Python 2.4.3. It's easy enough to do by modifying the makefile but I'd rather just append a configuration option to avoid supplying a patch.</p> <p>I do not understand the complex interplay between Modules/Setup*, setup.py and th...
3
2009-06-15T02:05:20Z
994,311
<p>Unfortunately I suspect you can't do it without editing <em>some</em> file or other -- it's not a <code>configure</code> option we wrote in as far as I recall (I hope I'm wrong and somebody else snuck it in while I wasn't looking but a quick look at the configure file seems to confirm they didnt'). Sorry -- we never...
5
2009-06-15T02:27:18Z
[ "python", "compilation", "tkinter" ]
Is the Python Imaging Library not available on PyPI, or am I missing something?
994,281
<p><code>easy_install pil</code> results in an error:</p> <pre><code>Searching for pil Reading http://pypi.python.org/simple/pil/ Reading http://www.pythonware.com/products/pil Reading http://effbot.org/zone/pil-changes-115.htm Reading http://effbot.org/downloads/#Imaging No local packages or download links found for ...
1
2009-06-15T02:08:00Z
994,284
<p>Of course PIL is on PyPi! Specifically, it's <a href="http://pypi.python.org/pypi/PIL/1.1.6">right here</a>.</p>
5
2009-06-15T02:09:35Z
[ "python", "django", "python-imaging-library" ]
Is the Python Imaging Library not available on PyPI, or am I missing something?
994,281
<p><code>easy_install pil</code> results in an error:</p> <pre><code>Searching for pil Reading http://pypi.python.org/simple/pil/ Reading http://www.pythonware.com/products/pil Reading http://effbot.org/zone/pil-changes-115.htm Reading http://effbot.org/downloads/#Imaging No local packages or download links found for ...
1
2009-06-15T02:08:00Z
994,358
<blockquote> <p>import Image</p> </blockquote> <p>Django tries to import PIL directly:</p> <pre><code>from PIL import Image </code></pre> <p>You should check presence of PIL directory in your site-packages</p>
0
2009-06-15T02:59:04Z
[ "python", "django", "python-imaging-library" ]
Is the Python Imaging Library not available on PyPI, or am I missing something?
994,281
<p><code>easy_install pil</code> results in an error:</p> <pre><code>Searching for pil Reading http://pypi.python.org/simple/pil/ Reading http://www.pythonware.com/products/pil Reading http://effbot.org/zone/pil-changes-115.htm Reading http://effbot.org/downloads/#Imaging No local packages or download links found for ...
1
2009-06-15T02:08:00Z
1,214,160
<p>easy_install is case-sensitive. The package is under PIL.</p>
1
2009-07-31T18:39:40Z
[ "python", "django", "python-imaging-library" ]
Is the Python Imaging Library not available on PyPI, or am I missing something?
994,281
<p><code>easy_install pil</code> results in an error:</p> <pre><code>Searching for pil Reading http://pypi.python.org/simple/pil/ Reading http://www.pythonware.com/products/pil Reading http://effbot.org/zone/pil-changes-115.htm Reading http://effbot.org/downloads/#Imaging No local packages or download links found for ...
1
2009-06-15T02:08:00Z
1,271,216
<p>workaround is in easy_install PIL egg directory create link to this directory in name "PIL"</p>
1
2009-08-13T10:39:27Z
[ "python", "django", "python-imaging-library" ]
Is the Python Imaging Library not available on PyPI, or am I missing something?
994,281
<p><code>easy_install pil</code> results in an error:</p> <pre><code>Searching for pil Reading http://pypi.python.org/simple/pil/ Reading http://www.pythonware.com/products/pil Reading http://effbot.org/zone/pil-changes-115.htm Reading http://effbot.org/downloads/#Imaging No local packages or download links found for ...
1
2009-06-15T02:08:00Z
3,228,207
<p>from <a href="http://code.djangoproject.com/ticket/6054" rel="nofollow">http://code.djangoproject.com/ticket/6054</a></p> <p>It seems that there is something wrong with easy_install which installs PIL in the root namespace, installing from sources fixes this, strange.</p>
0
2010-07-12T11:48:34Z
[ "python", "django", "python-imaging-library" ]
OpenOffice.org development with pyUno for Windows—which Python?
994,429
<p>At home, on Linux, I've experimented with pyUNO to control OpenOffice.org using Python. I've been using Python 2.6. It all seems to work nicely.</p> <p>Now I thought I would try one of my scripts (<a href="http://craig.mcqueen.id.au/OpenOfficeGraphicalDiff.html">run a graphical diff for ODF doc</a>) on Windows. But...
7
2009-06-15T03:47:34Z
994,432
<p>Per <a href="http://wiki.services.openoffice.org/wiki/Python" rel="nofollow">openoffice's docs</a>, the Python version supported is WAY behind -- "Efforts on moving PyUNO to Python 2.5 continue", 2.6 not even on the map. So "stuck with this situation for now" is a fair assessment!-)</p>
5
2009-06-15T03:50:11Z
[ "python", "windows", "openoffice.org", "uno", "pyuno" ]
OpenOffice.org development with pyUno for Windows—which Python?
994,429
<p>At home, on Linux, I've experimented with pyUNO to control OpenOffice.org using Python. I've been using Python 2.6. It all seems to work nicely.</p> <p>Now I thought I would try one of my scripts (<a href="http://craig.mcqueen.id.au/OpenOfficeGraphicalDiff.html">run a graphical diff for ODF doc</a>) on Windows. But...
7
2009-06-15T03:47:34Z
995,150
<p>OpenOffice.org 3.1 comes with Python 2.6.1. (As I recall, it was a fairly last-minute merge that ticked some people off, but it's there and it works.) Now the docs are the only thing hopelessly out-of-date. :)</p>
4
2009-06-15T09:09:27Z
[ "python", "windows", "openoffice.org", "uno", "pyuno" ]
OpenOffice.org development with pyUno for Windows—which Python?
994,429
<p>At home, on Linux, I've experimented with pyUNO to control OpenOffice.org using Python. I've been using Python 2.6. It all seems to work nicely.</p> <p>Now I thought I would try one of my scripts (<a href="http://craig.mcqueen.id.au/OpenOfficeGraphicalDiff.html">run a graphical diff for ODF doc</a>) on Windows. But...
7
2009-06-15T03:47:34Z
4,393,670
<p>You can import uno into your system's python on Win32 systems. (Not Python 3 yet). Tutorial at <a href="http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&amp;t=36370&amp;p=166783" rel="nofollow">http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&amp;t=36370&amp;p=166783</a> It's not diffic...
3
2010-12-09T00:14:14Z
[ "python", "windows", "openoffice.org", "uno", "pyuno" ]
Pylons FormEncode with an array of form elements
994,460
<p>I have a Pylons app and am using FormEncode and HtmlFill to handle my forms. I have an array of text fields in my template (Mako)</p> <pre> &lt;tr&gt; &lt;td&gt;Yardage&lt;/td&gt; &lt;td&gt;${h.text('yardage[]', maxlength=3, size=3)}&lt;/td&gt; &lt;td&gt;${h.text('yardage[]', maxlength=3, size=3)}&lt;...
2
2009-06-15T04:04:25Z
1,004,477
<p>Turns out what I wanted to do wasn't quite right. </p> <p><strong>Template</strong>:</p> <pre><code>&lt;tr&gt; &lt;td&gt;Yardage&lt;/td&gt; % for hole in range(9): &lt;td&gt;${h.text('hole-%s.yardage'%(hole), maxlength=3, size=3)}&lt;/td&gt; % endfor &lt;/tr&gt; </code></pre> <p>(Should have made it in a ...
5
2009-06-16T23:56:40Z
[ "python", "pylons", "formencode", "htmlfill" ]
Pylons FormEncode with an array of form elements
994,460
<p>I have a Pylons app and am using FormEncode and HtmlFill to handle my forms. I have an array of text fields in my template (Mako)</p> <pre> &lt;tr&gt; &lt;td&gt;Yardage&lt;/td&gt; &lt;td&gt;${h.text('yardage[]', maxlength=3, size=3)}&lt;/td&gt; &lt;td&gt;${h.text('yardage[]', maxlength=3, size=3)}&lt;...
2
2009-06-15T04:04:25Z
4,025,225
<pre><code>c.form_result = schema.to_python(request.params) - (without dict) </code></pre> <p>It seems to works fine.</p>
1
2010-10-26T15:26:00Z
[ "python", "pylons", "formencode", "htmlfill" ]
What is the equivalent of object oriented constructs in python?
994,476
<p>How does python handle object oriented constructs such as <strong>abstract</strong>, <strong>virtual</strong>, <strong>pure virtual</strong> etc </p> <p>Examples and links would really be good.</p>
9
2009-06-15T04:15:32Z
994,482
<p>An <strong>abstract</strong> method is one that (in the base class) raises <code>NotImplementedError</code>.</p> <p>An abstract class, like in C++, is any class that has one or more abstract methods.</p> <p>All methods in Python are virtual (i.e., all can be overridden by subclasses).</p> <p>A "pure virtual" meth...
28
2009-06-15T04:24:13Z
[ "python", "oop" ]
What is the equivalent of object oriented constructs in python?
994,476
<p>How does python handle object oriented constructs such as <strong>abstract</strong>, <strong>virtual</strong>, <strong>pure virtual</strong> etc </p> <p>Examples and links would really be good.</p>
9
2009-06-15T04:15:32Z
995,520
<p>"How does python handle object oriented constructs such as abstract, virtual, pure virtual etc."</p> <p>These are language constructs more than OO constructs. One can argue that abstract is a language-agnostic concept (even though Python doesn't need it.) Virtual and Pure Virtual are implementation details for C+...
6
2009-06-15T11:03:25Z
[ "python", "oop" ]
Getting an input/output error from Python with pySerial
994,538
<p>I have a Python script that writes data packets to an Arduino board through <a href="http://pyserial.sourceforge.net/" rel="nofollow">pySerial</a>. Sometimes while writing the code to the board pySerial raises an input/output error with errno 5.</p> <p>Some research says that this indicates an error while writing ...
4
2009-06-15T04:55:26Z
994,553
<p>The only issue I can immediately see in your code is an indentation problem -- change your code as follows:</p> <pre><code>try: # Check if it's already a single byte if isinstance(byte, str): if len(byte) == 1: # It is. Send it. self.serial.write(byte) else: # It's not ...
1
2009-06-15T05:03:32Z
[ "python", "serial-port", "arduino", "pyserial" ]
Getting an input/output error from Python with pySerial
994,538
<p>I have a Python script that writes data packets to an Arduino board through <a href="http://pyserial.sourceforge.net/" rel="nofollow">pySerial</a>. Sometimes while writing the code to the board pySerial raises an input/output error with errno 5.</p> <p>Some research says that this indicates an error while writing ...
4
2009-06-15T04:55:26Z
996,077
<p>If you are running this on Windows, you can't have the Arduino IDE open with a serial connection at the same time that you run your Python script. This will throw the same error.</p>
1
2009-06-15T13:21:00Z
[ "python", "serial-port", "arduino", "pyserial" ]
Getting an input/output error from Python with pySerial
994,538
<p>I have a Python script that writes data packets to an Arduino board through <a href="http://pyserial.sourceforge.net/" rel="nofollow">pySerial</a>. Sometimes while writing the code to the board pySerial raises an input/output error with errno 5.</p> <p>Some research says that this indicates an error while writing ...
4
2009-06-15T04:55:26Z
998,560
<p>Sorry to have bothered you but I'm very sure that the error is caused by the arduino resetting itself and therefore closing the connection to the computer. </p>
2
2009-06-15T21:45:22Z
[ "python", "serial-port", "arduino", "pyserial" ]