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 |
|---|---|---|---|---|---|---|---|---|---|
Search functionality for Django | 932,255 | <p>I'm developing a web app using Django, and I'll need to add search functionality soon. Search will be implemented for two models, one being an extension of the auth user class and another one with the fields <code>name</code>, <code>tags</code>, and <code>description</code>. So I guess nothing too scary here in cont... | 2 | 2009-05-31T15:33:44Z | 932,604 | <p>Django has <a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#search" rel="nofollow">full text searching</a> support in its QuerySet filters. Right now, if you only have two models that need searching, just make a view that searches the fields on both:</p>
<pre><code>search_string = "+Django -jazz... | 1 | 2009-05-31T18:38:27Z | [
"python",
"database",
"django",
"search",
"full-text-search"
] |
Python: defining my own operators? | 932,328 | <p>I would like to define my own operator. Does python support such a thing?</p>
| 33 | 2009-05-31T16:01:39Z | 932,333 | <p>no, python comes with a predefined, yet overridable, <a href="http://docs.python.org/library/operator.html#mapping-operators-to-functions">set of operators</a>.</p>
| 27 | 2009-05-31T16:03:03Z | [
"python",
"operators"
] |
Python: defining my own operators? | 932,328 | <p>I would like to define my own operator. Does python support such a thing?</p>
| 33 | 2009-05-31T16:01:39Z | 932,347 | <p>No, you can't create new operators. However, if you are just evaluating expressions, you could process the string yourself and calculate the results of the new operators.</p>
| 22 | 2009-05-31T16:06:16Z | [
"python",
"operators"
] |
Python: defining my own operators? | 932,328 | <p>I would like to define my own operator. Does python support such a thing?</p>
| 33 | 2009-05-31T16:01:39Z | 932,385 | <p>If you intend to apply the operation on a particular class of objects, you could just override the operator that matches your function the closest... for instance, overriding <code>__eq__()</code> will override the <code>==</code> operator to return whatever you want. This works for almost all the operators.</p>
| 7 | 2009-05-31T16:27:43Z | [
"python",
"operators"
] |
Python: defining my own operators? | 932,328 | <p>I would like to define my own operator. Does python support such a thing?</p>
| 33 | 2009-05-31T16:01:39Z | 932,580 | <p>While technically you cannot define new operators in Python, this <a href="http://code.activestate.com/recipes/384122/">clever hack</a> works around this limitation. It allows you to define infix operators like this:</p>
<pre><code># simple multiplication
x=Infix(lambda x,y: x*y)
print 2 |x| 4
# => 8
# class ch... | 107 | 2009-05-31T18:18:32Z | [
"python",
"operators"
] |
Python: defining my own operators? | 932,328 | <p>I would like to define my own operator. Does python support such a thing?</p>
| 33 | 2009-05-31T16:01:39Z | 20,667,084 | <p>Sage provides this functionality, essentially using the "clever hack" described by @Ayman Hourieh, but incorporated into a module as a decorator to give a cleaner appearance and additional functionality â you can choose the operator to overload and therefore the order of evaluation.</p>
<pre><code>from sage.misc.... | 5 | 2013-12-18T19:47:32Z | [
"python",
"operators"
] |
Python: defining my own operators? | 932,328 | <p>I would like to define my own operator. Does python support such a thing?</p>
| 33 | 2009-05-31T16:01:39Z | 27,858,621 | <p>Python 3.5 introduces the symbol <code>@</code> for an extra operator.</p>
<p><a href="http://legacy.python.org/dev/peps/pep-0465/" rel="nofollow">PEP465</a> introduced this new operator for matrix multiplication, to simplify the notation of many numerical code. The operator will not be implemented for all types, b... | 3 | 2015-01-09T10:32:36Z | [
"python",
"operators"
] |
How can I get the next string, in alphanumeric ordering, in Python? | 932,506 | <p>I need a simple program that given a string, returns to me the next one in the alphanumeric ordering (or just the alphabetic ordering).</p>
<pre><code>f("aaa")="aab"
f("aaZ")="aba"
</code></pre>
<p>And so on.</p>
<p>Is there a function for this in one of the modules already?</p>
| 5 | 2009-05-31T17:33:15Z | 932,525 | <p>Are the answers at <a href="http://stackoverflow.com/questions/604721/how-would-you-translate-this-from-perl-to-python/604777">http://stackoverflow.com/questions/604721/how-would-you-translate-this-from-perl-to-python/604777</a> sufficient? Not 100% what you're asking, but close...</p>
| 3 | 2009-05-31T17:42:06Z | [
"python",
"string"
] |
How can I get the next string, in alphanumeric ordering, in Python? | 932,506 | <p>I need a simple program that given a string, returns to me the next one in the alphanumeric ordering (or just the alphabetic ordering).</p>
<pre><code>f("aaa")="aab"
f("aaZ")="aba"
</code></pre>
<p>And so on.</p>
<p>Is there a function for this in one of the modules already?</p>
| 5 | 2009-05-31T17:33:15Z | 932,536 | <p>I don't think there's a built-in function to do this. The following should work:</p>
<pre><code>def next_string(s):
strip_zs = s.rstrip('z')
if strip_zs:
return strip_zs[:-1] + chr(ord(strip_zs[-1]) + 1) + 'a' * (len(s) - len(strip_zs))
else:
return 'a' * (len(s) + 1)
</code></pre>
<p>... | 12 | 2009-05-31T17:46:17Z | [
"python",
"string"
] |
How can I get the next string, in alphanumeric ordering, in Python? | 932,506 | <p>I need a simple program that given a string, returns to me the next one in the alphanumeric ordering (or just the alphabetic ordering).</p>
<pre><code>f("aaa")="aab"
f("aaZ")="aba"
</code></pre>
<p>And so on.</p>
<p>Is there a function for this in one of the modules already?</p>
| 5 | 2009-05-31T17:33:15Z | 932,719 | <p>A different, longer, but perhaps more readable and flexible solution:</p>
<pre><code>def toval(s):
"""Converts an 'azz' string into a number"""
v = 0
for c in s.lower():
v = v * 26 + ord(c) - ord('a')
return v
def tostr(v, minlen=0):
"""Converts a number into 'azz' string"""
s = ''
... | 2 | 2009-05-31T19:51:51Z | [
"python",
"string"
] |
How can I get the next string, in alphanumeric ordering, in Python? | 932,506 | <p>I need a simple program that given a string, returns to me the next one in the alphanumeric ordering (or just the alphabetic ordering).</p>
<pre><code>f("aaa")="aab"
f("aaZ")="aba"
</code></pre>
<p>And so on.</p>
<p>Is there a function for this in one of the modules already?</p>
| 5 | 2009-05-31T17:33:15Z | 12,358,681 | <p>Sucks that python doesn't have what ruby has: <code>String#next</code> So here's a shitty solution to deal with alpha-numerical strings:</p>
<pre><code>def next_string(s):
a1 = range(65, 91) # capital letters
a2 = range(97, 123) # letters
a3 = range(48, 58) # numbers
char = ord(s[-1])
for a in [a1, a2, ... | 1 | 2012-09-10T20:06:12Z | [
"python",
"string"
] |
Expression up to comment or end of line | 932,783 | <p>Although this question is similar to <a href="http://stackoverflow.com/questions/175103/regex-to-match-url-end-of-line-or-character">this thread</a></p>
<p>I think I might be doing something wrong at the time of constructing the code with the Regular Expression.</p>
<p>I want to match anything in a line up to a co... | 2 | 2009-05-31T20:23:33Z | 932,786 | <p>Here's the correct regex to do something like this:</p>
<pre><code>([^#]*)(#.*)?
</code></pre>
<p>Also, why don't you just use</p>
<pre><code>file = open('file.txt')
for line in file:
</code></pre>
| 3 | 2009-05-31T20:27:35Z | [
"python",
"regex"
] |
Expression up to comment or end of line | 932,783 | <p>Although this question is similar to <a href="http://stackoverflow.com/questions/175103/regex-to-match-url-end-of-line-or-character">this thread</a></p>
<p>I think I might be doing something wrong at the time of constructing the code with the Regular Expression.</p>
<p>I want to match anything in a line up to a co... | 2 | 2009-05-31T20:23:33Z | 932,805 | <p>The * is greedy (consumes as much of the string as it can) and is thus consuming the entire line (past the # and to the end-of-line). Change ".*" to ".*?" and it will work.</p>
<p>See the <a href="http://docs.python.org/howto/regex.html#repeating-things">Regular Expression HOWTO</a> for more information.</p>
| 6 | 2009-05-31T20:36:46Z | [
"python",
"regex"
] |
Expression up to comment or end of line | 932,783 | <p>Although this question is similar to <a href="http://stackoverflow.com/questions/175103/regex-to-match-url-end-of-line-or-character">this thread</a></p>
<p>I think I might be doing something wrong at the time of constructing the code with the Regular Expression.</p>
<p>I want to match anything in a line up to a co... | 2 | 2009-05-31T20:23:33Z | 932,846 | <p>Use this regular expression:</p>
<pre><code>^(.*?)(?:#|$)
</code></pre>
<p>With the non-greedy modifier (<code>?</code>), the <code>.*</code> expression will match as <em>soon</em> as either a hash sign or end-of-line is reached. The default is to match as <em>much</em> as possible, and that is why you always got ... | 0 | 2009-05-31T20:56:14Z | [
"python",
"regex"
] |
Expression up to comment or end of line | 932,783 | <p>Although this question is similar to <a href="http://stackoverflow.com/questions/175103/regex-to-match-url-end-of-line-or-character">this thread</a></p>
<p>I think I might be doing something wrong at the time of constructing the code with the Regular Expression.</p>
<p>I want to match anything in a line up to a co... | 2 | 2009-05-31T20:23:33Z | 932,855 | <p>@Can, @Benji and @ ΤÎΩΤÎÎÎÎ¥ give three excellent solutions, and it's fun to time them to see how fast they match (that's what <code>timeit</code> is for -- fun meaningless micro-benchmarks;-). E.g.:</p>
<pre><code>$ python -mtimeit -s'import re; r=re.compile(r"([^#]*)(#.*)?"); s="this is a line # and this... | 1 | 2009-05-31T21:00:17Z | [
"python",
"regex"
] |
How to parse angular values using regular expressions | 932,796 | <p>I have very little experience using regular expressions and I need to parse an angle value expressed as bearings, using regular expressions, example:</p>
<p>"N45°20'15.3"E" </p>
<p>Which represents:
45 degrees, 20 minutes with 15.3 seconds, located at the NE quadrant.</p>
<p>The restrictions are:</p>
<ul>
<li>T... | 3 | 2009-05-31T20:33:01Z | 932,806 | <p>A pattern you could use:</p>
<pre><code>pat = r"^([NS])(\d+)°(\d+)'([\d.]*)\"?([EW])$"
</code></pre>
<p>one way to use it:</p>
<pre><code>import re
r = re.compile(pat)
m = r.match(thestring)
if m is None:
print "%r does not match!" % thestring
else:
print "%r matches: %s" % (thestring, m.groups())
</code></p... | 4 | 2009-05-31T20:36:55Z | [
"python",
"regex",
"angle"
] |
How to parse angular values using regular expressions | 932,796 | <p>I have very little experience using regular expressions and I need to parse an angle value expressed as bearings, using regular expressions, example:</p>
<p>"N45°20'15.3"E" </p>
<p>Which represents:
45 degrees, 20 minutes with 15.3 seconds, located at the NE quadrant.</p>
<p>The restrictions are:</p>
<ul>
<li>T... | 3 | 2009-05-31T20:33:01Z | 932,812 | <p>Try this regular expression:</p>
<pre><code>^([NS])([0-5]?\d)°([0-5]?\d)'(?:([0-5]?\d)(?:\.\d)?")?([EW])$
</code></pre>
<p>It matches any string that â¦</p>
<ul>
<li><strong><code>^([NS])</code></strong>Â Â Â begins with <code>N</code> or <code>S</code></li>
<li><strong><code>([0-5]?\d)°</code></strong>   f... | 8 | 2009-05-31T20:41:01Z | [
"python",
"regex",
"angle"
] |
retrieving a variable's name in python at runtime? | 932,818 | <p>is there a way to know, during run-time, a variable's name (from the code) ?
or do var names forgotten during compilation (byte-code or not) ?</p>
<p>e.g.</p>
<pre>
>>> vari = 15
>>> print vari.~~name~~()
'vari'
</pre>
<p>note: i'm talking about plain data-type variables (int, str, list...)</p>
| 26 | 2009-05-31T20:44:07Z | 932,829 | <p>Variable names persist in the compiled code (that's how e.g. the <code>dir</code> built-in can work), but the mapping that's there goes from name to value, not vice versa. So if there are several variables all worth, for example, <code>23</code>, there's no way to tell them from each other base only on the value <co... | 10 | 2009-05-31T20:48:26Z | [
"python"
] |
retrieving a variable's name in python at runtime? | 932,818 | <p>is there a way to know, during run-time, a variable's name (from the code) ?
or do var names forgotten during compilation (byte-code or not) ?</p>
<p>e.g.</p>
<pre>
>>> vari = 15
>>> print vari.~~name~~()
'vari'
</pre>
<p>note: i'm talking about plain data-type variables (int, str, list...)</p>
| 26 | 2009-05-31T20:44:07Z | 932,835 | <p>Variable names don't get forgotten, you can access variables (and look which variables you have) by introspection, e.g. </p>
<pre><code>>>> i = 1
>>> locals()["i"]
1
</code></pre>
<p>However, because there are no pointers in Python, there's no way to reference a variable without actually writing ... | 28 | 2009-05-31T20:52:27Z | [
"python"
] |
retrieving a variable's name in python at runtime? | 932,818 | <p>is there a way to know, during run-time, a variable's name (from the code) ?
or do var names forgotten during compilation (byte-code or not) ?</p>
<p>e.g.</p>
<pre>
>>> vari = 15
>>> print vari.~~name~~()
'vari'
</pre>
<p>note: i'm talking about plain data-type variables (int, str, list...)</p>
| 26 | 2009-05-31T20:44:07Z | 932,906 | <p>Just yesterday I saw a blog post with working code that does just this. Here's the link:</p>
<p><a href="http://pyside.blogspot.com/2009/05/finding-objects-names.html" rel="nofollow">http://pyside.blogspot.com/2009/05/finding-objects-names.html</a></p>
| 0 | 2009-05-31T21:31:11Z | [
"python"
] |
retrieving a variable's name in python at runtime? | 932,818 | <p>is there a way to know, during run-time, a variable's name (from the code) ?
or do var names forgotten during compilation (byte-code or not) ?</p>
<p>e.g.</p>
<pre>
>>> vari = 15
>>> print vari.~~name~~()
'vari'
</pre>
<p>note: i'm talking about plain data-type variables (int, str, list...)</p>
| 26 | 2009-05-31T20:44:07Z | 1,101,302 | <p>I tried the following link from the post above with no success:
Googling returned this one.</p>
<p><a href="http://pythonic.pocoo.org/2009/5/30/finding-objects-names" rel="nofollow">http://pythonic.pocoo.org/2009/5/30/finding-objects-names</a></p>
| 1 | 2009-07-09T00:56:42Z | [
"python"
] |
retrieving a variable's name in python at runtime? | 932,818 | <p>is there a way to know, during run-time, a variable's name (from the code) ?
or do var names forgotten during compilation (byte-code or not) ?</p>
<p>e.g.</p>
<pre>
>>> vari = 15
>>> print vari.~~name~~()
'vari'
</pre>
<p>note: i'm talking about plain data-type variables (int, str, list...)</p>
| 26 | 2009-05-31T20:44:07Z | 6,504,447 | <p>This will work for simple data types (str, int, float, list etc.)</p>
<pre><code>def my_print(var_str) :
print var_str+':', globals()[var_str]
</code></pre>
| 3 | 2011-06-28T09:35:49Z | [
"python"
] |
retrieving a variable's name in python at runtime? | 932,818 | <p>is there a way to know, during run-time, a variable's name (from the code) ?
or do var names forgotten during compilation (byte-code or not) ?</p>
<p>e.g.</p>
<pre>
>>> vari = 15
>>> print vari.~~name~~()
'vari'
</pre>
<p>note: i'm talking about plain data-type variables (int, str, list...)</p>
| 26 | 2009-05-31T20:44:07Z | 15,220,835 | <p>Here is a function I use to print the value of variables, it works for local as well as globals:</p>
<pre><code>import sys
def print_var(var_name):
calling_frame = sys._getframe().f_back
var_val = calling_frame.f_locals.get(var_name, calling_frame.f_globals.get(var_name, None))
print (var_name+':', str(... | 4 | 2013-03-05T09:59:55Z | [
"python"
] |
retrieving a variable's name in python at runtime? | 932,818 | <p>is there a way to know, during run-time, a variable's name (from the code) ?
or do var names forgotten during compilation (byte-code or not) ?</p>
<p>e.g.</p>
<pre>
>>> vari = 15
>>> print vari.~~name~~()
'vari'
</pre>
<p>note: i'm talking about plain data-type variables (int, str, list...)</p>
| 26 | 2009-05-31T20:44:07Z | 19,681,131 | <p>You can do it, it's just not pretty.</p>
<pre><code>import inspect, sys
def addVarToDict(d, variable):
lineNumber = inspect.currentframe().f_back.f_lineno
with open(sys.argv[0]) as f:
lines = f.read().split("\n")
line = lines[lineNumber-1]
varName = line.split("addVarToDict")[1].split("(... | 2 | 2013-10-30T11:36:24Z | [
"python"
] |
retrieving a variable's name in python at runtime? | 932,818 | <p>is there a way to know, during run-time, a variable's name (from the code) ?
or do var names forgotten during compilation (byte-code or not) ?</p>
<p>e.g.</p>
<pre>
>>> vari = 15
>>> print vari.~~name~~()
'vari'
</pre>
<p>note: i'm talking about plain data-type variables (int, str, list...)</p>
| 26 | 2009-05-31T20:44:07Z | 29,522,250 | <p>here a basic (maybe weird) function that shows the name of its argument...
the idea is to analyze code and search for the calls to the function (added in the <strong>init</strong> method it could help to find the instance name, although with a more complex code analysis)</p>
<pre><code>def display(var):
import ... | 1 | 2015-04-08T18:11:55Z | [
"python"
] |
XML characters in python xml.dom | 933,004 | <p>I am working on producing an xml document from python. We are using the xml.dom package to create the xml document. We are having a problem where we want to produce the character &#x03c6; which is a φ. However, when we put that string in a text node and call toxml() on it we get &amp;#x03c6;. Our... | 1 | 2009-05-31T22:16:45Z | 933,091 | <p>I think you need to use a Unicode string with <code>\u03c6</code> in it, because the <code>.data</code> field of a text node is supposed (as far as I understand) to be "parsed" data, not including XML entities (whence the <code>&amp;</code> when made back into XML). If you want to ensure that, on output, non-as... | 1 | 2009-05-31T23:17:08Z | [
"python",
"xml",
"dom"
] |
Python module globals versus __init__ globals | 933,042 | <p>Apologies, somewhat confused Python newbie question. Let's say I have a module called <code>animals.py</code>.......</p>
<pre><code>globvar = 1
class dog:
def bark(self):
print globvar
class cat:
def miaow(self):
print globvar
</code></pre>
<p>What is the difference between this and</p>
<pre>... | 4 | 2009-05-31T22:44:09Z | 933,062 | <p>No, the <code>global</code> statement only matters when you're <em>assigning</em> to a global variable within a method or function. So that <code>__init__</code> is irrelevant -- it does <strong>not</strong> create the global, because it's not assigning anything to it.</p>
| 4 | 2009-05-31T22:53:45Z | [
"python",
"global"
] |
Python module globals versus __init__ globals | 933,042 | <p>Apologies, somewhat confused Python newbie question. Let's say I have a module called <code>animals.py</code>.......</p>
<pre><code>globvar = 1
class dog:
def bark(self):
print globvar
class cat:
def miaow(self):
print globvar
</code></pre>
<p>What is the difference between this and</p>
<pre>... | 4 | 2009-05-31T22:44:09Z | 933,084 | <p><code>global</code> doesn't create a new variable, it just states that this name should refer to a global variable instead of a local one. Usually assignments to variables in a function/class/... refer to local variables. For example take a function like this:</p>
<pre><code>def increment(n)
# this creates a new ... | 8 | 2009-05-31T23:12:13Z | [
"python",
"global"
] |
Python Regex combined with string substitution? | 933,046 | <p>I'm wondering if its possible to use string substitution along with the python re module?</p>
<p>For example I'm using optparse and have a variable named options.hostname which will change each time the user executes the script. </p>
<p>I have the following regex matching 3 strings in each line of the log file.</p... | -1 | 2009-05-31T22:47:24Z | 933,060 | <pre><code> match = re.search (r'^\[(\d+)\] (SERVICE NOTIFICATION:).*(\bCRITICAL).*(%s)'
% options.hostname, line)
</code></pre>
| 2 | 2009-05-31T22:52:15Z | [
"python",
"regex"
] |
Clipping FFT Matrix | 933,088 | <p>Audio processing is pretty new for me. And currently using Python Numpy for processing wave files. After calculating FFT matrix I am getting noisy power values for non-existent frequencies. I am interested in visualizing the data and accuracy is not a high priority. Is there a safe way to calculate the clipping valu... | 2 | 2009-05-31T23:15:35Z | 933,144 | <p>FFT's because they are windowed and <a href="http://en.wikipedia.org/wiki/Sampling%5F(signal%5Fprocessing)" rel="nofollow">sampled cause <a href="http://en.wikipedia.org/wiki/Aliasing" rel="nofollow">aliasing</a> and sampling in the frequency domain as well. Filtering in the time domain is just multiplication in th... | 2 | 2009-05-31T23:49:36Z | [
"python",
"audio",
"signal-processing",
"fft"
] |
Clipping FFT Matrix | 933,088 | <p>Audio processing is pretty new for me. And currently using Python Numpy for processing wave files. After calculating FFT matrix I am getting noisy power values for non-existent frequencies. I am interested in visualizing the data and accuracy is not a high priority. Is there a safe way to calculate the clipping valu... | 2 | 2009-05-31T23:15:35Z | 933,271 | <p>Simulated waveforms shouldn't show FFTs like your figure, so something is very wrong, and probably not with the FFT, but with the input waveform. The main problem in your plot is not the ripples, but the harmonics around 1000 Hz, and the subharmonic at 500 Hz. A simulated waveform shouldn't show any of this (for e... | 3 | 2009-06-01T01:27:00Z | [
"python",
"audio",
"signal-processing",
"fft"
] |
Clipping FFT Matrix | 933,088 | <p>Audio processing is pretty new for me. And currently using Python Numpy for processing wave files. After calculating FFT matrix I am getting noisy power values for non-existent frequencies. I am interested in visualizing the data and accuracy is not a high priority. Is there a safe way to calculate the clipping valu... | 2 | 2009-05-31T23:15:35Z | 933,558 | <p>It's worth mentioning for a 1D FFT that the first element (index <code>[0]</code>) contains the DC (zero-frequency) term, the elements <code>[1:N/2]</code> contain the positive frequencies and the elements <code>[N/2+1:N-1]</code> contain the negative frequencies. Since you didn't provide a code sample or additiona... | 1 | 2009-06-01T04:24:43Z | [
"python",
"audio",
"signal-processing",
"fft"
] |
Clipping FFT Matrix | 933,088 | <p>Audio processing is pretty new for me. And currently using Python Numpy for processing wave files. After calculating FFT matrix I am getting noisy power values for non-existent frequencies. I am interested in visualizing the data and accuracy is not a high priority. Is there a safe way to calculate the clipping valu... | 2 | 2009-05-31T23:15:35Z | 934,841 | <p>I don't know enough from your question to actually answer anything specific.</p>
<p>But here are a couple of things to try from my own experience writing FFTs:</p>
<ul>
<li>Make sure you are following Nyquist rule</li>
<li>If you are viewing the linear output of the FFT... you will have trouble seeing your own sig... | 1 | 2009-06-01T13:34:16Z | [
"python",
"audio",
"signal-processing",
"fft"
] |
Generic many-to-many relationships | 933,092 | <p>I'm trying to create a messaging system where a message's sender and recipients can be generic entities. This seems fine for the sender, where there is only object to reference (GenericForeignKey) but I can't figure out how to go about this for the recipients (GenericManyToManyKey ??)</p>
<p>Below is a simplified e... | 34 | 2009-05-31T23:18:01Z | 933,315 | <p>You might get around this problem by simplifying your schema to include a single <code>Client</code> table with a flag to indicate what type of client it was, instead of having two separate models.</p>
<pre><code>from django.db import models
from django.utils.translation import ugettext_lazy as _
class Client(mode... | 4 | 2009-06-01T02:02:47Z | [
"python",
"django",
"generics",
"django-models",
"many-to-many"
] |
Generic many-to-many relationships | 933,092 | <p>I'm trying to create a messaging system where a message's sender and recipients can be generic entities. This seems fine for the sender, where there is only object to reference (GenericForeignKey) but I can't figure out how to go about this for the recipients (GenericManyToManyKey ??)</p>
<p>Below is a simplified e... | 34 | 2009-05-31T23:18:01Z | 937,385 | <p>You can implement this using generic relationships by manually creating the junction table between message and recipient:</p>
<pre><code>from django.db import models
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
class Client(models.Model):
city = mod... | 45 | 2009-06-02T00:10:47Z | [
"python",
"django",
"generics",
"django-models",
"many-to-many"
] |
Generic many-to-many relationships | 933,092 | <p>I'm trying to create a messaging system where a message's sender and recipients can be generic entities. This seems fine for the sender, where there is only object to reference (GenericForeignKey) but I can't figure out how to go about this for the recipients (GenericManyToManyKey ??)</p>
<p>Below is a simplified e... | 34 | 2009-05-31T23:18:01Z | 32,989,576 | <p>The absolute best way to go about this is to use a library called django-gm2m</p>
<pre><code>pip install django-gm2m
</code></pre>
<p>Then if we have our models</p>
<pre><code>>>> from django.db import models
>>>
>>> class Video(models.Model):
>>> pass
>>>
>>... | 1 | 2015-10-07T10:13:16Z | [
"python",
"django",
"generics",
"django-models",
"many-to-many"
] |
Django-like abstract database API for non-Django projects | 933,232 | <p>I love the abstract database API that comes with Django, I was wondering if I could use this (or something similar) to model, access, and manage my (postgres) database for my non-Django Python projects.</p>
| 5 | 2009-06-01T00:58:06Z | 933,235 | <p>What you're looking for is an <a href="http://en.wikipedia.org/wiki/Object-relational%5Fmapping">object-relational mapper</a> (ORM). Django has its own, built-in.</p>
<p>To use Django's ORM by itself:</p>
<ul>
<li><a href="http://jystewart.net/process/2008/02/using-the-django-orm-as-a-standalone-component/">Using ... | 16 | 2009-06-01T01:00:11Z | [
"python",
"database",
"django",
"orm",
"django-models"
] |
Django-like abstract database API for non-Django projects | 933,232 | <p>I love the abstract database API that comes with Django, I was wondering if I could use this (or something similar) to model, access, and manage my (postgres) database for my non-Django Python projects.</p>
| 5 | 2009-06-01T00:58:06Z | 933,238 | <p>Popular stand-alone ORMs for Python:</p>
<ul>
<li><a href="http://www.sqlalchemy.org/">SQLAlchemy</a></li>
<li><a href="http://www.sqlobject.org/">SQLObject</a></li>
<li><a href="https://storm.canonical.com/">Storm</a></li>
</ul>
<p>They all support MySQL and PostgreSQL (among others).</p>
| 7 | 2009-06-01T01:01:55Z | [
"python",
"database",
"django",
"orm",
"django-models"
] |
Django-like abstract database API for non-Django projects | 933,232 | <p>I love the abstract database API that comes with Django, I was wondering if I could use this (or something similar) to model, access, and manage my (postgres) database for my non-Django Python projects.</p>
| 5 | 2009-06-01T00:58:06Z | 933,834 | <p>I especially like <a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a> with following tools:</p>
<ul>
<li><a href="http://elixir.ematia.de/" rel="nofollow">Elixir</a> (declarative syntax)</li>
<li><a href="http://code.google.com/p/sqlalchemy-migrate/" rel="nofollow">Migrate</a> (schema migration)</li>... | 2 | 2009-06-01T07:20:15Z | [
"python",
"database",
"django",
"orm",
"django-models"
] |
Control an embedded into website flash player with Python? | 933,441 | <p>I am trying to write few simple python scripts, which will allow me to control one of the Internet radio (which I listen) with an keybinded python scripts.</p>
<p>I am now able to connect and log into the website, I am able to get out the song data ( that is - all the data which are passed to the player).</p>
<p>I... | 0 | 2009-06-01T03:20:33Z | 933,478 | <p>No you can't control the player with Python, flash and javascript can talk to each other because of how the Flash player works when embedded in a web page. Sounds like you're circumventing the flash player anyhow, so why do you need to control a player you're not using?</p>
| 1 | 2009-06-01T03:41:23Z | [
"javascript",
"python",
"flash",
"control",
"embedded-resource"
] |
Is there a way to invoke a Python function with the wrong number of arguments without invoking a TypeError? | 933,484 | <p>When you invoke a function with the wrong number of arguments, or with a keyword argument that isn't in its definition, you get a TypeError. I'd like a piece of code to take a callback and invoke it with variable arguments, based on what the callback supports. One way of doing it would be to, for a callback <code>cb... | 1 | 2009-06-01T03:43:49Z | 933,493 | <p>Rather than digging down into the details yourself, you can <a href="http://docs.python.org/library/inspect.html" rel="nofollow">inspect</a> the function's signature -- you probably want <code>inspect.getargspec(cb)</code>.</p>
<p>Exactly how you want to use that info, and the args you have, to call the function "p... | 7 | 2009-06-01T03:47:31Z | [
"python",
"apply",
"invocation"
] |
Is there a way to invoke a Python function with the wrong number of arguments without invoking a TypeError? | 933,484 | <p>When you invoke a function with the wrong number of arguments, or with a keyword argument that isn't in its definition, you get a TypeError. I'd like a piece of code to take a callback and invoke it with variable arguments, based on what the callback supports. One way of doing it would be to, for a callback <code>cb... | 1 | 2009-06-01T03:43:49Z | 933,513 | <p>This maybe?</p>
<pre><code>def fnVariableArgLength(*args, **kwargs):
"""
- args is a list of non keywords arguments
- kwargs is a dict of keywords arguments (keyword, arg) pairs
"""
print args, kwargs
fnVariableArgLength() # () {}
fnVariableArgLength(1, 2, 3) # (1, 2, 3) {}
fnVariableArgLength... | 3 | 2009-06-01T03:57:23Z | [
"python",
"apply",
"invocation"
] |
Custom Markup in Django | 933,500 | <p>Can anyone give me an idea or perhaps some references on how to create custom markups for django using textile or Markdown(or am I thinking wrong here)?</p>
<p>For example: I'd like to convert the following markups(the outer bracket mean they are grouped as one tag:<br />
[<br />
[Contacts]<br />
* Contact #1<br />... | 1 | 2009-06-01T03:53:08Z | 933,504 | <p>A quick google search resulted with <a href="http://www.freewisdom.org/projects/python-markdown/Django" rel="nofollow">this</a></p>
| 0 | 2009-06-01T03:55:02Z | [
"python",
"django",
"markdown"
] |
Custom Markup in Django | 933,500 | <p>Can anyone give me an idea or perhaps some references on how to create custom markups for django using textile or Markdown(or am I thinking wrong here)?</p>
<p>For example: I'd like to convert the following markups(the outer bracket mean they are grouped as one tag:<br />
[<br />
[Contacts]<br />
* Contact #1<br />... | 1 | 2009-06-01T03:53:08Z | 934,715 | <p>Django comes with a built-in contrib app that provides filters to display data using several different markup languages, including textile and markdown.</p>
<p>See <a href="http://docs.djangoproject.com/en/dev/ref/contrib/#markup" rel="nofollow">the relevant docs</a> for more info.</p>
| 1 | 2009-06-01T12:59:55Z | [
"python",
"django",
"markdown"
] |
Custom Markup in Django | 933,500 | <p>Can anyone give me an idea or perhaps some references on how to create custom markups for django using textile or Markdown(or am I thinking wrong here)?</p>
<p>For example: I'd like to convert the following markups(the outer bracket mean they are grouped as one tag:<br />
[<br />
[Contacts]<br />
* Contact #1<br />... | 1 | 2009-06-01T03:53:08Z | 935,344 | <p>The built in <a href="http://docs.djangoproject.com/en/dev/ref/contrib/#markup" rel="nofollow">markup</a> app uses a filter template tag to render textile, markdown and restructuredtext. If that is not what your looking for, another option is to use a 'markup' field. e.g.,</p>
<pre><code>class TownHallUpdate(models... | 3 | 2009-06-01T15:36:57Z | [
"python",
"django",
"markdown"
] |
Custom Markup in Django | 933,500 | <p>Can anyone give me an idea or perhaps some references on how to create custom markups for django using textile or Markdown(or am I thinking wrong here)?</p>
<p>For example: I'd like to convert the following markups(the outer bracket mean they are grouped as one tag:<br />
[<br />
[Contacts]<br />
* Contact #1<br />... | 1 | 2009-06-01T03:53:08Z | 948,022 | <p>Well it seems the best way is still use a regex and create my own filter. </p>
<p>here are some links that helped me out:<br />
<a href="http://showmedo.com/videos/video?name=1100010&fromSeriesID=110" rel="nofollow">http://showmedo.com/videos/video?name=1100010&fromSeriesID=110</a><br />
<a href="http://ww... | 0 | 2009-06-04T00:36:22Z | [
"python",
"django",
"markdown"
] |
What is the best way to fetch/render one-to-many relationships? | 933,612 | <p>I have 2 models which look like that:</p>
<pre><code>class Entry(models.Model):
user = models.ForeignKey(User)
dataname = models.TextField()
datadesc = models.TextField()
timestamp = models.DateTimeField(auto_now=True)
class EntryFile(models.Model):
entry = models.ForeignKey(Entry)
datafile = models.FileFi... | 2 | 2009-06-01T05:01:38Z | 933,633 | <p>Just cut your view code to this line:</p>
<pre><code>entries = Entry.objects.filter(user=request.user).order_by("-timestamp")
</code></pre>
<p>And do this in the template:</p>
<pre><code>{% for entry in entries %}
<td>{{ entry.datadesc }}</td>
<td><table>
{% for file in entry.e... | 5 | 2009-06-01T05:13:44Z | [
"python",
"django"
] |
Packaging script source files in IronPython and IronRuby | 933,822 | <p>Does anyone know how to add python and ruby libs as a resource in a dll for deployment? I want to host a script engine in my app, but dont want to have to deploy the entire standard libraries of the respective languages in source files. Is there a simple way to do this so that a require or import statement will fi... | 3 | 2009-06-01T07:14:45Z | 933,954 | <p>You can create StreamContentProviders for example</p>
<p>In the ironrubymvc project under IronRubyMVC/Core/ you will find what you need.</p>
<p><a href="http://github.com/casualjim/ironrubymvc/blob/01fc9e5f4cd6b3c0f96a75acd9521673b3f0701e/IronRubyMvc/Core/AssemblyStreamContentProvider.cs" rel="nofollow">AssemblySt... | 0 | 2009-06-01T08:19:01Z | [
"c#",
"python",
"ruby",
"ironpython",
"ironruby"
] |
Packaging script source files in IronPython and IronRuby | 933,822 | <p>Does anyone know how to add python and ruby libs as a resource in a dll for deployment? I want to host a script engine in my app, but dont want to have to deploy the entire standard libraries of the respective languages in source files. Is there a simple way to do this so that a require or import statement will fi... | 3 | 2009-06-01T07:14:45Z | 933,988 | <p>IronPython 2.0 has a sample compiler called PYC on Codeplex.com/ironpython which can create DLL's (and applications if you need them too).</p>
<p>IronPython 2.6 has a newer version of PYC under Tools\script.</p>
<p>Cheers,
Davy</p>
| 0 | 2009-06-01T08:35:49Z | [
"c#",
"python",
"ruby",
"ironpython",
"ironruby"
] |
Packaging script source files in IronPython and IronRuby | 933,822 | <p>Does anyone know how to add python and ruby libs as a resource in a dll for deployment? I want to host a script engine in my app, but dont want to have to deploy the entire standard libraries of the respective languages in source files. Is there a simple way to do this so that a require or import statement will fi... | 3 | 2009-06-01T07:14:45Z | 934,609 | <p>You could add custom import hook that looks for embedded resources when an import is executed. This is slightly complex and probably not worth the trouble.</p>
<p>A better technique would be to fetch all of the embedded modules at startup time, execute them with the ScriptEngine and put the modules you have created... | 1 | 2009-06-01T12:23:55Z | [
"c#",
"python",
"ruby",
"ironpython",
"ironruby"
] |
Python Regex Search And Replace | 933,824 | <p>I'm not new to Python but a complete newbie with regular expressions (on my to do list)</p>
<p>I am trying to use python re to convert a string such as</p>
<pre><code>[Hollywood Holt](http://www.hollywoodholt.com)
</code></pre>
<p>to</p>
<pre><code><a href="http://www.hollywoodholt.com">Hollywood Holt</... | 4 | 2009-06-01T07:15:04Z | 933,826 | <p>Why are you bothering to use a regex? Your content is Markdown, why not simply take the string and run it through the markdown module?</p>
<p>First, make sure Markdown is installed. It has a dependancy on ElementTree so easy_install the two of them as follows. If you're running Windows, you can use the <a href="... | 12 | 2009-06-01T07:16:50Z | [
"python",
"regex",
"string",
"markdown"
] |
Python module for editing text in CLI | 933,941 | <p>Is there some python module or commands that would allow me to make my python program enter a CLI text editor, populate the editor with some text, and when it exits, get out the text into some variable?</p>
<p>At the moment I have users enter stuff in using raw_input(), but I would like something a bit more powerfu... | 2 | 2009-06-01T08:10:22Z | 933,952 | <p>If you don't need windows support you can use the <a href="http://docs.python.org/library/readline.html" rel="nofollow">readline module</a> to get basic command line editing like at the shell prompt.</p>
| 0 | 2009-06-01T08:18:28Z | [
"python",
"text-editor",
"command-line-interface"
] |
Python module for editing text in CLI | 933,941 | <p>Is there some python module or commands that would allow me to make my python program enter a CLI text editor, populate the editor with some text, and when it exits, get out the text into some variable?</p>
<p>At the moment I have users enter stuff in using raw_input(), but I would like something a bit more powerfu... | 2 | 2009-06-01T08:10:22Z | 933,962 | <p>You could have a look at <a href="http://excess.org/urwid/" rel="nofollow">urwid</a>, a curses-based, full-fledged UI toolkit for python. It allows you to define very sophisticated interfaces and it includes different edit box types for different types of text.</p>
| 2 | 2009-06-01T08:22:51Z | [
"python",
"text-editor",
"command-line-interface"
] |
Python module for editing text in CLI | 933,941 | <p>Is there some python module or commands that would allow me to make my python program enter a CLI text editor, populate the editor with some text, and when it exits, get out the text into some variable?</p>
<p>At the moment I have users enter stuff in using raw_input(), but I would like something a bit more powerfu... | 2 | 2009-06-01T08:10:22Z | 933,965 | <p>Well, you can launch the user's $EDITOR with subprocess, editing a temporary file:</p>
<pre><code>import tempfile
import subprocess
import os
t = tempfile.NamedTemporaryFile(delete=False)
try:
editor = os.environ['EDITOR']
except KeyError:
editor = 'nano'
subprocess.call([editor, t.name])
</code></pre>
| 7 | 2009-06-01T08:24:56Z | [
"python",
"text-editor",
"command-line-interface"
] |
Comparison of data in SQL through Python | 934,117 | <p>I have to parse a very complex dump (whatever it is). I have done the parsing through Python. Since the parsed data is very huge in amount, I have to feed it in the database (SQL). I have also done this. Now the thing is I have to compare the data now present in the SQL.</p>
<p>Actually I have to compare the data o... | 0 | 2009-06-01T09:27:51Z | 934,761 | <p>Why not do the 'dectect change' in SQL? Something like:</p>
<pre><code>select foo.data1, foo.data2 from foo where foo.id = 'dump1'
minus
select foo.data1, foo.data2 from foo where foo.id = 'dump2'
</code></pre>
| 0 | 2009-06-01T13:11:42Z | [
"python",
"sql"
] |
Comparison of data in SQL through Python | 934,117 | <p>I have to parse a very complex dump (whatever it is). I have done the parsing through Python. Since the parsed data is very huge in amount, I have to feed it in the database (SQL). I have also done this. Now the thing is I have to compare the data now present in the SQL.</p>
<p>Actually I have to compare the data o... | 0 | 2009-06-01T09:27:51Z | 936,733 | <p>If you don't have <code>MINUS</code> or <code>EXCEPT</code>, there is also this, which will show all non-matching rows using a <code>UNION</code>/<code>GROUP BY</code> trick</p>
<pre><code>SELECT MAX(table), data1, data2
FROM (
SELECT 'foo1' AS table, foo1.data1, foo1.data2 FROM foo1
UNION ALL
SELECT 'f... | 1 | 2009-06-01T20:53:28Z | [
"python",
"sql"
] |
Write to UTF-8 file in Python | 934,160 | <p>I'm really confused with the <code>codecs.open function</code>. When I do:</p>
<pre><code>file = codecs.open("temp", "w", "utf-8")
file.write(codecs.BOM_UTF8)
file.close()
</code></pre>
<p>It gives me the error</p>
<blockquote>
<p>UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position
0: ordinal... | 113 | 2009-06-01T09:42:23Z | 934,173 | <p>Disclaimer: I'm not a Python programmer.</p>
<p>I believe the problem is that <a href="https://docs.python.org/library/codecs.html#codecs.BOM_UTF8"><code>codecs.BOM_UTF8</code></a> is a byte string, not a Unicode string. I suspect the file handler is trying to guess what you really mean based on "I'm meant to be wr... | 168 | 2009-06-01T09:46:58Z | [
"python",
"utf-8",
"byte-order-mark"
] |
Write to UTF-8 file in Python | 934,160 | <p>I'm really confused with the <code>codecs.open function</code>. When I do:</p>
<pre><code>file = codecs.open("temp", "w", "utf-8")
file.write(codecs.BOM_UTF8)
file.close()
</code></pre>
<p>It gives me the error</p>
<blockquote>
<p>UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position
0: ordinal... | 113 | 2009-06-01T09:42:23Z | 934,203 | <p>Read the following: <a href="http://docs.python.org/library/codecs.html#module-encodings.utf_8_sig">http://docs.python.org/library/codecs.html#module-encodings.utf_8_sig</a></p>
<p>Do this </p>
<pre><code>with codecs.open("test_output", "w", "utf-8-sig") as temp:
temp.write("hi mom\n")
temp.write(u"This h... | 129 | 2009-06-01T09:58:14Z | [
"python",
"utf-8",
"byte-order-mark"
] |
Write to UTF-8 file in Python | 934,160 | <p>I'm really confused with the <code>codecs.open function</code>. When I do:</p>
<pre><code>file = codecs.open("temp", "w", "utf-8")
file.write(codecs.BOM_UTF8)
file.close()
</code></pre>
<p>It gives me the error</p>
<blockquote>
<p>UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position
0: ordinal... | 113 | 2009-06-01T09:42:23Z | 934,228 | <p>@S-Lott gives the right procedure, but expanding on the <em>Unicode</em> issues, the <em>Python</em> interpreter can provide more insights.</p>
<p>Jon Skeet is right (unusual) about the <a href="http://docs.python.org/library/codecs.html#codecs.BOM"><code>codecs</code></a> module - it contains byte strings:</p>
<p... | 11 | 2009-06-01T10:12:39Z | [
"python",
"utf-8",
"byte-order-mark"
] |
Write to UTF-8 file in Python | 934,160 | <p>I'm really confused with the <code>codecs.open function</code>. When I do:</p>
<pre><code>file = codecs.open("temp", "w", "utf-8")
file.write(codecs.BOM_UTF8)
file.close()
</code></pre>
<p>It gives me the error</p>
<blockquote>
<p>UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position
0: ordinal... | 113 | 2009-06-01T09:42:23Z | 9,200,975 | <p>I use the file *nix command to convert a unknown charset file in a utf-8 file</p>
<pre><code># -*- encoding: utf-8 -*-
# converting a unknown formatting file in utf-8
import codecs
import commands
file_location = "jumper.sub"
file_encoding = commands.getoutput('file -b --mime-encoding %s' % file_location)
file_... | 4 | 2012-02-08T20:35:11Z | [
"python",
"utf-8",
"byte-order-mark"
] |
python db connection | 934,221 | <p>I am having a script which makes a db connection and pereform some select operation.accroding to the fetch data i am calling different functions which also perform db operations.How can i pass db connection to the functions which are being called as i donot want to make new connection</p>
| 0 | 2009-06-01T10:08:00Z | 934,709 | <p>Why to pass connection itself? Maybe build a class that handles all the DB-operation and just pass this class' instance around, calling it's methods to perform selects, inserts and all that DB-specific code? </p>
| 2 | 2009-06-01T12:58:26Z | [
"python"
] |
Getting response from bluetooth device | 934,460 | <p>I'm trying to write a simple module that will enable sending SMS. I using bluetooth to connect to the mobile using the below example:</p>
<h1>file: bt-sendsms.py</h1>
<pre><code>import bluetooth
target = '00:32:AC:32:36:E8' # Mobile address
print "Trying to send SMS on %s" % target
BTSocket = bluetooth.Bluet... | 2 | 2009-06-01T11:35:07Z | 934,543 | <p>From the Python you look like you are opening any old RFCOMM channel and hoping it will magically take the AT commands and do the messaging.</p>
<p>I think (and I could be wrong) that you need to connect to a specific profile/sevice channel and I think for SMS it is the the Messaging Access Profile (MAP), which is ... | 3 | 2009-06-01T12:02:02Z | [
"python",
"sms",
"bluetooth",
"mobile-phones"
] |
Java equivalent of function mapping in Python | 934,509 | <p>In python, if I have a few functions that I would like to call based on an input, i can do this:</p>
<pre><code>lookup = {'function1':function1, 'function2':function2, 'function3':function3}
lookup[input]()
</code></pre>
<p>That is I have a dictionary of function name mapped to the function, and call the function ... | 7 | 2009-06-01T11:48:37Z | 934,520 | <p>You could use a Map<String,Method> or Map<String,Callable> etc,and then use map.get("function1").invoke(...). But usually these kinds of problems are tackled more cleanly by using polymorphism instead of a lookup.</p>
| 2 | 2009-06-01T11:52:36Z | [
"java",
"python",
"function"
] |
Java equivalent of function mapping in Python | 934,509 | <p>In python, if I have a few functions that I would like to call based on an input, i can do this:</p>
<pre><code>lookup = {'function1':function1, 'function2':function2, 'function3':function3}
lookup[input]()
</code></pre>
<p>That is I have a dictionary of function name mapped to the function, and call the function ... | 7 | 2009-06-01T11:48:37Z | 934,532 | <p>Java doesn't have first-class methods, so the <a href="http://en.wikipedia.org/wiki/Command%5Fpattern">command pattern</a> is your friend...</p>
<p>disclamer: code not tested!</p>
<pre><code>public interface Command
{
void invoke();
}
Map<String, Command> commands = new HashMap<String, Command>()... | 14 | 2009-06-01T11:58:09Z | [
"java",
"python",
"function"
] |
Java equivalent of function mapping in Python | 934,509 | <p>In python, if I have a few functions that I would like to call based on an input, i can do this:</p>
<pre><code>lookup = {'function1':function1, 'function2':function2, 'function3':function3}
lookup[input]()
</code></pre>
<p>That is I have a dictionary of function name mapped to the function, and call the function ... | 7 | 2009-06-01T11:48:37Z | 934,676 | <p>Polymorphic example..</p>
<pre><code>public interface Animal {public void speak();};
public class Dog implements Animal {public void speak(){System.out.println("treat? treat? treat?");}}
public class Cat implements Animal {public void speak(){System.out.println("leave me alone");}}
public class Hamster implements A... | 1 | 2009-06-01T12:45:54Z | [
"java",
"python",
"function"
] |
Java equivalent of function mapping in Python | 934,509 | <p>In python, if I have a few functions that I would like to call based on an input, i can do this:</p>
<pre><code>lookup = {'function1':function1, 'function2':function2, 'function3':function3}
lookup[input]()
</code></pre>
<p>That is I have a dictionary of function name mapped to the function, and call the function ... | 7 | 2009-06-01T11:48:37Z | 934,843 | <p>There are several ways to approach this problem. Most of these were posted already:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/934509/java-equivalent-of-function-mapping-in-python/934532#934532">Commands</a> - Keep a bunch of objects that have an execute() or invoke() method in a map; lookup the comm... | 3 | 2009-06-01T13:35:27Z | [
"java",
"python",
"function"
] |
Java equivalent of function mapping in Python | 934,509 | <p>In python, if I have a few functions that I would like to call based on an input, i can do this:</p>
<pre><code>lookup = {'function1':function1, 'function2':function2, 'function3':function3}
lookup[input]()
</code></pre>
<p>That is I have a dictionary of function name mapped to the function, and call the function ... | 7 | 2009-06-01T11:48:37Z | 935,077 | <p>As mentioned in other questions, a <code>Map<String,MyCommandType></code> with anonymous inner classes is one verbose way to do it.</p>
<p>A variation is to use enums in place of the anonymous inner classes. Each constant of the enum can implement/override methods of the enum or implemented interface, much th... | 0 | 2009-06-01T14:30:33Z | [
"java",
"python",
"function"
] |
Java equivalent of function mapping in Python | 934,509 | <p>In python, if I have a few functions that I would like to call based on an input, i can do this:</p>
<pre><code>lookup = {'function1':function1, 'function2':function2, 'function3':function3}
lookup[input]()
</code></pre>
<p>That is I have a dictionary of function name mapped to the function, and call the function ... | 7 | 2009-06-01T11:48:37Z | 935,788 | <p>Unfortunately, Java does not have first-class functions, but consider the following interface:</p>
<pre><code>public interface F<A, B> {
public B f(A a);
}
</code></pre>
<p>This models the type for functions from type <code>A</code> to type <code>B</code>, as first-class values that you can pass around. Wh... | 0 | 2009-06-01T17:13:49Z | [
"java",
"python",
"function"
] |
Java equivalent of function mapping in Python | 934,509 | <p>In python, if I have a few functions that I would like to call based on an input, i can do this:</p>
<pre><code>lookup = {'function1':function1, 'function2':function2, 'function3':function3}
lookup[input]()
</code></pre>
<p>That is I have a dictionary of function name mapped to the function, and call the function ... | 7 | 2009-06-01T11:48:37Z | 936,122 | <p>As everyone else said, Java doesn't support functions as first-level objects. To achieve this, you use a Functor, which is a class that wraps a function. Steve Yegge has a <a href="http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html" rel="nofollow">nice rant</a> about that.</p>
<p>To help you... | 0 | 2009-06-01T18:33:46Z | [
"java",
"python",
"function"
] |
Insert/Delete performance | 934,602 | <pre><code>DB Table:
id int(6)
message char(5)
</code></pre>
<p>I have to add a record (message) to the DB table. In case of duplicate message(this message already exists with different id) I want to delete (or inactivate somehow) the both of the messages and get their ID's in reply.</p>
<p>Is it possible to ... | 1 | 2009-06-01T12:19:54Z | 934,607 | <p>You could write a procedure with both of those commands in it, but it may make more sense to use an insert trigger to check for duplicates (or a nightly job, if it's not time-sensitive).</p>
| 1 | 2009-06-01T12:22:51Z | [
"python",
"database",
"performance",
"database-design"
] |
Insert/Delete performance | 934,602 | <pre><code>DB Table:
id int(6)
message char(5)
</code></pre>
<p>I have to add a record (message) to the DB table. In case of duplicate message(this message already exists with different id) I want to delete (or inactivate somehow) the both of the messages and get their ID's in reply.</p>
<p>Is it possible to ... | 1 | 2009-06-01T12:19:54Z | 934,726 | <p>It is a little difficult to understand your exact requirement. Let me rephrase it two ways:</p>
<ol>
<li><p>You want both the entries with same messages in the table (with different IDs), and want to know the IDs for some further processing (marking them as inactive, etc.). For this, You could write a procedure wit... | 0 | 2009-06-01T13:03:08Z | [
"python",
"database",
"performance",
"database-design"
] |
Insert/Delete performance | 934,602 | <pre><code>DB Table:
id int(6)
message char(5)
</code></pre>
<p>I have to add a record (message) to the DB table. In case of duplicate message(this message already exists with different id) I want to delete (or inactivate somehow) the both of the messages and get their ID's in reply.</p>
<p>Is it possible to ... | 1 | 2009-06-01T12:19:54Z | 935,952 | <p>If you really want to worry about locking do this.</p>
<ol>
<li><p>UPDATE table SET status='INACTIVE' WHERE id = 'key';</p>
<p>If this succeeds, there was a duplicate.</p>
<ul>
<li>INSERT the additional inactive record. Do whatever else you want with your duplicates.</li>
</ul>
<p>If this fails, there was no du... | 2 | 2009-06-01T18:00:45Z | [
"python",
"database",
"performance",
"database-design"
] |
How do I find out if a numpy array contains integers? | 934,616 | <p>I know there is a simple solution to this but can't seem to find it at the moment.</p>
<p>Given a numpy array, I need to know if the array contains integers.</p>
<p>Checking the dtype per-se is not enough, as there are multiple int dtypes (int8, int16, int32, int64 ...). </p>
| 24 | 2009-06-01T12:27:46Z | 934,652 | <p>Found it in the <a href="http://templatelab.com/numpybook/">numpy book</a>! Page 23:</p>
<blockquote>
<p>The other types in the hierarchy deï¬ne particular categories of types.
These categories can be useful for testing whether or not the object
returned by self.dtype.type is of a particular class (using i... | 27 | 2009-06-01T12:39:12Z | [
"python",
"numpy"
] |
How do I find out if a numpy array contains integers? | 934,616 | <p>I know there is a simple solution to this but can't seem to find it at the moment.</p>
<p>Given a numpy array, I need to know if the array contains integers.</p>
<p>Checking the dtype per-se is not enough, as there are multiple int dtypes (int8, int16, int32, int64 ...). </p>
| 24 | 2009-06-01T12:27:46Z | 1,168,729 | <p>This also works: </p>
<pre><code> n.dtype('int8').kind == 'i'
</code></pre>
| 6 | 2009-07-22T22:52:30Z | [
"python",
"numpy"
] |
How do I find out if a numpy array contains integers? | 934,616 | <p>I know there is a simple solution to this but can't seem to find it at the moment.</p>
<p>Given a numpy array, I need to know if the array contains integers.</p>
<p>Checking the dtype per-se is not enough, as there are multiple int dtypes (int8, int16, int32, int64 ...). </p>
| 24 | 2009-06-01T12:27:46Z | 7,236,784 | <p>Checking for an integer type does not work for floats that are integers, e.g. <code>4.</code> Better solution is <code>np.equal(np.mod(x, 1), 0)</code>, as in:</p>
<pre><code>>>> import numpy as np
>>> def isinteger(x):
... return np.equal(np.mod(x, 1), 0)
...
>>> foo = np.array([0.,... | 9 | 2011-08-29T22:34:52Z | [
"python",
"numpy"
] |
How do I find out if a numpy array contains integers? | 934,616 | <p>I know there is a simple solution to this but can't seem to find it at the moment.</p>
<p>Given a numpy array, I need to know if the array contains integers.</p>
<p>Checking the dtype per-se is not enough, as there are multiple int dtypes (int8, int16, int32, int64 ...). </p>
| 24 | 2009-06-01T12:27:46Z | 36,203,582 | <p>Numpy's issubdtype() function can be used as follows:</p>
<pre><code>import numpy as np
size=(3,3)
A = np.random.randint(0, 255, size)
B = np.random.random(size)
print 'Array A:\n', A
print 'Integers:', np.issubdtype(A[0,0], int)
print 'Floats:', np.issubdtype(A[0,0], float)
print '\nArray B:\n', B
print 'Inte... | 2 | 2016-03-24T15:12:23Z | [
"python",
"numpy"
] |
Implimenting NSText delegate methods in PyObjc and Cocoa | 934,628 | <p>In the project that I'm building, I'd like to have a method called when I paste some text into a specific text field. I can't seem to get this to work, but here's what I've tried</p>
<p>I implimented a custom class (based on NSObject) to be a delegate for my textfield, then gave it the method: textDidChange:</p>
<... | 3 | 2009-06-01T12:31:57Z | 936,075 | <p>The reason this isn't working for you is that <code>textDidChange_</code> isn't a delegate method. It's a method on the <code>NSTextField</code> that posts the notification of the change. If you have peek at the docs for <code>textDidChange</code>, you'll see that it mentions the actual name of the delegate method:<... | 3 | 2009-06-01T18:24:44Z | [
"python",
"cocoa",
"pyobjc"
] |
Python3.0 - tokenize and untokenize | 934,661 | <p>I am using something similar to the following simplified script to parse snippets of python from a larger file:</p>
<pre><code>import io
import tokenize
src = 'foo="bar"'
src = bytes(src.encode())
src = io.BytesIO(src)
src = list(tokenize.tokenize(src.readline))
for tok in src:
print(tok)
src = tokenize.untok... | 2 | 2009-06-01T12:41:21Z | 934,681 | <p>If you limit the input to <code>untokenize</code> to the first 2 items of the tokens, it seems to work.</p>
<pre><code>import io
import tokenize
src = 'foo="bar"'
src = bytes(src.encode())
src = io.BytesIO(src)
src = list(tokenize.tokenize(src.readline))
for tok in src:
print(tok)
src = [t[:2] for t in src]
s... | 0 | 2009-06-01T12:48:53Z | [
"python",
"python-3.x",
"tokenize",
"lexical-analysis"
] |
Python3.0 - tokenize and untokenize | 934,661 | <p>I am using something similar to the following simplified script to parse snippets of python from a larger file:</p>
<pre><code>import io
import tokenize
src = 'foo="bar"'
src = bytes(src.encode())
src = io.BytesIO(src)
src = list(tokenize.tokenize(src.readline))
for tok in src:
print(tok)
src = tokenize.untok... | 2 | 2009-06-01T12:41:21Z | 934,682 | <p><pre><code>src = 'foo="bar"\n'</code></pre>You forgot newline.</p>
| 3 | 2009-06-01T12:49:16Z | [
"python",
"python-3.x",
"tokenize",
"lexical-analysis"
] |
Using easy_install inside a python script? | 935,111 | <p>easy_install python extension allows to install python eggs from console like:</p>
<pre><code>easy_install py2app
</code></pre>
<p>But is it possible to access easy_install functionality inside a python script? I means, without calling os.system( "easy_install py2app" ) but instead importing easy_install as a pyth... | 15 | 2009-06-01T14:39:05Z | 935,186 | <p>I think you can get to that by using either importing setuptools.</p>
| -2 | 2009-06-01T14:57:33Z | [
"python",
"setuptools"
] |
Using easy_install inside a python script? | 935,111 | <p>easy_install python extension allows to install python eggs from console like:</p>
<pre><code>easy_install py2app
</code></pre>
<p>But is it possible to access easy_install functionality inside a python script? I means, without calling os.system( "easy_install py2app" ) but instead importing easy_install as a pyth... | 15 | 2009-06-01T14:39:05Z | 935,219 | <p>When I look at the setup tools source, it looks like you can try the following.</p>
<pre><code>from setuptools.command import easy_install
easy_install.main( ["-U","py2app"] )
</code></pre>
| 17 | 2009-06-01T15:05:46Z | [
"python",
"setuptools"
] |
Using easy_install inside a python script? | 935,111 | <p>easy_install python extension allows to install python eggs from console like:</p>
<pre><code>easy_install py2app
</code></pre>
<p>But is it possible to access easy_install functionality inside a python script? I means, without calling os.system( "easy_install py2app" ) but instead importing easy_install as a pyth... | 15 | 2009-06-01T14:39:05Z | 935,254 | <p>What specifically are you trying to do? Unless you have some weird requirements, I'd recommend declaring the package as a dependency in your setup.py:</p>
<pre><code>from setuptools import setup, find_packages
setup(
name = "HelloWorld",
version = "0.1",
packages = find_packages(),
scripts = ['say_... | 2 | 2009-06-01T15:13:47Z | [
"python",
"setuptools"
] |
Using easy_install inside a python script? | 935,111 | <p>easy_install python extension allows to install python eggs from console like:</p>
<pre><code>easy_install py2app
</code></pre>
<p>But is it possible to access easy_install functionality inside a python script? I means, without calling os.system( "easy_install py2app" ) but instead importing easy_install as a pyth... | 15 | 2009-06-01T14:39:05Z | 935,351 | <pre><code>from setuptools.command import easy_install
def install_with_easyinstall(package):
easy_install.main(["-U", package]).
install_with_easyinstall('py2app')
</code></pre>
| 4 | 2009-06-01T15:38:08Z | [
"python",
"setuptools"
] |
Using easy_install inside a python script? | 935,111 | <p>easy_install python extension allows to install python eggs from console like:</p>
<pre><code>easy_install py2app
</code></pre>
<p>But is it possible to access easy_install functionality inside a python script? I means, without calling os.system( "easy_install py2app" ) but instead importing easy_install as a pyth... | 15 | 2009-06-01T14:39:05Z | 5,944,496 | <p>The answer about invoking <code>setuptools.main()</code> is correct. However, if setuptools creates a .egg, the script will be unable to import the module after installing it. Eggs are added automatically to sys.path at python start time.</p>
<p>One solution is to use require() to add the new egg to the path:</p>
... | 0 | 2011-05-10T02:19:52Z | [
"python",
"setuptools"
] |
Cast a class instance to a subclass | 935,448 | <p>I'm using <a href="http://code.google.com/p/boto/" rel="nofollow">boto</a> to manage some <a href="http://aws.amazon.com/ec2/" rel="nofollow">EC2</a> instances. It provides an Instance class. I'd like to subclass it to meet my particular needs. Since boto provides a query interface to get your instances, I need some... | 3 | 2009-06-01T15:55:54Z | 936,498 | <p>I wouldn't subclass and cast. I don't think casting is ever a good policy. </p>
<p>Instead, consider a Wrapper or Façade.</p>
<pre><code>class MyThing( object ):
def __init__( self, theInstance ):
self.ec2_instance = theInstance
</code></pre>
<p>Now, you can subclass <code>MyThing</code> as much as... | 7 | 2009-06-01T20:03:39Z | [
"python",
"class",
"subclass",
"boto"
] |
Python Mod_WSGI Output Buffer | 935,978 | <p>This is a bit of a tricky question; </p>
<p>I'm working with mod_wsgi in python and want to make an output buffer that yields HTML on an ongoing basis (until the page is done loading). </p>
<p>Right now I have my script set up so that the Application() function creates a separate 'Page' thread for the page code, t... | 0 | 2009-06-01T18:05:40Z | 936,160 | <p>mod_wsgi should have built in support for Generators. So if your using a Framework like CherryPy you just need to do:</p>
<pre><code>def index():
yield "Some output"
#Do Somemore work
yield "Some more output"
</code></pre>
<p>Where each yield will return to the user a chunk of the page. </p>
<p>Here i... | 2 | 2009-06-01T18:45:04Z | [
"python",
"buffer",
"mod-wsgi",
"output-buffering"
] |
Python Mod_WSGI Output Buffer | 935,978 | <p>This is a bit of a tricky question; </p>
<p>I'm working with mod_wsgi in python and want to make an output buffer that yields HTML on an ongoing basis (until the page is done loading). </p>
<p>Right now I have my script set up so that the Application() function creates a separate 'Page' thread for the page code, t... | 0 | 2009-06-01T18:05:40Z | 937,324 | <blockquote>
<p>(It kinda sucks that mod_wsgi doesn't have a build in output buffer to handle this, I hate loading the entire page then sending output just once, it results in a much slower page load).</p>
</blockquote>
<p>Unless you're doing some kind of streaming or asynchronous application, you want to send the e... | 2 | 2009-06-01T23:41:08Z | [
"python",
"buffer",
"mod-wsgi",
"output-buffering"
] |
An algorithm to generate subsets of a set satisfying certian conditions | 936,015 | <p>Suppose I am given a sorted list of elements and I want to generate all subsets satisfying some condition, so that if a given set does not satisfy the condition, then a larger subset will also not satisfy it, and all sets of one element do satisfy it.</p>
<p>For example, given a list of all positive integers smalle... | 0 | 2009-06-01T18:13:13Z | 936,053 | <p>There are certainly ways to do it, but unless you can constrain the condition somehow, it's going to take O(2^n) steps. If you consider, for example a condition on 1â100 where all the subsets would be selected (eg, < Σ <em>i</em> for <em>i</em> in 1-<em>n</em>), then you would end up enumerating all the ... | 1 | 2009-06-01T18:20:22Z | [
"python",
"algorithm",
"subset"
] |
An algorithm to generate subsets of a set satisfying certian conditions | 936,015 | <p>Suppose I am given a sorted list of elements and I want to generate all subsets satisfying some condition, so that if a given set does not satisfy the condition, then a larger subset will also not satisfy it, and all sets of one element do satisfy it.</p>
<p>For example, given a list of all positive integers smalle... | 0 | 2009-06-01T18:13:13Z | 936,124 | <p>You can generate all the subsets using a <a href="http://en.wikipedia.org/wiki/Branch%5Fand%5Fbound" rel="nofollow">Branch-and-bound</a> technique: you can generate all the subsets in an incremental fashion (generating superset of subsets already determined), using as a prune condition "does not explore this branch ... | 4 | 2009-06-01T18:34:04Z | [
"python",
"algorithm",
"subset"
] |
An algorithm to generate subsets of a set satisfying certian conditions | 936,015 | <p>Suppose I am given a sorted list of elements and I want to generate all subsets satisfying some condition, so that if a given set does not satisfy the condition, then a larger subset will also not satisfy it, and all sets of one element do satisfy it.</p>
<p>For example, given a list of all positive integers smalle... | 0 | 2009-06-01T18:13:13Z | 936,189 | <p>You could construct your sets recursively, starting with the empty set and attempting to add more elements, giving up on a recursive line of execution if one of the subsets (and thus all of its supersets) fails to meet the condition. Here's some pseudocode, assuming a set S whose condition-satisfying subsets you wou... | 2 | 2009-06-01T18:55:35Z | [
"python",
"algorithm",
"subset"
] |
An algorithm to generate subsets of a set satisfying certian conditions | 936,015 | <p>Suppose I am given a sorted list of elements and I want to generate all subsets satisfying some condition, so that if a given set does not satisfy the condition, then a larger subset will also not satisfy it, and all sets of one element do satisfy it.</p>
<p>For example, given a list of all positive integers smalle... | 0 | 2009-06-01T18:13:13Z | 936,274 | <p>I've done something similar for a class schedule generating algorithm. Our schedule class had 2 elements - a list of courses added to the schedule, and a list of courses available to add.</p>
<p>Pseudocode:</p>
<pre><code>queue.add(new schedule(null, available_courses))
while( queue is not empty )
sched = que... | 1 | 2009-06-01T19:13:33Z | [
"python",
"algorithm",
"subset"
] |
An algorithm to generate subsets of a set satisfying certian conditions | 936,015 | <p>Suppose I am given a sorted list of elements and I want to generate all subsets satisfying some condition, so that if a given set does not satisfy the condition, then a larger subset will also not satisfy it, and all sets of one element do satisfy it.</p>
<p>For example, given a list of all positive integers smalle... | 0 | 2009-06-01T18:13:13Z | 936,335 | <p>Here's a concrete example of akappa's answer, using a recursive function to generate the subsets:</p>
<pre><code>def restofsubsets(goodsubset, remainingels, condition):
answers = []
for j in range(len(remainingels)):
nextsubset = goodsubset + remainingels[j:j+1]
if condition(nextsubset):
... | 1 | 2009-06-01T19:26:26Z | [
"python",
"algorithm",
"subset"
] |
An algorithm to generate subsets of a set satisfying certian conditions | 936,015 | <p>Suppose I am given a sorted list of elements and I want to generate all subsets satisfying some condition, so that if a given set does not satisfy the condition, then a larger subset will also not satisfy it, and all sets of one element do satisfy it.</p>
<p>For example, given a list of all positive integers smalle... | 0 | 2009-06-01T18:13:13Z | 18,223,946 | <p>I think in the worst case, you still have to generate all subsets and calculate the sum of each set to determine if it is qualify or not. Asymptotically, it is the cost of subsets generating procedure.</p>
<p>The following is the method I implemented in javascript for the same idea. </p>
<pre><code>//this is to ge... | 0 | 2013-08-14T05:37:54Z | [
"python",
"algorithm",
"subset"
] |
Is there an Oracle wrapper for Python that supports xmltype columns? | 936,381 | <p>It seems cx_Oracle doesn't.</p>
<p>Any other suggestion for handling xml with Oracle and Python is appreciated.</p>
<p>Thanks.</p>
| 5 | 2009-06-01T19:36:17Z | 936,404 | <p>(edited to remove mention of a non-Oracle Python DB-API module and add some more relevant and hopefully useful info).</p>
<p>Don't know of any alternative to <code>cx_oracle</code> (as the DCOracle2 author <a href="http://www.zope.org/Members/matt/dco2/" rel="nofollow">says</a>, "DCOracle2 is currently unmaintained... | 0 | 2009-06-01T19:41:55Z | [
"python",
"xml",
"oracle",
"xmltype"
] |
Is there an Oracle wrapper for Python that supports xmltype columns? | 936,381 | <p>It seems cx_Oracle doesn't.</p>
<p>Any other suggestion for handling xml with Oracle and Python is appreciated.</p>
<p>Thanks.</p>
| 5 | 2009-06-01T19:36:17Z | 946,854 | <p>I managed to do this with cx_Oracle.</p>
<p>I used the sys.xmltype.createxml() function in the statement that inserts the rows in a table with XMLTYPE fields; then I used prepare() and setinputsizes() to specify that the bind variables I used for XMLTYPE fields were of cx_Oracle.CLOB type.</p>
| 1 | 2009-06-03T20:00:08Z | [
"python",
"xml",
"oracle",
"xmltype"
] |
Is there an Oracle wrapper for Python that supports xmltype columns? | 936,381 | <p>It seems cx_Oracle doesn't.</p>
<p>Any other suggestion for handling xml with Oracle and Python is appreciated.</p>
<p>Thanks.</p>
| 5 | 2009-06-01T19:36:17Z | 2,858,568 | <p>I managed to get this to work by wrapping the XMLElement call in a call to <code>XMLType.GetClobVal()</code>:</p>
<p>For example:</p>
<pre><code>select xmltype.getclobval(xmlelement("rowcount", count(1)))
from...
</code></pre>
<p>No idea of the limitations yet but it got me out of trouble. Found the relelvant inf... | 1 | 2010-05-18T15:13:49Z | [
"python",
"xml",
"oracle",
"xmltype"
] |
Retrieving network mask in Python | 936,444 | <p>How would one go about retrieving a network device's netmask (In Linux preferably, but if it's cross-platform then cool)? I know how in C on Linux but I can't find a way in Python -- minus ctypes perhaps. That or parsing ifconfig. Any other way?</p>
<pre><code>ioctl(socknr, SIOCGIFNETMASK, &ifreq) // C version
... | 3 | 2009-06-01T19:50:14Z | 936,469 | <p>Did you look here?</p>
<p><a href="http://docs.python.org/library/fcntl.html" rel="nofollow">http://docs.python.org/library/fcntl.html</a></p>
<p>This works for me in python 2.5.2 on Linux. Was finishing it when Ben got ahead, but still here it goes (sad to waste the effort :-) ):</p>
<pre><code>vinko@parrot:~$ m... | 3 | 2009-06-01T19:57:33Z | [
"python"
] |
Retrieving network mask in Python | 936,444 | <p>How would one go about retrieving a network device's netmask (In Linux preferably, but if it's cross-platform then cool)? I know how in C on Linux but I can't find a way in Python -- minus ctypes perhaps. That or parsing ifconfig. Any other way?</p>
<pre><code>ioctl(socknr, SIOCGIFNETMASK, &ifreq) // C version
... | 3 | 2009-06-01T19:50:14Z | 936,536 | <p><a href="http://code.activestate.com/recipes/439094/">This</a> works for me in Python 2.2 on Linux:</p>
<pre><code>iface = "eth0"
socket.inet_ntoa(fcntl.ioctl(socket.socket(socket.AF_INET, socket.SOCK_DGRAM), 35099, struct.pack('256s', iface))[20:24])
</code></pre>
| 5 | 2009-06-01T20:13:31Z | [
"python"
] |
Retrieving network mask in Python | 936,444 | <p>How would one go about retrieving a network device's netmask (In Linux preferably, but if it's cross-platform then cool)? I know how in C on Linux but I can't find a way in Python -- minus ctypes perhaps. That or parsing ifconfig. Any other way?</p>
<pre><code>ioctl(socknr, SIOCGIFNETMASK, &ifreq) // C version
... | 3 | 2009-06-01T19:50:14Z | 937,213 | <p>In Windows this piece of code may be useful:</p>
<pre>
import os
import sys
import _winreg
def main():
adapter_list_key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
r'SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards')
adapter_count = _winreg.QueryInfoKey(adapter_list_key)[0]
for i... | 1 | 2009-06-01T22:57:53Z | [
"python"
] |
Retrieving network mask in Python | 936,444 | <p>How would one go about retrieving a network device's netmask (In Linux preferably, but if it's cross-platform then cool)? I know how in C on Linux but I can't find a way in Python -- minus ctypes perhaps. That or parsing ifconfig. Any other way?</p>
<pre><code>ioctl(socknr, SIOCGIFNETMASK, &ifreq) // C version
... | 3 | 2009-06-01T19:50:14Z | 2,649,654 | <p>You can use this library: <a href="http://github.com/rlisagor/pynetlinux" rel="nofollow">http://github.com/rlisagor/pynetlinux</a>. Note: I'm the author of the library.</p>
| 1 | 2010-04-15T23:25:03Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.