title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Way to call super(MyClass, self).__init__() without MyClass? | 2,535,037 | <p>I find this syntax astoundingly annoying. Every time I rename my class, I have to change this call for no apparent reason. Isn't there some <code>__class__</code> magic variable or something I can use at least? Interested in answers for Python 2.5, but it doesn't hurt to know if later versions fixed this.</p>
| 4 | 2010-03-28T23:35:57Z | 2,535,059 | <p>This is fixed in Python 3. <a href="http://docs.python.org/py3k/library/functions.html#super" rel="nofollow">http://docs.python.org/py3k/library/functions.html#super</a></p>
<p><a href="http://www.python.org/dev/peps/pep-3135/" rel="nofollow">http://www.python.org/dev/peps/pep-3135/</a></p>
| 4 | 2010-03-28T23:41:28Z | [
"python",
"syntax"
] |
Way to call super(MyClass, self).__init__() without MyClass? | 2,535,037 | <p>I find this syntax astoundingly annoying. Every time I rename my class, I have to change this call for no apparent reason. Isn't there some <code>__class__</code> magic variable or something I can use at least? Interested in answers for Python 2.5, but it doesn't hurt to know if later versions fixed this.</p>
| 4 | 2010-03-28T23:35:57Z | 2,535,075 | <p>If your class only inherits from <strong>one</strong> class it is safe to do just this:</p>
<pre><code>class B(A):
def __init__(self):
A.__init__(self)
</code></pre>
<p><del>But I could be mistaken.</del></p>
| 3 | 2010-03-28T23:46:29Z | [
"python",
"syntax"
] |
Way to call super(MyClass, self).__init__() without MyClass? | 2,535,037 | <p>I find this syntax astoundingly annoying. Every time I rename my class, I have to change this call for no apparent reason. Isn't there some <code>__class__</code> magic variable or something I can use at least? Interested in answers for Python 2.5, but it doesn't hurt to know if later versions fixed this.</p>
| 4 | 2010-03-28T23:35:57Z | 2,535,079 | <p><strong>EDIT:</strong> As pointed out by Alex, this causes infinite recursion when there is more than a single level of inheritance. Do not use this approach.</p>
<p>Yes, "new" style classes have a <code>__class__</code> attribute available which can be used, eg.</p>
<pre><code>class B(object):
def __init__(se... | -1 | 2010-03-28T23:49:10Z | [
"python",
"syntax"
] |
Check if remote host is up in Python | 2,535,055 | <p>How would I check if the remote host is up without having a port number? Is there any other way I could check other then using regular ping.</p>
<p>There is a possibility that the remote host might drop ping packets</p>
| 1 | 2010-03-28T23:40:56Z | 2,535,071 | <p>The best you can do is:</p>
<ul>
<li>Try and connect on a known port (eg port 80 or 443 for HTTP or HTTPS); or</li>
<li>Ping the site. See <a href="http://stackoverflow.com/questions/316866/ping-a-site-in-python">Ping a site in Python?</a></li>
</ul>
<p>Many sites block ICMP (the portocol used to ping sites) so yo... | 0 | 2010-03-28T23:45:59Z | [
"python",
"network-programming",
"network-protocols"
] |
Check if remote host is up in Python | 2,535,055 | <p>How would I check if the remote host is up without having a port number? Is there any other way I could check other then using regular ping.</p>
<p>There is a possibility that the remote host might drop ping packets</p>
| 1 | 2010-03-28T23:40:56Z | 2,535,076 | <p>Many firewalls are configured to drop ping packets without responding. In addition, some network adapters will respond to ICMP ping requests without input from the operating system network stack, which means the operating system might be down, but the host still responds to pings (usually you'll notice if you reboot... | 0 | 2010-03-28T23:46:30Z | [
"python",
"network-programming",
"network-protocols"
] |
Check if remote host is up in Python | 2,535,055 | <p>How would I check if the remote host is up without having a port number? Is there any other way I could check other then using regular ping.</p>
<p>There is a possibility that the remote host might drop ping packets</p>
| 1 | 2010-03-28T23:40:56Z | 2,535,139 | <p>A protocol-level PING is best, i.e., connecting to the server and interacting with it in a way that doesn't do real work. That's because it is the only real way to be sure that the <em>service</em> is up. An ICMP ECHO (a.k.a. ping) would only tell you that the other end's network interface is up, and even then might... | 1 | 2010-03-29T00:12:44Z | [
"python",
"network-programming",
"network-protocols"
] |
Check if remote host is up in Python | 2,535,055 | <p>How would I check if the remote host is up without having a port number? Is there any other way I could check other then using regular ping.</p>
<p>There is a possibility that the remote host might drop ping packets</p>
| 1 | 2010-03-28T23:40:56Z | 17,115,260 | <p>What about trying something that requires a RPC like a 'tasklist' command in conjunction with a ping?</p>
| 0 | 2013-06-14T18:43:52Z | [
"python",
"network-programming",
"network-protocols"
] |
Check if remote host is up in Python | 2,535,055 | <p>How would I check if the remote host is up without having a port number? Is there any other way I could check other then using regular ping.</p>
<p>There is a possibility that the remote host might drop ping packets</p>
| 1 | 2010-03-28T23:40:56Z | 30,358,778 | <p>I would use a port scanner. Original question states that you don't want to use a port. Then you need to specify which Protocol (Yes, this need a port) you want to monitor (HTTP, VNC, SSH, etc). In case you want to monitor via ICMP you can use subprocess and control ping parameters, number of pings, timeout, size, e... | 0 | 2015-05-20T19:31:17Z | [
"python",
"network-programming",
"network-protocols"
] |
How to load google map geo-location not using kml | 2,535,379 | <p>How to load google map geo-location not using kml. Like this site: <a href="http://www.housingmaps.com/" rel="nofollow">http://www.housingmaps.com/</a></p>
| 1 | 2010-03-29T01:43:34Z | 2,535,392 | <p><a href="http://code.google.com/apis/maps/documentation/examples/marker-simple.html" rel="nofollow">This example</a> from Google is what you're looking for.</p>
| 1 | 2010-03-29T01:50:44Z | [
"javascript",
"python",
"django",
"google-maps",
"kml"
] |
Potential annoyances of tab delimited Python source? | 2,535,397 | <p><strong>Edit</strong>: This question has already been asked and answered, and I apparently am not good at using the search wizard. See <a href="http://stackoverflow.com/questions/120926/why-does-python-pep-8-strongly-recommend-spaces-over-tabs-for-indentation">http://stackoverflow.com/questions/120926/why-does-pyth... | 1 | 2010-03-29T01:52:43Z | 2,535,407 | <p>Most Python programmers will have their editors configured to automatically use four spaces for all <code>.py</code> files⦠Which could, at least initially, cause some minor headaches if they try to edit your source.</p>
<p>But apart from that (given that <a href="http://www.python.org/dev/peps/pep-0666/" rel="no... | 1 | 2010-03-29T01:57:42Z | [
"python",
"ide",
"tabs"
] |
Potential annoyances of tab delimited Python source? | 2,535,397 | <p><strong>Edit</strong>: This question has already been asked and answered, and I apparently am not good at using the search wizard. See <a href="http://stackoverflow.com/questions/120926/why-does-python-pep-8-strongly-recommend-spaces-over-tabs-for-indentation">http://stackoverflow.com/questions/120926/why-does-pyth... | 1 | 2010-03-29T01:52:43Z | 2,535,422 | <p>If all the world used tab-indented Python source, then everyone would be happy.
If all the world used 4-space indented Python source, then everyone would be happy.</p>
<p>Unhappiness arises when one tries to comingle tab-indented code with 4-space indented code.</p>
<p>The majority of Python code seems to be of th... | 1 | 2010-03-29T02:03:43Z | [
"python",
"ide",
"tabs"
] |
Catching a python app before it exits | 2,535,403 | <p>I have a python app which is supposed to be very long-lived, but sometimes the process just disappears and I don't know why. Nothing gets logged when this happens, so I'm at a bit of a loss. </p>
<p>Is there some way in code I can hook in to an exit event, or some other way to get some of my code to run just befo... | 7 | 2010-03-29T01:54:55Z | 2,535,408 | <p>You might try running your application directly from a console (cmd on windows, sh/bash/etc on unix), so you can see any stack trace, etc printed to the console when the process dies.</p>
| 3 | 2010-03-29T01:58:11Z | [
"python",
"crash"
] |
Catching a python app before it exits | 2,535,403 | <p>I have a python app which is supposed to be very long-lived, but sometimes the process just disappears and I don't know why. Nothing gets logged when this happens, so I'm at a bit of a loss. </p>
<p>Is there some way in code I can hook in to an exit event, or some other way to get some of my code to run just befo... | 7 | 2010-03-29T01:54:55Z | 2,535,418 | <p><a href="http://docs.python.org/library/atexit.html"><code>atexit</code></a> is pronounced "at exit". The first times I read that function name, I read it as "a texit", which doesn't make <em>nearly</em> as much sense.</p>
| 8 | 2010-03-29T02:01:40Z | [
"python",
"crash"
] |
Catching a python app before it exits | 2,535,403 | <p>I have a python app which is supposed to be very long-lived, but sometimes the process just disappears and I don't know why. Nothing gets logged when this happens, so I'm at a bit of a loss. </p>
<p>Is there some way in code I can hook in to an exit event, or some other way to get some of my code to run just befo... | 7 | 2010-03-29T01:54:55Z | 2,535,447 | <p>I'm not sure if you are able to modify the source code, but if so you might want to try this:</p>
<pre><code>def debugexcept(type, value, tb):
if hasattr(sys, 'ps1') or not (sys.stderr.isatty() and sys.stdin.isatty()) or type == SyntaxError:
sys.__excepthook__(type, value, tb)
else:
import t... | 3 | 2010-03-29T02:12:18Z | [
"python",
"crash"
] |
What is a really simple explanation of unit testing? | 2,535,431 | <p>I've never done any unit testing before, and would like to learn what it is and how it can be useful in my Python code. </p>
<p>I've read through a few Python unit testing tutorials online but they're all so complicated and assume an extended programming background. I'm using Python with Pylons to create a simple... | 2 | 2010-03-29T02:07:47Z | 2,535,442 | <p>Consider this.</p>
<p>Here's a class we've written.</p>
<pre><code>class Something( object ):
def __init__( self, a, b ):
self.a= a
self.b= b
def sum( self ):
return self.a+self.b+self.a
</code></pre>
<p>That's a test for that class.</p>
<pre><code>import unittest
class TestSometh... | 5 | 2010-03-29T02:11:10Z | [
"python",
"unit-testing",
"pylons"
] |
passing an argument to a custom save() method | 2,535,435 | <p>How do I pass an argument to my custom save method, preserving proper <code>*args</code>, <code>**kwargs</code> for passing to te super method? I was trying something like:</p>
<pre><code>form.save(my_value)
</code></pre>
<p>and</p>
<pre><code>def save(self, my_value=None, *args, **kwargs):
super(MyModel, se... | 4 | 2010-03-29T02:09:29Z | 2,535,481 | <p>Keyword arguments must follow the positional arguments. Try this instead:</p>
<pre><code>def save(self, my_value, *args, **kwargs):
....
</code></pre>
<p>or:</p>
<pre><code>def save(self, *args, **kwargs):
my_value = kwargs.pop('my_value', None)
</code></pre>
| 10 | 2010-03-29T02:26:18Z | [
"python",
"django",
"django-models"
] |
passing an argument to a custom save() method | 2,535,435 | <p>How do I pass an argument to my custom save method, preserving proper <code>*args</code>, <code>**kwargs</code> for passing to te super method? I was trying something like:</p>
<pre><code>form.save(my_value)
</code></pre>
<p>and</p>
<pre><code>def save(self, my_value=None, *args, **kwargs):
super(MyModel, se... | 4 | 2010-03-29T02:09:29Z | 12,176,448 | <p>You can try the following.</p>
<p>Override the save method as:</p>
<pre><code>def save(self, my_val, *args, **kwargs):
print my_val
# do_something here
return super(MyModel, self).save(*args, **kwargs)
</code></pre>
<p>On calling the save method as:</p>
<pre><code>MyModel.save(my_val="fooooo")
</code... | 1 | 2012-08-29T11:01:36Z | [
"python",
"django",
"django-models"
] |
Looking for a smarter way to convert a Python list to a GList? | 2,535,448 | <p>I'm really new to C -> Python interaction and am currently writing a small app in C which will read a file (using Python to parse it) and then using the parsed information to execute small Python snippets. At the moment I'm feeling very much like I'm reinventing wheels, for example this function:</p>
<pre><code>typ... | 0 | 2010-03-29T02:12:37Z | 2,535,484 | <p>I recommend <a href="http://docs.python.org/c-api/sequence.html#PySequence_Fast" rel="nofollow">PySequence_Fast</a> and friends:</p>
<pre><code>else
{
PyObject *pSeqfast = PySequence_Fast(pylist, "must be a sequence");
Py_ssize_t n = PySequence_Fast_GET_SIZE(pSeqFast);
for(Py_ssize_t i = 0; i < n ; ... | 1 | 2010-03-29T02:28:34Z | [
"python",
"c",
"glib",
"python-embedding"
] |
How to change the value of None in Python? | 2,535,477 | <p>I'm currently reading chapter 5.8 of Dive Into Python and Mark Pilgrim says:</p>
<blockquote>
<p>There are no constants in Python. Everything can be changed if you try hard enough. This fits with one of the core principles of Python: bad behavior should be discouraged but not banned. If you really want to change ... | 8 | 2010-03-29T02:25:20Z | 2,535,491 | <p>You first have to install an <em>old</em> version of Python (I think it needs to be 2.2 or older). In 2.4 and newer for certain (and I believe in 2.3) the assignment in question is a syntax error. Mark's excellent book is, alas, a bit dated by now.</p>
| 13 | 2010-03-29T02:30:21Z | [
"python",
"syntax"
] |
Using numpy.apply | 2,535,556 | <p>What's wrong with this snippet of code?</p>
<pre><code>import numpy as np
from scipy import stats
d = np.arange(10.0)
cutoffs = [stats.scoreatpercentile(d, pct) for pct in range(0, 100, 20)]
f = lambda x: np.sum(x > cutoffs)
fv = np.vectorize(f)
# why don't these two lines output the same values?
[f(x) for x i... | 1 | 2010-03-29T02:55:15Z | 2,535,654 | <p><code>cutoffs</code> is a list. The numbers you extract from <code>d</code> are all turned into <code>float</code> and applied using <code>numpy.vectorize</code>. (It's actually rather oddâit looks like first it tries numpy floats that work like you want then it tries normal Python floats.) By a rather odd, stupid... | 1 | 2010-03-29T03:27:45Z | [
"python",
"numpy",
"scipy"
] |
Tips for debugging list comprehensions? | 2,535,683 | <p>Python list comprehensions are nice, but near impossible to debug. You guys have any good tips / tools for debugging them?</p>
| 5 | 2010-03-29T03:38:37Z | 2,535,689 | <p>If it's complicated enough that it's not obvious at first glance, unpack it into multiple steps and/or for loops. It's clearly too complicated, and making it more explicit is the easiest way to go about debugging it. Added bonus: you can now step through with the debugger or add print statements!</p>
| 3 | 2010-03-29T03:41:05Z | [
"python",
"debugging",
"list",
"list-comprehension"
] |
Tips for debugging list comprehensions? | 2,535,683 | <p>Python list comprehensions are nice, but near impossible to debug. You guys have any good tips / tools for debugging them?</p>
| 5 | 2010-03-29T03:38:37Z | 2,535,701 | <p>tip: Use list comprehension for simple tasks (1 or 2 levels). Otherwise, making it explicit is better for readability.</p>
| 2 | 2010-03-29T03:44:09Z | [
"python",
"debugging",
"list",
"list-comprehension"
] |
Tips for debugging list comprehensions? | 2,535,683 | <p>Python list comprehensions are nice, but near impossible to debug. You guys have any good tips / tools for debugging them?</p>
| 5 | 2010-03-29T03:38:37Z | 2,535,711 | <p>In Haskell I using something similar to:</p>
<pre><code>def trcPV(prompt, value):
print ("%s%s" % (prompt, str(value)))
return value
xs = trcPV("xs=", [x for x in range(0,100) if trcPV("check=",(trcPV("x=",x) % 15) in [0,3,5])])
</code></pre>
| 0 | 2010-03-29T03:48:47Z | [
"python",
"debugging",
"list",
"list-comprehension"
] |
Tips for debugging list comprehensions? | 2,535,683 | <p>Python list comprehensions are nice, but near impossible to debug. You guys have any good tips / tools for debugging them?</p>
| 5 | 2010-03-29T03:38:37Z | 2,535,774 | <p>Use a debugger like <code>pdb</code> to walk through or break the list comprehension into a full for loop.</p>
| 0 | 2010-03-29T04:22:54Z | [
"python",
"debugging",
"list",
"list-comprehension"
] |
Tips for debugging list comprehensions? | 2,535,683 | <p>Python list comprehensions are nice, but near impossible to debug. You guys have any good tips / tools for debugging them?</p>
| 5 | 2010-03-29T03:38:37Z | 2,535,879 | <p>Haskell list comprehensions at least can be (and that is what compilers do) rewritten in terms of map, concat and filter.</p>
<p>So this Haskell example:</p>
<pre><code>[ x*x | x<-[1..25], even x]
</code></pre>
<p>Works out as:</p>
<pre><code>map (\x-> x*x) (filter (even) [1..25])
</code></pre>
<p>I expec... | 1 | 2010-03-29T05:06:27Z | [
"python",
"debugging",
"list",
"list-comprehension"
] |
Tips for debugging list comprehensions? | 2,535,683 | <p>Python list comprehensions are nice, but near impossible to debug. You guys have any good tips / tools for debugging them?</p>
| 5 | 2010-03-29T03:38:37Z | 39,350,403 | <p>It depends on the list comprehension. You can move a part of the code to another function. This should be a clean solution which is more easy to debug.</p>
<p>Example:</p>
<pre><code>[sum([j*j for j in range(0, i)]) for i in [2, 5, 10]]
</code></pre>
<p>Can be devided into </p>
<pre><code>[f(i) for i in [2, 5, 1... | 0 | 2016-09-06T13:36:00Z | [
"python",
"debugging",
"list",
"list-comprehension"
] |
Python try...except comma vs 'as' in except | 2,535,760 | <p>What is the difference between ',' and 'as' in except statements, eg:</p>
<pre><code>try:
pass
except Exception, exception:
pass
</code></pre>
<p>and:</p>
<pre><code>try:
pass
except Exception as exception:
pass
</code></pre>
<p>Is the second syntax legal in 2.6? It works in CPython 2.6 on Windo... | 170 | 2010-03-29T04:16:56Z | 2,535,764 | <p>the "as" syntax is the preferred one going forward, however if your code needs to work with older Python versions (2.6 is the first to support the new one) then you'll need to use the comma syntax.</p>
| 17 | 2010-03-29T04:18:29Z | [
"python",
"python-2.6"
] |
Python try...except comma vs 'as' in except | 2,535,760 | <p>What is the difference between ',' and 'as' in except statements, eg:</p>
<pre><code>try:
pass
except Exception, exception:
pass
</code></pre>
<p>and:</p>
<pre><code>try:
pass
except Exception as exception:
pass
</code></pre>
<p>Is the second syntax legal in 2.6? It works in CPython 2.6 on Windo... | 170 | 2010-03-29T04:16:56Z | 2,535,770 | <p>The definitive document is <a href="http://www.python.org/dev/peps/pep-3110/">PEP-3110: Catching Exceptions</a></p>
<p>Summary:</p>
<ul>
<li>In Python 3.x, using <code>as</code> is <em>required</em>.</li>
<li>In Python 2.6+, use the <code>as</code> syntax, since it is far less ambiguous and forward compatible with... | 189 | 2010-03-29T04:19:44Z | [
"python",
"python-2.6"
] |
Python try...except comma vs 'as' in except | 2,535,760 | <p>What is the difference between ',' and 'as' in except statements, eg:</p>
<pre><code>try:
pass
except Exception, exception:
pass
</code></pre>
<p>and:</p>
<pre><code>try:
pass
except Exception as exception:
pass
</code></pre>
<p>Is the second syntax legal in 2.6? It works in CPython 2.6 on Windo... | 170 | 2010-03-29T04:16:56Z | 2,535,882 | <p>Yes it's legal. I'm running Python 2.6</p>
<pre><code>try:
[] + 3
except Exception as x:
print "woo hoo"
>>>
woo hoo
</code></pre>
<p><strong>Update</strong>: There is another reason to use the <code>as</code> syntax. Using <code>,</code> makes things a lot more ambiguous, as others have pointed... | 30 | 2010-03-29T05:07:56Z | [
"python",
"python-2.6"
] |
Python try...except comma vs 'as' in except | 2,535,760 | <p>What is the difference between ',' and 'as' in except statements, eg:</p>
<pre><code>try:
pass
except Exception, exception:
pass
</code></pre>
<p>and:</p>
<pre><code>try:
pass
except Exception as exception:
pass
</code></pre>
<p>Is the second syntax legal in 2.6? It works in CPython 2.6 on Windo... | 170 | 2010-03-29T04:16:56Z | 35,383,512 | <p>If you want to support all python versions you can use the sys.exc_info() function like this:</p>
<pre><code>try:
a = 1/'0'
except (ZeroDivisionError, TypeError):
e = sys.exc_info()[1]
print(e.args[0])
</code></pre>
<p>(source:<a href="http://python3porting.com/noconv.html" rel="nofollow">http://python... | 4 | 2016-02-13T18:13:13Z | [
"python",
"python-2.6"
] |
Copy **kwargs to self? | 2,535,917 | <p>Given</p>
<pre><code>class ValidationRule:
def __init__(self, **kwargs):
# code here
</code></pre>
<p>Is there a way that I can define <code>__init__</code> such that if I were to initialize the class with something like <code>ValidationRule(other='email')</code> then <code>self.other</code> would be "... | 12 | 2010-03-29T05:21:06Z | 2,535,926 | <p>You could do something like this:</p>
<pre><code>class ValidationRule:
def __init__(self, **kwargs):
for (k, v) in kwargs.items():
setattr(self, k, v)
</code></pre>
| 11 | 2010-03-29T05:25:08Z | [
"python",
"syntax"
] |
Copy **kwargs to self? | 2,535,917 | <p>Given</p>
<pre><code>class ValidationRule:
def __init__(self, **kwargs):
# code here
</code></pre>
<p>Is there a way that I can define <code>__init__</code> such that if I were to initialize the class with something like <code>ValidationRule(other='email')</code> then <code>self.other</code> would be "... | 12 | 2010-03-29T05:21:06Z | 2,535,952 | <p>I think somewhere on the stackoverflow I've seen such solution
Anyway it can look like:</p>
<pre><code>class ValidationRule:
__allowed = ("other", "same", "different")
def __init__(self, **kwargs):
for k, v in kwargs.iteritems():
assert( k in self.__class__.__allowed )
setatt... | 15 | 2010-03-29T05:35:55Z | [
"python",
"syntax"
] |
Copy **kwargs to self? | 2,535,917 | <p>Given</p>
<pre><code>class ValidationRule:
def __init__(self, **kwargs):
# code here
</code></pre>
<p>Is there a way that I can define <code>__init__</code> such that if I were to initialize the class with something like <code>ValidationRule(other='email')</code> then <code>self.other</code> would be "... | 12 | 2010-03-29T05:21:06Z | 2,535,961 | <pre><code>class ValidationRule:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
</code></pre>
| 3 | 2010-03-29T05:39:08Z | [
"python",
"syntax"
] |
Copy **kwargs to self? | 2,535,917 | <p>Given</p>
<pre><code>class ValidationRule:
def __init__(self, **kwargs):
# code here
</code></pre>
<p>Is there a way that I can define <code>__init__</code> such that if I were to initialize the class with something like <code>ValidationRule(other='email')</code> then <code>self.other</code> would be "... | 12 | 2010-03-29T05:21:06Z | 2,535,964 | <p>This may not be the cleanest way, but it works:</p>
<pre><code>class ValidationRule:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
</code></pre>
<p>I think I prefer <a href="http://stackoverflow.com/questions/2535917/copy-kwargs-to-self/2535952#2535952">ony's solution</a> because it rest... | 7 | 2010-03-29T05:39:49Z | [
"python",
"syntax"
] |
Copy **kwargs to self? | 2,535,917 | <p>Given</p>
<pre><code>class ValidationRule:
def __init__(self, **kwargs):
# code here
</code></pre>
<p>Is there a way that I can define <code>__init__</code> such that if I were to initialize the class with something like <code>ValidationRule(other='email')</code> then <code>self.other</code> would be "... | 12 | 2010-03-29T05:21:06Z | 2,535,966 | <p>You can set your <code>kwargs</code> arguments by updating <code>__dict__</code> attribute of the instance.</p>
<pre><code>class ValidationRule:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
</code></pre>
| 1 | 2010-03-29T05:40:21Z | [
"python",
"syntax"
] |
Copy **kwargs to self? | 2,535,917 | <p>Given</p>
<pre><code>class ValidationRule:
def __init__(self, **kwargs):
# code here
</code></pre>
<p>Is there a way that I can define <code>__init__</code> such that if I were to initialize the class with something like <code>ValidationRule(other='email')</code> then <code>self.other</code> would be "... | 12 | 2010-03-29T05:21:06Z | 8,902,159 | <p>I found the above answers helpful and then refined:</p>
<pre><code>class MyObj(object):
def __init__(self, key1=1, key2=2, key3=3):
for (k, v) in locals().iteritems():
if k != 'self':
setattr(self, k, v)
</code></pre>
<p>Test:</p>
<pre><code>>>> myobj = MyObj(key1=... | 0 | 2012-01-17T21:45:43Z | [
"python",
"syntax"
] |
Copy **kwargs to self? | 2,535,917 | <p>Given</p>
<pre><code>class ValidationRule:
def __init__(self, **kwargs):
# code here
</code></pre>
<p>Is there a way that I can define <code>__init__</code> such that if I were to initialize the class with something like <code>ValidationRule(other='email')</code> then <code>self.other</code> would be "... | 12 | 2010-03-29T05:21:06Z | 33,390,881 | <p>This could be considered nicer than updating <code>__dict__</code>:</p>
<pre><code>class C:
def __init__(self, **kwargs):
vars(self).update(kwargs)
>>> c = C(a='a', b='b')
>>> c.a # returns 'a'
>>> c.b # returns 'b'
</code></pre>
| 1 | 2015-10-28T12:18:24Z | [
"python",
"syntax"
] |
Simple way to create possible case | 2,535,924 | <p>I have lists of data such as</p>
<pre><code>a = [1,2,3,4]
b = ["a","b","c","d","e"]
c = ["001","002","003"]
</code></pre>
<p>And I want to create new another list that was mixed from all possible case of a,b,c like this</p>
<pre><code>d = ["1a001","1a002","1a003",...,"4e003"]
</code></pre>
<p>Is there any module... | 2 | 2010-03-29T05:24:04Z | 2,535,934 | <pre><code>[''.join(str(y) for y in x) for x in itertools.product(a, b, c)]
</code></pre>
| 11 | 2010-03-29T05:28:11Z | [
"python",
"methods",
"module",
"case"
] |
Simple way to create possible case | 2,535,924 | <p>I have lists of data such as</p>
<pre><code>a = [1,2,3,4]
b = ["a","b","c","d","e"]
c = ["001","002","003"]
</code></pre>
<p>And I want to create new another list that was mixed from all possible case of a,b,c like this</p>
<pre><code>d = ["1a001","1a002","1a003",...,"4e003"]
</code></pre>
<p>Is there any module... | 2 | 2010-03-29T05:24:04Z | 2,536,158 | <p>This is a little simpler to do if you convert <code>a</code> to be a list of <code>str</code> too.
and saves needlessly calling <code>str()</code> on each element of b and c</p>
<pre><code>>>> from itertools import product
>>> a = [1,2,3,4]
>>> b = ["a","b","c","d","e"]
>>> c = [... | 1 | 2010-03-29T06:38:21Z | [
"python",
"methods",
"module",
"case"
] |
Simple way to create possible case | 2,535,924 | <p>I have lists of data such as</p>
<pre><code>a = [1,2,3,4]
b = ["a","b","c","d","e"]
c = ["001","002","003"]
</code></pre>
<p>And I want to create new another list that was mixed from all possible case of a,b,c like this</p>
<pre><code>d = ["1a001","1a002","1a003",...,"4e003"]
</code></pre>
<p>Is there any module... | 2 | 2010-03-29T05:24:04Z | 2,536,231 | <p>How about this? Using <code>map</code></p>
<pre><code>print [''.join(map(str,y)) for y in itertools.product(a,b,c)]
</code></pre>
| 1 | 2010-03-29T06:56:26Z | [
"python",
"methods",
"module",
"case"
] |
Simple way to create possible case | 2,535,924 | <p>I have lists of data such as</p>
<pre><code>a = [1,2,3,4]
b = ["a","b","c","d","e"]
c = ["001","002","003"]
</code></pre>
<p>And I want to create new another list that was mixed from all possible case of a,b,c like this</p>
<pre><code>d = ["1a001","1a002","1a003",...,"4e003"]
</code></pre>
<p>Is there any module... | 2 | 2010-03-29T05:24:04Z | 2,536,433 | <pre><code>map(''.join, itertools.product(map(str, a), b, c))
</code></pre>
| 1 | 2010-03-29T07:47:17Z | [
"python",
"methods",
"module",
"case"
] |
Convert args to flat list? | 2,536,197 | <p>I know this is very <em>similar</em> to a few other questions, but I can't quite get this function to work correctly.</p>
<pre><code>def flatten(*args):
return list(item for iterable in args for item in iterable)
</code></pre>
<p>The output I'm looking for is:</p>
<pre><code>flatten(1) -> [1]
flatten(1,[2]... | 2 | 2010-03-29T06:48:40Z | 2,536,233 | <p>For a quick solution, just take your second function and make it recursive.</p>
<pre><code>def flatten(*args):
output = []
for arg in args:
if hasattr(arg, '__iter__'):
output.extend(flatten(*arg))
else:
output.append(arg)
return output
</code></pre>
| 6 | 2010-03-29T06:56:38Z | [
"python",
"list"
] |
Convert args to flat list? | 2,536,197 | <p>I know this is very <em>similar</em> to a few other questions, but I can't quite get this function to work correctly.</p>
<pre><code>def flatten(*args):
return list(item for iterable in args for item in iterable)
</code></pre>
<p>The output I'm looking for is:</p>
<pre><code>flatten(1) -> [1]
flatten(1,[2]... | 2 | 2010-03-29T06:48:40Z | 2,536,237 | <p>If you want to flatten arbitrarily nested lists you need a recursive function:</p>
<pre><code>def flatten(ls):
if isinstance(ls, list):
return [fa for a in ls for fa in flatten(a)]
else:
return [ls]
</code></pre>
<p>(If you expect to flatten big structures this could be made more efficient by using g... | 4 | 2010-03-29T06:57:11Z | [
"python",
"list"
] |
Convert args to flat list? | 2,536,197 | <p>I know this is very <em>similar</em> to a few other questions, but I can't quite get this function to work correctly.</p>
<pre><code>def flatten(*args):
return list(item for iterable in args for item in iterable)
</code></pre>
<p>The output I'm looking for is:</p>
<pre><code>flatten(1) -> [1]
flatten(1,[2]... | 2 | 2010-03-29T06:48:40Z | 2,542,272 | <p>Solved it...</p>
<pre><code>def flatlist(*args):
lst = []
for a in args:
if hasattr(a, '__iter__'): lst.extend(flatlist(*a))
else: lst.append(a)
return lst
</code></pre>
| -1 | 2010-03-30T01:19:20Z | [
"python",
"list"
] |
Convert args to flat list? | 2,536,197 | <p>I know this is very <em>similar</em> to a few other questions, but I can't quite get this function to work correctly.</p>
<pre><code>def flatten(*args):
return list(item for iterable in args for item in iterable)
</code></pre>
<p>The output I'm looking for is:</p>
<pre><code>flatten(1) -> [1]
flatten(1,[2]... | 2 | 2010-03-29T06:48:40Z | 6,936,753 | <p>Checking <strong>__<em>iter</em>__</strong> presence can be quite strange when flattening dictionary:</p>
<pre class="lang-py prettyprint-override"><code>>>> def flatten(*args):
... output = []
... for arg in args:
... if hasattr(arg, '__iter__'):
... output.extend(flatten(*arg)... | 1 | 2011-08-04T05:51:33Z | [
"python",
"list"
] |
Where do you use generators feature in your python code? | 2,536,241 | <p>I have studied generators feature and i think i got it but i would like to understand where i could apply it in my code.</p>
<p>I have in mind the following example i read in "Python essential reference" book:</p>
<pre><code># tail -f
def tail(f):
f.seek(0,2)
while True:
line = f.readline()
if not lin... | 5 | 2010-03-29T06:58:18Z | 2,536,268 | <p>Whenever your code would either generate an <strong>unlimited number of values</strong> or more generally if <strong>too much memory</strong> would be consumed by generating the whole list at first.</p>
<p>Or if it is likely that you <strong>don't</strong> iterate over the <strong>whole generated list</strong> (and... | 4 | 2010-03-29T07:05:28Z | [
"python",
"generator"
] |
Where do you use generators feature in your python code? | 2,536,241 | <p>I have studied generators feature and i think i got it but i would like to understand where i could apply it in my code.</p>
<p>I have in mind the following example i read in "Python essential reference" book:</p>
<pre><code># tail -f
def tail(f):
f.seek(0,2)
while True:
line = f.readline()
if not lin... | 5 | 2010-03-29T06:58:18Z | 2,536,296 | <p>I use them a lot when I implement scanners (tokenizers) or when I iterate over data containers.</p>
<p>Edit: here is a demo tokenizer I used for a C++ syntax highlight program:</p>
<pre><code>whitespace = ' \t\r\n'
operators = '~!%^&*()-+=[]{};:\'"/?.,<>\\|'
def scan(s):
"returns a token and a state... | 6 | 2010-03-29T07:12:34Z | [
"python",
"generator"
] |
Where do you use generators feature in your python code? | 2,536,241 | <p>I have studied generators feature and i think i got it but i would like to understand where i could apply it in my code.</p>
<p>I have in mind the following example i read in "Python essential reference" book:</p>
<pre><code># tail -f
def tail(f):
f.seek(0,2)
while True:
line = f.readline()
if not lin... | 5 | 2010-03-29T06:58:18Z | 2,536,641 | <p>In general, to separate data aquisition (which might be complicated) from consumption. In particular:</p>
<ul>
<li>to concatenate results of several b-tree queries - the db part generates and executes the queries <code>yield</code>-ing records from each one, the consumer only sees single data items arriving.</li>
<... | 1 | 2010-03-29T08:35:09Z | [
"python",
"generator"
] |
Where do you use generators feature in your python code? | 2,536,241 | <p>I have studied generators feature and i think i got it but i would like to understand where i could apply it in my code.</p>
<p>I have in mind the following example i read in "Python essential reference" book:</p>
<pre><code># tail -f
def tail(f):
f.seek(0,2)
while True:
line = f.readline()
if not lin... | 5 | 2010-03-29T06:58:18Z | 2,537,165 | <p>In all cases where I have algorithms that read anything, I use generators exclusively. </p>
<p>Why? </p>
<p>Layering in filtering, mapping and reduction rules is so much easier in a context of multiple generators.</p>
<p>Example:</p>
<pre><code>def discard_blank( source ):
for line in source:
if le... | 2 | 2010-03-29T10:21:25Z | [
"python",
"generator"
] |
XML RPC client for C# over secured socket (https) | 2,536,271 | <p>I have a secured (https) XML-RPC server written in python, and I have tested it with a python based client. but I need a C# based client for it, I have given a try to <a href="http://www.xml-rpc.net" rel="nofollow">xml-rpc.net</a></p>
<p>but it is not working with https? can any one please help me out? or I will ha... | 2 | 2010-03-29T07:06:16Z | 2,536,330 | <p>Your https server probably has a self-signed or other invalid certificate. Get a valid certificate or suppress https certificate validation with</p>
<pre><code>ServicePointManager.ServerCertificateValidationCallback = (a, b, c, e) => true ;
</code></pre>
| 2 | 2010-03-29T07:20:35Z | [
"c#",
"python",
"https",
"xml-rpc"
] |
Django Formset management-form validation error | 2,536,285 | <p>I have a form and a formset on my template. The problem is that the formset is throwing validation error claiming that the management form is "missing or has been tampered with".</p>
<p>Here is my view</p>
<pre><code>@login_required
def home(request):
user = UserProfile.objects.get(pk=request.session['_auth_u... | 6 | 2010-03-29T07:10:58Z | 2,538,377 | <p>I have figured this out after running into the same error. In situations where you are using a form and a formset in the same view and template, the form should be processed before the formset to avoid raising a formset validation error. </p>
<p>of importance Also, <code>if request.method == 'POST':</code> SHOULD O... | 1 | 2010-03-29T13:56:51Z | [
"python",
"django",
"django-templates",
"django-forms"
] |
Django Formset management-form validation error | 2,536,285 | <p>I have a form and a formset on my template. The problem is that the formset is throwing validation error claiming that the management form is "missing or has been tampered with".</p>
<p>Here is my view</p>
<pre><code>@login_required
def home(request):
user = UserProfile.objects.get(pk=request.session['_auth_u... | 6 | 2010-03-29T07:10:58Z | 3,988,490 | <p>To avoid this error just wrap your formset POST bounding in a try/except block like so.</p>
<pre><code>from django.core.exceptions import ValidationError # add this to your imports
if request.method == 'POST':
try:
delblogformset = delblog(request.POST)
except ValidationError:
delblogformset = No... | 5 | 2010-10-21T14:24:31Z | [
"python",
"django",
"django-templates",
"django-forms"
] |
decorators in the python standard lib (@deprecated specifically) | 2,536,307 | <p>I need to mark routines as deprecated, but apparently there's no standard library decorator for deprecation. I am aware of recipes for it and the warnings module, but my question is: why is there no standard library decorator for this (common) task ? </p>
<p>Additional question: are there standard decorators in the... | 27 | 2010-03-29T07:14:57Z | 2,536,365 | <p><a href="http://docs.python.org/library/functions.html#classmethod"><code>classmethod()</code></a>, <a href="http://docs.python.org/library/functions.html#staticmethod"><code>staticmethod()</code></a>, and the various <a href="http://docs.python.org/library/functions.html#property"><code>property</code></a> decorato... | 7 | 2010-03-29T07:31:13Z | [
"python",
"decorator"
] |
decorators in the python standard lib (@deprecated specifically) | 2,536,307 | <p>I need to mark routines as deprecated, but apparently there's no standard library decorator for deprecation. I am aware of recipes for it and the warnings module, but my question is: why is there no standard library decorator for this (common) task ? </p>
<p>Additional question: are there standard decorators in the... | 27 | 2010-03-29T07:14:57Z | 2,536,397 | <p>I guess the reason is that Python code can't be processed statically (as it done for C++ compilers), you can't get warning about using some things before actually using it. I don't think that it's a good idea to spam user of your script with a bunch of messages "Warning: this developer of this script is using deprec... | 3 | 2010-03-29T07:36:28Z | [
"python",
"decorator"
] |
decorators in the python standard lib (@deprecated specifically) | 2,536,307 | <p>I need to mark routines as deprecated, but apparently there's no standard library decorator for deprecation. I am aware of recipes for it and the warnings module, but my question is: why is there no standard library decorator for this (common) task ? </p>
<p>Additional question: are there standard decorators in the... | 27 | 2010-03-29T07:14:57Z | 21,908,140 | <p>These are not official, but might work for you:</p>
<ul>
<li><a href="https://wiki.python.org/moin/PythonDecoratorLibrary#Generating_Deprecation_Warnings">Generating Deprecation Warnings</a></li>
<li><a href="https://wiki.python.org/moin/PythonDecoratorLibrary#Smart_deprecation_warnings_.28with_valid_filenames.2C_l... | 6 | 2014-02-20T12:41:58Z | [
"python",
"decorator"
] |
decorators in the python standard lib (@deprecated specifically) | 2,536,307 | <p>I need to mark routines as deprecated, but apparently there's no standard library decorator for deprecation. I am aware of recipes for it and the warnings module, but my question is: why is there no standard library decorator for this (common) task ? </p>
<p>Additional question: are there standard decorators in the... | 27 | 2010-03-29T07:14:57Z | 30,253,848 | <p>Here's some snippet, modified from those cited by Leandro:</p>
<pre><code>import warnings
import functools
def deprecated(func):
"""This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emmitted
when the function is used."""
@functools.wraps(func)... | 8 | 2015-05-15T07:24:28Z | [
"python",
"decorator"
] |
Python's equivalence? | 2,536,318 | <p>Is there anyway to transform the following code in Java to Python's equivalence?</p>
<pre><code>public class Animal{
public enum AnimalBreed{
Dog, Cat, Cow, Chicken, Elephant
}
private static final int Animals = AnimalBreed.Dog.ordinal();
private static final String[] myAnimal = new String[Animals];
... | 0 | 2010-03-29T07:17:52Z | 2,536,343 | <p><a href="http://code.activestate.com/recipes/413486/" rel="nofollow">http://code.activestate.com/recipes/413486/</a> contains a lot of help on this topic. Be warned that deepcopy support probably doesn't work with it.</p>
| 0 | 2010-03-29T07:24:19Z | [
"python"
] |
Python's equivalence? | 2,536,318 | <p>Is there anyway to transform the following code in Java to Python's equivalence?</p>
<pre><code>public class Animal{
public enum AnimalBreed{
Dog, Cat, Cow, Chicken, Elephant
}
private static final int Animals = AnimalBreed.Dog.ordinal();
private static final String[] myAnimal = new String[Animals];
... | 0 | 2010-03-29T07:17:52Z | 2,536,360 | <p>Translating this code directly would be a waste of time. The hardest thing when moving from Java to Python is giving up most of what you know. But the simple fact is that <a href="http://dirtsimple.org/2004/12/python-is-not-java.html">Python is not Java</a>, and translating line by line won't work as you expect. It'... | 7 | 2010-03-29T07:28:32Z | [
"python"
] |
Python's equivalence? | 2,536,318 | <p>Is there anyway to transform the following code in Java to Python's equivalence?</p>
<pre><code>public class Animal{
public enum AnimalBreed{
Dog, Cat, Cow, Chicken, Elephant
}
private static final int Animals = AnimalBreed.Dog.ordinal();
private static final String[] myAnimal = new String[Animals];
... | 0 | 2010-03-29T07:17:52Z | 2,536,481 | <p>This is not a line-for-line translation, but something in the ballpark:</p>
<pre><code>class Animal(object):
animal_breeds = "Dog Cat Cow Chicken Elephant".split()
animals = {}
def __init__(self, breed, name):
self._breed = breed
self.name = name
Animal.animals[name] = self
... | 1 | 2010-03-29T07:59:11Z | [
"python"
] |
Python's equivalence? | 2,536,318 | <p>Is there anyway to transform the following code in Java to Python's equivalence?</p>
<pre><code>public class Animal{
public enum AnimalBreed{
Dog, Cat, Cow, Chicken, Elephant
}
private static final int Animals = AnimalBreed.Dog.ordinal();
private static final String[] myAnimal = new String[Animals];
... | 0 | 2010-03-29T07:17:52Z | 2,543,866 | <p>It's unclear to me what the desired semantics of your Java would be. I'm guessing you're sort of trying to model a collection of animals (species, not breeds, incidentally) and imbue a set of associated classes with the behavior that varies according to the type of animal (roughly speaking the sounds that each make... | 2 | 2010-03-30T08:46:35Z | [
"python"
] |
Intra-package references in python and GUI tests | 2,536,335 | <p>I have problem concerning python packages and testing. I'm writing an application using <em>wx python</em> and have the following basic folder/package structure for the gui parts. The <em>mainframe.py</em> window has a dependency to the <em>logpane.py</em> panel, which is easily imported using an absolute import in ... | 1 | 2010-03-29T07:22:25Z | 2,536,419 | <p>You could use <code>PYTHONPATH</code>. Set it to your main project directory, before executing your test file. It will then be able to resolve all your imports just as if you would be executing from that directory.</p>
<pre><code>$ find
.
./test
./test/test.py
./some
./some/__init__.py
$ cat some/__init__.py
x = ... | 2 | 2010-03-29T07:43:39Z | [
"python",
"testing",
"packages",
"project-layout"
] |
Suppose I have a dictionary. How do I strip out all the keys? Edit: This is a nested dictionary | 2,536,336 | <p>And have a big blob of values, with a space in between?</p>
<p>Edit: What if I have nested dictionaries? The current solutions work if my values are all strings. But what if my values are nested dictionaries?</p>
| 0 | 2010-03-29T07:22:43Z | 2,536,342 | <p>Assuming the values are already strings:</p>
<pre><code>>>> d = { 1 : 'foo', 2 : 'bar' }
>>> ' '.join(d.values())
'foo bar'
</code></pre>
<p>If not, you can try to convert them to strings using for example <code>str</code>:</p>
<pre><code>>>> d = { 1 : 2, 3: 4 }
>>> ' '.join(st... | 2 | 2010-03-29T07:24:17Z | [
"python"
] |
Suppose I have a dictionary. How do I strip out all the keys? Edit: This is a nested dictionary | 2,536,336 | <p>And have a big blob of values, with a space in between?</p>
<p>Edit: What if I have nested dictionaries? The current solutions work if my values are all strings. But what if my values are nested dictionaries?</p>
| 0 | 2010-03-29T07:22:43Z | 2,536,345 | <pre><code>>>> a = {1: 'hello', 2: 'world'}
>>> a.values()
['hello', 'world']
>>> ' '.join(a.values())
'hello world'
</code></pre>
| 1 | 2010-03-29T07:24:54Z | [
"python"
] |
Suppose I have a dictionary. How do I strip out all the keys? Edit: This is a nested dictionary | 2,536,336 | <p>And have a big blob of values, with a space in between?</p>
<p>Edit: What if I have nested dictionaries? The current solutions work if my values are all strings. But what if my values are nested dictionaries?</p>
| 0 | 2010-03-29T07:22:43Z | 2,540,408 | <p>if you want the values from a dictionary that contains dictionaries as values, try something like this:</p>
<pre><code>In [1]: from itertools import chain
In [2]: d = {'A': {1: 'pants', 2: 'trowsers'}, 'B': {'1': 'spam', '2': 'eggs'}}
In [3]: values = ' '.join(chain.from_iterable(dic.itervalues() for dic in d.iter... | 0 | 2010-03-29T18:46:40Z | [
"python"
] |
Pylons: View latest debug message | 2,536,468 | <p>Is there a way to view the latest debug message instead of having to copy and paste something like "_debug/view/1269848287" to the browser everytime? </p>
| 0 | 2010-03-29T07:56:25Z | 2,536,493 | <p>(On the off-chance that this helps...)</p>
<p>Ubuntu's default Terminal program auto-detects URLs. When my pylons programs burp, I just ctrl-click on the link in the console.</p>
| 0 | 2010-03-29T08:02:35Z | [
"python",
"debugging",
"pylons"
] |
How to write Unix end of line characters in Windows using Python | 2,536,545 | <p>How can I write to files using Python (on Windows) and use the Unix end of line character?</p>
<p>e.g. When doing:</p>
<pre>
f = open('file.txt', 'w')
f.write('hello\n')
f.close()
</pre>
<p>Python automatically replaces \n with \r\n.</p>
| 38 | 2010-03-29T08:17:22Z | 2,536,558 | <p>You'll need to use the binary pseudo-mode when opening the file.</p>
<pre><code>f = open('file.txt', 'wb')
</code></pre>
| 6 | 2010-03-29T08:19:37Z | [
"python",
"newline"
] |
How to write Unix end of line characters in Windows using Python | 2,536,545 | <p>How can I write to files using Python (on Windows) and use the Unix end of line character?</p>
<p>e.g. When doing:</p>
<pre>
f = open('file.txt', 'w')
f.write('hello\n')
f.close()
</pre>
<p>Python automatically replaces \n with \r\n.</p>
| 38 | 2010-03-29T08:17:22Z | 2,536,560 | <p>Open the file as binary to prevent the translation of end-of-line characters:</p>
<pre><code>f = open('file.txt', 'wb')
</code></pre>
<p>Quoting the Python manual:</p>
<blockquote>
<p>On Windows, 'b' appended to the mode opens the file in binary mode, so there are also modes like 'rb', 'wb', and 'r+b'. Python o... | 39 | 2010-03-29T08:19:59Z | [
"python",
"newline"
] |
How to write Unix end of line characters in Windows using Python | 2,536,545 | <p>How can I write to files using Python (on Windows) and use the Unix end of line character?</p>
<p>e.g. When doing:</p>
<pre>
f = open('file.txt', 'w')
f.write('hello\n')
f.close()
</pre>
<p>Python automatically replaces \n with \r\n.</p>
| 38 | 2010-03-29T08:17:22Z | 23,434,608 | <h2>The modern way: use newline=''</h2>
<p>Use the <code>newline=</code> keyword parameter to <a href="https://docs.python.org/2/library/io.html#io.open">io.open()</a> to use Unix-style LF end-of-line terminators:</p>
<pre><code>import io
f = io.open('file.txt', 'w', newline='') # newline='' means don't convert \n
... | 35 | 2014-05-02T18:25:12Z | [
"python",
"newline"
] |
python: list modules within the package | 2,536,610 | <p>I have a package with a few modules, each module has a class (or a few classes) defined within it. I need to get the list of all modules within the package. Is there an API for this in python?</p>
<p>Here is the file structure:</p>
<pre><code>\pkg\
\pkg\__init__.py
\pkg\module1.py -> defines Class1
\pkg\module2... | 1 | 2010-03-29T08:29:38Z | 2,536,713 | <p>One ad-hoc approach is list the files in the directory, import each file dynamically with <code>__import__</code> and then list the classes of the resulting module.</p>
| 1 | 2010-03-29T08:52:34Z | [
"python",
"import",
"module",
"packages"
] |
python: list modules within the package | 2,536,610 | <p>I have a package with a few modules, each module has a class (or a few classes) defined within it. I need to get the list of all modules within the package. Is there an API for this in python?</p>
<p>Here is the file structure:</p>
<pre><code>\pkg\
\pkg\__init__.py
\pkg\module1.py -> defines Class1
\pkg\module2... | 1 | 2010-03-29T08:29:38Z | 2,536,714 | <p>ok, this was actually pretty straightforward:</p>
<pre><code>import pkg
sub_modules = (
pkg.__dict__.get(a) for a in dir(pkg)
if isinstance(
pkg.__dict__.get(a), types.ModuleType
)
) ... | 0 | 2010-03-29T08:52:50Z | [
"python",
"import",
"module",
"packages"
] |
Generation of an array of Random numbers with defined Min, Max, Mean and Stdev with given number of elements and error level | 2,536,615 | <p>I'd like to generate an array of Random numbers with defined Min, Max, Mean and Stdev with given number of elements and error level. Is there such a library in C, C++, PHP or Python to do so? Please kindly advise. Thanks!</p>
| 0 | 2010-03-29T08:30:16Z | 2,536,669 | <p><a href="http://www.boost.org/doc/libs/1_42_0/libs/random/random-distributions.html" rel="nofollow">http://www.boost.org/doc/libs/1_42_0/libs/random/random-distributions.html</a></p>
| 3 | 2010-03-29T08:41:57Z | [
"c++",
"python",
"statistics",
"generator"
] |
Generation of an array of Random numbers with defined Min, Max, Mean and Stdev with given number of elements and error level | 2,536,615 | <p>I'd like to generate an array of Random numbers with defined Min, Max, Mean and Stdev with given number of elements and error level. Is there such a library in C, C++, PHP or Python to do so? Please kindly advise. Thanks!</p>
| 0 | 2010-03-29T08:30:16Z | 2,536,690 | <p>The <a href="http://www.boost.org/doc/libs/1_42_0/libs/random/index.html" rel="nofollow">Boost C++ random number library</a> may do some of what you want, certainly you can with some distributions select the modal value of the distribution. That's all I've needed in my own code, so I've never investigated further. T... | 4 | 2010-03-29T08:46:28Z | [
"c++",
"python",
"statistics",
"generator"
] |
Generation of an array of Random numbers with defined Min, Max, Mean and Stdev with given number of elements and error level | 2,536,615 | <p>I'd like to generate an array of Random numbers with defined Min, Max, Mean and Stdev with given number of elements and error level. Is there such a library in C, C++, PHP or Python to do so? Please kindly advise. Thanks!</p>
| 0 | 2010-03-29T08:30:16Z | 2,537,252 | <p>If you want to use python, then I suggest that you use numpy. </p>
<p><a href="http://docs.scipy.org/doc/numpy/reference/routines.random.html" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/routines.random.html</a></p>
<p>You can probably find many distributions that fit your needs, but maybe you can sam... | 4 | 2010-03-29T10:40:30Z | [
"c++",
"python",
"statistics",
"generator"
] |
How do I join the values of nested Python dictionary? | 2,536,625 | <p>Suppose I have a dictionary, and it's nested with dictionaries inside.
I want to join all the values of that dictionary, recursively?</p>
<pre><code>' '.join(d.values())
</code></pre>
<p>That works if there are no nests.</p>
| 3 | 2010-03-29T08:32:37Z | 2,536,686 | <p>The following works for any non-recursive nested dicts:</p>
<pre><code>def flatten_dict_values(d):
values = []
for value in d.itervalues():
if isinstance(value, dict):
values.extend(flatten_dict_values(value))
else:
values.append(value)
return values
>>>... | 7 | 2010-03-29T08:45:36Z | [
"python"
] |
How do I join the values of nested Python dictionary? | 2,536,625 | <p>Suppose I have a dictionary, and it's nested with dictionaries inside.
I want to join all the values of that dictionary, recursively?</p>
<pre><code>' '.join(d.values())
</code></pre>
<p>That works if there are no nests.</p>
| 3 | 2010-03-29T08:32:37Z | 2,536,689 | <p>Try something along</p>
<pre><code>def flatten(d):
ret = []
for v in d.values():
if isinstance(v, dict):
ret.extend(flatten(v))
else:
ret.append(v)
return ret
my_dict = {1: 'bar', 5: {6: 'foo', 7: {'cat': 'bat'}}}
assert ' '.join(flatten(my_dict)) == 'bar foo b... | 3 | 2010-03-29T08:46:18Z | [
"python"
] |
How do I join the values of nested Python dictionary? | 2,536,625 | <p>Suppose I have a dictionary, and it's nested with dictionaries inside.
I want to join all the values of that dictionary, recursively?</p>
<pre><code>' '.join(d.values())
</code></pre>
<p>That works if there are no nests.</p>
| 3 | 2010-03-29T08:32:37Z | 2,536,900 | <p><em>This would work with nested iterables of other sort than dict as well if configured right:</em></p>
<p><b>'Prototypes'</b>:</p>
<pre><code>def should_iter_fnc(it):
"""returns 'True' if 'it' is viewed as nested"""
raise NotImplementedError
def join_fnc(itr):
"""transform an iterable 'itr' into appr... | 1 | 2010-03-29T09:32:50Z | [
"python"
] |
How to improve my Python regex syntax? | 2,536,684 | <p>I very new to Python, and fairly new to regex. (I have no Perl experience.)</p>
<p>I am able to use regular expressions in a way that works, but I'm not sure that my code is particularly Pythonic or consise.</p>
<p>For example, If I wanted to read in a text file and print out text that appears directly between th... | 3 | 2010-03-29T08:45:05Z | 2,536,716 | <p>I think it's fine.</p>
<p>Some minor points:-</p>
<ul>
<li>You can replace <code>result.groups()[x]</code> with <code>result.group(x+1)</code>.</li>
<li>If you don't need to capture <code>foo</code> and <code>bar</code>, just use <code>r'foo(.*)bar'</code>.</li>
<li>If you're using Python 2.5+, try to use <a href=... | 3 | 2010-03-29T08:53:38Z | [
"regex",
"python"
] |
How to improve my Python regex syntax? | 2,536,684 | <p>I very new to Python, and fairly new to regex. (I have no Perl experience.)</p>
<p>I am able to use regular expressions in a way that works, but I'm not sure that my code is particularly Pythonic or consise.</p>
<p>For example, If I wanted to read in a text file and print out text that appears directly between th... | 3 | 2010-03-29T08:45:05Z | 2,536,737 | <p>you don't need regex. split your string on "bar", iterate them, find "foo", do a split on "foo" and get the results to the right. Of course, you can use other string manipulation like getting the index and stuff. </p>
<pre><code>>>> s="w1 w2 foo what i want bar w3 w4 foowhatiwantbar w5"
>>> for it... | 0 | 2010-03-29T08:58:04Z | [
"regex",
"python"
] |
How to improve my Python regex syntax? | 2,536,684 | <p>I very new to Python, and fairly new to regex. (I have no Perl experience.)</p>
<p>I am able to use regular expressions in a way that works, but I'm not sure that my code is particularly Pythonic or consise.</p>
<p>For example, If I wanted to read in a text file and print out text that appears directly between th... | 3 | 2010-03-29T08:45:05Z | 2,536,789 | <p>There are two tricks to be had: the first is the <a href="http://docs.python.org/library/re.html#re.finditer" rel="nofollow">re.finditer</a> regular expression function (and method).
The second is the use of the <a href="http://docs.python.org/library/mmap.html" rel="nofollow">mmap</a> module.</p>
<p>From the docum... | 1 | 2010-03-29T09:08:16Z | [
"regex",
"python"
] |
How to improve my Python regex syntax? | 2,536,684 | <p>I very new to Python, and fairly new to regex. (I have no Perl experience.)</p>
<p>I am able to use regular expressions in a way that works, but I'm not sure that my code is particularly Pythonic or consise.</p>
<p>For example, If I wanted to read in a text file and print out text that appears directly between th... | 3 | 2010-03-29T08:45:05Z | 2,536,805 | <p>I have a few minor suggestions:</p>
<ul>
<li>Unless you're certain that <code>foo</code> and <code>bar</code> can occur no more than once per line, it's better to use <code>.*?</code> instead of <code>.*</code></li>
<li>If you need to make sure that <code>foo</code> and <code>bar</code> should only be matched as en... | 0 | 2010-03-29T09:10:35Z | [
"regex",
"python"
] |
How to connect to local MQseries queue using Python? | 2,536,733 | <p>I am new to mqseries and I started with IBM WebSphere MQ curses. There are examples with <code>MQ_APPLE</code> and <code>MQ_ORANGE</code> queue managers. I have no problem with sending messages to local or remote queue with MQ Explorer, but I wanted to send such message from code: Python or Java. I tried Python pymq... | 4 | 2010-03-29T08:56:40Z | 2,538,241 | <p>Based on the error it appears that you are attempting to connect to a remote queue manager, but you are using the local queue manager bindings method to connect. I say this because the error is stating that the mqi client doesn't know which channel to connect to. Can you please clarify if you are using a local que... | 2 | 2010-03-29T13:37:26Z | [
"python",
"websphere-mq"
] |
How to connect to local MQseries queue using Python? | 2,536,733 | <p>I am new to mqseries and I started with IBM WebSphere MQ curses. There are examples with <code>MQ_APPLE</code> and <code>MQ_ORANGE</code> queue managers. I have no problem with sending messages to local or remote queue with MQ Explorer, but I wanted to send such message from code: Python or Java. I tried Python pymq... | 4 | 2010-03-29T08:56:40Z | 2,548,884 | <p>Your post mentions you'd like this to run in Python or Java. Python I can't help with but the previous responder did, so cool. As far as Java, maybe I can point you in the right direction. IBM supports both Java and JMS and provides a number of sample programs of each. By default, these are installed at: </p>
<p... | 1 | 2010-03-30T21:29:10Z | [
"python",
"websphere-mq"
] |
How to connect to local MQseries queue using Python? | 2,536,733 | <p>I am new to mqseries and I started with IBM WebSphere MQ curses. There are examples with <code>MQ_APPLE</code> and <code>MQ_ORANGE</code> queue managers. I have no problem with sending messages to local or remote queue with MQ Explorer, but I wanted to send such message from code: Python or Java. I tried Python pymq... | 4 | 2010-03-29T08:56:40Z | 2,562,672 | <blockquote>
<p>You are right. I used client bindings
while only such type of module is
available in precompiled form.</p>
</blockquote>
<p>Hello MichaÅ,</p>
<p>I don't follow StackOverflow that closely and have only now seen your question. As you can see, PyMQI is by default built in MQ client as that's what ... | 4 | 2010-04-01T18:28:18Z | [
"python",
"websphere-mq"
] |
Python Introspection: How to get varnames of class methods? | 2,536,879 | <p>I want to get the names of the keyword arguments of the methods of a class. I think I understood how to get the names of the methods and how to get the variable names of a specific method, but I don't get how to combine these:</p>
<pre><code>class A(object):
def A1(self, test1=None):
self.test1 = test1
... | 3 | 2010-03-29T09:28:33Z | 2,536,921 | <p>Well, as a direct extension of what you did:</p>
<pre><code>for varname in a.__class__.__dict__['A1'].__code__.co_varnames:
print varname
</code></pre>
<p>prints:</p>
<pre><code>self
test1
</code></pre>
<p><em>P.S.: to be honest, I have a feeling this can be done more elegantly...</em> </p>
<p>For example, ... | 5 | 2010-03-29T09:36:47Z | [
"python",
"class",
"introspection"
] |
Python Introspection: How to get varnames of class methods? | 2,536,879 | <p>I want to get the names of the keyword arguments of the methods of a class. I think I understood how to get the names of the methods and how to get the variable names of a specific method, but I don't get how to combine these:</p>
<pre><code>class A(object):
def A1(self, test1=None):
self.test1 = test1
... | 3 | 2010-03-29T09:28:33Z | 2,536,979 | <pre><code>import inspect
for name, method in inspect.getmembers(a, inspect.ismethod):
print name
(args, varargs, varkw, defaults) = inspect.getargspec(method)
for arg in args:
print arg
</code></pre>
| 9 | 2010-03-29T09:47:55Z | [
"python",
"class",
"introspection"
] |
Tornado or Django works with CGI? | 2,537,065 | <p>Tornado is a webserver + framework like Django but for real-time features.</p>
<p>On my server I don't have a python module or wsgi module so I thought
CGI.
Is there a way to get Tornado ( or Django ) works by using CGI folder ?
If yes, Could you explain me how do I do that ?</p>
| 2 | 2010-03-29T10:02:00Z | 2,537,086 | <p><a href="http://trac.saddi.com/flup" rel="nofollow">flup</a> provides a CGI-to-WSGI adapter, but you really should consider using something like FastCGI instead.</p>
| 2 | 2010-03-29T10:05:19Z | [
"python",
"django",
"cgi",
"webserver",
"tornado"
] |
Tornado or Django works with CGI? | 2,537,065 | <p>Tornado is a webserver + framework like Django but for real-time features.</p>
<p>On my server I don't have a python module or wsgi module so I thought
CGI.
Is there a way to get Tornado ( or Django ) works by using CGI folder ?
If yes, Could you explain me how do I do that ?</p>
| 2 | 2010-03-29T10:02:00Z | 3,244,176 | <p>Main feature of Tornado is that it is high performance web-server written in Python, for creating web applications using Python programming language.</p>
<p>Running Tornado as CGI application negates the very reason it exists, because running CGI scripts is expensive in terms of performance, and most probably there... | 5 | 2010-07-14T07:38:14Z | [
"python",
"django",
"cgi",
"webserver",
"tornado"
] |
Some jQuery-powered features not working in Chrome | 2,537,096 | <p>I'm using a <a href="http://www.gmarwaha.com/jquery/jcarousellite/" rel="nofollow">jCarouselLite</a> plugin for creating two image galleries on the main page of my Django-powered site. The code of elements with navigation arrows is generating dynamically like this:</p>
<pre><code>$(document).ready(function ()
{
... | 0 | 2010-03-29T10:07:06Z | 2,537,439 | <p>No idea if this matches your issues, but I've been running the dev channel of chrome for linux and this weekend had issues with it working with the jquery ui 1.8 release button plugin. Come to find out it was a Chrome bug and updating solved the issue. </p>
| 0 | 2010-03-29T11:20:56Z | [
"javascript",
"jquery",
"python",
"django"
] |
(Python/Django): How do I keep my production db in sync (scheme and data) and with dev pc db? | 2,537,253 | <p>I have a local Postgres database which will be filled with data (daily) on my local development machine. What is a good solution to transfer/sync/mirror this data to a production Postgres database.</p>
<p>For what it's worth I'm developing in Python using Django. </p>
<p>Thanks!</p>
| 3 | 2010-03-29T10:40:48Z | 2,537,449 | <p>This seems like a strange workflow for me. Wouldn't it be much better to import the data in the production database and then just sync it with your development db from time to time?
IMO, the development machine shouldn't be included in the production data workflow.</p>
<p>That's the way I do it using <a href="http:... | 3 | 2010-03-29T11:22:19Z | [
"python",
"django",
"postgresql"
] |
(Python/Django): How do I keep my production db in sync (scheme and data) and with dev pc db? | 2,537,253 | <p>I have a local Postgres database which will be filled with data (daily) on my local development machine. What is a good solution to transfer/sync/mirror this data to a production Postgres database.</p>
<p>For what it's worth I'm developing in Python using Django. </p>
<p>Thanks!</p>
| 3 | 2010-03-29T10:40:48Z | 2,559,496 | <p>South is a great tool for dealing with database migrations in Django projects. The latest release now supports both schema and data migrations</p>
<p><a href="http://south.aeracode.org/docs/tutorial/part3.html#data-migrations" rel="nofollow">http://south.aeracode.org/docs/tutorial/part3.html#data-migrations</a></p>... | 2 | 2010-04-01T09:51:56Z | [
"python",
"django",
"postgresql"
] |
How do I have signed fields in Django? | 2,537,319 | <pre><code>class MyTable(models.Model):
lat = models.FloatField(blank=True)
long = models.FloatField(blank=True)
</code></pre>
<p>How do I make them signed? Able to accept negative .</p>
| 1 | 2010-03-29T10:55:17Z | 2,537,352 | <p><code>FloatField</code> can accept floating point numbers, negatives included.</p>
<p>If you need positive-only integers, there's <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#positiveintegerfield">PositiveIntegerField</a>. Positive-only floats are a much rarer need, so I don't think they're nati... | 8 | 2010-03-29T11:02:24Z | [
"python",
"mysql",
"database",
"django"
] |
Exception Handling in google app engine | 2,537,357 | <p>i am raising exception using</p>
<pre><code>if UserId == '' and Password == '':
raise Exception.MyException , "wrong userId or password"
</code></pre>
<p>but i want print the error message on same page</p>
<pre><code>class MyException(Exception):
def __init__(self,msg):
Exception.__init__(self,ms... | 1 | 2010-03-29T11:03:43Z | 2,537,478 | <p>You are not using the <a href="http://code.google.com/appengine/docs/python/gettingstarted/usingusers.html" rel="nofollow">Users API</a>? Assuming you are handling a POST request, how about this:</p>
<pre><code>class LoginError(Exception):
CODES = { 'mismatch': 'Wrong credentials', 'disabled': 'Account disabled... | 1 | 2010-03-29T11:29:13Z | [
"python",
"google-app-engine",
"exception-handling"
] |
Exception Handling in google app engine | 2,537,357 | <p>i am raising exception using</p>
<pre><code>if UserId == '' and Password == '':
raise Exception.MyException , "wrong userId or password"
</code></pre>
<p>but i want print the error message on same page</p>
<pre><code>class MyException(Exception):
def __init__(self,msg):
Exception.__init__(self,ms... | 1 | 2010-03-29T11:03:43Z | 2,537,493 | <p>Why raising an exception instead of just stop function execution and redirect to new page using return statement</p>
| 0 | 2010-03-29T11:31:34Z | [
"python",
"google-app-engine",
"exception-handling"
] |
django views getid | 2,537,469 | <pre><code>class host(models.Model):
emp = models.ForeignKey(getname)
def __unicode__(self):
return self.topic
</code></pre>
<p>In views there is the code as,</p>
<pre><code> real =[]
for emp in my_emp:
real.append(host.objects.filter(emp=emp.id))
</code></pre>
<p>This above results onl... | 0 | 2010-03-29T11:27:16Z | 2,537,491 | <p>Just add them to the list when you are processing <code>my_emp</code> list, something like that:</p>
<pre><code>real = []
for emp in my_emp:
real.append((emp.id, host.objects.filter(emp=emp.id)))
</code></pre>
<p>Later</p>
<pre><code>for emp_id, host in real:
# do something usefull
</code></pre>
<p>You c... | 1 | 2010-03-29T11:31:07Z | [
"python",
"django",
"django-models",
"django-views"
] |
django views getid | 2,537,469 | <pre><code>class host(models.Model):
emp = models.ForeignKey(getname)
def __unicode__(self):
return self.topic
</code></pre>
<p>In views there is the code as,</p>
<pre><code> real =[]
for emp in my_emp:
real.append(host.objects.filter(emp=emp.id))
</code></pre>
<p>This above results onl... | 0 | 2010-03-29T11:27:16Z | 2,537,695 | <p>You probably want to do this whole thing in a single query:</p>
<pre><code>Host.objects.filter(emp__in=my_emp)
</code></pre>
<p>which will get you queryset of all Host objects for your list of emp ids.</p>
| 1 | 2010-03-29T12:12:42Z | [
"python",
"django",
"django-models",
"django-views"
] |
method of iterating over sqlalchemy model's defined columns? | 2,537,471 | <p>I've been trying to figure out how to iterate over the list of columns defined in a SqlAlchemy model. I want it for writing some serialization and copy methods to a couple of models. I can't just iterate over the obj.<strong>dict</strong> since it contains a lot of SA specific items. </p>
<p>Anyone know of a way to... | 55 | 2010-03-29T11:27:43Z | 2,537,548 | <p>You can get the list of defined properties from the mapper. For your case you're interested in only ColumnProperty objects.</p>
<pre><code>from sqlalchemy.orm import class_mapper
import sqlalchemy
def attribute_names(cls):
return [prop.key for prop in class_mapper(cls).iterate_properties
if isinstance(... | 49 | 2010-03-29T11:42:07Z | [
"python",
"sqlalchemy"
] |
method of iterating over sqlalchemy model's defined columns? | 2,537,471 | <p>I've been trying to figure out how to iterate over the list of columns defined in a SqlAlchemy model. I want it for writing some serialization and copy methods to a couple of models. I can't just iterate over the obj.<strong>dict</strong> since it contains a lot of SA specific items. </p>
<p>Anyone know of a way to... | 55 | 2010-03-29T11:27:43Z | 2,540,598 | <p>You could use the following function:</p>
<pre><code>def __unicode__(self):
return "[%s(%s)]" % (self.__class__.__name__, ', '.join('%s=%s' % (k, self.__dict__[k]) for k in sorted(self.__dict__) if '_sa_' != k[:4]))
</code></pre>
<p>It will exclude SA <em>magic</em> attributes, but will not exclude the relatio... | 44 | 2010-03-29T19:14:55Z | [
"python",
"sqlalchemy"
] |
method of iterating over sqlalchemy model's defined columns? | 2,537,471 | <p>I've been trying to figure out how to iterate over the list of columns defined in a SqlAlchemy model. I want it for writing some serialization and copy methods to a couple of models. I can't just iterate over the obj.<strong>dict</strong> since it contains a lot of SA specific items. </p>
<p>Anyone know of a way to... | 55 | 2010-03-29T11:27:43Z | 12,631,974 | <p>I realise that this is an old question, but I've just come across the same requirement and would like to offer an alternative solution to future readers.</p>
<p>As Josh notes, full SQL field names will be returned by <code>JobStatus.__table__.columns</code>, so rather than the original field name <em>id</em>, you ... | 17 | 2012-09-28T00:24:21Z | [
"python",
"sqlalchemy"
] |
method of iterating over sqlalchemy model's defined columns? | 2,537,471 | <p>I've been trying to figure out how to iterate over the list of columns defined in a SqlAlchemy model. I want it for writing some serialization and copy methods to a couple of models. I can't just iterate over the obj.<strong>dict</strong> since it contains a lot of SA specific items. </p>
<p>Anyone know of a way to... | 55 | 2010-03-29T11:27:43Z | 13,752,442 | <p><code>self.__table__.columns</code> will "only" give you the columns defined in that particular class, i.e. without inherited ones. if you need all, use <code>self.__mapper__.columns</code>. in your example i'd probably use something like this:</p>
<pre><code>class JobStatus(Base):
...
def __iter__(self... | 7 | 2012-12-06T20:58:58Z | [
"python",
"sqlalchemy"
] |
method of iterating over sqlalchemy model's defined columns? | 2,537,471 | <p>I've been trying to figure out how to iterate over the list of columns defined in a SqlAlchemy model. I want it for writing some serialization and copy methods to a couple of models. I can't just iterate over the obj.<strong>dict</strong> since it contains a lot of SA specific items. </p>
<p>Anyone know of a way to... | 55 | 2010-03-29T11:27:43Z | 32,116,563 | <p>To get an <code>as_dict</code> method on all of my classes I used a <code>Mixin</code> class which uses the technics described by <a href="http://stackoverflow.com/users/107366/ants-aasma">Ants Aasma</a>.</p>
<pre><code>class BaseMixin(object): ... | 3 | 2015-08-20T11:05:13Z | [
"python",
"sqlalchemy"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.