title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
How can I print over the current line in a command line application? | 465,348 | <p>On Unix, I can either use \r (carriage return) or \b (backspace) to print over text already visible in the shell (i.e. overwrite the current line again).</p>
<p>Can I achieve the same effect in a Windows command line from a Python script?</p>
<p>I tried the curses module but it doesn't seem to be available on Wind... | 10 | 2009-01-21T13:43:17Z | 465,360 | <p>Look <a href="http://stackoverflow.com/questions/60221/how-to-animate-the-command-line">here</a></p>
<p><a href="https://web.archive.org/web/20101025073658/http://adamv.com/dev/python/curses/" rel="nofollow">here</a> too for a curses library for python on windows...</p>
| -3 | 2009-01-21T13:46:03Z | [
"python",
"windows",
"command-line"
] |
How can I print over the current line in a command line application? | 465,348 | <p>On Unix, I can either use \r (carriage return) or \b (backspace) to print over text already visible in the shell (i.e. overwrite the current line again).</p>
<p>Can I achieve the same effect in a Windows command line from a Python script?</p>
<p>I tried the curses module but it doesn't seem to be available on Wind... | 10 | 2009-01-21T13:43:17Z | 465,475 | <p>yes:</p>
<pre><code>import sys
import time
def restart_line():
sys.stdout.write('\r')
sys.stdout.flush()
sys.stdout.write('some data')
sys.stdout.flush()
time.sleep(2) # wait 2 seconds...
restart_line()
sys.stdout.write('other different data')
sys.stdout.flush()
</code></pre>
| 16 | 2009-01-21T14:15:10Z | [
"python",
"windows",
"command-line"
] |
How can I print over the current line in a command line application? | 465,348 | <p>On Unix, I can either use \r (carriage return) or \b (backspace) to print over text already visible in the shell (i.e. overwrite the current line again).</p>
<p>Can I achieve the same effect in a Windows command line from a Python script?</p>
<p>I tried the curses module but it doesn't seem to be available on Wind... | 10 | 2009-01-21T13:43:17Z | 467,659 | <p>Simple way if you're just wanting to update the previous line:</p>
<pre><code>import time
for i in range(20):
print str(i) + '\r',
time.sleep(1)
</code></pre>
| 1 | 2009-01-22T00:37:07Z | [
"python",
"windows",
"command-line"
] |
How can I print over the current line in a command line application? | 465,348 | <p>On Unix, I can either use \r (carriage return) or \b (backspace) to print over text already visible in the shell (i.e. overwrite the current line again).</p>
<p>Can I achieve the same effect in a Windows command line from a Python script?</p>
<p>I tried the curses module but it doesn't seem to be available on Wind... | 10 | 2009-01-21T13:43:17Z | 9,543,690 | <p>On Windows (python 3), it seems to work (not using stdout directly):</p>
<pre><code>import sys
for i in reversed(range(0,20)):
time.sleep(0.1)
if(i == 19):
print(str(i), end='', file=sys.stdout)
else:
print("\r{0:{width}".format(str(i), width = w, fill = ' ', align = 'right'), end='', file=sys.stdout... | 1 | 2012-03-03T05:13:01Z | [
"python",
"windows",
"command-line"
] |
How can I print over the current line in a command line application? | 465,348 | <p>On Unix, I can either use \r (carriage return) or \b (backspace) to print over text already visible in the shell (i.e. overwrite the current line again).</p>
<p>Can I achieve the same effect in a Windows command line from a Python script?</p>
<p>I tried the curses module but it doesn't seem to be available on Wind... | 10 | 2009-01-21T13:43:17Z | 21,672,188 | <pre><code>import sys
import time
for i in range(10):
print '\r', # print is Ok, and comma is needed.
time.sleep(0.3)
print i,
sys.stdout.flush() # flush is needed.
</code></pre>
<p>And if on the IPython-notebook, just like this:</p>
<pre><code>import time
from IPython.display import clear_... | 7 | 2014-02-10T08:28:27Z | [
"python",
"windows",
"command-line"
] |
How can I print over the current line in a command line application? | 465,348 | <p>On Unix, I can either use \r (carriage return) or \b (backspace) to print over text already visible in the shell (i.e. overwrite the current line again).</p>
<p>Can I achieve the same effect in a Windows command line from a Python script?</p>
<p>I tried the curses module but it doesn't seem to be available on Wind... | 10 | 2009-01-21T13:43:17Z | 26,952,100 | <p>I know this is old, but i wanted to tell my version (it works on my PC in the cmd, but not in the idle) to override a line in Python 3:</p>
<pre><code>>>> from time import sleep
>>> for i in range(400):
>>> print("\r" + str(i), end="")
>>> sleep(0.5)
</code></pre>
<p><st... | 2 | 2014-11-15T23:42:30Z | [
"python",
"windows",
"command-line"
] |
How can I print over the current line in a command line application? | 465,348 | <p>On Unix, I can either use \r (carriage return) or \b (backspace) to print over text already visible in the shell (i.e. overwrite the current line again).</p>
<p>Can I achieve the same effect in a Windows command line from a Python script?</p>
<p>I tried the curses module but it doesn't seem to be available on Wind... | 10 | 2009-01-21T13:43:17Z | 27,175,096 | <p>I just had this problem. You can still use <code>\r</code>, even in Windows Command Prompt, however, it only takes you back to the previous linebreak (<code>\n</code>).</p>
<p>If you do something like this:</p>
<pre><code>cnt = 0
print str(cnt)
while True:
cnt += 1
print "\r" + str(cnt)
</code></pre>
<p>Y... | 3 | 2014-11-27T16:25:56Z | [
"python",
"windows",
"command-line"
] |
How can I print over the current line in a command line application? | 465,348 | <p>On Unix, I can either use \r (carriage return) or \b (backspace) to print over text already visible in the shell (i.e. overwrite the current line again).</p>
<p>Can I achieve the same effect in a Windows command line from a Python script?</p>
<p>I tried the curses module but it doesn't seem to be available on Wind... | 10 | 2009-01-21T13:43:17Z | 38,707,538 | <p>easy method :)</p>
<pre><code>import sys
from time import sleep
import os
#print("\033[y coordinate;[x coordinateH Hello")
os.system('cls')
sleep(0.2)
print("\033[1;1H[]")
sleep(0.2)
print("\033[1;1H []")
sleep(0.2)
print("\033[1;1H []")
sleep(0.2)
print("\033[1;1H []")
sleep(0.2)
print("\033[1;1H ... | 1 | 2016-08-01T20:27:20Z | [
"python",
"windows",
"command-line"
] |
How do I take the output of one program and use it as the input of another? | 465,421 | <p>I've looked at <a href="http://stackoverflow.com/questions/316007/what-is-the-best-way-to-make-the-output-of-one-stream-the-input-to-another">this</a> and it wasn't much help.</p>
<p>I have a Ruby program that puts a question to the cmd line and I would like to write a Python program that can return an answer. Doe... | 4 | 2009-01-21T14:01:11Z | 465,438 | <p>If you're on unix / linux you can use piping:</p>
<pre><code>question.rb | answer.py
</code></pre>
<p>Then the output of question.rb becomes the input of answer.py</p>
<p>I've not tried it recently, but I have a feeling the same syntax might work on Windows as well.</p>
| 4 | 2009-01-21T14:05:22Z | [
"python",
"ruby",
"io"
] |
How do I take the output of one program and use it as the input of another? | 465,421 | <p>I've looked at <a href="http://stackoverflow.com/questions/316007/what-is-the-best-way-to-make-the-output-of-one-stream-the-input-to-another">this</a> and it wasn't much help.</p>
<p>I have a Ruby program that puts a question to the cmd line and I would like to write a Python program that can return an answer. Doe... | 4 | 2009-01-21T14:01:11Z | 465,454 | <p>Pexpect</p>
<p><a href="http://www.noah.org/wiki/Pexpect" rel="nofollow">http://www.noah.org/wiki/Pexpect</a></p>
<blockquote>
<p>Pexpect is a pure Python expect-like
module. Pexpect makes Python a better
tool for controlling other
applications.</p>
<p>Pexpect is a pure Python module for
spawning ch... | 3 | 2009-01-21T14:08:51Z | [
"python",
"ruby",
"io"
] |
How do I take the output of one program and use it as the input of another? | 465,421 | <p>I've looked at <a href="http://stackoverflow.com/questions/316007/what-is-the-best-way-to-make-the-output-of-one-stream-the-input-to-another">this</a> and it wasn't much help.</p>
<p>I have a Ruby program that puts a question to the cmd line and I would like to write a Python program that can return an answer. Doe... | 4 | 2009-01-21T14:01:11Z | 465,455 | <p>There are two ways (off the top of my head) to do this. The simplest if you're in a Unix environment is to use piping. Simple example:</p>
<pre><code>cat .profile .shrc | more
</code></pre>
<p>This will send the output of the first command (<code>cat .profile .shrc</code>) to the <code>more</code> command using ... | 1 | 2009-01-21T14:08:57Z | [
"python",
"ruby",
"io"
] |
How do I take the output of one program and use it as the input of another? | 465,421 | <p>I've looked at <a href="http://stackoverflow.com/questions/316007/what-is-the-best-way-to-make-the-output-of-one-stream-the-input-to-another">this</a> and it wasn't much help.</p>
<p>I have a Ruby program that puts a question to the cmd line and I would like to write a Python program that can return an answer. Doe... | 4 | 2009-01-21T14:01:11Z | 465,466 | <pre><code>p = subprocess.Popen(['ruby', 'ruby_program.rb'], stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
ruby_question = p.stdout.readline()
answer = calculate_answer(ruby_question)
p.stdin.write(answer)
print p.communicate()[0] # prints further info ruby may show.
</code>... | 10 | 2009-01-21T14:12:23Z | [
"python",
"ruby",
"io"
] |
How do I take the output of one program and use it as the input of another? | 465,421 | <p>I've looked at <a href="http://stackoverflow.com/questions/316007/what-is-the-best-way-to-make-the-output-of-one-stream-the-input-to-another">this</a> and it wasn't much help.</p>
<p>I have a Ruby program that puts a question to the cmd line and I would like to write a Python program that can return an answer. Doe... | 4 | 2009-01-21T14:01:11Z | 465,468 | <p>First of all check this out:
[Unix piping][1]</p>
<p>It works on windows or unix but it's slighly dufferent, first the programs:</p>
<p>question.rb:</p>
<pre><code>puts "This is the question"
</code></pre>
<p>answer.rb:</p>
<pre><code>question = gets
#calculate answer
puts "This is the answer"
</code></pre>
<... | 3 | 2009-01-21T14:12:50Z | [
"python",
"ruby",
"io"
] |
How do I make IPython organize tab completion possibilities by class? | 465,605 | <p>When an object has hundreds of methods, tab completion is hard to use. More often than not the interesting methods are the ones defined or overridden by the inspected object's class and not its base classes.</p>
<p>How can I get IPython to group its tab completion possibilities so the methods and properties defined... | 4 | 2009-01-21T14:50:32Z | 467,430 | <p>I don't think this can be accomplished easily. There's no mechanism in Ipython to perform it in any case.</p>
<p>Initially I had thought you could modify Ipython's source to change the order (eg by changing the <code>dir2()</code> function in genutils.py). However it looks like readline alphabetically sorts the c... | 1 | 2009-01-21T23:06:42Z | [
"python",
"readline",
"ipython"
] |
How do I make IPython organize tab completion possibilities by class? | 465,605 | <p>When an object has hundreds of methods, tab completion is hard to use. More often than not the interesting methods are the ones defined or overridden by the inspected object's class and not its base classes.</p>
<p>How can I get IPython to group its tab completion possibilities so the methods and properties defined... | 4 | 2009-01-21T14:50:32Z | 488,461 | <p>It looks like I can use <code>readline.set_completion_display_matches_hook([function])</code> (new in Python 2.6) to display the results. The completer would return a list of possibilities as usual, but would also store the results of <code>inspect.classify_class_attrs(cls)</code> where applicable. The <code>complet... | 1 | 2009-01-28T17:04:55Z | [
"python",
"readline",
"ipython"
] |
How do I make IPython organize tab completion possibilities by class? | 465,605 | <p>When an object has hundreds of methods, tab completion is hard to use. More often than not the interesting methods are the ones defined or overridden by the inspected object's class and not its base classes.</p>
<p>How can I get IPython to group its tab completion possibilities so the methods and properties defined... | 4 | 2009-01-21T14:50:32Z | 492,328 | <p>Since I am not using Python 2.6 or 3.0 yet and don't have <code>readline.set_completion_display_matches_hook()</code>, I can use ctypes to set <code>completion_display_func</code> like so:</p>
<pre><code>from ctypes import *
rl = cdll.LoadLibrary('libreadline.so')
def completion_display_func(matches, num_matches,... | 5 | 2009-01-29T16:22:23Z | [
"python",
"readline",
"ipython"
] |
What is a simple way to generate keywords from a text? | 465,795 | <p>I suppose I could take a text and remove high frequency English words from it. By keywords, I mean that I want to extract words that are most the characterizing of the content of the text (tags ) . It doesn't have to be perfect, a good approximation is perfect for my needs.</p>
<p>Has anyone done anything like that... | 17 | 2009-01-21T15:43:36Z | 465,840 | <p>The simplest way to do what you want is this...</p>
<pre>
>>> text = "this is some of the sample text"
>>> words = [word for word in set(text.split(" ")) if len(word) > 3]
>>> words
['this', 'some', 'sample', 'text']
</pre>
<p>I don't know of any standard module that does this, but it wouldn't be hard to replace t... | 3 | 2009-01-21T15:54:43Z | [
"python",
"perl",
"metadata"
] |
What is a simple way to generate keywords from a text? | 465,795 | <p>I suppose I could take a text and remove high frequency English words from it. By keywords, I mean that I want to extract words that are most the characterizing of the content of the text (tags ) . It doesn't have to be perfect, a good approximation is perfect for my needs.</p>
<p>Has anyone done anything like that... | 17 | 2009-01-21T15:43:36Z | 465,909 | <p>The name for the "high frequency English words" is <a href="http://en.wikipedia.org/wiki/Stop_words">stop words</a> and there are many lists available. I'm not aware of any python or perl libraries, but you could encode your stop word list in a binary tree or hash (or you could use python's frozenset), then as you ... | 16 | 2009-01-21T16:14:29Z | [
"python",
"perl",
"metadata"
] |
What is a simple way to generate keywords from a text? | 465,795 | <p>I suppose I could take a text and remove high frequency English words from it. By keywords, I mean that I want to extract words that are most the characterizing of the content of the text (tags ) . It doesn't have to be perfect, a good approximation is perfect for my needs.</p>
<p>Has anyone done anything like that... | 17 | 2009-01-21T15:43:36Z | 466,013 | <p>In Perl there's <a href="http://search.cpan.org/perldoc?Lingua::EN::Keywords" rel="nofollow">Lingua::EN::Keywords</a>.</p>
| 4 | 2009-01-21T16:40:40Z | [
"python",
"perl",
"metadata"
] |
What is a simple way to generate keywords from a text? | 465,795 | <p>I suppose I could take a text and remove high frequency English words from it. By keywords, I mean that I want to extract words that are most the characterizing of the content of the text (tags ) . It doesn't have to be perfect, a good approximation is perfect for my needs.</p>
<p>Has anyone done anything like that... | 17 | 2009-01-21T15:43:36Z | 466,037 | <p>You could try using the perl module <a href="http://search.cpan.org/~acoburn/Lingua-EN-Tagger-0.15/Tagger.pm">Lingua::EN::Tagger</a> for a quick and easy solution. </p>
<p>A more complicated module <a href="http://code.google.com/p/lingua-en-semtags-engine/">Lingua::EN::Semtags::Engine</a> uses Lingua::EN::Tagger w... | 9 | 2009-01-21T16:44:49Z | [
"python",
"perl",
"metadata"
] |
What is a simple way to generate keywords from a text? | 465,795 | <p>I suppose I could take a text and remove high frequency English words from it. By keywords, I mean that I want to extract words that are most the characterizing of the content of the text (tags ) . It doesn't have to be perfect, a good approximation is perfect for my needs.</p>
<p>Has anyone done anything like that... | 17 | 2009-01-21T15:43:36Z | 466,304 | <p>To find the most frequently-used words in a text, do something like this:</p>
<pre><code>#!/usr/bin/perl -w
use strict;
use warnings 'all';
# Read the text:
open my $ifh, '<', 'text.txt'
or die "Cannot open file: $!";
local $/;
my $text = <$ifh>;
# Find all the words, and count how many times they app... | 4 | 2009-01-21T17:47:07Z | [
"python",
"perl",
"metadata"
] |
What is a simple way to generate keywords from a text? | 465,795 | <p>I suppose I could take a text and remove high frequency English words from it. By keywords, I mean that I want to extract words that are most the characterizing of the content of the text (tags ) . It doesn't have to be perfect, a good approximation is perfect for my needs.</p>
<p>Has anyone done anything like that... | 17 | 2009-01-21T15:43:36Z | 469,359 | <p>One liner solution (words longer than two chars which occurred more than two times):</p>
<pre><code>perl -ne'$h{$1}++while m/\b(\w{3,})\b/g}{printf"%-20s %5d\n",$_,$h{$_}for sort{$h{$b}<=>$h{$a}}grep{$h{$_}>2}keys%h'
</code></pre>
<p><strong>EDIT:</strong> If one wants to sort alphabetically words with sa... | 2 | 2009-01-22T14:36:23Z | [
"python",
"perl",
"metadata"
] |
What is a simple way to generate keywords from a text? | 465,795 | <p>I suppose I could take a text and remove high frequency English words from it. By keywords, I mean that I want to extract words that are most the characterizing of the content of the text (tags ) . It doesn't have to be perfect, a good approximation is perfect for my needs.</p>
<p>Has anyone done anything like that... | 17 | 2009-01-21T15:43:36Z | 469,690 | <p>I think the most accurate way that still maintains a semblance of simplicity would be to count the word frequencies in your source, then weight them according to their frequencies in common English (or whatever other language) usage. </p>
<p>Words that appear less frequently in common use, like "coffeehouse" are m... | 0 | 2009-01-22T15:54:08Z | [
"python",
"perl",
"metadata"
] |
What is a simple way to generate keywords from a text? | 465,795 | <p>I suppose I could take a text and remove high frequency English words from it. By keywords, I mean that I want to extract words that are most the characterizing of the content of the text (tags ) . It doesn't have to be perfect, a good approximation is perfect for my needs.</p>
<p>Has anyone done anything like that... | 17 | 2009-01-21T15:43:36Z | 20,750,315 | <p>TF-IDF (Term Frequency - Inverse Document Frequency) is designed for this. </p>
<p>Basically it asks, which words are frequent in this document, compared to all documents?</p>
<p>It will give a lower score to words that appear in all documents, and a higher score to words that appear in a given document frequently... | 0 | 2013-12-23T19:58:21Z | [
"python",
"perl",
"metadata"
] |
Delphi-like GUI designer for Python | 465,814 | <p>Is there any GUI toolkit for Python with form designer similar to Delphi, eg where one can drag and drop controls to form, move them around etc.</p>
| 7 | 2009-01-21T15:47:39Z | 465,864 | <p>I recommend <a href="http://www.riverbankcomputing.co.uk/software/pyqt/intro" rel="nofollow">PyQt</a> (now from Nokia), which uses <a href="http://www.qtsoftware.com/products/appdev/developer-tools/developer-tools?currentflipperobject=73543fa58dda72c632a376b97104ff78" rel="nofollow">Qt Designer</a>. Qt designer prod... | 4 | 2009-01-21T16:02:16Z | [
"python",
"user-interface",
"form-designer"
] |
Delphi-like GUI designer for Python | 465,814 | <p>Is there any GUI toolkit for Python with form designer similar to Delphi, eg where one can drag and drop controls to form, move them around etc.</p>
| 7 | 2009-01-21T15:47:39Z | 465,929 | <p>Use Glade + PyGTk to do GUI programming in Python. Glade is a tool which allows you to create graphical interfaces by dragging and dropping widgets. In turn Glade generates the interface definition in XML which you can hook up with your code using libglade. Check the website of <a href="http://glade.gnome.org/" rel=... | 2 | 2009-01-21T16:20:28Z | [
"python",
"user-interface",
"form-designer"
] |
Delphi-like GUI designer for Python | 465,814 | <p>Is there any GUI toolkit for Python with form designer similar to Delphi, eg where one can drag and drop controls to form, move them around etc.</p>
| 7 | 2009-01-21T15:47:39Z | 465,930 | <p>If your using wxPython check out <a href="http://boa-constructor.sourceforge.net/" rel="nofollow">BoaConstructor</a>, it is a complete Python IDE with a GUI designer.</p>
| 2 | 2009-01-21T16:21:20Z | [
"python",
"user-interface",
"form-designer"
] |
How to make a model instance read-only after saving it once? | 466,135 | <p>One of the functionalities in a Django project I am writing is sending a newsletter. I have a model, <code>Newsletter</code> and a function, <code>send_newsletter</code>, which I have registered to listen to <code>Newsletter</code>'s <code>post_save</code> signal. When the newsletter object is saved via the admin in... | 3 | 2009-01-21T17:11:14Z | 466,641 | <p>You can check if it is creation or update in the model's <code>save</code> method:</p>
<pre><code>def save(self, *args, **kwargs):
if self.pk:
raise StandardError('Can\'t modify bla bla bla.')
super(Payment, self).save(*args, **kwargs)
</code></pre>
<p>Code above will raise an exception if you try ... | 7 | 2009-01-21T19:29:25Z | [
"python",
"django",
"django-models",
"django-admin",
"django-signals"
] |
How to make a model instance read-only after saving it once? | 466,135 | <p>One of the functionalities in a Django project I am writing is sending a newsletter. I have a model, <code>Newsletter</code> and a function, <code>send_newsletter</code>, which I have registered to listen to <code>Newsletter</code>'s <code>post_save</code> signal. When the newsletter object is saved via the admin in... | 3 | 2009-01-21T17:11:14Z | 531,541 | <p>Suggested reading: The Zen of Admin in <a href="http://www.djangobook.com/en/1.0/chapter17/" rel="nofollow">chapter 17 of the Django Book</a>.</p>
<p>Summary: The admin is not designed for what you're trying to do :(</p>
<p>However, the 1.0 version of the book covers only Django 0.96, and good things have happened... | 1 | 2009-02-10T08:57:23Z | [
"python",
"django",
"django-models",
"django-admin",
"django-signals"
] |
How to make a model instance read-only after saving it once? | 466,135 | <p>One of the functionalities in a Django project I am writing is sending a newsletter. I have a model, <code>Newsletter</code> and a function, <code>send_newsletter</code>, which I have registered to listen to <code>Newsletter</code>'s <code>post_save</code> signal. When the newsletter object is saved via the admin in... | 3 | 2009-01-21T17:11:14Z | 2,477,830 | <p>use readonlyadmin in ur amdin.py.List all the fields which u want to make readonly.After creating the object u canot edit them then</p>
<p>use the link</p>
<pre><code>http://www.djangosnippets.org/snippets/937/
</code></pre>
<p>copy the file and then import in ur admin.py and used it</p>
| 0 | 2010-03-19T14:00:41Z | [
"python",
"django",
"django-models",
"django-admin",
"django-signals"
] |
How to make a model instance read-only after saving it once? | 466,135 | <p>One of the functionalities in a Django project I am writing is sending a newsletter. I have a model, <code>Newsletter</code> and a function, <code>send_newsletter</code>, which I have registered to listen to <code>Newsletter</code>'s <code>post_save</code> signal. When the newsletter object is saved via the admin in... | 3 | 2009-01-21T17:11:14Z | 21,147,017 | <p>What you can easily do, is making all fields readonly:</p>
<pre><code>class MyModelAdmin(ModelAdmin):
form = ...
def get_readonly_fields(self, request, obj=None):
if obj:
return MyModelAdmin.form.Meta.fields
else: # This is an addition
return []
</code></pre>
<p>As f... | 0 | 2014-01-15T19:58:53Z | [
"python",
"django",
"django-models",
"django-admin",
"django-signals"
] |
How can I hide the console window in a PyQt app running on Windows? | 466,203 | <p>Surely this is possible? I have been hunting through PyQt tutorials and documentation but cannot find the answer to it. Probably I just need to phrase my search query differently.</p>
<p>[Edit]</p>
<p>Thanks PEZ for the answer - more details including use of the <code>.pyw</code> extension in <a href="http://www.o... | 12 | 2009-01-21T17:25:38Z | 466,222 | <p>I think you should be able to run your app with pythonw.exe.</p>
| 17 | 2009-01-21T17:28:34Z | [
"python",
"windows",
"command-line",
"pyqt"
] |
How can I hide the console window in a PyQt app running on Windows? | 466,203 | <p>Surely this is possible? I have been hunting through PyQt tutorials and documentation but cannot find the answer to it. Probably I just need to phrase my search query differently.</p>
<p>[Edit]</p>
<p>Thanks PEZ for the answer - more details including use of the <code>.pyw</code> extension in <a href="http://www.o... | 12 | 2009-01-21T17:25:38Z | 466,279 | <p>An easy way to do this is to give your script a .pyw extension instead of the usual .py.</p>
<p>This has the same effect as PEZ's answer (runs the script using pythonw.exe).</p>
| 14 | 2009-01-21T17:39:19Z | [
"python",
"windows",
"command-line",
"pyqt"
] |
How can I generate multi-line build commands? | 466,293 | <p>In SCons, my command generators create ridiculously long command lines. I'd
like to be able to split these commands across multiple lines for
readability in the build log.</p>
<p>e.g. I have a SConscipt like:</p>
<pre><code>import os
# create dependency
def my_cmd_generator(source, target, env, for_signature):
... | 3 | 2009-01-21T17:44:04Z | 510,842 | <p>You are mixing two totally different things: the command to be executed, and its representation in the command line. By default, scons prints the command line, but if you split the command line, you are changing the commands executed.</p>
<p>Now, scons has a mechanism to change the printed commands. They are regist... | 1 | 2009-02-04T10:49:13Z | [
"python",
"build",
"build-automation",
"scons"
] |
How can I generate multi-line build commands? | 466,293 | <p>In SCons, my command generators create ridiculously long command lines. I'd
like to be able to split these commands across multiple lines for
readability in the build log.</p>
<p>e.g. I have a SConscipt like:</p>
<pre><code>import os
# create dependency
def my_cmd_generator(source, target, env, for_signature):
... | 3 | 2009-01-21T17:44:04Z | 521,783 | <p>Thanks to cournape's tip about Actions versus Generators ( and eclipse pydev debugger), I've finally figured out what I need to do. You want to pass in your function to the 'Builder' class as an 'action' not a 'generator'. This will allow you to actually execute the os.system or os.popen call directly. Here's the... | 3 | 2009-02-06T19:24:02Z | [
"python",
"build",
"build-automation",
"scons"
] |
Converting string into datetime | 466,345 | <p>Short and simple. I've got a huge list of date-times like this as strings:</p>
<pre><code>Jun 1 2005 1:33PM
Aug 28 1999 12:00AM
</code></pre>
<p>I'm going to be shoving these back into proper datetime fields in a database so I need to magic them into real datetime objects. </p>
<p>Any help (even if it's just a k... | 826 | 2009-01-21T18:00:29Z | 466,366 | <p>Check out <a href="http://docs.python.org/2/library/time.html#time.strptime">strptime</a> in the <a href="http://docs.python.org/2/library/time.html">time</a> module. It is the inverse of <a href="http://docs.python.org/2/library/time.html#time.strftime">strftime</a>.</p>
| 433 | 2009-01-21T18:07:17Z | [
"python",
"datetime"
] |
Converting string into datetime | 466,345 | <p>Short and simple. I've got a huge list of date-times like this as strings:</p>
<pre><code>Jun 1 2005 1:33PM
Aug 28 1999 12:00AM
</code></pre>
<p>I'm going to be shoving these back into proper datetime fields in a database so I need to magic them into real datetime objects. </p>
<p>Any help (even if it's just a k... | 826 | 2009-01-21T18:00:29Z | 466,376 | <pre><code>from datetime import datetime
date_object = datetime.strptime('Jun 1 2005 1:33PM', '%b %d %Y %I:%M%p')
</code></pre>
<p><a href="https://docs.python.org/2/library/datetime.html#datetime.datetime.strptime">Link to the Python documentation for strptime</a></p>
<p><a href="https://docs.python.org/2/library/... | 1,383 | 2009-01-21T18:08:52Z | [
"python",
"datetime"
] |
Converting string into datetime | 466,345 | <p>Short and simple. I've got a huge list of date-times like this as strings:</p>
<pre><code>Jun 1 2005 1:33PM
Aug 28 1999 12:00AM
</code></pre>
<p>I'm going to be shoving these back into proper datetime fields in a database so I need to magic them into real datetime objects. </p>
<p>Any help (even if it's just a k... | 826 | 2009-01-21T18:00:29Z | 470,303 | <p>Use the third party <a href="http://labix.org/python-dateutil">dateutil</a> library:</p>
<pre><code>from dateutil import parser
dt = parser.parse("Aug 28 1999 12:00AM")
</code></pre>
<p>It can handle most date formats, including the one you need to parse. It's more convenient than strptime as it can guess the corr... | 399 | 2009-01-22T18:27:18Z | [
"python",
"datetime"
] |
Converting string into datetime | 466,345 | <p>Short and simple. I've got a huge list of date-times like this as strings:</p>
<pre><code>Jun 1 2005 1:33PM
Aug 28 1999 12:00AM
</code></pre>
<p>I'm going to be shoving these back into proper datetime fields in a database so I need to magic them into real datetime objects. </p>
<p>Any help (even if it's just a k... | 826 | 2009-01-21T18:00:29Z | 7,761,860 | <p>Something that isn't mentioned here and is useful: adding a suffix to the day. I decoupled the suffix logic so you can use it for any number you like, not just dates.</p>
<pre><code>import time
def num_suffix(n):
'''
Returns the suffix for any given int
'''
suf = ('th','st', 'nd', 'rd')
n = abs... | 17 | 2011-10-14T00:13:28Z | [
"python",
"datetime"
] |
Converting string into datetime | 466,345 | <p>Short and simple. I've got a huge list of date-times like this as strings:</p>
<pre><code>Jun 1 2005 1:33PM
Aug 28 1999 12:00AM
</code></pre>
<p>I'm going to be shoving these back into proper datetime fields in a database so I need to magic them into real datetime objects. </p>
<p>Any help (even if it's just a k... | 826 | 2009-01-21T18:00:29Z | 22,128,786 | <p>I have put together a project that can convert some really neat expressions. Check out <strong><a href="http://github.com/stevepeak/timestring">timestring</a></strong>. </p>
<h2>Here are some examples below:</h2>
<a href="http://github.com/stevepeak/timestring"><code>pip install timestring</code></a>
<pre><code>&... | 50 | 2014-03-02T14:22:44Z | [
"python",
"datetime"
] |
Converting string into datetime | 466,345 | <p>Short and simple. I've got a huge list of date-times like this as strings:</p>
<pre><code>Jun 1 2005 1:33PM
Aug 28 1999 12:00AM
</code></pre>
<p>I'm going to be shoving these back into proper datetime fields in a database so I need to magic them into real datetime objects. </p>
<p>Any help (even if it's just a k... | 826 | 2009-01-21T18:00:29Z | 22,223,725 | <p>Many timestamps have an implied timezone. To ensure that your code will work in every timezone, you should use UTC internally and attach a timezone each time a foreign object enters the system.</p>
<p>Python 3.2+:</p>
<pre><code>>>> datetime.datetime.strptime(
... "March 5, 2014, 20:13:50", "%B %d, %Y... | 24 | 2014-03-06T11:53:05Z | [
"python",
"datetime"
] |
Converting string into datetime | 466,345 | <p>Short and simple. I've got a huge list of date-times like this as strings:</p>
<pre><code>Jun 1 2005 1:33PM
Aug 28 1999 12:00AM
</code></pre>
<p>I'm going to be shoving these back into proper datetime fields in a database so I need to magic them into real datetime objects. </p>
<p>Any help (even if it's just a k... | 826 | 2009-01-21T18:00:29Z | 27,046,382 | <p>Django Timezone aware datetime object example.</p>
<pre><code>import datetime
from django.utils.timezone import get_current_timezone
tz = get_current_timezone()
format = '%b %d %Y %I:%M%p'
date_object = datetime.datetime.strptime('Jun 1 2005 1:33PM', format)
date_obj = tz.localize(date_object)
</code></pre>
<p>T... | 4 | 2014-11-20T17:58:01Z | [
"python",
"datetime"
] |
Converting string into datetime | 466,345 | <p>Short and simple. I've got a huge list of date-times like this as strings:</p>
<pre><code>Jun 1 2005 1:33PM
Aug 28 1999 12:00AM
</code></pre>
<p>I'm going to be shoving these back into proper datetime fields in a database so I need to magic them into real datetime objects. </p>
<p>Any help (even if it's just a k... | 826 | 2009-01-21T18:00:29Z | 27,401,685 | <p>You string representation of datetime is</p>
<p><code>Jun 1 2005 1:33PM</code></p>
<p>which is equals to</p>
<p><code>%b %d %Y %I:%M%p</code></p>
<blockquote>
<p>%b Month as localeâs abbreviated name(Jun)</p>
<p>%d Day of the month as a zero-padded decimal number(1)</p>
<p>%Y Year with ce... | 14 | 2014-12-10T13:00:49Z | [
"python",
"datetime"
] |
Converting string into datetime | 466,345 | <p>Short and simple. I've got a huge list of date-times like this as strings:</p>
<pre><code>Jun 1 2005 1:33PM
Aug 28 1999 12:00AM
</code></pre>
<p>I'm going to be shoving these back into proper datetime fields in a database so I need to magic them into real datetime objects. </p>
<p>Any help (even if it's just a k... | 826 | 2009-01-21T18:00:29Z | 30,577,110 | <p>You can use <a href="https://github.com/ralphavalon/easy_date" rel="nofollow">easy_date</a> to make it easy:</p>
<pre><code>import date_converter
converted_date = date_converter.string_to_datetime('Jun 1 2005 1:33PM', '%b %d %Y %I:%M%p')
</code></pre>
| 1 | 2015-06-01T15:15:02Z | [
"python",
"datetime"
] |
Converting string into datetime | 466,345 | <p>Short and simple. I've got a huge list of date-times like this as strings:</p>
<pre><code>Jun 1 2005 1:33PM
Aug 28 1999 12:00AM
</code></pre>
<p>I'm going to be shoving these back into proper datetime fields in a database so I need to magic them into real datetime objects. </p>
<p>Any help (even if it's just a k... | 826 | 2009-01-21T18:00:29Z | 34,377,575 | <p>Here is a solution using Pandas to convert dates formatted as strings into datetime.date objects.</p>
<pre><code>import pandas as pd
dates = ['2015-12-25', '2015-12-26']
>>> [d.date() for d in pd.to_datetime(dates)]
[datetime.date(2015, 12, 25), datetime.date(2015, 12, 26)]
</code></pre>
<p>And here is ... | 7 | 2015-12-20T03:03:25Z | [
"python",
"datetime"
] |
Converting string into datetime | 466,345 | <p>Short and simple. I've got a huge list of date-times like this as strings:</p>
<pre><code>Jun 1 2005 1:33PM
Aug 28 1999 12:00AM
</code></pre>
<p>I'm going to be shoving these back into proper datetime fields in a database so I need to magic them into real datetime objects. </p>
<p>Any help (even if it's just a k... | 826 | 2009-01-21T18:00:29Z | 34,871,180 | <pre><code>In [34]: import datetime
In [35]: _now = datetime.datetime.now()
In [36]: _now
Out[36]: datetime.datetime(2016, 1, 19, 9, 47, 0, 432000)
In [37]: print _now
2016-01-19 09:47:00.432000
In [38]: _parsed = datetime.datetime.strptime(str(_now),"%Y-%m-%d %H:%M:%S.%f")
In [39]: _parsed
Out[39]: datetime.datet... | 6 | 2016-01-19T07:48:47Z | [
"python",
"datetime"
] |
Converting string into datetime | 466,345 | <p>Short and simple. I've got a huge list of date-times like this as strings:</p>
<pre><code>Jun 1 2005 1:33PM
Aug 28 1999 12:00AM
</code></pre>
<p>I'm going to be shoving these back into proper datetime fields in a database so I need to magic them into real datetime objects. </p>
<p>Any help (even if it's just a k... | 826 | 2009-01-21T18:00:29Z | 35,202,640 | <p>Create a small utility function like:</p>
<pre><code>def date(datestr="", format="%Y-%m-%d"):
from datetime import datetime
if not datestr:
return datetime.today().date()
return datetime.strptime(datestr, format).date()
</code></pre>
<p>This is versatile enough:</p>
<ul>
<li>If you dont pass a... | 3 | 2016-02-04T13:43:07Z | [
"python",
"datetime"
] |
Converting string into datetime | 466,345 | <p>Short and simple. I've got a huge list of date-times like this as strings:</p>
<pre><code>Jun 1 2005 1:33PM
Aug 28 1999 12:00AM
</code></pre>
<p>I'm going to be shoving these back into proper datetime fields in a database so I need to magic them into real datetime objects. </p>
<p>Any help (even if it's just a k... | 826 | 2009-01-21T18:00:29Z | 38,005,442 | <p>The <a href="https://docs.python.org/2/library/datetime.html" rel="nofollow">datetime</a> python module is good for get date time and convert date time formats.</p>
<pre><code>import datetime
new_date_format1 = datetime.datetime.strptime('Jun 1 2005 1:33PM', '%b %d %Y %I:%M%p')
new_date_format2 = datetime.datetim... | 0 | 2016-06-24T04:07:27Z | [
"python",
"datetime"
] |
How can I set it up so that threads communicate they're complete with their task? | 466,525 | <p>Conceptually, I would like to accomplish the following but have had trouble understand how to code it properly in Python:</p>
<pre><code>from threading import Thread
for i in range(0,3):
t = Thread(target=myfunction)
t.start()
# wait until threads have finished executing
print 'complete!'
</code></pre>
| 0 | 2009-01-21T18:59:25Z | 466,550 | <p>I have never used python, but I think the concept you are looking for is a "semaphore".</p>
<p>Google turned up this:</p>
<p><a href="http://www.python.org/doc/2.5.2/lib/semaphore-objects.html" rel="nofollow">http://www.python.org/doc/2.5.2/lib/semaphore-objects.html</a></p>
| -3 | 2009-01-21T19:06:02Z | [
"python",
"multithreading"
] |
How can I set it up so that threads communicate they're complete with their task? | 466,525 | <p>Conceptually, I would like to accomplish the following but have had trouble understand how to code it properly in Python:</p>
<pre><code>from threading import Thread
for i in range(0,3):
t = Thread(target=myfunction)
t.start()
# wait until threads have finished executing
print 'complete!'
</code></pre>
| 0 | 2009-01-21T18:59:25Z | 466,570 | <p>add the threads to a list and <code>join()</code> them.</p>
<pre><code>from threading import Thread
tlist = []
for i in range(3):
t = Thread(target=some_function)
t.start()
tlist.append(t)
# wait until threads have finished executing
for t in tlist:
t.join()
print 'complete!'
</code></pre>
| 6 | 2009-01-21T19:10:02Z | [
"python",
"multithreading"
] |
Why do I have to specify my own class when using super(), and is there a way to get around it? | 466,611 | <p>When using Python's <code>super()</code> to do method chaining, you have to explicitly specify your own class, for example:</p>
<pre><code>class MyDecorator(Decorator):
def decorate(self):
super(MyDecorator, self).decorate()
</code></pre>
<p>I have to specify the name of my class <code>MyDecorator</cod... | 12 | 2009-01-21T19:20:58Z | 466,638 | <p>The BDFL agrees. See <a href="http://www.python.org/dev/peps/pep-0367/" rel="nofollow">Pep 367 - New Super</a> for 2.6 and <a href="http://www.python.org/dev/peps/pep-3135/" rel="nofollow">PEP 3135 - New Super</a> for 3.0.</p>
| 7 | 2009-01-21T19:28:33Z | [
"python",
"multiple-inheritance"
] |
Why do I have to specify my own class when using super(), and is there a way to get around it? | 466,611 | <p>When using Python's <code>super()</code> to do method chaining, you have to explicitly specify your own class, for example:</p>
<pre><code>class MyDecorator(Decorator):
def decorate(self):
super(MyDecorator, self).decorate()
</code></pre>
<p>I have to specify the name of my class <code>MyDecorator</cod... | 12 | 2009-01-21T19:20:58Z | 466,647 | <p>Your wishes come true:</p>
<p>Just use python 3.0. In it you just use <code>super()</code> and it does <code>super(ThisClass, self)</code>.</p>
<p>Documentation <a href="http://docs.python.org/3.0/library/functions.html#super">here</a>. Code sample from the documentation:</p>
<pre><code>class C(B):
def method... | 10 | 2009-01-21T19:31:04Z | [
"python",
"multiple-inheritance"
] |
Why do I have to specify my own class when using super(), and is there a way to get around it? | 466,611 | <p>When using Python's <code>super()</code> to do method chaining, you have to explicitly specify your own class, for example:</p>
<pre><code>class MyDecorator(Decorator):
def decorate(self):
super(MyDecorator, self).decorate()
</code></pre>
<p>I have to specify the name of my class <code>MyDecorator</cod... | 12 | 2009-01-21T19:20:58Z | 466,922 | <p>you can also avoid writing a concrete class name in older versions of python by using</p>
<pre><code>def __init__(self):
super(self.__class__, self)
...
</code></pre>
| 0 | 2009-01-21T20:49:17Z | [
"python",
"multiple-inheritance"
] |
Why do I have to specify my own class when using super(), and is there a way to get around it? | 466,611 | <p>When using Python's <code>super()</code> to do method chaining, you have to explicitly specify your own class, for example:</p>
<pre><code>class MyDecorator(Decorator):
def decorate(self):
super(MyDecorator, self).decorate()
</code></pre>
<p>I have to specify the name of my class <code>MyDecorator</cod... | 12 | 2009-01-21T19:20:58Z | 25,377,660 | <p>This answer is wrong, try:</p>
<pre><code>def _super(cls):
setattr(cls, '_super', lambda self: super(cls, self))
return cls
class A(object):
def f(self):
print 'A.f'
@_super
class B(A):
def f(self):
self._super().f()
@_super
class C(B):
def f(self):
self._super().f()
... | 4 | 2014-08-19T07:19:10Z | [
"python",
"multiple-inheritance"
] |
How can I return system information in Python? | 466,684 | <p>Using Python, how can information such as CPU usage, memory usage (free, used, etc), process count, etc be returned in a generic manner so that the same code can be run on Linux, Windows, BSD, etc?</p>
<p>Alternatively, how could this information be returned on all the above systems with the code specific to that O... | 23 | 2009-01-21T19:40:34Z | 466,714 | <p>take a look at the <a href="http://docs.python.org/library/os.html" rel="nofollow">os module</a></p>
| 1 | 2009-01-21T19:53:19Z | [
"python",
"operating-system"
] |
How can I return system information in Python? | 466,684 | <p>Using Python, how can information such as CPU usage, memory usage (free, used, etc), process count, etc be returned in a generic manner so that the same code can be run on Linux, Windows, BSD, etc?</p>
<p>Alternatively, how could this information be returned on all the above systems with the code specific to that O... | 23 | 2009-01-21T19:40:34Z | 466,755 | <p>It looks like you want to get a lot more information than the standard Python library offers. If I were you, I would download the source code for 'ps' or 'top', or the Gnome/KDE version of the same, or any number of system monitoring/graphing programs which are more likely to have all the necessary Unix cross platfo... | 1 | 2009-01-21T20:07:49Z | [
"python",
"operating-system"
] |
How can I return system information in Python? | 466,684 | <p>Using Python, how can information such as CPU usage, memory usage (free, used, etc), process count, etc be returned in a generic manner so that the same code can be run on Linux, Windows, BSD, etc?</p>
<p>Alternatively, how could this information be returned on all the above systems with the code specific to that O... | 23 | 2009-01-21T19:40:34Z | 466,761 | <p>In a Linux environment you could read from the /proc file system.</p>
<pre><code>~$ cat /proc/meminfo
MemTotal: 2076816 kB
MemFree: 130284 kB
Buffers: 192664 kB
Cached: 1482760 kB
SwapCached: 0 kB
Active: 206584 kB
Inactive: 1528608 kB
HighTotal: 1179484 kB
HighFr... | 5 | 2009-01-21T20:09:07Z | [
"python",
"operating-system"
] |
How can I return system information in Python? | 466,684 | <p>Using Python, how can information such as CPU usage, memory usage (free, used, etc), process count, etc be returned in a generic manner so that the same code can be run on Linux, Windows, BSD, etc?</p>
<p>Alternatively, how could this information be returned on all the above systems with the code specific to that O... | 23 | 2009-01-21T19:40:34Z | 466,831 | <p>I recommend the platform module:</p>
<p><a href="http://doc.astro-wise.org/platform.html" rel="nofollow">http://doc.astro-wise.org/platform.html</a></p>
<p><a href="http://docs.python.org/library/platform.html" rel="nofollow">http://docs.python.org/library/platform.html</a></p>
<p><a href="http://www.doughellmann... | 3 | 2009-01-21T20:25:02Z | [
"python",
"operating-system"
] |
How can I return system information in Python? | 466,684 | <p>Using Python, how can information such as CPU usage, memory usage (free, used, etc), process count, etc be returned in a generic manner so that the same code can be run on Linux, Windows, BSD, etc?</p>
<p>Alternatively, how could this information be returned on all the above systems with the code specific to that O... | 23 | 2009-01-21T19:40:34Z | 466,961 | <p>There's the <a href="http://www.psychofx.com/psi/" rel="nofollow">PSI</a> (Python System Information) project with that aim, but they don't cover Windows yet.</p>
<p>You can probably use PSI and recpies <a href="http://code.activestate.com/recipes/511491/" rel="nofollow">like this one</a> and create a basic library... | 0 | 2009-01-21T20:58:19Z | [
"python",
"operating-system"
] |
How can I return system information in Python? | 466,684 | <p>Using Python, how can information such as CPU usage, memory usage (free, used, etc), process count, etc be returned in a generic manner so that the same code can be run on Linux, Windows, BSD, etc?</p>
<p>Alternatively, how could this information be returned on all the above systems with the code specific to that O... | 23 | 2009-01-21T19:40:34Z | 467,291 | <p>Regarding cross-platform: your best bet is probably to write platform-specific code, and then import it conditionally. e.g.</p>
<pre><code>import sys
if sys.platform == 'win32':
import win32_sysinfo as sysinfo
elif sys.platform == 'darwin':
import mac_sysinfo as sysinfo
elif 'linux' in sys.platform:
import l... | 16 | 2009-01-21T22:25:02Z | [
"python",
"operating-system"
] |
How can I return system information in Python? | 466,684 | <p>Using Python, how can information such as CPU usage, memory usage (free, used, etc), process count, etc be returned in a generic manner so that the same code can be run on Linux, Windows, BSD, etc?</p>
<p>Alternatively, how could this information be returned on all the above systems with the code specific to that O... | 23 | 2009-01-21T19:40:34Z | 29,018,179 | <p><a href="https://github.com/giampaolo/psutil" rel="nofollow">psutil</a> should provide what you need:</p>
<blockquote>
<p>[...] cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) [...]</p>
<p>[...] supports Linux, Windows, OSX, FreeBSD ... | 1 | 2015-03-12T19:03:19Z | [
"python",
"operating-system"
] |
reading/writing xmp metadatas on pdf files through pypdf | 466,692 | <p>I can read xmp metadatas through pyPdf with this code:</p>
<pre><code>a = pyPdf.PdfFileReader(open(self.fileName))
b = a.getXmpMetadata()
c = b.pdf_keywords
</code></pre>
<p>but: is this the best way? </p>
<p>And if I don't use the pdf_keywords property?</p>
<p>And is there any way to set t... | 5 | 2009-01-21T19:43:46Z | 472,721 | <p>As far as I can see, this is the best way to do so - and there is no way to change the metadata with pyPDF.</p>
| 3 | 2009-01-23T12:32:54Z | [
"python",
"pdf",
"metadata",
"xmp",
"pypdf"
] |
Python piping on Windows: Why does this not work? | 466,801 | <p>I'm trying something like this</p>
<p>Output.py</p>
<pre><code>print "Hello"
</code></pre>
<p>Input.py</p>
<pre><code>greeting = raw_input("Give me the greeting. ")
print "The greeting is:", greeting
</code></pre>
<p>At the cmd line</p>
<pre><code>Output.py | Input.py
</code></pre>
<p>But it returns an <i>EOF... | 10 | 2009-01-21T20:20:05Z | 466,849 | <p>I tested this on my Windows machine and it works if you specify the Python exe: </p>
<pre><code>C:\>C:\Python25\python.exe output.py | C:\Python25\python.exe input.py
Give me the greeting. The greeting is: hello
</code></pre>
<p>But I get an EOFError also if running the commands directly as: </p>
<pre><code>ou... | 23 | 2009-01-21T20:30:27Z | [
"python",
"windows",
"piping"
] |
Python piping on Windows: Why does this not work? | 466,801 | <p>I'm trying something like this</p>
<p>Output.py</p>
<pre><code>print "Hello"
</code></pre>
<p>Input.py</p>
<pre><code>greeting = raw_input("Give me the greeting. ")
print "The greeting is:", greeting
</code></pre>
<p>At the cmd line</p>
<pre><code>Output.py | Input.py
</code></pre>
<p>But it returns an <i>EOF... | 10 | 2009-01-21T20:20:05Z | 466,851 | <p>Change it to:</p>
<pre><code>Output.py | python Input.py
</code></pre>
<p>The output will be:</p>
<blockquote>
<p>Give me the greeting. The greeting is: hello</p>
</blockquote>
| 4 | 2009-01-21T20:30:46Z | [
"python",
"windows",
"piping"
] |
Python piping on Windows: Why does this not work? | 466,801 | <p>I'm trying something like this</p>
<p>Output.py</p>
<pre><code>print "Hello"
</code></pre>
<p>Input.py</p>
<pre><code>greeting = raw_input("Give me the greeting. ")
print "The greeting is:", greeting
</code></pre>
<p>At the cmd line</p>
<pre><code>Output.py | Input.py
</code></pre>
<p>But it returns an <i>EOF... | 10 | 2009-01-21T20:20:05Z | 467,756 | <p>Here's why you get the EOFError (from the documentation on raw_input):</p>
<blockquote>
<p>The function then reads a line from
input, converts it to a string
(stripping a trailing newline), and
returns that. When EOF is read,
EOFError is raised.</p>
</blockquote>
<p><a href="http://docs.python.org/librar... | 0 | 2009-01-22T01:22:47Z | [
"python",
"windows",
"piping"
] |
How will Python and Ruby applications be affected by .NET? | 466,897 | <p>I'm curious about how .NET will affect Python and Ruby applications. </p>
<p>Will applications written in IronPython/IronRuby be so specific to the .NET environment, that they will essentially become platform specific? </p>
<p>If they don't use any of the .NET features, then what is the advantage of IronPython/Iro... | 5 | 2009-01-21T20:43:40Z | 466,930 | <p>IronPython/IronRuby are built to work on the .net virtual machine, so they are as you say essentially platform specific. </p>
<p>Apparently they are compatible with Python and Ruby as long as you don't use any of the .net framework in your programs. </p>
| 1 | 2009-01-21T20:51:04Z | [
".net",
"python",
"ruby",
"ironpython",
"ironruby"
] |
How will Python and Ruby applications be affected by .NET? | 466,897 | <p>I'm curious about how .NET will affect Python and Ruby applications. </p>
<p>Will applications written in IronPython/IronRuby be so specific to the .NET environment, that they will essentially become platform specific? </p>
<p>If they don't use any of the .NET features, then what is the advantage of IronPython/Iro... | 5 | 2009-01-21T20:43:40Z | 467,031 | <p>You answer your first question with the second one, if you don't use anything from .Net only the original libs provided by the implementation of the language, you could interpret your *.py or *.rb file with another implementation and it should work.</p>
<p>The advantage would be if your a .Net shop you usually take... | 0 | 2009-01-21T21:12:41Z | [
".net",
"python",
"ruby",
"ironpython",
"ironruby"
] |
How will Python and Ruby applications be affected by .NET? | 466,897 | <p>I'm curious about how .NET will affect Python and Ruby applications. </p>
<p>Will applications written in IronPython/IronRuby be so specific to the .NET environment, that they will essentially become platform specific? </p>
<p>If they don't use any of the .NET features, then what is the advantage of IronPython/Iro... | 5 | 2009-01-21T20:43:40Z | 467,067 | <p>It would be cool to run Rails/Django under IIS rather then Apache/Mongrel type solutions</p>
| 0 | 2009-01-21T21:21:19Z | [
".net",
"python",
"ruby",
"ironpython",
"ironruby"
] |
How will Python and Ruby applications be affected by .NET? | 466,897 | <p>I'm curious about how .NET will affect Python and Ruby applications. </p>
<p>Will applications written in IronPython/IronRuby be so specific to the .NET environment, that they will essentially become platform specific? </p>
<p>If they don't use any of the .NET features, then what is the advantage of IronPython/Iro... | 5 | 2009-01-21T20:43:40Z | 467,145 | <p>If you create a library or framework, people can use it on .NET with their .NET code. That's pretty cool for them, and for you!</p>
<p>When developing an application, if you use .NET's facilities with abandon then you lose "cross-platformity", which is not always an issue.</p>
<p>If you wrap these uses with an int... | 1 | 2009-01-21T21:41:33Z | [
".net",
"python",
"ruby",
"ironpython",
"ironruby"
] |
How will Python and Ruby applications be affected by .NET? | 466,897 | <p>I'm curious about how .NET will affect Python and Ruby applications. </p>
<p>Will applications written in IronPython/IronRuby be so specific to the .NET environment, that they will essentially become platform specific? </p>
<p>If they don't use any of the .NET features, then what is the advantage of IronPython/Iro... | 5 | 2009-01-21T20:43:40Z | 467,385 | <p>According to the Mono page, IronPython is compatible with Mono's implementation of the .Net runtime, so executables should work both on Windows and Linux.</p>
| 1 | 2009-01-21T22:50:17Z | [
".net",
"python",
"ruby",
"ironpython",
"ironruby"
] |
How will Python and Ruby applications be affected by .NET? | 466,897 | <p>I'm curious about how .NET will affect Python and Ruby applications. </p>
<p>Will applications written in IronPython/IronRuby be so specific to the .NET environment, that they will essentially become platform specific? </p>
<p>If they don't use any of the .NET features, then what is the advantage of IronPython/Iro... | 5 | 2009-01-21T20:43:40Z | 475,953 | <p>I can't say anything about IronRuby, but most python implementations (like IronPython, Jython and PyPy) try to be as true to the CPython implementation as possible. IronPython is quickly becoming one of the best in this respect though, and there is a lot of traffic on Planet Python about it.</p>
<p>The main thing t... | 5 | 2009-01-24T12:23:04Z | [
".net",
"python",
"ruby",
"ironpython",
"ironruby"
] |
How will Python and Ruby applications be affected by .NET? | 466,897 | <p>I'm curious about how .NET will affect Python and Ruby applications. </p>
<p>Will applications written in IronPython/IronRuby be so specific to the .NET environment, that they will essentially become platform specific? </p>
<p>If they don't use any of the .NET features, then what is the advantage of IronPython/Iro... | 5 | 2009-01-21T20:43:40Z | 1,285,474 | <blockquote>
<p><em>Will applications written in IronPython/IronRuby be so specific to the .NET environment, that they will essentially become platform specific?</em></p>
</blockquote>
<p>IronRuby currently ships with most of the core ruby standard library, and support for ruby gems.</p>
<p>This means that it will ... | 2 | 2009-08-16T22:16:17Z | [
".net",
"python",
"ruby",
"ironpython",
"ironruby"
] |
python: list comprehension tactics | 467,094 | <p>I'm looking to take a string and create a list of strings that build up the original string.</p>
<p>e.g.:</p>
<pre><code>"asdf" => ["a", "as", "asd", "asdf"]
</code></pre>
<p>I'm sure there's a "pythonic" way to do it; I think I'm just losing my mind. What's the best way to get this done?</p>
| 8 | 2009-01-21T21:27:47Z | 467,102 | <p>One possibility:</p>
<pre><code>>>> st = 'asdf'
>>> [st[:n+1] for n in range(len(st))]
['a', 'as', 'asd', 'asdf']
</code></pre>
| 19 | 2009-01-21T21:30:19Z | [
"python",
"list-comprehension"
] |
python: list comprehension tactics | 467,094 | <p>I'm looking to take a string and create a list of strings that build up the original string.</p>
<p>e.g.:</p>
<pre><code>"asdf" => ["a", "as", "asd", "asdf"]
</code></pre>
<p>I'm sure there's a "pythonic" way to do it; I think I'm just losing my mind. What's the best way to get this done?</p>
| 8 | 2009-01-21T21:27:47Z | 467,161 | <p>If you're going to be looping over the elements of your "list", you may be better off using a generator rather than list comprehension:</p>
<pre><code>>>> text = "I'm a little teapot."
>>> textgen = (text[:i + 1] for i in xrange(len(text)))
>>> textgen
<generator object <genexpr>... | 16 | 2009-01-21T21:47:34Z | [
"python",
"list-comprehension"
] |
How to prevent overwriting an object someone else has modified | 467,134 | <p>I would like to find a generic way of preventing to save an object if it is saved after I checked it out.</p>
<p>We can assume the object has a <code>timestamp</code> field that contains last modification time. If I had checked out (visited a view using a ModelForm for instance) at <code>t1</code> and the object is... | 2 | 2009-01-21T21:38:39Z | 467,159 | <p>Overwrite the save method that would first check the last timestamp:</p>
<pre><code>def save(self):
if(self.id):
foo = Foo.objects.get(pk=self.id)
if(foo.timestamp > self.timestamp):
raise Exception, "trying to save outdated Foo"
super(Foo, self).save()
</code></pre>
| 4 | 2009-01-21T21:47:10Z | [
"python",
"django",
"django-models",
"locking",
"blocking"
] |
How can I read system information in Python on OS X? | 467,600 | <p>Following from this <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python">OS-agnostic question</a>, specifically <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python#467291">this response</a>, similar to data available from the l... | 1 | 2009-01-22T00:08:19Z | 467,698 | <p>I did some more googling (looking for "OS X /proc") -- it looks like the sysctl command might be what you want, although I'm not sure if it will give you all the information you need. Here's the manpage: <a href="http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man8/sysctl.8.html" rel="nofollow">h... | 2 | 2009-01-22T00:52:59Z | [
"python",
"osx",
"operating-system"
] |
How can I read system information in Python on OS X? | 467,600 | <p>Following from this <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python">OS-agnostic question</a>, specifically <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python#467291">this response</a>, similar to data available from the l... | 1 | 2009-01-22T00:08:19Z | 467,701 | <p>You can get a large amount of system information from the command line utilities <a href="http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man8/sysctl.8.html" rel="nofollow"><code>sysctl</code></a> and <a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man1/vm_stat.1.html" ... | 3 | 2009-01-22T00:54:13Z | [
"python",
"osx",
"operating-system"
] |
How can I read system information in Python on OS X? | 467,600 | <p>Following from this <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python">OS-agnostic question</a>, specifically <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python#467291">this response</a>, similar to data available from the l... | 1 | 2009-01-22T00:08:19Z | 467,726 | <p>The only stuff that's really nicely accesible is available from the platform module, but it's extremely limited (cpu, os version, architecture, etc). For cpu usage and uptime I think you will have to wrap the command line utilities 'uptime' and 'vm_stat'.</p>
<p>I built you one for vm_stat, the other one is up to y... | 3 | 2009-01-22T01:04:24Z | [
"python",
"osx",
"operating-system"
] |
How can I read system information in Python on OS X? | 467,600 | <p>Following from this <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python">OS-agnostic question</a>, specifically <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python#467291">this response</a>, similar to data available from the l... | 1 | 2009-01-22T00:08:19Z | 467,783 | <p>Here's a MacFUSE-based /proc fs:</p>
<p><a href="http://www.osxbook.com/book/bonus/chapter11/procfs" rel="nofollow">http://www.osxbook.com/book/bonus/chapter11/procfs</a></p>
<p>If you have control of the boxes you're running your python program on it might be a reasonable solution. At any rate it's nice to have ... | 0 | 2009-01-22T01:42:18Z | [
"python",
"osx",
"operating-system"
] |
How can I read system information in Python on OS X? | 467,600 | <p>Following from this <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python">OS-agnostic question</a>, specifically <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python#467291">this response</a>, similar to data available from the l... | 1 | 2009-01-22T00:08:19Z | 23,185,536 | <p>i was searching for this same thing, and i noticed there was no accepted answer for this question. in the intervening time since the question was originally asked, a python module called psutil was released:</p>
<p><a href="https://github.com/giampaolo/psutil" rel="nofollow">https://github.com/giampaolo/psutil</a>... | 0 | 2014-04-20T17:32:58Z | [
"python",
"osx",
"operating-system"
] |
How can I read system information in Python on Windows? | 467,602 | <p>Following from this <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python">OS-agnostic question</a>, specifically <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python#467291">this response</a>, similar to data available from the l... | 1 | 2009-01-22T00:09:44Z | 467,648 | <p>There was a similar question asked:</p>
<p><a href="http://stackoverflow.com/questions/276052/how-to-get-current-cpu-and-ram-usage-in-python">http://stackoverflow.com/questions/276052/how-to-get-current-cpu-and-ram-usage-in-python</a></p>
<p>There are quite a few answers telling you how to accomplish this in windo... | 1 | 2009-01-22T00:32:16Z | [
"python",
"windows",
"operating-system"
] |
How can I read system information in Python on Windows? | 467,602 | <p>Following from this <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python">OS-agnostic question</a>, specifically <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python#467291">this response</a>, similar to data available from the l... | 1 | 2009-01-22T00:09:44Z | 1,996,085 | <p>You can try using the systeminfo.exe wrapper I created a while back, it's a bit unorthodox but it seems to do the trick easily enough and without much code.</p>
<p>This should work on 2000/XP/2003 Server, and should work on Vista and Win7 provided they come with systeminfo.exe and it is located on the path.</p>
<p... | 2 | 2010-01-03T19:53:01Z | [
"python",
"windows",
"operating-system"
] |
How can I read system information in Python on Windows? | 467,602 | <p>Following from this <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python">OS-agnostic question</a>, specifically <a href="http://stackoverflow.com/questions/466684/how-can-i-return-system-information-in-python#467291">this response</a>, similar to data available from the l... | 1 | 2009-01-22T00:09:44Z | 11,785,020 | <p>In Windows, if you want to get info like from the SYSTEMINFO command, you can use the <a href="https://pypi.python.org/pypi/WMI/" rel="nofollow">WMI module.</a></p>
<pre><code>import wmi
c = wmi.WMI()
systeminfo = c.Win32_ComputerSystem()[0]
Manufacturer = systeminfo.Manufacturer
Model = systeminfo.Model
</co... | 3 | 2012-08-02T20:11:41Z | [
"python",
"windows",
"operating-system"
] |
Implementing a "rules engine" in Python | 467,738 | <p>I'm writing a log collection / analysis application in Python and I need to write a "rules engine" to match and act on log messages.</p>
<p>It needs to feature:</p>
<ul>
<li>Regular expression matching for the message itself</li>
<li>Arithmetic comparisons for message severity/priority</li>
<li>Boolean operators</... | 16 | 2009-01-22T01:11:24Z | 467,752 | <p>The only place that's different from Python syntax itself is the <code>message ~ "program\\[\d+\\]: message"</code> part, so I wonder if you really need a new syntax.</p>
<p><strong>Update:</strong> OK, you have either usability or safety concerns -- that's reasonable. A couple suggestions:</p>
<ul>
<li><p>Take a ... | 0 | 2009-01-22T01:20:11Z | [
"python",
"parsing",
"rules"
] |
Implementing a "rules engine" in Python | 467,738 | <p>I'm writing a log collection / analysis application in Python and I need to write a "rules engine" to match and act on log messages.</p>
<p>It needs to feature:</p>
<ul>
<li>Regular expression matching for the message itself</li>
<li>Arithmetic comparisons for message severity/priority</li>
<li>Boolean operators</... | 16 | 2009-01-22T01:11:24Z | 467,906 | <p>It's a little hard to answer the question without knowing what the scope of the application is.</p>
<ul>
<li>What are you trying to reason about?</li>
<li>What level of analysis are you talking about?</li>
<li>How complicated do you see the rules becoming?</li>
<li>How complicated is the interplay between different... | 0 | 2009-01-22T02:56:07Z | [
"python",
"parsing",
"rules"
] |
Implementing a "rules engine" in Python | 467,738 | <p>I'm writing a log collection / analysis application in Python and I need to write a "rules engine" to match and act on log messages.</p>
<p>It needs to feature:</p>
<ul>
<li>Regular expression matching for the message itself</li>
<li>Arithmetic comparisons for message severity/priority</li>
<li>Boolean operators</... | 16 | 2009-01-22T01:11:24Z | 468,737 | <p>Do not invent yet another rules language.</p>
<p>Either use Python or use some other existing, already debugged and working language like BPEL.</p>
<p>Just write your rules in Python, import them and execute them. Life is simpler, far easier to debug, and you've actually solved the actual log-reading problem with... | 52 | 2009-01-22T11:22:15Z | [
"python",
"parsing",
"rules"
] |
Implementing a "rules engine" in Python | 467,738 | <p>I'm writing a log collection / analysis application in Python and I need to write a "rules engine" to match and act on log messages.</p>
<p>It needs to feature:</p>
<ul>
<li>Regular expression matching for the message itself</li>
<li>Arithmetic comparisons for message severity/priority</li>
<li>Boolean operators</... | 16 | 2009-01-22T01:11:24Z | 1,925,675 | <p>You might also want to look at <a href="http://pyke.sourceforge.net/logic%5Fprogramming/index.html">PyKE</a>.</p>
| 5 | 2009-12-18T01:07:25Z | [
"python",
"parsing",
"rules"
] |
Implementing a "rules engine" in Python | 467,738 | <p>I'm writing a log collection / analysis application in Python and I need to write a "rules engine" to match and act on log messages.</p>
<p>It needs to feature:</p>
<ul>
<li>Regular expression matching for the message itself</li>
<li>Arithmetic comparisons for message severity/priority</li>
<li>Boolean operators</... | 16 | 2009-01-22T01:11:24Z | 19,260,664 | <p>Have you considered NebriOS? We just released this tool after building it for our own purposes. It's a <strong>pure Python/Django rules engine</strong>. We actually use it for workflow tasks, but it's generic enough to help your in your situation. You would need to connect to the remote DB and run the rules against ... | 1 | 2013-10-09T00:00:33Z | [
"python",
"parsing",
"rules"
] |
Is there a Perl equivalent of Python's re.findall/re.finditer (iterative regex results)? | 467,800 | <p>In Python compiled regex patterns <a href="http://docs.python.org/library/re.html#re.findall">have a <code>findall</code> method</a> that does the following:</p>
<blockquote>
<p>Return all non-overlapping matches of
pattern in string, as a list of
strings. The string is scanned
left-to-right, and matches ar... | 6 | 2009-01-22T01:52:54Z | 467,820 | <p>Use the <code>/g</code> modifier in your match. From the <code>perlop</code> manual:</p>
<blockquote>
<p>The "<code>/g</code>" modifier specifies global pattern matching--that is, matching as many times as possible within the string. How it behaves depends on the context. In list context, it returns a list of t... | 13 | 2009-01-22T02:04:14Z | [
"python",
"regex",
"perl",
"iterator"
] |
Is there a Perl equivalent of Python's re.findall/re.finditer (iterative regex results)? | 467,800 | <p>In Python compiled regex patterns <a href="http://docs.python.org/library/re.html#re.findall">have a <code>findall</code> method</a> that does the following:</p>
<blockquote>
<p>Return all non-overlapping matches of
pattern in string, as a list of
strings. The string is scanned
left-to-right, and matches ar... | 6 | 2009-01-22T01:52:54Z | 467,874 | <p>To build on Chris' response, it's probably most relevant to encase the <code>//g</code> regex in a <code>while</code> loop, like:</p>
<pre><code>my @matches;
while ( 'foobarbaz' =~ m/([aeiou])/g )
{
push @matches, $1;
}
</code></pre>
<p>Pasting some quick Python I/O:</p>
<pre><code>>>> import re
>... | 7 | 2009-01-22T02:35:09Z | [
"python",
"regex",
"perl",
"iterator"
] |
Is there a Perl equivalent of Python's re.findall/re.finditer (iterative regex results)? | 467,800 | <p>In Python compiled regex patterns <a href="http://docs.python.org/library/re.html#re.findall">have a <code>findall</code> method</a> that does the following:</p>
<blockquote>
<p>Return all non-overlapping matches of
pattern in string, as a list of
strings. The string is scanned
left-to-right, and matches ar... | 6 | 2009-01-22T01:52:54Z | 467,877 | <p>Nice beginner reference with similar content to <a href="http://stackoverflow.com/questions/467800/is-there-a-perl-equivalent-of-pythons-re-findall-re-finditer-iterative-regex-re#467874">@kyle</a>'s answer: <a href="http://perldoc.perl.org/perlretut.html#Using-regular-expressions-in-Perl" rel="nofollow">Perl Tutoria... | 2 | 2009-01-22T02:36:28Z | [
"python",
"regex",
"perl",
"iterator"
] |
Permutations in python, with a twist | 467,878 | <p>I have a list of objects (for the sake of example, let's say 5). I want a list of some of the possible permutations. Specifically, given that some pairs are not together, and some triples don't make sandwiches, how can I generate all other permutations? I realize that I generate all of them first and check that t... | 1 | 2009-01-22T02:38:17Z | 467,928 | <p>You would have to find an algorithm that cuts off more than one unwanted permutation after a single check, in order to gain anything. The obvious strategy is to build the permutations sequentially, for example, in a tree. Each cut then eliminates a whole branch.</p>
<p><em>edit:</em><br />
Example: in the set (A ... | 5 | 2009-01-22T03:09:38Z | [
"python"
] |
In what situation should the built-in 'operator' module be used in python? | 467,920 | <p>I'm speaking of this module:
<a href="http://docs.python.org/library/operator.html">http://docs.python.org/library/operator.html</a></p>
<p>From the article:</p>
<blockquote>
<p>The operator module exports a set of
functions implemented in C
corresponding to the intrinsic
operators of Python. For example,
... | 21 | 2009-01-22T03:03:46Z | 467,937 | <p>One example is in the use of the <code>reduce()</code> function:</p>
<pre><code>>>> import operator
>>> a = [2, 3, 4, 5]
>>> reduce(lambda x, y: x + y, a)
14
>>> reduce(operator.add, a)
14
</code></pre>
| 16 | 2009-01-22T03:15:07Z | [
"python",
"operators"
] |
In what situation should the built-in 'operator' module be used in python? | 467,920 | <p>I'm speaking of this module:
<a href="http://docs.python.org/library/operator.html">http://docs.python.org/library/operator.html</a></p>
<p>From the article:</p>
<blockquote>
<p>The operator module exports a set of
functions implemented in C
corresponding to the intrinsic
operators of Python. For example,
... | 21 | 2009-01-22T03:03:46Z | 467,945 | <p>Possibly the most popular usage is operator.itemgetter. Given a list <code>lst</code> of tuples, you can sort by the ith element by: <code>lst.sort(key=operator.itemgetter(i))</code></p>
<p>Certainly, you could do the same thing without operator by defining your own key function, but the operator module makes it s... | 22 | 2009-01-22T03:19:40Z | [
"python",
"operators"
] |
Sample a running Python app | 467,925 | <p>I'm used to sampling C-based apps, which every few milliseconds sees what function stack is being called at that moment.</p>
<p>This allows me to see where most of the time is spent in an app so I can optimize it.</p>
<p>When using python, however, sample isn't so helpful, since it's sampling the C functions of th... | 3 | 2009-01-22T03:07:25Z | 467,932 | <p>Python includes a built-in set of <a href="http://docs.python.org/library/profile.html" rel="nofollow">profiling tools</a>. In particular, you can run cProfile on an arbitrary python script from the command-line:</p>
<pre><code>$ python -m cProfile myscript.py
</code></pre>
<p>Much more elaborate usage is availabl... | 4 | 2009-01-22T03:11:30Z | [
"python",
"performance",
"sample"
] |
Adding a generic image field onto a ModelForm in django | 467,985 | <p>I have two models, <code>Room</code> and <code>Image</code>. <code>Image</code> is a generic model that can tack onto any other model. I want to give users a form to upload an image when they post information about a room. I've written code that works, but I'm afraid I've done it the hard way, and specifically in... | 2 | 2009-01-22T03:45:49Z | 468,787 | <p>Why don't you do just use a ImageField? I don't see the need for the "Image" class.</p>
<pre><code># model
class Room(models.Model):
name = models.CharField(max_length=50)
image = models.ImageField(upload_to="uploads/images/")
# form
from django import forms
class UploadFileForm(forms.Form):
name = f... | 4 | 2009-01-22T11:39:09Z | [
"python",
"django",
"django-forms"
] |
Adding a generic image field onto a ModelForm in django | 467,985 | <p>I have two models, <code>Room</code> and <code>Image</code>. <code>Image</code> is a generic model that can tack onto any other model. I want to give users a form to upload an image when they post information about a room. I've written code that works, but I'm afraid I've done it the hard way, and specifically in... | 2 | 2009-01-22T03:45:49Z | 468,889 | <p>You don't have to use the Image class. As <a href="http://stackoverflow.com/users/30300/dzpm">DZPM</a> suggested, convert the image field to an ImageField. You also need to make some changes to the view.</p>
<p>Instead of using an upload handler, you can create a Image object with the uploaded data and attach the I... | 1 | 2009-01-22T12:12:45Z | [
"python",
"django",
"django-forms"
] |
Adding a generic image field onto a ModelForm in django | 467,985 | <p>I have two models, <code>Room</code> and <code>Image</code>. <code>Image</code> is a generic model that can tack onto any other model. I want to give users a form to upload an image when they post information about a room. I've written code that works, but I'm afraid I've done it the hard way, and specifically in... | 2 | 2009-01-22T03:45:49Z | 531,471 | <p>What about using two forms on the page: one for the room and one for the image?</p>
<p>You'll just have to make the generic foreign key fields of the image form not required, and fill in their values in the view after saving the room.</p>
| 0 | 2009-02-10T08:28:03Z | [
"python",
"django",
"django-forms"
] |
Adding a generic image field onto a ModelForm in django | 467,985 | <p>I have two models, <code>Room</code> and <code>Image</code>. <code>Image</code> is a generic model that can tack onto any other model. I want to give users a form to upload an image when they post information about a room. I've written code that works, but I'm afraid I've done it the hard way, and specifically in... | 2 | 2009-01-22T03:45:49Z | 531,501 | <p>Django does support your use case at least up to a point:</p>
<ul>
<li>formsets display repeated forms</li>
<li>model formsets handle repeated model forms</li>
<li>inline formsets bind model formsets to related objects of an instance</li>
<li><em>generic inline formsets</em> do the same for generic relations</li>
<... | 0 | 2009-02-10T08:38:50Z | [
"python",
"django",
"django-forms"
] |
Adding a generic image field onto a ModelForm in django | 467,985 | <p>I have two models, <code>Room</code> and <code>Image</code>. <code>Image</code> is a generic model that can tack onto any other model. I want to give users a form to upload an image when they post information about a room. I've written code that works, but I'm afraid I've done it the hard way, and specifically in... | 2 | 2009-01-22T03:45:49Z | 549,978 | <p>I found this page look for a solution to this same problem.</p>
<p>Here is my info -- hopefully helps some.</p>
<p>MODELS: Image, Review, Manufacturer, Profile</p>
<p>I want Review, Manufacturer, Profile to have a relationship to the Image model. But you have to beable to have multiple Images per object. (Ie, One... | 0 | 2009-02-14T23:26:50Z | [
"python",
"django",
"django-forms"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.