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 |
|---|---|---|---|---|---|---|---|---|---|
Python: Check if a string represents an int, Without using Try/Except? | 1,265,665 | <p>Is there any way to tell whether a <strong>string</strong> represents an integer (e.g., <code>'3'</code>, <code>'-17'</code> but not <code>'3.14'</code> or <code>'asfasfas'</code>) Without using a try/except mechanism?</p>
<pre><code>is_int('3.14') = False
is_int('-7') = True
</code></pre>
| 138 | 2009-08-12T11:46:13Z | 10,219,553 | <pre><code>>>> "+7".lstrip("-+").isdigit()
True
>>> "-7".lstrip("-+").isdigit()
True
>>> "7".lstrip("-+").isdigit()
True
>>> "13.4".lstrip("-+").isdigit()
False
</code></pre>
<p>So your function would be:</p>
<pre><code>def is_int(val):
return val[1].isdigit() and val.lstrip("-+... | 2 | 2012-04-18T23:25:01Z | [
"python",
"string",
"integer"
] |
Python: Check if a string represents an int, Without using Try/Except? | 1,265,665 | <p>Is there any way to tell whether a <strong>string</strong> represents an integer (e.g., <code>'3'</code>, <code>'-17'</code> but not <code>'3.14'</code> or <code>'asfasfas'</code>) Without using a try/except mechanism?</p>
<pre><code>is_int('3.14') = False
is_int('-7') = True
</code></pre>
| 138 | 2009-08-12T11:46:13Z | 12,863,921 | <p>This is probably the most straightforward and pythonic way to approach it in my opinion. I didn't see this solution and it's basically the same as the regex one, but without the regex. </p>
<pre><code>def is_int(test):
import string
return not (set(test) - set(string.digits))
</code></pre>
| 2 | 2012-10-12T17:07:52Z | [
"python",
"string",
"integer"
] |
Python: Check if a string represents an int, Without using Try/Except? | 1,265,665 | <p>Is there any way to tell whether a <strong>string</strong> represents an integer (e.g., <code>'3'</code>, <code>'-17'</code> but not <code>'3.14'</code> or <code>'asfasfas'</code>) Without using a try/except mechanism?</p>
<pre><code>is_int('3.14') = False
is_int('-7') = True
</code></pre>
| 138 | 2009-08-12T11:46:13Z | 29,031,758 | <p>I think</p>
<pre><code>s.startswith('-') and s[1:].isdigit()
</code></pre>
<p>would be better to rewrite to:</p>
<pre><code>s.replace('-', '').isdigit()
</code></pre>
<p>because s[1:] also creates a new string</p>
| 0 | 2015-03-13T12:03:14Z | [
"python",
"string",
"integer"
] |
Python: Check if a string represents an int, Without using Try/Except? | 1,265,665 | <p>Is there any way to tell whether a <strong>string</strong> represents an integer (e.g., <code>'3'</code>, <code>'-17'</code> but not <code>'3.14'</code> or <code>'asfasfas'</code>) Without using a try/except mechanism?</p>
<pre><code>is_int('3.14') = False
is_int('-7') = True
</code></pre>
| 138 | 2009-08-12T11:46:13Z | 29,032,755 | <p>I have one possibility that doesn't use int at all, and should not raise an exception unless the string does not represent a number</p>
<pre><code>float(number)==float(number)//1
</code></pre>
<p>It should work for any kind of string that float accepts, positive, negative, engineering notation...</p>
| 1 | 2015-03-13T12:52:31Z | [
"python",
"string",
"integer"
] |
Python: Check if a string represents an int, Without using Try/Except? | 1,265,665 | <p>Is there any way to tell whether a <strong>string</strong> represents an integer (e.g., <code>'3'</code>, <code>'-17'</code> but not <code>'3.14'</code> or <code>'asfasfas'</code>) Without using a try/except mechanism?</p>
<pre><code>is_int('3.14') = False
is_int('-7') = True
</code></pre>
| 138 | 2009-08-12T11:46:13Z | 29,330,386 | <p>Here is a function that parses without raising errors. It handles obvious cases returns <code>None</code> on failure (handles up to 2000 '-/+' signs by default on CPython!):</p>
<pre><code>#!/usr/bin/env python
def get_int(number):
splits = number.split('.')
if len(splits) > 2:
# too many splits... | 1 | 2015-03-29T14:33:37Z | [
"python",
"string",
"integer"
] |
Python: Check if a string represents an int, Without using Try/Except? | 1,265,665 | <p>Is there any way to tell whether a <strong>string</strong> represents an integer (e.g., <code>'3'</code>, <code>'-17'</code> but not <code>'3.14'</code> or <code>'asfasfas'</code>) Without using a try/except mechanism?</p>
<pre><code>is_int('3.14') = False
is_int('-7') = True
</code></pre>
| 138 | 2009-08-12T11:46:13Z | 39,972,859 | <p>What about using <a href="https://docs.python.org/3/library/stdtypes.html#float.is_integer" rel="nofollow"><code>float.is_integer</code></a> ? :</p>
<pre><code>float("7").is_integer() #True
float("+1").is_integer() #True
float("+1.0").is_integer() #True
float("+1.7").is_integer() #False
float("-3").is_... | 0 | 2016-10-11T08:05:11Z | [
"python",
"string",
"integer"
] |
Changing height of an object in wxPython | 1,265,821 | <ol>
<li><p>How to change only hight of an object in wxPython, leaving its width automatic? In my case it's a TextCtrl.</p></li>
<li><p>How to make the height of the window available for change and lock the width?</p></li>
</ol>
| 2 | 2009-08-12T12:22:33Z | 1,265,988 | <p>For the width or height to be automatically determined based on context you use for it the value of -1, for example <code>(-1, 100)</code> for a height of 100 and automatic width.</p>
<p>The default size for controls is usually <code>(-1, -1)</code>.</p>
<p>If a width or height is specified and the sizer item for ... | 6 | 2009-08-12T12:49:26Z | [
"python",
"wxpython",
"size"
] |
Python non-trivial C++ Extension | 1,266,570 | <p>I have fairly large C++ library with several sub-libraries that support it, and I need to turn the whole thing into a python extension. I'm using distutils because it needs to be cross-platform, but if there's a better tool I'm open to suggestions.</p>
<p>Is there a way to make distutils first compile the sub-libr... | 4 | 2009-08-12T14:36:05Z | 1,266,621 | <p>I do just this with a massive C++ library in our product. There are several tools out there that can help you automate the task of writing bindings: the most popular is <a href="http://www.swig.org/">SWIG</a>, which has been around a while, is used in lots of projects, and generally works very well. </p>
<p>The ... | 10 | 2009-08-12T14:42:17Z | [
"c++",
"python",
"swig",
"distutils",
"py++"
] |
Does PHP have an equivalent to Python's list comprehension syntax? | 1,266,911 | <p>Python has syntactically sweet list comprehensions:</p>
<pre><code>S = [x**2 for x in range(10)]
print S;
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
</code></pre>
<p>In PHP I would need to do some looping:</p>
<pre><code>$output = array();
$Nums = range(0,9);
foreach ($Nums as $num)
{
$out[] = $num*=$num;
}
print... | 46 | 2009-08-12T15:26:07Z | 1,266,942 | <p>Maybe something like this?</p>
<pre><code>$out=array_map(function($x) {return $x*$x;}, range(0, 9))
</code></pre>
<p>This will work in PHP 5.3+, in an older version you'd have to define the callback for <a href="http://php.net/array%5Fmap">array_map</a> separately</p>
<pre><code>function sq($x) {return $x*$x;}
$o... | 56 | 2009-08-12T15:32:02Z | [
"php",
"python",
"arrays"
] |
Does PHP have an equivalent to Python's list comprehension syntax? | 1,266,911 | <p>Python has syntactically sweet list comprehensions:</p>
<pre><code>S = [x**2 for x in range(10)]
print S;
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
</code></pre>
<p>In PHP I would need to do some looping:</p>
<pre><code>$output = array();
$Nums = range(0,9);
foreach ($Nums as $num)
{
$out[] = $num*=$num;
}
print... | 46 | 2009-08-12T15:26:07Z | 1,266,945 | <p>not out of the box, but take a look at:
<a href="http://code.google.com/p/php-lc/" rel="nofollow">http://code.google.com/p/php-lc/</a> or <a href="http://code.google.com/p/phparrayplus/" rel="nofollow">http://code.google.com/p/phparrayplus/</a></p>
| 2 | 2009-08-12T15:32:44Z | [
"php",
"python",
"arrays"
] |
Does PHP have an equivalent to Python's list comprehension syntax? | 1,266,911 | <p>Python has syntactically sweet list comprehensions:</p>
<pre><code>S = [x**2 for x in range(10)]
print S;
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
</code></pre>
<p>In PHP I would need to do some looping:</p>
<pre><code>$output = array();
$Nums = range(0,9);
foreach ($Nums as $num)
{
$out[] = $num*=$num;
}
print... | 46 | 2009-08-12T15:26:07Z | 11,628,187 | <p>PHP 5.5 may support list comprehensions - see the mailing list announcement:</p>
<ul>
<li><a href="http://markmail.org/thread/uvendztpe2rrwiif" rel="nofollow">[PHP-DEV] List comprehensions and generator expressions for PHP</a> (28 Jun 2012)</li>
</ul>
<p>And further discussion:</p>
<ul>
<li><a href="http://blog.i... | 4 | 2012-07-24T09:44:37Z | [
"php",
"python",
"arrays"
] |
Does PHP have an equivalent to Python's list comprehension syntax? | 1,266,911 | <p>Python has syntactically sweet list comprehensions:</p>
<pre><code>S = [x**2 for x in range(10)]
print S;
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
</code></pre>
<p>In PHP I would need to do some looping:</p>
<pre><code>$output = array();
$Nums = range(0,9);
foreach ($Nums as $num)
{
$out[] = $num*=$num;
}
print... | 46 | 2009-08-12T15:26:07Z | 30,633,691 | <p>In .NET, the equivalent of Python's "syntactically sweet list comprehensions" is LINQ. And in PHP, there're several ports of it, including <a href="https://github.com/Athari/YaLinqo" rel="nofollow">YaLinqo</a> library*. Syntactically, it's closer to SQL rather than a sequence of traditional constructs with <code>for... | 0 | 2015-06-04T01:54:36Z | [
"php",
"python",
"arrays"
] |
Python: remove lots of items from a list | 1,267,260 | <p>I am in the final stretch of a project I have been working on. Everything is running smoothly but I have a bottleneck that I am having trouble working around.</p>
<p>I have a list of tuples. The list ranges in length from say 40,000 - 1,000,000 records. Now I have a dictionary where each and every (value, key) i... | 10 | 2009-08-12T16:28:46Z | 1,267,294 | <p>The problem looks to me to be the fact you are using a <code>list</code> as the container you are trying to remove from, and it is a totally unordered type. So to find each item in the list is a linear operation (<a href="http://en.wikipedia.org/wiki/Big%5FO%5Fnotation" rel="nofollow">O(n)</a>), it has to iterate o... | 2 | 2009-08-12T16:35:38Z | [
"python"
] |
Python: remove lots of items from a list | 1,267,260 | <p>I am in the final stretch of a project I have been working on. Everything is running smoothly but I have a bottleneck that I am having trouble working around.</p>
<p>I have a list of tuples. The list ranges in length from say 40,000 - 1,000,000 records. Now I have a dictionary where each and every (value, key) i... | 10 | 2009-08-12T16:28:46Z | 1,267,317 | <p>Every time you call <code>myList.remove</code>, Python has to scan over the entire list to search for that item and remove it. In the worst case scenario, every item you look for would be at the end of the list each time.</p>
<p>Have you tried doing the "inverse" operation of:</p>
<pre><code>newMyList = [(v,k) fo... | 5 | 2009-08-12T16:40:09Z | [
"python"
] |
Python: remove lots of items from a list | 1,267,260 | <p>I am in the final stretch of a project I have been working on. Everything is running smoothly but I have a bottleneck that I am having trouble working around.</p>
<p>I have a list of tuples. The list ranges in length from say 40,000 - 1,000,000 records. Now I have a dictionary where each and every (value, key) i... | 10 | 2009-08-12T16:28:46Z | 1,267,318 | <p>You'll have to measure, but I can imagine this to be more performant:</p>
<pre><code>myList = filter(lambda x: myDict.get(x[1], None) != x[0], myList)
</code></pre>
<p>because the lookup happens in the dict, which is more suited for this kind of thing. Note, though, that this will create a new list before removing... | 19 | 2009-08-12T16:40:11Z | [
"python"
] |
Python: remove lots of items from a list | 1,267,260 | <p>I am in the final stretch of a project I have been working on. Everything is running smoothly but I have a bottleneck that I am having trouble working around.</p>
<p>I have a list of tuples. The list ranges in length from say 40,000 - 1,000,000 records. Now I have a dictionary where each and every (value, key) i... | 10 | 2009-08-12T16:28:46Z | 1,267,319 | <pre><code>[(i, j) for i, j in myList if myDict.get(j) != i]
</code></pre>
| 2 | 2009-08-12T16:40:14Z | [
"python"
] |
Python: remove lots of items from a list | 1,267,260 | <p>I am in the final stretch of a project I have been working on. Everything is running smoothly but I have a bottleneck that I am having trouble working around.</p>
<p>I have a list of tuples. The list ranges in length from say 40,000 - 1,000,000 records. Now I have a dictionary where each and every (value, key) i... | 10 | 2009-08-12T16:28:46Z | 1,267,333 | <p>Try something like this:</p>
<pre><code>myListSet = set(myList)
myDictSet = set(zip(myDict.values(), myDict.keys()))
myList = list(myListSet - myDictSet)
</code></pre>
<p>This will convert <code>myList</code> to a set, will swap the keys/values in <code>myDict</code> and put them into a set, and will then find the... | 2 | 2009-08-12T16:41:56Z | [
"python"
] |
Python: remove lots of items from a list | 1,267,260 | <p>I am in the final stretch of a project I have been working on. Everything is running smoothly but I have a bottleneck that I am having trouble working around.</p>
<p>I have a list of tuples. The list ranges in length from say 40,000 - 1,000,000 records. Now I have a dictionary where each and every (value, key) i... | 10 | 2009-08-12T16:28:46Z | 1,268,545 | <pre><code>[i for i in myList if i not in list(zip(myDict.values(), myDict.keys()))]
</code></pre>
| 0 | 2009-08-12T20:30:34Z | [
"python"
] |
Python: remove lots of items from a list | 1,267,260 | <p>I am in the final stretch of a project I have been working on. Everything is running smoothly but I have a bottleneck that I am having trouble working around.</p>
<p>I have a list of tuples. The list ranges in length from say 40,000 - 1,000,000 records. Now I have a dictionary where each and every (value, key) i... | 10 | 2009-08-12T16:28:46Z | 1,269,380 | <p>A list containing a million 2-tuples is not large on most machines running Python. However if you absolutely must do the removal in situ, here is a clean way of doing it properly:</p>
<pre><code>def filter_by_dict(my_list, my_dict):
sentinel = object()
for i in xrange(len(my_list) - 1, -1, -1):
key ... | 0 | 2009-08-13T00:06:52Z | [
"python"
] |
Python: remove lots of items from a list | 1,267,260 | <p>I am in the final stretch of a project I have been working on. Everything is running smoothly but I have a bottleneck that I am having trouble working around.</p>
<p>I have a list of tuples. The list ranges in length from say 40,000 - 1,000,000 records. Now I have a dictionary where each and every (value, key) i... | 10 | 2009-08-12T16:28:46Z | 1,274,668 | <p>To remove about 10,000 tuples from a list of about 1,000,000, if the values are hashable, the fastest approach should be:</p>
<pre><code>totoss = set((v,k) for (k,v) in myDict.iteritems())
myList[:] = [x for x in myList if x not in totoss]
</code></pre>
<p>The preparation of the set is a small one-time cost, wich ... | 9 | 2009-08-13T21:23:00Z | [
"python"
] |
What's the best way to do literate programming in Python on Windows? | 1,267,280 | <p>I've been playing with various ways of doing literate programming in Python. I like <a href="http://www.cs.tufts.edu/~nr/noweb/"><code>noweb</code></a>, but I have two main problems with it: first, it is hard to build on Windows, where I spend about half my development time; and second, it requires me to indent eac... | 31 | 2009-08-12T16:32:54Z | 1,268,602 | <p>I did this:</p>
<p><a href="http://sourceforge.net/projects/pywebtool/">http://sourceforge.net/projects/pywebtool/</a></p>
<p>You can get any number of web/weave products that will help you construct a document and code in one swoop.</p>
<p>You can -- pretty easily -- write your own. It's not rocket science to y... | 6 | 2009-08-12T20:39:55Z | [
"python",
"windows",
"literate-programming",
"noweb"
] |
What's the best way to do literate programming in Python on Windows? | 1,267,280 | <p>I've been playing with various ways of doing literate programming in Python. I like <a href="http://www.cs.tufts.edu/~nr/noweb/"><code>noweb</code></a>, but I have two main problems with it: first, it is hard to build on Windows, where I spend about half my development time; and second, it requires me to indent eac... | 31 | 2009-08-12T16:32:54Z | 2,709,739 | <p>You might find <a href="http://www.cs.tufts.edu/~nr/noweb" rel="nofollow">noweb 3</a> easier to build on Windows. It was designed to be more portable than standard noweb.</p>
| 2 | 2010-04-25T20:02:16Z | [
"python",
"windows",
"literate-programming",
"noweb"
] |
What's the best way to do literate programming in Python on Windows? | 1,267,280 | <p>I've been playing with various ways of doing literate programming in Python. I like <a href="http://www.cs.tufts.edu/~nr/noweb/"><code>noweb</code></a>, but I have two main problems with it: first, it is hard to build on Windows, where I spend about half my development time; and second, it requires me to indent eac... | 31 | 2009-08-12T16:32:54Z | 2,887,123 | <p>I have written Pweave <a href="http://mpastell.com/pweave">http://mpastell.com/pweave</a>, that is aimed for dynamic report generation and uses noweb syntax. It is a pure python script so it also runs on Windows. It doesn't fix your indent problem, but maybe you can modify it for that, the code is really quite simpl... | 9 | 2010-05-22T06:01:40Z | [
"python",
"windows",
"literate-programming",
"noweb"
] |
What's the best way to do literate programming in Python on Windows? | 1,267,280 | <p>I've been playing with various ways of doing literate programming in Python. I like <a href="http://www.cs.tufts.edu/~nr/noweb/"><code>noweb</code></a>, but I have two main problems with it: first, it is hard to build on Windows, where I spend about half my development time; and second, it requires me to indent eac... | 31 | 2009-08-12T16:32:54Z | 11,155,300 | <p>You could use org-mode and babel-tangle.</p>
<p>That works quite well, since you can give :noweb-ref to source blocks.</p>
<p>Hereâs a minimal example: <a href="http://orgmode.org/worg/org-contrib/babel/intro.html#literate-programming">Activate org-babel-tangle</a>, then put this into the file <code>noweb-test.o... | 7 | 2012-06-22T11:27:27Z | [
"python",
"windows",
"literate-programming",
"noweb"
] |
What's the best way to do literate programming in Python on Windows? | 1,267,280 | <p>I've been playing with various ways of doing literate programming in Python. I like <a href="http://www.cs.tufts.edu/~nr/noweb/"><code>noweb</code></a>, but I have two main problems with it: first, it is hard to build on Windows, where I spend about half my development time; and second, it requires me to indent eac... | 31 | 2009-08-12T16:32:54Z | 14,341,393 | <p>See also my last LP tool: <a href="http://code.google.com/p/nano-lp" rel="nofollow">http://code.google.com/p/nano-lp</a>. It does not requires special input format, supports Markdown/MultiMarkdown, reStructuredText, OpenOffice/LibreOffice, Creole, TeX/LaTeX and has super light and clean syntax - no more cryptic lite... | 0 | 2013-01-15T15:46:49Z | [
"python",
"windows",
"literate-programming",
"noweb"
] |
What's the best way to do literate programming in Python on Windows? | 1,267,280 | <p>I've been playing with various ways of doing literate programming in Python. I like <a href="http://www.cs.tufts.edu/~nr/noweb/"><code>noweb</code></a>, but I have two main problems with it: first, it is hard to build on Windows, where I spend about half my development time; and second, it requires me to indent eac... | 31 | 2009-08-12T16:32:54Z | 22,131,669 | <p>The de-facto standard in the community is IPython notebooks.</p>
<p>Excellent example in which Peter Norvig demonstrates algorithms to solve the Travelling Salesman Problem: <a href="http://nbviewer.ipython.org/url/norvig.com/ipython/TSPv3.ipynb">http://nbviewer.ipython.org/url/norvig.com/ipython/TSPv3.ipynb</a></p... | 8 | 2014-03-02T18:38:13Z | [
"python",
"windows",
"literate-programming",
"noweb"
] |
How do I calculate the numeric value of a string with unicode components in python? | 1,267,314 | <p>Along the lines of my previous question, <a href="http://stackoverflow.com/questions/1263796/how-do-i-convert-unicode-characters-to-floats-in-python">http://stackoverflow.com/questions/1263796/how-do-i-convert-unicode-characters-to-floats-in-python</a> , I would like to find a more elegant solution to calculating th... | 4 | 2009-08-12T16:38:49Z | 1,267,346 | <pre><code>>>> import unicodedata
>>> b = '10 â
'
>>> int(b[:-1]) + unicodedata.numeric(b[-1])
10.2
define convert_dubious_strings(s):
try:
return int(s)
except UnicodeEncodeError:
return int(b[:-1]) + unicodedata.numeric(b[-1])
</code></pre>
<p>and if it might have... | 1 | 2009-08-12T16:44:53Z | [
"python",
"string",
"unicode",
"floating-point"
] |
How do I calculate the numeric value of a string with unicode components in python? | 1,267,314 | <p>Along the lines of my previous question, <a href="http://stackoverflow.com/questions/1263796/how-do-i-convert-unicode-characters-to-floats-in-python">http://stackoverflow.com/questions/1263796/how-do-i-convert-unicode-characters-to-floats-in-python</a> , I would like to find a more elegant solution to calculating th... | 4 | 2009-08-12T16:38:49Z | 1,267,425 | <p>I think you'll need a regular expression, explicitly listing the characters that you want to support. Not all numerical characters are suitable for the kind of composition that you envision - for example, what should be the numerical value of</p>
<pre><code>u"4\N{CIRCLED NUMBER FORTY TWO}2\N{SUPERSCRIPT SIX}"
</cod... | -1 | 2009-08-12T16:59:56Z | [
"python",
"string",
"unicode",
"floating-point"
] |
How do I calculate the numeric value of a string with unicode components in python? | 1,267,314 | <p>Along the lines of my previous question, <a href="http://stackoverflow.com/questions/1263796/how-do-i-convert-unicode-characters-to-floats-in-python">http://stackoverflow.com/questions/1263796/how-do-i-convert-unicode-characters-to-floats-in-python</a> , I would like to find a more elegant solution to calculating th... | 4 | 2009-08-12T16:38:49Z | 1,267,473 | <p>This might be sufficient for you, depending on the strange edge cases you want to deal with:</p>
<pre><code>val = 0
for c in my_unicode_string:
if unicodedata.category(unichr(c)) == 'No':
cval = unicodedata.numeric(c)
elif c.isdigit():
cval = int(c)
else:
continue
if cval == ... | 0 | 2009-08-12T17:11:06Z | [
"python",
"string",
"unicode",
"floating-point"
] |
How do I calculate the numeric value of a string with unicode components in python? | 1,267,314 | <p>Along the lines of my previous question, <a href="http://stackoverflow.com/questions/1263796/how-do-i-convert-unicode-characters-to-floats-in-python">http://stackoverflow.com/questions/1263796/how-do-i-convert-unicode-characters-to-floats-in-python</a> , I would like to find a more elegant solution to calculating th... | 4 | 2009-08-12T16:38:49Z | 1,267,487 | <p>I think this is what you want...</p>
<pre><code>import unicodedata
def eval_unicode(s):
#sum all the unicode fractions
u = sum(map(unicodedata.numeric, filter(lambda x: unicodedata.category(x)=="No",s)))
#eval the regular digits (with optional dot) as a float, or default to 0
n = float("".join(filte... | 2 | 2009-08-12T17:14:17Z | [
"python",
"string",
"unicode",
"floating-point"
] |
How do you resolve traditional coding standard vs python idomatic code? | 1,267,444 | <p>In my experience code clarity and readability are the primary concerns in traditional coding standards. PEP-8 would have been rejected by some of my previous customers.</p>
<p>The idiomatic concepts such as, using dictionaries and lambda functions to emulate the behavior of a switch statement looks like something t... | -3 | 2009-08-12T17:04:27Z | 1,267,455 | <p>You should write code that's idiomatic in the language you're using, and anyone reviewing the code should be familiar enough with the language to recognise and understand idiomatic code.</p>
<p>Using a dictionary for dispatching is idiomatic Python IMHO. Go with what's Pythonic rather than trying to fit coding sta... | 11 | 2009-08-12T17:08:00Z | [
"python",
"coding-style",
"code-review"
] |
How do you resolve traditional coding standard vs python idomatic code? | 1,267,444 | <p>In my experience code clarity and readability are the primary concerns in traditional coding standards. PEP-8 would have been rejected by some of my previous customers.</p>
<p>The idiomatic concepts such as, using dictionaries and lambda functions to emulate the behavior of a switch statement looks like something t... | -3 | 2009-08-12T17:04:27Z | 1,267,526 | <p><strong>Software is hard.</strong> No-ubergeek rule is good but it doesn't mean that any random person with a title <em>programmer</em> could review or should be able to understand any code he's looking at with ease.</p>
<p>Lambdas that span multiple lines are shouldn't exist in your code regardless who you're writ... | 3 | 2009-08-12T17:21:14Z | [
"python",
"coding-style",
"code-review"
] |
How do you resolve traditional coding standard vs python idomatic code? | 1,267,444 | <p>In my experience code clarity and readability are the primary concerns in traditional coding standards. PEP-8 would have been rejected by some of my previous customers.</p>
<p>The idiomatic concepts such as, using dictionaries and lambda functions to emulate the behavior of a switch statement looks like something t... | -3 | 2009-08-12T17:04:27Z | 1,268,407 | <p>If you don't like using a dict of functions to implement switch type functionality, then just don't use it and use an if-else structure instead.</p>
<pre><code>if var == "a":
pass
elif var == "b":
pass
elif var == "c":
pass
else:
#Default case
pass
</code></pre>
<p>There. That was easy, wasn't it.</p>
| 1 | 2009-08-12T20:03:28Z | [
"python",
"coding-style",
"code-review"
] |
How do you resolve traditional coding standard vs python idomatic code? | 1,267,444 | <p>In my experience code clarity and readability are the primary concerns in traditional coding standards. PEP-8 would have been rejected by some of my previous customers.</p>
<p>The idiomatic concepts such as, using dictionaries and lambda functions to emulate the behavior of a switch statement looks like something t... | -3 | 2009-08-12T17:04:27Z | 1,268,484 | <blockquote>
<p>But it isn't a good replacement for a
light weight switch. In some cases
it's a hammer instead of a
screwdriver.</p>
</blockquote>
<p>Python cannot make jump table optimizations mostly due to its nature as a dynamic language. Therefore if Python had a switch statement, it would be no different ... | 3 | 2009-08-12T20:17:28Z | [
"python",
"coding-style",
"code-review"
] |
How do you resolve traditional coding standard vs python idomatic code? | 1,267,444 | <p>In my experience code clarity and readability are the primary concerns in traditional coding standards. PEP-8 would have been rejected by some of my previous customers.</p>
<p>The idiomatic concepts such as, using dictionaries and lambda functions to emulate the behavior of a switch statement looks like something t... | -3 | 2009-08-12T17:04:27Z | 1,268,563 | <p>In answer to your question:</p>
<blockquote>
<p>how do you handle the "default"
condition in Python?</p>
</blockquote>
<p>You do this:</p>
<pre><code>fruits = {
"red": "apple",
"blue": "blueberry",
"pink": "watermelon",
}
print fruits.get(colour, "unknown")
</code></pre>
<p>Or you use the <code>... | 1 | 2009-08-12T20:33:23Z | [
"python",
"coding-style",
"code-review"
] |
Does __str__() call decode() method behind scenes? | 1,267,754 | <p>It seems to me that built-in functions <code>__repr__</code> and <code>__str__</code> have an important difference in their base definition.</p>
<pre><code>>>> t2 = u'\u0131\u015f\u0131k'
>>> print t2
ıÅık
>>> t2
Out[0]: u'\u0131\u015f\u0131k'
</code></pre>
<p><code>t2.decode</code> r... | 0 | 2009-08-12T18:03:28Z | 1,267,835 | <p>Basically, <code>__str__</code> can only output ascii strings. Since t2 contains unicode codepoints above ascii, it cannot be represented with just a string. <code>__repr__</code>, on the other hand, tries to output the python code needed to recreate the object. You'll see that the output from repr(t2) (this syntax ... | 7 | 2009-08-12T18:20:16Z | [
"python",
"django",
"string",
"unicode"
] |
Does __str__() call decode() method behind scenes? | 1,267,754 | <p>It seems to me that built-in functions <code>__repr__</code> and <code>__str__</code> have an important difference in their base definition.</p>
<pre><code>>>> t2 = u'\u0131\u015f\u0131k'
>>> print t2
ıÅık
>>> t2
Out[0]: u'\u0131\u015f\u0131k'
</code></pre>
<p><code>t2.decode</code> r... | 0 | 2009-08-12T18:03:28Z | 1,267,923 | <p>In general, calling <code>str.__unicode__()</code> or <code>unicode.__str__()</code> is a very bad idea, because bytes can't be safely converted to Unicode character points and vice versa. The exception is ASCII values, which are generally the same in all single-byte encodings. The problem is that you're using the w... | 5 | 2009-08-12T18:34:12Z | [
"python",
"django",
"string",
"unicode"
] |
Does __str__() call decode() method behind scenes? | 1,267,754 | <p>It seems to me that built-in functions <code>__repr__</code> and <code>__str__</code> have an important difference in their base definition.</p>
<pre><code>>>> t2 = u'\u0131\u015f\u0131k'
>>> print t2
ıÅık
>>> t2
Out[0]: u'\u0131\u015f\u0131k'
</code></pre>
<p><code>t2.decode</code> r... | 0 | 2009-08-12T18:03:28Z | 1,268,096 | <p>To add a bit of support to John's good answer:</p>
<p>To understand the naming of the two methods <em>encode()</em> and <em>decode()</em>, you just have to see that Python considers unicode strings of the form <strong>u'...'</strong> to be in the <strong>reference format</strong>. You <em>encode</em> going from the... | 2 | 2009-08-12T19:04:37Z | [
"python",
"django",
"string",
"unicode"
] |
Does __str__() call decode() method behind scenes? | 1,267,754 | <p>It seems to me that built-in functions <code>__repr__</code> and <code>__str__</code> have an important difference in their base definition.</p>
<pre><code>>>> t2 = u'\u0131\u015f\u0131k'
>>> print t2
ıÅık
>>> t2
Out[0]: u'\u0131\u015f\u0131k'
</code></pre>
<p><code>t2.decode</code> r... | 0 | 2009-08-12T18:03:28Z | 1,268,599 | <p>Note that in Python 3, unicode is the default, and <code>__str__()</code> should always give you unicode.</p>
| 0 | 2009-08-12T20:39:34Z | [
"python",
"django",
"string",
"unicode"
] |
Django Formset without instance | 1,267,810 | <p>In <a href="http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#inline-formsets">this</a> Django Doc explain how to create a formset that allows you to edit books belonging to a particular author.</p>
<p>What I want to do is: Create a formset that allows you to ADD new book belonging to a NEW author... Ad... | 6 | 2009-08-12T18:14:45Z | 1,268,136 | <p>This depends on whether you're doing it yourself, or using the built-in admin.</p>
<p>If you're using the admin, you can use <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects" rel="nofollow">inlines</a>.</p>
<p>If you're doing this in your own application, then it's up to yo... | 0 | 2009-08-12T19:11:15Z | [
"python",
"django",
"forms",
"formset",
"inline-formset"
] |
Django Formset without instance | 1,267,810 | <p>In <a href="http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#inline-formsets">this</a> Django Doc explain how to create a formset that allows you to edit books belonging to a particular author.</p>
<p>What I want to do is: Create a formset that allows you to ADD new book belonging to a NEW author... Ad... | 6 | 2009-08-12T18:14:45Z | 1,269,142 | <p>When you're instantiating the form and formset for the initial display, you don't need to provide an instance - so you will just get blank forms.</p>
<p>When you pass in the data on POST, you can do the form first, save it, and get an instance. Then you can pass that instance into the formset, so that it correctly ... | 6 | 2009-08-12T22:47:28Z | [
"python",
"django",
"forms",
"formset",
"inline-formset"
] |
How can I force division to be floating point in Python? Division keeps rounding down to 0 | 1,267,869 | <p>I have two integer values <code>a</code> and <code>b</code>, but I need their ratio in floating point. I know that <code>a<b</code> and I want to calculate <code>a/b</code>, so if I use integer division I'll always get 0 with a remainder of <code>a</code>.</p>
<p>How can I force <code>c</code> to be a floating ... | 455 | 2009-08-12T18:25:15Z | 1,267,883 | <pre><code>c = a / (b * 1.0)
</code></pre>
| 70 | 2009-08-12T18:26:57Z | [
"python",
"floating-point",
"integer",
"division",
"python-2.x"
] |
How can I force division to be floating point in Python? Division keeps rounding down to 0 | 1,267,869 | <p>I have two integer values <code>a</code> and <code>b</code>, but I need their ratio in floating point. I know that <code>a<b</code> and I want to calculate <code>a/b</code>, so if I use integer division I'll always get 0 with a remainder of <code>a</code>.</p>
<p>How can I force <code>c</code> to be a floating ... | 455 | 2009-08-12T18:25:15Z | 1,267,890 | <p>You can cast to float by doing <code>c = a / float(b)</code>. If the numerator or denominator is a float, then the result will be also.</p>
<hr>
<p>A caveat: as commenters have pointed out, this won't work if <code>b</code> might be something other than an integer or floating-point number (or a string representing... | 523 | 2009-08-12T18:28:02Z | [
"python",
"floating-point",
"integer",
"division",
"python-2.x"
] |
How can I force division to be floating point in Python? Division keeps rounding down to 0 | 1,267,869 | <p>I have two integer values <code>a</code> and <code>b</code>, but I need their ratio in floating point. I know that <code>a<b</code> and I want to calculate <code>a/b</code>, so if I use integer division I'll always get 0 with a remainder of <code>a</code>.</p>
<p>How can I force <code>c</code> to be a floating ... | 455 | 2009-08-12T18:25:15Z | 1,267,892 | <pre><code>>>> from __future__ import division
>>> a = 4
>>> b = 6
>>> c = a / b
>>> c
0.66666666666666663
</code></pre>
| 508 | 2009-08-12T18:28:26Z | [
"python",
"floating-point",
"integer",
"division",
"python-2.x"
] |
How can I force division to be floating point in Python? Division keeps rounding down to 0 | 1,267,869 | <p>I have two integer values <code>a</code> and <code>b</code>, but I need their ratio in floating point. I know that <code>a<b</code> and I want to calculate <code>a/b</code>, so if I use integer division I'll always get 0 with a remainder of <code>a</code>.</p>
<p>How can I force <code>c</code> to be a floating ... | 455 | 2009-08-12T18:25:15Z | 1,267,901 | <p>In Python 3.x, the single slash (<code>/</code>) always means true (non-truncating) division. (The <code>//</code> operator is used for truncating division.) In Python 2.x (2.2 and above), you can get this same behavior by putting a</p>
<pre><code>from __future__ import division
</code></pre>
<p>at the top of your... | 49 | 2009-08-12T18:30:30Z | [
"python",
"floating-point",
"integer",
"division",
"python-2.x"
] |
How can I force division to be floating point in Python? Division keeps rounding down to 0 | 1,267,869 | <p>I have two integer values <code>a</code> and <code>b</code>, but I need their ratio in floating point. I know that <code>a<b</code> and I want to calculate <code>a/b</code>, so if I use integer division I'll always get 0 with a remainder of <code>a</code>.</p>
<p>How can I force <code>c</code> to be a floating ... | 455 | 2009-08-12T18:25:15Z | 3,784,679 | <p>Just making any of the parameters for division in floating-point format also produces the output in floating-point.</p>
<p>Example:</p>
<pre><code>>>> 4.0/3
1.3333333333333333
</code></pre>
<p>or,</p>
<pre><code>>>> 4 / 3.0
1.3333333333333333
</code></pre>
<p>or, </p>
<pre><code>>>> ... | 25 | 2010-09-24T06:22:39Z | [
"python",
"floating-point",
"integer",
"division",
"python-2.x"
] |
How can I force division to be floating point in Python? Division keeps rounding down to 0 | 1,267,869 | <p>I have two integer values <code>a</code> and <code>b</code>, but I need their ratio in floating point. I know that <code>a<b</code> and I want to calculate <code>a/b</code>, so if I use integer division I'll always get 0 with a remainder of <code>a</code>.</p>
<p>How can I force <code>c</code> to be a floating ... | 455 | 2009-08-12T18:25:15Z | 20,766,181 | <p>This will also work</p>
<pre><code>>>> u=1./5
>>> print u
</code></pre>
<blockquote>
<p>0.2</p>
</blockquote>
| 8 | 2013-12-24T19:58:41Z | [
"python",
"floating-point",
"integer",
"division",
"python-2.x"
] |
How can I force division to be floating point in Python? Division keeps rounding down to 0 | 1,267,869 | <p>I have two integer values <code>a</code> and <code>b</code>, but I need their ratio in floating point. I know that <code>a<b</code> and I want to calculate <code>a/b</code>, so if I use integer division I'll always get 0 with a remainder of <code>a</code>.</p>
<p>How can I force <code>c</code> to be a floating ... | 455 | 2009-08-12T18:25:15Z | 20,979,168 | <p>If you want to use "true" (floating point) division by default, there is a command line flag:</p>
<pre><code>python -Q new foo.py
</code></pre>
<p>There are some drawbacks (from the PEP):</p>
<blockquote>
<p>It has been argued that a command line option to change the
default is evil. It can certainly b... | 6 | 2014-01-07T18:33:47Z | [
"python",
"floating-point",
"integer",
"division",
"python-2.x"
] |
How can I force division to be floating point in Python? Division keeps rounding down to 0 | 1,267,869 | <p>I have two integer values <code>a</code> and <code>b</code>, but I need their ratio in floating point. I know that <code>a<b</code> and I want to calculate <code>a/b</code>, so if I use integer division I'll always get 0 with a remainder of <code>a</code>.</p>
<p>How can I force <code>c</code> to be a floating ... | 455 | 2009-08-12T18:25:15Z | 27,078,572 | <p>Add a dot (<code>.</code>) to indicate floating point numbers</p>
<pre><code>>>> 4/3.
1.3333333333333333
</code></pre>
<p>or</p>
<pre><code>>>> from __future__ import division
>>> 4/3
1.3333333333333333
</code></pre>
| 16 | 2014-11-22T14:39:24Z | [
"python",
"floating-point",
"integer",
"division",
"python-2.x"
] |
How can I force division to be floating point in Python? Division keeps rounding down to 0 | 1,267,869 | <p>I have two integer values <code>a</code> and <code>b</code>, but I need their ratio in floating point. I know that <code>a<b</code> and I want to calculate <code>a/b</code>, so if I use integer division I'll always get 0 with a remainder of <code>a</code>.</p>
<p>How can I force <code>c</code> to be a floating ... | 455 | 2009-08-12T18:25:15Z | 32,649,302 | <pre><code>from operator import truediv
c = truediv(a, b)
</code></pre>
| 3 | 2015-09-18T10:04:34Z | [
"python",
"floating-point",
"integer",
"division",
"python-2.x"
] |
How can I force division to be floating point in Python? Division keeps rounding down to 0 | 1,267,869 | <p>I have two integer values <code>a</code> and <code>b</code>, but I need their ratio in floating point. I know that <code>a<b</code> and I want to calculate <code>a/b</code>, so if I use integer division I'll always get 0 with a remainder of <code>a</code>.</p>
<p>How can I force <code>c</code> to be a floating ... | 455 | 2009-08-12T18:25:15Z | 32,657,822 | <blockquote>
<h1>How can I force division to be floating point in Python?</h1>
<p>I have two integer values a and b, but I need their ratio in floating point. I know that a < b and I want to calculate a/b, so if I use integer division I'll always get 0 with a remainder of a.</p>
<p>How can I force c to b... | 31 | 2015-09-18T17:29:08Z | [
"python",
"floating-point",
"integer",
"division",
"python-2.x"
] |
How can I force division to be floating point in Python? Division keeps rounding down to 0 | 1,267,869 | <p>I have two integer values <code>a</code> and <code>b</code>, but I need their ratio in floating point. I know that <code>a<b</code> and I want to calculate <code>a/b</code>, so if I use integer division I'll always get 0 with a remainder of <code>a</code>.</p>
<p>How can I force <code>c</code> to be a floating ... | 455 | 2009-08-12T18:25:15Z | 34,670,051 | <pre><code>from operator import truediv
c = truediv(a, b)
</code></pre>
<p>where a is dividend and b is the divisor.
This function is handy when quotient after division of two integers is a float.</p>
| 2 | 2016-01-08T05:23:18Z | [
"python",
"floating-point",
"integer",
"division",
"python-2.x"
] |
How to prevent Satchmo forms from displaying asterisk after required fields? | 1,267,874 | <p>I'm customizing my Satchmo store forms and have an icon that appears before any required fields. The problem is, Satchmo seems to want to render a text asterisk after the required fields. I'm using <code>field.label</code> to get this label, should I be using something else?</p>
<p><strong>EDIT:</strong> All my f... | 2 | 2009-08-12T18:25:45Z | 1,282,557 | <p>What happens if you do the following?</p>
<ol>
<li>Copy some or all of Satchmo's form templates to a new location and modify them to remove the asterisks</li>
<li>Arrange it so that your copies of those templates are seen before Satchmo's copies (by configuring the template loader settings appropriately, say by pla... | 1 | 2009-08-15T18:55:44Z | [
"python",
"django",
"forms",
"field",
"satchmo"
] |
Python standard module for emulating geometric points | 1,267,968 | <p>Is there a standard class in Python to emulate a geometric point that includes coordinates and a value, including arithmetic operations between the coordinates? </p>
| 0 | 2009-08-12T18:41:48Z | 1,268,052 | <p>If you just want standard matrix arithmetic operations for your coordinates, try <a href="http://numpy.scipy.org/" rel="nofollow">numpy</a>'s array type.</p>
| 1 | 2009-08-12T18:56:38Z | [
"python",
"geometry"
] |
Standard Solution for Decoding Additive Numbers | 1,268,050 | <p>From the Oracle docs.</p>
<blockquote>
<p>A number representing one or more statistics class. The following class numbers are additive:</p>
</blockquote>
<pre><code> 1 - User
2 - Redo
4 - Enqueue
8 - Cache
16 - OS
32 - Real Application Clusters
64 - SQL
128 - Debug
</code></pre>
<p>It there a sta... | 0 | 2009-08-12T18:56:07Z | 1,268,066 | <p>Each of those values corresponds to a single bit. So use the binary.</p>
<pre><code>1<<0 - 1 - User
1<<1 - 2 - Redo
1<<2 - 4 - Enqueue
1<<3 - 8 - Cache
1<<4 - 16 - OS
1<<5 - 32 - Real Application Clusters
1<<6 - 64 - SQL
1<<7 - 128 - Debug
</code></pre>
<p>Use &... | 4 | 2009-08-12T18:59:10Z | [
"python",
"algorithm"
] |
Standard Solution for Decoding Additive Numbers | 1,268,050 | <p>From the Oracle docs.</p>
<blockquote>
<p>A number representing one or more statistics class. The following class numbers are additive:</p>
</blockquote>
<pre><code> 1 - User
2 - Redo
4 - Enqueue
8 - Cache
16 - OS
32 - Real Application Clusters
64 - SQL
128 - Debug
</code></pre>
<p>It there a sta... | 0 | 2009-08-12T18:56:07Z | 1,268,111 | <p>You want to use binary operations to decode the original. The following code actually returns the correct strings:</p>
<pre><code>>>> FLAGS = ('User', 'Redo', 'Enqueue', 'Cache', 'OS',
... 'Real Application Clusters', 'SQL', 'Debug')
>>> def getFlags(value):
... flags = []
... for i, ... | 4 | 2009-08-12T19:07:29Z | [
"python",
"algorithm"
] |
Displaying X and y axis in pylab | 1,268,175 | <p>Is there a way in pylab to display the X and Y axis? I know using grid() will display them, but it comes with numerous other lines all given the same emphasis.</p>
| 1 | 2009-08-12T19:19:34Z | 1,268,859 | <p><code>foo.grid(b=True)</code> should help, but it is very raw.</p>
<p>If you supply any of the additional arguments it automatically assumes that b is True</p>
<p>For example:</p>
<pre><code>foo.grid(label='My awesome grid')
</code></pre>
| 1 | 2009-08-12T21:34:30Z | [
"python",
"matplotlib"
] |
Displaying X and y axis in pylab | 1,268,175 | <p>Is there a way in pylab to display the X and Y axis? I know using grid() will display them, but it comes with numerous other lines all given the same emphasis.</p>
| 1 | 2009-08-12T19:19:34Z | 1,269,164 | <p>What plot function do you use?</p>
<p>Axis are drawn automatically by all plotting functions I've seen so far, e.g.</p>
<pre><code>from pylab import *
hist(randn(10000), 100)
show()
</code></pre>
<p>Additionally, axis can be generated manually with the <a href="http://matplotlib.sourceforge.net/api/pyplot%5Fapi.h... | 3 | 2009-08-12T22:53:08Z | [
"python",
"matplotlib"
] |
Displaying X and y axis in pylab | 1,268,175 | <p>Is there a way in pylab to display the X and Y axis? I know using grid() will display them, but it comes with numerous other lines all given the same emphasis.</p>
| 1 | 2009-08-12T19:19:34Z | 1,269,451 | <p>If you are looking to name the axis you can using the label function:</p>
<pre><code>import pylab
pylab.xlabel("X")
pylab.ylabel("Y")
pylab.plot(range(10))
pylab.show()
</code></pre>
<p>Anyway, I'm pretty sure the x and y axis are automatically generated.</p>
<p><a href="http://matplotlib.sourceforge.net/api/pypl... | 8 | 2009-08-13T00:32:25Z | [
"python",
"matplotlib"
] |
Displaying X and y axis in pylab | 1,268,175 | <p>Is there a way in pylab to display the X and Y axis? I know using grid() will display them, but it comes with numerous other lines all given the same emphasis.</p>
| 1 | 2009-08-12T19:19:34Z | 1,273,543 | <p>It sounds like your problem has been addressed in the new <a href="http://matplotlib.sourceforge.net/users/whats%5Fnew.html" rel="nofollow">Matplotlib 0.99</a> with the Axis spine placement feature. Take a <a href="http://matplotlib.sourceforge.net/examples/pylab%5Fexamples/spine%5Fplacement%5Fdemo.html#pylab-exampl... | 2 | 2009-08-13T17:47:29Z | [
"python",
"matplotlib"
] |
Displaying X and y axis in pylab | 1,268,175 | <p>Is there a way in pylab to display the X and Y axis? I know using grid() will display them, but it comes with numerous other lines all given the same emphasis.</p>
| 1 | 2009-08-12T19:19:34Z | 33,480,294 | <p>The best way for me is to add vertical and horizontal lines at 0:</p>
<pre><code>pylab.axvline(linewidth=0.5, color = 'k')
pylab.axhline(linewidth=0.5, color = 'k')
</code></pre>
| 0 | 2015-11-02T14:46:54Z | [
"python",
"matplotlib"
] |
Django ModelForm CheckBox Widget | 1,268,209 | <p>I'm currently have an issue, and likely overlooking something very trivial. I have a field in my model that should allow for multiple choices via a checkbox form (it doesn't have to be a checkbox in the admin screen, just in the form area that the end-user will see). Currently I have the field setup like so:</p>
<p... | 1 | 2009-08-12T19:26:34Z | 1,268,493 | <p>In such a case, the easiest way is to put the choices into a separate model and then use a ManyToMany relationship. After that, you simply override the ModelForm's widget for that field to use <a href="http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.CheckboxSelectMultiple">forms.CheckboxSelectMu... | 13 | 2009-08-12T20:19:08Z | [
"python",
"django",
"django-models",
"django-forms"
] |
Django ModelForm CheckBox Widget | 1,268,209 | <p>I'm currently have an issue, and likely overlooking something very trivial. I have a field in my model that should allow for multiple choices via a checkbox form (it doesn't have to be a checkbox in the admin screen, just in the form area that the end-user will see). Currently I have the field setup like so:</p>
<p... | 1 | 2009-08-12T19:26:34Z | 1,269,612 | <p>I've just started to look into widgets assignment with ModelForms. In a lot of examples I've seen, piquadrat's included, the Form's __ init __ method is overridden.</p>
<p>I find this a little confusing, and just overriding the desired field is more natural for me:</p>
<pre><code>class SomeModelForm(forms.ModelFo... | 1 | 2009-08-13T01:41:00Z | [
"python",
"django",
"django-models",
"django-forms"
] |
Django ModelForm CheckBox Widget | 1,268,209 | <p>I'm currently have an issue, and likely overlooking something very trivial. I have a field in my model that should allow for multiple choices via a checkbox form (it doesn't have to be a checkbox in the admin screen, just in the form area that the end-user will see). Currently I have the field setup like so:</p>
<p... | 1 | 2009-08-12T19:26:34Z | 4,262,838 | <p>Using piquadrat's answer worked for me, but needed to add a line to define the queryset for the M2M. See <a href="http://bitkickers.blogspot.com/2010/05/django-manytomanyfield-on-modelform-as.html" rel="nofollow">this link</a>.</p>
| 0 | 2010-11-24T01:53:17Z | [
"python",
"django",
"django-models",
"django-forms"
] |
Python: Possible to share in-memory data between 2 separate processes | 1,268,252 | <p>I have an xmlrpc server using Twisted. The server has a huge amount of data stored in-memory. Is it possible to have a secondary, separate xmlrpc server running which can access the object in-memory in the first server?</p>
<p>So, serverA starts up and creates an object. serverB starts up and can read from the o... | 27 | 2009-08-12T19:33:11Z | 1,268,264 | <pre><code>mmap.mmap(0, 65536, 'GlobalSharedMemory')
</code></pre>
<p>I think the tag ("GlobalSharedMemory") must be the same for all processes wishing to share the same memory.</p>
<p><a href="http://docs.python.org/library/mmap.html">http://docs.python.org/library/mmap.html</a></p>
| 12 | 2009-08-12T19:36:36Z | [
"python"
] |
Python: Possible to share in-memory data between 2 separate processes | 1,268,252 | <p>I have an xmlrpc server using Twisted. The server has a huge amount of data stored in-memory. Is it possible to have a secondary, separate xmlrpc server running which can access the object in-memory in the first server?</p>
<p>So, serverA starts up and creates an object. serverB starts up and can read from the o... | 27 | 2009-08-12T19:33:11Z | 1,268,499 | <p>You can use the Python Multiprocessing module.</p>
<p><a href="http://docs.python.org/library/multiprocessing.html#sharing-state-between-processes" rel="nofollow">http://docs.python.org/library/multiprocessing.html#sharing-state-between-processes</a></p>
| 1 | 2009-08-12T20:20:08Z | [
"python"
] |
Python: Possible to share in-memory data between 2 separate processes | 1,268,252 | <p>I have an xmlrpc server using Twisted. The server has a huge amount of data stored in-memory. Is it possible to have a secondary, separate xmlrpc server running which can access the object in-memory in the first server?</p>
<p>So, serverA starts up and creates an object. serverB starts up and can read from the o... | 27 | 2009-08-12T19:33:11Z | 1,269,055 | <p>Without some deep and dark rewriting of the Python core runtime (to allow forcing of an allocator that uses a given segment of shared memory and ensures compatible addresses between disparate processes) there is no way to "share objects in memory" in any general sense. That list will hold a million addresses of tupl... | 63 | 2009-08-12T22:20:42Z | [
"python"
] |
Python: Possible to share in-memory data between 2 separate processes | 1,268,252 | <p>I have an xmlrpc server using Twisted. The server has a huge amount of data stored in-memory. Is it possible to have a secondary, separate xmlrpc server running which can access the object in-memory in the first server?</p>
<p>So, serverA starts up and creates an object. serverB starts up and can read from the o... | 27 | 2009-08-12T19:33:11Z | 1,270,886 | <p>Why not just use a database for the shared data? You have a multitude of lightweight options where you don't need to worry about the concurrency issues: sqlite, any of the nosql/key-value breed of databases, etc. </p>
| 0 | 2009-08-13T09:03:16Z | [
"python"
] |
Python: Possible to share in-memory data between 2 separate processes | 1,268,252 | <p>I have an xmlrpc server using Twisted. The server has a huge amount of data stored in-memory. Is it possible to have a secondary, separate xmlrpc server running which can access the object in-memory in the first server?</p>
<p>So, serverA starts up and creates an object. serverB starts up and can read from the o... | 27 | 2009-08-12T19:33:11Z | 1,270,922 | <p>Why not stick the shared data into memcache server? then both servers can access it quite easily.</p>
| 1 | 2009-08-13T09:13:36Z | [
"python"
] |
Python: Possible to share in-memory data between 2 separate processes | 1,268,252 | <p>I have an xmlrpc server using Twisted. The server has a huge amount of data stored in-memory. Is it possible to have a secondary, separate xmlrpc server running which can access the object in-memory in the first server?</p>
<p>So, serverA starts up and creates an object. serverB starts up and can read from the o... | 27 | 2009-08-12T19:33:11Z | 1,271,568 | <p>You could write a C library to create and manipulate shared-memory arrays for your specific purpose, and then use ctypes to access them from Python.</p>
<p>Or, put them on the filesystem in /dev/shm (which is tmpfs). You'd save a lot of development effort for very little performance overhead: reads/writes from a t... | 2 | 2009-08-13T12:06:53Z | [
"python"
] |
Python: Possible to share in-memory data between 2 separate processes | 1,268,252 | <p>I have an xmlrpc server using Twisted. The server has a huge amount of data stored in-memory. Is it possible to have a secondary, separate xmlrpc server running which can access the object in-memory in the first server?</p>
<p>So, serverA starts up and creates an object. serverB starts up and can read from the o... | 27 | 2009-08-12T19:33:11Z | 28,376,308 | <p>There are a couple<sup>1</sup> of third party libraries available for low-level shared memory manipulations in Python:</p>
<ul>
<li><a href="http://semanchuk.com/philip/sysv_ipc/" rel="nofollow">sysv_ipc</a>
<ul>
<li>> For posix non-compliant systems</li>
</ul></li>
<li><a href="http://semanchuk.com/philip/posix_ip... | 2 | 2015-02-06T23:01:35Z | [
"python"
] |
Importing Model / Lib Class and calling from controller | 1,268,432 | <p>I'm new to python and pylons although experienced in PHP. </p>
<p>I'm trying to write a model class which will act as a my data access to my database (couchdb). My problem is simple </p>
<p>My model looks like this and is called models/BlogModel.py</p>
<pre><code>from couchdb import *
class BlogModel:
def g... | 1 | 2009-08-12T20:07:23Z | 1,268,461 | <pre><code>x = BlogModel.BlogModel()
</code></pre>
<p>Or, more verbosely:</p>
<p>After you did the import, you have an object in your namespace called 'BlogModel'. That object is the BlogModel module. (The module name comes from the filename.) Inside that module, there is a class object called 'BlogModel', which i... | 2 | 2009-08-12T20:13:46Z | [
"python",
"model-view-controller",
"pylons"
] |
Regex Matching Error | 1,268,761 | <p>I am new to Python (I dont have any programming training either), so please keep that in mind as I ask my question.</p>
<p>I am trying to search a retrieved webpage and find all links using a specified pattern. I have done this successfully in other scripts, but I am getting an error that says </p>
<blockquote>
<... | 8 | 2009-08-12T21:15:29Z | 1,268,780 | <p>You need to escape the literal '?' and the literal '(' and ')' that you are trying to match.</p>
<p>Also, instead of '?+', I think you're looking for the non-greedy matching provided by '+?'.</p>
<p><a href="http://docs.python.org/library/re.html" rel="nofollow">More documentation here.</a></p>
<p>For your case, ... | 1 | 2009-08-12T21:19:14Z | [
"python",
"regex"
] |
Regex Matching Error | 1,268,761 | <p>I am new to Python (I dont have any programming training either), so please keep that in mind as I ask my question.</p>
<p>I am trying to search a retrieved webpage and find all links using a specified pattern. I have done this successfully in other scripts, but I am getting an error that says </p>
<blockquote>
<... | 8 | 2009-08-12T21:15:29Z | 1,268,783 | <p>That means your regular expression has an error.</p>
<pre><code>(.?+)</a> <i>((.?+)
</code></pre>
<p>What does ?+ mean? Both ? and + are meta characters that does not make sense right next to each other. Maybe you forgot to escape the '?' or something.</p>
| 1 | 2009-08-12T21:19:26Z | [
"python",
"regex"
] |
Regex Matching Error | 1,268,761 | <p>I am new to Python (I dont have any programming training either), so please keep that in mind as I ask my question.</p>
<p>I am trying to search a retrieved webpage and find all links using a specified pattern. I have done this successfully in other scripts, but I am getting an error that says </p>
<blockquote>
<... | 8 | 2009-08-12T21:15:29Z | 1,268,804 | <p>To extend on what others wrote:</p>
<p>.? means "one or zero of any character"</p>
<p>.+ means "one ore more of any character"</p>
<p>As you can hopefully see, combining the two makes no sense; they are different and contradictory "repeat" characters. So, your error about "multiple repeats" is because you combin... | 0 | 2009-08-12T21:24:03Z | [
"python",
"regex"
] |
Regex Matching Error | 1,268,761 | <p>I am new to Python (I dont have any programming training either), so please keep that in mind as I ask my question.</p>
<p>I am trying to search a retrieved webpage and find all links using a specified pattern. I have done this successfully in other scripts, but I am getting an error that says </p>
<blockquote>
<... | 8 | 2009-08-12T21:15:29Z | 1,268,929 | <p>As you're discovering, parsing arbitrary HTML is not easy to do correctly. That's what packages like Beautiful Soup do. Note, you're calling it in your script but then not using the results. Refer to its documentation <a href="http://www.crummy.com/software/BeautifulSoup/documentation.html#Parsing%20HTML" rel="nof... | 1 | 2009-08-12T21:46:48Z | [
"python",
"regex"
] |
Regex Matching Error | 1,268,761 | <p>I am new to Python (I dont have any programming training either), so please keep that in mind as I ask my question.</p>
<p>I am trying to search a retrieved webpage and find all links using a specified pattern. I have done this successfully in other scripts, but I am getting an error that says </p>
<blockquote>
<... | 8 | 2009-08-12T21:15:29Z | 1,268,976 | <pre><code>import urllib2
import re
from BeautifulSoup import BeautifulSoup
url = "http://forums.epicgames.com/archive/index.php?f-356-p-164.html"
page = urllib2.urlopen(url).read()
soup = BeautifulSoup(page)
# Get all the links
links = [str(match) for match in soup('a')]
s = r'<a href="http://forums.epicgames.co... | 0 | 2009-08-12T22:01:25Z | [
"python",
"regex"
] |
Really long query | 1,268,899 | <p>How do u do long query? Is there way to optimize it?
I would do complicated and long query:</p>
<pre><code>all_accepted_parts = acceptedFragment.objects.filter(fragmentID = fragment.objects.filter(categories = fragmentCategory.objects.filter(id=1)))
</code></pre>
<p>but it doesn't work, i get: </p>
<pre><code>Err... | 0 | 2009-08-12T21:41:22Z | 1,269,024 | <p>If it's not working, you can't optimize it. First make it work.</p>
<p>At first glance, it seems that you have really mixed concepts about fields, relationships and equality/membership. First go thought the docs, and build your query piece by piece on the python shell (likely from the inside out).</p>
<p>Just a ... | 4 | 2009-08-12T22:10:55Z | [
"python",
"django",
"django-models"
] |
Really long query | 1,268,899 | <p>How do u do long query? Is there way to optimize it?
I would do complicated and long query:</p>
<pre><code>all_accepted_parts = acceptedFragment.objects.filter(fragmentID = fragment.objects.filter(categories = fragmentCategory.objects.filter(id=1)))
</code></pre>
<p>but it doesn't work, i get: </p>
<pre><code>Err... | 0 | 2009-08-12T21:41:22Z | 1,269,125 | <p>As others have said, we really need the models, and some explanation of what you're actually trying to achieve.</p>
<p>But it looks like you want to do a related table lookup. Rather than getting all the related objects in a separate nested query, you should use Django's related model syntax to do the join within y... | 4 | 2009-08-12T22:42:33Z | [
"python",
"django",
"django-models"
] |
Python http proxy library based on libevent or comparable technology? | 1,268,984 | <p>I'm looking to build an intelligent reverse http proxy capable of routing, header examination and enrichment (eg. examine and build cookies and http headers), and various other fanciness. For a general idea of what I'm looking to build see <a href="http://www.igvita.com/2009/04/20/ruby-proxies-for-scale-and-monitori... | 3 | 2009-08-12T22:02:30Z | 1,269,155 | <p>Not sure if meets all your needs, but <a href="http://pypi.python.org/pypi/proxylet/" rel="nofollow">proxylet</a> is a reverse proxy based on Linden Lab's <a href="http://eventlet.net/" rel="nofollow">eventlet</a>.</p>
| 3 | 2009-08-12T22:51:46Z | [
"python",
"http",
"proxy",
"libevent"
] |
InlineFormSet with queryset of different model | 1,269,052 | <p>What we're trying to do is populate a list of inline forms with initial values using some queryset of a different model. We have products, metrics (some category or type or rating), and a rating, which stores the actual rating and ties metrics to products.</p>
<pre><code>class Product(models.Model):
name = mode... | 1 | 2009-08-12T22:19:30Z | 1,843,537 | <p>Are you looking for an admin or front-end solution? The admin way is the following, you could reverse engineer it to get a similar front-end solution:</p>
<pre><code># admin.py
class RatingInline(admin.StackedInline):
model = Rating
class ProductAdmin(admin.ModelAdmin):
inlines = [
RatingInline
... | 0 | 2009-12-03T22:42:49Z | [
"python",
"django",
"forms",
"django-admin",
"django-forms"
] |
InlineFormSet with queryset of different model | 1,269,052 | <p>What we're trying to do is populate a list of inline forms with initial values using some queryset of a different model. We have products, metrics (some category or type or rating), and a rating, which stores the actual rating and ties metrics to products.</p>
<pre><code>class Product(models.Model):
name = mode... | 1 | 2009-08-12T22:19:30Z | 8,985,270 | <p>I have managed to implement similar functionality a bit like this:</p>
<pre><code>from django.forms.models import BaseInlineFormSet
from django.forms.models import inlineformset_factory
class RawQueryAdapter(object):
"""
Implement some extra methods to make a RawQuery
compatible with FormSet, which... | 0 | 2012-01-24T10:32:13Z | [
"python",
"django",
"forms",
"django-admin",
"django-forms"
] |
Calling a base class's classmethod in Python | 1,269,217 | <p>Consider the following code:</p>
<pre><code>class Base(object):
@classmethod
def do(cls, a):
print cls, a
class Derived(Base):
@classmethod
def do(cls, a):
print 'In derived!'
# Base.do(cls, a) -- can't pass `cls`
Base.do(a)
if __name__ == '__main__':
d = Deri... | 56 | 2009-08-12T23:07:22Z | 1,269,224 | <pre><code>super(Derived, cls).do(a)
</code></pre>
<p><em>EDIT</em>: Oh, wait a minute... it's not clear exactly what you're asking. This is how you would invoke the code in the base class's version of the method, from the derived class.</p>
| 64 | 2009-08-12T23:09:50Z | [
"python",
"class",
"overriding",
"class-method"
] |
Calling a base class's classmethod in Python | 1,269,217 | <p>Consider the following code:</p>
<pre><code>class Base(object):
@classmethod
def do(cls, a):
print cls, a
class Derived(Base):
@classmethod
def do(cls, a):
print 'In derived!'
# Base.do(cls, a) -- can't pass `cls`
Base.do(a)
if __name__ == '__main__':
d = Deri... | 56 | 2009-08-12T23:07:22Z | 1,269,233 | <p>This works for me:</p>
<pre><code>Base.do('hi')
</code></pre>
| 0 | 2009-08-12T23:12:48Z | [
"python",
"class",
"overriding",
"class-method"
] |
Calling a base class's classmethod in Python | 1,269,217 | <p>Consider the following code:</p>
<pre><code>class Base(object):
@classmethod
def do(cls, a):
print cls, a
class Derived(Base):
@classmethod
def do(cls, a):
print 'In derived!'
# Base.do(cls, a) -- can't pass `cls`
Base.do(a)
if __name__ == '__main__':
d = Deri... | 56 | 2009-08-12T23:07:22Z | 5,682,347 | <p>this has been a while, but I think I may have found an answer. When you decorate a method to become a classmethod the original unbound method is stored in a property named 'im_func':</p>
<pre><code>class Base(object):
@classmethod
def do(cls, a):
print cls, a
class Derived(Base):
@classmethod
... | 8 | 2011-04-15T21:01:49Z | [
"python",
"class",
"overriding",
"class-method"
] |
Differences between Smalltalk and python? | 1,269,242 | <p>I'm studying Smalltalk right now. It looks very similar to python (actually, the opposite, python is very similar to Smalltalk), so I was wondering, as a python enthusiast, if it's really worth for me to study it.</p>
<p>Apart from message passing, what are other notable conceptual differences between Smalltalk and... | 8 | 2009-08-12T23:17:31Z | 1,269,258 | <p>In Python, the "basic" constructs such as <code>if/else</code>, short-circuiting boolean operators, and loops are part of the language itself. In Smalltalk, they are all just messages. In that sense, while both Python and Smalltalk agree that "everything is an object", Smalltalk goes further in that it also asserts ... | 16 | 2009-08-12T23:24:01Z | [
"python",
"smalltalk"
] |
Differences between Smalltalk and python? | 1,269,242 | <p>I'm studying Smalltalk right now. It looks very similar to python (actually, the opposite, python is very similar to Smalltalk), so I was wondering, as a python enthusiast, if it's really worth for me to study it.</p>
<p>Apart from message passing, what are other notable conceptual differences between Smalltalk and... | 8 | 2009-08-12T23:17:31Z | 1,269,259 | <p>Smalltalk historically has had an amazing IDE built in. I have missed this IDE on many languages.</p>
<p>Smalltalk also has the lovely property that it is typically in a living system. You start up clean and start modifying things. This is basically an object persistent storage system. That being said, this is both... | 7 | 2009-08-12T23:24:14Z | [
"python",
"smalltalk"
] |
Differences between Smalltalk and python? | 1,269,242 | <p>I'm studying Smalltalk right now. It looks very similar to python (actually, the opposite, python is very similar to Smalltalk), so I was wondering, as a python enthusiast, if it's really worth for me to study it.</p>
<p>Apart from message passing, what are other notable conceptual differences between Smalltalk and... | 8 | 2009-08-12T23:17:31Z | 1,269,266 | <p>The language aspect often isn't that important, and many languages are quite <em>samey</em>,</p>
<p>From what I see, Python and Smalltalk share OOP ideals ... but are very different in their implementation and the power in the presented language interface.</p>
<p>the real value comes in what the <em>subtle</em> di... | 2 | 2009-08-12T23:25:26Z | [
"python",
"smalltalk"
] |
Differences between Smalltalk and python? | 1,269,242 | <p>I'm studying Smalltalk right now. It looks very similar to python (actually, the opposite, python is very similar to Smalltalk), so I was wondering, as a python enthusiast, if it's really worth for me to study it.</p>
<p>Apart from message passing, what are other notable conceptual differences between Smalltalk and... | 8 | 2009-08-12T23:17:31Z | 1,271,000 | <p>As someone new to smalltalk, the two things that really strike me are the image-based system, and that reflection is everywhere. These two simple facts appear to give rise to everything else cool in the system:</p>
<ul>
<li>The image means that you do everything by manipulating objects, including writing and compi... | 9 | 2009-08-13T09:34:40Z | [
"python",
"smalltalk"
] |
Differences between Smalltalk and python? | 1,269,242 | <p>I'm studying Smalltalk right now. It looks very similar to python (actually, the opposite, python is very similar to Smalltalk), so I was wondering, as a python enthusiast, if it's really worth for me to study it.</p>
<p>Apart from message passing, what are other notable conceptual differences between Smalltalk and... | 8 | 2009-08-12T23:17:31Z | 33,929,812 | <p>The Smalltalk language itself is very important. It comprises a small set of powerful, orthogonal features that makes the language highly extensible. As Alan Lovejoy says:
"Smalltalk is also fun because defining and using <em>domain specific languages</em> isnât an afterthought, itâs the only way Smalltalk works... | 0 | 2015-11-26T02:49:51Z | [
"python",
"smalltalk"
] |
In GTK, is there an easy way to scale all widgets by an arbitrary amount? | 1,269,268 | <p>I want my widget to look exactly like it does now, except to be smaller. It includes buttons, labels, text, images, etc. Is there any way to just say "scale this to be half the size", and have GTK do all the image processing, widget resizing, etc., necessary? If not, what's the easiest way to accomplish this?</p>
| 0 | 2009-08-12T23:25:54Z | 1,269,286 | <p>There is no built in way to do this. To do this, you'll have to consider what is "taking up space" in your ui, and how to reduce it.</p>
<p>If your UI is mostly text and images, you can use a smaller font size, then scale all images down by an appropriate percentage. The widget sizing will shrink automatically once... | 1 | 2009-08-12T23:29:55Z | [
"python",
"user-interface",
"gtk",
"pygtk"
] |
In GTK, is there an easy way to scale all widgets by an arbitrary amount? | 1,269,268 | <p>I want my widget to look exactly like it does now, except to be smaller. It includes buttons, labels, text, images, etc. Is there any way to just say "scale this to be half the size", and have GTK do all the image processing, widget resizing, etc., necessary? If not, what's the easiest way to accomplish this?</p>
| 0 | 2009-08-12T23:25:54Z | 1,283,493 | <p>Change the theme from the user interface is not something that I recommend, but you can do it if you require it, using a custom gtkrc may help you to change the font and the way the buttons are drawed, mostly because of the xthickness and ythickness.</p>
<pre><code> import gtk
file = "/path/to/the/gtkrc"
gtk.rc_p... | 2 | 2009-08-16T05:12:15Z | [
"python",
"user-interface",
"gtk",
"pygtk"
] |
In GTK, is there an easy way to scale all widgets by an arbitrary amount? | 1,269,268 | <p>I want my widget to look exactly like it does now, except to be smaller. It includes buttons, labels, text, images, etc. Is there any way to just say "scale this to be half the size", and have GTK do all the image processing, widget resizing, etc., necessary? If not, what's the easiest way to accomplish this?</p>
| 0 | 2009-08-12T23:25:54Z | 1,283,503 | <p>Having written a 100% scalable gtk app, what I did was limit myself to gdk_draw_line, and gdk_draw_rectangle, which were easy to then scale myself. Text was "done" via gdk_draw_line. (for certain low values of "done.") See: <a href="http://wordwarvi.sourceforge.net" rel="nofollow">http://wordwarvi.sourceforge.ne... | 0 | 2009-08-16T05:24:10Z | [
"python",
"user-interface",
"gtk",
"pygtk"
] |
In GTK, is there an easy way to scale all widgets by an arbitrary amount? | 1,269,268 | <p>I want my widget to look exactly like it does now, except to be smaller. It includes buttons, labels, text, images, etc. Is there any way to just say "scale this to be half the size", and have GTK do all the image processing, widget resizing, etc., necessary? If not, what's the easiest way to accomplish this?</p>
| 0 | 2009-08-12T23:25:54Z | 1,309,447 | <p>Resolution independence has been worked on by some gtk devs, and here is an update with a very big patch to introduce it into GTK. The patch is however a year old now and it is still unclear how/when/if it is going to be included: (screenshots at the end)</p>
<p><a href="http://mail.gnome.org/archives/gtk-devel-lis... | 2 | 2009-08-20T23:49:45Z | [
"python",
"user-interface",
"gtk",
"pygtk"
] |
Scale an image in GTK | 1,269,320 | <p>In GTK, how can I scale an image? Right now I load images with PIL and scale them beforehand, but is there a way to do it with GTK?</p>
| 11 | 2009-08-12T23:44:38Z | 1,283,486 | <p>Load the image from a file using gtk.gdk.Pixbuf for that:</p>
<pre><code>import gtk
pixbuf = gtk.gdk.pixbuf_new_from_file('/path/to/the/image.png')
</code></pre>
<p>then scale it:</p>
<pre><code>pixbuf = pixbuf.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR)
</code></pre>
<p>Then, if you want use it in a gt... | 10 | 2009-08-16T05:06:11Z | [
"python",
"user-interface",
"image",
"gtk",
"pygtk"
] |
Scale an image in GTK | 1,269,320 | <p>In GTK, how can I scale an image? Right now I load images with PIL and scale them beforehand, but is there a way to do it with GTK?</p>
| 11 | 2009-08-12T23:44:38Z | 1,309,462 | <p>It might be more effective to simply scale them before loading. I especially think so since I use these functions to load in 96x96 thumbnails from sometimes very large JPEGs, still very fast.</p>
<pre><code>gtk.gdk.pixbuf_new_from_file_at_scale(..)
gtk.gdk.pixbuf_new_from_file_at_size(..)
</code></pre>
| 6 | 2009-08-20T23:55:21Z | [
"python",
"user-interface",
"image",
"gtk",
"pygtk"
] |
Scale an image in GTK | 1,269,320 | <p>In GTK, how can I scale an image? Right now I load images with PIL and scale them beforehand, but is there a way to do it with GTK?</p>
| 11 | 2009-08-12T23:44:38Z | 19,303,924 | <p>Scale image from URL. ( <a href="http://www.pygtk.org/docs/pygtk/class-gdkpixbufloader.html#method-gdkpixbufloader--set-size" rel="nofollow">scale reference</a> )</p>
<pre><code>import pygtk
pygtk.require('2.0')
import gtk
import urllib2
class MainWin:
def destroy(self, widget, data=None):
print "dest... | 1 | 2013-10-10T18:52:13Z | [
"python",
"user-interface",
"image",
"gtk",
"pygtk"
] |
How can I change the font size in GTK? | 1,269,326 | <p>Is there an easy way to change the font size of text elements in GTK? Right now the best I can do is do <code>set_markup</code> on a label, with something silly like:</p>
<pre><code>lbl.set_markup("<span font_desc='Tahoma 5.4'>%s</span>" % text)
</code></pre>
<p>This 1) requires me to set the font , 2)... | 1 | 2009-08-12T23:46:40Z | 1,269,338 | <p>In C, you can do:</p>
<pre><code>gtk_widget_modify_font(lbl, pango_font_description_from_string("Tahoma 5.4"));
</code></pre>
<p>In PyGTK, I believe it's something like:</p>
<pre><code>pangoFont = pango.FontDescription("Tahoma 5.4")
lbl.modify_font(pangoFont)
</code></pre>
| 3 | 2009-08-12T23:52:32Z | [
"python",
"fonts",
"gtk",
"pygtk",
"gtk2"
] |
How can I change the font size in GTK? | 1,269,326 | <p>Is there an easy way to change the font size of text elements in GTK? Right now the best I can do is do <code>set_markup</code> on a label, with something silly like:</p>
<pre><code>lbl.set_markup("<span font_desc='Tahoma 5.4'>%s</span>" % text)
</code></pre>
<p>This 1) requires me to set the font , 2)... | 1 | 2009-08-12T23:46:40Z | 1,269,367 | <p>If you want to change font overall in your app(s), I'd leave this job to gtkrc (then becomes a google question, and "gtkrc font" query brings us to <a href="http://ubuntuforums.org/showthread.php?t=846348">this ubuntu forums link</a> which has the following snippet of the the gtkrc file):</p>
<pre><code>style "font... | 6 | 2009-08-13T00:02:07Z | [
"python",
"fonts",
"gtk",
"pygtk",
"gtk2"
] |
Python threading question - returning control to parent | 1,269,466 | <p>Basically, I have a python program which listens for DeviceAdded DBus events (e.g. when someone plugs in a USB drive), and when an event occurs, I want to create a thread which collects metadata on that newly connected device. However, I want to do this asynchronously - that is, allow one thread to keep collecting m... | 0 | 2009-08-13T00:37:30Z | 1,269,514 | <p>Try spawning a thread just for the capture stuff, by changing the following lines in your <code>_filter()</code> function to this:</p>
<pre><code>if device.QueryCapability("volume"):
threading.start_new_thread(self.capture, (device))
</code></pre>
<p>This is assuming that the bulk of the work is happening in t... | 2 | 2009-08-13T00:53:12Z | [
"python",
"multithreading",
"dbus"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.