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 |
|---|---|---|---|---|---|---|---|---|---|
How to generate dynamic (parametrized) unit tests in python? | 32,899 | <p>I have some kind of test data and want to create an unit test for each item. My first idea was to do it like this:</p>
<pre><code>import unittest
l = [["foo", "a", "a",], ["bar", "a", "b"], ["lee", "b", "b"]]
class TestSequence(unittest.TestCase):
def testsample(self):
for name, a,b in l:
... | 111 | 2008-08-28T17:49:02Z | 31,161,347 | <p>I use metaclasses and decorators for generate tests. You can check my implementation <a href="https://github.com/erm0l0v/python_wrap_cases" rel="nofollow">python_wrap_cases</a>. This library doesn't require any test frameworks.</p>
<p>Your example:</p>
<pre><code>import unittest
from python_wrap_cases import wrap_... | 2 | 2015-07-01T12:28:27Z | [
"python",
"unit-testing",
"parameterized-unit-test"
] |
How to generate dynamic (parametrized) unit tests in python? | 32,899 | <p>I have some kind of test data and want to create an unit test for each item. My first idea was to do it like this:</p>
<pre><code>import unittest
l = [["foo", "a", "a",], ["bar", "a", "b"], ["lee", "b", "b"]]
class TestSequence(unittest.TestCase):
def testsample(self):
for name, a,b in l:
... | 111 | 2008-08-28T17:49:02Z | 33,884,166 | <p>There's also Hypothesis which adds fuzz or property based testing: <a href="https://pypi.python.org/pypi/hypothesis" rel="nofollow">https://pypi.python.org/pypi/hypothesis</a></p>
<p>This is a very powerful testing method.</p>
| 1 | 2015-11-24T02:00:00Z | [
"python",
"unit-testing",
"parameterized-unit-test"
] |
How to generate dynamic (parametrized) unit tests in python? | 32,899 | <p>I have some kind of test data and want to create an unit test for each item. My first idea was to do it like this:</p>
<pre><code>import unittest
l = [["foo", "a", "a",], ["bar", "a", "b"], ["lee", "b", "b"]]
class TestSequence(unittest.TestCase):
def testsample(self):
for name, a,b in l:
... | 111 | 2008-08-28T17:49:02Z | 34,382,688 | <p>You can use <code>TestSuite</code> and custom <code>TestCase</code> classes. </p>
<pre><code>import unittest
class CustomTest(unittest.TestCase):
def __init__(self, name, a, b):
super().__init__()
self.name = name
self.a = a
self.b = b
def runTest(self):
print("test... | 1 | 2015-12-20T15:41:54Z | [
"python",
"unit-testing",
"parameterized-unit-test"
] |
How to generate dynamic (parametrized) unit tests in python? | 32,899 | <p>I have some kind of test data and want to create an unit test for each item. My first idea was to do it like this:</p>
<pre><code>import unittest
l = [["foo", "a", "a",], ["bar", "a", "b"], ["lee", "b", "b"]]
class TestSequence(unittest.TestCase):
def testsample(self):
for name, a,b in l:
... | 111 | 2008-08-28T17:49:02Z | 36,788,233 | <p>I'd been having trouble with a very particular style of parameterized tests. All our Selenium tests can run locally, but they also should be able to be run remotely against several platforms on SauceLabs. Basically, I wanted to take a large amount of already-written test cases and parameterize them with the fewest... | 0 | 2016-04-22T08:02:46Z | [
"python",
"unit-testing",
"parameterized-unit-test"
] |
How to generate dynamic (parametrized) unit tests in python? | 32,899 | <p>I have some kind of test data and want to create an unit test for each item. My first idea was to do it like this:</p>
<pre><code>import unittest
l = [["foo", "a", "a",], ["bar", "a", "b"], ["lee", "b", "b"]]
class TestSequence(unittest.TestCase):
def testsample(self):
for name, a,b in l:
... | 111 | 2008-08-28T17:49:02Z | 37,470,261 | <p>Besides using setattr, we can use load_tests since python 3.2. Please refer to blog post <a href="http://blog.livreuro.com/en/coding/python/how-to-generate-discoverable-unit-tests-in-python-dynamically/" rel="nofollow">blog.livreuro.com/en/coding/python/how-to-generate-discoverable-unit-tests-in-python-dynamically/<... | -1 | 2016-05-26T20:20:39Z | [
"python",
"unit-testing",
"parameterized-unit-test"
] |
How to generate dynamic (parametrized) unit tests in python? | 32,899 | <p>I have some kind of test data and want to create an unit test for each item. My first idea was to do it like this:</p>
<pre><code>import unittest
l = [["foo", "a", "a",], ["bar", "a", "b"], ["lee", "b", "b"]]
class TestSequence(unittest.TestCase):
def testsample(self):
for name, a,b in l:
... | 111 | 2008-08-28T17:49:02Z | 38,726,022 | <p>Following is my solution. I find this useful when:
1. Should work for unittest.Testcase and unittest discover
2. Have a set of tests to be run for different parameter settings.
3. Very simple no dependency on other packages
import unittest</p>
<pre><code> class BaseClass(unittest.TestCase):
def s... | -1 | 2016-08-02T16:35:17Z | [
"python",
"unit-testing",
"parameterized-unit-test"
] |
How to generate dynamic (parametrized) unit tests in python? | 32,899 | <p>I have some kind of test data and want to create an unit test for each item. My first idea was to do it like this:</p>
<pre><code>import unittest
l = [["foo", "a", "a",], ["bar", "a", "b"], ["lee", "b", "b"]]
class TestSequence(unittest.TestCase):
def testsample(self):
for name, a,b in l:
... | 111 | 2008-08-28T17:49:02Z | 39,350,898 | <p>This solution works with <code>unittest</code> and <code>nose</code>:</p>
<pre><code>#!/usr/bin/env python
import unittest
def make_function(description, a, b):
def ghost(self):
self.assertEqual(a, b, description)
print description
ghost.__name__ = 'test_{0}'.format(description)
return ghos... | 0 | 2016-09-06T13:57:36Z | [
"python",
"unit-testing",
"parameterized-unit-test"
] |
ssh hangs when command invoked directly, but exits cleanly when run interactive | 33,475 | <p>I need to launch a server on the remote machine and retrieve the port number that the server process is lsitening on. When invoked, the server will listen on a random port and output the port number on stderr.</p>
<p>I want to automate the process of logging on to the remote machine, launching the process, and ret... | 1 | 2008-08-28T21:48:09Z | 33,486 | <blockquote>
<pre><code>s = p.stderr.readline()
</code></pre>
</blockquote>
<p>I suspect it's the above line. When you invoke a command directly through ssh, you don't get your full pty (assuming Linux), and thus no stderr to read from.</p>
<p>When you log in interactively, stdin, stdout, and stderr are set up for y... | 3 | 2008-08-28T21:53:10Z | [
"python",
"ssh"
] |
ssh hangs when command invoked directly, but exits cleanly when run interactive | 33,475 | <p>I need to launch a server on the remote machine and retrieve the port number that the server process is lsitening on. When invoked, the server will listen on a random port and output the port number on stderr.</p>
<p>I want to automate the process of logging on to the remote machine, launching the process, and ret... | 1 | 2008-08-28T21:48:09Z | 33,673 | <p>what if you do the following:</p>
<h2><code>ssh <remote host> '<your command> ;<your regexp using awk or something>'</code></h2>
<p>For example</p>
<h2><code>ssh <remote host> '<your program>; ps aux | awk \'/root/ {print $2}\''</code></h2>
<p>This will connect to , execute and the... | 0 | 2008-08-28T23:50:19Z | [
"python",
"ssh"
] |
ssh hangs when command invoked directly, but exits cleanly when run interactive | 33,475 | <p>I need to launch a server on the remote machine and retrieve the port number that the server process is lsitening on. When invoked, the server will listen on a random port and output the port number on stderr.</p>
<p>I want to automate the process of logging on to the remote machine, launching the process, and ret... | 1 | 2008-08-28T21:48:09Z | 33,873 | <p>@Ben Collins</p>
<p>I think you're right about stderr being an issue. I am pretty sure it's blocking on the readline() call. </p>
<p>In the end, I gave up and decided to use the pxssh module from <a href="http://pexpect.sourceforge.net" rel="nofollow">pexpect</a> to automate my interaction with an ssh session.</p>... | 0 | 2008-08-29T02:42:07Z | [
"python",
"ssh"
] |
Extending base classes in Python | 33,534 | <p>I'm trying to extend some "base" classes in Python:</p>
<pre><code>class xlist (list):
def len(self):
return len(self)
def add(self, *args):
self.extend(args)
return None
class xint (int):
def add(self, value):
self += value
return self
x = xlist([1,2,3])
pri... | 10 | 2008-08-28T22:18:02Z | 33,556 | <p>Ints are immutable and you can't modify them in place, so you should go with option #2 (because option #1 is impossible without some trickery).</p>
| 0 | 2008-08-28T22:28:36Z | [
"python"
] |
Extending base classes in Python | 33,534 | <p>I'm trying to extend some "base" classes in Python:</p>
<pre><code>class xlist (list):
def len(self):
return len(self)
def add(self, *args):
self.extend(args)
return None
class xint (int):
def add(self, value):
self += value
return self
x = xlist([1,2,3])
pri... | 10 | 2008-08-28T22:18:02Z | 33,563 | <p><strong>int</strong> is a value type, so each time you do an assignment, (e.g. both instances of <strong>+=</strong> above), it doesn't modify the object you have on the heap, but replaces the reference with one of the result of the right hand side of the assignment (i.e. an int)</p>
<p><strong>list</strong> isn't ... | 5 | 2008-08-28T22:32:40Z | [
"python"
] |
Extending base classes in Python | 33,534 | <p>I'm trying to extend some "base" classes in Python:</p>
<pre><code>class xlist (list):
def len(self):
return len(self)
def add(self, *args):
self.extend(args)
return None
class xint (int):
def add(self, value):
self += value
return self
x = xlist([1,2,3])
pri... | 10 | 2008-08-28T22:18:02Z | 33,663 | <p>Your two <code>xint</code> examples don't work for two different reasons.</p>
<p>The first doesn't work because <code>self += value</code> is equivalent to <code>self = self + value</code> which just reassigns the local variable <code>self</code> to a different object (an integer) but doesn't change the original ob... | 22 | 2008-08-28T23:41:55Z | [
"python"
] |
Extending base classes in Python | 33,534 | <p>I'm trying to extend some "base" classes in Python:</p>
<pre><code>class xlist (list):
def len(self):
return len(self)
def add(self, *args):
self.extend(args)
return None
class xint (int):
def add(self, value):
self += value
return self
x = xlist([1,2,3])
pri... | 10 | 2008-08-28T22:18:02Z | 6,809,498 | <p>i expanded you xlist class just a bit, made it so you could find all index points of a number making it so you can extend with multiple lists at once making it initialize and making it so you can iterate through it</p>
<pre><code>class xlist:
def __init__(self,alist):
if type(alist)==type(' '):
... | 1 | 2011-07-24T20:30:07Z | [
"python"
] |
Find out how much memory is being used by an object in Python | 33,978 | <p>How would you go about finding out how much memory is being used by an object? I know it is possible to find out how much is used by a block of code, but not by an instantiated object (anytime during its life), which is what I want. </p>
| 117 | 2008-08-29T04:59:31Z | 34,011 | <p>I haven't any personal experience with either of the following, but a simple search for a "Python [memory] profiler" yield:</p>
<ul>
<li><p>PySizer, "a memory profiler for Python," found at <a href="http://pysizer.8325.org/" rel="nofollow">http://pysizer.8325.org/</a>. However the page seems to indicate that the p... | 3 | 2008-08-29T05:33:49Z | [
"python",
"performance",
"memory-profiling"
] |
Find out how much memory is being used by an object in Python | 33,978 | <p>How would you go about finding out how much memory is being used by an object? I know it is possible to find out how much is used by a block of code, but not by an instantiated object (anytime during its life), which is what I want. </p>
| 117 | 2008-08-29T04:59:31Z | 35,645 | <p><strong>There's no easy way to find out the memory size of a python object</strong>. One of the problems you may find is that Python objects - like lists and dicts - may have references to other python objects (in this case, what would your size be? The size containing the size of each object or not?). There are som... | 67 | 2008-08-30T03:25:43Z | [
"python",
"performance",
"memory-profiling"
] |
Find out how much memory is being used by an object in Python | 33,978 | <p>How would you go about finding out how much memory is being used by an object? I know it is possible to find out how much is used by a block of code, but not by an instantiated object (anytime during its life), which is what I want. </p>
| 117 | 2008-08-29T04:59:31Z | 12,924,399 | <p>Another approach is to use pickle. See <a href="http://stackoverflow.com/a/565382/420867">this answer</a> to a duplicate of this question.</p>
| 14 | 2012-10-16T22:25:06Z | [
"python",
"performance",
"memory-profiling"
] |
Find out how much memory is being used by an object in Python | 33,978 | <p>How would you go about finding out how much memory is being used by an object? I know it is possible to find out how much is used by a block of code, but not by an instantiated object (anytime during its life), which is what I want. </p>
| 117 | 2008-08-29T04:59:31Z | 19,865,746 | <p>Try this:</p>
<pre><code>sys.getsizeof(object)
</code></pre>
<p><a href="https://docs.python.org/3/library/sys.html#sys.getsizeof" rel="nofollow">getsizeof()</a> calls the objectâs <code>__sizeof__</code> method and adds an additional garbage collector overhead <strong>if</strong> the object is managed by the ga... | 24 | 2013-11-08T18:11:11Z | [
"python",
"performance",
"memory-profiling"
] |
Find out how much memory is being used by an object in Python | 33,978 | <p>How would you go about finding out how much memory is being used by an object? I know it is possible to find out how much is used by a block of code, but not by an instantiated object (anytime during its life), which is what I want. </p>
| 117 | 2008-08-29T04:59:31Z | 20,906,366 | <p>This must be used with care because an override on the objects __sizeof__ might be misleading.</p>
<p>Using the bregman.suite, some tests with sys.getsizeof output a copy of an array object (data) in an object instance as being bigger than the object itself (mfcc).</p>
<pre><code>>>> mfcc = MelFrequencyCe... | 1 | 2014-01-03T14:54:15Z | [
"python",
"performance",
"memory-profiling"
] |
Find out how much memory is being used by an object in Python | 33,978 | <p>How would you go about finding out how much memory is being used by an object? I know it is possible to find out how much is used by a block of code, but not by an instantiated object (anytime during its life), which is what I want. </p>
| 117 | 2008-08-29T04:59:31Z | 24,495,011 | <p>For big objects you may use a somewhat crude but effective method:
check how much memory your Python process occupies in the system, then delete the object and compare.</p>
<p>This method has many drawbacks but it will give you a very fast estimate for very big objects.</p>
| -2 | 2014-06-30T16:44:04Z | [
"python",
"performance",
"memory-profiling"
] |
Are Python threads buggy? | 34,020 | <p>A reliable coder friend told me that Python's current multi-threading implementation is seriously buggy - enough to avoid using altogether. What can said about this rumor?</p>
| 17 | 2008-08-29T05:43:16Z | 34,024 | <p>I've used it in several applications and have never had nor heard of threading being anything other than 100% reliable, as long as you know its limits. You can't spawn 1000 threads at the same time and expect your program to run properly on Windows, however you can easily write a worker pool and just feed it 1000 o... | -2 | 2008-08-29T05:50:47Z | [
"python",
"multithreading"
] |
Are Python threads buggy? | 34,020 | <p>A reliable coder friend told me that Python's current multi-threading implementation is seriously buggy - enough to avoid using altogether. What can said about this rumor?</p>
| 17 | 2008-08-29T05:43:16Z | 34,031 | <p>As far as I know there are no real bugs, but the performance when threading in cPython is really bad (compared to most other threading implementations, but usually good enough if all most of the threads do is block) due to the <a href="http://docs.python.org/api/threads.html" rel="nofollow">GIL</a> (Global Interpret... | 3 | 2008-08-29T05:58:34Z | [
"python",
"multithreading"
] |
Are Python threads buggy? | 34,020 | <p>A reliable coder friend told me that Python's current multi-threading implementation is seriously buggy - enough to avoid using altogether. What can said about this rumor?</p>
| 17 | 2008-08-29T05:43:16Z | 34,060 | <p>Python threads are good for <strong>concurrent I/O programming</strong>. Threads are swapped out of the CPU as soon as they block waiting for input from file, network, etc. This allows other Python threads to use the CPU while others wait. This would allow you to write a multi-threaded web server or web crawler, for... | 43 | 2008-08-29T06:33:54Z | [
"python",
"multithreading"
] |
Are Python threads buggy? | 34,020 | <p>A reliable coder friend told me that Python's current multi-threading implementation is seriously buggy - enough to avoid using altogether. What can said about this rumor?</p>
| 17 | 2008-08-29T05:43:16Z | 34,078 | <p>The GIL (Global Interpreter Lock) might be a problem, but the API is quite OK. Try out the excellent <code>processing</code> module, which implements the Threading API for separate processes. I am using that right now (albeit on OS X, have yet to do some testing on Windows) and am really impressed. The Queue class i... | 7 | 2008-08-29T06:55:14Z | [
"python",
"multithreading"
] |
Are Python threads buggy? | 34,020 | <p>A reliable coder friend told me that Python's current multi-threading implementation is seriously buggy - enough to avoid using altogether. What can said about this rumor?</p>
| 17 | 2008-08-29T05:43:16Z | 34,782 | <p>The standard implementation of Python (generally known as CPython as it is written in C) uses OS threads, but since there is the <a href="http://en.wikipedia.org/wiki/Global_Interpreter_Lock" rel="nofollow">Global Interpreter Lock</a>, only one thread at a time is allowed to run Python code. But within those limita... | 13 | 2008-08-29T17:17:18Z | [
"python",
"multithreading"
] |
Are Python threads buggy? | 34,020 | <p>A reliable coder friend told me that Python's current multi-threading implementation is seriously buggy - enough to avoid using altogether. What can said about this rumor?</p>
| 17 | 2008-08-29T05:43:16Z | 576,667 | <p>If you want to code in python and get great threading support, you might want to check out IronPython or Jython. Since the python code in IronPython and Jython run on the .NET CLR and Java VM respectively, they enjoy the great threading support built into those libraries. In addition to that, IronPython doesn't have... | 1 | 2009-02-23T06:15:07Z | [
"python",
"multithreading"
] |
How to specify an authenticated proxy for a python http connection? | 34,079 | <p>What's the best way to specify a proxy with username and password for an http connection in python?</p>
| 44 | 2008-08-29T06:55:54Z | 34,116 | <p>This works for me: </p>
<pre><code>import urllib2
proxy = urllib2.ProxyHandler({'http': 'http://
username:password@proxyurl:proxyport'})
auth = urllib2.HTTPBasicAuthHandler()
opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
urllib2.install_opener(opener)
conn = urllib2.urlopen('http://python.org')... | 53 | 2008-08-29T07:30:35Z | [
"python",
"http",
"proxy"
] |
How to specify an authenticated proxy for a python http connection? | 34,079 | <p>What's the best way to specify a proxy with username and password for an http connection in python?</p>
| 44 | 2008-08-29T06:55:54Z | 35,443 | <p>The best way of going through a proxy that requires authentication is using <a href="http://docs.python.org/lib/module-urllib2.html">urllib2</a> to build a custom url opener, then using that to make all the requests you want to go through the proxy. Note in particular, you probably don't want to embed the proxy pass... | 8 | 2008-08-29T22:52:47Z | [
"python",
"http",
"proxy"
] |
How to specify an authenticated proxy for a python http connection? | 34,079 | <p>What's the best way to specify a proxy with username and password for an http connection in python?</p>
| 44 | 2008-08-29T06:55:54Z | 142,324 | <p>Or if you want to install it, so that it is always used with urllib2.urlopen (so you don't need to keep a reference to the opener around):</p>
<pre><code>import urllib2
url = 'www.proxyurl.com'
username = 'user'
password = 'pass'
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
# None, with the "WithDefault... | 3 | 2008-09-26T22:17:59Z | [
"python",
"http",
"proxy"
] |
How to specify an authenticated proxy for a python http connection? | 34,079 | <p>What's the best way to specify a proxy with username and password for an http connection in python?</p>
| 44 | 2008-08-29T06:55:54Z | 3,942,980 | <p>Setting an environment var named <strong>http_proxy</strong> like this: <strong>http://username:password@proxy_url:port</strong></p>
| 11 | 2010-10-15T14:06:56Z | [
"python",
"http",
"proxy"
] |
How to specify an authenticated proxy for a python http connection? | 34,079 | <p>What's the best way to specify a proxy with username and password for an http connection in python?</p>
| 44 | 2008-08-29T06:55:54Z | 36,216,636 | <p>Here is the method use urllib </p>
<pre><code>import urllib.request
# set up authentication info
authinfo = urllib.request.HTTPBasicAuthHandler()
proxy_support = urllib.request.ProxyHandler({"http" : "http://ahad-haam:3128"})
# build a new opener that adds authentication and caching FTP handlers
opener = urllib.r... | 0 | 2016-03-25T08:37:45Z | [
"python",
"http",
"proxy"
] |
Django ImageField core=False in newforms admin | 34,209 | <p>In the transition to newforms admin I'm having difficulty figuring out how specify core=False for ImageFields.</p>
<p>I get the following error:</p>
<pre><code>TypeError: __init__() got an unexpected keyword argument 'core'
</code></pre>
<p>[Edit] However, by just removing the core argument I get a "This field is... | 1 | 2008-08-29T09:03:27Z | 34,391 | <p>This is simple. I started getting this problems a few revisions ago. Basically, just remove the "core=True" parameter in the ImageField in the models, and then follow the instructions <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects" rel="nofollow">here</a> to convert to what... | 2 | 2008-08-29T11:39:27Z | [
"python",
"django",
"django-models"
] |
Django ImageField core=False in newforms admin | 34,209 | <p>In the transition to newforms admin I'm having difficulty figuring out how specify core=False for ImageFields.</p>
<p>I get the following error:</p>
<pre><code>TypeError: __init__() got an unexpected keyword argument 'core'
</code></pre>
<p>[Edit] However, by just removing the core argument I get a "This field is... | 1 | 2008-08-29T09:03:27Z | 35,089 | <p>The <code>core</code> attribute isn't used anymore.</p>
<p>From <a href="http://oebfare.com/blog/2008/jul/20/newforms-admin-migration-and-screencast/" rel="nofollow">Brian Rosner's Blog</a>:</p>
<blockquote>
<p>You can safely just remove any and all <code>core</code> arguments. They are no longer used. <em>newfo... | 3 | 2008-08-29T19:20:47Z | [
"python",
"django",
"django-models"
] |
Django ImageField core=False in newforms admin | 34,209 | <p>In the transition to newforms admin I'm having difficulty figuring out how specify core=False for ImageFields.</p>
<p>I get the following error:</p>
<pre><code>TypeError: __init__() got an unexpected keyword argument 'core'
</code></pre>
<p>[Edit] However, by just removing the core argument I get a "This field is... | 1 | 2008-08-29T09:03:27Z | 35,633 | <p>To get rid of "This field is required," you need to make it not required, by using blank=True (and possibly null=True as well, if it's not a CharField).</p>
| 3 | 2008-08-30T03:04:44Z | [
"python",
"django",
"django-models"
] |
Python descriptor protocol analog in other languages? | 34,243 | <p>Is there something like the Python descriptor protocol implemented in other languages? It seems like a nice way to increase modularity/encapsulation without bloating your containing class' implementation, but I've never heard of a similar thing in any other languages. Is it likely absent from other languages because... | 8 | 2008-08-29T09:24:08Z | 34,266 | <p>I've not heard of a direct equivalent either. You could probably achieve the same effect with macros, especially in a language like Lisp which has extremely powerful macros.</p>
<p>I wouldn't be at all surprised if other languages start to incorporate something similar because it is so powerful.</p>
| 4 | 2008-08-29T09:39:47Z | [
"python",
"language-features",
"encapsulation"
] |
Python descriptor protocol analog in other languages? | 34,243 | <p>Is there something like the Python descriptor protocol implemented in other languages? It seems like a nice way to increase modularity/encapsulation without bloating your containing class' implementation, but I've never heard of a similar thing in any other languages. Is it likely absent from other languages because... | 8 | 2008-08-29T09:24:08Z | 48,974 | <p>Ruby and C# both easily let you create accessors by specifying getter/setter methods for an attribute, much like in Python. However, this isn't designed to naturally let you write the code for these methods in another class the way that Python allows. In practice, I'm not sure how much this matters, since every ti... | 0 | 2008-09-08T01:31:32Z | [
"python",
"language-features",
"encapsulation"
] |
How do I make Windows aware of a service I have written in Python? | 34,328 | <p>In <a href="http://stackoverflow.com/questions/32404/can-i-run-a-python-script-as-a-service-in-windows-how" rel="nofollow" title="Python scripts as Windows service">another question</a> I posted yesterday, I got very good advice on how a Python script could be run as a service in Windows. What I'm left wondering is:... | 10 | 2008-08-29T10:18:21Z | 34,330 | <p>Here is code to install a python-script as a service, written in python :)</p>
<p><a href="http://code.activestate.com/recipes/551780/">http://code.activestate.com/recipes/551780/</a></p>
<p>This post could also help you out:</p>
<p><a href="http://essiene.blogspot.com/2005/04/python-windows-services.html">http:/... | 8 | 2008-08-29T10:20:39Z | [
"python",
"windows",
"cross-platform"
] |
How do I make Windows aware of a service I have written in Python? | 34,328 | <p>In <a href="http://stackoverflow.com/questions/32404/can-i-run-a-python-script-as-a-service-in-windows-how" rel="nofollow" title="Python scripts as Windows service">another question</a> I posted yesterday, I got very good advice on how a Python script could be run as a service in Windows. What I'm left wondering is:... | 10 | 2008-08-29T10:18:21Z | 34,418 | <p>As with most "aware" things in Windows, the answer is "Registry".</p>
<p>Take a look at this Microsoft Knowledge Base article: <a href="http://support.microsoft.com/kb/103000" rel="nofollow">http://support.microsoft.com/kb/103000</a></p>
<p>Search for "A Win32 program that can be started by the Service Controller ... | 3 | 2008-08-29T15:00:52Z | [
"python",
"windows",
"cross-platform"
] |
How do I make Windows aware of a service I have written in Python? | 34,328 | <p>In <a href="http://stackoverflow.com/questions/32404/can-i-run-a-python-script-as-a-service-in-windows-how" rel="nofollow" title="Python scripts as Windows service">another question</a> I posted yesterday, I got very good advice on how a Python script could be run as a service in Windows. What I'm left wondering is:... | 10 | 2008-08-29T10:18:21Z | 34,421 | <p>You can use srvany.exe from Windows NT Resource Kit to create a user defined service that will show up in the admin tools...</p>
<p><a href="http://support.microsoft.com/kb/137890" rel="nofollow">http://support.microsoft.com/kb/137890</a></p>
<p>I am using this method to run tracd (a python script / server) for tr... | 0 | 2008-08-29T15:01:50Z | [
"python",
"windows",
"cross-platform"
] |
How do I make Windows aware of a service I have written in Python? | 34,328 | <p>In <a href="http://stackoverflow.com/questions/32404/can-i-run-a-python-script-as-a-service-in-windows-how" rel="nofollow" title="Python scripts as Windows service">another question</a> I posted yesterday, I got very good advice on how a Python script could be run as a service in Windows. What I'm left wondering is:... | 10 | 2008-08-29T10:18:21Z | 259,438 | <p>Don't muck with the registry directly. User the SC command-line tool. Namely, SC CREATE</p>
<pre>
DESCRIPTION:
SC is a command line program used for communicating with the
NT Service Controller and services.
USAGE:
sc [command] [service name] ...
The option has the form "... | 5 | 2008-11-03T18:03:16Z | [
"python",
"windows",
"cross-platform"
] |
Finding what methods an object has | 34,439 | <p>Given a Python object of any kind, is there an easy way to get a list of all methods that this object has?<br>
Or,</p>
<p>if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?</p>
| 159 | 2008-08-29T15:05:17Z | 34,452 | <p>It appears you can use this code, replacing 'object' with the object you're interested in:-</p>
<pre><code>[method for method in dir(object) if callable(getattr(object, method))]
</code></pre>
<p>I discovered it at <a href="http://www.diveintopython.net/power_of_introspection/index.html">this site</a>, hopefully t... | 188 | 2008-08-29T15:09:05Z | [
"python",
"introspection"
] |
Finding what methods an object has | 34,439 | <p>Given a Python object of any kind, is there an easy way to get a list of all methods that this object has?<br>
Or,</p>
<p>if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?</p>
| 159 | 2008-08-29T15:05:17Z | 34,467 | <p>You can use the built in <code>dir()</code> function to get a list of all the attributes a module has. Try this at the command line to see how it works.</p>
<pre><code>>>> import moduleName
>>> dir(moduleName)
</code></pre>
<p>Also, you can use the <code>hasattr(module_name, "attr_name")</code> ... | 78 | 2008-08-29T15:36:55Z | [
"python",
"introspection"
] |
Finding what methods an object has | 34,439 | <p>Given a Python object of any kind, is there an easy way to get a list of all methods that this object has?<br>
Or,</p>
<p>if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?</p>
| 159 | 2008-08-29T15:05:17Z | 34,472 | <p>To check if it has a particular method:</p>
<pre><code>hasattr(object,"method")
</code></pre>
| 20 | 2008-08-29T15:40:05Z | [
"python",
"introspection"
] |
Finding what methods an object has | 34,439 | <p>Given a Python object of any kind, is there an easy way to get a list of all methods that this object has?<br>
Or,</p>
<p>if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?</p>
| 159 | 2008-08-29T15:05:17Z | 34,481 | <p>On top of the more direct answers, I'd be remiss if I didn't mention <a href="http://ipython.scipy.org/">iPython</a>.
Hit 'tab' to see the available methods, with autocompletion.</p>
<p>And once you've found a method, try:</p>
<pre><code>help(object.method)
</code></pre>
<p>to see the pydocs, method signature, e... | 11 | 2008-08-29T15:47:04Z | [
"python",
"introspection"
] |
Finding what methods an object has | 34,439 | <p>Given a Python object of any kind, is there an easy way to get a list of all methods that this object has?<br>
Or,</p>
<p>if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?</p>
| 159 | 2008-08-29T15:05:17Z | 15,640,132 | <blockquote>
<p>...is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called</p>
</blockquote>
<p>While "<a href="http://docs.python.org/2/glossary.html#term-eafp" rel="nofollow">Easier to ask for forgiveness than permission</a>" is c... | 1 | 2013-03-26T14:51:55Z | [
"python",
"introspection"
] |
Finding what methods an object has | 34,439 | <p>Given a Python object of any kind, is there an easy way to get a list of all methods that this object has?<br>
Or,</p>
<p>if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?</p>
| 159 | 2008-08-29T15:05:17Z | 20,100,900 | <p>The simplest method is to use dir(objectname). It will display all the methods available for that object. Cool trick.</p>
| 21 | 2013-11-20T16:06:27Z | [
"python",
"introspection"
] |
Finding what methods an object has | 34,439 | <p>Given a Python object of any kind, is there an easy way to get a list of all methods that this object has?<br>
Or,</p>
<p>if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?</p>
| 159 | 2008-08-29T15:05:17Z | 27,380,776 | <p>The problem with all methods indicated here is that you CAN'T be sure that a method doesn't exist.</p>
<p>In Python you can intercept the dot calling thru <code>__getattr__</code> and <code>__getattribute__</code>, making it possible to create method "at runtime"</p>
<p>Exemple:</p>
<pre><code>class MoreMethod(ob... | 4 | 2014-12-09T14:02:06Z | [
"python",
"introspection"
] |
Finding what methods an object has | 34,439 | <p>Given a Python object of any kind, is there an easy way to get a list of all methods that this object has?<br>
Or,</p>
<p>if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?</p>
| 159 | 2008-08-29T15:05:17Z | 28,220,562 | <p>If you specifically want <strong>methods</strong>, you should use <a href="https://docs.python.org/2/library/inspect.html#inspect.ismethod" rel="nofollow">inspect.ismethod</a>.</p>
<p>For method names:</p>
<pre><code>import inspect
method_names = [attr for attr in dir(self) if inspect.ismethod(getattr(self, attr))... | 4 | 2015-01-29T17:10:18Z | [
"python",
"introspection"
] |
Finding what methods an object has | 34,439 | <p>Given a Python object of any kind, is there an easy way to get a list of all methods that this object has?<br>
Or,</p>
<p>if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?</p>
| 159 | 2008-08-29T15:05:17Z | 29,851,741 | <p>One can create a <code>getAttrs</code> function that will return an object's callable property names</p>
<pre><code>def getAttrs(object):
return filter(lambda m: callable(getattr(object, m)), dir(object))
print getAttrs('Foo bar'.split(' '))
</code></pre>
<p>That'd return</p>
<pre><code>['__add__', '__class__'... | 1 | 2015-04-24T15:37:28Z | [
"python",
"introspection"
] |
Finding what methods an object has | 34,439 | <p>Given a Python object of any kind, is there an easy way to get a list of all methods that this object has?<br>
Or,</p>
<p>if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?</p>
| 159 | 2008-08-29T15:05:17Z | 32,608,298 | <p>There is no reliable way to list all object's methods. <code>dir(object)</code> is usually useful, but in some cases it may not list all methods. According to <a href="https://docs.python.org/2/library/functions.html#dir" rel="nofollow"><code>dir()</code> documentation</a>: <em>"With an argument, <strong>attempt</st... | 2 | 2015-09-16T12:13:18Z | [
"python",
"introspection"
] |
Finding what methods an object has | 34,439 | <p>Given a Python object of any kind, is there an easy way to get a list of all methods that this object has?<br>
Or,</p>
<p>if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?</p>
| 159 | 2008-08-29T15:05:17Z | 37,464,502 | <p>I believe that what you want is a something like this: a list of attributes/methods of your object. dir() built-in can do this job for you IMHO :).</p>
<pre><code>$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>... | 1 | 2016-05-26T14:58:48Z | [
"python",
"introspection"
] |
Scaffolding in pylons | 34,916 | <p>Is there anything similar to rails' scaffolding fo pylons? I've been poking around google, but fofund only this thing caled dbsprockets, which is fine, although probably way to much for my needs. What i really need is a basic CRUD thas is based on the SQLAlchemy model.</p>
| 8 | 2008-08-29T18:12:30Z | 35,110 | <p>I hear you, I've followed the Pylons mailing list for a while looking for something similar. There have been some attempts in the past (see <a href="http://adminpylon.devjavu.com/" rel="nofollow">AdminPylon</a> and <a href="http://code.google.com/p/restin/" rel="nofollow">Restin</a>) but none have really kept up wit... | 4 | 2008-08-29T19:30:29Z | [
"python",
"pylons"
] |
Scaffolding in pylons | 34,916 | <p>Is there anything similar to rails' scaffolding fo pylons? I've been poking around google, but fofund only this thing caled dbsprockets, which is fine, although probably way to much for my needs. What i really need is a basic CRUD thas is based on the SQLAlchemy model.</p>
| 8 | 2008-08-29T18:12:30Z | 1,056,092 | <p>The question is super old, but hell: <a href="http://code.google.com/p/formalchemy/" rel="nofollow">http://code.google.com/p/formalchemy/</a></p>
<p>Gives you basic crud out of the box, customizable to do even relatively complex things easily, and gives you a drop-in Pylons admin app too (written and customizable w... | 6 | 2009-06-29T00:02:20Z | [
"python",
"pylons"
] |
Scaffolding in pylons | 34,916 | <p>Is there anything similar to rails' scaffolding fo pylons? I've been poking around google, but fofund only this thing caled dbsprockets, which is fine, although probably way to much for my needs. What i really need is a basic CRUD thas is based on the SQLAlchemy model.</p>
| 8 | 2008-08-29T18:12:30Z | 1,869,967 | <p>Just updating an old question. DBSprockets has been replaced by <a href="http://sprox.org/" rel="nofollow">sprox</a> which learns a lot of lessons from it and is pretty cool.</p>
<p>It isn't quite the throwaway 'scaffolding' that Rails provides, it is more like an agile form generation tool that is highly extensibl... | 0 | 2009-12-08T21:28:30Z | [
"python",
"pylons"
] |
Validate (X)HTML in Python | 35,538 | <p>What's the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I'd like to be able to know where the failures occur, as in a web-based validator, except in a native Python app.</p>
| 21 | 2008-08-30T01:15:32Z | 35,543 | <p>XHTML is easy, use <a href="http://lxml.de/validation.html" rel="nofollow">lxml</a>.</p>
<p>HTML is harder, since there's traditionally not been as much interest in validation among the HTML crowd (run StackOverflow itself through a validator, yikes). The easiest solution would be to execute external applications s... | 7 | 2008-08-30T01:20:52Z | [
"python",
"html",
"validation",
"xhtml"
] |
Validate (X)HTML in Python | 35,538 | <p>What's the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I'd like to be able to know where the failures occur, as in a web-based validator, except in a native Python app.</p>
| 21 | 2008-08-30T01:15:32Z | 35,562 | <p>I think that <a href="http://tidy.sourceforge.net/" rel="nofollow">HTML tidy</a> will do what you want. There is a Python binding for it.</p>
| 3 | 2008-08-30T01:48:07Z | [
"python",
"html",
"validation",
"xhtml"
] |
Validate (X)HTML in Python | 35,538 | <p>What's the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I'd like to be able to know where the failures occur, as in a web-based validator, except in a native Python app.</p>
| 21 | 2008-08-30T01:15:32Z | 35,572 | <p>Try tidylib. You can get some really basic bindings as part of the elementtidy module (builds elementtrees from HTML documents). <a href="http://effbot.org/downloads/#elementtidy">http://effbot.org/downloads/#elementtidy</a></p>
<pre><code>>>> import _elementtidy
>>> xhtml, log = _elementtidy.fixu... | 5 | 2008-08-30T01:55:50Z | [
"python",
"html",
"validation",
"xhtml"
] |
Validate (X)HTML in Python | 35,538 | <p>What's the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I'd like to be able to know where the failures occur, as in a web-based validator, except in a native Python app.</p>
| 21 | 2008-08-30T01:15:32Z | 646,877 | <p>Starting with html5, you can try to use <a href="http://code.google.com/p/html5lib/">html5lib</a>. </p>
<p>You can also decide to install the HTML validator locally and create a client to request the validation. </p>
<p>Here I had made a program to validate a list of urls in a txt file. I was just checking the HEA... | 11 | 2009-03-14T22:42:12Z | [
"python",
"html",
"validation",
"xhtml"
] |
Validate (X)HTML in Python | 35,538 | <p>What's the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I'd like to be able to know where the failures occur, as in a web-based validator, except in a native Python app.</p>
| 21 | 2008-08-30T01:15:32Z | 1,279,293 | <p><a href="http://countergram.com/software/pytidylib">http://countergram.com/software/pytidylib</a> is a nice python binding for HTML Tidy. Their example:</p>
<pre><code>from tidylib import tidy_document
document, errors = tidy_document('''<p>f&otilde;o <img src="bar.jpg">''',
options={'numeric-e... | 18 | 2009-08-14T18:04:38Z | [
"python",
"html",
"validation",
"xhtml"
] |
Validate (X)HTML in Python | 35,538 | <p>What's the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I'd like to be able to know where the failures occur, as in a web-based validator, except in a native Python app.</p>
| 21 | 2008-08-30T01:15:32Z | 10,519,634 | <p>I think the most elegant way it to invoke the W3C Validation Service at</p>
<pre><code>http://validator.w3.org/
</code></pre>
<p>programmatically. Few people know that you do not have to screen-scrape the results in order to get the results, because the service returns non-standard HTTP header paramaters </p>
<pr... | 14 | 2012-05-09T15:53:46Z | [
"python",
"html",
"validation",
"xhtml"
] |
Validate (X)HTML in Python | 35,538 | <p>What's the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I'd like to be able to know where the failures occur, as in a web-based validator, except in a native Python app.</p>
| 21 | 2008-08-30T01:15:32Z | 39,336,630 | <p>In my case the python W3C/HTML validation packages did not work <code>pip search w3c</code> (as of sept 2016).</p>
<p>I solved this with</p>
<pre><code>$ pip install requests
$ python
Python 2.7.12 (default, Jun 29 2016, 12:46:54)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copy... | 0 | 2016-09-05T19:30:06Z | [
"python",
"html",
"validation",
"xhtml"
] |
Why does Python's iter() on a mapping return iterkeys() instead of iteritems()? | 35,569 | <p>It seems like if you want to get the keys of a mapping, you ask for them; otherwise, give me the <em>whole</em> mapping (constituted by a set of key-value pairs). Is there a historical reason for this?</p>
| 6 | 2008-08-30T01:51:05Z | 35,582 | <p>Check out <a href="http://mail.python.org/pipermail/python-3000/2007-September/010209.html" rel="nofollow">this thread</a> for a discussion on the reasons behind this behavior (including that Guido likes it, and it's <a href="http://mail.python.org/pipermail/python-3000/2007-September/010222.html" rel="nofollow">not... | 8 | 2008-08-30T02:01:57Z | [
"python",
"mapping",
"iteration"
] |
Ruby "is" equivalent | 35,634 | <p>Is there a Ruby equivalent for Python's "is"? It tests whether two objects are identical (i.e. have the same memory location).</p>
| 6 | 2008-08-30T03:04:54Z | 35,635 | <p>Use <code>a.equal? b</code></p>
<p><a href="http://www.ruby-doc.org/core/classes/Object.html">http://www.ruby-doc.org/core/classes/Object.html</a></p>
<blockquote>
<p>Unlike ==, the equal? method should never be overridden by subclasses: it is used to determine object identity (that is, a.equal?(b) iff a is the ... | 12 | 2008-08-30T03:06:02Z | [
"python",
"ruby"
] |
Ruby "is" equivalent | 35,634 | <p>Is there a Ruby equivalent for Python's "is"? It tests whether two objects are identical (i.e. have the same memory location).</p>
| 6 | 2008-08-30T03:04:54Z | 39,062 | <p>You could also use <code>__id__</code>. This gives you the objects internal ID number, which is always unique. To check if to objects are the same, try</p>
<blockquote>
<p><code>a.__id__ = b.__id__</code></p>
</blockquote>
<p>This is how Ruby's standard library does it as far as I can tell (see <code>group_by</c... | 2 | 2008-09-02T09:02:34Z | [
"python",
"ruby"
] |
Is Python good for big software projects (not web based)? | 35,753 | <p>Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity). </p>
<p>Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you... | 25 | 2008-08-30T07:08:22Z | 35,757 | <p>In my opinion python is more than ready for developing complex applications. I see pythons strength more on the server side than writing graphical clients. But have a look at <a href="http://www.resolversystems.com/" rel="nofollow">http://www.resolversystems.com/</a>. They develop a whole spreadsheet in python using... | 16 | 2008-08-30T07:19:40Z | [
"python",
"ide"
] |
Is Python good for big software projects (not web based)? | 35,753 | <p>Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity). </p>
<p>Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you... | 25 | 2008-08-30T07:08:22Z | 35,759 | <p>I really like python, it's usually my language of choice these days for small (non-gui) stuff that I do on my own.</p>
<p>However, for some larger Python projects I've tackled, I'm finding that it's not quite the same as programming in say, C++. I was working on a language parser, and needed to represent an AST in ... | 11 | 2008-08-30T07:22:03Z | [
"python",
"ide"
] |
Is Python good for big software projects (not web based)? | 35,753 | <p>Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity). </p>
<p>Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you... | 25 | 2008-08-30T07:08:22Z | 35,776 | <p>Python is considered (among Python programmers :) to be a great language for rapid prototyping. There's not a lot of extraneous syntax getting in the way of your thought processes, so most of the work you do tends to go into the code. (There's far less idioms required to be involved in writing good Python code than ... | 8 | 2008-08-30T08:21:18Z | [
"python",
"ide"
] |
Is Python good for big software projects (not web based)? | 35,753 | <p>Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity). </p>
<p>Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you... | 25 | 2008-08-30T07:08:22Z | 35,777 | <p>You'll find mostly two answers to that – the religous one (Yes! Of course! It's the best language ever!) and the other religious one (you gotta be kidding me! Python? No... it's not mature enough). I will maybe skip the last religion (Python?! Use Ruby!). The truth, as always, is far from obvious. </p>
<p><st... | 19 | 2008-08-30T08:21:24Z | [
"python",
"ide"
] |
Is Python good for big software projects (not web based)? | 35,753 | <p>Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity). </p>
<p>Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you... | 25 | 2008-08-30T07:08:22Z | 35,838 | <p>I know I'm probably stating the obvious, but don't forget that the quality of the development team and their familiarity with the technology will have a major impact on your ability to deliver. </p>
<p>If you have a strong team, then it's probably not an issue if they're familiar. But if you have people who are mor... | 0 | 2008-08-30T09:49:27Z | [
"python",
"ide"
] |
Is Python good for big software projects (not web based)? | 35,753 | <p>Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity). </p>
<p>Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you... | 25 | 2008-08-30T07:08:22Z | 35,841 | <p>Refactoring is inevitable on larger codebases and the lack of static typing makes this much harder in python than in statically typed languages.</p>
| 2 | 2008-08-30T09:53:02Z | [
"python",
"ide"
] |
Is Python good for big software projects (not web based)? | 35,753 | <p>Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity). </p>
<p>Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you... | 25 | 2008-08-30T07:08:22Z | 36,238 | <p>One way to judge what python is used for is to look at what products use python at the moment. This <a href="http://en.wikipedia.org/wiki/Python_software" rel="nofollow">wikipedia page</a> has a long list including various web frameworks, content management systems, version control systems, desktop apps and IDEs.</... | 4 | 2008-08-30T18:42:19Z | [
"python",
"ide"
] |
Is Python good for big software projects (not web based)? | 35,753 | <p>Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity). </p>
<p>Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you... | 25 | 2008-08-30T07:08:22Z | 259,591 | <p>We've used IronPython to build our flagship spreadsheet application (40kloc production code - and it's Python, which IMO means loc per feature is low) at <a href="http://www.resolversystems.com/">Resolver Systems</a>, so I'd definitely say it's ready for production use of complex apps.</p>
<p>There are two ways in ... | 28 | 2008-11-03T19:05:14Z | [
"python",
"ide"
] |
Is Python good for big software projects (not web based)? | 35,753 | <p>Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity). </p>
<p>Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you... | 25 | 2008-08-30T07:08:22Z | 263,761 | <p>Nothing to add to the other answers, <em>besides</em> that if you choose python you <strong>must</strong> use something like <a href="http://pypi.python.org/pypi/pylint" rel="nofollow">pylint</a> which nobody mentioned so far.</p>
| 4 | 2008-11-04T22:44:46Z | [
"python",
"ide"
] |
Is Python good for big software projects (not web based)? | 35,753 | <p>Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity). </p>
<p>Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you... | 25 | 2008-08-30T07:08:22Z | 277,490 | <p>I had only one python experience, my trash-cli project.</p>
<p>I know that probably some or all problems depends of my inexperience with python.</p>
<p>I found frustrating these things: </p>
<ol>
<li>the difficult of finding a good IDE for free</li>
<li>the limited support to automatic refactoring</li>
</ol>
<p>... | -1 | 2008-11-10T10:03:07Z | [
"python",
"ide"
] |
Is Python good for big software projects (not web based)? | 35,753 | <p>Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity). </p>
<p>Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you... | 25 | 2008-08-30T07:08:22Z | 286,449 | <blockquote>
<p>And as far as I know they use a lot of python inside google too.</p>
</blockquote>
<p>Well i'd hope so, the maker of python still works at google if i'm not mistaken? </p>
<p>As for the use of Python, i think it's a great language for stand-alone apps. It's heavily used in a lot of Linux programs, a... | 1 | 2008-11-13T07:36:28Z | [
"python",
"ide"
] |
Is Python good for big software projects (not web based)? | 35,753 | <p>Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity). </p>
<p>Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you... | 25 | 2008-08-30T07:08:22Z | 286,491 | <p>Python is a delight to use. I use it routinely and also write a lot of code for work in C#. There are two drawbacks to writing UI code in Python. one is that there is not a single ui framework that is accepted by the majority of the community. when you write in c# the .NET runtime and class libraries are all meant t... | 1 | 2008-11-13T08:12:21Z | [
"python",
"ide"
] |
Is Python good for big software projects (not web based)? | 35,753 | <p>Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity). </p>
<p>Except for the performances (a problem that could be sometimes solved thanks to the ease of interfacing Python with C modules), do you... | 25 | 2008-08-30T07:08:22Z | 3,445,481 | <p>Try Django or Pylons, write a simple app with both of them and then decide which one suits you best. There are others (like Turbogears or Werkzeug) but those are the most used.</p>
| 0 | 2010-08-10T01:51:26Z | [
"python",
"ide"
] |
Why is my instance variable not in __dict__? | 35,805 | <p>If I create a class <code>A</code> as follows:</p>
<pre><code>class A:
def __init__(self):
self.name = 'A'
</code></pre>
<p>Inspecting the <code>__dict__</code> member looks like <code>{'name': 'A'}</code></p>
<p>If however I create a class <code>B</code>:</p>
<pre><code>class B:
name = 'B'
</cod... | 27 | 2008-08-30T09:12:41Z | 35,823 | <p><code>B.name</code> is a class attribute, not an instance attribute. It shows up in <code>B.__dict__</code>, but not in <code>b = B(); b.__dict__</code>.</p>
<p>The distinction is obscured somewhat because when you access an attribute on an instance, the class dict is a fallback. So in the above example, <code>b.... | 38 | 2008-08-30T09:33:00Z | [
"python"
] |
Why is my instance variable not in __dict__? | 35,805 | <p>If I create a class <code>A</code> as follows:</p>
<pre><code>class A:
def __init__(self):
self.name = 'A'
</code></pre>
<p>Inspecting the <code>__dict__</code> member looks like <code>{'name': 'A'}</code></p>
<p>If however I create a class <code>B</code>:</p>
<pre><code>class B:
name = 'B'
</cod... | 27 | 2008-08-30T09:12:41Z | 39,755 | <pre><code>class A:
def _ _init_ _(self):
self.name = 'A'
a = A()
</code></pre>
<p>Creates an attribute on the object instance a of type A and it can therefore be found in: <code>a.__dict__</code></p>
<pre><code>class B:
name = 'B'
b = B()
</code></pre>
<p>Creates an attribute on the class B and the ... | 11 | 2008-09-02T15:12:12Z | [
"python"
] |
How to escape os.system() calls in Python? | 35,817 | <p>When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash.</p>
<p>I'm currently doing the following, but am sure there must be a libra... | 72 | 2008-08-30T09:27:24Z | 35,831 | <p>I believe that os.system just invokes whatever command shell is configured for the user, so I don't think you can do it in a platform independent way. My command shell could be anything from bash, emacs, ruby, or even quake3. Some of these programs aren't expecting the kind of arguments you are passing to them and... | 3 | 2008-08-30T09:43:50Z | [
"python",
"shell",
"escaping"
] |
How to escape os.system() calls in Python? | 35,817 | <p>When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash.</p>
<p>I'm currently doing the following, but am sure there must be a libra... | 72 | 2008-08-30T09:27:24Z | 35,857 | <p>This is what I use:</p>
<pre><code>def shellquote(s):
return "'" + s.replace("'", "'\\''") + "'"
</code></pre>
<p>The shell will always accept a quoted filename and remove the surrounding quotes before passing it to the program in question. Notably, this avoids problems with filenames that contain spaces or an... | 44 | 2008-08-30T10:13:11Z | [
"python",
"shell",
"escaping"
] |
How to escape os.system() calls in Python? | 35,817 | <p>When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash.</p>
<p>I'm currently doing the following, but am sure there must be a libra... | 72 | 2008-08-30T09:27:24Z | 35,858 | <p>Perhaps you have a specific reason for using <code>os.system()</code>. But if not you should probably be using the <a href="http://docs.python.org/lib/module-subprocess.html"><code>subprocess</code> module</a>. You can specify the pipes directly and avoid using the shell.</p>
<p>The following is from <a href="http:... | 49 | 2008-08-30T10:15:02Z | [
"python",
"shell",
"escaping"
] |
How to escape os.system() calls in Python? | 35,817 | <p>When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash.</p>
<p>I'm currently doing the following, but am sure there must be a libra... | 72 | 2008-08-30T09:27:24Z | 35,900 | <p>If you do use the system command, I would try and whitelist what goes into the os.system() call.. For example..</p>
<pre><code>clean_user_input re.sub("[^a-zA-Z]", "", user_input)
os.system("ls %s" % (clean_user_input))
</code></pre>
<p>The subprocess module is a better option, and I would recommend trying to avoi... | -2 | 2008-08-30T11:43:44Z | [
"python",
"shell",
"escaping"
] |
How to escape os.system() calls in Python? | 35,817 | <p>When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash.</p>
<p>I'm currently doing the following, but am sure there must be a libra... | 72 | 2008-08-30T09:27:24Z | 847,800 | <p><a href="https://docs.python.org/3/library/shlex.html#shlex.quote"><code>shlex.quote()</code></a> does what you want since python 3.</p>
<p>(Use <a href="https://docs.python.org/2/library/pipes.html#pipes.quote"><code>pipes.quote</code></a> to support both python 2 and python 3)</p>
| 101 | 2009-05-11T12:06:40Z | [
"python",
"shell",
"escaping"
] |
How to escape os.system() calls in Python? | 35,817 | <p>When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash.</p>
<p>I'm currently doing the following, but am sure there must be a libra... | 72 | 2008-08-30T09:27:24Z | 1,884,718 | <p>Note that pipes.quote is actually broken in Python 2.5 and Python 3.1 and not safe to use--It doesn't handle zero-length arguments.</p>
<pre><code>>>> from pipes import quote
>>> args = ['arg1', '', 'arg3']
>>> print 'mycommand %s' % (' '.join(quote(arg) for arg in args))
mycommand arg1 ... | 4 | 2009-12-10T23:03:55Z | [
"python",
"shell",
"escaping"
] |
How to escape os.system() calls in Python? | 35,817 | <p>When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash.</p>
<p>I'm currently doing the following, but am sure there must be a libra... | 72 | 2008-08-30T09:27:24Z | 3,851,646 | <p>The function I use is:</p>
<pre><code>def quote_argument(argument):
return '"%s"' % (
argument
.replace('\\', '\\\\')
.replace('"', '\\"')
.replace('$', '\\$')
.replace('`', '\\`')
)
</code></pre>
<p>that is: I always enclose the argument in double quotes, and then b... | 1 | 2010-10-03T21:21:44Z | [
"python",
"shell",
"escaping"
] |
How to escape os.system() calls in Python? | 35,817 | <p>When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash.</p>
<p>I'm currently doing the following, but am sure there must be a libra... | 72 | 2008-08-30T09:27:24Z | 10,750,633 | <p>Maybe <code>subprocess.list2cmdline</code> is a better shot?</p>
| 7 | 2012-05-25T07:54:41Z | [
"python",
"shell",
"escaping"
] |
How to escape os.system() calls in Python? | 35,817 | <p>When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash.</p>
<p>I'm currently doing the following, but am sure there must be a libra... | 72 | 2008-08-30T09:27:24Z | 16,210,253 | <p>The real answer is: Don't use <code>os.system()</code> in the first place. Use <a href="http://docs.python.org/2/library/subprocess.html#subprocess.call" rel="nofollow"><code>subprocess.call</code></a> instead and supply the unescaped arguments.</p>
| -2 | 2013-04-25T08:44:50Z | [
"python",
"shell",
"escaping"
] |
How to escape os.system() calls in Python? | 35,817 | <p>When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash.</p>
<p>I'm currently doing the following, but am sure there must be a libra... | 72 | 2008-08-30T09:27:24Z | 29,597,408 | <p><strong>Notice</strong>: This is an answer for Python 2.7.x.</p>
<p>According to the <a href="https://hg.python.org/cpython/file/2.7/Lib/pipes.py#l262" rel="nofollow">source</a>, <code>pipes.quote()</code> is a way to "<em>Reliably quote a string as a single argument for <strong>/bin/sh</em></strong>". (Although it... | 2 | 2015-04-13T03:26:35Z | [
"python",
"shell",
"escaping"
] |
Django templates and variable attributes | 35,948 | <p>I'm using Google App Engine and Django templates.<br>
I have a table that I want to display the objects look something like:<br></p>
<pre><code>Object Result:
Items = [item1,item2]
Users = [{name='username',item1=3,item2=4},..]
</code></pre>
<p>The Django template is:</p>
<pre><code><table>
<tr a... | 30 | 2008-08-30T13:20:02Z | 35,978 | <p>I'm assuming that the part the doesn't work is <code>{{ user.item }}</code>.</p>
<p>Django will be trying a dictionary lookup, but using the string <code>"item"</code> and not the value of the <code>item</code> loop variable. Django did the same thing when it resolved <code>{{ user.name }}</code> to the <code>nam... | 9 | 2008-08-30T14:16:54Z | [
"python",
"django",
"google-app-engine"
] |
Django templates and variable attributes | 35,948 | <p>I'm using Google App Engine and Django templates.<br>
I have a table that I want to display the objects look something like:<br></p>
<pre><code>Object Result:
Items = [item1,item2]
Users = [{name='username',item1=3,item2=4},..]
</code></pre>
<p>The Django template is:</p>
<pre><code><table>
<tr a... | 30 | 2008-08-30T13:20:02Z | 37,190 | <p>shouldn't this:</p>
<pre><code>{{ user.item }}
</code></pre>
<p>be this?</p>
<pre><code>{{ item }}
</code></pre>
<p>there is no user object in the context within that loop....?</p>
| 0 | 2008-08-31T22:29:14Z | [
"python",
"django",
"google-app-engine"
] |
Django templates and variable attributes | 35,948 | <p>I'm using Google App Engine and Django templates.<br>
I have a table that I want to display the objects look something like:<br></p>
<pre><code>Object Result:
Items = [item1,item2]
Users = [{name='username',item1=3,item2=4},..]
</code></pre>
<p>The Django template is:</p>
<pre><code><table>
<tr a... | 30 | 2008-08-30T13:20:02Z | 50,425 | <p>I found a "nicer"/"better" solution for getting variables inside
Its not the nicest way, but it works.</p>
<p>You install a custom filter into django which gets the key of your dict as a parameter</p>
<p>To make it work in google app-engine you need to add a file to your main directory,
I called mine *django_hack.... | 30 | 2008-09-08T19:01:24Z | [
"python",
"django",
"google-app-engine"
] |
Django templates and variable attributes | 35,948 | <p>I'm using Google App Engine and Django templates.<br>
I have a table that I want to display the objects look something like:<br></p>
<pre><code>Object Result:
Items = [item1,item2]
Users = [{name='username',item1=3,item2=4},..]
</code></pre>
<p>The Django template is:</p>
<pre><code><table>
<tr a... | 30 | 2008-08-30T13:20:02Z | 1,278,623 | <p>@Dave Webb (i haven't been rated high enough to comment yet)</p>
<p>The dot lookups can be summarized like this: when the template system encounters a dot in a variable name, it tries the following lookups, in this order:</p>
<pre><code>* Dictionary lookup (e.e., foo["bar"])
* Attribute lookup (e.g., foo.bar)
* Me... | 3 | 2009-08-14T15:45:39Z | [
"python",
"django",
"google-app-engine"
] |
Django templates and variable attributes | 35,948 | <p>I'm using Google App Engine and Django templates.<br>
I have a table that I want to display the objects look something like:<br></p>
<pre><code>Object Result:
Items = [item1,item2]
Users = [{name='username',item1=3,item2=4},..]
</code></pre>
<p>The Django template is:</p>
<pre><code><table>
<tr a... | 30 | 2008-08-30T13:20:02Z | 3,125,956 | <p>As a replacement for k,v in user.items on Google App Engine using django templates where user = {'a':1, 'b', 2, 'c', 3}</p>
<pre><code>{% for pair in user.items %}
{% for keyval in pair %} {{ keyval }}{% endfor %}<br>
{% endfor %}
</code></pre>
<p>a 1<br>
b 2<br>
c 3<br></p>
<p>pair = (key, value) for ea... | 1 | 2010-06-27T00:34:47Z | [
"python",
"django",
"google-app-engine"
] |
Django templates and variable attributes | 35,948 | <p>I'm using Google App Engine and Django templates.<br>
I have a table that I want to display the objects look something like:<br></p>
<pre><code>Object Result:
Items = [item1,item2]
Users = [{name='username',item1=3,item2=4},..]
</code></pre>
<p>The Django template is:</p>
<pre><code><table>
<tr a... | 30 | 2008-08-30T13:20:02Z | 3,466,349 | <p>Or you can use the default django system which is used to resolve attributes in tempaltes like this : </p>
<pre><code>from django.template import Variable, VariableDoesNotExist
@register.filter
def hash(object, attr):
pseudo_context = { 'object' : object }
try:
value = Variable('object.%s' % attr).r... | 7 | 2010-08-12T09:36:35Z | [
"python",
"django",
"google-app-engine"
] |
C-like structures in Python | 35,988 | <p>Is there a way to conveniently define a C-like structure in Python? I'm tired of writing stuff like:</p>
<pre><code>class MyStruct():
def __init__(self, field1, field2, field3):
self.field1 = field1
self.field2 = field2
self.field3 = field3
</code></pre>
| 210 | 2008-08-30T14:33:25Z | 35,990 | <p>How about a dictionary?</p>
<p>Something like this:</p>
<pre><code>myStruct = {'field1': 'some val', 'field2': 'some val'}
</code></pre>
<p>Then you can use this to manipulate values:</p>
<pre><code>print myStruct['field1']
myStruct['field2'] = 'some other values'
</code></pre>
<p>And the values don't have to b... | 47 | 2008-08-30T14:35:29Z | [
"python",
"struct"
] |
C-like structures in Python | 35,988 | <p>Is there a way to conveniently define a C-like structure in Python? I'm tired of writing stuff like:</p>
<pre><code>class MyStruct():
def __init__(self, field1, field2, field3):
self.field1 = field1
self.field2 = field2
self.field3 = field3
</code></pre>
| 210 | 2008-08-30T14:33:25Z | 35,993 | <p>You can use a tuple for a lot of things where you would use a struct in C (something like x,y coordinates or RGB colors for example).</p>
<p>For everything else you can use dictionary, or a utility class like <a href="http://code.activestate.com/recipes/52308/">this one</a>:</p>
<pre><code>>>> class Bunch... | 70 | 2008-08-30T14:38:38Z | [
"python",
"struct"
] |
C-like structures in Python | 35,988 | <p>Is there a way to conveniently define a C-like structure in Python? I'm tired of writing stuff like:</p>
<pre><code>class MyStruct():
def __init__(self, field1, field2, field3):
self.field1 = field1
self.field2 = field2
self.field3 = field3
</code></pre>
| 210 | 2008-08-30T14:33:25Z | 36,033 | <p>Use a <a href="https://docs.python.org/2/library/collections.html#collections.namedtuple">named tuple</a>, which was added to the <a href="http://docs.python.org/library/collections.html">collections module</a> in the standard library in Python 2.6. It's also possible to use Raymond Hettinger's <a href="http://code.... | 202 | 2008-08-30T15:18:59Z | [
"python",
"struct"
] |
C-like structures in Python | 35,988 | <p>Is there a way to conveniently define a C-like structure in Python? I'm tired of writing stuff like:</p>
<pre><code>class MyStruct():
def __init__(self, field1, field2, field3):
self.field1 = field1
self.field2 = field2
self.field3 = field3
</code></pre>
| 210 | 2008-08-30T14:33:25Z | 36,034 | <blockquote>
<p>dF: that's pretty cool... I didn't
know that I could access the fields in
a class using dict.</p>
<p>Mark: the situations that I wish I had
this are precisely when I want a tuple
but nothing as "heavy" as a
dictionary.</p>
</blockquote>
<p>You can access the fields of a class using a d... | 17 | 2008-08-30T15:20:15Z | [
"python",
"struct"
] |
C-like structures in Python | 35,988 | <p>Is there a way to conveniently define a C-like structure in Python? I'm tired of writing stuff like:</p>
<pre><code>class MyStruct():
def __init__(self, field1, field2, field3):
self.field1 = field1
self.field2 = field2
self.field3 = field3
</code></pre>
| 210 | 2008-08-30T14:33:25Z | 36,061 | <p>You can also pass the init parameters to the instance variables by position</p>
<pre><code># Abstract struct class
class Struct:
def __init__ (self, *argv, **argd):
if len(argd):
# Update by dictionary
self.__dict__.update (argd)
else:
# Update by posit... | 13 | 2008-08-30T15:53:10Z | [
"python",
"struct"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.