title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Telnet automation / scripting | 1,491,494 | <p>I have already checked <a href="http://stackoverflow.com/questions/709801/creating-a-script-for-a-telnet-session">This Question</a> but could not find what i'm looking for. I am running Windows (the client), and the server is a legacy mainframe type server.</p>
<p>Basically I need to write a script, python code or... | 5 | 2009-09-29T09:29:42Z | 1,491,566 | <p>I've never used it myself, but maybe <a href="http://pypi.python.org/pypi/pexpect" rel="nofollow">pexpect</a> is what you need?</p>
<blockquote>
<p>"Pexpect can be used for automating
interactive applications such as ssh,
ftp, passwd, telnet, etc."</p>
</blockquote>
| 0 | 2009-09-29T09:44:36Z | [
"python",
"windows",
"scripting",
"automation",
"telnet"
] |
Telnet automation / scripting | 1,491,494 | <p>I have already checked <a href="http://stackoverflow.com/questions/709801/creating-a-script-for-a-telnet-session">This Question</a> but could not find what i'm looking for. I am running Windows (the client), and the server is a legacy mainframe type server.</p>
<p>Basically I need to write a script, python code or... | 5 | 2009-09-29T09:29:42Z | 2,184,149 | <p>You may want to consider <a href="http://wiki.github.com/knipknap/exscript/" rel="nofollow">Exscript</a> as well. It simplifies some of the easy tasks but for more complicated there is additional level of abstraction (Exscript is a scripting language in itself). Either way - worth checking out.</p>
| 3 | 2010-02-02T12:59:55Z | [
"python",
"windows",
"scripting",
"automation",
"telnet"
] |
Telnet automation / scripting | 1,491,494 | <p>I have already checked <a href="http://stackoverflow.com/questions/709801/creating-a-script-for-a-telnet-session">This Question</a> but could not find what i'm looking for. I am running Windows (the client), and the server is a legacy mainframe type server.</p>
<p>Basically I need to write a script, python code or... | 5 | 2009-09-29T09:29:42Z | 5,316,604 | <p>This thread is old but I thought I'd go ahead and post anyway. There is a prog called AutoMate that would most likely suit your needs well. It runs on Windows and is pretty easy to use. </p>
<p>More info on telnet automation - <a href="http://www.networkautomation.com/sales/terminal-emulation-automation/" rel="n... | 0 | 2011-03-15T19:00:04Z | [
"python",
"windows",
"scripting",
"automation",
"telnet"
] |
a better way to do ajax in django | 1,491,618 | <p>The other day I wrote some AJAX for a Django app that i have been working on.</p>
<p>I come from Ruby on Rails, so I haven't done much in the way of raw JS.</p>
<p>So based on Rails' partials, I something similar to the following in a sort of pseudocode, don't sweat the details:</p>
<p>1) JS function using protot... | 5 | 2009-09-29T09:59:44Z | 1,491,640 | <p>What exactly seems hacky about it? Seems like a perfectly valid way of doing something.</p>
<p>I guess an alternative would be <a href="http://docs.djangoproject.com/en/dev/topics/serialization/" rel="nofollow">serialising</a> to json and sending it back to a javascript <a href="http://plugins.jquery.com/project/te... | 1 | 2009-09-29T10:04:58Z | [
"javascript",
"python",
"ajax",
"django"
] |
a better way to do ajax in django | 1,491,618 | <p>The other day I wrote some AJAX for a Django app that i have been working on.</p>
<p>I come from Ruby on Rails, so I haven't done much in the way of raw JS.</p>
<p>So based on Rails' partials, I something similar to the following in a sort of pseudocode, don't sweat the details:</p>
<p>1) JS function using protot... | 5 | 2009-09-29T09:59:44Z | 1,491,654 | <p><em>No matter what</em>, you're going to need at least two things:</p>
<ol>
<li><p>Your javascript code to make the call (you have this)</p></li>
<li><p>Server side code to handle the request (this is your view and url-config)</p></li>
</ol>
<p>There is absolutely nothing "hacky" about this.</p>
<p>The third thin... | 2 | 2009-09-29T10:08:12Z | [
"javascript",
"python",
"ajax",
"django"
] |
a better way to do ajax in django | 1,491,618 | <p>The other day I wrote some AJAX for a Django app that i have been working on.</p>
<p>I come from Ruby on Rails, so I haven't done much in the way of raw JS.</p>
<p>So based on Rails' partials, I something similar to the following in a sort of pseudocode, don't sweat the details:</p>
<p>1) JS function using protot... | 5 | 2009-09-29T09:59:44Z | 1,491,693 | <p>It kinda depends what you want to do I think. Ajax being quite a wide range of scenarios from Google Maps to a simple auto-complete varys greatly in complexity and the best approach.</p>
<p>However, there are some useful things you can do that help.</p>
<p>1) Template level</p>
<p>Make sure you have "django.core.... | 5 | 2009-09-29T10:18:30Z | [
"javascript",
"python",
"ajax",
"django"
] |
a better way to do ajax in django | 1,491,618 | <p>The other day I wrote some AJAX for a Django app that i have been working on.</p>
<p>I come from Ruby on Rails, so I haven't done much in the way of raw JS.</p>
<p>So based on Rails' partials, I something similar to the following in a sort of pseudocode, don't sweat the details:</p>
<p>1) JS function using protot... | 5 | 2009-09-29T09:59:44Z | 1,732,118 | <p>I am quite late, but I want to document how to combine and adapt the solutions presented by <a href="http://stackoverflow.com/questions/1491618/a-better-way-to-do-ajax-in-django/1491693#1491693">d0ugal</a>
in a way, that it will resolve a much cleaner template-code.</p>
<p>I have a model representing contact person... | 4 | 2009-11-13T21:45:04Z | [
"javascript",
"python",
"ajax",
"django"
] |
get the exit code for python program | 1,491,796 | <p>I'm running a python program on windowsXP, how can i obtain the exit code after my program ends ?</p>
<p>Thanks.</p>
| 5 | 2009-09-29T10:40:30Z | 1,491,834 | <p>From a Windows command line you can use:</p>
<pre><code>echo %ERRORLEVEL%
</code></pre>
<p>For example:</p>
<pre><code>C:\work>python helloworld.py
Hello World!
C:\work>echo %ERRORLEVEL%
0
</code></pre>
| 5 | 2009-09-29T10:47:15Z | [
"python"
] |
get the exit code for python program | 1,491,796 | <p>I'm running a python program on windowsXP, how can i obtain the exit code after my program ends ?</p>
<p>Thanks.</p>
| 5 | 2009-09-29T10:40:30Z | 1,491,844 | <p>How do you run the program?</p>
<p>Exit in python with sys.exit(1)</p>
<p>If you're in CMD or a BAT file you can access the variable %ERRORLEVEL% to obtain the exit code.</p>
<p>For example (batch file):</p>
<pre><code>IF ERRORLEVEL 1 GOTO LABEL
</code></pre>
| 4 | 2009-09-29T10:51:07Z | [
"python"
] |
get the exit code for python program | 1,491,796 | <p>I'm running a python program on windowsXP, how can i obtain the exit code after my program ends ?</p>
<p>Thanks.</p>
| 5 | 2009-09-29T10:40:30Z | 1,491,863 | <p>You can also use python to start your python-program</p>
<pre><code>import subprocess
import sys
retcode = subprocess.call([sys.executable, "myscript.py"])
print retcode
</code></pre>
| 3 | 2009-09-29T10:57:16Z | [
"python"
] |
get the exit code for python program | 1,491,796 | <p>I'm running a python program on windowsXP, how can i obtain the exit code after my program ends ?</p>
<p>Thanks.</p>
| 5 | 2009-09-29T10:40:30Z | 1,491,864 | <p>If you want to use ERRORLEVEL (as opposed to %ERRORLEVEL%) to <a href="http://support.microsoft.com/kb/69576" rel="nofollow">check for a specific exit value</a> use</p>
<pre><code>IF ERRORLEVEL <N> IF NOT ERRORLEVEL <N+1> <COMMAND>
</code></pre>
<p>For example </p>
<pre><code>IF ERRORLEVEL 3 IF ... | 1 | 2009-09-29T10:57:22Z | [
"python"
] |
get the exit code for python program | 1,491,796 | <p>I'm running a python program on windowsXP, how can i obtain the exit code after my program ends ?</p>
<p>Thanks.</p>
| 5 | 2009-09-29T10:40:30Z | 2,028,050 | <p>I got the following in a script:</p>
<pre><code>set ERRORLEVEL=17
python.exe -c "import sys; sys.exit(1)"
echo %ERRORLEVEL%
</code></pre>
<p>==> <strong>17</strong></p>
| 1 | 2010-01-08T14:06:02Z | [
"python"
] |
Testing for an empty iterator in a Python for... loop | 1,491,957 | <p>The code below is based on <a href="http://code.activestate.com/recipes/413614/" rel="nofollow">this recipe</a>. However, the key point of the recipe - that it provides a way to break out of the iteration on an iterator if the iterator is empty - doesn't seem to work here, instead behaving in the following undesired... | 1 | 2009-09-29T11:27:15Z | 1,492,039 | <p>why are you doing it this way at all? why not just:</p>
<pre><code>def get_choice(pattern, inpt):
choices = pattern.finditer(inpt, re.M)
if not choices:
sys.exit('No choices')
for choice in choices:
print(choice.group(0))
if get_yes_no_answer():
return choice
sys.... | 3 | 2009-09-29T11:43:03Z | [
"python",
"exception",
"iterator",
"conditional"
] |
Testing for an empty iterator in a Python for... loop | 1,491,957 | <p>The code below is based on <a href="http://code.activestate.com/recipes/413614/" rel="nofollow">this recipe</a>. However, the key point of the recipe - that it provides a way to break out of the iteration on an iterator if the iterator is empty - doesn't seem to work here, instead behaving in the following undesired... | 1 | 2009-09-29T11:27:15Z | 1,492,102 | <p>See the pairwise iterator from <a href="http://stackoverflow.com/questions/914715/python-looping-through-all-but-the-last-item-of-a-list/914786#914786">this question</a>. You can then check for last item like this:</p>
<pre><code>MISSING = object()
for choice, next_choice in pairwise(chain(choice_iterator, [MISSING... | 0 | 2009-09-29T11:58:44Z | [
"python",
"exception",
"iterator",
"conditional"
] |
Testing for an empty iterator in a Python for... loop | 1,491,957 | <p>The code below is based on <a href="http://code.activestate.com/recipes/413614/" rel="nofollow">this recipe</a>. However, the key point of the recipe - that it provides a way to break out of the iteration on an iterator if the iterator is empty - doesn't seem to work here, instead behaving in the following undesired... | 1 | 2009-09-29T11:27:15Z | 1,492,111 | <p>Why so complex approach?</p>
<p>I think this should do pretty much the same:</p>
<pre><code>def my_func(pattern, data):
choices = pattern.findall(data, re.M)
while(len(choices)>1):
choice = choices.pop(0)
if get_yes_no_answer():
return choice
else:
choices.pop(0)
else:
return N... | 0 | 2009-09-29T12:00:30Z | [
"python",
"exception",
"iterator",
"conditional"
] |
Testing for an empty iterator in a Python for... loop | 1,491,957 | <p>The code below is based on <a href="http://code.activestate.com/recipes/413614/" rel="nofollow">this recipe</a>. However, the key point of the recipe - that it provides a way to break out of the iteration on an iterator if the iterator is empty - doesn't seem to work here, instead behaving in the following undesired... | 1 | 2009-09-29T11:27:15Z | 1,492,146 | <p>You don't need to check if the iterator is empty. The for loop will do that for you, and stop when the iterator is empty. It's as simple as that.</p>
<p>Also, you don't need the <code>else</code> after the sys.exit() or the return.</p>
<p>That done, your code looks like this:</p>
<pre><code>def my_func(choice_pat... | 1 | 2009-09-29T12:06:53Z | [
"python",
"exception",
"iterator",
"conditional"
] |
Download multiple pages concurrently? | 1,491,993 | <p>I'd like to write a script in Python that can grab url's from a database, and download web pages concurrently to speed things instead of waiting for each page to download one after the other.</p>
<p>According to <a href="http://stackoverflow.com/questions/1155404/python-accessing-multiple-webpages-at-once">this thr... | 2 | 2009-09-29T11:35:11Z | 1,492,033 | <p>You can have a look at the <a href="http://docs.python.org/library/multiprocessing.html" rel="nofollow">multiprocessing package</a> which avoid the GIL lock problem.</p>
| 0 | 2009-09-29T11:42:23Z | [
"python",
"concurrent-processing"
] |
Download multiple pages concurrently? | 1,491,993 | <p>I'd like to write a script in Python that can grab url's from a database, and download web pages concurrently to speed things instead of waiting for each page to download one after the other.</p>
<p>According to <a href="http://stackoverflow.com/questions/1155404/python-accessing-multiple-webpages-at-once">this thr... | 2 | 2009-09-29T11:35:11Z | 1,492,076 | <p>Don't worry about GIL. In your case it doesn't matter.</p>
<p>Easiest way to do what you want is to create thread pool, using <em>threading</em> module and one of thread pool implementations from <a href="http://code.activestate.com/recipes/langs/python/tags/pool/" rel="nofollow">ASPN</a>. Each thread from that poo... | 9 | 2009-09-29T11:52:32Z | [
"python",
"concurrent-processing"
] |
Download multiple pages concurrently? | 1,491,993 | <p>I'd like to write a script in Python that can grab url's from a database, and download web pages concurrently to speed things instead of waiting for each page to download one after the other.</p>
<p>According to <a href="http://stackoverflow.com/questions/1155404/python-accessing-multiple-webpages-at-once">this thr... | 2 | 2009-09-29T11:35:11Z | 1,492,094 | <p>Downloading is IO, which may be done asynchronously using non-blocking sockets or twisted. Both of these solutions will be much more efficient than threading or multiprocessing.</p>
| 0 | 2009-09-29T11:57:11Z | [
"python",
"concurrent-processing"
] |
Download multiple pages concurrently? | 1,491,993 | <p>I'd like to write a script in Python that can grab url's from a database, and download web pages concurrently to speed things instead of waiting for each page to download one after the other.</p>
<p>According to <a href="http://stackoverflow.com/questions/1155404/python-accessing-multiple-webpages-at-once">this thr... | 2 | 2009-09-29T11:35:11Z | 1,492,194 | <p>GIL prevents you from effectively doing processor load balancing with threads. As this is not processor loads balancing but preventing one IO wait from stopping the whole download, the GIL is not relevant here. *)</p>
<p>So all you need to do is create several processes that download at the same time. You can do th... | 7 | 2009-09-29T12:17:17Z | [
"python",
"concurrent-processing"
] |
Download multiple pages concurrently? | 1,491,993 | <p>I'd like to write a script in Python that can grab url's from a database, and download web pages concurrently to speed things instead of waiting for each page to download one after the other.</p>
<p>According to <a href="http://stackoverflow.com/questions/1155404/python-accessing-multiple-webpages-at-once">this thr... | 2 | 2009-09-29T11:35:11Z | 1,492,284 | <p>I recently solved this same problem. One thing to consider is that some people don't take kindly to having their servers bogged down and will block an IP address that does so. The standard courtesy that I've heard is about 3 seconds between page requests, but this is flexible.</p>
<p>If you are downloading from m... | 2 | 2009-09-29T12:38:07Z | [
"python",
"concurrent-processing"
] |
Download multiple pages concurrently? | 1,491,993 | <p>I'd like to write a script in Python that can grab url's from a database, and download web pages concurrently to speed things instead of waiting for each page to download one after the other.</p>
<p>According to <a href="http://stackoverflow.com/questions/1155404/python-accessing-multiple-webpages-at-once">this thr... | 2 | 2009-09-29T11:35:11Z | 1,493,005 | <p><a href="http://docs.python.org/library/urllib.html" rel="nofollow">urllib</a> & <a href="http://docs.python.org/library/threading.html#module-threading" rel="nofollow">threading</a> (or <a href="http://docs.python.org/library/multiprocessing.html#module-multiprocessing" rel="nofollow">multiprocessing</a>) packa... | 1 | 2009-09-29T14:43:24Z | [
"python",
"concurrent-processing"
] |
Download multiple pages concurrently? | 1,491,993 | <p>I'd like to write a script in Python that can grab url's from a database, and download web pages concurrently to speed things instead of waiting for each page to download one after the other.</p>
<p>According to <a href="http://stackoverflow.com/questions/1155404/python-accessing-multiple-webpages-at-once">this thr... | 2 | 2009-09-29T11:35:11Z | 9,016,152 | <p>Nowadays there are excellent Python libs that do this for you - <a href="http://urllib3.readthedocs.org/" rel="nofollow">urllib3</a> and <a href="http://docs.python-requests.org/" rel="nofollow">requests</a></p>
| 1 | 2012-01-26T09:37:52Z | [
"python",
"concurrent-processing"
] |
Python: can you tell the name of the calling shell? | 1,492,508 | <p>I have a python script that is always called from a shell, which can be either zsh or bash. </p>
<p>How can I tell which one called the script?</p>
| 1 | 2009-09-29T13:22:00Z | 1,492,532 | <p>os.system("echo $0")</p>
<p>This works flawlessly on my system:</p>
<pre><code>cat shell.py:
#!/ms/dist/python/PROJ/core/2.5/bin/python
import os
print os.system("echo $0")
</code></pre>
<p><br></p>
<pre><code>bash-2.05b$ uname -a
Linux pi929c1n10 2.4.21-32.0.1.EL.msdwhugemem #1 SMP Mon Dec 5 21:3... | -2 | 2009-09-29T13:24:08Z | [
"python",
"shell"
] |
Python: can you tell the name of the calling shell? | 1,492,508 | <p>I have a python script that is always called from a shell, which can be either zsh or bash. </p>
<p>How can I tell which one called the script?</p>
| 1 | 2009-09-29T13:22:00Z | 1,492,602 | <p>You can't do this in a reliable automated way.</p>
<ul>
<li><p>Environment variables can be misleading (a user can maliciously switch them). Most automatic shell variables aren't "leaky", i.e. they are only visible in the shell process, and not for child processes.</p></li>
<li><p>You could figure out your parent P... | 0 | 2009-09-29T13:35:18Z | [
"python",
"shell"
] |
Python: can you tell the name of the calling shell? | 1,492,508 | <p>I have a python script that is always called from a shell, which can be either zsh or bash. </p>
<p>How can I tell which one called the script?</p>
| 1 | 2009-09-29T13:22:00Z | 1,492,649 | <pre><code>import os
shell = os.getenv('SHELL')
</code></pre>
| 0 | 2009-09-29T13:42:20Z | [
"python",
"shell"
] |
Python: can you tell the name of the calling shell? | 1,492,508 | <p>I have a python script that is always called from a shell, which can be either zsh or bash. </p>
<p>How can I tell which one called the script?</p>
| 1 | 2009-09-29T13:22:00Z | 1,492,667 | <p>In Linux you can use procfs:</p>
<pre><code>>>> os.readlink('/proc/%d/exe' % os.getppid())
'/bin/bash'
</code></pre>
<p><code>os.getppid()</code> returns the PID of parent process. This is portable. But obtaining process name can't be done in portable way. You can parse <code>ps</code> output which is ava... | 6 | 2009-09-29T13:44:54Z | [
"python",
"shell"
] |
How to shutdown cherrypy from within? | 1,492,699 | <p>I am developing on cherrypy, I start it from a python script.</p>
<p>For better development I wonder what is the correct way to stop cherrypy from within the main process (and not from the outside with ctrl-c or SIGTERM).</p>
<p>I assume I have to register a callback function from the main application to be able t... | 0 | 2009-09-29T13:49:19Z | 1,492,746 | <pre><code>import sys
class MyCherryPyApplication(object):
def default(self):
sys.exit()
default.exposed = True
cherrypy.quickstart(MyCherryPyApplication())
</code></pre>
<p>Putting a sys.exit() in any request handler exits the whole server</p>
<p>I would have expected this only terminates the current threa... | 5 | 2009-09-29T14:02:06Z | [
"python",
"cherrypy"
] |
Rhythmbox: how do I access the 'rating' field of a track through Python script? | 1,492,849 | <p>I would like the capability to get/set the rating associated with a specific track through a Python. How do I achieve this?</p>
| 2 | 2009-09-29T14:18:47Z | 1,493,522 | <p>You can use Rhythmbox' D-Bus interface. I have written a small script that can get/set the rating and displays a notification, all acting on the currently playing song.</p>
<p>The script is here: <a href="http://kaizer.se/wiki/code/rhrating.py" rel="nofollow">http://kaizer.se/wiki/code/rhrating.py</a></p>
<p>Adden... | 3 | 2009-09-29T16:07:23Z | [
"python",
"linux",
"rhythmbox"
] |
Creating a news archive in Django | 1,492,866 | <p>I looking to build a news archive in python/django, I have no idea where to start with it though. I need the view to pull out all the news articles with I have done I then need to divide them in months and years so e.g.</p>
<p>Sept 09
Oct 09</p>
<p>I then need in the view to some every time a new news article is ... | 2 | 2009-09-29T14:21:55Z | 1,493,485 | <p>It seems like you are trying to make a single view that pulls out of of the data and then try to order them by dates ect. I don't think that would be the best way to go about this.</p>
<p>Instead what you could do is to make a view to display each month's articles. I don't know your models but something like:</p>
... | 0 | 2009-09-29T16:01:25Z | [
"python",
"django",
"django-models",
"mysql",
"django-templates"
] |
Creating a news archive in Django | 1,492,866 | <p>I looking to build a news archive in python/django, I have no idea where to start with it though. I need the view to pull out all the news articles with I have done I then need to divide them in months and years so e.g.</p>
<p>Sept 09
Oct 09</p>
<p>I then need in the view to some every time a new news article is ... | 2 | 2009-09-29T14:21:55Z | 1,493,543 | <p>An excellent place to start is the book <a href="http://www.apress.com/book/view/9781430219385" rel="nofollow">Practical Django Projects</a> by James Bennett. Among other things, it guides you through the development of a web blog with multiple time-based views (by month, etc) that should serve you well as the basi... | 3 | 2009-09-29T16:11:23Z | [
"python",
"django",
"django-models",
"mysql",
"django-templates"
] |
Creating a news archive in Django | 1,492,866 | <p>I looking to build a news archive in python/django, I have no idea where to start with it though. I need the view to pull out all the news articles with I have done I then need to divide them in months and years so e.g.</p>
<p>Sept 09
Oct 09</p>
<p>I then need in the view to some every time a new news article is ... | 2 | 2009-09-29T14:21:55Z | 1,493,824 | <p>One option you can try is to create a custom manager for your model that provides a way to pull out the archives. Here's code that I use:</p>
<pre><code>from django.db import models, connection
import datetime
class EntryManager(models.Manager):
def get_archives(self, level=0):
query = """
... | 3 | 2009-09-29T17:08:07Z | [
"python",
"django",
"django-models",
"mysql",
"django-templates"
] |
Identical string return FALSE with '==' in Python, why? | 1,493,007 | <p>The data string is receive through a socket connexion. When receiving the first example where action variable would = 'IDENTIFY', it works. But when receiving the second example where action variable would = 'MSG' it does not compare.</p>
<p>And the most bizarre thing, when I use Telnet instead of my socket client... | 1 | 2009-09-29T14:44:03Z | 1,493,039 | <p>Can't reproduce your problem. To debug it, print or log the <code>repr()</code> of <code>data</code> and <code>action</code>: this will likely show you the cause (probably some non-visible binary byte has snuck into <code>data</code>, based on how you obtained it [[which you don't show us]] and hence into <code>acti... | 5 | 2009-09-29T14:50:26Z | [
"python",
"string-comparison"
] |
Program new functionality for zoom button on Microsoft Natural Ergonomic Desktop 7000 | 1,493,202 | <p>I just bought a new keyboard and mouse (Microsoft Natural Ergonomic Desktop 7000) and it has a neat little zoom lever in the middle of the keyboard. What I'd like to do is write a little program (in C# or Python, for use on Windows Vista) which makes the zoom button act like a scroll button instead.</p>
<p>I have n... | 1 | 2009-09-29T15:13:15Z | 1,493,412 | <p>This web page en comments should help you out a bit: <a href="http://oliiscool.blogspot.com/2006/11/hacking-microsoft-natural-ergonomic.html" rel="nofollow">Icool blog</a></p>
| 1 | 2009-09-29T15:47:44Z | [
"c#",
"python",
"keyboard",
"driver"
] |
Subclass of webapp.RequestHandler doesn't have a response attribute | 1,493,467 | <p>Using the below code, my template loads fine until I submit the from, then I get the following error:</p>
<pre><code>e = AttributeError("'ToDo' object has no attribute 'response'",)
</code></pre>
<p>Why doesn't my <code>ToDo</code> object not have a <code>response</code> attribute? It works the first time it's cal... | 0 | 2009-09-29T15:58:17Z | 1,493,607 | <p>why do you do what you do in <code>post</code>? it should be:</p>
<pre><code>def post(self):
task = Task() # not ToDo()
task.description = self.request.get('description')
task.put()
self.redirect('/')
</code></pre>
<p><code>put</code> called on a subclass of <code>webapp.RequestHandl... | 3 | 2009-09-29T16:24:22Z | [
"python",
"google-app-engine",
"post-redirect-get"
] |
Cannot access django app through ip address while accessing it through localhost | 1,493,479 | <p>I have a django app on my local computer. I can access the application from a browser by using the url: <a href="http://localhost:8000/myapp/">http://localhost:8000/myapp/</a></p>
<p>But I cannot access the application by using the ip of the host computer: <a href="http://193.140.209.49:8000/myapp/">http://193.140.... | 13 | 2009-09-29T16:00:31Z | 1,493,598 | <p>I assume you're using the development server. If so, then you need to specifically bind to your external IP for the server to be available there. Try this command:</p>
<pre><code>./manage.py runserver 193.140.209.49:8000
</code></pre>
| 47 | 2009-09-29T16:22:37Z | [
"python",
"django",
"networking"
] |
Embeddable Workflow/BPM Library For Python? | 1,493,550 | <p>Let's say you are building a Python-based web app that requires some workflow management such as that in jBPM or Windows Workflow Foundation. Is there a library that offers this in the Python world?</p>
| 7 | 2009-09-29T16:12:20Z | 1,493,731 | <p>Oh yes, tons. But most of them depend on a specific framework. DCWorkflow is integrated with Zopes CMF, for example. hurry.workflow is for Zope 3, etc. SpiffWorkflow presumes sql-alchemy, etc. This is because you need to have something to apply the workflow to, and that means you need to make some basic assumptions ... | 2 | 2009-09-29T16:50:21Z | [
"python",
"workflow",
"bpm"
] |
Embeddable Workflow/BPM Library For Python? | 1,493,550 | <p>Let's say you are building a Python-based web app that requires some workflow management such as that in jBPM or Windows Workflow Foundation. Is there a library that offers this in the Python world?</p>
| 7 | 2009-09-29T16:12:20Z | 1,927,875 | <p>Have you looked at this? <a href="http://code.djangoproject.com/wiki/GoFlow" rel="nofollow">http://code.djangoproject.com/wiki/GoFlow</a></p>
| 1 | 2009-12-18T12:12:08Z | [
"python",
"workflow",
"bpm"
] |
Regex find non digit and/or end of string | 1,493,871 | <p>How do I include an end-of-string and one non-digit characters in a python 2.6 regular expression set for searching?</p>
<p>I want to find 10-digit numbers with a non-digit at the beginning and a non-digit or end-of-string at the end. It is a 10-digit ISBN number and 'X' is valid for the final digit.</p>
<p>The fo... | 2 | 2009-09-29T17:18:10Z | 1,493,900 | <p>You have to group the alternatives with parenthesis, not brackets:</p>
<pre><code>r'\D(\d{9}[\dXx])($|\D)'
</code></pre>
<p><code>|</code> is a different construct than <code>[]</code>. It marks an alternative between two patterns, while <code>[]</code> matches one of the contained characters. So <code>|</code> sh... | 4 | 2009-09-29T17:22:41Z | [
"python",
"regex"
] |
Regex find non digit and/or end of string | 1,493,871 | <p>How do I include an end-of-string and one non-digit characters in a python 2.6 regular expression set for searching?</p>
<p>I want to find 10-digit numbers with a non-digit at the beginning and a non-digit or end-of-string at the end. It is a 10-digit ISBN number and 'X' is valid for the final digit.</p>
<p>The fo... | 2 | 2009-09-29T17:18:10Z | 1,493,929 | <pre><code>\D(\d{10})(?:\Z|\D)
</code></pre>
<p>find non-digit followed by 10 digits, and a single non-digit or a end-of-string. Captures only digits. While I see that you're searching for nine digit followed by digit or <code>X</code> or <code>x</code>, I don't see same thing in your requirements.</p>
| 0 | 2009-09-29T17:26:54Z | [
"python",
"regex"
] |
Django - accessing the RequestContext from within a custom filter | 1,493,874 | <p>I've got a filter <code>currency</code>, which takes a value in USD and converts it to a currency (either USD or GBP). The currency to convert to is stored in the session, but filters don't take <code>RequestContext</code>, so I can't grab it straight from there.</p>
<p>Is there a better way than passing the releva... | 14 | 2009-09-29T17:18:29Z | 1,494,009 | <p>If you create a template tag instead of a filter, you are given the context to work with (which contains the request). <a href="http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-tags">http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-tags... | 7 | 2009-09-29T17:45:22Z | [
"python",
"django",
"django-templates"
] |
Django - accessing the RequestContext from within a custom filter | 1,493,874 | <p>I've got a filter <code>currency</code>, which takes a value in USD and converts it to a currency (either USD or GBP). The currency to convert to is stored in the session, but filters don't take <code>RequestContext</code>, so I can't grab it straight from there.</p>
<p>Is there a better way than passing the releva... | 14 | 2009-09-29T17:18:29Z | 1,511,457 | <p>This can be done using a filter. First make sure that you have <code>"django.core.context_processors.request"</code> in you <code>TEMPLATE_CONTEXT_PROCESSORS</code>. If you don't, you can add this to your settings.py file:</p>
<pre><code>TEMPLATE_CONTEXT_PROCESSORS += (
"django.core.context_processors.request"
... | 3 | 2009-10-02T19:49:20Z | [
"python",
"django",
"django-templates"
] |
Django - accessing the RequestContext from within a custom filter | 1,493,874 | <p>I've got a filter <code>currency</code>, which takes a value in USD and converts it to a currency (either USD or GBP). The currency to convert to is stored in the session, but filters don't take <code>RequestContext</code>, so I can't grab it straight from there.</p>
<p>Is there a better way than passing the releva... | 14 | 2009-09-29T17:18:29Z | 28,098,279 | <p>I would have to agree with Adam that migrating the code to a custom tag is the best way.</p>
<p>However, a client needed to record the use of certain filters only when a page was published and had a HUGE inventory of templates that used the existing filter syntax. It would have been a costly undertaking to rewrite... | 0 | 2015-01-22T20:40:22Z | [
"python",
"django",
"django-templates"
] |
Django - accessing the RequestContext from within a custom filter | 1,493,874 | <p>I've got a filter <code>currency</code>, which takes a value in USD and converts it to a currency (either USD or GBP). The currency to convert to is stored in the session, but filters don't take <code>RequestContext</code>, so I can't grab it straight from there.</p>
<p>Is there a better way than passing the releva... | 14 | 2009-09-29T17:18:29Z | 28,581,108 | <p>A somehow less hacky solution to Daniel Rhoden's proposal is, to use <code>threading.local()</code>. Define a middleware class, which stores your <code>request</code> as a global object inside your local thread, and add that class to your <code>MIDDLEWARE_CLASSES</code>.</p>
<p>Now a template filter can easily acce... | 0 | 2015-02-18T10:20:15Z | [
"python",
"django",
"django-templates"
] |
Is there any Python XML parser that was designed with humans in mind? | 1,493,899 | <p>I like Python, but I don't want to write 10 lines just to get an attribute from an element. Maybe it's just me, but <code>minidom</code> isn't that <code>mini</code>. The code I have to write in order to parse something using it looks a lot like Java code.</p>
<p>Is there something that is more <code>user-friendly<... | 23 | 2009-09-29T17:22:34Z | 1,493,970 | <p>You should take a look at <a href="http://effbot.org/zone/element-index.htm">ElementTree</a>. It's not doing exactly what you want but it's a lot better then minidom. If I remember correctly, starting from python 2.4, it's included in the standard libraries. For more speed use cElementTree. For more more speed (and ... | 22 | 2009-09-29T17:35:42Z | [
"python",
"xml",
"user-friendly"
] |
Is there any Python XML parser that was designed with humans in mind? | 1,493,899 | <p>I like Python, but I don't want to write 10 lines just to get an attribute from an element. Maybe it's just me, but <code>minidom</code> isn't that <code>mini</code>. The code I have to write in order to parse something using it looks a lot like Java code.</p>
<p>Is there something that is more <code>user-friendly<... | 23 | 2009-09-29T17:22:34Z | 1,494,188 | <p>I actually wrote a library that does things exactly the way you imagined it. The library is called "xe" and you can get it from: <a href="http://home.avvanta.com/~steveha/xe.html" rel="nofollow">http://home.avvanta.com/~steveha/xe.html</a></p>
<p>xe can import XML to let you work with the data in an object-oriente... | 3 | 2009-09-29T18:32:14Z | [
"python",
"xml",
"user-friendly"
] |
Is there any Python XML parser that was designed with humans in mind? | 1,493,899 | <p>I like Python, but I don't want to write 10 lines just to get an attribute from an element. Maybe it's just me, but <code>minidom</code> isn't that <code>mini</code>. The code I have to write in order to parse something using it looks a lot like Java code.</p>
<p>Is there something that is more <code>user-friendly<... | 23 | 2009-09-29T17:22:34Z | 12,743,457 | <p>I had same need for simple xml parser and after a long time spent on checking different libraries I found <a href="http://www.aaronsw.com/2002/xmltramp/" rel="nofollow">xmltramp</a>.</p>
<p>Based on your example xml:
</p>
<pre><code>import xmltramp
xml_string = """<root>
<node value="30">text</node... | 2 | 2012-10-05T09:33:23Z | [
"python",
"xml",
"user-friendly"
] |
Is there any Python XML parser that was designed with humans in mind? | 1,493,899 | <p>I like Python, but I don't want to write 10 lines just to get an attribute from an element. Maybe it's just me, but <code>minidom</code> isn't that <code>mini</code>. The code I have to write in order to parse something using it looks a lot like Java code.</p>
<p>Is there something that is more <code>user-friendly<... | 23 | 2009-09-29T17:22:34Z | 20,976,225 | <p>I spent a fair bit of time going through the examples provided above and through the repositories listed on pip.</p>
<p>The easiest (and most Pythonic) way of parsing XML that I have found so far has been XMLToDict - <a href="https://github.com/martinblech/xmltodict" rel="nofollow">https://github.com/martinblech/xm... | 0 | 2014-01-07T16:00:25Z | [
"python",
"xml",
"user-friendly"
] |
POSTing a complex JSON object using Prototype | 1,494,039 | <p>I'm using Prototype 1.6.1 to create an application under IIS, using ASP and Python.</p>
<p>The python is generating a complex JSON object. I want to pass this object to another page via an AJAX request, but the Prototype documentation is a little too cunning for me.</p>
<p>Can someone show me an example of how to... | 1 | 2009-09-29T17:54:50Z | 1,494,095 | <pre><code>new Ajax.Request('/some_url',
{
method:"post",
postBody:"{'some':'json'}",
onSuccess: function(transport){
var response = transport.responseText || "no response text";
alert("Success! \n\n" + response);
},
onFailure: function(){ alert('Something went wrong...') }
});
</code></pre>
| 7 | 2009-09-29T18:08:08Z | [
"javascript",
"python",
"iis",
"prototypejs"
] |
How to define [] for class in Python? | 1,494,146 | <p>I feel like this question has already been asked and answered, yet I couldn't find anything on-topic, so excuse me if it is so. I want to define the behaviour of [] brackets when applied to class, similar to <code>def []=()</code> construct in ruby, so that calling Python <code>obj['foo']</code> would actually call ... | 3 | 2009-09-29T18:22:17Z | 1,494,160 | <p>It's all in the docs: <a href="http://docs.python.org/reference/datamodel.html#object.%5F%5Fgetitem%5F%5F" rel="nofollow"><code>__getitem__</code></a>.</p>
| 11 | 2009-09-29T18:25:51Z | [
"python"
] |
How to define [] for class in Python? | 1,494,146 | <p>I feel like this question has already been asked and answered, yet I couldn't find anything on-topic, so excuse me if it is so. I want to define the behaviour of [] brackets when applied to class, similar to <code>def []=()</code> construct in ruby, so that calling Python <code>obj['foo']</code> would actually call ... | 3 | 2009-09-29T18:22:17Z | 1,494,161 | <p>This is done with <code>__getitem___</code> in Python.</p>
<p>Here is a list of all the operators:
<a href="http://docs.python.org/library/operator.html" rel="nofollow">http://docs.python.org/library/operator.html</a></p>
| 7 | 2009-09-29T18:26:39Z | [
"python"
] |
How to define [] for class in Python? | 1,494,146 | <p>I feel like this question has already been asked and answered, yet I couldn't find anything on-topic, so excuse me if it is so. I want to define the behaviour of [] brackets when applied to class, similar to <code>def []=()</code> construct in ruby, so that calling Python <code>obj['foo']</code> would actually call ... | 3 | 2009-09-29T18:22:17Z | 1,494,172 | <p>define a method in your class with <code>__getitem__(key)</code> and <code>__setitem__(key, value)</code></p>
| 5 | 2009-09-29T18:28:13Z | [
"python"
] |
How to define [] for class in Python? | 1,494,146 | <p>I feel like this question has already been asked and answered, yet I couldn't find anything on-topic, so excuse me if it is so. I want to define the behaviour of [] brackets when applied to class, similar to <code>def []=()</code> construct in ruby, so that calling Python <code>obj['foo']</code> would actually call ... | 3 | 2009-09-29T18:22:17Z | 1,494,177 | <p><a href="http://docs.python.org/reference/datamodel.html" rel="nofollow">http://docs.python.org/reference/datamodel.html</a></p>
<p>Section 3.4 in the above link shows you all or most of the operators you can overload in Python. The one you want to overload is</p>
<pre><code>__getitem__()
</code></pre>
| 4 | 2009-09-29T18:29:13Z | [
"python"
] |
How to get a timestamp older than 1901 | 1,494,231 | <p>I'm trying to find to accurately count the number of seconds since Jan 1, 1850 to the present in a couple of languages (JavaScript, C++, and Python [don't even ask, I stopped asking these questions long ago]).</p>
<p>Problem is the platforms store timestamps as 32-bit signed integers, so I can't get a timestamp for... | 3 | 2009-09-29T18:41:33Z | 1,494,267 | <p>In python, there's the <a href="http://docs.python.org/library/datetime.html#date-objects" rel="nofollow">datetime module</a>. Specifically, the date class will help.</p>
<pre><code>from datetime import date
print date(1850, 1, 1).weekday() # 1, which is Tuesday
# (Mon is 0)
</code></pre>
<p><strong>Edit</stron... | 4 | 2009-09-29T18:48:34Z | [
"javascript",
"c++",
"python",
"timestamp"
] |
How to get a timestamp older than 1901 | 1,494,231 | <p>I'm trying to find to accurately count the number of seconds since Jan 1, 1850 to the present in a couple of languages (JavaScript, C++, and Python [don't even ask, I stopped asking these questions long ago]).</p>
<p>Problem is the platforms store timestamps as 32-bit signed integers, so I can't get a timestamp for... | 3 | 2009-09-29T18:41:33Z | 1,494,286 | <p>The portable, language-agnostic approach:</p>
<p>Step 1. Count the number of seconds between 01/01/1850 00:00 and 01/01/1901 00:00. Save this number somewhere (call it M)</p>
<p>Step 2. Use available language functionality to count the number of seconds between 01/01/1901 00:00 and whatever other date and time you... | 3 | 2009-09-29T18:52:09Z | [
"javascript",
"c++",
"python",
"timestamp"
] |
How to get a timestamp older than 1901 | 1,494,231 | <p>I'm trying to find to accurately count the number of seconds since Jan 1, 1850 to the present in a couple of languages (JavaScript, C++, and Python [don't even ask, I stopped asking these questions long ago]).</p>
<p>Problem is the platforms store timestamps as 32-bit signed integers, so I can't get a timestamp for... | 3 | 2009-09-29T18:41:33Z | 1,494,464 | <p>Under WIN32, you can use <strong>SystemTimeToFileTime</strong>.</p>
<p><strong>FILETIME</strong> is a 64-bit unsigned integer that counts the number of 100-nanosecond intervals since January 1, 1601 (UTC).</p>
<p>You can convert two timestamps to FILETIME. You can convert it to ULARGE_INTEGER (t.dwLowDateTime + t.... | 1 | 2009-09-29T19:27:34Z | [
"javascript",
"c++",
"python",
"timestamp"
] |
How to get a timestamp older than 1901 | 1,494,231 | <p>I'm trying to find to accurately count the number of seconds since Jan 1, 1850 to the present in a couple of languages (JavaScript, C++, and Python [don't even ask, I stopped asking these questions long ago]).</p>
<p>Problem is the platforms store timestamps as 32-bit signed integers, so I can't get a timestamp for... | 3 | 2009-09-29T18:41:33Z | 1,495,334 | <p>Why not use <strong>Date</strong> objects instead of integers, at least to get a starting point.</p>
<pre><code>function secondsSince(D){
D= new Date(Date.parse(D));
D.setUTCHours(0,0,0,0);
return Math.floor((new Date()-D)/1000);
}
</code></pre>
<p>//test with a date</p>
<p>var daystring='Jan 1, 1850',
ss= s... | 0 | 2009-09-29T22:40:58Z | [
"javascript",
"c++",
"python",
"timestamp"
] |
How to get a timestamp older than 1901 | 1,494,231 | <p>I'm trying to find to accurately count the number of seconds since Jan 1, 1850 to the present in a couple of languages (JavaScript, C++, and Python [don't even ask, I stopped asking these questions long ago]).</p>
<p>Problem is the platforms store timestamps as 32-bit signed integers, so I can't get a timestamp for... | 3 | 2009-09-29T18:41:33Z | 1,495,736 | <p>The egenix datetime is also worth looking at
<a href="http://www.egenix.com/products/python/mxBase/mxDateTime/" rel="nofollow">http://www.egenix.com/products/python/mxBase/mxDateTime/</a></p>
| 0 | 2009-09-30T01:33:41Z | [
"javascript",
"c++",
"python",
"timestamp"
] |
asn.1 parser in C/Python | 1,494,372 | <p>I am looking for a solution to parse asn.1 spec files and generate a decoder from those.</p>
<p>Ideally I would like to work with Python modules, but if nothing is available I would use C/C++ libraries and interface them with Python with the plethora of solutions out there.</p>
<p>In the past I have been using pya... | 10 | 2009-09-29T19:06:56Z | 1,494,480 | <p>There is an <a href="http://www.antlr.org/grammar/1231433381400/ASN.g" rel="nofollow">ANTLR ASN.1 grammar</a>; using ANTLR, you should be able to make an ASN.1 parser out of it. Generating code for pyasn1 is left as an exercise to the poster :-)</p>
| 2 | 2009-09-29T19:30:35Z | [
"python",
"c",
"parsing",
"asn.1"
] |
asn.1 parser in C/Python | 1,494,372 | <p>I am looking for a solution to parse asn.1 spec files and generate a decoder from those.</p>
<p>Ideally I would like to work with Python modules, but if nothing is available I would use C/C++ libraries and interface them with Python with the plethora of solutions out there.</p>
<p>In the past I have been using pya... | 10 | 2009-09-29T19:06:56Z | 1,494,811 | <p>Never tried them but:</p>
<ul>
<li><a href="http://asn1c.sourceforge.net/" rel="nofollow">asn1c</a></li>
<li><a href="http://svn.debian.org/wsvn/collab-maint/deb-maint/snacc/" rel="nofollow">snacc</a></li>
</ul>
<p>Both seems to do what you want (C, not Python).</p>
| 4 | 2009-09-29T20:40:49Z | [
"python",
"c",
"parsing",
"asn.1"
] |
asn.1 parser in C/Python | 1,494,372 | <p>I am looking for a solution to parse asn.1 spec files and generate a decoder from those.</p>
<p>Ideally I would like to work with Python modules, but if nothing is available I would use C/C++ libraries and interface them with Python with the plethora of solutions out there.</p>
<p>In the past I have been using pya... | 10 | 2009-09-29T19:06:56Z | 1,495,428 | <p>I have done a similar job using asn1c and building around it a Pyrex extension. The wrapped structure is described in <a href="http://www.3gpp.org/ftp/Specs/html-info/32401.htm" rel="nofollow">3GPP TS 32.401</a>.</p>
<p>With Pyrex you can write a wrapper thick enough to convert between native Python data types and ... | 1 | 2009-09-29T23:18:32Z | [
"python",
"c",
"parsing",
"asn.1"
] |
asn.1 parser in C/Python | 1,494,372 | <p>I am looking for a solution to parse asn.1 spec files and generate a decoder from those.</p>
<p>Ideally I would like to work with Python modules, but if nothing is available I would use C/C++ libraries and interface them with Python with the plethora of solutions out there.</p>
<p>In the past I have been using pya... | 10 | 2009-09-29T19:06:56Z | 1,496,061 | <p>I have experience with <a href="http://pyasn1.sourceforge.net/" rel="nofollow">pyasn1</a> and it's enough to parse quite complex grammars. A grammar is expressed with python structure, so no need to run code generator.</p>
| 2 | 2009-09-30T04:00:19Z | [
"python",
"c",
"parsing",
"asn.1"
] |
asn.1 parser in C/Python | 1,494,372 | <p>I am looking for a solution to parse asn.1 spec files and generate a decoder from those.</p>
<p>Ideally I would like to work with Python modules, but if nothing is available I would use C/C++ libraries and interface them with Python with the plethora of solutions out there.</p>
<p>In the past I have been using pya... | 10 | 2009-09-29T19:06:56Z | 1,497,694 | <p>I'm the author of LEPL, a parser written in Python, and what you want to do is one of the things on my "TODO" list.</p>
<p>I will not be doing this soon, but you might consider using LEPL to construct your solution because:</p>
<p>1 - it's a pure Python solution (which makes life simpler)</p>
<p>2 - it can alread... | 2 | 2009-09-30T12:01:58Z | [
"python",
"c",
"parsing",
"asn.1"
] |
asn.1 parser in C/Python | 1,494,372 | <p>I am looking for a solution to parse asn.1 spec files and generate a decoder from those.</p>
<p>Ideally I would like to work with Python modules, but if nothing is available I would use C/C++ libraries and interface them with Python with the plethora of solutions out there.</p>
<p>In the past I have been using pya... | 10 | 2009-09-29T19:06:56Z | 3,006,715 | <p>I wrote such parser a few years ago. It generates python classes for pyasn1 library. I used in on ericsson doc to make parser for their CDRs.</p>
<p>I'll try posting the code here now.</p>
<pre><code>import sys
from pyparsing import *
OpenBracket = Regex("[({]").suppress()
CloseBracket = Regex("[)}]").suppress()
... | 11 | 2010-06-09T14:20:12Z | [
"python",
"c",
"parsing",
"asn.1"
] |
General Command pattern and Command Dispatch pattern in Python | 1,494,442 | <p>I was looking for a <em>Command</em> pattern implementation in Python...
(According to <a href="http://en.wikipedia.org/wiki/Command%5Fpattern">Wikipedia</a>, </p>
<blockquote>
<p>the command pattern is a design
pattern in which an object is used to
represent and encapsulate all the
information needed to ca... | 19 | 2009-09-29T19:23:23Z | 1,494,455 | <p>Yes, you do miss something: the command pattern is only necessary in languages that don't have function pointers (or functions as first class objects), such as Java. In languages with functions-as-objects, you can use the function itself; no need to have a separate command object (which then should have a "doit" met... | 2 | 2009-09-29T19:26:13Z | [
"python",
"design-patterns",
"oop"
] |
General Command pattern and Command Dispatch pattern in Python | 1,494,442 | <p>I was looking for a <em>Command</em> pattern implementation in Python...
(According to <a href="http://en.wikipedia.org/wiki/Command%5Fpattern">Wikipedia</a>, </p>
<blockquote>
<p>the command pattern is a design
pattern in which an object is used to
represent and encapsulate all the
information needed to ca... | 19 | 2009-09-29T19:23:23Z | 1,494,501 | <p>Did some searching and found this. It appears to do the job of encapsulating an action.</p>
<pre><code>def demo(a,b,c):
print 'a:',a
print 'b:',b
print 'c:',c
class Command:
def __init__(self, cmd, *args):
self._cmd=cmd
self._args=args
def __call__(self, *args):
return ... | 3 | 2009-09-29T19:36:45Z | [
"python",
"design-patterns",
"oop"
] |
General Command pattern and Command Dispatch pattern in Python | 1,494,442 | <p>I was looking for a <em>Command</em> pattern implementation in Python...
(According to <a href="http://en.wikipedia.org/wiki/Command%5Fpattern">Wikipedia</a>, </p>
<blockquote>
<p>the command pattern is a design
pattern in which an object is used to
represent and encapsulate all the
information needed to ca... | 19 | 2009-09-29T19:23:23Z | 1,494,510 | <p>If I recall the gang of four correctly, the Command pattern is about commands like "File - Save", not commands like "svn commit", which is what your code is good for.</p>
<p>Martin suggests the Command pattern is unneeded because functions as first class objects take its place, but the Command pattern is richer tha... | 2 | 2009-09-29T19:39:20Z | [
"python",
"design-patterns",
"oop"
] |
General Command pattern and Command Dispatch pattern in Python | 1,494,442 | <p>I was looking for a <em>Command</em> pattern implementation in Python...
(According to <a href="http://en.wikipedia.org/wiki/Command%5Fpattern">Wikipedia</a>, </p>
<blockquote>
<p>the command pattern is a design
pattern in which an object is used to
represent and encapsulate all the
information needed to ca... | 19 | 2009-09-29T19:23:23Z | 1,494,532 | <p>The simplest command pattern is already built into Python, simply use a callable:</p>
<pre><code>def greet(who):
print "Hello %s" % who
greet_command = lambda: greet("World")
# pass the callable around, and invoke it later
greet_command()
</code></pre>
<p>The command pattern as an object oriented design patte... | 47 | 2009-09-29T19:44:04Z | [
"python",
"design-patterns",
"oop"
] |
Separate Admin/User authentication system in Django | 1,494,524 | <p>I've recently started learning/using django; I'm trying to figure out a way to have two separate authentications systems for administrators and users. Rather than create a whole new auth system, I'd like to leverage django's built-in functionality (i.e. session management, @login_required decorator, etc.). </p>
<p>... | 5 | 2009-09-29T19:41:26Z | 1,494,572 | <p>Modify things slightly so that users have a category prefix on their username? You haven't given us much info on what you want to do, it's possible that your needs might be met by using the sites framework, or simply two separate django installs.</p>
<p>If what you're trying to do is make the user login page and th... | 0 | 2009-09-29T19:53:29Z | [
"python",
"django",
"authentication"
] |
Separate Admin/User authentication system in Django | 1,494,524 | <p>I've recently started learning/using django; I'm trying to figure out a way to have two separate authentications systems for administrators and users. Rather than create a whole new auth system, I'd like to leverage django's built-in functionality (i.e. session management, @login_required decorator, etc.). </p>
<p>... | 5 | 2009-09-29T19:41:26Z | 1,494,779 | <p>You could potentially write one or more custom authentication backends. This is documented <a href="http://docs.djangoproject.com/en/dev/topics/auth/#writing-an-authentication-backend" rel="nofollow">here</a>. I have written a custom backend to authenticate against an LDAP server, for example.</p>
| 1 | 2009-09-29T20:33:29Z | [
"python",
"django",
"authentication"
] |
Separate Admin/User authentication system in Django | 1,494,524 | <p>I've recently started learning/using django; I'm trying to figure out a way to have two separate authentications systems for administrators and users. Rather than create a whole new auth system, I'd like to leverage django's built-in functionality (i.e. session management, @login_required decorator, etc.). </p>
<p>... | 5 | 2009-09-29T19:41:26Z | 1,494,848 | <p>If I understand your question correctly (and perhaps I don't), I think you're asking how to create a separate login form for non-admin users, while still using the standard Django authentication mechanisms, <code>User</code> model, etc. This is supported natively by Django through views in <code>django.contrib.auth.... | 1 | 2009-09-29T20:46:42Z | [
"python",
"django",
"authentication"
] |
Are Python's bools passed by value? | 1,494,696 | <p>I sent a reference to a bool object, and I modified it within a method. After the method finished it's execution, the value of the bool outside the method was unchanged.</p>
<p>This leads me to believe that Python's bools are passed by value. Is that true? What other Python types behave that way?</p>
| 5 | 2009-09-29T20:17:19Z | 1,494,722 | <p>It depends on whether the object is mutable or immutable. Immutable objects behave like you saw with the bool, whereas mutable objects will change.</p>
<p>For reference: <a href="http://www.testingreflections.com/node/view/5126" rel="nofollow">http://www.testingreflections.com/node/view/5126</a></p>
<blockquote>
... | 1 | 2009-09-29T20:22:06Z | [
"python",
"boolean",
"pass-by-value"
] |
Are Python's bools passed by value? | 1,494,696 | <p>I sent a reference to a bool object, and I modified it within a method. After the method finished it's execution, the value of the bool outside the method was unchanged.</p>
<p>This leads me to believe that Python's bools are passed by value. Is that true? What other Python types behave that way?</p>
| 5 | 2009-09-29T20:17:19Z | 1,494,728 | <p>Python variables are not "references" in the C++ sense. Rather, they are simply local names bound to an object at some arbitrary location in memory. If that object is itself mutable, changes to it will be visible in other scopes that have bound a name to the object. Many primitive types (including <code>bool</code>,... | 12 | 2009-09-29T20:23:48Z | [
"python",
"boolean",
"pass-by-value"
] |
Are Python's bools passed by value? | 1,494,696 | <p>I sent a reference to a bool object, and I modified it within a method. After the method finished it's execution, the value of the bool outside the method was unchanged.</p>
<p>This leads me to believe that Python's bools are passed by value. Is that true? What other Python types behave that way?</p>
| 5 | 2009-09-29T20:17:19Z | 1,494,730 | <p>In short, <em>there are no variables in Python</em>; there are objects (Like True and False, the bools happen to be immutable), and names. Names are what you call variables, but names belong to a scope, you can't normally change names other than the local names.</p>
| 0 | 2009-09-29T20:24:08Z | [
"python",
"boolean",
"pass-by-value"
] |
Are Python's bools passed by value? | 1,494,696 | <p>I sent a reference to a bool object, and I modified it within a method. After the method finished it's execution, the value of the bool outside the method was unchanged.</p>
<p>This leads me to believe that Python's bools are passed by value. Is that true? What other Python types behave that way?</p>
| 5 | 2009-09-29T20:17:19Z | 1,495,889 | <p>The thing to remember is that there is <em>no</em> way in Python for a function or a method to rebind a name in the calling namespace. When you write "I sent a reference to a bool object, and I modified it within a method", what you actually did (I am guessing) was to rebind the parameter name (to which the bool val... | 1 | 2009-09-30T02:51:58Z | [
"python",
"boolean",
"pass-by-value"
] |
Percentage with variable precision | 1,494,708 | <p>I would like to display a percentage with three decimal places unless it's greater than 99%. Then, I'd like to display the number with all the available nines plus 3 non-nine characters.</p>
<p>How can I write this in Python? The <code>"%.8f"</code> string formatting works decently, but I need to keep the last thre... | 0 | 2009-09-29T20:19:32Z | 1,494,759 | <p>Try this:</p>
<pre><code>def print_percent(p):
for i in range(30):
if p <= 100. - 10.**(-i):
print ("%." + str(max(3,3+i-1)) + "f") % p
return
</code></pre>
<p>or this if you just want to retrieve the string</p>
<pre><code>def print_percent(p):
for i in range(20)... | 0 | 2009-09-29T20:29:03Z | [
"python",
"algorithm",
"precision"
] |
Percentage with variable precision | 1,494,708 | <p>I would like to display a percentage with three decimal places unless it's greater than 99%. Then, I'd like to display the number with all the available nines plus 3 non-nine characters.</p>
<p>How can I write this in Python? The <code>"%.8f"</code> string formatting works decently, but I need to keep the last thre... | 0 | 2009-09-29T20:19:32Z | 1,494,770 | <p>I am quite confident that this is not possible with standard formating. I suggest to use something like the following (C# like pseudo code). Especially I suggest to rely on string operations and not to use math code because of many possible precision and rounding problems.</p>
<pre><code>string numberString = numbe... | 0 | 2009-09-29T20:31:52Z | [
"python",
"algorithm",
"precision"
] |
Percentage with variable precision | 1,494,708 | <p>I would like to display a percentage with three decimal places unless it's greater than 99%. Then, I'd like to display the number with all the available nines plus 3 non-nine characters.</p>
<p>How can I write this in Python? The <code>"%.8f"</code> string formatting works decently, but I need to keep the last thre... | 0 | 2009-09-29T20:19:32Z | 1,494,778 | <pre><code>def ceilpowerof10(x):
return math.pow(10, math.ceil(math.log10(x)))
def nines(x):
return -int(math.log10(ceilpowerof10(x) - x))
def threeplaces(x):
return ('%.' + str(nines(x) + 3) + 'f') % x
</code></pre>
<p>Note that nines() throws an error on numbers that are a power of 10 to begin with, it... | 1 | 2009-09-29T20:32:52Z | [
"python",
"algorithm",
"precision"
] |
Percentage with variable precision | 1,494,708 | <p>I would like to display a percentage with three decimal places unless it's greater than 99%. Then, I'd like to display the number with all the available nines plus 3 non-nine characters.</p>
<p>How can I write this in Python? The <code>"%.8f"</code> string formatting works decently, but I need to keep the last thre... | 0 | 2009-09-29T20:19:32Z | 1,494,850 | <p>Try this:</p>
<pre><code>import math
def format_percentage(x, precision=3):
return ("%%.%df%%%%" % (precision - min(0,math.log10(100-x)))) % x
</code></pre>
| 3 | 2009-09-29T20:47:25Z | [
"python",
"algorithm",
"precision"
] |
Percentage with variable precision | 1,494,708 | <p>I would like to display a percentage with three decimal places unless it's greater than 99%. Then, I'd like to display the number with all the available nines plus 3 non-nine characters.</p>
<p>How can I write this in Python? The <code>"%.8f"</code> string formatting works decently, but I need to keep the last thre... | 0 | 2009-09-29T20:19:32Z | 1,495,094 | <pre><code> def ilike9s(f):
return re.sub(r"(\d*\.9*\d\d\d)\d*",r"\1","%.17f" % f)
</code></pre>
<p><hr /></p>
<p>So...</p>
<pre><code>>>> ilike9s(1.0)
'1.000'
>>> ilike9s(12.9999991232132132)
'12.999999123'
>>> ilike9s(12.345678901234)
'12.345'
</code></pre>
<p>And don't forget to <co... | 0 | 2009-09-29T21:35:57Z | [
"python",
"algorithm",
"precision"
] |
Percentage with variable precision | 1,494,708 | <p>I would like to display a percentage with three decimal places unless it's greater than 99%. Then, I'd like to display the number with all the available nines plus 3 non-nine characters.</p>
<p>How can I write this in Python? The <code>"%.8f"</code> string formatting works decently, but I need to keep the last thre... | 0 | 2009-09-29T20:19:32Z | 1,495,175 | <p>Mark Ransom's answer is a beautiful thing. With a little bit of work, it can solve the problem for any inputs. I went ahead and did the little bit of work.</p>
<p>You just need to add some code to nines():</p>
<pre><code>def nines(x):
x = abs(x) # avoid exception caused if x is negative
x -= int(x) # k... | 2 | 2009-09-29T21:58:24Z | [
"python",
"algorithm",
"precision"
] |
http checks python | 1,495,367 | <p>learning python here, I want to check if anybody is running a web server on my local
network, using this code, but it gives me a lot of error in the concole.</p>
<pre><code>#!/usr/bin/env python
import httplib
last = 1
while last <> 255:
url = "10.1.1." + "last"
connection = httplib.HTTPConne... | 3 | 2009-09-29T22:52:31Z | 1,495,378 | <p>Remove the quotes from the variable names <code>last</code> and <code>url</code>. Python is interpreting them as strings rather than variables. Try this:</p>
<pre><code>#!/usr/bin/env python
import httplib
last = 1
while last <> 255:
url = "10.1.1.%d" % last
connection = httplib.HTTPConnectio... | 1 | 2009-09-29T22:59:52Z | [
"python",
"http"
] |
http checks python | 1,495,367 | <p>learning python here, I want to check if anybody is running a web server on my local
network, using this code, but it gives me a lot of error in the concole.</p>
<pre><code>#!/usr/bin/env python
import httplib
last = 1
while last <> 255:
url = "10.1.1." + "last"
connection = httplib.HTTPConne... | 3 | 2009-09-29T22:52:31Z | 1,495,379 | <p>You're trying to connect to an url that is <strong>literally</strong> the string <code>'url'</code>: that's what the quotes you're using in </p>
<pre><code> connection = httplib.HTTPConnection("url", 80)
</code></pre>
<p><strong>mean</strong>. Once you remedy that (by removing those quotes) you'll be trying to... | 1 | 2009-09-29T23:00:17Z | [
"python",
"http"
] |
http checks python | 1,495,367 | <p>learning python here, I want to check if anybody is running a web server on my local
network, using this code, but it gives me a lot of error in the concole.</p>
<pre><code>#!/usr/bin/env python
import httplib
last = 1
while last <> 255:
url = "10.1.1." + "last"
connection = httplib.HTTPConne... | 3 | 2009-09-29T22:52:31Z | 1,495,480 | <p>I do suggest changing the while loop to the more idiomatic for loop, and handling exceptions:</p>
<pre><code>#!/usr/bin/env python
import httplib
import socket
for i in range(1, 256):
try:
url = "10.1.1.%d" % i
connection = httplib.HTTPConnection(url, 80)
connection.request("GET","/")... | 5 | 2009-09-29T23:39:05Z | [
"python",
"http"
] |
http checks python | 1,495,367 | <p>learning python here, I want to check if anybody is running a web server on my local
network, using this code, but it gives me a lot of error in the concole.</p>
<pre><code>#!/usr/bin/env python
import httplib
last = 1
while last <> 255:
url = "10.1.1." + "last"
connection = httplib.HTTPConne... | 3 | 2009-09-29T22:52:31Z | 1,500,046 | <p>as pointed out, you have some basic
quotation issues. but more fundamentally:</p>
<ol>
<li>you're not using Pythonesque
constructs to handle things but
you're coding them as simple
imperative code. that's fine, of course, but below are examples of funner (and better) ways to express things</li>
<li>you need to ex... | 2 | 2009-09-30T19:01:05Z | [
"python",
"http"
] |
Is there any python library for parsing dates and times from a natural language? | 1,495,487 | <p>What I'm looking for is something that can translate 'tomorrow at 6am' or 'next moday at noon' to the appropriate datetime objects.</p>
| 26 | 2009-09-29T23:43:41Z | 1,495,548 | <p><a href="https://github.com/bear/parsedatetime">parsedatetime</a> - <em>Python module that is able to parse 'human readable' date/time expressions.</em></p>
<pre><code>#!/usr/bin/env python
from datetime import datetime
import parsedatetime as pdt # $ pip install parsedatetime
cal = pdt.Calendar()
now = datetime.n... | 34 | 2009-09-30T00:06:17Z | [
"python",
"parsing"
] |
Is there any python library for parsing dates and times from a natural language? | 1,495,487 | <p>What I'm looking for is something that can translate 'tomorrow at 6am' or 'next moday at noon' to the appropriate datetime objects.</p>
| 26 | 2009-09-29T23:43:41Z | 1,496,032 | <p>See what you think of <a href="http://pyparsing.wikispaces.com/UnderDevelopment#toc0">this example</a> from the pyparsing wiki. It handles the following test cases:</p>
<pre><code>today
tomorrow
yesterday
in a couple of days
a couple of days from now
a couple of days from today
in a day
3 days ago
3 days from now
... | 10 | 2009-09-30T03:48:08Z | [
"python",
"parsing"
] |
Combining Dictionaries Of Lists In Python | 1,495,510 | <p>I have a very large collection of (p, q) tuples that I would like to convert into a dictionary of lists where the first item in each tuple is a key that indexes a list that contains q.</p>
<p>Example: </p>
<pre><code>Original List: (1, 2), (1, 3), (2, 3)
Resultant Dictionary: {1:[2, 3], 2:[3]}
</code></pre>
<p... | 10 | 2009-09-29T23:54:01Z | 1,495,552 | <p>defaltdict to the rescue (as usual)</p>
<pre><code>from collections import defaultdict
my_dict = defaultdict(list)
for key,value in original_list:
my_dict[key].append(value)
</code></pre>
<p>Combining the two dicts can be done like this (note that duplicates will be preserved):</p>
<pre><code>for key,value i... | 3 | 2009-09-30T00:09:15Z | [
"python",
"list",
"dictionary"
] |
Combining Dictionaries Of Lists In Python | 1,495,510 | <p>I have a very large collection of (p, q) tuples that I would like to convert into a dictionary of lists where the first item in each tuple is a key that indexes a list that contains q.</p>
<p>Example: </p>
<pre><code>Original List: (1, 2), (1, 3), (2, 3)
Resultant Dictionary: {1:[2, 3], 2:[3]}
</code></pre>
<p... | 10 | 2009-09-29T23:54:01Z | 1,495,562 | <p><a href="http://docs.python.org/3.1/library/collections.html#defaultdict-objects" rel="nofollow"><code>collections.defaultdict</code></a> works like this:</p>
<pre><code>from collections import defaultdict
dic = defaultdict(list)
for i, j in tuples:
dic[i].append(j)
</code></pre>
<p>similar for the dicts:</p>
... | 3 | 2009-09-30T00:12:36Z | [
"python",
"list",
"dictionary"
] |
Combining Dictionaries Of Lists In Python | 1,495,510 | <p>I have a very large collection of (p, q) tuples that I would like to convert into a dictionary of lists where the first item in each tuple is a key that indexes a list that contains q.</p>
<p>Example: </p>
<pre><code>Original List: (1, 2), (1, 3), (2, 3)
Resultant Dictionary: {1:[2, 3], 2:[3]}
</code></pre>
<p... | 10 | 2009-09-29T23:54:01Z | 1,495,730 | <p>Here is the iterator style of doing it</p>
<pre>
>>> mylist=[(1, 2), (1, 3), (2, 3)]
>>> from itertools import groupby
>>> from operator import itemgetter
>>> mylist=[(1, 2), (1, 3), (2, 3)]
>>> groupby(mylist,itemgetter(0))
>>> list(_)
[(1, <itertools._grouper object at 0xb7d402ec>), (2, <itertools._grouper... | 0 | 2009-09-30T01:29:55Z | [
"python",
"list",
"dictionary"
] |
Combining Dictionaries Of Lists In Python | 1,495,510 | <p>I have a very large collection of (p, q) tuples that I would like to convert into a dictionary of lists where the first item in each tuple is a key that indexes a list that contains q.</p>
<p>Example: </p>
<pre><code>Original List: (1, 2), (1, 3), (2, 3)
Resultant Dictionary: {1:[2, 3], 2:[3]}
</code></pre>
<p... | 10 | 2009-09-29T23:54:01Z | 1,495,821 | <p>If the list of tuples is sorted, <code>itertools.groupby</code>, as suggested by @gnibbler, is not a bad alternative to <code>defaultdict</code>, but it needs to be used differently than he suggested:</p>
<pre><code>import itertools
import operator
def lot_to_dict(lot):
key = operator.itemgetter(0)
# if lot's ... | 9 | 2009-09-30T02:17:58Z | [
"python",
"list",
"dictionary"
] |
Combining Dictionaries Of Lists In Python | 1,495,510 | <p>I have a very large collection of (p, q) tuples that I would like to convert into a dictionary of lists where the first item in each tuple is a key that indexes a list that contains q.</p>
<p>Example: </p>
<pre><code>Original List: (1, 2), (1, 3), (2, 3)
Resultant Dictionary: {1:[2, 3], 2:[3]}
</code></pre>
<p... | 10 | 2009-09-29T23:54:01Z | 1,496,094 | <p>I wanted these done in <strong>one line</strong> just for fun:</p>
<pre><code>>>> from itertools import groupby
>>> t=(1, 2), (1, 3), (2, 3)
>>> [(i,[x for _,x in list(f)]) for i,f in groupby(sorted(t),lambda t: t[0])]
[(1, [2, 3]), (2, [3])]
>>> b={1:[2, 3], 2:[3]}, {1:[4], 3:... | 0 | 2009-09-30T04:18:17Z | [
"python",
"list",
"dictionary"
] |
Combining Dictionaries Of Lists In Python | 1,495,510 | <p>I have a very large collection of (p, q) tuples that I would like to convert into a dictionary of lists where the first item in each tuple is a key that indexes a list that contains q.</p>
<p>Example: </p>
<pre><code>Original List: (1, 2), (1, 3), (2, 3)
Resultant Dictionary: {1:[2, 3], 2:[3]}
</code></pre>
<p... | 10 | 2009-09-29T23:54:01Z | 9,815,938 | <p>This is how I do it in Python 2.7:</p>
<pre><code>combined = {}
combined.update(d1)
combined.update(d2)
</code></pre>
<p>It is good to define a utility function to do this:</p>
<pre><code>def merge(d1, d2):
''' Merge two dictionaries. '''
merged = {}
merged.update(d1)
merged.update(d2)
return ... | 0 | 2012-03-22T03:15:08Z | [
"python",
"list",
"dictionary"
] |
How to download any(!) webpage with correct charset in python? | 1,495,627 | <h1>Problem</h1>
<p><strong>When screen-scraping a webpage using python one has to know the character encoding of the page.</strong> If you get the character encoding wrong than your output will be messed up.</p>
<p>People usually use some rudimentary technique to detect the encoding. They either use the charset from... | 28 | 2009-09-30T00:41:59Z | 1,495,631 | <p>Use the <a href="http://pypi.python.org/pypi/chardet">Universal Encoding Detector</a>:</p>
<pre><code>>>> import chardet
>>> chardet.detect(urlread("http://google.cn/"))
{'encoding': 'GB2312', 'confidence': 0.99}
</code></pre>
<p>The other option would be to just use wget:</p>
<pre><code> impor... | 13 | 2009-09-30T00:44:15Z | [
"python",
"character-encoding",
"screen-scraping",
"urllib2",
"urllib"
] |
How to download any(!) webpage with correct charset in python? | 1,495,627 | <h1>Problem</h1>
<p><strong>When screen-scraping a webpage using python one has to know the character encoding of the page.</strong> If you get the character encoding wrong than your output will be messed up.</p>
<p>People usually use some rudimentary technique to detect the encoding. They either use the charset from... | 28 | 2009-09-30T00:41:59Z | 1,495,675 | <p>When you download a file with urllib or urllib2, you can find out whether a charset header was transmitted:</p>
<pre><code>fp = urllib2.urlopen(request)
charset = fp.headers.getparam('charset')
</code></pre>
<p>You can use BeautifulSoup to locate a meta element in the HTML:</p>
<pre><code>soup = BeatifulSoup.Beau... | 32 | 2009-09-30T01:04:36Z | [
"python",
"character-encoding",
"screen-scraping",
"urllib2",
"urllib"
] |
How to download any(!) webpage with correct charset in python? | 1,495,627 | <h1>Problem</h1>
<p><strong>When screen-scraping a webpage using python one has to know the character encoding of the page.</strong> If you get the character encoding wrong than your output will be messed up.</p>
<p>People usually use some rudimentary technique to detect the encoding. They either use the charset from... | 28 | 2009-09-30T00:41:59Z | 1,499,920 | <p>instead of trying to get a page then figuring out the charset the browser would use, why not just use a browser to fetch the page and check what charset it uses.. </p>
<pre><code>from win32com.client import DispatchWithEvents
import threading
stopEvent=threading.Event()
class EventHandler(object):
def OnDown... | 1 | 2009-09-30T18:37:16Z | [
"python",
"character-encoding",
"screen-scraping",
"urllib2",
"urllib"
] |
How to download any(!) webpage with correct charset in python? | 1,495,627 | <h1>Problem</h1>
<p><strong>When screen-scraping a webpage using python one has to know the character encoding of the page.</strong> If you get the character encoding wrong than your output will be messed up.</p>
<p>People usually use some rudimentary technique to detect the encoding. They either use the charset from... | 28 | 2009-09-30T00:41:59Z | 1,544,836 | <p>It seems like you need a hybrid of the answers presented:</p>
<ol>
<li>Fetch the page using urllib</li>
<li>Find <code><meta></code> tags using beautiful soup or other method</li>
<li>If no meta tags exist, check the headers returned by urllib</li>
<li>If that still doesn't give you an answer, use the univers... | 3 | 2009-10-09T16:34:22Z | [
"python",
"character-encoding",
"screen-scraping",
"urllib2",
"urllib"
] |
How to download any(!) webpage with correct charset in python? | 1,495,627 | <h1>Problem</h1>
<p><strong>When screen-scraping a webpage using python one has to know the character encoding of the page.</strong> If you get the character encoding wrong than your output will be messed up.</p>
<p>People usually use some rudimentary technique to detect the encoding. They either use the charset from... | 28 | 2009-09-30T00:41:59Z | 9,756,911 | <p>BeautifulSoup dose this with UnicodeDammit : <a href="http://www.crummy.com/software/BeautifulSoup/bs3/documentation.html#Beautiful%20Soup%20Gives%20You%20Unicode,%20Dammit" rel="nofollow">Unicode, Dammit</a></p>
| 1 | 2012-03-18T08:05:33Z | [
"python",
"character-encoding",
"screen-scraping",
"urllib2",
"urllib"
] |
How to download any(!) webpage with correct charset in python? | 1,495,627 | <h1>Problem</h1>
<p><strong>When screen-scraping a webpage using python one has to know the character encoding of the page.</strong> If you get the character encoding wrong than your output will be messed up.</p>
<p>People usually use some rudimentary technique to detect the encoding. They either use the charset from... | 28 | 2009-09-30T00:41:59Z | 15,481,982 | <p>I would use <a href="https://code.google.com/p/html5lib/" rel="nofollow">html5lib</a> for this.</p>
| 3 | 2013-03-18T16:31:10Z | [
"python",
"character-encoding",
"screen-scraping",
"urllib2",
"urllib"
] |
How to define a class in Python | 1,495,666 | <p>Quite simple, I'm learning python and I can't find a reference that tells me how to write the following:</p>
<pre><code>public class Team {
private String name;
private String logo;
private int members;
public Team(){}
// getters/setters
}
</code></pre>
<p>Later:</p>
<pre><code>Team t... | 40 | 2009-09-30T01:02:16Z | 1,495,680 | <pre><code>class Team:
def __init__(self):
self.name = None
self.logo = None
self.members = 0
</code></pre>
<p>In Python, you typically don't write getters and setters, unless you really have a non-trivial implementation for them (at which point you use property descriptors).</p>
| 38 | 2009-09-30T01:06:33Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.