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 |
|---|---|---|---|---|---|---|---|---|---|
Python programming general questions | 1,926,019 | <p>I heard that Python is easy and powerful, but I don't know if I'm on the right track to learn it. I learn from online tutorials, I know basic maths calculation and printing strings, but how long will it take to develop something useful? I don't really know the exact uses of Python, though.</p>
| 0 | 2009-12-18T03:02:11Z | 1,926,200 | <p>Making a comparison between Python, and other languages would not help, as there is always somebody who would find a reason to prefer one language instead of another.<br>
If you want a scripting language that is powerful, but that it is easier to read than perl, that doesn't have a curly bracket syntax, and that all... | 0 | 2009-12-18T04:00:29Z | [
"python"
] |
How should I perform cleanup at the end of a repoze.bfg response? | 1,926,169 | <p>Example code for the <a href="http://bfg.repoze.org/" rel="nofollow">repoze.bfg</a> web framework performs post-response cleanup by adding a <code>__del__</code> method to an object attached to the request's <code>environ</code>.</p>
<p>Is there a better way to clean up database connections, etc. after the response... | 0 | 2009-12-18T03:50:39Z | 1,926,300 | <p>Since you are dealing with repoze.bfg, best you use their documented way of doing things as it is going to be compatible with their framework and how they manage the request lifecycle. That said, if you want the generic WSGI way of doing it, it is documented in:</p>
<p><a href="http://code.google.com/p/modwsgi/wiki... | 1 | 2009-12-18T04:36:33Z | [
"python",
"wsgi",
"repoze.bfg"
] |
How do I plug a new templating language into repoze.bfg? | 1,926,199 | <p>What do I need to implement to add a new templating language to repoze.bfg? Will the framework send my plugin absolute paths or package relative paths, or both depending?</p>
| 0 | 2009-12-18T04:00:27Z | 1,929,163 | <p>The package at <a href="http://svn.repoze.org/repoze.bfg.jinja2/trunk/repoze/bfg/jinja2/" rel="nofollow">http://svn.repoze.org/repoze.bfg.jinja2/trunk/repoze/bfg/jinja2/</a> provides add-on Jinja2 bindings for BFG. Basically, you do create a package like that, then allow folks to wire it into their systems.</p>
<... | 2 | 2009-12-18T16:14:33Z | [
"python",
"repoze.bfg"
] |
Editing the XML texts from a XML file using Python | 1,926,512 | <p>I have an XML file which contains some data as given.</p>
<pre><code><?xml version="1.0" encoding="UTF-8" ?>
- <ParameterData>
<CreationInfo date="10/28/2009 03:05:14 PM" user="manoj" />
- <ParameterList count="85">
- <Parameter name="Spec 2 Included" type="boolean" mode="both">
... | 6 | 2009-12-18T05:39:52Z | 1,926,556 | <p>Well, you could start with</p>
<pre><code>import xml.etree.ElementTree as ET
tree = ET.parse("blah.xml")
</code></pre>
<p><a href="http://effbot.org/zone/element.htm#searching-for-subelements" rel="nofollow">Find the elements</a> you want to modify.</p>
<p>To replace the contents of an element, just do</p>
<pre>... | 4 | 2009-12-18T05:53:25Z | [
"python",
"xml"
] |
Editing the XML texts from a XML file using Python | 1,926,512 | <p>I have an XML file which contains some data as given.</p>
<pre><code><?xml version="1.0" encoding="UTF-8" ?>
- <ParameterData>
<CreationInfo date="10/28/2009 03:05:14 PM" user="manoj" />
- <ParameterList count="85">
- <Parameter name="Spec 2 Included" type="boolean" mode="both">
... | 6 | 2009-12-18T05:39:52Z | 1,926,787 | <p>You can convert your data text into python dictionary by regular expression</p>
<pre><code>data="""Spec 2 Included : TRUE
Spec 2 Label: 19-Flat2-HS3
Spec 3 Included : FALSE
Spec 3 Label: 4-1-Bead1-HS3"""
#data=open("data.txt").read()
import re
data=dict(re.findall('(Spec \d+ (?:Included|Label))\s*:\s*(\S+)',data... | 6 | 2009-12-18T07:09:27Z | [
"python",
"xml"
] |
Editing the XML texts from a XML file using Python | 1,926,512 | <p>I have an XML file which contains some data as given.</p>
<pre><code><?xml version="1.0" encoding="UTF-8" ?>
- <ParameterData>
<CreationInfo date="10/28/2009 03:05:14 PM" user="manoj" />
- <ParameterList count="85">
- <Parameter name="Spec 2 Included" type="boolean" mode="both">
... | 6 | 2009-12-18T05:39:52Z | 1,927,314 | <p>Unfortunately, the XPath supported by ElementTree isn't complete. Since Python 2.6 includes an older version, finding elements by attribute (as stated <a href="http://effbot.org/zone/element-xpath.htm" rel="nofollow">here</a>) does not work. So <a href="http://docs.python.org/" rel="nofollow">Python's own documentat... | 1 | 2009-12-18T09:59:33Z | [
"python",
"xml"
] |
Editing the XML texts from a XML file using Python | 1,926,512 | <p>I have an XML file which contains some data as given.</p>
<pre><code><?xml version="1.0" encoding="UTF-8" ?>
- <ParameterData>
<CreationInfo date="10/28/2009 03:05:14 PM" user="manoj" />
- <ParameterList count="85">
- <Parameter name="Spec 2 Included" type="boolean" mode="both">
... | 6 | 2009-12-18T05:39:52Z | 1,934,375 | <p>Here is how you could do it using <a href="http://wiki.xml3k.org/Amara2" rel="nofollow">Amara</a></p>
<pre><code>from amara import bindery
doc = bindery.parse(XML)
def cleanup_for_dict(key, value):
return key.strip(), value.strip()
params = dict(( cleanup_for_dict(*line.split(':', 1))
for lin... | 1 | 2009-12-19T22:59:21Z | [
"python",
"xml"
] |
what is blocking and non-blocking web server, what difference between both? | 1,926,602 | <p>i have seen many web framework provide non-blocking web server, i just want to know what it mean.</p>
| 19 | 2009-12-18T06:07:58Z | 1,926,619 | <p>Non-blocking generally means event driven, multiplexing all activity via an event driven system in a single thread, as opposed to using multiple threads.</p>
| 4 | 2009-12-18T06:12:11Z | [
"python",
"webserver"
] |
what is blocking and non-blocking web server, what difference between both? | 1,926,602 | <p>i have seen many web framework provide non-blocking web server, i just want to know what it mean.</p>
| 19 | 2009-12-18T06:07:58Z | 1,926,631 | <p>Using a <strong>blocking</strong> socket, execution will wait (ie. "block") until the full socket operation has taken place. So, you can process any results/responses in your code immediately after. These are also called <em>synchronous</em> sockets.</p>
<p>A <strong>non-blocking</strong> socket operation will al... | 28 | 2009-12-18T06:16:05Z | [
"python",
"webserver"
] |
what is blocking and non-blocking web server, what difference between both? | 1,926,602 | <p>i have seen many web framework provide non-blocking web server, i just want to know what it mean.</p>
| 19 | 2009-12-18T06:07:58Z | 5,670,665 | <p>a blocking web-server is similar to a phone call. you need to wait on-line to get a response and continue; where as a non-blocking web-server is like a sms service. you sms your request,do your things and react when you receive an sms back!</p>
| 49 | 2011-04-14T22:58:00Z | [
"python",
"webserver"
] |
Strange thing about tabbar.. Help me to solve | 1,926,863 | <p>I just started learning pyqt.. When i'm experimenting with the tabbar i encountered this.. As a minimal example i want to show a button in tab1 and a label in tab2.. Here's what i did</p>
<pre><code>from PyQt4 import QtGui
class Ui_TabWidget(QtGui.QTabWidget):
def __init__(self,parent=None):
... | 0 | 2009-12-18T07:33:44Z | 1,926,954 | <p>The best way to accomplish what you're trying here is to use a <code>QTabWidget</code>. It's much more convenient than <code>QTabBar</code> and will do everything you want 99.99% of the time.</p>
<p>Here's a canonical example of working with QTabWidget:</p>
<pre><code>from PyQt4.QtCore import *
from PyQt4.QtGui im... | 1 | 2009-12-18T08:03:20Z | [
"python",
"pyqt"
] |
Strange thing about tabbar.. Help me to solve | 1,926,863 | <p>I just started learning pyqt.. When i'm experimenting with the tabbar i encountered this.. As a minimal example i want to show a button in tab1 and a label in tab2.. Here's what i did</p>
<pre><code>from PyQt4 import QtGui
class Ui_TabWidget(QtGui.QTabWidget):
def __init__(self,parent=None):
... | 0 | 2009-12-18T07:33:44Z | 7,294,781 | <p>I know it's been a while since this question was asked, but I notice your response to the previous answer was that you needed to be able to customize the tabs using stylesheets. This is also possible when using QTabWidget! Since all QWidgets have <a href="http://doc.trolltech.com/latest/qwidget.html#styleSheet-prop"... | 2 | 2011-09-03T17:43:52Z | [
"python",
"pyqt"
] |
How to run server script indefinitely | 1,927,144 | <p>I would like to run an asynchronous program on a remote linux server indefinitely. This script doesn't output anything to the server itself(other than occasionally writing information to a mysql database). So far the only option I have been able to find is the nohup command:</p>
<pre><code>nohup script_name &
<... | 2 | 2009-12-18T09:10:03Z | 1,927,187 | <p>That is the simplest way to do it if you want to (or have to) avoid changing the script itself. If the script is always to be run like this, you can write a mini script containing the line you just typed and run that instead. (or use an alias, if appropriate) </p>
<p>To answer you second question:</p>
<pre><code> ... | 0 | 2009-12-18T09:25:14Z | [
"python",
"linux",
"nohup"
] |
How to run server script indefinitely | 1,927,144 | <p>I would like to run an asynchronous program on a remote linux server indefinitely. This script doesn't output anything to the server itself(other than occasionally writing information to a mysql database). So far the only option I have been able to find is the nohup command:</p>
<pre><code>nohup script_name &
<... | 2 | 2009-12-18T09:10:03Z | 1,927,230 | <p>If you can modify the script, then you can catch <code>SIGHUP</code> signals and avoid the need for <code>nohup</code>. In a bash script you would write:</p>
<pre><code>trap " echo ignoring hup; " SIGHUP
</code></pre>
<p>You can employ the same technique to terminate the program: catch, say, a SIGUSR1 signal in a ... | 2 | 2009-12-18T09:34:44Z | [
"python",
"linux",
"nohup"
] |
How to run server script indefinitely | 1,927,144 | <p>I would like to run an asynchronous program on a remote linux server indefinitely. This script doesn't output anything to the server itself(other than occasionally writing information to a mysql database). So far the only option I have been able to find is the nohup command:</p>
<pre><code>nohup script_name &
<... | 2 | 2009-12-18T09:10:03Z | 1,930,015 | <p>What you are basically asking is "How do I create a daemon process?" What you want to do is "daemonize", there are many examples of this floating around on the web. The process is basically that you <code>fork()</code>, the child creates a new session, the parent exits, the child duplicates and then closes open fi... | 3 | 2009-12-18T18:49:14Z | [
"python",
"linux",
"nohup"
] |
How to run server script indefinitely | 1,927,144 | <p>I would like to run an asynchronous program on a remote linux server indefinitely. This script doesn't output anything to the server itself(other than occasionally writing information to a mysql database). So far the only option I have been able to find is the nohup command:</p>
<pre><code>nohup script_name &
<... | 2 | 2009-12-18T09:10:03Z | 2,280,888 | <p>There are some situations when you want to execute/start some scripts on a remote machine/server (which will terminate automatically) and disconnect from the server.</p>
<p>eg: A script running on a box which when executed 1) takes a model and copies it to a custer (remote server) 2) creates a script for running a ... | 1 | 2010-02-17T13:18:18Z | [
"python",
"linux",
"nohup"
] |
Searching a file | 1,927,276 | <p>This is in reference to a question I posted yesterday <a href="http://stackoverflow.com/questions/1925284/searching-a-file-in-3-different-ways">http://stackoverflow.com/questions/1925284/searching-a-file-in-3-different-ways</a></p>
<p>I just require help now on two things, searching a file and and printing the line... | 0 | 2009-12-18T09:48:56Z | 1,927,413 | <p>for the first part</p>
<pre><code>for line in open("file"):
line=line.rstrip()
if "search" in line:
f=1
if f: print line
</code></pre>
<p>for the second part</p>
<pre><code>context=3
search="myword"
f=open("file")
d={}
for n,line in enumerate(f):
d[n%context]=line.rstrip()
if search in... | 2 | 2009-12-18T10:25:51Z | [
"python",
"file",
"search"
] |
Python OSError: [Errno 2] No such file or directory | 1,927,284 | <p>I am trying to write this script to my linux terminal and I am recieving the following error message: "OSError: [Errno 2] No such file or directory". Can anyone help, Thanks</p>
<pre><code>#!/home/build/test/Python-2.6.4
import os, subprocess
# Create a long command line
cmd =[\
"si createsandbox --yes --host... | 1 | 2009-12-18T09:51:52Z | 1,927,313 | <p>If the error is in your script, May be you got error on this line</p>
<pre><code>errptr = file(errFile, "r")
</code></pre>
<p>you can do like </p>
<pre><code>if os.path.exists(errFile):
errptr = file(errFile, "r")
errData = errptr.read()
errptr.close()
raise Exception("Error executing command: " + repr(er... | 4 | 2009-12-18T09:59:20Z | [
"python"
] |
Python OSError: [Errno 2] No such file or directory | 1,927,284 | <p>I am trying to write this script to my linux terminal and I am recieving the following error message: "OSError: [Errno 2] No such file or directory". Can anyone help, Thanks</p>
<pre><code>#!/home/build/test/Python-2.6.4
import os, subprocess
# Create a long command line
cmd =[\
"si createsandbox --yes --host... | 1 | 2009-12-18T09:51:52Z | 16,078,236 | <p>try modify like this:</p>
<pre><code>cmd =[\
"si", \
" createsandbox --yes --hostname=be", \
" --port=70", \
" --user=gh", \
" --password=34", \
" --populate --project=e:/project.pj", \
" --lineTerminator=lf new_sandbox"\
]
</code></pre>
<p>I guset subprocess.call will think that the first parameter... | 0 | 2013-04-18T08:39:47Z | [
"python"
] |
Python script running in linux | 1,927,375 | <p>I am having trouble trying to get this script to work. When I debug this code it will not read into the class or functions. The code will not execute properly. Has anyone know the problem here, Thanks</p>
<pre><code>#!/home/build/test/Python-2.6.4
import os, subprocess
class mks_function:
sandbox="new_sandbox"
... | 1 | 2009-12-18T10:13:00Z | 1,927,385 | <p>Try put as the first line:</p>
<pre><code>#!/usr/bin/env python
</code></pre>
<p>If you really need specific version of Python, setup your environment before running.</p>
<p>Possible problems:</p>
<ul>
<li><p>your code is never executed (it's like you define the class only). Use it in the file (names are mislead... | 1 | 2009-12-18T10:15:47Z | [
"python"
] |
Python script running in linux | 1,927,375 | <p>I am having trouble trying to get this script to work. When I debug this code it will not read into the class or functions. The code will not execute properly. Has anyone know the problem here, Thanks</p>
<pre><code>#!/home/build/test/Python-2.6.4
import os, subprocess
class mks_function:
sandbox="new_sandbox"
... | 1 | 2009-12-18T10:13:00Z | 1,927,444 | <p>Few things to check your code</p>
<ul>
<li><code>call</code> should be <code>subprocess.call</code></li>
<li>better use full path when you call for example, <code>/usr/bin/si createsandbox</code>, you can check with <code>which si</code> in shell</li>
<li>instead of concatenating the commands <code>"si createsandbo... | 2 | 2009-12-18T10:32:03Z | [
"python"
] |
Python - Tkinter - Padding woes | 1,927,475 | <p>I have a scrollbar widget that ALWAYS hides the last 15 px under the resize button, is there an option to stop this happening on mac or a padding "under" the widget option?\</p>
<p>thanks!</p>
| 1 | 2009-12-18T10:44:47Z | 1,927,946 | <p>No, there isn't an option. You need to adjust your padding so that the scrollbar doesn't extend all the way to the bottom of the window. Perhaps the easiest way is to add a statusbar that extends across the bottom of the window. </p>
| 0 | 2009-12-18T12:29:07Z | [
"python",
"user-interface",
"tkinter"
] |
Python - Tkinter - Padding woes | 1,927,475 | <p>I have a scrollbar widget that ALWAYS hides the last 15 px under the resize button, is there an option to stop this happening on mac or a padding "under" the widget option?\</p>
<p>thanks!</p>
| 1 | 2009-12-18T10:44:47Z | 1,927,968 | <p>Or, you could also try switching to the place() layout manager.</p>
| -1 | 2009-12-18T12:34:57Z | [
"python",
"user-interface",
"tkinter"
] |
"For" loop first iteration | 1,927,544 | <p>Greetings pyc-sires and py-ladies,
I would like to inquire if there is an elegant pythonic way of executing some function on the first loop iteration.
The only possibility I can think of is:</p>
<pre><code>first = True
for member in something.get():
if first:
root.copy(member)
first = False
... | 33 | 2009-12-18T11:03:26Z | 1,927,563 | <p>Can't you do <code>root.copy(something.get())</code> before the loop?</p>
<p><strong>EDIT:</strong> Sorry, I missed the second bit. But you get the general idea. Otherwise, enumerate and check for <code>0</code>?</p>
<p><strong>EDIT2:</strong> Ok, got rid of the silly second idea.</p>
| 1 | 2009-12-18T11:07:31Z | [
"python",
"algorithm",
"iteration"
] |
"For" loop first iteration | 1,927,544 | <p>Greetings pyc-sires and py-ladies,
I would like to inquire if there is an elegant pythonic way of executing some function on the first loop iteration.
The only possibility I can think of is:</p>
<pre><code>first = True
for member in something.get():
if first:
root.copy(member)
first = False
... | 33 | 2009-12-18T11:03:26Z | 1,927,564 | <p>Something like this should work.</p>
<pre><code>for i, member in enumerate(something.get()):
if i == 0:
# Do thing
# Code for everything
</code></pre>
<p>However, I would strongly recommend thinking about your code to see if you really have to do it this way, because it's sort of "dirty". Better w... | 41 | 2009-12-18T11:07:38Z | [
"python",
"algorithm",
"iteration"
] |
"For" loop first iteration | 1,927,544 | <p>Greetings pyc-sires and py-ladies,
I would like to inquire if there is an elegant pythonic way of executing some function on the first loop iteration.
The only possibility I can think of is:</p>
<pre><code>first = True
for member in something.get():
if first:
root.copy(member)
first = False
... | 33 | 2009-12-18T11:03:26Z | 1,927,565 | <p>This works:</p>
<pre><code>for number, member in enumerate(something.get()):
if not number:
root.copy(member)
else:
somewhereElse.copy(member)
foo(member)
</code></pre>
<p>In most cases, though, I'd suggest just iterating over <code>whatever[1:]</code> and doing the root thing outside t... | 3 | 2009-12-18T11:07:49Z | [
"python",
"algorithm",
"iteration"
] |
"For" loop first iteration | 1,927,544 | <p>Greetings pyc-sires and py-ladies,
I would like to inquire if there is an elegant pythonic way of executing some function on the first loop iteration.
The only possibility I can think of is:</p>
<pre><code>first = True
for member in something.get():
if first:
root.copy(member)
first = False
... | 33 | 2009-12-18T11:03:26Z | 1,927,567 | <p>If something.get() iterates over something, you can do it also as follows:</p>
<pre><code>root.copy(something.get())
for member in something.get():
# the rest of the loop
</code></pre>
| 3 | 2009-12-18T11:08:33Z | [
"python",
"algorithm",
"iteration"
] |
"For" loop first iteration | 1,927,544 | <p>Greetings pyc-sires and py-ladies,
I would like to inquire if there is an elegant pythonic way of executing some function on the first loop iteration.
The only possibility I can think of is:</p>
<pre><code>first = True
for member in something.get():
if first:
root.copy(member)
first = False
... | 33 | 2009-12-18T11:03:26Z | 1,927,575 | <p>You have several choices for the <strong>Head-Tail</strong> design pattern.</p>
<pre><code>seq= something.get()
root.copy( seq[0] )
foo( seq[0] )
for member in seq[1:]:
somewhereElse.copy(member)
foo( member )
</code></pre>
<p>Or this</p>
<pre><code>seq_iter= iter( something.get() )
head = seq_iter.next()... | 22 | 2009-12-18T11:09:46Z | [
"python",
"algorithm",
"iteration"
] |
"For" loop first iteration | 1,927,544 | <p>Greetings pyc-sires and py-ladies,
I would like to inquire if there is an elegant pythonic way of executing some function on the first loop iteration.
The only possibility I can think of is:</p>
<pre><code>first = True
for member in something.get():
if first:
root.copy(member)
first = False
... | 33 | 2009-12-18T11:03:26Z | 1,927,706 | <p>Here, I could come with a Pythonic idiom that can look "pertty". Although, most likely I'd use the form you suggested in asking the question, just for the code to remain more obvious, though less elegant.</p>
<pre><code>def copy_iter():
yield root.copy
while True:
yield somewhereElse.copy
for membe... | 3 | 2009-12-18T11:36:01Z | [
"python",
"algorithm",
"iteration"
] |
"For" loop first iteration | 1,927,544 | <p>Greetings pyc-sires and py-ladies,
I would like to inquire if there is an elegant pythonic way of executing some function on the first loop iteration.
The only possibility I can think of is:</p>
<pre><code>first = True
for member in something.get():
if first:
root.copy(member)
first = False
... | 33 | 2009-12-18T11:03:26Z | 1,927,800 | <p>I think this is quite elegant, but maybe too convoluted for what it does...</p>
<pre><code>from itertools import chain, repeat, izip
for place, member in izip(chain([root], repeat(somewhereElse)), something.get()):
place.copy(member)
foo(member)
</code></pre>
| 5 | 2009-12-18T11:55:47Z | [
"python",
"algorithm",
"iteration"
] |
"For" loop first iteration | 1,927,544 | <p>Greetings pyc-sires and py-ladies,
I would like to inquire if there is an elegant pythonic way of executing some function on the first loop iteration.
The only possibility I can think of is:</p>
<pre><code>first = True
for member in something.get():
if first:
root.copy(member)
first = False
... | 33 | 2009-12-18T11:03:26Z | 1,927,984 | <p>How about using <code>iter</code>, and consuming the first element?</p>
<p><strong>Edit:</strong> Going back on the OP's question, there is a common operation that you want to perform on all elements, and then one operation you want to perform on the first element, and another on the rest.</p>
<p>If it's just a si... | 3 | 2009-12-18T12:37:32Z | [
"python",
"algorithm",
"iteration"
] |
"For" loop first iteration | 1,927,544 | <p>Greetings pyc-sires and py-ladies,
I would like to inquire if there is an elegant pythonic way of executing some function on the first loop iteration.
The only possibility I can think of is:</p>
<pre><code>first = True
for member in something.get():
if first:
root.copy(member)
first = False
... | 33 | 2009-12-18T11:03:26Z | 1,928,039 | <p>I don't know Python, but I use almost the exact pattern of your example.<br>
What I do also is making the <code>if</code> condition the most frequent, so usually check for <code>if( first == false )</code><br>
Why? for long loops, first will be true only one time and will be false all the other times, meaning that i... | 1 | 2009-12-18T12:50:47Z | [
"python",
"algorithm",
"iteration"
] |
"For" loop first iteration | 1,927,544 | <p>Greetings pyc-sires and py-ladies,
I would like to inquire if there is an elegant pythonic way of executing some function on the first loop iteration.
The only possibility I can think of is:</p>
<pre><code>first = True
for member in something.get():
if first:
root.copy(member)
first = False
... | 33 | 2009-12-18T11:03:26Z | 1,928,477 | <p>I think the first S.Lott solution is the best, but there's another choice if you're using a pretty recent python (>= 2.6 I think, since izip_longest doesn't seem available before that version) that lets doing different things for the first element and successive one, and can be easily modified to do distinct operati... | 2 | 2009-12-18T14:23:19Z | [
"python",
"algorithm",
"iteration"
] |
"For" loop first iteration | 1,927,544 | <p>Greetings pyc-sires and py-ladies,
I would like to inquire if there is an elegant pythonic way of executing some function on the first loop iteration.
The only possibility I can think of is:</p>
<pre><code>first = True
for member in something.get():
if first:
root.copy(member)
first = False
... | 33 | 2009-12-18T11:03:26Z | 1,935,799 | <p>how about:</p>
<pre><code>my_array = something.get()
for member in my_array:
if my_array.index(member) == 0:
root.copy(member)
else:
somewhereElse.copy(member)
foo(member)
</code></pre>
<p>or maybe:</p>
<pre><code>for index, member in enumerate(something.get()):
if index == 0:
... | 7 | 2009-12-20T13:06:22Z | [
"python",
"algorithm",
"iteration"
] |
Compare two images the python/linux way | 1,927,660 | <p>Trying to solve a problem of preventing duplicate images to be uploaded.</p>
<p>I have two JPGs. Looking at them I can see that they are in fact identical. But for some reason they have different file size (one is pulled from a backup, the other is another upload) and so they have a different md5 checksum. </p>
<p... | 31 | 2009-12-18T11:27:38Z | 1,927,681 | <p>There is a OSS project that uses WebDriver to take screen shots and then compares the images to see if there are any issues (<a href="http://code.google.com/p/fighting-layout-bugs/">http://code.google.com/p/fighting-layout-bugs/)</a>). It does it by openning the file into a stream and then comparing every bit. </p>
... | 22 | 2009-12-18T11:32:36Z | [
"python",
"linux",
"image"
] |
Compare two images the python/linux way | 1,927,660 | <p>Trying to solve a problem of preventing duplicate images to be uploaded.</p>
<p>I have two JPGs. Looking at them I can see that they are in fact identical. But for some reason they have different file size (one is pulled from a backup, the other is another upload) and so they have a different md5 checksum. </p>
<p... | 31 | 2009-12-18T11:27:38Z | 1,927,689 | <p>I guess you should decode the images and do a pixel by pixel comparison to see if they're reasonably similar.</p>
<p>With PIL and Numpy you can do it quite easily:</p>
<pre><code>import Image
import numpy
import sys
def main():
img1 = Image.open(sys.argv[1])
img2 = Image.open(sys.argv[2])
if img1.siz... | 11 | 2009-12-18T11:34:01Z | [
"python",
"linux",
"image"
] |
Compare two images the python/linux way | 1,927,660 | <p>Trying to solve a problem of preventing duplicate images to be uploaded.</p>
<p>I have two JPGs. Looking at them I can see that they are in fact identical. But for some reason they have different file size (one is pulled from a backup, the other is another upload) and so they have a different md5 checksum. </p>
<p... | 31 | 2009-12-18T11:27:38Z | 1,927,720 | <p>You can either compare it using <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a> (iterate through pixels / segments of the picture and compare) or if you're looking for a complete identical copy comparison, try comparing the MD5 hash of both files.</p>
| 1 | 2009-12-18T11:39:21Z | [
"python",
"linux",
"image"
] |
Compare two images the python/linux way | 1,927,660 | <p>Trying to solve a problem of preventing duplicate images to be uploaded.</p>
<p>I have two JPGs. Looking at them I can see that they are in fact identical. But for some reason they have different file size (one is pulled from a backup, the other is another upload) and so they have a different md5 checksum. </p>
<p... | 31 | 2009-12-18T11:27:38Z | 1,927,991 | <p>First, I should note theyâre <strong>not</strong> identical; b has been recompressed and lost quality. You can see this if you look carefully on a good monitor.</p>
<p>To determine that they are subjectively âthe same,â you would have to do something like what fortran suggested, although you will have to arbi... | 2 | 2009-12-18T12:39:39Z | [
"python",
"linux",
"image"
] |
Compare two images the python/linux way | 1,927,660 | <p>Trying to solve a problem of preventing duplicate images to be uploaded.</p>
<p>I have two JPGs. Looking at them I can see that they are in fact identical. But for some reason they have different file size (one is pulled from a backup, the other is another upload) and so they have a different md5 checksum. </p>
<p... | 31 | 2009-12-18T11:27:38Z | 1,928,417 | <p>the problem of knowing what makes some features of the image more important than other is a whole scientific program. I would suggest some alternatives depending on the solution you want:</p>
<ul>
<li><p>if your problem is to see if there is a flipping of bits in your JPEGs, then try to image the difference image (... | 4 | 2009-12-18T14:12:21Z | [
"python",
"linux",
"image"
] |
Compare two images the python/linux way | 1,927,660 | <p>Trying to solve a problem of preventing duplicate images to be uploaded.</p>
<p>I have two JPGs. Looking at them I can see that they are in fact identical. But for some reason they have different file size (one is pulled from a backup, the other is another upload) and so they have a different md5 checksum. </p>
<p... | 31 | 2009-12-18T11:27:38Z | 6,204,954 | <p>From <a href="http://effbot.org/zone/pil-comparing-images.htm">here</a></p>
<p>The quickest way to determine if two images have exactly the same contents is to get the difference between the two images, and then calculate the bounding box of the non-zero regions in this image. If the images are identical, all pixel... | 14 | 2011-06-01T17:01:50Z | [
"python",
"linux",
"image"
] |
Compare two images the python/linux way | 1,927,660 | <p>Trying to solve a problem of preventing duplicate images to be uploaded.</p>
<p>I have two JPGs. Looking at them I can see that they are in fact identical. But for some reason they have different file size (one is pulled from a backup, the other is another upload) and so they have a different md5 checksum. </p>
<p... | 31 | 2009-12-18T11:27:38Z | 9,698,890 | <p>Using ImageMagick, you can simply use in your shell [or call via the OS library from within a program]</p>
<pre><code>compare image1 image2 output
</code></pre>
<p>This will create an output image with the differences marked</p>
<pre><code>compare -metric AE -fuzz 5% image1 image2 output
</code></pre>
<p>Will gi... | 10 | 2012-03-14T09:16:09Z | [
"python",
"linux",
"image"
] |
Compare two images the python/linux way | 1,927,660 | <p>Trying to solve a problem of preventing duplicate images to be uploaded.</p>
<p>I have two JPGs. Looking at them I can see that they are in fact identical. But for some reason they have different file size (one is pulled from a backup, the other is another upload) and so they have a different md5 checksum. </p>
<p... | 31 | 2009-12-18T11:27:38Z | 35,807,550 | <p>I tested this one and it works the best of all methods and extremly fast!</p>
<pre><code>def rmsdiff_1997(im1, im2):
"Calculate the root-mean-square difference between two images"
h = ImageChops.difference(im1, im2).histogram()
# calculate rms
return math.sqrt(reduce(operator.add,
map(lamb... | 1 | 2016-03-04T22:54:43Z | [
"python",
"linux",
"image"
] |
In python (django) how can I stop access to a global dictionary data structure when it's being updated? | 1,927,887 | <p>In django when updating a global dictionary data structure I want to lock access to it by different request. I am planning to have a wrapper function to update and access and synchronize it. Coming from Java background! Any pointers? </p>
| 1 | 2009-12-18T12:14:54Z | 1,928,134 | <p>One fun option is to create a Lockable DIctionary class that will lock itself based on teh exection frame of the caller. :-)</p>
<p>Python introspection allows this - and depending on you r needs, this might fit -
(you would have to catch the exception raised in the places you want to use the valu, though --
I ... | 1 | 2009-12-18T13:13:59Z | [
"python",
"django"
] |
In python (django) how can I stop access to a global dictionary data structure when it's being updated? | 1,927,887 | <p>In django when updating a global dictionary data structure I want to lock access to it by different request. I am planning to have a wrapper function to update and access and synchronize it. Coming from Java background! Any pointers? </p>
| 1 | 2009-12-18T12:14:54Z | 1,930,869 | <p>Extending the LockableDict example somewhat, to make it a little more robust you can use the real Lock:</p>
<pre><code>class LockableDict(dict):
def __init__(self, *args, **kwargs):
from threading import Lock
self.lock = Lock()
dict.__init__(self, *args, **kwargs)
@property
def ... | 1 | 2009-12-18T21:48:07Z | [
"python",
"django"
] |
django + mysql + UTF-8 - Chars are not displayed | 1,928,087 | <p>I have both, django and mysql set to work with UTF-8.
My base.html set utf-8 in head.</p>
<p>row on my db :</p>
<pre>
+----+--------+------------------------------------------------------------------+-----------------------------+-----------------------------+---------------------+
| id | psn_id | name ... | 0 | 2009-12-18T13:04:13Z | 1,928,165 | <p>That source code, when placed into an otherwise empty HTML document, looks like this for me in Google Chrome, IE and Firefox:</p>
<blockquote>
<p>ã¾ãã«ã¡ãã£ãã</p>
</blockquote>
<p>Which appears to be what you want.</p>
<p>My only thought is that that is not really the source code, and you've in fact... | 3 | 2009-12-18T13:21:23Z | [
"python",
"django",
"unicode"
] |
django + mysql + UTF-8 - Chars are not displayed | 1,928,087 | <p>I have both, django and mysql set to work with UTF-8.
My base.html set utf-8 in head.</p>
<p>row on my db :</p>
<pre>
+----+--------+------------------------------------------------------------------+-----------------------------+-----------------------------+---------------------+
| id | psn_id | name ... | 0 | 2009-12-18T13:04:13Z | 1,931,067 | <p>As Dominic has said, the generated HTML source code is correct (these are your Japanese characters translated into HTML entities), but we're not sure, if you see the same code rendered in the page (in this case, you have probably set <code>content-type</code> to "<code>text/plain</code>" instead of "<code>text/html<... | 0 | 2009-12-18T22:30:47Z | [
"python",
"django",
"unicode"
] |
django + mysql + UTF-8 - Chars are not displayed | 1,928,087 | <p>I have both, django and mysql set to work with UTF-8.
My base.html set utf-8 in head.</p>
<p>row on my db :</p>
<pre>
+----+--------+------------------------------------------------------------------+-----------------------------+-----------------------------+---------------------+
| id | psn_id | name ... | 0 | 2009-12-18T13:04:13Z | 1,939,157 | <p>the problem is the auto escape django function ...
my source code is like the one that Dominic pasted :</p>
<pre>
&#12414;&#12356;&#12395;&#12385;&#12356;&#12387;&#12375;&#12423;
</pre>
<p>i simple put the tag in places there i known that may be some diff chars:</p>
<pre>
{% autoes... | 0 | 2009-12-21T09:43:23Z | [
"python",
"django",
"unicode"
] |
fb:promt-permission gives me a link, I need a direct popup | 1,928,098 | <p>I'm using Django/Python , I need to ask the user for permission to let me put feeds ( ideally oneliners which was not working so I thought to use full streams) into the user profile. </p>
<p>Would you like to receive email from our application?</p>
<p>This is giving me a hyper link which I click and it shows me th... | 0 | 2009-12-18T13:06:28Z | 1,935,117 | <p>use the javascript <a href="http://developers.facebook.com/docs/?u=facebook.jslib.FB.Connect.showPermissionDialog" rel="nofollow">FB.Connect.showPermissionDialog</a> method.</p>
<p>it takes an optional callback function to which it passes whether the permission was allowed or not, so you could call FB.Connect.strea... | 1 | 2009-12-20T07:27:50Z | [
"python",
"django",
"facebook"
] |
calling an outside function in python | 1,928,718 | <p>I am trying to return (execute) a function from another file in an if statement.
I have read that the return statement will not work, I was hoping someone would know what statement would allow me to call an outside function.</p>
<p>The function creates a sandbox but if one exists I want to pass the if statement.</p... | 0 | 2009-12-18T15:02:48Z | 1,928,731 | <p>You probably need to <code>import</code> the module which contains the function, no?</p>
<p>Of course, a little more precision as to what you are trying to achieve would help.</p>
| 1 | 2009-12-18T15:05:22Z | [
"python",
"return"
] |
calling an outside function in python | 1,928,718 | <p>I am trying to return (execute) a function from another file in an if statement.
I have read that the return statement will not work, I was hoping someone would know what statement would allow me to call an outside function.</p>
<p>The function creates a sandbox but if one exists I want to pass the if statement.</p... | 0 | 2009-12-18T15:02:48Z | 1,928,735 | <p>Say your function <code>bar</code> is in a file called foo.py on your Python path.</p>
<p>If foo.py contains this:</p>
<pre><code>def bar():
return True
</code></pre>
<p>Then you can do this:</p>
<pre><code>from foo import bar
if bar():
print "bar() is True!"
</code></pre>
| 4 | 2009-12-18T15:06:17Z | [
"python",
"return"
] |
calling an outside function in python | 1,928,718 | <p>I am trying to return (execute) a function from another file in an if statement.
I have read that the return statement will not work, I was hoping someone would know what statement would allow me to call an outside function.</p>
<p>The function creates a sandbox but if one exists I want to pass the if statement.</p... | 0 | 2009-12-18T15:02:48Z | 1,928,738 | <p>What exactly do you mean by "the return statement will not work"?</p>
<p>You can <code>import</code> the function from the other file and call it like a local function.</p>
| 1 | 2009-12-18T15:06:31Z | [
"python",
"return"
] |
calling an outside function in python | 1,928,718 | <p>I am trying to return (execute) a function from another file in an if statement.
I have read that the return statement will not work, I was hoping someone would know what statement would allow me to call an outside function.</p>
<p>The function creates a sandbox but if one exists I want to pass the if statement.</p... | 0 | 2009-12-18T15:02:48Z | 1,928,739 | <p>It depends what you mean. If you want to create a static method then you would do something like</p>
<pre><code>class fubar(object):
@classmethod
def foo():
return bar
fubar.foo() # returns bar
</code></pre>
<p>If you want to run an external process then you would use <a href="http://docs.python.or... | 0 | 2009-12-18T15:06:51Z | [
"python",
"return"
] |
calling an outside function in python | 1,928,718 | <p>I am trying to return (execute) a function from another file in an if statement.
I have read that the return statement will not work, I was hoping someone would know what statement would allow me to call an outside function.</p>
<p>The function creates a sandbox but if one exists I want to pass the if statement.</p... | 0 | 2009-12-18T15:02:48Z | 1,928,743 | <p>Do you mean <code>import</code>? Say, your external function lives in mymodule.py in the same directory, you have to import it first:</p>
<pre><code>import mymodule
# or
from mymodule import myfunction
</code></pre>
<p>Then it is straight forward to use the function:</p>
<pre><code>if mymodule.myfunction() == "ab... | 0 | 2009-12-18T15:07:51Z | [
"python",
"return"
] |
calling an outside function in python | 1,928,718 | <p>I am trying to return (execute) a function from another file in an if statement.
I have read that the return statement will not work, I was hoping someone would know what statement would allow me to call an outside function.</p>
<p>The function creates a sandbox but if one exists I want to pass the if statement.</p... | 0 | 2009-12-18T15:02:48Z | 1,928,762 | <p>file1.py (comment out 2 of the versions)</p>
<pre><code>#version 1
from file2 import outsidefunction
print (outsidefunction(3))
#version 2
import file2
print (file2.outsidefunction(3))
#version 3
from file2 import *
print (outsidefunction(3))
</code></pre>
<p>file2.py</p>
<pre><code>def outsidefunction(num):
... | -1 | 2009-12-18T15:11:14Z | [
"python",
"return"
] |
calling an outside function in python | 1,928,718 | <p>I am trying to return (execute) a function from another file in an if statement.
I have read that the return statement will not work, I was hoping someone would know what statement would allow me to call an outside function.</p>
<p>The function creates a sandbox but if one exists I want to pass the if statement.</p... | 0 | 2009-12-18T15:02:48Z | 1,928,836 | <p>let's see <a href="http://docs.python.org/reference/simple%5Fstmts.html#the-return-statement" rel="nofollow">what docs say</a>:</p>
<blockquote>
<p><code>return</code> may only occur syntactically nested in a function definition, not within a nested class definition.</p>
</blockquote>
<p>what you're trying to do... | 2 | 2009-12-18T15:22:28Z | [
"python",
"return"
] |
calling an outside function in python | 1,928,718 | <p>I am trying to return (execute) a function from another file in an if statement.
I have read that the return statement will not work, I was hoping someone would know what statement would allow me to call an outside function.</p>
<p>The function creates a sandbox but if one exists I want to pass the if statement.</p... | 0 | 2009-12-18T15:02:48Z | 1,942,318 | <p>I have a big touch on this recently as I was working on my final project in python. I would be engaged to look at your outside function file too.</p>
<p>If you are calling a module (well actually, any function outside the same file can be treated as a module, I hate to specify things too precise), you need to make ... | 1 | 2009-12-21T20:09:25Z | [
"python",
"return"
] |
Calling a method on class A depending on type of parameter | 1,928,806 | <pre><code>class Class1(object):
...
class Class2(object):
...
class Class3(object):
...
class A(object):
def _methA(parm1, parm2)
...
def _methB(parm1, parm2)
...
def _methC(parm1, parm2)
...
def manager(parm1, method, params)
...
if parm1.__cla... | 4 | 2009-12-18T15:17:10Z | 1,928,852 | <p>I would prefer </p>
<pre><code>if isinstance(parm1, Class1):
_methA(parm1, params)
elif isinstance(parm1, Class2):
_methB(parm1, params)
elif isinstance(parm1, Class3):
_methC(parm1, params)
</code></pre>
<p>but this still smells of a design flaw. :)</p>
<p>Maybe your three classes <code>ClassX</code>... | 0 | 2009-12-18T15:24:52Z | [
"python",
"design",
"oop"
] |
Calling a method on class A depending on type of parameter | 1,928,806 | <pre><code>class Class1(object):
...
class Class2(object):
...
class Class3(object):
...
class A(object):
def _methA(parm1, parm2)
...
def _methB(parm1, parm2)
...
def _methC(parm1, parm2)
...
def manager(parm1, method, params)
...
if parm1.__cla... | 4 | 2009-12-18T15:17:10Z | 1,928,856 | <p>You're trying to emulate what language geeks call "<a href="http://en.wikipedia.org/wiki/Multiple%5Fdispatch" rel="nofollow">multiple dispatch</a>", or "multimethods". The linked-to Wikipedia article has a good discussion, including Python examples.</p>
| 1 | 2009-12-18T15:25:23Z | [
"python",
"design",
"oop"
] |
Calling a method on class A depending on type of parameter | 1,928,806 | <pre><code>class Class1(object):
...
class Class2(object):
...
class Class3(object):
...
class A(object):
def _methA(parm1, parm2)
...
def _methB(parm1, parm2)
...
def _methC(parm1, parm2)
...
def manager(parm1, method, params)
...
if parm1.__cla... | 4 | 2009-12-18T15:17:10Z | 1,928,867 | <p>That's one of many wrong ways to implement polymorphism. You should never look at class names. Looking at class names should bother you because it means that you haven't delegated the responsibility correctly.</p>
<p>Move each method into the appropriate class.</p>
<pre><code>class Class1(object):
def method... | 5 | 2009-12-18T15:28:00Z | [
"python",
"design",
"oop"
] |
Calling a method on class A depending on type of parameter | 1,928,806 | <pre><code>class Class1(object):
...
class Class2(object):
...
class Class3(object):
...
class A(object):
def _methA(parm1, parm2)
...
def _methB(parm1, parm2)
...
def _methC(parm1, parm2)
...
def manager(parm1, method, params)
...
if parm1.__cla... | 4 | 2009-12-18T15:17:10Z | 1,928,951 | <p>I usually do this when processing messages, so i don't have tons of ifs ... but it still uses the class names. </p>
<p>Kind of a poor man's polymorphism - but, as S.Lott said, Python supports real polymorphism so why not use it :p</p>
<pre><code>class Handler(object):
# .. stuff
def dispatch(self, msg):
... | 0 | 2009-12-18T15:44:03Z | [
"python",
"design",
"oop"
] |
Robocopy error code 6 ''The handle is invalid' | 1,928,855 | <p>I have written a python script that uses subprocess to call robocopy to sync log files from a remote host. </p>
<p>Like so:</p>
<pre><code>program = 'Robocopy'
options = ['/S']
args.append(program)
args.append(options)
args.append('\\\\%s\%s' % (hostname, source_path))
args.append(local_path)
proc = subprocess.Pop... | 2 | 2009-12-18T15:25:20Z | 1,930,751 | <p>Google searches for <a href="http://www.google.com/search?q=robocopy+handle+is+invalid" rel="nofollow">"robocopy handle is invalid"</a> suggest you might find success by using the /b option for "backup mode".</p>
<p>Even if that doesn't work, I'd suggest adding code to output the filenames as they are being copied ... | 1 | 2009-12-18T21:21:15Z | [
"python",
"subprocess",
"robocopy"
] |
cross platform usb module for python? | 1,928,936 | <p>I was interested in doing some cross platform work with a usb device in python, any tips or recommendations on modules that can do this type of thing?</p>
<p>I've looked around SF and googlecode without a lot of luck.</p>
<p>thanks!</p>
<p>ct</p>
| 5 | 2009-12-18T15:41:27Z | 1,928,956 | <p><a href="http://pyusb.berlios.de/">PyUSB</a> is what you are looking for. it is a wrapper around libusb which works on linux and was ported on Windows. </p>
| 5 | 2009-12-18T15:44:59Z | [
"python",
"usb"
] |
Python GUI (glade) to display output of shell process | 1,929,018 | <p>I'm writing a python application that runs several subprocesses using subprocess.Popen objects.
I have a glade GUI and want to display the output of these commands (running in subprocess.Popen) in the gui in real time.</p>
<p>Can anyone suggest a way to do this? What glade object do I need to use and how to redirec... | 2 | 2009-12-18T15:55:10Z | 1,929,138 | <p>glade is only a program to build gui with gtk so when you ask for a <em>glade object</em> maybe you should ask for <em>gtk widget</em> and in this case textbuffer and textview chould be a solution or maybe treeview and liststore.
<code>subprocess.Popen</code> has <code>stdout</code> and <code>stderr</code> arguments... | 1 | 2009-12-18T16:12:15Z | [
"python",
"user-interface",
"glade"
] |
Python GUI (glade) to display output of shell process | 1,929,018 | <p>I'm writing a python application that runs several subprocesses using subprocess.Popen objects.
I have a glade GUI and want to display the output of these commands (running in subprocess.Popen) in the gui in real time.</p>
<p>Can anyone suggest a way to do this? What glade object do I need to use and how to redirec... | 2 | 2009-12-18T15:55:10Z | 1,941,028 | <p>After lots of reading and not getting the results I wanted, I found another method that works.</p>
<p>It goes like this</p>
<pre><code>#!/usr/bine/env python
import subprocess
import gtk
### Of course, you should have the gui built and know which widgets to use for this.
viewer = self.builder.get_widget('txtview'... | 1 | 2009-12-21T16:17:48Z | [
"python",
"user-interface",
"glade"
] |
Python GUI (glade) to display output of shell process | 1,929,018 | <p>I'm writing a python application that runs several subprocesses using subprocess.Popen objects.
I have a glade GUI and want to display the output of these commands (running in subprocess.Popen) in the gui in real time.</p>
<p>Can anyone suggest a way to do this? What glade object do I need to use and how to redirec... | 2 | 2009-12-18T15:55:10Z | 1,942,579 | <p>Here is a link that also displays another way of doing this.</p>
<p>I found this to be very insightful, maybe someone else can use these tips.</p>
<p><a href="http://pygabriel.wordpress.com/2009/07/27/redirecting-the-stdout-on-a-gtk-textview/" rel="nofollow">http://pygabriel.wordpress.com/2009/07/27/redirecting-th... | 2 | 2009-12-21T20:56:58Z | [
"python",
"user-interface",
"glade"
] |
Implementing tridiagonal matrix algorithm (TDMA) with NumPy | 1,929,045 | <p>I'm implementing TDMA in Python using NumPy. The tridiagonal matrix is stored in three arrays:</p>
<pre><code>a = array([...])
b = array([...])
c = array([...])
</code></pre>
<p>I'd like to calculate <code>alpha</code>-coefficients efficiently. The algorithm is as follows:</p>
<pre><code># n = size of the given m... | 4 | 2009-12-18T15:59:41Z | 1,931,047 | <p>If its tridiagonal systems you want to solve there is <code>solve_banded()</code> in <code>numpy.linalg</code>. Not sure if that's what you're looking for.</p>
| 2 | 2009-12-18T22:28:14Z | [
"python",
"numpy",
"numerical-methods"
] |
Implementing tridiagonal matrix algorithm (TDMA) with NumPy | 1,929,045 | <p>I'm implementing TDMA in Python using NumPy. The tridiagonal matrix is stored in three arrays:</p>
<pre><code>a = array([...])
b = array([...])
c = array([...])
</code></pre>
<p>I'd like to calculate <code>alpha</code>-coefficients efficiently. The algorithm is as follows:</p>
<pre><code># n = size of the given m... | 4 | 2009-12-18T15:59:41Z | 2,038,604 | <p>Apparently, there is no way to do this in Python without using C or its <em>pythonic</em> variations.</p>
| 2 | 2010-01-10T21:03:19Z | [
"python",
"numpy",
"numerical-methods"
] |
Nested dot lookups in Django templates | 1,929,109 | <p>According to <a href="http://www.djangobook.com/en/beta/chapter04/">The Django Book</a>, Django's templating system supports nested dot lookups:</p>
<blockquote>
<p>Dot lookups can be nested multiple levels deep. For instance, the following example uses {{ person.name.upper }}, which translates into a dictionary ... | 5 | 2009-12-18T16:07:35Z | 1,929,161 | <p>I think the problem is that you are expecting <code>ndx</code> to be evaluated when that simply never happens. Have you tried this:</p>
<pre><code>{{ test.0.bar }}
</code></pre>
<p>I think that will do what you're looking for.</p>
<blockquote>
<p>Are there goblins with this approach...?</p>
</blockquote>
<p>S... | 8 | 2009-12-18T16:14:25Z | [
"python",
"django",
"django-templates"
] |
Nested dot lookups in Django templates | 1,929,109 | <p>According to <a href="http://www.djangobook.com/en/beta/chapter04/">The Django Book</a>, Django's templating system supports nested dot lookups:</p>
<blockquote>
<p>Dot lookups can be nested multiple levels deep. For instance, the following example uses {{ person.name.upper }}, which translates into a dictionary ... | 5 | 2009-12-18T16:07:35Z | 1,929,241 | <p>David is right: <code>ndx</code> won't be evaluated to get a key, it will be used literally as a key. You can define a new template tag to do what you want, here's a simple one: <a href="http://www.djangosnippets.org/snippets/1412/" rel="nofollow">http://www.djangosnippets.org/snippets/1412/</a></p>
| 1 | 2009-12-18T16:22:14Z | [
"python",
"django",
"django-templates"
] |
Nested dot lookups in Django templates | 1,929,109 | <p>According to <a href="http://www.djangobook.com/en/beta/chapter04/">The Django Book</a>, Django's templating system supports nested dot lookups:</p>
<blockquote>
<p>Dot lookups can be nested multiple levels deep. For instance, the following example uses {{ person.name.upper }}, which translates into a dictionary ... | 5 | 2009-12-18T16:07:35Z | 1,929,255 | <p>To expand on David's answer, Django's template system doesn't allow you to use the value of a context variable as a key. So, in your example</p>
<pre><code>{{ test.0.ndx }}
</code></pre>
<p>is actually looking for the key <code>"ndx"</code> in the first item in the <code>test</code> context variable.</p>
<p>If y... | 4 | 2009-12-18T16:23:52Z | [
"python",
"django",
"django-templates"
] |
Nested dot lookups in Django templates | 1,929,109 | <p>According to <a href="http://www.djangobook.com/en/beta/chapter04/">The Django Book</a>, Django's templating system supports nested dot lookups:</p>
<blockquote>
<p>Dot lookups can be nested multiple levels deep. For instance, the following example uses {{ person.name.upper }}, which translates into a dictionary ... | 5 | 2009-12-18T16:07:35Z | 1,929,258 | <p>I'd suggest either (and I agree with David's interpretation of your problem):</p>
<pre><code>{{ test.0.bar }} # as david mentioned, or
ndx=test[0]['bar'] # in views
{{ ndx }} # in template
</code></pre>
| 1 | 2009-12-18T16:24:04Z | [
"python",
"django",
"django-templates"
] |
python-config ldflags on mac | 1,929,180 | <p>I have a problem with <code>python-config --ldflags</code> on OS X 10.6.2.</p>
<p>Using my non-system python.org python install:</p>
<pre><code>robin-mbp:~ robince$ which python
/Library/Frameworks/Python.framework/Versions/2.5/bin/python
robin-mbp:~ robince$ python-config --ldflags
-L/Library/Frameworks/Python.fr... | 2 | 2009-12-18T16:15:48Z | 1,929,321 | <p>Sorry to answer my own question but I got an amazingly prompt reply on the pythonmac-sig mailing list where I also asked. It is a bug with current python: <a href="http://bugs.python.org/issue7541" rel="nofollow">http://bugs.python.org/issue7541</a></p>
<p>Suggested workaround:</p>
<blockquote>
<p>The easiest wo... | 2 | 2009-12-18T16:33:55Z | [
"python",
"osx",
"linker",
"ld"
] |
In Python, use "dict" with keywords or anonymous dictionaries? | 1,929,274 | <p>Say you want to pass a dictionary of values to a function, or otherwise want to work with a short-lived dictionary that won't be reused. There are two easy ways to do this:</p>
<p>Use the <code>dict()</code> function to create a dictionary:</p>
<pre><code>foo.update(dict(bar=42, baz='qux'))
</code></pre>
<p>Use a... | 5 | 2009-12-18T16:26:56Z | 1,929,280 | <p>I prefer your "anonymous dictionary" method and I think this is purely a personal style thing. I just find the latter version more readable but it's also what I'm used to seeing. </p>
| 2 | 2009-12-18T16:28:24Z | [
"python"
] |
In Python, use "dict" with keywords or anonymous dictionaries? | 1,929,274 | <p>Say you want to pass a dictionary of values to a function, or otherwise want to work with a short-lived dictionary that won't be reused. There are two easy ways to do this:</p>
<p>Use the <code>dict()</code> function to create a dictionary:</p>
<pre><code>foo.update(dict(bar=42, baz='qux'))
</code></pre>
<p>Use a... | 5 | 2009-12-18T16:26:56Z | 1,929,292 | <p>I prefer the anonymous dictionary, too, just out of personal style.</p>
| 1 | 2009-12-18T16:29:50Z | [
"python"
] |
In Python, use "dict" with keywords or anonymous dictionaries? | 1,929,274 | <p>Say you want to pass a dictionary of values to a function, or otherwise want to work with a short-lived dictionary that won't be reused. There are two easy ways to do this:</p>
<p>Use the <code>dict()</code> function to create a dictionary:</p>
<pre><code>foo.update(dict(bar=42, baz='qux'))
</code></pre>
<p>Use a... | 5 | 2009-12-18T16:26:56Z | 1,929,304 | <p>I prefer the anonymous dict option.</p>
<p>I don't like the <code>dict()</code> option for the same reason I don't like:</p>
<pre><code> i = int("1")
</code></pre>
<p>With the <code>dict()</code> option you're needlessly calling a function which is adding overhead you don't need:</p>
<pre><code>>>> from... | 13 | 2009-12-18T16:32:09Z | [
"python"
] |
In Python, use "dict" with keywords or anonymous dictionaries? | 1,929,274 | <p>Say you want to pass a dictionary of values to a function, or otherwise want to work with a short-lived dictionary that won't be reused. There are two easy ways to do this:</p>
<p>Use the <code>dict()</code> function to create a dictionary:</p>
<pre><code>foo.update(dict(bar=42, baz='qux'))
</code></pre>
<p>Use a... | 5 | 2009-12-18T16:26:56Z | 1,929,333 | <p>If I have a lot of arguments, sometimes it is nice to omit the quotes on the keys:</p>
<pre><code>DoSomething(dict(
Name = 'Joe',
Age = 20,
Gender = 'Male',
))
</code></pre>
<p>This is a very subjective question, BTW. :)</p>
| 1 | 2009-12-18T16:36:51Z | [
"python"
] |
In Python, use "dict" with keywords or anonymous dictionaries? | 1,929,274 | <p>Say you want to pass a dictionary of values to a function, or otherwise want to work with a short-lived dictionary that won't be reused. There are two easy ways to do this:</p>
<p>Use the <code>dict()</code> function to create a dictionary:</p>
<pre><code>foo.update(dict(bar=42, baz='qux'))
</code></pre>
<p>Use a... | 5 | 2009-12-18T16:26:56Z | 1,929,350 | <p>I think the <code>dict()</code> function is really there for when you're creating a dict from something else, maybe something that easily produces the necessary keyword args. The anonymous method is best for 'dict literals' in the same way you'd use "" for strings, not str().</p>
| 1 | 2009-12-18T16:40:21Z | [
"python"
] |
In Python, use "dict" with keywords or anonymous dictionaries? | 1,929,274 | <p>Say you want to pass a dictionary of values to a function, or otherwise want to work with a short-lived dictionary that won't be reused. There are two easy ways to do this:</p>
<p>Use the <code>dict()</code> function to create a dictionary:</p>
<pre><code>foo.update(dict(bar=42, baz='qux'))
</code></pre>
<p>Use a... | 5 | 2009-12-18T16:26:56Z | 1,929,440 | <p>I think in this specific case I'd probably prefer this:</p>
<pre><code>foo.update(bar=42, baz='qux')
</code></pre>
<p>In the more general case, I often prefer the literal syntax (what you call an anonymous dictionary, though it's just as anonymous to use <code>{}</code> as it is to use <code>dict()</code>). I thi... | 6 | 2009-12-18T16:50:49Z | [
"python"
] |
In Python, use "dict" with keywords or anonymous dictionaries? | 1,929,274 | <p>Say you want to pass a dictionary of values to a function, or otherwise want to work with a short-lived dictionary that won't be reused. There are two easy ways to do this:</p>
<p>Use the <code>dict()</code> function to create a dictionary:</p>
<pre><code>foo.update(dict(bar=42, baz='qux'))
</code></pre>
<p>Use a... | 5 | 2009-12-18T16:26:56Z | 1,929,451 | <p>The dict() method has the added overhead of a function call.</p>
<pre><code>>>>import timeit,dis
>>> timeit.Timer("{'bar': 42, 'baz': 'qux'}").repeat()
[0.59602910425766709, 0.60173793037941437, 0.59139834811408321]
>>> timeit.Timer("dict(bar=42, baz='qux')").repeat()
[0.98166498814792646... | 2 | 2009-12-18T16:53:09Z | [
"python"
] |
In Python, use "dict" with keywords or anonymous dictionaries? | 1,929,274 | <p>Say you want to pass a dictionary of values to a function, or otherwise want to work with a short-lived dictionary that won't be reused. There are two easy ways to do this:</p>
<p>Use the <code>dict()</code> function to create a dictionary:</p>
<pre><code>foo.update(dict(bar=42, baz='qux'))
</code></pre>
<p>Use a... | 5 | 2009-12-18T16:26:56Z | 1,930,122 | <p>Actually, if the receiving function will only receive a dictionary with not pre-dertermined keywords, I normally use the ** passing convention.</p>
<p>In this example, that would be:</p>
<pre><code>class Foo(object):
def update(self, **param_dict):
for key in param_dict:
....
foo = Foo()
....
f... | 0 | 2009-12-18T19:07:51Z | [
"python"
] |
In Python, use "dict" with keywords or anonymous dictionaries? | 1,929,274 | <p>Say you want to pass a dictionary of values to a function, or otherwise want to work with a short-lived dictionary that won't be reused. There are two easy ways to do this:</p>
<p>Use the <code>dict()</code> function to create a dictionary:</p>
<pre><code>foo.update(dict(bar=42, baz='qux'))
</code></pre>
<p>Use a... | 5 | 2009-12-18T16:26:56Z | 1,980,262 | <p>My answer will largely talk about the design of APIs to use dicts vs. keyword args.
But it's also applicable the individual use of <code>{...}</code> vs. <code>dict(...)</code>.</p>
<p>The bottom line: be consistent. If most of your code will refer to <code>'bar'</code> as a string - keep it a string in <code>{...... | 3 | 2009-12-30T13:41:49Z | [
"python"
] |
Searching for text in a file | 1,929,432 | <p>hi there got a couple of probs, say in my text file i have:</p>
<ul>
<li>abase </li>
<li>abased</li>
<li>abasement</li>
<li>abasements </li>
<li>abases</li>
</ul>
<p>This coding below is meant to find a word in a file and print all the lines to the end of the file. But it doesnt it only prints out my search term a... | 0 | 2009-12-18T16:49:24Z | 1,929,459 | <p>For the first part of the question, unindent your <code>if f: print line,</code>. Otherwise, you're only trying to print when the regex matches.</p>
<p>It's not clear to me what your question is in the second part. I see what you're trying to do, and your code, but you've not indicated how it misbehaves.</p>
| 1 | 2009-12-18T16:54:25Z | [
"python",
"file",
"search"
] |
Searching for text in a file | 1,929,432 | <p>hi there got a couple of probs, say in my text file i have:</p>
<ul>
<li>abase </li>
<li>abased</li>
<li>abasement</li>
<li>abasements </li>
<li>abases</li>
</ul>
<p>This coding below is meant to find a word in a file and print all the lines to the end of the file. But it doesnt it only prints out my search term a... | 0 | 2009-12-18T16:49:24Z | 1,929,494 | <p>For the first part the algorithm goes like this (in pseudo code):</p>
<pre><code>found = False
for every line in the file:
if line contains search term:
found = True
if found:
print line
</code></pre>
| 1 | 2009-12-18T16:58:59Z | [
"python",
"file",
"search"
] |
pyfacebook stream.publish not publishing all details | 1,929,495 | <p>Trying to publish a stream to facebook using py facebook. The stream publishes a single attachment perfectly i.e media or name or href , e.t.c </p>
<p>But when it comes to appending all the attachments in one line it breaks down and just publishes the message. </p>
<p>attachment = [media,description] etc does not ... | 0 | 2009-12-18T16:59:01Z | 1,935,105 | <p>You haven't really given enough information to know what is causing the first issue (the only code you pasted doesn't include the pyfacebook call and has a syntax error from indentation).</p>
<p>about the second issue, python and pyfacebook can deal with facebook's server api only. If you want a popup displayed to ... | 0 | 2009-12-20T07:20:03Z | [
"python",
"facebook"
] |
Reading the same file multiple times in Python | 1,929,662 | <p>I need to download a zip archive of text files, dispatch each text file in the archive to other handlers for processing, and finally write the unzipped text file to disk.</p>
<p>I have the following code. It uses multiple open/close on the same file, which does not seem elegant. How do I make it more elegant and ef... | 2 | 2009-12-18T17:37:24Z | 1,929,683 | <p>You could say something like:</p>
<pre><code>handler_dispatch(logfile)
</code></pre>
<p>and</p>
<pre><code>def handler_dispatch(file):
for line in file:
handler1(line)
handler2(line)
</code></pre>
<p>or even make it more dynamic by constructing a Handler class with multiple handlerN functions, and... | 1 | 2009-12-18T17:40:37Z | [
"python",
"file-io",
"zip",
"unzip"
] |
Reading the same file multiple times in Python | 1,929,662 | <p>I need to download a zip archive of text files, dispatch each text file in the archive to other handlers for processing, and finally write the unzipped text file to disk.</p>
<p>I have the following code. It uses multiple open/close on the same file, which does not seem elegant. How do I make it more elegant and ef... | 2 | 2009-12-18T17:37:24Z | 1,929,694 | <p>Open the zip file once, loop through all the names, extract the file for each name and process it, then write it to disk.</p>
<p>Like so:</p>
<pre><code>for f_info in unzipped.info_list():
file = unzipped.open(f_info)
data = file.read()
# If you need a file like object, wrap it in a cStringIO
fobj ... | 1 | 2009-12-18T17:41:50Z | [
"python",
"file-io",
"zip",
"unzip"
] |
Reading the same file multiple times in Python | 1,929,662 | <p>I need to download a zip archive of text files, dispatch each text file in the archive to other handlers for processing, and finally write the unzipped text file to disk.</p>
<p>I have the following code. It uses multiple open/close on the same file, which does not seem elegant. How do I make it more elegant and ef... | 2 | 2009-12-18T17:37:24Z | 1,929,715 | <p>Your answer is in your example code. Just use StringIO to buffer the logfile:</p>
<pre><code>zipped = urllib.urlopen('www.abc.com/xyz.zip')
buf = cStringIO.StringIO(zipped.read())
zipped.close()
unzipped = zipfile.ZipFile(buf, 'r')
for f_info in unzipped.infolist():
logfile = unzipped.open(f_info)
# Here's wh... | 5 | 2009-12-18T17:46:21Z | [
"python",
"file-io",
"zip",
"unzip"
] |
Is there a better way to serve the results of an expensive, blocking python process over HTTP? | 1,929,681 | <p>We have a web service which serves small, arbitrary segments of a fixed inventory of larger MP3 files. The MP3 files are generated on-the-fly by a python application. The model is, make a GET request to a URL specifying which segments you want, get an <code>audio/mpeg</code> stream in response. This is an expensive... | 5 | 2009-12-18T17:39:52Z | 1,929,711 | <p>You might consider a queuing system with AJAX notification methods.</p>
<p>Whenever there is a request for your expensive resource, and that resource needs to be generated, add that request to the queue (if it's not already there). That queuing operation should return an ID of an object that you can query to get it... | 1 | 2009-12-18T17:46:05Z | [
"python",
"http",
"mod-wsgi",
"tornado"
] |
Is there a better way to serve the results of an expensive, blocking python process over HTTP? | 1,929,681 | <p>We have a web service which serves small, arbitrary segments of a fixed inventory of larger MP3 files. The MP3 files are generated on-the-fly by a python application. The model is, make a GET request to a URL specifying which segments you want, get an <code>audio/mpeg</code> stream in response. This is an expensive... | 5 | 2009-12-18T17:39:52Z | 1,929,738 | <p>It looks like you are doing things right -- just lacking CPU power: can you determine what is the CPU loading in the process of generating these MP3?</p>
<p>I think the next thing you have to do there is to add more hardware to render the MP3's on other machines. Or that or find a way to deliver pre-rendered MP3 (... | 0 | 2009-12-18T17:50:19Z | [
"python",
"http",
"mod-wsgi",
"tornado"
] |
Is there a better way to serve the results of an expensive, blocking python process over HTTP? | 1,929,681 | <p>We have a web service which serves small, arbitrary segments of a fixed inventory of larger MP3 files. The MP3 files are generated on-the-fly by a python application. The model is, make a GET request to a URL specifying which segments you want, get an <code>audio/mpeg</code> stream in response. This is an expensive... | 5 | 2009-12-18T17:39:52Z | 1,929,876 | <p>Have you tried <a href="http://pypi.python.org/pypi/Spawning" rel="nofollow">Spawning</a>? It is a WSGI server with a flexible assortment of threading modes.</p>
| 2 | 2009-12-18T18:18:12Z | [
"python",
"http",
"mod-wsgi",
"tornado"
] |
Is there a better way to serve the results of an expensive, blocking python process over HTTP? | 1,929,681 | <p>We have a web service which serves small, arbitrary segments of a fixed inventory of larger MP3 files. The MP3 files are generated on-the-fly by a python application. The model is, make a GET request to a URL specifying which segments you want, get an <code>audio/mpeg</code> stream in response. This is an expensive... | 5 | 2009-12-18T17:39:52Z | 1,934,893 | <p>Are you making the mistake of using embedded mode of Apache/mod_wsgi? Read:</p>
<p><a href="http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usage.html" rel="nofollow">http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usage.html</a></p>
<p>Ensure you use daemon mode if using Apache... | 1 | 2009-12-20T04:51:15Z | [
"python",
"http",
"mod-wsgi",
"tornado"
] |
Is there a better way to serve the results of an expensive, blocking python process over HTTP? | 1,929,681 | <p>We have a web service which serves small, arbitrary segments of a fixed inventory of larger MP3 files. The MP3 files are generated on-the-fly by a python application. The model is, make a GET request to a URL specifying which segments you want, get an <code>audio/mpeg</code> stream in response. This is an expensive... | 5 | 2009-12-18T17:39:52Z | 1,937,378 | <p>Please define "cascading load", as it has no common meaning.</p>
<p>Your most likely problem is going to be if you're running too many Apache processes.</p>
<p>For a load like this, make sure you're using the prefork mpm, and make sure you're limiting yourself to an appropriate number of processes (no less than on... | 1 | 2009-12-20T22:48:36Z | [
"python",
"http",
"mod-wsgi",
"tornado"
] |
Django Admin: not seeing any app (permission problem?) | 1,929,707 | <p>I have a site with Django running some custom apps. I was not using the Django ORM, just the view and templates but now I need to store some info so I created some models in one app and enabled the Admin.</p>
<p>The problem is when I log in the Admin it just says "You don't have permission to edit anything", not ev... | 5 | 2009-12-18T17:45:02Z | 1,929,816 | <p>Make sure you have added your application to settings.INSTALLED_APPS.</p>
<p>The django template for the admin app index page reads:</p>
<pre><code>{% if app_list %}
{% for app in app_list %}
...
{% else %}
<p>{% trans "You don't have permission to edit anything." %}</p>
{% endif %}
</code>... | 2 | 2009-12-18T18:05:36Z | [
"python",
"django",
"permissions",
"django-admin"
] |
Django Admin: not seeing any app (permission problem?) | 1,929,707 | <p>I have a site with Django running some custom apps. I was not using the Django ORM, just the view and templates but now I need to store some info so I created some models in one app and enabled the Admin.</p>
<p>The problem is when I log in the Admin it just says "You don't have permission to edit anything", not ev... | 5 | 2009-12-18T17:45:02Z | 1,929,896 | <p>Try accessing your database and in the table auth_user make sure that the fiels is_staff, is_active and is_superuser are marked as true (1) for your user.</p>
| 2 | 2009-12-18T18:23:01Z | [
"python",
"django",
"permissions",
"django-admin"
] |
Django Admin: not seeing any app (permission problem?) | 1,929,707 | <p>I have a site with Django running some custom apps. I was not using the Django ORM, just the view and templates but now I need to store some info so I created some models in one app and enabled the Admin.</p>
<p>The problem is when I log in the Admin it just says "You don't have permission to edit anything", not ev... | 5 | 2009-12-18T17:45:02Z | 1,930,130 | <p>It sounds like you haven't registered any apps with the admin (step 5 in <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overview">this overview</a>).</p>
<p>Try adding the line <code>admin.autodiscover()</code> to your main urls.py, making sure to do <code>from django.contrib import admin</code> f... | 11 | 2009-12-18T19:10:00Z | [
"python",
"django",
"permissions",
"django-admin"
] |
Django Admin: not seeing any app (permission problem?) | 1,929,707 | <p>I have a site with Django running some custom apps. I was not using the Django ORM, just the view and templates but now I need to store some info so I created some models in one app and enabled the Admin.</p>
<p>The problem is when I log in the Admin it just says "You don't have permission to edit anything", not ev... | 5 | 2009-12-18T17:45:02Z | 2,616,516 | <p>We encountered the same problem when installing django 1.1 over an old installation of django 0.96</p>
<p>it was solved when we made a fresh install</p>
| 0 | 2010-04-11T09:00:06Z | [
"python",
"django",
"permissions",
"django-admin"
] |
Django Admin: not seeing any app (permission problem?) | 1,929,707 | <p>I have a site with Django running some custom apps. I was not using the Django ORM, just the view and templates but now I need to store some info so I created some models in one app and enabled the Admin.</p>
<p>The problem is when I log in the Admin it just says "You don't have permission to edit anything", not ev... | 5 | 2009-12-18T17:45:02Z | 7,021,995 | <p>Hopefully this helps someone, but we had this same problem because someone added a different authentication backend to settings.py and did not keep the default ModelBackend. Changing the setting to:</p>
<pre><code>AUTHENTICATION_BACKENDS = (
'auth.authentication.EmailBackend',
'django.contrib.auth.backends.... | 18 | 2011-08-11T06:58:21Z | [
"python",
"django",
"permissions",
"django-admin"
] |
Django Admin: not seeing any app (permission problem?) | 1,929,707 | <p>I have a site with Django running some custom apps. I was not using the Django ORM, just the view and templates but now I need to store some info so I created some models in one app and enabled the Admin.</p>
<p>The problem is when I log in the Admin it just says "You don't have permission to edit anything", not ev... | 5 | 2009-12-18T17:45:02Z | 18,900,876 | <p>I had the same problem, my settings file was like follow:</p>
<pre><code> PROJECT_APPS = (
'app1',
'app2',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django... | 0 | 2013-09-19T17:04:42Z | [
"python",
"django",
"permissions",
"django-admin"
] |
regex to remove URL from text | 1,929,793 | <p>I want to remove all occurrences of URL [full path, query string] from the text in Python. Any suggestions on how to do this? I am new to regex!</p>
<pre><code>http://example.com/url/?x=data
</code></pre>
<p>This whole URL should be removed!
Thanks</p>
| 1 | 2009-12-18T18:02:17Z | 1,929,821 | <p>This is definitely a non-trivial task assuming you want to remove any valid URL. I'd take a look at the Regex Lib <a href="http://regexlib.com/Search.aspx?k=URL" rel="nofollow">page on the topic</a>.</p>
| 1 | 2009-12-18T18:06:46Z | [
"python",
"regex",
"url"
] |
regex to remove URL from text | 1,929,793 | <p>I want to remove all occurrences of URL [full path, query string] from the text in Python. Any suggestions on how to do this? I am new to regex!</p>
<pre><code>http://example.com/url/?x=data
</code></pre>
<p>This whole URL should be removed!
Thanks</p>
| 1 | 2009-12-18T18:02:17Z | 1,929,823 | <p><a href="http://stackoverflow.com/questions/1141848/regex-to-match-url">This previous question will get you off to a good start to match the URL</a>, (ie. <a href="http://regexlib.com/DisplayPatterns.aspx?cattabindex=1&categoryId=2" rel="nofollow">RegExLib.com</a>) then its just a matter of the removal</p>
| 1 | 2009-12-18T18:07:16Z | [
"python",
"regex",
"url"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.