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 do I use a regular expression to match a name? | 2,317,134 | <p>I am a newbie in Python. I want to write a regular expression for some name checking.
My input string can contain a-z, A-Z, 0-9, and ' _ ', but it should start with either a-z or A-Z (not 0-9 and ' _ '). I want to write a regular expression for this. I tried, but nothing was matching perfectly.</p>
<p>Once the inp... | 5 | 2010-02-23T09:52:53Z | 2,317,153 | <pre><code>>>> import re
>>> re.match("[a-zA-Z][\w-]*$","A")
<_sre.SRE_Match object at 0x00932E20>
>>> re.match("[a-zA-Z][\w-]*$","A_B")
<_sre.SRE_Match object at 0x008CA950>
>>> re.match("[a-zA-Z][\w-]*$","0A")
>>>
>>> re.match("[a-zA-Z][\w-]*$","!A... | 4 | 2010-02-23T09:58:04Z | [
"python",
"regex"
] |
How do I use a regular expression to match a name? | 2,317,134 | <p>I am a newbie in Python. I want to write a regular expression for some name checking.
My input string can contain a-z, A-Z, 0-9, and ' _ ', but it should start with either a-z or A-Z (not 0-9 and ' _ '). I want to write a regular expression for this. I tried, but nothing was matching perfectly.</p>
<p>Once the inp... | 5 | 2010-02-23T09:52:53Z | 2,318,190 | <p>Here's an answer to your question:</p>
<p>Interpreting that you want <code>_</code> (not <code>-</code>), this should do the job:</p>
<pre><code>>>> tests = ["a", "A", "a1", "a_1", "1a", "_a", "a\n", "", "z_"]
>>> for test in tests:
... print repr(test), bool(re.match(r"[A-Za-z]\w*\Z", test))
... | 4 | 2010-02-23T12:51:13Z | [
"python",
"regex"
] |
How do I use a regular expression to match a name? | 2,317,134 | <p>I am a newbie in Python. I want to write a regular expression for some name checking.
My input string can contain a-z, A-Z, 0-9, and ' _ ', but it should start with either a-z or A-Z (not 0-9 and ' _ '). I want to write a regular expression for this. I tried, but nothing was matching perfectly.</p>
<p>Once the inp... | 5 | 2010-02-23T09:52:53Z | 2,318,813 | <p>here's a non re way</p>
<pre><code>import string
flag=0
mystring="abcadsf123"
if not mystring[0] in string.digits+"_":
for c in mystring:
if not c in string.letters+string.digits+"-":
flag=1
if flag: print "%s not ok" % mystring
else: print "%s ok" % mystring
else: print "%s starts wit... | -1 | 2010-02-23T14:27:36Z | [
"python",
"regex"
] |
setting windows live messenger nick and status message using win32com.client | 2,317,175 | <p>is their any way to set windows live messenger using the win32com library ? </p>
| 0 | 2010-02-23T10:02:57Z | 2,317,244 | <p><a href="http://social.msdn.microsoft.com/Forums/en/wlmessengerapidev/thread/f0b08334-883a-42b9-b79c-8f1f899e65d6" rel="nofollow">This thread</a> at MSDN forum discusses the topic thoroughly.</p>
<p>In short, you can do it with <a href="http://msdn.microsoft.com/en-us/library/dd570146.aspx" rel="nofollow">this API<... | 0 | 2010-02-23T10:14:52Z | [
"python",
"windows",
"live",
"windows-live-messenger"
] |
Django group / aggregation | 2,317,374 | <p>I have following structure with example data:</p>
<pre><code>id season_id title
1 1 Intro
2 1 Second part
3 1 Third part
4 4 Other intro
5 4 Other second part
</code></pre>
<p>(don't ask why), where season_id is always point to id of first... | 1 | 2010-02-23T10:39:44Z | 2,318,188 | <p>Movie.objects.annotate(category_min_season = models.Min('category__season_id')).filter(season_id=category_min_season)</p>
<p>assuming that your catgory has FK to the Movies model.</p>
<p>Update:</p>
<p>Actually you don't even need annotation; thanks to the denormalised data you have stored in the table.</p>
<p>Y... | 1 | 2010-02-23T12:50:50Z | [
"python",
"django",
"orm",
"group-by",
"annotate"
] |
PIP: Installing only the dependencies | 2,317,410 | <p>I have a script that creates a <code>virtualenv</code>, installs <code>distribute</code> and <code>pip</code> in it and then optionally clones a <code>git</code> repo.</p>
<p>Now I have the project I will be working on, installed. But its dependencies are not installed. How can I make <code>pip</code> install all t... | 10 | 2010-02-23T10:44:38Z | 2,318,246 | <p>You should use the pip requirements file.</p>
<p>Essentially, place all your requirements, one in each line in a file and pass that to pip using the command </p>
<pre><code>pip install -r requirements.txt
</code></pre>
<p>What more, if you have a standard environment, pip can actually dump such a file from existi... | 13 | 2010-02-23T12:59:39Z | [
"python",
"distribution",
"virtualenv",
"pip",
"distribute"
] |
PIP: Installing only the dependencies | 2,317,410 | <p>I have a script that creates a <code>virtualenv</code>, installs <code>distribute</code> and <code>pip</code> in it and then optionally clones a <code>git</code> repo.</p>
<p>Now I have the project I will be working on, installed. But its dependencies are not installed. How can I make <code>pip</code> install all t... | 10 | 2010-02-23T10:44:38Z | 2,354,586 | <p>In my package root issuing <code>pip install -e .</code> installs dependencies.</p>
| 14 | 2010-03-01T08:31:43Z | [
"python",
"distribution",
"virtualenv",
"pip",
"distribute"
] |
Django count RawQuerySet | 2,317,452 | <p>Hay, I'm using django 1.2 and i want to know how to count rows from a raw queryset(RawQuerySet).</p>
<p>The traditional .count() method doesn't work.</p>
<p>Heres my query</p>
<pre><code>query = "SELECT *, ((ACOS(SIN(%s * PI() / 180) * SIN(lat * PI() / 180) + COS(%s * PI() / 180) * COS(lat * PI() / 180) * COS((%s... | 15 | 2010-02-23T10:52:45Z | 2,317,552 | <p>Use the 'len()' function. This would give:</p>
<pre><code>query = "SELECT *, ((ACOS(SIN(%s * PI() / 180) * SIN(lat * PI() / 180) + COS(%s * PI() / 180) * COS(lat * PI() / 180) * COS((%s - lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance FROM app_car WHERE price BETWEEN %s AND %s HAVING distance<=%s O... | 16 | 2010-02-23T11:09:44Z | [
"python",
"django",
"count"
] |
Django count RawQuerySet | 2,317,452 | <p>Hay, I'm using django 1.2 and i want to know how to count rows from a raw queryset(RawQuerySet).</p>
<p>The traditional .count() method doesn't work.</p>
<p>Heres my query</p>
<pre><code>query = "SELECT *, ((ACOS(SIN(%s * PI() / 180) * SIN(lat * PI() / 180) + COS(%s * PI() / 180) * COS(lat * PI() / 180) * COS((%s... | 15 | 2010-02-23T10:52:45Z | 14,761,914 | <p>The reason there is no 'count' is because you would need an extra "count(*)" query to the database to know the size of your result set.</p>
<p>So bear in mind that calling <code>list(cars)</code> is loading all your results into memory. This allows you to get the count with <code>len</code>, but may be an expensive... | 1 | 2013-02-07T22:06:09Z | [
"python",
"django",
"count"
] |
Django count RawQuerySet | 2,317,452 | <p>Hay, I'm using django 1.2 and i want to know how to count rows from a raw queryset(RawQuerySet).</p>
<p>The traditional .count() method doesn't work.</p>
<p>Heres my query</p>
<pre><code>query = "SELECT *, ((ACOS(SIN(%s * PI() / 180) * SIN(lat * PI() / 180) + COS(%s * PI() / 180) * COS(lat * PI() / 180) * COS((%s... | 15 | 2010-02-23T10:52:45Z | 18,179,123 | <p>Truth be told, if all you want is the total number of records in the RawQuerySet, then by all means you should avoid casting the RawQuerySet into a list.</p>
<p>Casting the RawQuerySet into a list will iterate through each record matching the query. This is potentially burdensome for the server. Use count(<em>) ins... | 6 | 2013-08-12T03:21:19Z | [
"python",
"django",
"count"
] |
Django count RawQuerySet | 2,317,452 | <p>Hay, I'm using django 1.2 and i want to know how to count rows from a raw queryset(RawQuerySet).</p>
<p>The traditional .count() method doesn't work.</p>
<p>Heres my query</p>
<pre><code>query = "SELECT *, ((ACOS(SIN(%s * PI() / 180) * SIN(lat * PI() / 180) + COS(%s * PI() / 180) * COS(lat * PI() / 180) * COS((%s... | 15 | 2010-02-23T10:52:45Z | 36,069,542 | <p>Here is the improved solution that is based on user871977's:</p>
<pre><code>from django.db import connection
def get_len(rawqueryset):
def __len__(self):
params = ["""'%s'""" % p for p in self.params]
sql = 'SELECT COUNT(*) FROM (' + (rawqueryset.raw_query % tuple(params)) + ') B;'
curs... | 0 | 2016-03-17T19:06:22Z | [
"python",
"django",
"count"
] |
Asynchronous COMET query with Tornado and Prototype | 2,317,501 | <p>I'm trying to write simple web application using Tornado and JS Prototype library. So, the client can execute long running job on server. I wish, that this job runs Asynchronously - so that others clients could view page and do some stuff there.</p>
<p>Here what i've got:</p>
<pre><code>#!/usr/bin/env/ pytthon
im... | 9 | 2010-02-23T11:00:53Z | 2,430,614 | <p>Tornado is single-threaded web server. Your while loop in <code>wait_for_smith</code> method is blocking Tornado.</p>
<p>You can rewrite that method like this:</p>
<pre><code>def wait_for_smth(self, callback, t=10):
if t:
print "Sleeping 2 second, t=%s" % t
tornado.ioloop.IOLoop.instance().add_... | 15 | 2010-03-12T05:05:43Z | [
"python",
"ajax",
"comet",
"long-polling",
"tornado"
] |
Asynchronous COMET query with Tornado and Prototype | 2,317,501 | <p>I'm trying to write simple web application using Tornado and JS Prototype library. So, the client can execute long running job on server. I wish, that this job runs Asynchronously - so that others clients could view page and do some stuff there.</p>
<p>Here what i've got:</p>
<pre><code>#!/usr/bin/env/ pytthon
im... | 9 | 2010-02-23T11:00:53Z | 3,398,561 | <p>I've converted Tornado's chat example to run on <a href="http://www.gevent.org/" rel="nofollow">gevent</a>. Take a look at <a href="http://chat.gevent.org" rel="nofollow">the live demo here</a> and <a href="http://blog.gevent.org/2009/10/10/simpler-long-polling-with-django-and-gevent/" rel="nofollow">the explanation... | 0 | 2010-08-03T16:26:28Z | [
"python",
"ajax",
"comet",
"long-polling",
"tornado"
] |
Asynchronous COMET query with Tornado and Prototype | 2,317,501 | <p>I'm trying to write simple web application using Tornado and JS Prototype library. So, the client can execute long running job on server. I wish, that this job runs Asynchronously - so that others clients could view page and do some stuff there.</p>
<p>Here what i've got:</p>
<pre><code>#!/usr/bin/env/ pytthon
im... | 9 | 2010-02-23T11:00:53Z | 6,484,273 | <pre><code>function test(){
new Ajax.Request("http://172.22.22.22:8888/longPolling",
{
method:"get",
asynchronous:true,
onSuccess: function (transport){
alert(transport.responseText);
}
})
}
<... | 1 | 2011-06-26T13:34:29Z | [
"python",
"ajax",
"comet",
"long-polling",
"tornado"
] |
Asynchronous COMET query with Tornado and Prototype | 2,317,501 | <p>I'm trying to write simple web application using Tornado and JS Prototype library. So, the client can execute long running job on server. I wish, that this job runs Asynchronously - so that others clients could view page and do some stuff there.</p>
<p>Here what i've got:</p>
<pre><code>#!/usr/bin/env/ pytthon
im... | 9 | 2010-02-23T11:00:53Z | 9,444,544 | <p>I have read the book called <a href="http://rads.stackoverflow.com/amzn/click/0596806159" rel="nofollow">"Building the Realtime User Experience"</a> by Ted Roden, and it was very helpful. I have managed to create a complex realtime chat system using Tornado (python). I recommend this book to be read as well as <a hr... | 0 | 2012-02-25T13:50:44Z | [
"python",
"ajax",
"comet",
"long-polling",
"tornado"
] |
XML file using Python | 2,317,626 | <p>I have made a XML file using python. How can I retrieve an element from it? Will you help me with the code?</p>
<p>Also I need to have my output (i.e. element of each attribute come in separate lines in that particular XML file).</p>
| -1 | 2010-02-23T11:24:36Z | 2,317,700 | <p>Python comes with 2 modules for xml processing <a href="http://docs.python.org/library/xml.dom.minidom.html" rel="nofollow">mindom</a> which is a DOM implemetation and the more 'pythonic' <a href="http://docs.python.org/library/xml.etree.elementtree.html" rel="nofollow">Element Tree</a> which has <a href="http://eff... | 0 | 2010-02-23T11:33:15Z | [
"python",
"xml"
] |
XML file using Python | 2,317,626 | <p>I have made a XML file using python. How can I retrieve an element from it? Will you help me with the code?</p>
<p>Also I need to have my output (i.e. element of each attribute come in separate lines in that particular XML file).</p>
| -1 | 2010-02-23T11:24:36Z | 2,317,735 | <p>There is also the excellent <a href="http://codespeak.net/lxml/index.html" rel="nofollow">lxml</a> library. You can query the tree with <a href="http://codespeak.net/lxml/xpathxslt.html" rel="nofollow">xpath</a> or if you are familiar with css you can select elements with <a href="http://codespeak.net/lxml/cssselect... | 0 | 2010-02-23T11:38:24Z | [
"python",
"xml"
] |
clicking "cancel" in tkColorChooser dialog leads to Error | 2,317,680 | <p>I use python 2.6 under linux (SUSE Linux Enterprise Desktop 11 (x86_64)). I tested some very simple code :</p>
<pre><code>import tkColorChooser
tkColorChooser.askcolor()
</code></pre>
<p>then if I click on cancel, I always get error like:</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", l... | 1 | 2010-02-23T11:30:55Z | 2,344,119 | <p>Looking at the version of tkColorChooser.py I have (Python 2.6.4, Win32), it should support the user pressing <code>cancel</code> (as do and should the other predefined dialogs): it is indeed supposed to return None when the results evals to <code>False</code> in a boolean context.</p>
<p>Therefore, something stran... | 0 | 2010-02-26T19:03:59Z | [
"python",
"tkinter"
] |
JSON serializers not working in Django | 2,317,818 | <p>Hay, serializers is not returning JSON object</p>
<pre><code> make = Make.objects.filter(slug__exact=make)
models = Model.objects.filter(make=make).values('slug','name')
json_models = serializers.get_serializer("json")()
json_models.serialize(models)
return HttpResponse(json_models.getvalue())
... | 2 | 2010-02-23T11:52:05Z | 2,317,888 | <p>The serializer is meant to be used on <code>QuerySet</code> instances. Use <a href="http://docs.python.org/library/json.html#json.dumps" rel="nofollow"><code>django.utils.simplejson.dumps()</code></a> if you have a normal Python structure.</p>
| 1 | 2010-02-23T12:01:32Z | [
"python",
"django",
"json"
] |
JSON serializers not working in Django | 2,317,818 | <p>Hay, serializers is not returning JSON object</p>
<pre><code> make = Make.objects.filter(slug__exact=make)
models = Model.objects.filter(make=make).values('slug','name')
json_models = serializers.get_serializer("json")()
json_models.serialize(models)
return HttpResponse(json_models.getvalue())
... | 2 | 2010-02-23T11:52:05Z | 2,317,901 | <p>As the other answer hints, its because <code>.values(...)</code> returns a list and <code>serializers</code> is meant for Querysets. However you can still do this without needing raw SimpleJSON quite simply:</p>
<pre><code>queryset = Model.objects.filter(make__slug__exact=make)
return serializers.serialize("json", ... | 4 | 2010-02-23T12:04:00Z | [
"python",
"django",
"json"
] |
How can I use a SOCKS 4/5 proxy with urllib2? | 2,317,849 | <p>How can I use a SOCKS 4/5 proxy with urllib2 to download a web page?</p>
| 39 | 2010-02-23T11:55:57Z | 2,318,560 | <p>Since SOCKS is a socket level proxy, you have to replace the socket object used by <code>urllib2</code>. Please take a look a <a href="http://coding.derkeiler.com/Archive/Python/comp.lang.python/2006-04/msg01816.html" rel="nofollow">this</a> solution. If monkey patching is not good enough for you, then you can try t... | 2 | 2010-02-23T13:50:59Z | [
"python",
"proxy",
"urllib2",
"socks"
] |
How can I use a SOCKS 4/5 proxy with urllib2? | 2,317,849 | <p>How can I use a SOCKS 4/5 proxy with urllib2 to download a web page?</p>
| 39 | 2010-02-23T11:55:57Z | 2,339,260 | <p>You can use <a href="http://sourceforge.net/projects/socksipy/">SocksiPy</a> module. Simply copy the file "socks.py" to your Python's lib/site-packages directory, and you're ready to go. </p>
<p>You must use <strong>socks</strong> before urllib2. (Try it <code>pip install PySocks</code> )</p>
<p>For example:</p>
... | 53 | 2010-02-26T03:06:52Z | [
"python",
"proxy",
"urllib2",
"socks"
] |
How can I use a SOCKS 4/5 proxy with urllib2? | 2,317,849 | <p>How can I use a SOCKS 4/5 proxy with urllib2 to download a web page?</p>
| 39 | 2010-02-23T11:55:57Z | 8,100,870 | <p>Adding an alternative to pan's answer when you need to use many different proxies at the same time.</p>
<p>In that case you need to create an opener like you do with a http proxy. There is a code available in GitHub <a href="https://gist.github.com/869791">https://gist.github.com/869791</a></p>
<pre><code>opener =... | 18 | 2011-11-11T22:44:52Z | [
"python",
"proxy",
"urllib2",
"socks"
] |
print_r functionality in iPython | 2,317,921 | <p>Is there a way to get PHP-like <code>print_r(object)</code> funcionality in iPython?</p>
<p>I know I can use '?' to get info about an object, but how do I view the <em>values</em> of the object?</p>
| 1 | 2010-02-23T12:08:12Z | 2,317,934 | <p><a href="http://docs.python.org/library/functions.html#repr" rel="nofollow"><code>repr()</code></a> calls the <code>__repr__()</code> method of the object, which usually gives some information about the contents of the object if written appropriately.</p>
| 0 | 2010-02-23T12:09:54Z | [
"php",
"python",
"object",
"ipython"
] |
print_r functionality in iPython | 2,317,921 | <p>Is there a way to get PHP-like <code>print_r(object)</code> funcionality in iPython?</p>
<p>I know I can use '?' to get info about an object, but how do I view the <em>values</em> of the object?</p>
| 1 | 2010-02-23T12:08:12Z | 2,317,941 | <p>Is </p>
<pre><code>print my_object.__dict__
</code></pre>
<p>perhaps what you are looking for?</p>
<p>Or have a look at <a href="http://docs.python.org/library/pprint.html" rel="nofollow">the standard python pretty printer</a> for more advanced, recursive printing.</p>
| 3 | 2010-02-23T12:11:07Z | [
"php",
"python",
"object",
"ipython"
] |
print_r functionality in iPython | 2,317,921 | <p>Is there a way to get PHP-like <code>print_r(object)</code> funcionality in iPython?</p>
<p>I know I can use '?' to get info about an object, but how do I view the <em>values</em> of the object?</p>
| 1 | 2010-02-23T12:08:12Z | 2,317,942 | <p><code>dir(object)</code> will give you all its attribute names.</p>
| 2 | 2010-02-23T12:11:10Z | [
"php",
"python",
"object",
"ipython"
] |
print_r functionality in iPython | 2,317,921 | <p>Is there a way to get PHP-like <code>print_r(object)</code> funcionality in iPython?</p>
<p>I know I can use '?' to get info about an object, but how do I view the <em>values</em> of the object?</p>
| 1 | 2010-02-23T12:08:12Z | 2,318,790 | <p>I'd use the <code>pprint</code> module if you want it to be nicely formatted:</p>
<pre><code>import pprint
obj = {'a':1, 'b':2}
pprint.pprint(obj)
</code></pre>
| 1 | 2010-02-23T14:23:12Z | [
"php",
"python",
"object",
"ipython"
] |
Python equivalent for Ruby's ObjectSpace? | 2,318,044 | <p>I've a name of a class stored in var, which I need to create an object from.
However I do not know in which module it is defined (if I did, I would just call getattr(module,var), but I do know it's imported.</p>
<p>Should I go over every module and test if the class is defined there ? How do I do it in python ?</p>... | 1 | 2010-02-23T12:29:18Z | 2,318,065 | <p>Classes are not added to a global registry in Python by default. You'll need to iterate over all imported modules and look for it.</p>
| 0 | 2010-02-23T12:32:46Z | [
"python",
"ruby",
"module",
"metaprogramming"
] |
Python equivalent for Ruby's ObjectSpace? | 2,318,044 | <p>I've a name of a class stored in var, which I need to create an object from.
However I do not know in which module it is defined (if I did, I would just call getattr(module,var), but I do know it's imported.</p>
<p>Should I go over every module and test if the class is defined there ? How do I do it in python ?</p>... | 1 | 2010-02-23T12:29:18Z | 2,318,078 | <p><code>globals()[classname]</code> should do it.</p>
<p>More code: <a href="http://code.activestate.com/recipes/285262/" rel="nofollow">http://code.activestate.com/recipes/285262/</a></p>
| 1 | 2010-02-23T12:35:04Z | [
"python",
"ruby",
"module",
"metaprogramming"
] |
Python equivalent for Ruby's ObjectSpace? | 2,318,044 | <p>I've a name of a class stored in var, which I need to create an object from.
However I do not know in which module it is defined (if I did, I would just call getattr(module,var), but I do know it's imported.</p>
<p>Should I go over every module and test if the class is defined there ? How do I do it in python ?</p>... | 1 | 2010-02-23T12:29:18Z | 2,318,282 | <p>Rather than storing the classname as a string, why don't you store the class object in the var, so you can instantiate it directly.</p>
<pre><code>>>> class A(object):
... def __init__(self):
... print 'A new object created'
...
>>> class_object = A
>>> object = class_object(... | 0 | 2010-02-23T13:06:35Z | [
"python",
"ruby",
"module",
"metaprogramming"
] |
Controlling VirtualBox | 2,318,127 | <p>Documentation for pyVB is given in <a href="http://enomalism.com/api/pyvb/" rel="nofollow">http://enomalism.com/api/pyvb/</a></p>
<p>we are trying to make a commandline interface to virtualbox using pyvb module in python.</p>
<pre><code>>>> import pyvb
>>> n=pyvb.vm.vbVM()
>>> n.setUUID(... | 0 | 2010-02-23T12:42:26Z | 2,318,432 | <p>Why reinvent the wheel; VirtualBox already comes with <a href="http://www.virtualbox.org/manual/ch08.html" rel="nofollow">a command line interface</a>?</p>
| 0 | 2010-02-23T13:29:27Z | [
"python"
] |
Django - Template not complete rendered | 2,318,169 | <p>I have a website on a django framework, and in a set of pages I use the Paginator. With paginator, my last page sometimes does not render completely.</p>
<p>You can see the problem <a href="http://myps3t.dyndns.org:8000/rank/?page=4" rel="nofollow">here</a>.</p>
<p>Code:</p>
<p>view rank - <a href="http://code.go... | 1 | 2010-02-23T12:48:07Z | 2,329,138 | <p>You asked if you can see the template render output. You can.</p>
<p>django.shortcuts.render_to_response is a very short function:</p>
<pre><code>httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
</code></pre>
<p>... | 1 | 2010-02-24T20:13:17Z | [
"python",
"django"
] |
Connect to a remote sqlite3 database with Python | 2,318,315 | <p>I am able to create a connection to a local sqlite3 database ( Using Mac OS X 10.5 and Python 2.5.1 ) with this:</p>
<pre><code>conn = sqlite3.connect('/db/MyDb')
</code></pre>
<p>How can I connect to this database if it is located on a server ( for example on a server running Ubuntu 8.04 with an IP address of 10.... | 1 | 2010-02-23T13:13:38Z | 2,318,358 | <p>SQLite is embedded-only. You'll need to mount the remote filesystem before you can access it. And don't try to have more than one machine accessing the SQLite database at a time; SQLite is not built for that. Use something like PostgreSQL instead if you need that.</p>
| 8 | 2010-02-23T13:18:29Z | [
"python",
"osx",
"sqlite3"
] |
Connect to a remote sqlite3 database with Python | 2,318,315 | <p>I am able to create a connection to a local sqlite3 database ( Using Mac OS X 10.5 and Python 2.5.1 ) with this:</p>
<pre><code>conn = sqlite3.connect('/db/MyDb')
</code></pre>
<p>How can I connect to this database if it is located on a server ( for example on a server running Ubuntu 8.04 with an IP address of 10.... | 1 | 2010-02-23T13:13:38Z | 2,320,068 | <p>The sqlite FAQ has <a href="http://sqlite.org/faq.html#q5" rel="nofollow">an answer relevant to your question</a>. It points out that although multi-machine network access is theoretically possible (using a remote filesystem) it likely won't be reliable unless the filesystem properly supports locks. </p>
<p>If yo... | 2 | 2010-02-23T16:58:07Z | [
"python",
"osx",
"sqlite3"
] |
how to follow meta refreshes in Python | 2,318,446 | <p>Python's urllib2 follows 3xx redirects to get the final content. Is there a way to make urllib2 (or some other library such as <a href="http://code.google.com/p/httplib2/">httplib2</a>) also follow <a href="http://en.wikipedia.org/wiki/Meta_refresh">meta refreshes</a>? Or do I need to parse the HTML manually for the... | 9 | 2010-02-23T13:31:41Z | 2,318,487 | <p>Use BeautifulSoup or lxml to parse the HTML.</p>
| -1 | 2010-02-23T13:39:04Z | [
"python",
"redirect",
"refresh",
"urllib2",
"httplib2"
] |
how to follow meta refreshes in Python | 2,318,446 | <p>Python's urllib2 follows 3xx redirects to get the final content. Is there a way to make urllib2 (or some other library such as <a href="http://code.google.com/p/httplib2/">httplib2</a>) also follow <a href="http://en.wikipedia.org/wiki/Meta_refresh">meta refreshes</a>? Or do I need to parse the HTML manually for the... | 9 | 2010-02-23T13:31:41Z | 2,345,877 | <p>OK, seems no library supports it so I have been using this code:</p>
<pre><code>import urllib2
import urlparse
import re
def get_hops(url):
redirect_re = re.compile('<meta[^>]*?url=(.*?)["\']', re.IGNORECASE)
hops = []
while url:
if url in hops:
url = None
else:
... | 1 | 2010-02-27T01:27:26Z | [
"python",
"redirect",
"refresh",
"urllib2",
"httplib2"
] |
how to follow meta refreshes in Python | 2,318,446 | <p>Python's urllib2 follows 3xx redirects to get the final content. Is there a way to make urllib2 (or some other library such as <a href="http://code.google.com/p/httplib2/">httplib2</a>) also follow <a href="http://en.wikipedia.org/wiki/Meta_refresh">meta refreshes</a>? Or do I need to parse the HTML manually for the... | 9 | 2010-02-23T13:31:41Z | 3,668,771 | <p>Here is a solution using BeautifulSoup and httplib2 (and certificate based authentication):</p>
<pre><code>import BeautifulSoup
import httplib2
def meta_redirect(content):
soup = BeautifulSoup.BeautifulSoup(content)
result=soup.find("meta",attrs={"http-equiv":"Refresh"})
if result:
wait,text=... | 8 | 2010-09-08T14:30:59Z | [
"python",
"redirect",
"refresh",
"urllib2",
"httplib2"
] |
how to follow meta refreshes in Python | 2,318,446 | <p>Python's urllib2 follows 3xx redirects to get the final content. Is there a way to make urllib2 (or some other library such as <a href="http://code.google.com/p/httplib2/">httplib2</a>) also follow <a href="http://en.wikipedia.org/wiki/Meta_refresh">meta refreshes</a>? Or do I need to parse the HTML manually for the... | 9 | 2010-02-23T13:31:41Z | 16,926,326 | <p>A similar solution using the requests and lxml libraries. Also does a simple check that the thing being tested is actually HTML (a requirement in my implementation). Also is able to capture and use cookies by using the request library's sessions (sometimes necessary if redirection + cookies are being used as an anti... | 3 | 2013-06-04T19:52:43Z | [
"python",
"redirect",
"refresh",
"urllib2",
"httplib2"
] |
groovy map coercion in python | 2,318,494 | <p>I'm a relative newcomer to python and I'm just wondering if there is some equivalent to the map coercion feature available in groovy.</p>
<p>For context, I am writing a unit test and want to mock a class with a simple two method interface, in groovy I would do the following:</p>
<pre><code>mock = [apply:{value -&g... | 1 | 2010-02-23T13:40:13Z | 2,318,518 | <p>Use the 3-parameter form of <a href="http://docs.python.org/library/functions.html#type" rel="nofollow"><code>type()</code></a>:</p>
<pre><code>mock = type('mock', (object,), {'apply': (lambda self, value: value * 2),
'isValid': lambda self: True})
</code></pre>
| 2 | 2010-02-23T13:44:21Z | [
"python",
"mocking",
"closures"
] |
Plotting only upper/lower triangle of a heatmap | 2,318,529 | <p>In maptplotlib, one can create a heatmap representation of a correlation matrix using the imshow function. By definition, such a matrix is symmetrical around its main diagonal, therefore there is no need to present both the upper and lower triangles. For example:
<img src="http://yin.che.wisc.edu/images/ProteinMatri... | 9 | 2010-02-23T13:46:30Z | 2,319,256 | <pre><code>import numpy as NP
from matplotlib import pyplot as PLT
from matplotlib import cm as CM
A = NP.random.randint(10, 100, 100).reshape(10, 10)
# create an upper triangular 'matrix' from A
A2 = NP.triu(A)
fig = PLT.figure()
ax1 = fig.add_subplot(111)
# use dir(matplotlib.cm) to get a list of the installed color... | 7 | 2010-02-23T15:22:10Z | [
"python",
"matplotlib",
"plot"
] |
Plotting only upper/lower triangle of a heatmap | 2,318,529 | <p>In maptplotlib, one can create a heatmap representation of a correlation matrix using the imshow function. By definition, such a matrix is symmetrical around its main diagonal, therefore there is no need to present both the upper and lower triangles. For example:
<img src="http://yin.che.wisc.edu/images/ProteinMatri... | 9 | 2010-02-23T13:46:30Z | 2,319,298 | <p>You could plot over one white matrix with upper/lower part transparent</p>
<pre><code>a =random((10,10))
imshow(a, interpolation='nearest')
b = ones(a.shape+(4,)) # «white» matrix with alpha=1
for i in range(a.shape[0]):
for j in range(i, a.shape[1]):
b[i,j,3] = 0 # upper triangle, alpha = 0
imshow... | 2 | 2010-02-23T15:28:18Z | [
"python",
"matplotlib",
"plot"
] |
Plotting only upper/lower triangle of a heatmap | 2,318,529 | <p>In maptplotlib, one can create a heatmap representation of a correlation matrix using the imshow function. By definition, such a matrix is symmetrical around its main diagonal, therefore there is no need to present both the upper and lower triangles. For example:
<img src="http://yin.che.wisc.edu/images/ProteinMatri... | 9 | 2010-02-23T13:46:30Z | 2,332,520 | <p>The problem with the answer provided by doug is that it relies on the fact that the colormap maps zero values to white. This means that colormaps that do not include white color are not useful. The key for solution is <code>cm.set_bad</code> function. You mask the unneeded parts of the matrix with None or with NumPy... | 11 | 2010-02-25T08:12:07Z | [
"python",
"matplotlib",
"plot"
] |
Simple question: In numpy how do you make a multidimensional array of arrays? | 2,318,667 | <p>Right, perhaps I should be using the normal Python lists for this, but here goes:</p>
<p>I want a 9 by 4 multidimensional array/matrix (whatever really) that I want to store arrays in. These arrays will be 1-dimensional and of length 4096.</p>
<p>So, I want to be able to go something like</p>
<pre><code>column = ... | 3 | 2010-02-23T14:05:03Z | 2,318,742 | <p>The <a href="http://www.scipy.org/Tentative_NumPy_Tutorial" rel="nofollow">Tentative NumPy Tutorial</a> says you can declare a 2D array using the comma operator:</p>
<pre><code>x = ones( (3,4) )
</code></pre>
<p>and index into a 2D array like this:</p>
<pre><code>>>> x[1,2] = 20
>>> x[1,:] ... | 0 | 2010-02-23T14:14:56Z | [
"python",
"arrays",
"multidimensional-array",
"numpy"
] |
Simple question: In numpy how do you make a multidimensional array of arrays? | 2,318,667 | <p>Right, perhaps I should be using the normal Python lists for this, but here goes:</p>
<p>I want a 9 by 4 multidimensional array/matrix (whatever really) that I want to store arrays in. These arrays will be 1-dimensional and of length 4096.</p>
<p>So, I want to be able to go something like</p>
<pre><code>column = ... | 3 | 2010-02-23T14:05:03Z | 2,319,006 | <p>Note that to leverage the full power of numpy, you'd be much better off with a 3-dimensional numpy array. Breaking apart the 3-d array into a 2-d array with 1-d values
may complicate your code and force you to use loops instead of built-in numpy functions.</p>
<p>It may be worth investing the time to refactor you... | 8 | 2010-02-23T14:51:18Z | [
"python",
"arrays",
"multidimensional-array",
"numpy"
] |
Interrupt all running signals in Python? | 2,318,831 | <p>How can I interrupt all running signals in a Python script? I would like something like <code>signal.interrupt_all()</code>.</p>
<p>Is there any way to do that?</p>
<p>Thanks</p>
| 1 | 2010-02-23T14:29:42Z | 2,328,116 | <p>What exactly do you mean? Do you want to temporairly ignore a signal, or to completely ignore some kinds of signals?</p>
<p>Generally speaking, you can't "vanish" a signal once it has been generated. You either set its action to "ignore" or you block the signal, preventing it from being delivered, but you need to d... | 1 | 2010-02-24T17:37:21Z | [
"python",
"signals"
] |
is there a limit to command.getstatusoutput() buffer in python | 2,318,881 | <p>I have created a script to run a test script on a batch of files,have been testing it overnight for two nights, however it just hangs at a certain point. </p>
<p>I was wondering if the the commands.getstatusoutput() is the issue here since the test script is has a heavy logging mechanism. </p>
<p>Update:<br>
How i... | 2 | 2010-02-23T14:34:36Z | 2,319,003 | <p>The method <code>getstatusoutput()</code> returns a string, which can be very long and therefore take up a lot of space and cause paging to disk and other nasty things. </p>
<p>Since the <code>commands</code> module is deprecated anyway, better use the <code>subprocess</code> module which provides a file-like acce... | 5 | 2010-02-23T14:51:03Z | [
"python",
"linux"
] |
Using regex to remove comments from source files | 2,319,019 | <p>I'm making a program to automate the writing of some C code, (I'm writing to parse strings into enumerations with the same name)
C's handling of strings is not that great.
So some people have been nagging me to try python.</p>
<p>I made a function that is supposed to remove C-style <code>/* COMMENT */</code> and <c... | 16 | 2010-02-23T14:52:54Z | 2,319,054 | <p>You are doing it wrong. </p>
<p>Regex is for <a href="http://en.wikipedia.org/wiki/Regular_language" rel="nofollow">Regular Languages</a>, which C isn't. </p>
| 2 | 2010-02-23T14:58:05Z | [
"python",
"regex",
"string"
] |
Using regex to remove comments from source files | 2,319,019 | <p>I'm making a program to automate the writing of some C code, (I'm writing to parse strings into enumerations with the same name)
C's handling of strings is not that great.
So some people have been nagging me to try python.</p>
<p>I made a function that is supposed to remove C-style <code>/* COMMENT */</code> and <c... | 16 | 2010-02-23T14:52:54Z | 2,319,078 | <p>I would suggest using a REAL parser like <a href="http://pypi.python.org/pypi/SimpleParse/2.1.1a2">SimpleParse</a> or <a href="http://pypi.python.org/pypi/pyparsing/1.5.2">PyParsing</a>. SimpleParse requires that you actually know EBNF, but is very fast. PyParsing has its own EBNF-like syntax but that is adapted f... | 14 | 2010-02-23T15:00:10Z | [
"python",
"regex",
"string"
] |
Using regex to remove comments from source files | 2,319,019 | <p>I'm making a program to automate the writing of some C code, (I'm writing to parse strings into enumerations with the same name)
C's handling of strings is not that great.
So some people have been nagging me to try python.</p>
<p>I made a function that is supposed to remove C-style <code>/* COMMENT */</code> and <c... | 16 | 2010-02-23T14:52:54Z | 2,319,116 | <p><code>re.sub</code> returns a string, so changing your code to the following will give results:</p>
<pre><code>def removeComments(string):
string = re.sub(re.compile("/\*.*?\*/",re.DOTALL ) ,"" ,string) # remove all occurance streamed comments (/*COMMENT */) from string
string = re.sub(re.compile("//.*?\n" ... | 17 | 2010-02-23T15:04:47Z | [
"python",
"regex",
"string"
] |
Using regex to remove comments from source files | 2,319,019 | <p>I'm making a program to automate the writing of some C code, (I'm writing to parse strings into enumerations with the same name)
C's handling of strings is not that great.
So some people have been nagging me to try python.</p>
<p>I made a function that is supposed to remove C-style <code>/* COMMENT */</code> and <c... | 16 | 2010-02-23T14:52:54Z | 2,319,146 | <p>I would recommend you read this page that has a quite detailed analyzis of the problem and gives a good understanding on why your approach doesn't work: <a href="http://ostermiller.org/findcomment.html" rel="nofollow">http://ostermiller.org/findcomment.html</a></p>
<p>Short version: The regex you are looking for is... | 4 | 2010-02-23T15:07:30Z | [
"python",
"regex",
"string"
] |
Using regex to remove comments from source files | 2,319,019 | <p>I'm making a program to automate the writing of some C code, (I'm writing to parse strings into enumerations with the same name)
C's handling of strings is not that great.
So some people have been nagging me to try python.</p>
<p>I made a function that is supposed to remove C-style <code>/* COMMENT */</code> and <c... | 16 | 2010-02-23T14:52:54Z | 2,319,150 | <p>I see several things you might want to revise.</p>
<p>First, Python passes objects by value, but some object types are immutable. Strings and integers are among these immutable types. So if you pass a string to a function, any changes to the string you make within the function won't affect the string you passed in.... | 1 | 2010-02-23T15:08:00Z | [
"python",
"regex",
"string"
] |
Using regex to remove comments from source files | 2,319,019 | <p>I'm making a program to automate the writing of some C code, (I'm writing to parse strings into enumerations with the same name)
C's handling of strings is not that great.
So some people have been nagging me to try python.</p>
<p>I made a function that is supposed to remove C-style <code>/* COMMENT */</code> and <c... | 16 | 2010-02-23T14:52:54Z | 2,320,670 | <p>As noted in one of my other comments, comment nesting isn't really the problem (in C, comments don't nest, though a few compilers to support nested comments anyway). The problem is with things like string literals, that can contain the exact same character sequence as a comment delimiter without actually being one.<... | 0 | 2010-02-23T18:24:03Z | [
"python",
"regex",
"string"
] |
Using regex to remove comments from source files | 2,319,019 | <p>I'm making a program to automate the writing of some C code, (I'm writing to parse strings into enumerations with the same name)
C's handling of strings is not that great.
So some people have been nagging me to try python.</p>
<p>I made a function that is supposed to remove C-style <code>/* COMMENT */</code> and <c... | 16 | 2010-02-23T14:52:54Z | 2,322,860 | <pre><code>mystring="""
blah1 /* comments with
multiline */
blah2
blah3
// double slashes comments
blah4 // some junk comments
"""
for s in mystring.split("*/"):
s=s[:s.find("/*")]
print s[:s.find("//")]
</code></pre>
<p>output</p>
<pre><code>$ ./python.py
blah1
blah2
blah3
</code></pre>
| 1 | 2010-02-24T00:31:44Z | [
"python",
"regex",
"string"
] |
Using regex to remove comments from source files | 2,319,019 | <p>I'm making a program to automate the writing of some C code, (I'm writing to parse strings into enumerations with the same name)
C's handling of strings is not that great.
So some people have been nagging me to try python.</p>
<p>I made a function that is supposed to remove C-style <code>/* COMMENT */</code> and <c... | 16 | 2010-02-23T14:52:54Z | 17,776,351 | <p>This program removes comments with // and /* */ from the given file:</p>
<pre><code>#! /usr/bin/python3
import sys
import re
if len(sys.argv)!=2:
exit("Syntax:python3 exe18.py inputfile.cc ")
else:
print ('The following files are given by you:',sys.argv[0],sys.argv[1])
with open(sys.argv[1],'r') as ifile:... | 0 | 2013-07-21T20:01:43Z | [
"python",
"regex",
"string"
] |
Using regex to remove comments from source files | 2,319,019 | <p>I'm making a program to automate the writing of some C code, (I'm writing to parse strings into enumerations with the same name)
C's handling of strings is not that great.
So some people have been nagging me to try python.</p>
<p>I made a function that is supposed to remove C-style <code>/* COMMENT */</code> and <c... | 16 | 2010-02-23T14:52:54Z | 18,381,470 | <p>Again, an old question and many answers are given already but;<br>
what about <code>"//comment-like strings inside quotes"</code>?</p>
<p>OP is asking how to do do it using regular expressions; so:
</p>
<pre><code>def remove_comments(string):
pattern = r"(\".*?\"|\'.*?\')|(/\*.*?\*/|//[^\r\n]*$)"
# first ... | 16 | 2013-08-22T13:12:19Z | [
"python",
"regex",
"string"
] |
a == b is false, but id(a) == id(b) is true? | 2,319,107 | <p>Ran into the following:</p>
<pre><code>>>> class A:
... def __str__(self):
... return "some A()"
...
>>> class B(A):
... def __str__(self):
... return "some B()"
...
>>> print A()
some A()
>>> print B()
some B()
>>> A.__str__ == B.__str_... | 13 | 2010-02-23T15:03:18Z | 2,319,152 | <p>The following works:</p>
<pre><code>>>> id(A.__str__.im_func) == id(A.__str__.im_func)
True
>>> id(B.__str__.im_func) == id(A.__str__.im_func)
False
</code></pre>
| 7 | 2010-02-23T15:08:20Z | [
"python",
"object",
"methods",
"override"
] |
a == b is false, but id(a) == id(b) is true? | 2,319,107 | <p>Ran into the following:</p>
<pre><code>>>> class A:
... def __str__(self):
... return "some A()"
...
>>> class B(A):
... def __str__(self):
... return "some B()"
...
>>> print A()
some A()
>>> print B()
some B()
>>> A.__str__ == B.__str_... | 13 | 2010-02-23T15:03:18Z | 2,319,238 | <p>As the string <code>id(A.__str__) == id(B.__str__)</code> is evaluated, <code>A.__str__</code> is created, its id taken, and then garbage collected. Then <code>B.__str__</code> is created, and happens to end up at the exact same address that <code>A.__str__</code> was at earlier, so it gets (in CPython) the same id... | 10 | 2010-02-23T15:19:39Z | [
"python",
"object",
"methods",
"override"
] |
a == b is false, but id(a) == id(b) is true? | 2,319,107 | <p>Ran into the following:</p>
<pre><code>>>> class A:
... def __str__(self):
... return "some A()"
...
>>> class B(A):
... def __str__(self):
... return "some B()"
...
>>> print A()
some A()
>>> print B()
some B()
>>> A.__str__ == B.__str_... | 13 | 2010-02-23T15:03:18Z | 23,534,612 | <p>For those of us here attracted by your title, to determine whether a method was overridden:</p>
<pre><code>class A:
def __str__(self):
return "some A()"
def strWasOverridden(self):
return A.__str__ != self.__str__
</code></pre>
| 0 | 2014-05-08T06:43:35Z | [
"python",
"object",
"methods",
"override"
] |
django and sqlalchemy | 2,319,231 | <p>hey,
I'm fairly new to Django and have a basic question: I want to use an ORM that I can work with it for Django and other python projects, so the basic question is Django ORM agnostic and if so how can I use SQLAlchemy with it for example?</p>
<p>If it's not, then what do you suggest for the above problem (using... | 7 | 2010-02-23T15:18:46Z | 2,319,331 | <p>Option 1: Use the Django ORM for other projects. <a href="http://stackoverflow.com/questions/579511/using-only-the-db-part-of-django">http://stackoverflow.com/questions/579511/using-only-the-db-part-of-django</a></p>
<p>This works well. I prefer it.</p>
<p>Option 2: Use SQLAlchemy with Django. <a href="http://st... | 12 | 2010-02-23T15:32:23Z | [
"python",
"django",
"orm"
] |
Installing python with python win32 extensions on a network drive | 2,319,495 | <p>I need to keep a large number of Windows XP machines running the same version of python, with an assortment of modules, one of which is python-win32. I thought about installing python on a network drive that is mounted by all the client machines, and just adjust the path on the clients. Python starts up fine from ... | 5 | 2010-02-23T15:49:52Z | 2,319,650 | <p>"""I searched the python directory for the pywintypes24.dll and it is present in "Lib\site-packages\pywin32_system32" """. The existence of the dll is not in question. Is that entry point in that dll?</p>
<p>Have you tried installing exactly the same configuration on a non-network drive?</p>
<p>Have you tried imp... | 0 | 2010-02-23T16:07:02Z | [
"python",
"windows",
"networking",
"share"
] |
Installing python with python win32 extensions on a network drive | 2,319,495 | <p>I need to keep a large number of Windows XP machines running the same version of python, with an assortment of modules, one of which is python-win32. I thought about installing python on a network drive that is mounted by all the client machines, and just adjust the path on the clients. Python starts up fine from ... | 5 | 2010-02-23T15:49:52Z | 2,319,700 | <p>You could use <a href="http://isg.ee.ethz.ch/tools/realmen/index.en.html" rel="nofollow">batch files running at boot</a> to</p>
<ul>
<li>Mount the network share (<code>net use \\server\share</code>)</li>
<li>Copy the Python and packages installers from the network share to a local folder</li>
<li>Check version of t... | 0 | 2010-02-23T16:10:52Z | [
"python",
"windows",
"networking",
"share"
] |
Installing python with python win32 extensions on a network drive | 2,319,495 | <p>I need to keep a large number of Windows XP machines running the same version of python, with an assortment of modules, one of which is python-win32. I thought about installing python on a network drive that is mounted by all the client machines, and just adjust the path on the clients. Python starts up fine from ... | 5 | 2010-02-23T15:49:52Z | 2,319,894 | <p>On every machine you have to basically run following <code>pywin32_postinstall.py -install</code> once. Assuming your python installation on the network is <code>N:\Python26</code>, run following command on every client:</p>
<pre><code>N:\Python26\python.exe N:\Python26\Scripts\pywin32_postinstall.py -install
</cod... | 5 | 2010-02-23T16:35:17Z | [
"python",
"windows",
"networking",
"share"
] |
Installing python with python win32 extensions on a network drive | 2,319,495 | <p>I need to keep a large number of Windows XP machines running the same version of python, with an assortment of modules, one of which is python-win32. I thought about installing python on a network drive that is mounted by all the client machines, and just adjust the path on the clients. Python starts up fine from ... | 5 | 2010-02-23T15:49:52Z | 4,919,533 | <p>Python (or precisely, the OS) searches the DLLs using os.environ["PATH"] and not by searching sys.path.</p>
<p>So you could start Python using a simple .cmd file instead which adds \server\share\python26 to the path (given the installer (or you) copied the DLLs from \server\share\python26\lib\site-packages\pywin32-... | 1 | 2011-02-07T09:09:14Z | [
"python",
"windows",
"networking",
"share"
] |
django, admin template error Caught an exception while rendering: 'NoneType' object has no attribute 'label' | 2,319,649 | <p>good day guys!
in project, among others, have models:</p>
<pre><code>class Category(models.Model):
name = models.CharField(max_length = 50, blank = False, null = False)
def __unicode__(self):
return "Category %s" % self.name
class Meta:
db_table = "categories"
managed = False
... | 0 | 2010-02-23T16:07:01Z | 2,320,175 | <p>For that you need to add undocumented <code>formfield_for_manytomany</code> method to your <code>SiteAdmin</code> class:</p>
<pre><code>from django.contrib.admin import widgets
class SitebAdmin(admin.ModelAdmin):
list_display = ('id', 'name')
list_filter = ('name', 'categories')
def formfield_for_manyto... | 1 | 2010-02-23T17:15:41Z | [
"python",
"django-models",
"django-admin",
"django-templates"
] |
Can I run two web servers on the same computer? | 2,319,697 | <p>I just found out that I can write a really <a href="http://fragments.turtlemeat.com/pythonwebserver.php">simple web server</a> using Python. I have already an Apache web server I would like to try the Python based web server on this machine. But I am afraid that I can get some kind of conflict if I try it. I mean h... | 12 | 2010-02-23T16:10:40Z | 2,319,706 | <p>Make them listen to different ports and you will be fine.</p>
<p>The default web port is 80. When you open some url in browser without specifying a port, 80 is used by default.</p>
<p>You can configure your web server to listen to a different port but then you will also need to specify it explicitly in the url:</p... | 22 | 2010-02-23T16:11:15Z | [
"python",
"apache",
"webserver",
"conflict"
] |
Can I run two web servers on the same computer? | 2,319,697 | <p>I just found out that I can write a really <a href="http://fragments.turtlemeat.com/pythonwebserver.php">simple web server</a> using Python. I have already an Apache web server I would like to try the Python based web server on this machine. But I am afraid that I can get some kind of conflict if I try it. I mean h... | 12 | 2010-02-23T16:10:40Z | 2,319,719 | <p>You cannot open two web servers in the same port (which default is 80), if you desire to make two or more web servers, you have to use different ports.</p>
<p>If you are using a DNS, you could easily set up your web server to respond with different web sites to different requests, that could be useful if you need t... | 0 | 2010-02-23T16:13:24Z | [
"python",
"apache",
"webserver",
"conflict"
] |
Can I run two web servers on the same computer? | 2,319,697 | <p>I just found out that I can write a really <a href="http://fragments.turtlemeat.com/pythonwebserver.php">simple web server</a> using Python. I have already an Apache web server I would like to try the Python based web server on this machine. But I am afraid that I can get some kind of conflict if I try it. I mean h... | 12 | 2010-02-23T16:10:40Z | 2,319,726 | <p>A web server is tied to a specific port. Normally, this is port 80. If the port is not explicitly specified, this is the port that a browser will attempt to hit.</p>
<p>You can get your alternate server to run on a different port ( 8080 or 8081 seem to be popular alts for web servers, but the choice is yours ). ... | 5 | 2010-02-23T16:14:26Z | [
"python",
"apache",
"webserver",
"conflict"
] |
Can I run two web servers on the same computer? | 2,319,697 | <p>I just found out that I can write a really <a href="http://fragments.turtlemeat.com/pythonwebserver.php">simple web server</a> using Python. I have already an Apache web server I would like to try the Python based web server on this machine. But I am afraid that I can get some kind of conflict if I try it. I mean h... | 12 | 2010-02-23T16:10:40Z | 2,319,751 | <p>The webservers would have no say in who services a connection request (this task is still at the operating system level). Furthermore, without special socket options, the socket must be bound to a unique combination of interface, internet address and port.</p>
| 0 | 2010-02-23T16:17:15Z | [
"python",
"apache",
"webserver",
"conflict"
] |
Can I run two web servers on the same computer? | 2,319,697 | <p>I just found out that I can write a really <a href="http://fragments.turtlemeat.com/pythonwebserver.php">simple web server</a> using Python. I have already an Apache web server I would like to try the Python based web server on this machine. But I am afraid that I can get some kind of conflict if I try it. I mean h... | 12 | 2010-02-23T16:10:40Z | 2,319,784 | <p>I would suggest you dedicate one server to serving https (port 443) requests.</p>
<p>That way you can avoid the port conflict others have mentioned while also not requiring users to type anything strange into their browsers (arbitrary port numbers). You can even have each server redirect traffic to the other (e.g. ... | 0 | 2010-02-23T16:20:37Z | [
"python",
"apache",
"webserver",
"conflict"
] |
Can I run two web servers on the same computer? | 2,319,697 | <p>I just found out that I can write a really <a href="http://fragments.turtlemeat.com/pythonwebserver.php">simple web server</a> using Python. I have already an Apache web server I would like to try the Python based web server on this machine. But I am afraid that I can get some kind of conflict if I try it. I mean h... | 12 | 2010-02-23T16:10:40Z | 2,735,298 | <p>If you actually want to run separate servers to test out server software see the other answers, but...</p>
<p>It sounds like (because you are a developer, not a sysadmin right?) you <em>really</em> just want to run Python and PHP sites on the same computer. So, forgive me if I'm reading into your question, but thi... | 5 | 2010-04-29T06:54:18Z | [
"python",
"apache",
"webserver",
"conflict"
] |
Open a program with python minimized or hidden | 2,319,838 | <p>What I'm trying to do is to write a script which would open an application only in process list. Meaning it would be "hidden". I don't even know if its possible in python.</p>
<p>If its not possible, I would settle for even a function that would allow for a program to be opened with python in a minimized state mayb... | 1 | 2010-02-23T16:27:26Z | 2,319,859 | <p>If what is appearing is a terminal, redirect the process's stdout.</p>
| 0 | 2010-02-23T16:30:53Z | [
"python",
"windows"
] |
Open a program with python minimized or hidden | 2,319,838 | <p>What I'm trying to do is to write a script which would open an application only in process list. Meaning it would be "hidden". I don't even know if its possible in python.</p>
<p>If its not possible, I would settle for even a function that would allow for a program to be opened with python in a minimized state mayb... | 1 | 2010-02-23T16:27:26Z | 2,319,944 | <p>What is the purpose?</p>
<p>if you want a hidden(no window) process working in background, best way would be to write a windows service and start/stop it using usual window service mechanism. Windows service can be easily written in python e.g. here is part of my own service (it will not run without some modificati... | 0 | 2010-02-23T16:42:18Z | [
"python",
"windows"
] |
Open a program with python minimized or hidden | 2,319,838 | <p>What I'm trying to do is to write a script which would open an application only in process list. Meaning it would be "hidden". I don't even know if its possible in python.</p>
<p>If its not possible, I would settle for even a function that would allow for a program to be opened with python in a minimized state mayb... | 1 | 2010-02-23T16:27:26Z | 2,323,367 | <p>You should use win32api and hide your window e.g. using <a href="http://msdn.microsoft.com/en-us/library/ms633497%28VS.85%29.aspx" rel="nofollow">win32gui.EnumWindows</a> you can enumerate all top windows and hide your window</p>
<p>Here is a small example, you may do something like this:</p>
<pre><code>import sub... | 2 | 2010-02-24T02:58:54Z | [
"python",
"windows"
] |
Open a program with python minimized or hidden | 2,319,838 | <p>What I'm trying to do is to write a script which would open an application only in process list. Meaning it would be "hidden". I don't even know if its possible in python.</p>
<p>If its not possible, I would settle for even a function that would allow for a program to be opened with python in a minimized state mayb... | 1 | 2010-02-23T16:27:26Z | 32,121,910 | <p>It's easy :) <br />
Python Popen Accept STARTUPINFO Structure...<br />
About STARTUPINFO Structure: <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v=vs.85).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v=vs.85).aspx</a></p>
<p>Run Hidden:</p>
<pr... | 4 | 2015-08-20T15:07:29Z | [
"python",
"windows"
] |
M2Crypto: Override Post Connection Check of HostName | 2,319,909 | <p>I am using M2Crypto 0.20.2 and python 2.4.3. I connect to the server with the fully qualified domain name. The common name in the server certificate does not use the FQDN so I get this error:</p>
<p><code>M2Crypto.SSL.Checker.WrongHost: Peer certificate commonName does not match host</code></p>
<p>How do I overr... | 2 | 2010-02-23T16:37:46Z | 2,321,344 | <p>Setting <code>SSL.Connection.clientPostConnectionCheck = None</code> does bypass the WrongHost check, but it also bypasses many other checks that you probably don't want to bypass (such as checking if there is any certificate at all). I would recommend using a try/except combo to catch the WrongHost because there is... | 2 | 2010-02-23T20:11:01Z | [
"python",
"m2crypto"
] |
Python: Fastest way to iterate this through a large file | 2,319,928 | <p>Right, I'm iterating through a large binary file</p>
<p>I need to minimise the time of this loop:</p>
<pre><code>def NB2(self, ID_LEN):
r1=np.fromfile(ReadFile.fid,dTypes.NB_HDR,1)
num_receivers=r1[0][0]
num_channels=r1[0][1]
num_samples=r1[0][5]
blockReturn = np.zeros((num_samples,num_receive... | 2 | 2010-02-23T16:39:51Z | 2,320,014 | <p>This is more of an observation than a solution, but porting that function to C++ and loading it in with the Python API would get you a lot of speed gain to begin with before loop optimization.</p>
| 0 | 2010-02-23T16:50:10Z | [
"python",
"binary",
"numpy",
"iteration"
] |
Python: Fastest way to iterate this through a large file | 2,319,928 | <p>Right, I'm iterating through a large binary file</p>
<p>I need to minimise the time of this loop:</p>
<pre><code>def NB2(self, ID_LEN):
r1=np.fromfile(ReadFile.fid,dTypes.NB_HDR,1)
num_receivers=r1[0][0]
num_channels=r1[0][1]
num_samples=r1[0][5]
blockReturn = np.zeros((num_samples,num_receive... | 2 | 2010-02-23T16:39:51Z | 2,320,159 | <p>I'd try to use as few loops and as much constants as possible.
Everything that can be done in a linear fashion should be done so.
If values don't change, use constants to reduce lookups and such,
because that eats up cpu cycles.</p>
<p>This is from a theoretical point of view ;-)</p>
<p>If possible use highly opti... | 1 | 2010-02-23T17:13:33Z | [
"python",
"binary",
"numpy",
"iteration"
] |
Python: Fastest way to iterate this through a large file | 2,319,928 | <p>Right, I'm iterating through a large binary file</p>
<p>I need to minimise the time of this loop:</p>
<pre><code>def NB2(self, ID_LEN):
r1=np.fromfile(ReadFile.fid,dTypes.NB_HDR,1)
num_receivers=r1[0][0]
num_channels=r1[0][1]
num_samples=r1[0][5]
blockReturn = np.zeros((num_samples,num_receive... | 2 | 2010-02-23T16:39:51Z | 2,320,690 | <pre><code>import numpy as np
def NB2(self, ID_LEN):
r1=np.fromfile(ReadFile.fid,dTypes.NB_HDR,1)
num_receivers=r1[0][0]
num_channels=r1[0][1]
num_samples=r1[0][5]
# first, match your array bounds to the way you are walking the file
blockReturn = np.zeros((num_receivers,num_channels,num_samples... | 3 | 2010-02-23T18:26:42Z | [
"python",
"binary",
"numpy",
"iteration"
] |
Python: Fastest way to iterate this through a large file | 2,319,928 | <p>Right, I'm iterating through a large binary file</p>
<p>I need to minimise the time of this loop:</p>
<pre><code>def NB2(self, ID_LEN):
r1=np.fromfile(ReadFile.fid,dTypes.NB_HDR,1)
num_receivers=r1[0][0]
num_channels=r1[0][1]
num_samples=r1[0][5]
blockReturn = np.zeros((num_samples,num_receive... | 2 | 2010-02-23T16:39:51Z | 2,320,723 | <p>Most importantly, you shouldn't do file access at the lowest level of a triple nested loop, whether you do this in C or Python. You've got to read in large chunks of data at a time.</p>
<p>So to speed this up, read in large chunks of data at a time, and process that data using numpy indexing (that is, vectorize yo... | 1 | 2010-02-23T18:32:03Z | [
"python",
"binary",
"numpy",
"iteration"
] |
Python: Fastest way to iterate this through a large file | 2,319,928 | <p>Right, I'm iterating through a large binary file</p>
<p>I need to minimise the time of this loop:</p>
<pre><code>def NB2(self, ID_LEN):
r1=np.fromfile(ReadFile.fid,dTypes.NB_HDR,1)
num_receivers=r1[0][0]
num_channels=r1[0][1]
num_samples=r1[0][5]
blockReturn = np.zeros((num_samples,num_receive... | 2 | 2010-02-23T16:39:51Z | 2,320,746 | <p>Because you know the length of a block after you read the header, read the whole block at once. Then reshape the array (very fast, only affects metadata) and take use the <code>np.hypot</code> ufunc:</p>
<pre><code>blockData = np.fromfile(ReadFile.fid, np.int16, num_receivers*num_channels*num_samples*2)
blockData =... | 3 | 2010-02-23T18:34:25Z | [
"python",
"binary",
"numpy",
"iteration"
] |
Python and curl question | 2,320,107 | <p>I will be transmitting purchase info (like CC) to a bank gateway and retrieve the result by using Django thus via Python.</p>
<p>What would be the efficient and secure way of doing this?</p>
<p>I have read a documentation of this gateway for php, they seem to use this method:</p>
<pre><code>$xml= Some xml holding... | 4 | 2010-02-23T17:05:27Z | 2,320,147 | <p>Citing pycurl.sourceforge.net:</p>
<blockquote>
<p>To sum up, PycURL is very fast (esp. for multiple concurrent operations) and very feature complete, but has a somewhat complex interface. If you need something simpler or prefer a pure Python module you might want to check out urllib2 and urlgrabber. There is als... | 3 | 2010-02-23T17:11:02Z | [
"python",
"django",
"curl"
] |
Python and curl question | 2,320,107 | <p>I will be transmitting purchase info (like CC) to a bank gateway and retrieve the result by using Django thus via Python.</p>
<p>What would be the efficient and secure way of doing this?</p>
<p>I have read a documentation of this gateway for php, they seem to use this method:</p>
<pre><code>$xml= Some xml holding... | 4 | 2010-02-23T17:05:27Z | 2,320,926 | <p>Use of the standard library <code>urllib2</code> module should be enough:</p>
<pre><code>import urllib
import urllib2
request_data = urllib.urlencode({"DATA": xml})
response = urllib2.urlopen("https://url of the virtual bank POS", request_data)
response_data = response.read()
data = response_data.split('\n')
</co... | 10 | 2010-02-23T19:07:21Z | [
"python",
"django",
"curl"
] |
In Python, what's a good pattern for disabling certain code during unit tests? | 2,320,210 | <p>In general I want to disable as little code as possible, and I want it to be explicit: I don't want the code being tested to decide whether it's a test or not, I want the test to tell that code "hey, BTW, I'm running a unit test, can you please not make your call to solr, instead can you please stick what you would ... | 10 | 2010-02-23T17:20:48Z | 2,320,302 | <p>You have two ways to do this is no <sub>,or minimal in the case of <a href="http://stackoverflow.com/questions/130794/what-is-dependency-injection">DI</a>,</sub> modifications to your source code</p>
<ul>
<li><a href="http://stackoverflow.com/questions/130794/what-is-dependency-injection">Dependency injection</a></... | 0 | 2010-02-23T17:32:24Z | [
"python",
"unit-testing",
"testing",
"dependency-injection"
] |
In Python, what's a good pattern for disabling certain code during unit tests? | 2,320,210 | <p>In general I want to disable as little code as possible, and I want it to be explicit: I don't want the code being tested to decide whether it's a test or not, I want the test to tell that code "hey, BTW, I'm running a unit test, can you please not make your call to solr, instead can you please stick what you would ... | 10 | 2010-02-23T17:20:48Z | 2,320,317 | <p>You can use <a href="http://en.wikipedia.org/wiki/Mock_object" rel="nofollow">Mock objects</a> to intercept the method calls that you do not want to execute.
E.g. You have some class <code>A</code>, where you don't want method <code>no()</code> to be called during a test.</p>
<pre><code>class A:
def do(self):
... | 7 | 2010-02-23T17:34:13Z | [
"python",
"unit-testing",
"testing",
"dependency-injection"
] |
In Python, what's a good pattern for disabling certain code during unit tests? | 2,320,210 | <p>In general I want to disable as little code as possible, and I want it to be explicit: I don't want the code being tested to decide whether it's a test or not, I want the test to tell that code "hey, BTW, I'm running a unit test, can you please not make your call to solr, instead can you please stick what you would ... | 10 | 2010-02-23T17:20:48Z | 2,320,366 | <p>Typically when something like this arises you use Monkey Patching (also called Duck Punching) to achieve the desired results. Check out <a href="http://en.wikipedia.org/wiki/Monkey_patch" rel="nofollow">this link</a> to learn more about Monkey Patching.</p>
<p>In this case, for example, you would overwrite solr to ... | 0 | 2010-02-23T17:40:44Z | [
"python",
"unit-testing",
"testing",
"dependency-injection"
] |
In Python, what's a good pattern for disabling certain code during unit tests? | 2,320,210 | <p>In general I want to disable as little code as possible, and I want it to be explicit: I don't want the code being tested to decide whether it's a test or not, I want the test to tell that code "hey, BTW, I'm running a unit test, can you please not make your call to solr, instead can you please stick what you would ... | 10 | 2010-02-23T17:20:48Z | 2,320,706 | <p>Use Michael Foord's <a href="http://www.voidspace.org.uk/python/mock/" rel="nofollow">Mock</a>
in your unit test do this:</p>
<pre><code>from mock import Mock
class Person(object):
def __init__(self, name):
super(Person, self).__init__()
self.name = name
def say(self, str):
print "... | 5 | 2010-02-23T18:28:31Z | [
"python",
"unit-testing",
"testing",
"dependency-injection"
] |
In Python, what's a good pattern for disabling certain code during unit tests? | 2,320,210 | <p>In general I want to disable as little code as possible, and I want it to be explicit: I don't want the code being tested to decide whether it's a test or not, I want the test to tell that code "hey, BTW, I'm running a unit test, can you please not make your call to solr, instead can you please stick what you would ... | 10 | 2010-02-23T17:20:48Z | 2,320,900 | <p>I know it's the typical use case for mock objects, but that's also an old argument... are Mock objects necessary at all or are they <strong>evil</strong> ?</p>
<p>I'm on the side of those who believe mocks are <strong>evil</strong> and would try to avoid changing tested code at all. I even believe such need to modi... | 0 | 2010-02-23T19:03:47Z | [
"python",
"unit-testing",
"testing",
"dependency-injection"
] |
In Python, what's a good pattern for disabling certain code during unit tests? | 2,320,210 | <p>In general I want to disable as little code as possible, and I want it to be explicit: I don't want the code being tested to decide whether it's a test or not, I want the test to tell that code "hey, BTW, I'm running a unit test, can you please not make your call to solr, instead can you please stick what you would ... | 10 | 2010-02-23T17:20:48Z | 2,321,289 | <p>The big problem that I was having was with the mechanics of the dependency injection. I have now figured that part out.</p>
<p>I need to import the module in the exact same way in both places to successfully inject the new code. For example, if I have the following code that I want to disable:</p>
<pre><code>from ... | 1 | 2010-02-23T20:03:27Z | [
"python",
"unit-testing",
"testing",
"dependency-injection"
] |
UTF-8 Encoding error, need help converting text | 2,320,315 | <p>I've been working on a statistical translation system for haiti (code.google.com/p/ccmts) that uses a C++ backend (http://www.statmt.org/moses/?n=Development.GetStarted) and Python drives the C++ engine/backend.</p>
<p>I've passed a UTF-8 Python string into a C++ <code>std::string</code>, done some processing, gott... | 2 | 2010-02-23T17:34:00Z | 2,320,543 | <p>Looks like your <a href="http://docs.python.org/library/sys.html#sys.getdefaultencoding" rel="nofollow">default encoding</a> is ASCII.</p>
<p>You can either explicitly convert your unicode strings:</p>
<pre><code>print u"Hellö, Wörld".encode("utf-8")
</code></pre>
<p>Or, if you want to change this globally in y... | 1 | 2010-02-23T18:03:13Z | [
"c++",
"python",
"unicode",
"swig"
] |
UTF-8 Encoding error, need help converting text | 2,320,315 | <p>I've been working on a statistical translation system for haiti (code.google.com/p/ccmts) that uses a C++ backend (http://www.statmt.org/moses/?n=Development.GetStarted) and Python drives the C++ engine/backend.</p>
<p>I've passed a UTF-8 Python string into a C++ <code>std::string</code>, done some processing, gott... | 2 | 2010-02-23T17:34:00Z | 2,321,860 | <p>Edit: Nevermind that junk I posted before; it was wrong.</p>
<p>As others have suggested, this will get you the correct unicode object in python, assuming that's meant to be utf-8:</p>
<pre><code>>>> ' mwen bezwen \xc3\xa3 \xc2\xa8 d medikal '.decode('utf-8')
u' mwen bezwen \xe3 \xa8 d medikal '
>>&... | 1 | 2010-02-23T21:27:18Z | [
"c++",
"python",
"unicode",
"swig"
] |
UTF-8 Encoding error, need help converting text | 2,320,315 | <p>I've been working on a statistical translation system for haiti (code.google.com/p/ccmts) that uses a C++ backend (http://www.statmt.org/moses/?n=Development.GetStarted) and Python drives the C++ engine/backend.</p>
<p>I've passed a UTF-8 Python string into a C++ <code>std::string</code>, done some processing, gott... | 2 | 2010-02-23T17:34:00Z | 2,321,931 | <p>It looks like a case of garbage in, garbage out. Here are a few clues on how to see what you've got in your data. <code>repr()</code> and <code>unicodedata.name()</code> are your friends.</p>
<pre><code>>>> s = ' mwen bezwen \xc3\xa3 \xc2\xa8 d medikal '
>>> print repr(s.decode('utf8'))
u' mwen be... | 3 | 2010-02-23T21:37:44Z | [
"c++",
"python",
"unicode",
"swig"
] |
python & sql server | 2,320,342 | <p>When I do a select statement for varbinary field in microsoft enterprise manager i get the field on readabel hex format like ab2c2f2d... but when i do the same statment with pymssql i get a gibrish</p>
<p>the select statment is : select x from table --where x the varbinary field</p>
<p>could someone help with thi... | 0 | 2010-02-23T17:38:15Z | 2,320,552 | <p>Microsoft Enterprise Manager is converting the binary value to a hexadecimal string for you. </p>
<p>One option is to change your query to SELECT CAST( x AS varchar ) FROM table. This will have SQL Server convert the varbinary to a hexdecimal string for you, <a href="http://msdn.microsoft.com/en-us/library/aa2260... | 2 | 2010-02-23T18:05:46Z | [
"python",
"sql-server"
] |
Yet another Subversion "Commit failed" MERGE of 'blabla': 200 OK | 2,320,787 | <p>I get the infamous "MERGE of 'whatever': 200 OK" whenever I try to commit using a post-commit hook on Windows (running the repository and Trac locally), and I'm going crazy. I've been looking all over for a day now, without finding any solutions.</p>
<p>So here's how it's set up and what I've tried so far:</p>
<p>... | 0 | 2010-02-23T18:42:45Z | 2,320,951 | <p>To get the error message while doing the SVN commit, you should be able to change:</p>
<pre><code>if __name__ == "__main__":
if len(sys.argv) < 5:
print "For usage: %s --help" % (sys.argv[0])
else:
CommitHook()
</code></pre>
<p>to:</p>
<pre><code>if __name__ == "__main__":
if ... | 0 | 2010-02-23T19:10:32Z | [
"python",
"svn",
"tortoisesvn",
"post-commit",
"visualsvn-server"
] |
Remove and ignore all files that have an extension from a git repository | 2,320,895 | <p>I'm working on a django project with a few other developers and we have recently realized that all the .pwc files in our app cause the commits and repository to be cluttered.</p>
<p>Is there any way I can remove all .pwc files from all child directories in my git repository and then ignore them for any future commi... | 26 | 2010-02-23T19:03:13Z | 2,320,930 | <p>Plenty of ways to remove them:</p>
<pre><code>git ls-files | grep '\.pwc$' | xargs git rm
find . -name *.pwc | xargs git rm
</code></pre>
<p>Note: If you haven't committed them, just use <code>rm</code>, not <code>git rm</code>.</p>
<p>To ignore them in the future, simply add *.pwc to the .gitignore. (If you don... | 37 | 2010-02-23T19:07:37Z | [
"python",
"django",
"git",
"github"
] |
Remove and ignore all files that have an extension from a git repository | 2,320,895 | <p>I'm working on a django project with a few other developers and we have recently realized that all the .pwc files in our app cause the commits and repository to be cluttered.</p>
<p>Is there any way I can remove all .pwc files from all child directories in my git repository and then ignore them for any future commi... | 26 | 2010-02-23T19:03:13Z | 2,321,075 | <p>Jefromi's answer will remove them for the present and the future...you could also remove them in the past using <a href="http://git-scm.com/docs/git-filter-branch" rel="nofollow">git filter-branch</a>. Of course this has some other ramifications, like requiring everyone else working on the repo to re-checkout (and p... | 3 | 2010-02-23T19:32:39Z | [
"python",
"django",
"git",
"github"
] |
Remove and ignore all files that have an extension from a git repository | 2,320,895 | <p>I'm working on a django project with a few other developers and we have recently realized that all the .pwc files in our app cause the commits and repository to be cluttered.</p>
<p>Is there any way I can remove all .pwc files from all child directories in my git repository and then ignore them for any future commi... | 26 | 2010-02-23T19:03:13Z | 14,625,656 | <p>You can also use the following: </p>
<pre><code>git rm -r '*.pwc'
</code></pre>
<p>and then make those files ignored by git:</p>
<pre><code>echo '*.pwc' >> .gitignore
</code></pre>
<p>The last one is in case if you already have .gitignore file, if not, us single '>' sign.</p>
| 11 | 2013-01-31T12:20:28Z | [
"python",
"django",
"git",
"github"
] |
Remove and ignore all files that have an extension from a git repository | 2,320,895 | <p>I'm working on a django project with a few other developers and we have recently realized that all the .pwc files in our app cause the commits and repository to be cluttered.</p>
<p>Is there any way I can remove all .pwc files from all child directories in my git repository and then ignore them for any future commi... | 26 | 2010-02-23T19:03:13Z | 35,080,612 | <p>In <em>Windows</em> this worked for me:</p>
<pre><code>git rm -r '*.pwc' -f
</code></pre>
<p>And for keeping it in .gitignore</p>
<pre><code>echo '*.pwc' >> .gitignore
</code></pre>
| 0 | 2016-01-29T09:07:03Z | [
"python",
"django",
"git",
"github"
] |
Python: Using vars() to assign a string to a variable | 2,320,945 | <p>I find it very useful to be able to create new variables during runtime and create a dictionary of the results for processing later, i.e. writing to a file:</p>
<pre><code>myDict = {}
for i in range (1,10):
temp = "variable"+str(i)
vars()[temp] = myFunctionThatReturnsData() # variable1= data1, variable2 = ... | 17 | 2010-02-23T19:09:41Z | 2,320,989 | <p>I can answer number 3: this isn't good programming practice. I don't exactly see what you are trying to accomplish, but I am sure there is a more elegant way of doing it without using <code>locals()</code> (which is the same as <code>vars()</code> according to <code>help(vars)</code> in the interactive Python shell)... | 2 | 2010-02-23T19:16:45Z | [
"python",
"string",
"dictionary",
"variables"
] |
Python: Using vars() to assign a string to a variable | 2,320,945 | <p>I find it very useful to be able to create new variables during runtime and create a dictionary of the results for processing later, i.e. writing to a file:</p>
<pre><code>myDict = {}
for i in range (1,10):
temp = "variable"+str(i)
vars()[temp] = myFunctionThatReturnsData() # variable1= data1, variable2 = ... | 17 | 2010-02-23T19:09:41Z | 2,320,995 | <p>From the help for vars,</p>
<blockquote>
<p>vars(...)
vars([object]) -> dictionary</p>
<pre><code>Without arguments, equivalent to locals().
With an argument, equivalent to object.__dict__.
</code></pre>
</blockquote>
<p>You are using it without vars, so let's look at the help for locals()</p>
<blockquot... | 5 | 2010-02-23T19:19:30Z | [
"python",
"string",
"dictionary",
"variables"
] |
Python: Using vars() to assign a string to a variable | 2,320,945 | <p>I find it very useful to be able to create new variables during runtime and create a dictionary of the results for processing later, i.e. writing to a file:</p>
<pre><code>myDict = {}
for i in range (1,10):
temp = "variable"+str(i)
vars()[temp] = myFunctionThatReturnsData() # variable1= data1, variable2 = ... | 17 | 2010-02-23T19:09:41Z | 2,321,474 | <p>Do this instead. It's simpler. </p>
<pre><code>myDict = {}
for i in range (1,10):
temp = "variable"+str(i)
myDict[temp] = myFunctionThatReturnsData() # variable1= data1, variable2 = data2,etc.
</code></pre>
<p>That's all you ever need to do.</p>
<p>The results will be <code>myDict['variable1']</code> t... | 5 | 2010-02-23T20:29:06Z | [
"python",
"string",
"dictionary",
"variables"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.