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 |
|---|---|---|---|---|---|---|---|---|---|
Storing Python scripts on a webserver | 905,902 | <p>Following on my previous question, if I have some hosting how can I put a python script on their that I can then run from there? Do I need to do something special to run it/install something?
EDIT-Clarification-I would like to be able to upload the script which does stuff on the internet-no data is stored on my com... | 0 | 2009-05-25T08:42:53Z | 905,924 | <p>Usually python is already installed, but it depends on your hoster. Ask them.</p>
| 0 | 2009-05-25T08:49:29Z | [
"python",
"hosting"
] |
Storing Python scripts on a webserver | 905,902 | <p>Following on my previous question, if I have some hosting how can I put a python script on their that I can then run from there? Do I need to do something special to run it/install something?
EDIT-Clarification-I would like to be able to upload the script which does stuff on the internet-no data is stored on my com... | 0 | 2009-05-25T08:42:53Z | 906,016 | <p>You have to ensure your hoster system supports Python.</p>
<p>You can ask them about that.</p>
<p>To run the script once it is there, you can act in several ways, depending on what you want to do.</p>
<p>You can have your server side language to invoke it (i.e. from the backend of a web page), or if you have a sh... | 1 | 2009-05-25T09:15:32Z | [
"python",
"hosting"
] |
Python Twisted protocol unregistering? | 906,496 | <p>I've came up with problem regarding unregistering protocols from reactor in twisted while application is running. </p>
<p>I use hardware modems connected to PC by USB and that's why this scenario is so important for my solution.
Has anyone an idea how to do it?</p>
<p>Greets,
Chris</p>
| 6 | 2009-05-25T12:12:09Z | 907,370 | <p>When you first call <code>reactor.listen</code> on your protocol factory, it returns an object that implements <code>IListeningPort</code>, see <a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.interfaces.IListeningPort.html">http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.interfac... | 6 | 2009-05-25T16:47:28Z | [
"python",
"twisted",
"protocols"
] |
show lyrics on ubuntu | 906,509 | <p>I'm writing a little script for Ubuntu.
My intention is to call rhythmbox lyrics plug-in with a global short-cut (configuring gnome) .
I can call it from rhythmbox python console, but I don't know how to import rhythmbox built-in modules (eg. rhythmdb).<br />
Any ideas?</p>
| 0 | 2009-05-25T12:16:07Z | 1,450,802 | <p>You can't import rhythmbox "built-in" modules from a standard python console. </p>
<p>As far as I know they aren't real modules, they are just objects from the rhythmbox process exposed to plugins. So you can access them only if you are running your script from the rhythmbox process.</p>
| 1 | 2009-09-20T11:12:17Z | [
"python",
"plugins",
"gnome",
"rhythmbox"
] |
show lyrics on ubuntu | 906,509 | <p>I'm writing a little script for Ubuntu.
My intention is to call rhythmbox lyrics plug-in with a global short-cut (configuring gnome) .
I can call it from rhythmbox python console, but I don't know how to import rhythmbox built-in modules (eg. rhythmdb).<br />
Any ideas?</p>
| 0 | 2009-05-25T12:16:07Z | 4,594,514 | <p>in this case i guess you'll have to write the whole plugin yourself and , then listen to dbus for change of songs in rhythmbox , to detect which song is being played .</p>
| 0 | 2011-01-04T14:10:41Z | [
"python",
"plugins",
"gnome",
"rhythmbox"
] |
How do I inspect the scope of a function where Python raises an exception? | 906,649 | <p>I've recently discovered the very useful '-i' flag to Python</p>
<pre>
-i : inspect interactively after running script, (also PYTHONINSPECT=x)
and force prompts, even if stdin does not appear to be a terminal
</pre>
<p>this is great for inspecting objects in the global scope, but what happens if the e... | 1 | 2009-05-25T12:58:43Z | 906,665 | <p>use ipython: <a href="http://mail.scipy.org/pipermail/ipython-user/2007-January/003985.html" rel="nofollow">http://mail.scipy.org/pipermail/ipython-user/2007-January/003985.html</a></p>
<p>Usage example:</p>
<pre><code>from IPython.Debugger import Tracer; debug_here = Tracer()
#... later in your code
debug_here()... | 4 | 2009-05-25T13:02:13Z | [
"python",
"debugging"
] |
How do I inspect the scope of a function where Python raises an exception? | 906,649 | <p>I've recently discovered the very useful '-i' flag to Python</p>
<pre>
-i : inspect interactively after running script, (also PYTHONINSPECT=x)
and force prompts, even if stdin does not appear to be a terminal
</pre>
<p>this is great for inspecting objects in the global scope, but what happens if the e... | 1 | 2009-05-25T12:58:43Z | 906,892 | <p>In ipython, you can inspect variables at the location where your code crashed without having to modify it:</p>
<pre><code>>>> %pdb on
>>> %run my_script.py
</code></pre>
| 5 | 2009-05-25T14:16:25Z | [
"python",
"debugging"
] |
How do I inspect the scope of a function where Python raises an exception? | 906,649 | <p>I've recently discovered the very useful '-i' flag to Python</p>
<pre>
-i : inspect interactively after running script, (also PYTHONINSPECT=x)
and force prompts, even if stdin does not appear to be a terminal
</pre>
<p>this is great for inspecting objects in the global scope, but what happens if the e... | 1 | 2009-05-25T12:58:43Z | 931,275 | <p>At the interactive prompt, immediately type</p>
<pre><code>>>> import pdb
>>> pdb.pm()
</code></pre>
<p>pdb.pm() is the "post-mortem" debugger. It will put you at the scope where the exception was raised, and then you can use the usual pdb commands.</p>
<p>I use this <em>all the time</em>. It's ... | 5 | 2009-05-31T04:37:45Z | [
"python",
"debugging"
] |
Alternative to innerhtml that includes header? | 906,660 | <p>I'm trying to extract data from the following page:</p>
<p><a href="http://www.bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServlet?param1=&param2=&param3=&param4=&param5=2009-04-22&param6=37#" rel="nofollow">http://www.bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServlet?param1=&... | 0 | 2009-05-25T13:00:59Z | 906,689 | <p><strong>Untested:</strong> Did you try looking at what <a href="http://msdn.microsoft.com/en-us/library/aa752604%28VS.85%29.aspx" rel="nofollow">Document.scripts</a> contains?</p>
<p><strong>UPDATE:</strong></p>
<p>For some reason, I am having immense difficulty getting this to work using the Windows Scripting Hos... | 1 | 2009-05-25T13:10:39Z | [
"python",
"html",
"css",
"dom",
"com"
] |
Alternative to innerhtml that includes header? | 906,660 | <p>I'm trying to extract data from the following page:</p>
<p><a href="http://www.bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServlet?param1=&param2=&param3=&param4=&param5=2009-04-22&param6=37#" rel="nofollow">http://www.bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServlet?param1=&... | 0 | 2009-05-25T13:00:59Z | 906,695 | <p>fetch the source of that page using ajax, and parse the response text like XML using jquery. It should be simple enought to get the text of the first tag you encounter inside the </p>
<p>I'm out of touch with jquery, or I would have posted code examples.</p>
<p>EDIT: I assume you are talking about fetching the cs... | 0 | 2009-05-25T13:12:16Z | [
"python",
"html",
"css",
"dom",
"com"
] |
Alternative to innerhtml that includes header? | 906,660 | <p>I'm trying to extract data from the following page:</p>
<p><a href="http://www.bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServlet?param1=&param2=&param3=&param4=&param5=2009-04-22&param6=37#" rel="nofollow">http://www.bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServlet?param1=&... | 0 | 2009-05-25T13:00:59Z | 906,852 | <p>If this is just a one off script then exctracting this csv data is as simple as this:</p>
<pre><code>import urllib2
response = urllib2.urlopen('http://www.bmreports.com/foo?bar?')
html = response.read()
csv = data.split('gs_csv=')[1].split('</SCRIPT>')[0]
#process csv data here
</code></pre>
| 0 | 2009-05-25T14:02:46Z | [
"python",
"html",
"css",
"dom",
"com"
] |
Alternative to innerhtml that includes header? | 906,660 | <p>I'm trying to extract data from the following page:</p>
<p><a href="http://www.bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServlet?param1=&param2=&param3=&param4=&param5=2009-04-22&param6=37#" rel="nofollow">http://www.bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServlet?param1=&... | 0 | 2009-05-25T13:00:59Z | 907,209 | <p>Thanks to Sinan (this is mostly his solution transcribed into Python).</p>
<p>import win32com.client </p>
<p>import time import os </p>
<p>import os.path</p>
<p>ie = Dispatch("InternetExplorer.Application") ie.Visible=False </p>
<p>ie.Navigate("http://www.bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServl... | 0 | 2009-05-25T15:47:11Z | [
"python",
"html",
"css",
"dom",
"com"
] |
exec statement with/without prior compile | 906,920 | <p>These weekend I've been tearing down to pieces Michele Simionato's <a href="http://pypi.python.org/pypi/decorator/3.0.1" rel="nofollow">decorator module</a>, that builds signature-preserving decorators. At the heart of it all there is a dynamically generated function, which works something similar to this...</p>
<p... | 1 | 2009-05-25T14:26:02Z | 907,127 | <p>There are a few differences that I see. Firstly, <a href="http://www.python.org/doc/2.6.2/library/functions.html#compile" rel="nofollow"><code>compile</code></a> has slightly better semantics in the face of syntax errors than <a href="http://www.python.org/doc/2.6.2/reference/simple%5Fstmts.html#the-exec-statement" ... | 2 | 2009-05-25T15:19:16Z | [
"python",
"compilation",
"eval",
"exec"
] |
exec statement with/without prior compile | 906,920 | <p>These weekend I've been tearing down to pieces Michele Simionato's <a href="http://pypi.python.org/pypi/decorator/3.0.1" rel="nofollow">decorator module</a>, that builds signature-preserving decorators. At the heart of it all there is a dynamically generated function, which works something similar to this...</p>
<p... | 1 | 2009-05-25T14:26:02Z | 907,818 | <p>compile() allows you to control the code object created and its name and source, while exec is not so flexible. it is also worth doing so that others, when reading your code, will learn they are separate steps and have this in mind later, when they need to exec the same code more than once (where compile() once, exe... | 2 | 2009-05-25T19:37:26Z | [
"python",
"compilation",
"eval",
"exec"
] |
A neat way of extending a class attribute in subclasses | 907,324 | <p>Let's say I have the following class</p>
<pre><code>class Parent(object):
Options = {
'option1': 'value1',
'option2': 'value2'
}
</code></pre>
<p>And a subclass called Child</p>
<pre><code>class Child(Parent):
Options = Parent.Options.copy()
Options.update({
'option2': 'value... | 15 | 2009-05-25T16:28:54Z | 907,335 | <p>Why not just use class attributes?</p>
<pre><code>class Parent(object):
option1 = 'value1'
option2 = 'value2'
class Child(Parent):
option2 = 'value2'
option3 = 'value3'
</code></pre>
| 4 | 2009-05-25T16:38:01Z | [
"python"
] |
A neat way of extending a class attribute in subclasses | 907,324 | <p>Let's say I have the following class</p>
<pre><code>class Parent(object):
Options = {
'option1': 'value1',
'option2': 'value2'
}
</code></pre>
<p>And a subclass called Child</p>
<pre><code>class Child(Parent):
Options = Parent.Options.copy()
Options.update({
'option2': 'value... | 15 | 2009-05-25T16:28:54Z | 907,338 | <pre><code>class ParentOptions:
option1 = 'value1'
option2 = 'value2'
class ChildOptions(ParentOptions):
option2 = 'value2'
option3 = 'value3'
class Parent(object):
options = ParentOptions()
class Child(Parent):
options = ChildOptions()
</code></pre>
| 2 | 2009-05-25T16:38:38Z | [
"python"
] |
A neat way of extending a class attribute in subclasses | 907,324 | <p>Let's say I have the following class</p>
<pre><code>class Parent(object):
Options = {
'option1': 'value1',
'option2': 'value2'
}
</code></pre>
<p>And a subclass called Child</p>
<pre><code>class Child(Parent):
Options = Parent.Options.copy()
Options.update({
'option2': 'value... | 15 | 2009-05-25T16:28:54Z | 907,423 | <p>One way would be to use keyword arguments to dict to specify additional keys:</p>
<pre><code>Parent.options = dict(
option1='value1',
option2='value2',
)
Child.options = dict(Parent.options,
option2='value2a',
option3='value3',
)
</code></pre>
<p>If you want to get fancier, then using the descript... | 8 | 2009-05-25T17:05:43Z | [
"python"
] |
A neat way of extending a class attribute in subclasses | 907,324 | <p>Let's say I have the following class</p>
<pre><code>class Parent(object):
Options = {
'option1': 'value1',
'option2': 'value2'
}
</code></pre>
<p>And a subclass called Child</p>
<pre><code>class Child(Parent):
Options = Parent.Options.copy()
Options.update({
'option2': 'value... | 15 | 2009-05-25T16:28:54Z | 907,476 | <p>Semantically equivalent to your code but arguably neater:</p>
<pre><code>class Child(Parent):
Options = dict(Parent.Options,
option2='value2',
option3='value3')
</code></pre>
<p>Remember, "life is better without braces", and by calling <code>dict</code> explicitly you can often avoid braces (and ext... | 19 | 2009-05-25T17:25:19Z | [
"python"
] |
A neat way of extending a class attribute in subclasses | 907,324 | <p>Let's say I have the following class</p>
<pre><code>class Parent(object):
Options = {
'option1': 'value1',
'option2': 'value2'
}
</code></pre>
<p>And a subclass called Child</p>
<pre><code>class Child(Parent):
Options = Parent.Options.copy()
Options.update({
'option2': 'value... | 15 | 2009-05-25T16:28:54Z | 907,481 | <p>After thinking more about it, and thanks to @SpliFF suggestion this is what I came up with:</p>
<pre><code>class Parent(object):
class Options:
option1 = 'value1'
option2 = 'value2'
class Child(Parent):
class Options(Parent.Options):
option2 = 'value2'
option3 = 'value3'
</... | 6 | 2009-05-25T17:26:22Z | [
"python"
] |
A neat way of extending a class attribute in subclasses | 907,324 | <p>Let's say I have the following class</p>
<pre><code>class Parent(object):
Options = {
'option1': 'value1',
'option2': 'value2'
}
</code></pre>
<p>And a subclass called Child</p>
<pre><code>class Child(Parent):
Options = Parent.Options.copy()
Options.update({
'option2': 'value... | 15 | 2009-05-25T16:28:54Z | 3,219,533 | <p>Here is a way using a metaclass</p>
<pre><code>class OptionMeta(type):
@property
def options(self):
result = {}
for d in self.__mro__[::-1]:
result.update(getattr(d,'_options',{}))
return result
class Parent(object):
__metaclass__ = OptionMeta
_options = dict(
... | 2 | 2010-07-10T14:23:27Z | [
"python"
] |
European date input in Django Admin | 907,351 | <p>Django has a DATE_FORMAT and a DATE_TIME_FORMAT options that allow us to choose which format to use when viewing dates, but doesn't apparently let me change the input format for the date when editing or adding in the Django Admin.</p>
<p>The default for the admin is: YYYY-MM-DD</p>
<p>But would be awesome to use: ... | 6 | 2009-05-25T16:42:52Z | 909,154 | <p>Looks like this is <a href="http://code.djangoproject.com/ticket/6483" rel="nofollow">not yet supported</a>, as I understand it, so yes, you'll have to do some custom work for now.</p>
| 1 | 2009-05-26T06:19:51Z | [
"python",
"django",
"date",
"django-admin"
] |
European date input in Django Admin | 907,351 | <p>Django has a DATE_FORMAT and a DATE_TIME_FORMAT options that allow us to choose which format to use when viewing dates, but doesn't apparently let me change the input format for the date when editing or adding in the Django Admin.</p>
<p>The default for the admin is: YYYY-MM-DD</p>
<p>But would be awesome to use: ... | 6 | 2009-05-25T16:42:52Z | 912,041 | <p>You have to do this yourself for now, but it's quite easy to do with a custom form field class that sets the input_formats argument of DateField. This should do it:</p>
<pre><code>class MyDateField(forms.DateField):
def __init__(self, *args, **kwargs):
kwargs.setdefault('input_formats', ("%d-%m-%Y",))
su... | 2 | 2009-05-26T18:28:37Z | [
"python",
"django",
"date",
"django-admin"
] |
European date input in Django Admin | 907,351 | <p>Django has a DATE_FORMAT and a DATE_TIME_FORMAT options that allow us to choose which format to use when viewing dates, but doesn't apparently let me change the input format for the date when editing or adding in the Django Admin.</p>
<p>The default for the admin is: YYYY-MM-DD</p>
<p>But would be awesome to use: ... | 6 | 2009-05-25T16:42:52Z | 1,437,608 | <p>Based on this idea I made new db.fields class EuDateField:</p>
<p>mydbfields.py</p>
<pre><code>from django import forms
from django.forms.fields import DEFAULT_DATE_INPUT_FORMATS
from django.db import models
class EuDateFormField(forms.DateField):
def __init__(self, *args, **kwargs):
kwargs.update({'i... | 2 | 2009-09-17T08:59:25Z | [
"python",
"django",
"date",
"django-admin"
] |
European date input in Django Admin | 907,351 | <p>Django has a DATE_FORMAT and a DATE_TIME_FORMAT options that allow us to choose which format to use when viewing dates, but doesn't apparently let me change the input format for the date when editing or adding in the Django Admin.</p>
<p>The default for the admin is: YYYY-MM-DD</p>
<p>But would be awesome to use: ... | 6 | 2009-05-25T16:42:52Z | 8,604,000 | <p>I've modified settings so that it disables l10n and set date format explicite:</p>
<pre><code>USE_L10N = False
DATE_FORMAT = 'd-m-Y'
DATETIME_FORMAT = 'd-m-Y H:i'
</code></pre>
<p>You can set DATE_INPUT_FORMATS as well. </p>
| 2 | 2011-12-22T12:42:20Z | [
"python",
"django",
"date",
"django-admin"
] |
European date input in Django Admin | 907,351 | <p>Django has a DATE_FORMAT and a DATE_TIME_FORMAT options that allow us to choose which format to use when viewing dates, but doesn't apparently let me change the input format for the date when editing or adding in the Django Admin.</p>
<p>The default for the admin is: YYYY-MM-DD</p>
<p>But would be awesome to use: ... | 6 | 2009-05-25T16:42:52Z | 8,860,276 | <p>There is an official way to do this now since the closing of <a href="https://code.djangoproject.com/ticket/6483">Django ticket 6483</a> & release of Django 1.2.</p>
<p>If you have <a href="https://docs.djangoproject.com/en/1.3/ref/settings/#std%3asetting-USE_L10N"><code>USE_L10N</code></a> set to <code>False</... | 8 | 2012-01-14T05:03:44Z | [
"python",
"django",
"date",
"django-admin"
] |
European date input in Django Admin | 907,351 | <p>Django has a DATE_FORMAT and a DATE_TIME_FORMAT options that allow us to choose which format to use when viewing dates, but doesn't apparently let me change the input format for the date when editing or adding in the Django Admin.</p>
<p>The default for the admin is: YYYY-MM-DD</p>
<p>But would be awesome to use: ... | 6 | 2009-05-25T16:42:52Z | 16,724,725 | <p>just beware not to write it as a string but as a tuple.
eg:</p>
<pre><code>DATE_INPUT_FORMATS = ('%d.%m.%Y',)
</code></pre>
<p>if you want to have only one valid way of writing date in a form.</p>
| 0 | 2013-05-23T22:10:38Z | [
"python",
"django",
"date",
"django-admin"
] |
Making a Python script executable chmod755? | 907,579 | <p>My hosting provider says my python script must be made to be executable(chmod755). What does this mean & how do I do it?</p>
<p>Cheers!</p>
| 4 | 2009-05-25T18:05:23Z | 907,585 | <p>on the shell (such as bash), just type</p>
<pre><code>chmod 755 file.py
</code></pre>
<p>to make it executable. You can use</p>
<pre><code>ls -l file.py
</code></pre>
<p>to verify the execution permission is set (the "x" in "rwxr-xr-x")</p>
| 0 | 2009-05-25T18:06:57Z | [
"python",
"hosting"
] |
Making a Python script executable chmod755? | 907,579 | <p>My hosting provider says my python script must be made to be executable(chmod755). What does this mean & how do I do it?</p>
<p>Cheers!</p>
| 4 | 2009-05-25T18:05:23Z | 907,591 | <p>Unix-like systems have "file modes" that say who can read/write/execute a file. The mode 755 means owner can read/write/execute, and everyone else can read/execute but not write. To make your Python script have this mode, you type</p>
<pre><code>chmod 0755 script.py
</code></pre>
<p>You also need a shebang like</p... | 5 | 2009-05-25T18:08:55Z | [
"python",
"hosting"
] |
Making a Python script executable chmod755? | 907,579 | <p>My hosting provider says my python script must be made to be executable(chmod755). What does this mean & how do I do it?</p>
<p>Cheers!</p>
| 4 | 2009-05-25T18:05:23Z | 907,595 | <p>If you have ssh access to your web space, connect and issue</p>
<pre><code>chmod 755 nameofyourscript.py
</code></pre>
<p>If you do not have ssh access but rather connect by FTP, check your FTP application to see whether it supports setting the permissions.</p>
<p>As to the meaning of 755:</p>
<ul>
<li>first dig... | 5 | 2009-05-25T18:09:51Z | [
"python",
"hosting"
] |
Making a Python script executable chmod755? | 907,579 | <p>My hosting provider says my python script must be made to be executable(chmod755). What does this mean & how do I do it?</p>
<p>Cheers!</p>
| 4 | 2009-05-25T18:05:23Z | 907,605 | <p>In addition to the other fine answers here, you should be aware that most FTP clients have a <code>chmod</code> command to allow you to set permissions on files at the server. You may not need this if permissions come across properly, but there's a good chance they do not.</p>
| 0 | 2009-05-25T18:13:18Z | [
"python",
"hosting"
] |
Making a Python script executable chmod755? | 907,579 | <p>My hosting provider says my python script must be made to be executable(chmod755). What does this mean & how do I do it?</p>
<p>Cheers!</p>
| 4 | 2009-05-25T18:05:23Z | 907,625 | <p>It means, that somebody (the user, a group or everybody) has the right so execute (or read or write) the script (or a file in general). </p>
<p>The permissions are expressed in different ways:</p>
<pre><code>$ chmod +x file.py # makes it executable by anyone
$ chmod +w file.py # makes it writeabel by anyone
$ chmo... | 1 | 2009-05-25T18:20:19Z | [
"python",
"hosting"
] |
Gather all Python modules used into one folder? | 907,660 | <p>I don't think this has been asked before-I have a folder that has lots of different .py files. The script I've made only uses some-but some call others & I don't know all the ones being used. Is there a program that will get everything needed to make that script run into one folder?</p>
<p>Cheers!</p>
| 6 | 2009-05-25T18:31:23Z | 907,683 | <p><a href="http://wiki.python.org/moin/Freeze" rel="nofollow">Freeze</a> does pretty close to what you describe. It does an extra step of generating C files to create a stand-alone executable, but you could use the log output it produces to get the list of modules your script uses. From there it's a simple matter to c... | 0 | 2009-05-25T18:41:05Z | [
"python"
] |
Gather all Python modules used into one folder? | 907,660 | <p>I don't think this has been asked before-I have a folder that has lots of different .py files. The script I've made only uses some-but some call others & I don't know all the ones being used. Is there a program that will get everything needed to make that script run into one folder?</p>
<p>Cheers!</p>
| 6 | 2009-05-25T18:31:23Z | 907,736 | <pre><code># zipmod.py - make a zip archive consisting of Python modules and their dependencies as reported by modulefinder
# To use: cd to the directory containing your Python module tree and type
# $ python zipmod.py archive.zip mod1.py mod2.py ...
# Only modules in the current working directory and its subdirectorie... | 6 | 2009-05-25T19:00:04Z | [
"python"
] |
Gather all Python modules used into one folder? | 907,660 | <p>I don't think this has been asked before-I have a folder that has lots of different .py files. The script I've made only uses some-but some call others & I don't know all the ones being used. Is there a program that will get everything needed to make that script run into one folder?</p>
<p>Cheers!</p>
| 6 | 2009-05-25T18:31:23Z | 907,744 | <p>Use the <code>modulefinder</code> module in the standard library, see e.g. <a href="http://docs.python.org/library/modulefinder.html" rel="nofollow">http://docs.python.org/library/modulefinder.html</a></p>
| 6 | 2009-05-25T19:04:03Z | [
"python"
] |
How to let Django's generic view use a form with initial values? | 907,858 | <p>I know how to set initial values to a form from the view. But how do I go about letting a generic view set initial values to a form? I can write a wrapper view for the generic view, but I still have no access to the form object instantiation.</p>
<p>The specific goal I'm trying to achieve is to have a user create a... | 2 | 2009-05-25T19:51:55Z | 908,038 | <p>Unfortunately, you cannot achieve this behavior through Django's <code>create_object</code> generic view; you will have to write your own. However, this is rather simple.</p>
<p>To start off, you must create a new form class, like this:</p>
<pre><code>from django import forms
class MyForm(forms.ModelForm):
cl... | 4 | 2009-05-25T20:59:36Z | [
"python",
"django",
"forms",
"user"
] |
How to let Django's generic view use a form with initial values? | 907,858 | <p>I know how to set initial values to a form from the view. But how do I go about letting a generic view set initial values to a form? I can write a wrapper view for the generic view, but I still have no access to the form object instantiation.</p>
<p>The specific goal I'm trying to achieve is to have a user create a... | 2 | 2009-05-25T19:51:55Z | 912,099 | <p>You could do this in a generic view wrapper by dynamically constructing a form class and passing it to the generic view, but that cure is probably worse than the disease. Just write your own view, and wait eagerly for <a href="http://code.djangoproject.com/ticket/6735" rel="nofollow">this</a> to land.</p>
| 3 | 2009-05-26T18:42:41Z | [
"python",
"django",
"forms",
"user"
] |
How to let Django's generic view use a form with initial values? | 907,858 | <p>I know how to set initial values to a form from the view. But how do I go about letting a generic view set initial values to a form? I can write a wrapper view for the generic view, but I still have no access to the form object instantiation.</p>
<p>The specific goal I'm trying to achieve is to have a user create a... | 2 | 2009-05-25T19:51:55Z | 8,945,139 | <p>If you want all the features of the generic view then you can just create a new generic view using the original as a template.</p>
<p>Eg:</p>
<pre><code>def create_object_with_initial(request, model=None, template_name=None,
template_loader=loader, extra_context=None, post_save_redirect=None,
login_require... | 0 | 2012-01-20T17:07:26Z | [
"python",
"django",
"forms",
"user"
] |
Generating file to download with Django | 908,258 | <p>Is it possible to make a zip archive and offer it to download, but still not save a file to the hard drive?</p>
| 76 | 2009-05-25T22:26:01Z | 908,266 | <p>Yes, you can use the <a href="http://www.python.org/doc/2.5.2/lib/zipfile-objects.html">zipfile module</a>, <a href="http://www.python.org/doc/2.5.2/lib/module-zlib.html">zlib module</a> or other <a href="http://www.python.org/doc/2.5.2/lib/archiving.html">compression modules</a> to create a zip archive in memory. ... | 8 | 2009-05-25T22:29:21Z | [
"python",
"django"
] |
Generating file to download with Django | 908,258 | <p>Is it possible to make a zip archive and offer it to download, but still not save a file to the hard drive?</p>
| 76 | 2009-05-25T22:26:01Z | 908,293 | <p>You'll be happier creating a temporary file. This saves a lot of memory. When you have more than one or two users concurrently, you'll find the memory saving is very, very important.</p>
<p>You can, however, write to a <a href="http://docs.python.org/library/stringio.html">StringIO</a> object.</p>
<pre><code>>... | 24 | 2009-05-25T22:42:00Z | [
"python",
"django"
] |
Generating file to download with Django | 908,258 | <p>Is it possible to make a zip archive and offer it to download, but still not save a file to the hard drive?</p>
| 76 | 2009-05-25T22:26:01Z | 909,088 | <p>To trigger a download you need to set <code>Content-Disposition</code> header:</p>
<pre><code>from django.http import HttpResponse
from wsgiref.util import FileWrapper
# generate the file
response = HttpResponse(FileWrapper(myfile.getvalue()), content_type='application/zip')
response['Content-Disposition'] = 'atta... | 95 | 2009-05-26T05:53:30Z | [
"python",
"django"
] |
Generating file to download with Django | 908,258 | <p>Is it possible to make a zip archive and offer it to download, but still not save a file to the hard drive?</p>
| 76 | 2009-05-25T22:26:01Z | 5,905,850 | <p>There is a code example at <a href="http://djangosnippets.org/snippets/365/">http://djangosnippets.org/snippets/365/</a></p>
| 5 | 2011-05-06T01:14:46Z | [
"python",
"django"
] |
Generating file to download with Django | 908,258 | <p>Is it possible to make a zip archive and offer it to download, but still not save a file to the hard drive?</p>
| 76 | 2009-05-25T22:26:01Z | 6,922,996 | <h3>models.py</h3>
<pre><code>from django.db import models
class PageHeader(models.Model):
image = models.ImageField(upload_to='uploads')
</code></pre>
<h3>views.py</h3>
<pre><code>from django.http import HttpResponse
from StringIO import StringIO
from models import *
import os, mimetypes, urllib
def random_he... | 5 | 2011-08-03T07:24:04Z | [
"python",
"django"
] |
Generating file to download with Django | 908,258 | <p>Is it possible to make a zip archive and offer it to download, but still not save a file to the hard drive?</p>
| 76 | 2009-05-25T22:26:01Z | 7,353,876 | <p>Why not make a tar file instead? Like so:</p>
<pre><code>def downloadLogs(req, dir):
response = HttpResponse(mimetype='application/x-gzip')
response['Content-Disposition'] = 'attachment; filename=download.tar.gz'
tarred = tarfile.open(fileobj=response, mode='w:gz')
tarred.add(dir)
tarred.close()... | 6 | 2011-09-08T20:12:00Z | [
"python",
"django"
] |
Generating file to download with Django | 908,258 | <p>Is it possible to make a zip archive and offer it to download, but still not save a file to the hard drive?</p>
| 76 | 2009-05-25T22:26:01Z | 38,659,790 | <pre><code>def download_zip(request,file_name):
filePath = '<path>/'+file_name
fsock = open(file_name_with_path,"rb")
response = HttpResponse(fsock, content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename=myfile.zip'
return response
</code></pre>
<p>You can rep... | 3 | 2016-07-29T13:10:32Z | [
"python",
"django"
] |
Secure plugin system for python application | 908,285 | <p>I have an application written in python. I created a plugin system for the application that uses egg files. Egg files contain compiled python files and can be easily decompiled and used to hack the application. Is there a way to secure this system? I'd like to use digital signature for this - sign these egg files an... | 2 | 2009-05-25T22:39:48Z | 908,307 | <p>Maybe some crypto library like this <a href="http://chandlerproject.org/Projects/MeTooCrypto" rel="nofollow">http://chandlerproject.org/Projects/MeTooCrypto</a> helps to build an ad-hoc solution. Example usage: <a href="http://tdilshod.livejournal.com/38040.html" rel="nofollow">http://tdilshod.livejournal.com/38040.... | 1 | 2009-05-25T22:49:00Z | [
"python",
"plugins",
"signing"
] |
Secure plugin system for python application | 908,285 | <p>I have an application written in python. I created a plugin system for the application that uses egg files. Egg files contain compiled python files and can be easily decompiled and used to hack the application. Is there a way to secure this system? I'd like to use digital signature for this - sign these egg files an... | 2 | 2009-05-25T22:39:48Z | 908,846 | <blockquote>
<p>Is there a way to secure this system?</p>
</blockquote>
<p>The answer is "that depends".</p>
<p>The two questions you should ask is "what are people supposed to be able to do" and "what are people able to do (for a given implementation)". If there exists an implementation where the latter is a subs... | 3 | 2009-05-26T03:51:12Z | [
"python",
"plugins",
"signing"
] |
How to write binary data in stdout in python 3? | 908,331 | <p>In python 2.x I could do this:</p>
<pre><code>import sys, array
a = array.array('B', range(100))
a.tofile(sys.stdout)</code></pre>
<p>Now however, I get a <code>TypeError: can't write bytes to text stream</code>. Is there some secret encoding that I should use?</p>
| 32 | 2009-05-25T23:04:05Z | 908,339 | <pre><code>import os
os.write(1, a.tostring())
</code></pre>
<p>or, <code>os.write(sys.stdout.fileno(), â¦)</code> if that's more readable than <code>1</code> for you.</p>
| 5 | 2009-05-25T23:11:15Z | [
"python",
"python-3.x"
] |
How to write binary data in stdout in python 3? | 908,331 | <p>In python 2.x I could do this:</p>
<pre><code>import sys, array
a = array.array('B', range(100))
a.tofile(sys.stdout)</code></pre>
<p>Now however, I get a <code>TypeError: can't write bytes to text stream</code>. Is there some secret encoding that I should use?</p>
| 32 | 2009-05-25T23:04:05Z | 908,440 | <p>A better way:</p>
<pre><code>import sys
sys.stdout.buffer.write(b"some binary data")
</code></pre>
| 51 | 2009-05-26T00:09:34Z | [
"python",
"python-3.x"
] |
How to write binary data in stdout in python 3? | 908,331 | <p>In python 2.x I could do this:</p>
<pre><code>import sys, array
a = array.array('B', range(100))
a.tofile(sys.stdout)</code></pre>
<p>Now however, I get a <code>TypeError: can't write bytes to text stream</code>. Is there some secret encoding that I should use?</p>
| 32 | 2009-05-25T23:04:05Z | 29,606,070 | <p>In case you would like to specify an encoding in python3 you can still use the bytes command like below:</p>
<pre><code>import os
os.write(1,bytes('Your string to Stdout','UTF-8'))
</code></pre>
<p>where 1 is the corresponding usual number for stdout --> sys.stdout.fileno()</p>
<p>Otherwise if you don't care of t... | 0 | 2015-04-13T13:05:25Z | [
"python",
"python-3.x"
] |
Python Getting date online? | 908,550 | <p>How can I get the current date, month & year online using Python? Thanks!</p>
<p>EDIT-By this I mean, rather than getting it from the computer's date-visit a website & get it, so it doesn't rely on the computer.</p>
| 2 | 2009-05-26T01:21:57Z | 908,572 | <p>here is a python module for hitting NIST online <a href="http://freshmeat.net/projects/mxdatetime" rel="nofollow">http://freshmeat.net/projects/mxdatetime</a>. </p>
| 0 | 2009-05-26T01:31:04Z | [
"python"
] |
Python Getting date online? | 908,550 | <p>How can I get the current date, month & year online using Python? Thanks!</p>
<p>EDIT-By this I mean, rather than getting it from the computer's date-visit a website & get it, so it doesn't rely on the computer.</p>
| 2 | 2009-05-26T01:21:57Z | 908,582 | <p>Perhaps you mean the NTP protocol? This project may help: <a href="http://pypi.python.org/pypi/ntplib/0.1.3" rel="nofollow">http://pypi.python.org/pypi/ntplib/0.1.3</a></p>
| 0 | 2009-05-26T01:35:23Z | [
"python"
] |
Python Getting date online? | 908,550 | <p>How can I get the current date, month & year online using Python? Thanks!</p>
<p>EDIT-By this I mean, rather than getting it from the computer's date-visit a website & get it, so it doesn't rely on the computer.</p>
| 2 | 2009-05-26T01:21:57Z | 908,604 | <p>If you can't use NTP, but rather want to stick with HTTP, you could <code>urllib.urlget("http://developer.yahooapis.com/TimeService/V1/getTime")</code> and parse the results:</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<Error xmlns="urn:yahoo:api">
The following errors were detected:
... | 3 | 2009-05-26T01:44:55Z | [
"python"
] |
Python Getting date online? | 908,550 | <p>How can I get the current date, month & year online using Python? Thanks!</p>
<p>EDIT-By this I mean, rather than getting it from the computer's date-visit a website & get it, so it doesn't rely on the computer.</p>
| 2 | 2009-05-26T01:21:57Z | 908,649 | <p>So thinking about the "would be so trivial" part I went ahead and just made <a href="http://just-the-time.appspot.com/">a google app engine web app</a> -- when you visit it, it returns a simple response claiming to be HTML but actually just a string such as <code>2009-05-26 02:01:12 UTC\n</code>. Any feature request... | 24 | 2009-05-26T02:04:50Z | [
"python"
] |
Regex Subtitution in Python | 908,739 | <p>I have a CSV file with several entries, and each entry has 2 unix timestamp formatted dates.</p>
<p>I have a method called <code>convert()</code>, which takes in the timestamp and converts it to <code>YYYYMMDD</code>.</p>
<p>Now, since I have 2 timestamps in each line, how would I replace each one with the new val... | 2 | 2009-05-26T02:48:22Z | 908,751 | <p>If you know the replacement:</p>
<pre><code>p = re.compile( r',\d{8},')
p.sub( ','+someval+',', csvstring )
</code></pre>
<p>if it's a format change:</p>
<pre><code>p = re.compile( r',(\d{4})(\d\d)(\d\d),')
p.sub( r',\3-\2-\1,', csvstring )
</code></pre>
<p>EDIT: sorry, just realised you said python, modified ab... | 3 | 2009-05-26T02:53:37Z | [
"python",
"regex",
"timestamp"
] |
Regex Subtitution in Python | 908,739 | <p>I have a CSV file with several entries, and each entry has 2 unix timestamp formatted dates.</p>
<p>I have a method called <code>convert()</code>, which takes in the timestamp and converts it to <code>YYYYMMDD</code>.</p>
<p>Now, since I have 2 timestamps in each line, how would I replace each one with the new val... | 2 | 2009-05-26T02:48:22Z | 908,800 | <p>I assume that by "unix timestamp formatted date" you mean a number of seconds since the epoch. This assumes that every number in the file is a UNIX timestamp. If that isn't the case you'll need to adjust the regex:</p>
<pre><code>import re, sys
# your convert function goes here
regex = re.compile(r'(\d+)')
for li... | 1 | 2009-05-26T03:20:59Z | [
"python",
"regex",
"timestamp"
] |
Regex Subtitution in Python | 908,739 | <p>I have a CSV file with several entries, and each entry has 2 unix timestamp formatted dates.</p>
<p>I have a method called <code>convert()</code>, which takes in the timestamp and converts it to <code>YYYYMMDD</code>.</p>
<p>Now, since I have 2 timestamps in each line, how would I replace each one with the new val... | 2 | 2009-05-26T02:48:22Z | 908,851 | <p>I'd use something along these lines. A lot like Laurence's response but with the timestamp conversion that you requested and takes the filename as a param. This code assumes you are working with recent dates (after 9/9/2001). If you need earlier dates, lower 10 to 9 or less.</p>
<pre><code>import re, sys, time
reg... | 0 | 2009-05-26T03:55:32Z | [
"python",
"regex",
"timestamp"
] |
Regex Subtitution in Python | 908,739 | <p>I have a CSV file with several entries, and each entry has 2 unix timestamp formatted dates.</p>
<p>I have a method called <code>convert()</code>, which takes in the timestamp and converts it to <code>YYYYMMDD</code>.</p>
<p>Now, since I have 2 timestamps in each line, how would I replace each one with the new val... | 2 | 2009-05-26T02:48:22Z | 909,261 | <p>Not able to comment your question, but did you take a look at the CSV module of python?
<a href="http://docs.python.org/library/csv.html#module-csv" rel="nofollow">http://docs.python.org/library/csv.html#module-csv</a></p>
| 1 | 2009-05-26T06:55:48Z | [
"python",
"regex",
"timestamp"
] |
How can I mine an XML document with awk, Perl, or Python? | 909,062 | <p>I have a XML file with the following data format:</p>
<pre><code><net NetName="abc" attr1="123" attr2="234" attr3="345".../>
<net NetName="cde" attr1="456" attr2="567" attr3="678".../>
....
</code></pre>
<p>Can anyone tell me how could I data mine the XML file using an awk one-liner? For example, I wou... | 3 | 2009-05-26T05:35:57Z | 909,076 | <p>In general, <a href="http://stackoverflow.com/questions/701166/can-you-provide-some-examples-of-why-it-is-hard-to-parse-xml-and-html-with-a-rege">you don't</a>. XML/HTML parsing is hard enough without trying to do it concisely, and while you may be able to hack together a solution that succeeds with a limited subset... | 7 | 2009-05-26T05:47:28Z | [
"python",
"xml",
"perl",
"awk"
] |
How can I mine an XML document with awk, Perl, or Python? | 909,062 | <p>I have a XML file with the following data format:</p>
<pre><code><net NetName="abc" attr1="123" attr2="234" attr3="345".../>
<net NetName="cde" attr1="456" attr2="567" attr3="678".../>
....
</code></pre>
<p>Can anyone tell me how could I data mine the XML file using an awk one-liner? For example, I wou... | 3 | 2009-05-26T05:35:57Z | 909,363 | <p>I have written a tool called <code>xml_grep2</code>, based on <a href="http://search.cpan.org/dist/XML-LibXML" rel="nofollow">XML::LibXML</a>, the perl interface to <a href="http://xmlsoft.org" rel="nofollow">libxml2</a>.</p>
<p>You would find the value you're looking for by doing this:</p>
<pre><code>xml_grep2 -t... | 7 | 2009-05-26T07:23:43Z | [
"python",
"xml",
"perl",
"awk"
] |
How can I mine an XML document with awk, Perl, or Python? | 909,062 | <p>I have a XML file with the following data format:</p>
<pre><code><net NetName="abc" attr1="123" attr2="234" attr3="345".../>
<net NetName="cde" attr1="456" attr2="567" attr3="678".../>
....
</code></pre>
<p>Can anyone tell me how could I data mine the XML file using an awk one-liner? For example, I wou... | 3 | 2009-05-26T05:35:57Z | 910,520 | <p>xmlgawk can use XML very easily.</p>
<pre><code>$ xgawk -lxml 'XMLATTR["NetName"]=="abc"{print XMLATTR["attr3"]}' test.xml
</code></pre>
<p>This one liner can parse XML and print "345".</p>
| 5 | 2009-05-26T12:53:00Z | [
"python",
"xml",
"perl",
"awk"
] |
How can I mine an XML document with awk, Perl, or Python? | 909,062 | <p>I have a XML file with the following data format:</p>
<pre><code><net NetName="abc" attr1="123" attr2="234" attr3="345".../>
<net NetName="cde" attr1="456" attr2="567" attr3="678".../>
....
</code></pre>
<p>Can anyone tell me how could I data mine the XML file using an awk one-liner? For example, I wou... | 3 | 2009-05-26T05:35:57Z | 910,614 | <p>If you do not have xmlgawk and your XML format is fixed, normal awk can do.</p>
<pre><code>$ nawk -F '[ ="]+' '/abc/{for(i=1;i<=NF;i++){if($i=="attr3"){print $(i+1)}}}' test.xml
</code></pre>
<p>This script can return "345".
But I think it is very dangerous because normal awk can not use XML.</p>
| 2 | 2009-05-26T13:16:07Z | [
"python",
"xml",
"perl",
"awk"
] |
How can I mine an XML document with awk, Perl, or Python? | 909,062 | <p>I have a XML file with the following data format:</p>
<pre><code><net NetName="abc" attr1="123" attr2="234" attr3="345".../>
<net NetName="cde" attr1="456" attr2="567" attr3="678".../>
....
</code></pre>
<p>Can anyone tell me how could I data mine the XML file using an awk one-liner? For example, I wou... | 3 | 2009-05-26T05:35:57Z | 19,667,533 | <p>You might try this nifty little script: <a href="http://awk.info/?doc/tools/xmlparse.html" rel="nofollow">http://awk.info/?doc/tools/xmlparse.html</a></p>
| 0 | 2013-10-29T19:33:42Z | [
"python",
"xml",
"perl",
"awk"
] |
Why is the compiler package discontinued in Python 3? | 909,092 | <p>I was just pleasantly surprised to came across the documentation of <a href="http://docs.python.org/library/compiler">Python's compiler package</a>, but noticed that it's gone in Python 3.0, without any clear replacement or explanation.</p>
<p>I can't seem to find any discussion on python-dev about how this decisio... | 29 | 2009-05-26T05:54:30Z | 909,172 | <p>I believe the functionality is now built in:</p>
<ul>
<li><a href="http://docs.python.org/3/library/functions.html#compile">compile</a></li>
<li><a href="http://docs.python.org/3.3/library/ast.html">ast</a></li>
</ul>
| 29 | 2009-05-26T06:24:50Z | [
"python",
"compiler-construction",
"python-3.x"
] |
Python code that needs some overview | 909,279 | <p>im currently learning python (in the very begining), so I still have some doubts about good code manners and how should I proceed with it.</p>
<p>Today I created this code that should random trought 01 to 60 (but is running from 01 to 69)</p>
<pre><code>import random
dez = ['0', '1', '2', '3', '4', '5', '6']
uni ... | 1 | 2009-05-26T07:02:10Z | 909,293 | <p>You do realize you can write the exact same code in 1 line, right? It is easy using <a href="http://docs.python.org/library/random.html#random.randint" rel="nofollow">randint</a>:</p>
<pre><code>>>> [random.randint(1,60) for _ in range(6)]
[22, 29, 48, 18, 20, 22]
</code></pre>
<p>This will give you a lis... | 4 | 2009-05-26T07:05:48Z | [
"python"
] |
Python code that needs some overview | 909,279 | <p>im currently learning python (in the very begining), so I still have some doubts about good code manners and how should I proceed with it.</p>
<p>Today I created this code that should random trought 01 to 60 (but is running from 01 to 69)</p>
<pre><code>import random
dez = ['0', '1', '2', '3', '4', '5', '6']
uni ... | 1 | 2009-05-26T07:02:10Z | 909,296 | <p>you will get no real benefit by shuffling on each loop. Do it once before the loop.</p>
<p>choosen isn't a word</p>
| 0 | 2009-05-26T07:06:29Z | [
"python"
] |
Python code that needs some overview | 909,279 | <p>im currently learning python (in the very begining), so I still have some doubts about good code manners and how should I proceed with it.</p>
<p>Today I created this code that should random trought 01 to 60 (but is running from 01 to 69)</p>
<pre><code>import random
dez = ['0', '1', '2', '3', '4', '5', '6']
uni ... | 1 | 2009-05-26T07:02:10Z | 909,302 | <p>You can just use </p>
<pre><code>random.randrange(1,60)
</code></pre>
| 2 | 2009-05-26T07:07:45Z | [
"python"
] |
Python code that needs some overview | 909,279 | <p>im currently learning python (in the very begining), so I still have some doubts about good code manners and how should I proceed with it.</p>
<p>Today I created this code that should random trought 01 to 60 (but is running from 01 to 69)</p>
<pre><code>import random
dez = ['0', '1', '2', '3', '4', '5', '6']
uni ... | 1 | 2009-05-26T07:02:10Z | 2,477,769 | <p>To get 6 unique random integers in the range from 1 to 59:</p>
<pre><code>sample = random.sample(xrange(1, 60), 6)
# -> [8, 34, 16, 28, 46, 39]
</code></pre>
<p>To get strings:</p>
<pre><code>['%02d' % i for i in sample]
# -> ['08', '34', '16', '28', '46', '39']
</code></pre>
| 1 | 2010-03-19T13:49:53Z | [
"python"
] |
Factory for Callback methods - Python TKinter | 909,551 | <p>Writing a test app to emulate PIO lines, I have a very simple Python/Tk GUI app. Using the numeric Keys 1 to 8 to simulate PIO pins 1 to 8. Press the key down = PIO High, release the Key = PIO goes low. What I need it for is not the problem. I kind of went down a rabbit hole trying to use a factory to create the key... | 1 | 2009-05-26T08:18:17Z | 909,579 | <p>cb expects 'self' and 'event'. Maybe it only gets event from the bind?</p>
| 1 | 2009-05-26T08:25:04Z | [
"python",
"methods",
"factory"
] |
Factory for Callback methods - Python TKinter | 909,551 | <p>Writing a test app to emulate PIO lines, I have a very simple Python/Tk GUI app. Using the numeric Keys 1 to 8 to simulate PIO pins 1 to 8. Press the key down = PIO High, release the Key = PIO goes low. What I need it for is not the problem. I kind of went down a rabbit hole trying to use a factory to create the key... | 1 | 2009-05-26T08:18:17Z | 910,510 | <p>Here is the amended code, taking into account SpliFF's answer. I find this much more aesthetically pleasing but it bugs me that I don't understand how it works. So, for extra credit, can anyone explain how this does work?</p>
<pre><code>#!usr/bin/env python
"""
Python + Tk GUI interface to simulate a 8 Pio lines.
"... | 0 | 2009-05-26T12:50:31Z | [
"python",
"methods",
"factory"
] |
Factory for Callback methods - Python TKinter | 909,551 | <p>Writing a test app to emulate PIO lines, I have a very simple Python/Tk GUI app. Using the numeric Keys 1 to 8 to simulate PIO pins 1 to 8. Press the key down = PIO High, release the Key = PIO goes low. What I need it for is not the problem. I kind of went down a rabbit hole trying to use a factory to create the key... | 1 | 2009-05-26T08:18:17Z | 910,861 | <p>In answer to your followup question.</p>
<p>I'm not sure which part you don't understand but I'm guessing you don't quite have a handle on how event callbacks work? If so it's pretty easy. Tk runs in a loop looking for events (keypresses, mouseclicks, etc..). When you bind a callback/function to a event you're just... | 1 | 2009-05-26T14:03:10Z | [
"python",
"methods",
"factory"
] |
on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself? | 909,618 | <p>on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself?</p>
<p>such as<br />
<a href="http://comics.com/peanuts/" rel="nofollow">http://comics.com/peanuts/</a></p>
<p><strong>Update</strong>: i know how to download the image as a file. the hard part is how ... | 5 | 2009-05-26T08:36:43Z | 909,643 | <p>A quick look on google reveals two command-line programs that you should be able to lash together in a batch file or using the scripting language of your choice.</p>
<p><a href="http://www.gnu.org/software/wget/" rel="nofollow">http://www.gnu.org/software/wget/</a> - to do the download</p>
<p><a href="http://www.b... | 3 | 2009-05-26T08:43:31Z | [
"php",
"python",
"ruby",
"scheduled-tasks"
] |
on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself? | 909,618 | <p>on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself?</p>
<p>such as<br />
<a href="http://comics.com/peanuts/" rel="nofollow">http://comics.com/peanuts/</a></p>
<p><strong>Update</strong>: i know how to download the image as a file. the hard part is how ... | 5 | 2009-05-26T08:36:43Z | 909,827 | <p>Here is perhaps the shortest distance to your goal.</p>
<p>It's not simple... you will need to work out how to parse out the image, and the peanuts example seems to be an unpredictable URI, so it might be more difficult than it looks to get the image itself. Your best bet will be to <strong>read the HTML</strong> o... | 1 | 2009-05-26T09:36:28Z | [
"php",
"python",
"ruby",
"scheduled-tasks"
] |
on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself? | 909,618 | <p>on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself?</p>
<p>such as<br />
<a href="http://comics.com/peanuts/" rel="nofollow">http://comics.com/peanuts/</a></p>
<p><strong>Update</strong>: i know how to download the image as a file. the hard part is how ... | 5 | 2009-05-26T08:36:43Z | 910,031 | <p>This depends how precise you want to be. Downloading the entire web page wouldn't be too challenging - using wget, as Earwicker mentions above.</p>
<p>If you want the actual image file of the comic downloaded, you would need a bit more in your arsenal. In Python - because that's what I know best - I would imagine y... | 8 | 2009-05-26T10:36:14Z | [
"php",
"python",
"ruby",
"scheduled-tasks"
] |
on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself? | 909,618 | <p>on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself?</p>
<p>such as<br />
<a href="http://comics.com/peanuts/" rel="nofollow">http://comics.com/peanuts/</a></p>
<p><strong>Update</strong>: i know how to download the image as a file. the hard part is how ... | 5 | 2009-05-26T08:36:43Z | 910,102 | <p>Configure feedburner on the RSS feed, subscribe yourself to the email alerts?</p>
| 2 | 2009-05-26T10:56:17Z | [
"php",
"python",
"ruby",
"scheduled-tasks"
] |
on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself? | 909,618 | <p>on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself?</p>
<p>such as<br />
<a href="http://comics.com/peanuts/" rel="nofollow">http://comics.com/peanuts/</a></p>
<p><strong>Update</strong>: i know how to download the image as a file. the hard part is how ... | 5 | 2009-05-26T08:36:43Z | 911,727 | <p>Emailing it is easy. Pick a library in your favorite language and read the documentation. Send it through your regular email account, or create a new free GMail account for it.</p>
<ul>
<li><a href="http://docs.python.org/library/email" rel="nofollow">http://docs.python.org/library/email</a></li>
<li><a href="htt... | 1 | 2009-05-26T17:02:32Z | [
"php",
"python",
"ruby",
"scheduled-tasks"
] |
on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself? | 909,618 | <p>on my local Windows machine, how do i write a script to download a comic strip every day and email it to myself?</p>
<p>such as<br />
<a href="http://comics.com/peanuts/" rel="nofollow">http://comics.com/peanuts/</a></p>
<p><strong>Update</strong>: i know how to download the image as a file. the hard part is how ... | 5 | 2009-05-26T08:36:43Z | 913,993 | <p>It's pretty simple if you already know how to download the file. Once its downloaded create a cronjob that emails it to yourself. </p>
<p>Using something like phpmailer would be the easiest way to email it</p>
<p><a href="http://phpmailer.codeworxtech.com/index.php?pg=examplebmail" rel="nofollow">http://phpmailer... | 1 | 2009-05-27T04:50:41Z | [
"php",
"python",
"ruby",
"scheduled-tasks"
] |
Windows Authentication with Python and urllib2 | 909,658 | <p>I want to grab some data off a webpage that requires my windows username and password.</p>
<p>So far, I've got:</p>
<pre><code>opener = build_opener()
try:
page = opener.open("http://somepagewhichneedsmywindowsusernameandpassword/")
print page
except URLError:
print "Oh noes."
</code></pre>
<p>Is this... | 10 | 2009-05-26T08:48:09Z | 909,919 | <p>There are several forms of authentication that web sites can use.</p>
<ol>
<li><p>HTTP Authentication. This where the browser pops up a window for you to enter your username and password. There are two mechanisms: basic and digest. There is an "Authorization" Header that comes along with the page that tells a b... | -1 | 2009-05-26T10:08:29Z | [
"python",
"urllib2"
] |
Windows Authentication with Python and urllib2 | 909,658 | <p>I want to grab some data off a webpage that requires my windows username and password.</p>
<p>So far, I've got:</p>
<pre><code>opener = build_opener()
try:
page = opener.open("http://somepagewhichneedsmywindowsusernameandpassword/")
print page
except URLError:
print "Oh noes."
</code></pre>
<p>Is this... | 10 | 2009-05-26T08:48:09Z | 910,023 | <p>Assuming you are writing your client code on Windows and need seamless NTLM authentication then you should read Mark Hammond's <a href="http://mail.python.org/pipermail/python-win32/2008-June/007722.html">Hooking in NTLM</a> post from the python-win32 mailing list which essentially answers the same question. This po... | 13 | 2009-05-26T10:34:05Z | [
"python",
"urllib2"
] |
pywikipedia logging in? | 909,834 | <p>For various reasons I can't use login.py to log me in so I was wondering if anyone knew code so that I could log in to Wikipedia with my script without running a separate script?
Cheers!</p>
| -1 | 2009-05-26T09:39:54Z | 1,023,283 | <p>The answer is going to be simple: you can't use pywikipedia without being able to run <code>login.py</code>.</p>
<p>That file not only provides a nice User-interface to try your configuration: it contains all the authentication primitives that we use in the framework to log in. Without logging-in, you can't do much... | 1 | 2009-06-21T05:37:05Z | [
"python",
"login",
"pywikipedia"
] |
pywikipedia logging in? | 909,834 | <p>For various reasons I can't use login.py to log me in so I was wondering if anyone knew code so that I could log in to Wikipedia with my script without running a separate script?
Cheers!</p>
| -1 | 2009-05-26T09:39:54Z | 20,646,716 | <p>One alternative that worked for me, when I wasn't able to interactively use my remote server (and thus not enter my password), was to copy my credentials to the remote server.</p>
<p>By default your remote permissions are stored in <code>~/.pywikibot/pywikibot.lwp</code>, and it has worked for me in the past to log... | 0 | 2013-12-17T23:21:39Z | [
"python",
"login",
"pywikipedia"
] |
Reading "raw" Unicode-strings in Python | 909,886 | <p>I am quite new to Python so my question might be silly, but even though reading through a lot of threads I didn't find an answer to my question.</p>
<p>I have a mixed source document which contains html, xml, latex and other textformats and which I try to get into a latex-only format. </p>
<p>Therefore, I have use... | 1 | 2009-05-26T09:54:22Z | 909,921 | <p>You talk of ``raw'' Unicode strings. What does that mean? Unicode itself is not an encoding, but there are different encodings to store Unicode characters (read <a href="http://www.joelonsoftware.com/articles/Unicode.html" rel="nofollow">this post</a> by Joel).</p>
<p>The <a href="http://docs.python.org/3.0/library... | 3 | 2009-05-26T10:09:09Z | [
"python",
"string",
"unicode",
"readability"
] |
Reading "raw" Unicode-strings in Python | 909,886 | <p>I am quite new to Python so my question might be silly, but even though reading through a lot of threads I didn't find an answer to my question.</p>
<p>I have a mixed source document which contains html, xml, latex and other textformats and which I try to get into a latex-only format. </p>
<p>Therefore, I have use... | 1 | 2009-05-26T09:54:22Z | 910,046 | <p>You need to determine the "encoding" of the input document. Unicode can encode millions of characters but files can only story 8-bit values (0-255). So the Unicode text must be encoded in some way.</p>
<p>If the document is XML, it should be in the first line (encoding="..."; "utf-8" is the default if there is no "... | 0 | 2009-05-26T10:39:30Z | [
"python",
"string",
"unicode",
"readability"
] |
Reading "raw" Unicode-strings in Python | 909,886 | <p>I am quite new to Python so my question might be silly, but even though reading through a lot of threads I didn't find an answer to my question.</p>
<p>I have a mixed source document which contains html, xml, latex and other textformats and which I try to get into a latex-only format. </p>
<p>Therefore, I have use... | 1 | 2009-05-26T09:54:22Z | 910,051 | <p>Please, first, read this:</p>
<p><a href="http://www.joelonsoftware.com/articles/Unicode.html" rel="nofollow">The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)</a></p>
<p>Then, come back and ask questions.</p>
| 1 | 2009-05-26T10:42:40Z | [
"python",
"string",
"unicode",
"readability"
] |
Changing a get request to a post in python? | 909,929 | <blockquote>
<p>en.wikipedia.org/w/api.php?action=login&lgname=user&lgpassword=password</p>
</blockquote>
<p>But it doesn't work because it is a get request. What would the the post request version of this?</p>
<p>Cheers!</p>
| 0 | 2009-05-26T10:11:19Z | 909,958 | <p>The variables for a POST request are in the HTTP headers, not in the URL.
Check <a href="http://docs.python.org/library/urllib.html" rel="nofollow">urllib</a>.</p>
<p>edit:
Try this (i got it from <a href="http://www.voidspace.org.uk/python/articles/urllib2.shtml" rel="nofollow">here</a>):</p>
<pre><code>import ur... | 3 | 2009-05-26T10:17:23Z | [
"python",
"forms",
"post",
"get"
] |
Changing a get request to a post in python? | 909,929 | <blockquote>
<p>en.wikipedia.org/w/api.php?action=login&lgname=user&lgpassword=password</p>
</blockquote>
<p>But it doesn't work because it is a get request. What would the the post request version of this?</p>
<p>Cheers!</p>
| 0 | 2009-05-26T10:11:19Z | 909,975 | <p>Since your sample is in PHP, use $_REQUEST, this holds the contents of both $_GET and $_POST. </p>
| 0 | 2009-05-26T10:23:00Z | [
"python",
"forms",
"post",
"get"
] |
Changing a get request to a post in python? | 909,929 | <blockquote>
<p>en.wikipedia.org/w/api.php?action=login&lgname=user&lgpassword=password</p>
</blockquote>
<p>But it doesn't work because it is a get request. What would the the post request version of this?</p>
<p>Cheers!</p>
| 0 | 2009-05-26T10:11:19Z | 910,024 | <pre><code>params = urllib.urlencode({'action' : 'login', 'lgname' : 'user', 'lgpassword' : 'password'})
response = urllib.urlopen("http://en.wikipedia.org/w/api.php", params)
</code></pre>
<p>info about urllib can be found <a href="http://docs.python.org/library/urllib.html" rel="nofollow">here</a>.</p>
| 2 | 2009-05-26T10:34:21Z | [
"python",
"forms",
"post",
"get"
] |
Python MemoryError - how can I force object deletion | 910,153 | <p>I have a program that process several files, and for each file a report is generated. The report generating part is a separate function that takes a filename, then returns. During report generation, intermediate parts are cached in memory, as they may be used for several parts of the report, to avoid recalculating.<... | 0 | 2009-05-26T11:11:40Z | 910,162 | <p>You should check out the gc module: <a href="http://docs.python.org/library/gc.html#module-gc" rel="nofollow">http://docs.python.org/library/gc.html#module-gc</a>. </p>
| 3 | 2009-05-26T11:13:21Z | [
"python",
"memory",
"resources",
"garbage-collection"
] |
Resize fields in Django Admin | 910,169 | <p>Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 characters wide, or a CharField, also 6 or 8 chars wide, and then the edit box goes up to 15 or 20 chars.</p>
<p>How can I tell the admin how wide a... | 77 | 2009-05-26T11:16:16Z | 911,915 | <p>You can set arbitrary HTML attributes on a widget using its <a href="http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Widget.attrs">"attrs" property</a>.</p>
<p>You can do this in the Django admin using formfield_for_dbfield:</p>
<pre><code>class MyModelAdmin(admin.ModelAdmin):
def formfield_... | 40 | 2009-05-26T17:57:49Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Resize fields in Django Admin | 910,169 | <p>Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 characters wide, or a CharField, also 6 or 8 chars wide, and then the edit box goes up to 15 or 20 chars.</p>
<p>How can I tell the admin how wide a... | 77 | 2009-05-26T11:16:16Z | 912,661 | <p>A quick and dirty option is to simply provide a custom template for the model in question. </p>
<p>If you create a template named <code>admin/<app label>/<class name>/change_form.html</code> then the admin will use that template instead of the default. That is, if you've got a model named <code>Person</... | 19 | 2009-05-26T20:45:00Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Resize fields in Django Admin | 910,169 | <p>Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 characters wide, or a CharField, also 6 or 8 chars wide, and then the edit box goes up to 15 or 20 chars.</p>
<p>How can I tell the admin how wide a... | 77 | 2009-05-26T11:16:16Z | 913,565 | <p>If you want to change the attributes on a per-field instance, you can add the "attrs" property directly in to your form entries.</p>
<p>for example:</p>
<pre><code>class BlogPostForm(forms.ModelForm):
title = forms.CharField(label='Title:', max_length=128)
body = forms.CharField(label='Post:', max_length=2... | 9 | 2009-05-27T01:36:50Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Resize fields in Django Admin | 910,169 | <p>Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 characters wide, or a CharField, also 6 or 8 chars wide, and then the edit box goes up to 15 or 20 chars.</p>
<p>How can I tell the admin how wide a... | 77 | 2009-05-26T11:16:16Z | 1,251,864 | <p>The best way I found is something like this:</p>
<pre><code>class NotificationForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(NotificationForm, self).__init__(*args, **kwargs)
self.fields['content'].widget.attrs['cols'] = 80
self.fields['content'].widget.attrs['rows'] ... | 6 | 2009-08-09T17:58:57Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Resize fields in Django Admin | 910,169 | <p>Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 characters wide, or a CharField, also 6 or 8 chars wide, and then the edit box goes up to 15 or 20 chars.</p>
<p>How can I tell the admin how wide a... | 77 | 2009-05-26T11:16:16Z | 1,368,252 | <p>It's well described in <a href="http://code.djangoproject.com/wiki/NewformsHOWTO#Q%3AHowdoIchangetheattributesforawidgetonafieldinmymodel.">Django FAQ</a>:</p>
<p><strong>Q:</strong> How do I change the attributes for a widget on a field in my model?</p>
<p><strong>A:</strong> Override the formfield_for_dbfield in... | 5 | 2009-09-02T15:02:06Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Resize fields in Django Admin | 910,169 | <p>Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 characters wide, or a CharField, also 6 or 8 chars wide, and then the edit box goes up to 15 or 20 chars.</p>
<p>How can I tell the admin how wide a... | 77 | 2009-05-26T11:16:16Z | 1,744,292 | <p>You should use <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/">ModelAdmin.formfield_overrides</a>.</p>
<p>It is quite easy - in <code>admin.py</code>, define:</p>
<pre><code>class YourModelAdmin(admin.ModelAdmin):
formfield_overrides = {
models.CharField: {'widget': TextInput(attrs={'... | 129 | 2009-11-16T19:24:46Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Resize fields in Django Admin | 910,169 | <p>Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 characters wide, or a CharField, also 6 or 8 chars wide, and then the edit box goes up to 15 or 20 chars.</p>
<p>How can I tell the admin how wide a... | 77 | 2009-05-26T11:16:16Z | 2,137,240 | <p>I had a similar problem with TextField. I'm using Django 1.0.2 and wanted to change the default value for 'rows' in the associated textarea. formfield_overrides doesn't exist in this version. Overriding formfield_for_dbfield worked but I had to do it for each of my ModelAdmin subclasses or it would result in a re... | 7 | 2010-01-26T02:48:20Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Resize fields in Django Admin | 910,169 | <p>Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 characters wide, or a CharField, also 6 or 8 chars wide, and then the edit box goes up to 15 or 20 chars.</p>
<p>How can I tell the admin how wide a... | 77 | 2009-05-26T11:16:16Z | 2,138,384 | <p>You can always set your fields sizes in a custom stylesheet and tell Django to use that for your ModelAdmin class:</p>
<pre><code>class MyModelAdmin(ModelAdmin):
class Media:
css = {"all": ("my_stylesheet.css",)}
</code></pre>
| 4 | 2010-01-26T09:11:02Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Resize fields in Django Admin | 910,169 | <p>Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 characters wide, or a CharField, also 6 or 8 chars wide, and then the edit box goes up to 15 or 20 chars.</p>
<p>How can I tell the admin how wide a... | 77 | 2009-05-26T11:16:16Z | 8,552,571 | <p>Same answer as msdin but with TextInput instead of TextArea:</p>
<pre><code>from django.forms import TextInput
class ShortTextField(models.TextField):
def formfield(self, **kwargs):
kwargs.update(
{"widget": TextInput(attrs={'size': 10})}
)
return super(ShortTextField, se... | 1 | 2011-12-18T15:04:13Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Resize fields in Django Admin | 910,169 | <p>Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 characters wide, or a CharField, also 6 or 8 chars wide, and then the edit box goes up to 15 or 20 chars.</p>
<p>How can I tell the admin how wide a... | 77 | 2009-05-26T11:16:16Z | 15,650,812 | <p>for 1.6, using forms I had to specify the attributes of the textarea inside the charfield:</p>
<pre><code>test1 = forms.CharField(max_length=400, widget=forms.Textarea( attrs={'rows':'2', 'cols': '10'}), initial='', help_text=helptexts.helptxt['test'])
</code></pre>
| 0 | 2013-03-27T02:10:18Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Resize fields in Django Admin | 910,169 | <p>Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 characters wide, or a CharField, also 6 or 8 chars wide, and then the edit box goes up to 15 or 20 chars.</p>
<p>How can I tell the admin how wide a... | 77 | 2009-05-26T11:16:16Z | 21,766,384 | <p><strong>To change the width for a specific field.</strong></p>
<p>Made via <a href="https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_form" rel="nofollow">ModelAdmin.get_form</a>:</p>
<pre><code>class YourModelAdmin(admin.ModelAdmin):
def get_form(self, request, obj=N... | 13 | 2014-02-13T21:56:18Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Problems with python script on web hosting | 910,219 | <p>I have written a script for Wikipedia & it works fine on my computer, yet when I upload it to my web host(Dreamhost) it doesn't work & says that the user I am trying to log in as is blocked-this is not true, it works on my computer & I#m not blocked.
This is the exact error message I get-</p>
<pre><code... | 0 | 2009-05-26T11:32:49Z | 910,254 | <p>It could be that your host (Dreamhost) is blocked, and not your user.</p>
| 1 | 2009-05-26T11:38:47Z | [
"python",
"hosting",
"pywikipedia"
] |
Problems with python script on web hosting | 910,219 | <p>I have written a script for Wikipedia & it works fine on my computer, yet when I upload it to my web host(Dreamhost) it doesn't work & says that the user I am trying to log in as is blocked-this is not true, it works on my computer & I#m not blocked.
This is the exact error message I get-</p>
<pre><code... | 0 | 2009-05-26T11:32:49Z | 910,428 | <p>I'd start by adding in some debug. Can you capture the output you're sending to wikipedia and the results it resturns? There's probably some more information lodged in there which you can extract to see why it's failing.</p>
<p><strong>[Edit]</strong> r.e. debugging - it's hard to give advice given the small snippe... | 0 | 2009-05-26T12:30:42Z | [
"python",
"hosting",
"pywikipedia"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.