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 |
|---|---|---|---|---|---|---|---|---|---|
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 2,084,521 | <p>What about escape sequences?</p>
<pre><code>print(chr(27) + "[2J")
</code></pre>
| 47 | 2010-01-18T07:38:09Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 2,084,525 | <p><code>python -c "from os import system; system('clear')"</code></p>
| 2 | 2010-01-18T07:40:02Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 2,084,560 | <p>If you are on a Linux/UNIX system then printing the ANSI escape sequence to clear the screen should do the job. You will also want to move cursor to the top of the screen. This will work on any terminal that supports ANSI.</p>
<pre><code>import sys
sys.stderr.write("\x1b[2J\x1b[H")
</code></pre>
<p>This will not... | 22 | 2010-01-18T07:50:16Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 2,084,592 | <p>you can make your own. this will not be dependent on your terminal, or OS type.</p>
<pre><code>def clear(num):
for i in range(num): print
clear(80)
print "hello"
</code></pre>
| 0 | 2010-01-18T07:56:59Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 2,084,628 | <p>A simple and cross-platform solution would be to use either the <code>cls</code> command on Windows, or <code>clear</code> on Unix systems. Used with <a href="http://docs.python.org/3/library/os.html#os.system"><code>os.system</code></a>, this makes a nice one-liner:</p>
<pre><code>import os
os.system('cls' if os.n... | 160 | 2010-01-18T08:09:07Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 4,808,001 | <p>If all you need is to clear the screen, this is probably good enough. The problem is there's not even a 100% cross platform way of doing this across linux versions. The problem is the implementations of the terminal all support slightly different things. I'm fairly sure that "clear" will work everywhere. But the mor... | 1 | 2011-01-26T17:50:06Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 4,808,046 | <p>You could try to rely on clear but it might not be available on all Linux distributions. On windows use cls as you mentionned.</p>
<pre><code>import subprocess
import platform
def clear():
subprocess.Popen( "cls" if platform.system() == "Windows" else "clear", shell=True)
clear()
</code></pre>
<p>Note: It co... | 6 | 2011-01-26T17:54:10Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 4,808,134 | <p>A perhaps cheesy way to clear the screen, but one that will work on any platform I know of, is as follows:</p>
<pre><code>for i in xrange(0,100):
print ""
</code></pre>
| 0 | 2011-01-26T18:04:35Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 16,299,506 | <p>This will clear 25 new lines:</p>
<pre><code>def clear():
print(' \n' * 25)
clear()
</code></pre>
<p>I use eclipse with pydev. I like the newline solution better than the <strong>for num in range</strong> . The <strong>for</strong> loop throws warnings, while the print newline doesn't.
If you want to specify... | 1 | 2013-04-30T12:05:53Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 17,157,446 | <p>For windows, on the interpreter COMMAND LINE ONLY (NOT THE GUI)!!! Simply type:
(Remember to use proper indentation with python): </p>
<pre><code>import os
def clear():
os.system('cls')
</code></pre>
<p>Every time you type clear() on the shell (COMMAND LINE), it will clear the screen on your shell. If you exit... | -1 | 2013-06-17T21:48:45Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 18,128,909 | <p>By default, <code>os.system("clear")</code>/<code>os.system("cls")</code> will return an int type as 0.
We can completely clear the screen by assigning it to a variable and deleting that.</p>
<pre><code>def clear():
if (os.name == 'nt'):
c = os.system('cls')
else:
c = os.system('clear')
... | -2 | 2013-08-08T14:39:12Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 21,471,101 | <p>This function works in gnome-terminal because, by default, it recognizes ANSI escape sequences. It gives you a CLEAN PROMPT <code>rows_max</code> distance from the bottom of the terminal, but also precisely from where it was called. Gives you complete control over how much to clear.</p>
<pre><code>def clear(rows=-1... | 3 | 2014-01-31T01:45:04Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 21,916,027 | <p>this works on all platforms and it should work in python 2 and 3 I know it works in 2 though</p>
<pre><code>def clear(number ):
for i in range(900):
print(" ")
</code></pre>
<p>then to clear just type clear()</p>
| -2 | 2014-02-20T18:05:34Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 23,075,152 | <p>As a wise person once posted, for at least Linux, you can do the Python equivalent of this, which you can use on the command-line. It will clear the screen more than the Linux <code>clear</code> command (such that you can't scroll up to see your text):</p>
<pre><code>printf "\033c"
</code></pre>
<p>For Windows you... | 10 | 2014-04-15T05:14:02Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 23,722,984 | <p>I would do it in this way to make it look more like bash:</p>
<p>Just create a file named .pythonstartup at Home directory and use poke's answer in a function</p>
<p>On Linux:</p>
<pre><code>echo "from subprocess import call
def clear(int=None):
call('clear')
if int == 0:
exit()
clear()" >>... | 0 | 2014-05-18T14:27:07Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 23,980,136 | <p>A Pure Python solution.<br>
Does not rely on either ANSI, or external commands.<br>
Only your terminal has to have the ability to tell you how many lines are in view.</p>
<pre><code>from shutil import get_terminal_size
print("\n" * get_terminal_size().lines, end='')
</code></pre>
<p>Python version >= 3.3.0</p>
| 3 | 2014-06-01T12:58:13Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 26,639,250 | <p>Why hasn't anyone talked about just simply doing <kbd>Ctrl</kbd>+<kbd>L</kbd>.<br>
Surely the simplest way of clearing screen.</p>
| 20 | 2014-10-29T19:44:33Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 36,941,376 | <p>As for me, the most elegant variant:</p>
<pre><code>import os
os.system('cls||clear')
</code></pre>
| 0 | 2016-04-29T14:48:25Z | [
"python"
] |
clear terminal in python | 2,084,508 | <p>Does any standard "comes with batteries" method exist to clear the terminal screen from a python script, or do I have to go curses (the libraries, not the words) ?</p>
| 91 | 2010-01-18T07:34:58Z | 39,096,404 | <p>you can use call function to execute terminal's commands :</p>
<pre><code>from subprocess import call
call("clear")
</code></pre>
| 0 | 2016-08-23T08:44:17Z | [
"python"
] |
sendinput to directinput(like games) | 2,084,634 | <p>I'm trying to simulate keypress to my games that use direct input(I guess).
<br><br>
I googled around and I found out the method SendIput().<br>
It work fine if I try to send keypress to notepad.exe but nothing happend when I tried to games.<br>
I checked this site<br>
<a href="http://www.elitepvpers.de/forum/war-ha... | 2 | 2010-01-18T08:11:11Z | 2,084,685 | <p>It seems you are looking for a Python answer, but personally I would try using <a href="http://www.autohotkey.com/" rel="nofollow">AutoHotkey</a>. Its scripting language is on the ugly side, but rather easy to use. There are forum posts (both on Warhammer forums and AutoHotkey forums) to indicate that other Warham... | 0 | 2010-01-18T08:27:19Z | [
"python",
"c",
"keypress",
"directinput",
"sendinput"
] |
How to extract links from a webpage using lxml, XPath and Python? | 2,084,670 | <p>I've got this xpath query:</p>
<pre><code>/html/body//tbody/tr[*]/td[*]/a[@title]/@href
</code></pre>
<p>It extracts all the links with the title attribute - and gives the <code>href</code> in <a href="https://addons.mozilla.org/en-US/firefox/addon/1095" rel="nofollow">FireFox's Xpath checker add-on</a>.</p>
<p>H... | 5 | 2010-01-18T08:22:26Z | 2,084,852 | <p>I was able to make it work with the following code:</p>
<pre><code>from lxml import html, etree
from StringIO import StringIO
html_string = '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head/>
<body>
<t... | 8 | 2010-01-18T09:03:58Z | [
"python",
"screen-scraping",
"hyperlink",
"lxml",
"extraction"
] |
How to extract links from a webpage using lxml, XPath and Python? | 2,084,670 | <p>I've got this xpath query:</p>
<pre><code>/html/body//tbody/tr[*]/td[*]/a[@title]/@href
</code></pre>
<p>It extracts all the links with the title attribute - and gives the <code>href</code> in <a href="https://addons.mozilla.org/en-US/firefox/addon/1095" rel="nofollow">FireFox's Xpath checker add-on</a>.</p>
<p>H... | 5 | 2010-01-18T08:22:26Z | 8,394,365 | <p>Firefox <a href="http://doc.scrapy.org/en/latest/topics/firefox.html#caveats-with-inspecting-the-live-browser-dom" rel="nofollow">adds additional html tags</a> to the html when it renders, making the xpath returned by the firebug tool inconsistent with the actual html returned by the server (and what urllib/2 will r... | 2 | 2011-12-06T01:48:51Z | [
"python",
"screen-scraping",
"hyperlink",
"lxml",
"extraction"
] |
What is the difference between these codes, and what does the repr do? | 2,084,728 | <p>1.</p>
<pre><code>>>> s = u"4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf"
>>> print s
4-12ä¸ªè±æåæ¯ãæ°ååä¸å线
>>> print repr(s)
u'4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf'
</code></pre>
<p>2.</p>
<pre><... | 3 | 2010-01-18T08:38:06Z | 2,084,738 | <p>Regarding repr</p>
<pre><code>>>> help(repr)
Help on built-in function repr in module __builtin__:
repr(...)
repr(object) -> string
Return the canonical string representation of the object.
For most object types, eval(repr(object)) == object.
</code></pre>
| 1 | 2010-01-18T08:40:31Z | [
"python"
] |
What is the difference between these codes, and what does the repr do? | 2,084,728 | <p>1.</p>
<pre><code>>>> s = u"4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf"
>>> print s
4-12ä¸ªè±æåæ¯ãæ°ååä¸å线
>>> print repr(s)
u'4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf'
</code></pre>
<p>2.</p>
<pre><... | 3 | 2010-01-18T08:38:06Z | 2,084,754 | <p>In the first case, the Python interpreter has automatically decoded the bytes passed to it in the characters by the terminal encoding since it is a unicode literal. Printing the <code>repr()</code> of that yields Unicode escape sequences.</p>
<p>In the second case, no decoding is done since it is a str literal, and... | 1 | 2010-01-18T08:44:08Z | [
"python"
] |
What is the difference between these codes, and what does the repr do? | 2,084,728 | <p>1.</p>
<pre><code>>>> s = u"4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf"
>>> print s
4-12ä¸ªè±æåæ¯ãæ°ååä¸å线
>>> print repr(s)
u'4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf'
</code></pre>
<p>2.</p>
<pre><... | 3 | 2010-01-18T08:38:06Z | 2,085,276 | <p>In the first case, you are getting the repr of a unicode object. This is conceptually a series of unicode characters, and the repr is giving you the sequence of unicode codepoints for these characters as an escape sequence. ie '\u4e2a' is codepoint 20010 (0x4e2a is the hexidecimal representation), which is display... | 1 | 2010-01-18T10:24:04Z | [
"python"
] |
What is the difference between these codes, and what does the repr do? | 2,084,728 | <p>1.</p>
<pre><code>>>> s = u"4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf"
>>> print s
4-12ä¸ªè±æåæ¯ãæ°ååä¸å线
>>> print repr(s)
u'4-12\u4e2a\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf'
</code></pre>
<p>2.</p>
<pre><... | 3 | 2010-01-18T08:38:06Z | 2,086,460 | <p>I'll take a stab at this, 'repr' is the machine representation of the object while 'print' shows the human readable representation of the object. There are built in methods '<strong>repr</strong>', '<strong>str</strong>', and '<strong>unicode</strong>' that can be used by programmers to implement the different print... | 2 | 2010-01-18T13:59:19Z | [
"python"
] |
Running syncdb on Django project not working: Can't create/write to file | 2,084,760 | <p>When I run:</p>
<pre><code>$ python manage.py syncdb
</code></pre>
<p>I get the following output:</p>
<pre><code>Creating table auth_permission
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/mana... | 1 | 2010-01-18T08:45:00Z | 2,084,880 | <p>This might help:</p>
<blockquote>
<p>agos@server:~$ perror 2<br>
OS error code 2: No such file or directory</p>
</blockquote>
<p>Is your MySQL configured correctly? Try querying it yourself via <code>mysql</code> command.<br>
Also, as luc suggested in the comment, try with sqlite.</p>
| 2 | 2010-01-18T09:10:05Z | [
"python",
"mysql",
"django"
] |
Running syncdb on Django project not working: Can't create/write to file | 2,084,760 | <p>When I run:</p>
<pre><code>$ python manage.py syncdb
</code></pre>
<p>I get the following output:</p>
<pre><code>Creating table auth_permission
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/mana... | 1 | 2010-01-18T08:45:00Z | 2,085,039 | <p>The question was how to debug the problem and as already pointed out by Agos, Errno 2 is 'No such file or directory'. You might want to look in the data directory of MySQL and check if the directory is actually there and has correct permissions</p>
<pre><code>shell> cd /usr/local/mysql/data/
shell> ls -ld *
d... | 4 | 2010-01-18T09:40:12Z | [
"python",
"mysql",
"django"
] |
timeout for urllib2.urlopen() in pre Python 2.6 versions | 2,084,782 | <p>The <a href="http://docs.python.org/library/urllib2.html">urllib2 documentation</a> says that <em>timeout</em> parameter was added in Python 2.6. Unfortunately my code base has been running on Python 2.5 and 2.4 platforms.</p>
<p>Is there any alternate way to simulate the timeout? All I want to do is allow the code... | 28 | 2010-01-18T08:49:58Z | 2,084,902 | <p>I think your best choice is to patch (or deploy an local version of) your urllib2 with <a href="http://svn.python.org/view/python/branches/release26-maint/Lib/urllib2.py?r1=55389&r2=55792" rel="nofollow">the change from the 2.6 maintenance branch</a></p>
<p>The file should be in <code>/usr/lib/python2.4/urllib... | 2 | 2010-01-18T09:13:04Z | [
"python",
"urllib2",
"urlopen"
] |
timeout for urllib2.urlopen() in pre Python 2.6 versions | 2,084,782 | <p>The <a href="http://docs.python.org/library/urllib2.html">urllib2 documentation</a> says that <em>timeout</em> parameter was added in Python 2.6. Unfortunately my code base has been running on Python 2.5 and 2.4 platforms.</p>
<p>Is there any alternate way to simulate the timeout? All I want to do is allow the code... | 28 | 2010-01-18T08:49:58Z | 2,084,938 | <p>I use httplib from the standard library. It has a dead simple API, but only handles http as you might guess. IIUC urllib uses httplib to implement the http stuff.</p>
| 1 | 2010-01-18T09:19:05Z | [
"python",
"urllib2",
"urlopen"
] |
timeout for urllib2.urlopen() in pre Python 2.6 versions | 2,084,782 | <p>The <a href="http://docs.python.org/library/urllib2.html">urllib2 documentation</a> says that <em>timeout</em> parameter was added in Python 2.6. Unfortunately my code base has been running on Python 2.5 and 2.4 platforms.</p>
<p>Is there any alternate way to simulate the timeout? All I want to do is allow the code... | 28 | 2010-01-18T08:49:58Z | 2,086,596 | <p>you can set a global timeout for all socket operations (including HTTP requests) by using:</p>
<p><a href="http://docs.python.org/library/socket.html#socket.setdefaulttimeout"><code>socket.setdefaulttimeout()</code></a></p>
<p>like this:</p>
<pre><code>import urllib2
import socket
socket.setdefaulttimeout(30)
f =... | 57 | 2010-01-18T14:19:07Z | [
"python",
"urllib2",
"urlopen"
] |
timeout for urllib2.urlopen() in pre Python 2.6 versions | 2,084,782 | <p>The <a href="http://docs.python.org/library/urllib2.html">urllib2 documentation</a> says that <em>timeout</em> parameter was added in Python 2.6. Unfortunately my code base has been running on Python 2.5 and 2.4 platforms.</p>
<p>Is there any alternate way to simulate the timeout? All I want to do is allow the code... | 28 | 2010-01-18T08:49:58Z | 5,482,145 | <p>Well, the way timeout is handled in either 2.4 or 2.6 is the same. If you open the urllib2.py file in 2.6 u would see that it takes an extra argument as timeout and handles it using the socket.defaulttimeout() method as mentioned is answer 1. </p>
<p>So you really need not update your urllib2.py in that case.</p>
| 0 | 2011-03-30T05:13:55Z | [
"python",
"urllib2",
"urlopen"
] |
timeout for urllib2.urlopen() in pre Python 2.6 versions | 2,084,782 | <p>The <a href="http://docs.python.org/library/urllib2.html">urllib2 documentation</a> says that <em>timeout</em> parameter was added in Python 2.6. Unfortunately my code base has been running on Python 2.5 and 2.4 platforms.</p>
<p>Is there any alternate way to simulate the timeout? All I want to do is allow the code... | 28 | 2010-01-18T08:49:58Z | 9,918,050 | <p>With considerable irritation, you can override the httplib.HTTPConnection class that the urllib2.HTTPHandler uses.</p>
<pre><code>def urlopen_with_timeout(url, data=None, timeout=None):
# Create these two helper classes fresh each time, since
# timeout needs to be in the closure.
class TimeoutHTTPConnection(... | 4 | 2012-03-29T01:41:37Z | [
"python",
"urllib2",
"urlopen"
] |
timeout for urllib2.urlopen() in pre Python 2.6 versions | 2,084,782 | <p>The <a href="http://docs.python.org/library/urllib2.html">urllib2 documentation</a> says that <em>timeout</em> parameter was added in Python 2.6. Unfortunately my code base has been running on Python 2.5 and 2.4 platforms.</p>
<p>Is there any alternate way to simulate the timeout? All I want to do is allow the code... | 28 | 2010-01-18T08:49:58Z | 10,188,138 | <p>You must set timeout in two places.</p>
<pre><code>import urllib2
import socket
socket.setdefaulttimeout(30)
f = urllib2.urlopen('http://www.python.org/', timeout=30)
</code></pre>
| 1 | 2012-04-17T08:57:59Z | [
"python",
"urllib2",
"urlopen"
] |
Python matplotlib graph problem | 2,084,805 | <pre><code>import matplotlib
import matplotlib.pyplot as plt
import pylab as PL
matplotlib.rcParams['axes.unicode_minus'] = False
fig = plt.figure()
ax = fig.add_subplot(111)
PL.loglog(a, b,'o')
ax.set_title('Graph Example')
plt.show()
</code></pre>
<p>1) This displays the graph with points on the plot. Is there a wa... | 0 | 2010-01-18T08:56:26Z | 2,085,335 | <ol>
<li>See @Ber's comment</li>
<li>Simply call <code>PL.loglog</code> multiple times.</li>
</ol>
| 1 | 2010-01-18T10:35:18Z | [
"python"
] |
How can I create 1000 files that I can use to test a script? | 2,084,832 | <p>I would like to create 1000+ text files with some text to test a script, how to create this much if text files at a go using shell script or Perl. Please could anyone help me.</p>
| 8 | 2010-01-18T09:00:37Z | 2,084,894 | <p>I don't know in shell or perl but in python would be:</p>
<pre><code>#!/usr/bin/python
for i in xrange(1000):
with open('file%0.3d' %i,'w') as fd:
fd.write('some text')
</code></pre>
<p>I think is pretty straightforward what it does.</p>
| 1 | 2010-01-18T09:12:09Z | [
"python",
"perl",
"shell",
"scripting"
] |
How can I create 1000 files that I can use to test a script? | 2,084,832 | <p>I would like to create 1000+ text files with some text to test a script, how to create this much if text files at a go using shell script or Perl. Please could anyone help me.</p>
| 8 | 2010-01-18T09:00:37Z | 2,084,939 | <pre><code>#!/bin/bash
seq 1 1000 | split -l 1 -a 3 -d - file
</code></pre>
<p>Above will create 1000 files with each file having a number from 1 to 1000. The files will be named file000 ... file999</p>
| 6 | 2010-01-18T09:19:28Z | [
"python",
"perl",
"shell",
"scripting"
] |
How can I create 1000 files that I can use to test a script? | 2,084,832 | <p>I would like to create 1000+ text files with some text to test a script, how to create this much if text files at a go using shell script or Perl. Please could anyone help me.</p>
| 8 | 2010-01-18T09:00:37Z | 2,084,946 | <pre><code>for i in {0001..1000}
do
echo "some text" > "file_${i}.txt"
done
</code></pre>
<p>or if you want to use Python <2.6</p>
<pre><code>for x in range(1000):
open("file%03d.txt" % x,"w").write("some text")
</code></pre>
| 7 | 2010-01-18T09:20:05Z | [
"python",
"perl",
"shell",
"scripting"
] |
How can I create 1000 files that I can use to test a script? | 2,084,832 | <p>I would like to create 1000+ text files with some text to test a script, how to create this much if text files at a go using shell script or Perl. Please could anyone help me.</p>
| 8 | 2010-01-18T09:00:37Z | 2,084,962 | <pre><code>#!/bin/bash
for suf in $(seq -w 1000)
do
cat << EOF > myfile.$suf
this is my text file
there are many like it
but this one is mine.
EOF
done
</code></pre>
| 2 | 2010-01-18T09:24:39Z | [
"python",
"perl",
"shell",
"scripting"
] |
How can I create 1000 files that I can use to test a script? | 2,084,832 | <p>I would like to create 1000+ text files with some text to test a script, how to create this much if text files at a go using shell script or Perl. Please could anyone help me.</p>
| 8 | 2010-01-18T09:00:37Z | 2,085,267 | <p>You can use only Bash with no externals and still be able to pad the numbers so the filenames sort properly (if needed):</p>
<pre><code>read -r -d '' text << 'EOF'
Some text for
my files
EOF
for i in {1..1000}
do
printf -v filename "file%04d" "$i"
echo "$text" > "$filename"
done
</code></pre>
<p>... | 1 | 2010-01-18T10:22:25Z | [
"python",
"perl",
"shell",
"scripting"
] |
How can I create 1000 files that I can use to test a script? | 2,084,832 | <p>I would like to create 1000+ text files with some text to test a script, how to create this much if text files at a go using shell script or Perl. Please could anyone help me.</p>
| 8 | 2010-01-18T09:00:37Z | 2,086,436 | <p>In Perl:</p>
<pre><code>use strict;
use warnings;
for my $i (1..1000) {
open(my $out,">",sprintf("file%04d",$i));
print $out "some text\n";
close $out;
}
</code></pre>
<p>Why the first 2 lines? Because they are good practice so I use them even in 1-shot programs like these.</p>
<p>Regards,
Offer</p>
| 4 | 2010-01-18T13:54:31Z | [
"python",
"perl",
"shell",
"scripting"
] |
How can I create 1000 files that I can use to test a script? | 2,084,832 | <p>I would like to create 1000+ text files with some text to test a script, how to create this much if text files at a go using shell script or Perl. Please could anyone help me.</p>
| 8 | 2010-01-18T09:00:37Z | 2,087,079 | <p>For variety:</p>
<pre><code>#!/usr/bin/perl
use strict; use warnings;
use File::Slurp;
write_file $_, "$_\n" for map sprintf('file%04d.txt', $_), 1 .. 1000;
</code></pre>
| 3 | 2010-01-18T15:32:11Z | [
"python",
"perl",
"shell",
"scripting"
] |
How can I create 1000 files that I can use to test a script? | 2,084,832 | <p>I would like to create 1000+ text files with some text to test a script, how to create this much if text files at a go using shell script or Perl. Please could anyone help me.</p>
| 8 | 2010-01-18T09:00:37Z | 2,089,245 | <p>Here is a short command-line Perl program.</p>
<pre><code>perl -E'say $_ $_ for grep {open $_, ">f$_"} 1..1000'
</code></pre>
| 0 | 2010-01-18T21:11:11Z | [
"python",
"perl",
"shell",
"scripting"
] |
How can I create 1000 files that I can use to test a script? | 2,084,832 | <p>I would like to create 1000+ text files with some text to test a script, how to create this much if text files at a go using shell script or Perl. Please could anyone help me.</p>
| 8 | 2010-01-18T09:00:37Z | 14,595,114 | <p>Just take any big file that has more than 1000 bytes (for 1000 files with content). There are lots of them on your computer. Then do (for example):</p>
<pre><code>split -n 1000 /usr/bin/firefox
</code></pre>
<p>This is instantly fast.</p>
<p>Or a bigger file:</p>
<pre><code>split -n 10000 /usr/bin/cat
</code></p... | 1 | 2013-01-30T01:17:00Z | [
"python",
"perl",
"shell",
"scripting"
] |
Vim's Omnicompletion with Python just doesn't work | 2,084,875 | <p>I've searched around for an hour, both on Stack Overflow and elsewhere. Alas! Please help. Vim's omnicompletion just <em>doesn't work</em>.</p>
<ol>
<li><p>I have Vim 7.2 compiled with Python support.</p></li>
<li><p><code>filetype plugin on</code> is in my <code>.vimrc</code>.</p></li>
<li><p>When a <code>.py</cod... | 46 | 2010-01-18T09:08:03Z | 2,086,309 | <p>What module contains the symbol you are trying to complete? Is it in the python stdlib? Or is it a third-party module?</p>
<p>Make sure that the module/package is in the PYTHONPATH.</p>
<p>In Vim, do:</p>
<pre><code>:python import sys
:python print sys.path
</code></pre>
<p>To add the module's directory:</p>
<p... | 11 | 2010-01-18T13:35:29Z | [
"python",
"vim",
"autocomplete",
"omnicomplete"
] |
Vim's Omnicompletion with Python just doesn't work | 2,084,875 | <p>I've searched around for an hour, both on Stack Overflow and elsewhere. Alas! Please help. Vim's omnicompletion just <em>doesn't work</em>.</p>
<ol>
<li><p>I have Vim 7.2 compiled with Python support.</p></li>
<li><p><code>filetype plugin on</code> is in my <code>.vimrc</code>.</p></li>
<li><p>When a <code>.py</cod... | 46 | 2010-01-18T09:08:03Z | 2,245,120 | <p>Since you were prudent and made certain your code is reachable by the PYTHONPATH, per codeape's suggestion, is there a possibility that you are running into the <a href="http://groups.google.com/group/vim_dev/browse_thread/thread/58191d176ebd9722/d9cd31cee304b7df?pli=1" rel="nofollow"><code>import</code> bug for Vim... | 8 | 2010-02-11T14:38:15Z | [
"python",
"vim",
"autocomplete",
"omnicomplete"
] |
Vim's Omnicompletion with Python just doesn't work | 2,084,875 | <p>I've searched around for an hour, both on Stack Overflow and elsewhere. Alas! Please help. Vim's omnicompletion just <em>doesn't work</em>.</p>
<ol>
<li><p>I have Vim 7.2 compiled with Python support.</p></li>
<li><p><code>filetype plugin on</code> is in my <code>.vimrc</code>.</p></li>
<li><p>When a <code>.py</cod... | 46 | 2010-01-18T09:08:03Z | 2,247,206 | <p>Have you tried using <code><C_x><C-]></code> ?</p>
| 0 | 2010-02-11T19:40:53Z | [
"python",
"vim",
"autocomplete",
"omnicomplete"
] |
Vim's Omnicompletion with Python just doesn't work | 2,084,875 | <p>I've searched around for an hour, both on Stack Overflow and elsewhere. Alas! Please help. Vim's omnicompletion just <em>doesn't work</em>.</p>
<ol>
<li><p>I have Vim 7.2 compiled with Python support.</p></li>
<li><p><code>filetype plugin on</code> is in my <code>.vimrc</code>.</p></li>
<li><p>When a <code>.py</cod... | 46 | 2010-01-18T09:08:03Z | 3,106,405 | <p><code>c-x c-n</code> works to get the list of members of an object.</p>
| 0 | 2010-06-24T00:01:43Z | [
"python",
"vim",
"autocomplete",
"omnicomplete"
] |
Vim's Omnicompletion with Python just doesn't work | 2,084,875 | <p>I've searched around for an hour, both on Stack Overflow and elsewhere. Alas! Please help. Vim's omnicompletion just <em>doesn't work</em>.</p>
<ol>
<li><p>I have Vim 7.2 compiled with Python support.</p></li>
<li><p><code>filetype plugin on</code> is in my <code>.vimrc</code>.</p></li>
<li><p>When a <code>.py</cod... | 46 | 2010-01-18T09:08:03Z | 5,192,351 | <p>I used supertab (http://www.vim.org/scripts/script.php?script_id=1643)</p>
<p>Since C-x C-o is a bit frustrating to use</p>
<p>in .vimrc:</p>
<pre><code>let g:SuperTabDefaultCompletionType = "<c-x><c-o>"
</code></pre>
<p>then just use Tabb for omnicompletion</p>
| 0 | 2011-03-04T10:11:45Z | [
"python",
"vim",
"autocomplete",
"omnicomplete"
] |
Vim's Omnicompletion with Python just doesn't work | 2,084,875 | <p>I've searched around for an hour, both on Stack Overflow and elsewhere. Alas! Please help. Vim's omnicompletion just <em>doesn't work</em>.</p>
<ol>
<li><p>I have Vim 7.2 compiled with Python support.</p></li>
<li><p><code>filetype plugin on</code> is in my <code>.vimrc</code>.</p></li>
<li><p>When a <code>.py</cod... | 46 | 2010-01-18T09:08:03Z | 6,895,757 | <p>Sounds like the questioner has long since gone to the dark side*, but for what it's worth I've just had this symptom, and in my case the cause was that a module I was using relied on Python 2.7 but my version of Vim was compiled with Python 2.5.</p>
<p>To diagnose I tried <code>:python import mymodule</code>, which... | 9 | 2011-08-01T08:15:04Z | [
"python",
"vim",
"autocomplete",
"omnicomplete"
] |
Vim's Omnicompletion with Python just doesn't work | 2,084,875 | <p>I've searched around for an hour, both on Stack Overflow and elsewhere. Alas! Please help. Vim's omnicompletion just <em>doesn't work</em>.</p>
<ol>
<li><p>I have Vim 7.2 compiled with Python support.</p></li>
<li><p><code>filetype plugin on</code> is in my <code>.vimrc</code>.</p></li>
<li><p>When a <code>.py</cod... | 46 | 2010-01-18T09:08:03Z | 9,720,190 | <p>Having updated to Fedora 16 (but still compiling vim from source), omni completion stopped working with the same message as above. I "fixed" it by re-maping the keys. </p>
<pre><code>inoremap <C-space> <C-x><C-o>
</code></pre>
<p>in <code>~/.vimrc</code> and now it works again.</p>
| 2 | 2012-03-15T12:58:30Z | [
"python",
"vim",
"autocomplete",
"omnicomplete"
] |
Vim's Omnicompletion with Python just doesn't work | 2,084,875 | <p>I've searched around for an hour, both on Stack Overflow and elsewhere. Alas! Please help. Vim's omnicompletion just <em>doesn't work</em>.</p>
<ol>
<li><p>I have Vim 7.2 compiled with Python support.</p></li>
<li><p><code>filetype plugin on</code> is in my <code>.vimrc</code>.</p></li>
<li><p>When a <code>.py</cod... | 46 | 2010-01-18T09:08:03Z | 12,230,039 | <p>I had a similar problem with omni completion not working. In my case it turned out that the minibufexpl.vim plugin was interfering with omni completion. Here is how I found out:</p>
<p>Normal keyword completion works. Omni complete does not work for any language, not just Python. omnifunc is set correctly. After I ... | 2 | 2012-09-01T17:54:36Z | [
"python",
"vim",
"autocomplete",
"omnicomplete"
] |
How to deploy highly iterative updates | 2,084,969 | <p>I have a set of binary assets (swf files) each about 150Kb in size. I am developing them locally on my home computer and I want to periodically deploy them for review. My current strategy is:</p>
<ol>
<li>Copy the .swf's into a transfer directory that is also a hg (mercurial) repo.</li>
<li><code>hg push</code> the... | 0 | 2010-01-18T09:25:13Z | 2,085,042 | <p>to avoid <code>su www</code> I see two easy choices.</p>
<ul>
<li><p>make a folder writable to you and readable by www's group in some path that the web-server will be able to serve, then you can rsync to that folder from somewhere on your local machine.</p></li>
<li><p>put your public ssh key in www's authorized_k... | 1 | 2010-01-18T09:41:33Z | [
"python",
"osx",
"deployment",
"ubuntu",
"rsync"
] |
How to deploy highly iterative updates | 2,084,969 | <p>I have a set of binary assets (swf files) each about 150Kb in size. I am developing them locally on my home computer and I want to periodically deploy them for review. My current strategy is:</p>
<ol>
<li>Copy the .swf's into a transfer directory that is also a hg (mercurial) repo.</li>
<li><code>hg push</code> the... | 0 | 2010-01-18T09:25:13Z | 2,087,917 | <p>If you're at all comfortable in Python, I recommend <a href="http://fabfile.org" rel="nofollow">Fabric</a> for automated deployment scripts.</p>
<p>In addition to group permissions or ssh-ing as www (with key-based auth), a third solution to the permissions issue would be to add your user to /etc/sudoers and use su... | 1 | 2010-01-18T17:30:05Z | [
"python",
"osx",
"deployment",
"ubuntu",
"rsync"
] |
Database password requested when running "manage.py test" | 2,085,002 | <p>When I try to run </p>
<pre><code>manage.py test
</code></pre>
<p>a database password prompt shows.</p>
<p>Previously, tests would run without me having to enter the db password manaually.
I just updated my database to postgres 8.4. I assume it's some setting I'm forgetting.</p>
<p>How can I configure it to run... | 1 | 2010-01-18T09:32:51Z | 2,085,320 | <blockquote>
<p>I assume it's some setting I'm
forgetting.</p>
</blockquote>
<p>Not trying to make a fool out of you, but sometimes simple solutions are overlooked:
Did you set the DATABASE_PASSWORD setting in your settings.py file?</p>
| 0 | 2010-01-18T10:33:20Z | [
"python",
"django"
] |
Database password requested when running "manage.py test" | 2,085,002 | <p>When I try to run </p>
<pre><code>manage.py test
</code></pre>
<p>a database password prompt shows.</p>
<p>Previously, tests would run without me having to enter the db password manaually.
I just updated my database to postgres 8.4. I assume it's some setting I'm forgetting.</p>
<p>How can I configure it to run... | 1 | 2010-01-18T09:32:51Z | 2,087,965 | <p>Django tests use a different database; your DATABASE_NAME setting with "_test" appended. My first guess would be that somewhere in your Postgres authentication config (either in pg_hba.conf or in a ~/.pgpass file), you are allowing access to DATABASE_NAME with no password, but you don't have the same config for DATA... | 1 | 2010-01-18T17:37:03Z | [
"python",
"django"
] |
Error Handling in Python with SUDS | 2,085,128 | <p>I have been trying to control a camera through a wsdl file using SUDS. I have got the code working but I want to place error handling into the script. I have tried different exceptions but am unable to get the script working. When I enter an invalid coordinate I get an error. The code I am using is below followed by... | 11 | 2010-01-18T09:56:21Z | 2,085,160 | <p>You need to catch <a href="http://jortel.fedorapeople.org/suds/doc/suds.WebFault-class.html" rel="nofollow"><code>suds.WebFault</code></a> by the looks of that traceback. The error itself seems legitimate, IE, your requests are being executed correctly, but perhaps your parameters are wrong in the given context.</... | 1 | 2010-01-18T10:02:23Z | [
"python",
"web-services",
"suds"
] |
Error Handling in Python with SUDS | 2,085,128 | <p>I have been trying to control a camera through a wsdl file using SUDS. I have got the code working but I want to place error handling into the script. I have tried different exceptions but am unable to get the script working. When I enter an invalid coordinate I get an error. The code I am using is below followed by... | 11 | 2010-01-18T09:56:21Z | 2,085,187 | <p>If you want to catch that exception you should put</p>
<pre><code>try:
result = client.service.AbsoluteMove(token, dest, speed)
except suds.WebFault as detail:
...
</code></pre>
| 9 | 2010-01-18T10:06:00Z | [
"python",
"web-services",
"suds"
] |
Error Handling in Python with SUDS | 2,085,128 | <p>I have been trying to control a camera through a wsdl file using SUDS. I have got the code working but I want to place error handling into the script. I have tried different exceptions but am unable to get the script working. When I enter an invalid coordinate I get an error. The code I am using is below followed by... | 11 | 2010-01-18T09:56:21Z | 7,002,072 | <p>I believe you refer to a harmless diagnostic message in your comment. I could suppress messages from suds calling <code>logging.error()</code> by assigning <code>logging.INFO</code> to <code>basicConfig</code> and <code>logging.CRITICAL</code> to <code>suds.client</code>.</p>
<p><a href="https://fedorahosted.org/s... | 0 | 2011-08-09T19:50:32Z | [
"python",
"web-services",
"suds"
] |
Error Handling in Python with SUDS | 2,085,128 | <p>I have been trying to control a camera through a wsdl file using SUDS. I have got the code working but I want to place error handling into the script. I have tried different exceptions but am unable to get the script working. When I enter an invalid coordinate I get an error. The code I am using is below followed by... | 11 | 2010-01-18T09:56:21Z | 7,712,443 | <p>If you handled all exceptions and errors in your code and your code is working fine but still you are getting below message with your correct output. </p>
<p>Msg : "No handlers could be found for logger <code>suds.client</code> "</p>
<p>Then a simple solution is to add this line </p>
<pre class="lang-cpp prettypr... | 14 | 2011-10-10T12:02:31Z | [
"python",
"web-services",
"suds"
] |
Python: create graph based on degree correlation | 2,085,231 | <p>I want to create a graph using networkx which has positive or negative degree correlation.
Like a graph for a social network or citations in academic papers etc.
Can you suggest some function for this?</p>
| 2 | 2010-01-18T10:15:28Z | 2,085,282 | <p>If you are talking about producing a visual graph (diagram) you could look at using <a href="http://matplotlib.sourceforge.net/" rel="nofollow">matplotlib</a> to generate them. I'm not sure if there is going to be a single function that will do what you want (not enough detail) but its a comprehensive library used ... | 1 | 2010-01-18T10:26:23Z | [
"python"
] |
When loading a dll in Python does the dir function shows its methods? | 2,085,295 | <p>Does this code shows the methods from a dll?</p>
<pre><code>from ctypes import *
x = cdll.LoadLibrary("olari.dll")
dir(x)
</code></pre>
<p>if not, how can we see the .dll methods in python?</p>
| 2 | 2010-01-18T10:28:43Z | 2,085,325 | <p>No, it doesn't. But It can cache when you call, and will show in <code>dir</code> after that.</p>
<p>You could take a look this <a href="http://stackoverflow.com/questions/1128150/win32-api-to-enumerate-dll-export-functions">SO Thread</a>, even in Win32, seems like need to parse PE Header. I think python need to do... | 2 | 2010-01-18T10:34:12Z | [
"python",
"methods",
"dllimport"
] |
Pylons Custom Middleware return 404 | 2,085,334 | <p>I have the following code as a middleware in an pylons application:</p>
<pre><code>import testing.model as model
import re
from pylons.controllers.util import abort
class SubdomainCheckMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
... | 0 | 2010-01-18T10:35:16Z | 2,085,375 | <p>It's pretty straightforward to return a basic 404 in a WSGI app: </p>
<pre><code>if error:
start_response("404 Not Found", [('Content-type', 'text/plain')])
return ['Page not found']
</code></pre>
<p>If you want something more elaborate you could use some other middleware to handle errors for you. It actu... | 1 | 2010-01-18T10:41:54Z | [
"python",
"pylons",
"wsgi",
"paster"
] |
how-to apache 2.2 mod_fcgid set python path | 2,085,369 | <p>i have trouble with seting the python path or any other enviroment variable for mod_fcgid (solaris 10, glassfish apache 2.2)</p>
<p>I have it set in apache, but nothing in os.environ in the fcgi script:</p>
<pre><code>SetEnv PYTHONPATH "/opt/uusis/lib/python2.4/site-packages/:/usr/lib/python2.4/"
</code></pre>
<p... | 0 | 2010-01-18T10:40:31Z | 2,085,379 | <p>not quite sure if this help. <a href="http://httpd.apache.org/docs/2.0/env.html" rel="nofollow">http://httpd.apache.org/docs/2.0/env.html</a></p>
| 0 | 2010-01-18T10:42:30Z | [
"python",
"apache2",
"environment-variables",
"mod-fcgid"
] |
how-to apache 2.2 mod_fcgid set python path | 2,085,369 | <p>i have trouble with seting the python path or any other enviroment variable for mod_fcgid (solaris 10, glassfish apache 2.2)</p>
<p>I have it set in apache, but nothing in os.environ in the fcgi script:</p>
<pre><code>SetEnv PYTHONPATH "/opt/uusis/lib/python2.4/site-packages/:/usr/lib/python2.4/"
</code></pre>
<p... | 0 | 2010-01-18T10:40:31Z | 2,093,044 | <p>I found out that Solaris 10 glassfish apache 2.2 mod_fcgid has "DefaultInitEnv"</p>
<p>This is not documented in the apache mod_fcgid ...</p>
<p>Example:</p>
<pre><code>DefaultInitEnv PYTHONPATH "/opt/something/lib/python2.4/site-packages/:/usr/lib/python2.4/"
</code></pre>
| 0 | 2010-01-19T11:23:08Z | [
"python",
"apache2",
"environment-variables",
"mod-fcgid"
] |
populating data from xml file to a sqlite database using python | 2,085,430 | <p>I have a question related to some guidances to solve a problem. I have with me an xml file, I have to populate it into a database system (whatever, it might be sqlite, mysql) using scripting language: Python.</p>
<p>Does anyone have any idea on how to proceed?</p>
<ul>
<li>Which technologies I need to read further... | 5 | 2010-01-18T10:55:11Z | 2,085,657 | <p>If you are accustomed to DOM (tree) access to xml from other language, you may find useful these standard library modules (and their respective docs):</p>
<ul>
<li>xml.dom </li>
<li>xml.dom.minidom</li>
</ul>
<p>To save tha data to DB, you can use standard module sqlite3 or look for binding to mysql. Or you may wi... | 1 | 2010-01-18T11:34:28Z | [
"python",
"xml",
"database",
"sqlite",
"parsing"
] |
populating data from xml file to a sqlite database using python | 2,085,430 | <p>I have a question related to some guidances to solve a problem. I have with me an xml file, I have to populate it into a database system (whatever, it might be sqlite, mysql) using scripting language: Python.</p>
<p>Does anyone have any idea on how to proceed?</p>
<ul>
<li>Which technologies I need to read further... | 5 | 2010-01-18T10:55:11Z | 2,088,934 | <p>I recommend you study on <a href="http://effbot.org/zone/element-index.htm" rel="nofollow">ElementTree</a> for parsing your XML file into memory (parse it all, then emit it all to a SQL DB, is probably easier, but element-tree also allows incremental operation if your file is huge) -- it's part of the standard Pytho... | 7 | 2010-01-18T20:22:27Z | [
"python",
"xml",
"database",
"sqlite",
"parsing"
] |
populating data from xml file to a sqlite database using python | 2,085,430 | <p>I have a question related to some guidances to solve a problem. I have with me an xml file, I have to populate it into a database system (whatever, it might be sqlite, mysql) using scripting language: Python.</p>
<p>Does anyone have any idea on how to proceed?</p>
<ul>
<li>Which technologies I need to read further... | 5 | 2010-01-18T10:55:11Z | 8,051,526 | <p>You can do it all by hand with <code>sqlite3</code> and <code>xmlstarlet</code>.<br></p>
<ul>
<li>convert xml to csv</li>
<li>import csv to db.</li>
</ul>
<p>(Maybe it's not your want. but it's handy)</p>
<pre><code># content of xml file
$ cat artist.xml
<results><artist><id>Ae2300d8b0232c06c<... | 5 | 2011-11-08T13:58:15Z | [
"python",
"xml",
"database",
"sqlite",
"parsing"
] |
How to read file headers in Python similar to C? | 2,085,464 | <p>I am new to Python. I am a C programmer by profession. I have file, whose header has some specific data, that I need to extract. For example, Byte 0-5 has a magic, Byte 6-8 has offset etc.</p>
<p>In C (An Example) :</p>
<pre><code>struct {
int32_t payload_offset,
int32_t len,
char *magic,
int32... | 5 | 2010-01-18T11:01:38Z | 2,085,491 | <p>One way is to use the python <code>struct</code> module, docs are <a href="http://docs.python.org/library/struct.html" rel="nofollow">here</a>.<br>
Another option, if you need something more powerful, is to use the awesome <a href="http://construct.wikispaces.com/" rel="nofollow">construct</a> library that can do th... | 6 | 2010-01-18T11:06:17Z | [
"python",
"file-io",
"header"
] |
How to read file headers in Python similar to C? | 2,085,464 | <p>I am new to Python. I am a C programmer by profession. I have file, whose header has some specific data, that I need to extract. For example, Byte 0-5 has a magic, Byte 6-8 has offset etc.</p>
<p>In C (An Example) :</p>
<pre><code>struct {
int32_t payload_offset,
int32_t len,
char *magic,
int32... | 5 | 2010-01-18T11:01:38Z | 2,085,496 | <p>This is typically done using the <a href="http://docs.python.org/library/struct.html" rel="nofollow">struct</a> module in Python. It allows you to extract values from packed binary representations, driven by format-specification strings that you provide.</p>
<p>You would load the data in using binary I/O into a str... | 3 | 2010-01-18T11:06:56Z | [
"python",
"file-io",
"header"
] |
Querying a view in SQLAlchemy | 2,085,592 | <p>I want to know if SQLAlchemy has problems querying a view. If I query the view with normal SQL on the server like:</p>
<pre><code>SELECT * FROM ViewMyTable WHERE index1 = '608_56_56';
</code></pre>
<p>I get a whole bunch of records. But with SQLAlchemy I get only the first one. But in the count is the correct numb... | 3 | 2010-01-18T11:24:54Z | 2,098,162 | <p>if you've mapped <code>ViewMyTable</code>, the query will only return rows that have a fully non-NULL primary key. This behavior is specific to versions 0.5 and lower - on 0.6, if any of the columns have a non-NULL in the primary key, the row is turned into an instance. Specify the flag <code>allow_null_pks=True... | 7 | 2010-01-20T00:06:36Z | [
"python",
"postgresql",
"sqlalchemy"
] |
Python : generate a graph for a social network | 2,085,676 | <p>I have installed matplotlib and networkx packages.
Can someone tell me the function present in these packages that can be used to generate a social network graph like graph for film actor collaborations, co-authorship or even a graph for a P2P network.</p>
| 2 | 2010-01-18T11:36:59Z | 2,085,727 | <p>I think that matplotlib is not too suitable for this task. Try <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a> instead. </p>
<p>Also, <a href="http://pyevolve.sourceforge.net/wordpress/?p=203" rel="nofollow">this post</a> shows how Christian S. Perone used <a href="http://ubietylab.net/ubig... | 3 | 2010-01-18T11:47:36Z | [
"python",
"social-networking"
] |
Python : generate a graph for a social network | 2,085,676 | <p>I have installed matplotlib and networkx packages.
Can someone tell me the function present in these packages that can be used to generate a social network graph like graph for film actor collaborations, co-authorship or even a graph for a P2P network.</p>
| 2 | 2010-01-18T11:36:59Z | 2,085,809 | <p>I would use <a href="http://code.google.com/p/pydot/" rel="nofollow">PyDot</a>, it's the pythton binding of the graphviz library.</p>
| 2 | 2010-01-18T12:02:32Z | [
"python",
"social-networking"
] |
Python : generate a graph for a social network | 2,085,676 | <p>I have installed matplotlib and networkx packages.
Can someone tell me the function present in these packages that can be used to generate a social network graph like graph for film actor collaborations, co-authorship or even a graph for a P2P network.</p>
| 2 | 2010-01-18T11:36:59Z | 2,086,297 | <p>Count this as a second vote for <a href="http://www.graphviz.org/" rel="nofollow">Graphviz</a>. The format is pretty simple, and the layout engine is powerful. Having installed Graphviz, you could then add PyDot to run things, or simply write your data to files with format showing the graph structure.</p>
<p>Look... | 1 | 2010-01-18T13:32:31Z | [
"python",
"social-networking"
] |
Python : generate a graph for a social network | 2,085,676 | <p>I have installed matplotlib and networkx packages.
Can someone tell me the function present in these packages that can be used to generate a social network graph like graph for film actor collaborations, co-authorship or even a graph for a P2P network.</p>
| 2 | 2010-01-18T11:36:59Z | 4,346,430 | <p>You could also use <a href="http://graph-tool.skewed.de" rel="nofollow">graph-tool</a> since it has an interface to graphviz, which is very easy to use. See the documentation in the website for more details.</p>
| 1 | 2010-12-03T14:22:26Z | [
"python",
"social-networking"
] |
Windows file creation date/time using python | 2,085,992 | <p>I need to get a file creation date&time using python. I tried:</p>
<pre><code>os.stat(r"path")[ST_CTIME]
</code></pre>
<p>But it is returning:</p>
<pre><code>1263538277
</code></pre>
<p>This is not the creation date time. Is there a way to do it?</p>
| 1 | 2010-01-18T12:31:50Z | 2,086,005 | <p>Why not?</p>
<pre><code>>>> import time
>>> time.ctime(1263538277)
'Fri Jan 15 04:51:17 2010'
</code></pre>
<p>Looks like a valid creation time to me.</p>
| 8 | 2010-01-18T12:34:24Z | [
"python",
"datetime"
] |
Windows file creation date/time using python | 2,085,992 | <p>I need to get a file creation date&time using python. I tried:</p>
<pre><code>os.stat(r"path")[ST_CTIME]
</code></pre>
<p>But it is returning:</p>
<pre><code>1263538277
</code></pre>
<p>This is not the creation date time. Is there a way to do it?</p>
| 1 | 2010-01-18T12:31:50Z | 2,086,009 | <p>Are you sure it isn't? Using <a href="http://www.unixtimestamp.com/index.php" rel="nofollow">unixtimestamp.com</a> it converts to "01/18/2010 @ 7:34am" which at least makes sense.</p>
<p>The timestamp is returned as a time in seconds from 1970-01-01.</p>
| 3 | 2010-01-18T12:35:19Z | [
"python",
"datetime"
] |
Windows file creation date/time using python | 2,085,992 | <p>I need to get a file creation date&time using python. I tried:</p>
<pre><code>os.stat(r"path")[ST_CTIME]
</code></pre>
<p>But it is returning:</p>
<pre><code>1263538277
</code></pre>
<p>This is not the creation date time. Is there a way to do it?</p>
| 1 | 2010-01-18T12:31:50Z | 2,086,011 | <p>See <a href="http://docs.python.org/library/os.html#os.stat" rel="nofollow">http://docs.python.org/library/os.html#os.stat</a></p>
<blockquote>
<p>st_ctime (platform dependent; time of most recent metadata change on Unix, or the time of creation on Windows)</p>
</blockquote>
<p>Everything is OK.</p>
| 0 | 2010-01-18T12:35:49Z | [
"python",
"datetime"
] |
Windows file creation date/time using python | 2,085,992 | <p>I need to get a file creation date&time using python. I tried:</p>
<pre><code>os.stat(r"path")[ST_CTIME]
</code></pre>
<p>But it is returning:</p>
<pre><code>1263538277
</code></pre>
<p>This is not the creation date time. Is there a way to do it?</p>
| 1 | 2010-01-18T12:31:50Z | 2,086,013 | <p>From <a href="http://bytes.com/topic/python/answers/520807-st_ctime-convert-yyyymmdd" rel="nofollow">bytes.com</a>:</p>
<pre><code>import os
import time
create_date = os.stat('/tmp/myfile.txt')[9]
print time.strftime("%Y-%m-%d", time.gmtime(create_date))
</code></pre>
<p>Which gives:</p>
<pre><code>2009-11-25
</c... | 5 | 2010-01-18T12:36:09Z | [
"python",
"datetime"
] |
Django Admin site TemplateSyntaxError at /admin/: name not defined | 2,086,016 | <p>I have an issue where, when I log in to the Django admin site, I get a template syntax error in /Library/Python/2.6/site-packages/django/template/debug.py in render_node, line 81.</p>
<p>I can't find out how to solve this as it is part of Django, I didn't write the code and I have no idea how it works.</p>
<p>This... | 0 | 2010-01-18T12:36:43Z | 2,086,034 | <p>It seems like an error in the admin.py file for your app.</p>
<p>It may be a missing import, or even a typo, but it's hard to tell without any code. It would be great if you could post your admin.py file so we can take a look.</p>
<p>TemplateSyntaxErrors in Django are terrible, they almost never tell you what the ... | 1 | 2010-01-18T12:40:47Z | [
"python",
"django",
"admin"
] |
Django Admin site TemplateSyntaxError at /admin/: name not defined | 2,086,016 | <p>I have an issue where, when I log in to the Django admin site, I get a template syntax error in /Library/Python/2.6/site-packages/django/template/debug.py in render_node, line 81.</p>
<p>I can't find out how to solve this as it is part of Django, I didn't write the code and I have no idea how it works.</p>
<p>This... | 0 | 2010-01-18T12:36:43Z | 2,094,101 | <p>It turns out it was a rather simple thing, I am just not experienced enough with Python and I was calling on my .NET experience. Bad mistake.</p>
<p>I called <code>project.settings.SETTING</code> where I should have imported <code> project.settings</code> and then accessed <code>settings.SETTING</code>. </p>
<p>In... | 0 | 2010-01-19T14:26:39Z | [
"python",
"django",
"admin"
] |
Caching non-view returns | 2,086,420 | <p>I have a dozen or so permission lookups on views that make sure users have the right permissions to do something on the system (ie make sure they're in the right group, if they can edit their profile, if they're group administrators, etc).</p>
<p>A check might look like this:</p>
<pre><code>from django.contrib.aut... | 5 | 2010-01-18T13:51:48Z | 2,088,620 | <p>You might need to serialize the function (which I'm not doing when I use it as the key to the cache), but something like this should work:</p>
<pre><code>from django.core.cache import cache
def cached_user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
if not login_url:
... | 1 | 2010-01-18T19:22:02Z | [
"python",
"django",
"decorator",
"django-cache"
] |
Caching non-view returns | 2,086,420 | <p>I have a dozen or so permission lookups on views that make sure users have the right permissions to do something on the system (ie make sure they're in the right group, if they can edit their profile, if they're group administrators, etc).</p>
<p>A check might look like this:</p>
<pre><code>from django.contrib.aut... | 5 | 2010-01-18T13:51:48Z | 2,100,179 | <p>First you can simply write:</p>
<pre><code>from django.contrib.auth.decorators import permission_required
@permission_required('polls.can_vote')
def my_view(request):
# ...
</code></pre>
<p>Second, if the permissions don't change in time, you are free to store some info in the session (I found it more conveni... | 0 | 2010-01-20T09:16:02Z | [
"python",
"django",
"decorator",
"django-cache"
] |
specifying a list as a command line argument in python | 2,086,556 | <p>I am using getopt to process a command line optional argument, which should accept a list. Something like this: </p>
<pre><code>foo.py --my_list=[1, 2, 3, 4,5]
</code></pre>
<p>But this trims everything after "[1,"</p>
<p>My questions are:
A) Is there a way to specify a list without converting it into a string? ... | 14 | 2010-01-18T14:13:45Z | 2,086,579 | <p>Maybe you should just enclose the argument in quotes?</p>
<pre><code>foo.py "--my_list=[1, 2, 3, 4,5]"
</code></pre>
<p>Otherwise every space will be treated as a separator for arguments.</p>
| 4 | 2010-01-18T14:16:57Z | [
"python"
] |
specifying a list as a command line argument in python | 2,086,556 | <p>I am using getopt to process a command line optional argument, which should accept a list. Something like this: </p>
<pre><code>foo.py --my_list=[1, 2, 3, 4,5]
</code></pre>
<p>But this trims everything after "[1,"</p>
<p>My questions are:
A) Is there a way to specify a list without converting it into a string? ... | 14 | 2010-01-18T14:13:45Z | 2,086,615 | <p>There are two options that I can think of:</p>
<ul>
<li>Use <a href="http://docs.python.org/library/optparse.html">optparse</a>, and use <a href="http://docs.python.org/library/optparse.html#other-actions"><code>append</code></a> action to specify what you want to do as: <code>foo.py --my_list=1 --my_list=2 ...</co... | 19 | 2010-01-18T14:22:58Z | [
"python"
] |
specifying a list as a command line argument in python | 2,086,556 | <p>I am using getopt to process a command line optional argument, which should accept a list. Something like this: </p>
<pre><code>foo.py --my_list=[1, 2, 3, 4,5]
</code></pre>
<p>But this trims everything after "[1,"</p>
<p>My questions are:
A) Is there a way to specify a list without converting it into a string? ... | 14 | 2010-01-18T14:13:45Z | 8,156,311 | <p>From the python optparse help page:
"</p>
<pre><code>parser.add_option("-f")
parser.add_option("-p", type="float", nargs=3, dest="point")
</code></pre>
<p>As it parses the command line</p>
<pre><code>-f foo.txt -p 1 -3.5 4 -fbar.txt
</code></pre>
<p>optparse will set</p>
<pre><code>options.f = "foo.txt"
options... | 1 | 2011-11-16T17:54:16Z | [
"python"
] |
specifying a list as a command line argument in python | 2,086,556 | <p>I am using getopt to process a command line optional argument, which should accept a list. Something like this: </p>
<pre><code>foo.py --my_list=[1, 2, 3, 4,5]
</code></pre>
<p>But this trims everything after "[1,"</p>
<p>My questions are:
A) Is there a way to specify a list without converting it into a string? ... | 14 | 2010-01-18T14:13:45Z | 21,163,749 | <p>If I can't use a standard parser (optparse or argparse) to my application then I use the ast.literal_eval function to parse input arguments of type list as follows:</p>
<pre><code>import sys, ast
inputList = ast.literal_eval( sys.argv[1] )
print type( inputList )
print inputList
</code></pre>
<p>Let suppose that ... | 7 | 2014-01-16T13:55:58Z | [
"python"
] |
Extra variables on a custom 404 template | 2,086,715 | <p>I want to be able to use <strong>extra variables</strong> on a <strong>custom 404 template</strong>.</p>
<pre><code>#404.html
{{ extra_var }}
</code></pre>
<p>I have already tried:</p>
<pre><code>#urls.py
from myproject.myapp import views
handler404 = views.handler404
#views.py
from django.template import Reques... | 2 | 2010-01-18T14:41:12Z | 2,087,234 | <p>The fact that you can access <code>request_path</code> but not <code>extra_var</code> suggests to me your view is not being called properly, since <code>request_path</code> is passed automatically to the <code>404.html</code> template, per the <a href="http://docs.djangoproject.com/en/dev/topics/http/views/#the-404-... | 2 | 2010-01-18T15:50:00Z | [
"python",
"django",
"django-templates"
] |
Extra variables on a custom 404 template | 2,086,715 | <p>I want to be able to use <strong>extra variables</strong> on a <strong>custom 404 template</strong>.</p>
<pre><code>#404.html
{{ extra_var }}
</code></pre>
<p>I have already tried:</p>
<pre><code>#urls.py
from myproject.myapp import views
handler404 = views.handler404
#views.py
from django.template import Reques... | 2 | 2010-01-18T14:41:12Z | 7,517,148 | <p>I had a similar problem.</p>
<p><code>handler404</code> should be set in the <code>urls.py</code> file, but you also have to import it, and that's not in the docs.</p>
<ol>
<li><p>add <code>handler404</code> to your imports</p>
<pre><code>from django.conf.urls.defaults import patterns, include, url, handler404
</... | 3 | 2011-09-22T15:13:19Z | [
"python",
"django",
"django-templates"
] |
How can I determine if a python script is executed from crontab? | 2,086,961 | <p>I would like to know how can I determine if a python script is executed from crontab?</p>
<p>I don't want a solution that will require adding a parameter because I want to be able to detect this even from an imported module (not the main script).</p>
| 4 | 2010-01-18T15:17:06Z | 2,086,972 | <p>Check its PPID - the ID of its parent process. Compare that to the cron pid; If they are the same, it was invoked by the crontab.</p>
<p>This can be done by:</p>
<pre><code>$ sudo ps -Af | grep cron | grep -v grep
root 6363 1 0 10:17 ? 00:00:00 /usr/sbin/cron
</code></pre>
<p>The PID of the cron process in th... | 7 | 2010-01-18T15:17:56Z | [
"python",
"unix",
"terminal",
"cron"
] |
How can I determine if a python script is executed from crontab? | 2,086,961 | <p>I would like to know how can I determine if a python script is executed from crontab?</p>
<p>I don't want a solution that will require adding a parameter because I want to be able to detect this even from an imported module (not the main script).</p>
| 4 | 2010-01-18T15:17:06Z | 2,087,031 | <p>Not quite what you asked, but maybe what you want is <code>os.isatty(sys.stdout.fileno())</code>, which tells if <code>stdout</code> is connected to (roughly speaking) a terminal. It will be false if you pipe the output to a file or another process, or if the process is run from cron.</p>
| 18 | 2010-01-18T15:26:29Z | [
"python",
"unix",
"terminal",
"cron"
] |
How can I determine if a python script is executed from crontab? | 2,086,961 | <p>I would like to know how can I determine if a python script is executed from crontab?</p>
<p>I don't want a solution that will require adding a parameter because I want to be able to detect this even from an imported module (not the main script).</p>
| 4 | 2010-01-18T15:17:06Z | 2,087,053 | <p>Set an environment variable at the <code>cron</code> command invocation. That works even within a module, as you can just check <code>os.getenv()</code>.</p>
| 3 | 2010-01-18T15:29:11Z | [
"python",
"unix",
"terminal",
"cron"
] |
How can I determine if a python script is executed from crontab? | 2,086,961 | <p>I would like to know how can I determine if a python script is executed from crontab?</p>
<p>I don't want a solution that will require adding a parameter because I want to be able to detect this even from an imported module (not the main script).</p>
| 4 | 2010-01-18T15:17:06Z | 2,087,056 | <p>An easier workaround would be to pass a flag to the script only from the crontab, like --crontab, and then just check for that flag.</p>
| 2 | 2010-01-18T15:29:50Z | [
"python",
"unix",
"terminal",
"cron"
] |
How can I determine if a python script is executed from crontab? | 2,086,961 | <p>I would like to know how can I determine if a python script is executed from crontab?</p>
<p>I don't want a solution that will require adding a parameter because I want to be able to detect this even from an imported module (not the main script).</p>
| 4 | 2010-01-18T15:17:06Z | 2,087,816 | <p>If you want to detect this from an imported module, I would have the main program set a global variable in the module, which would output different things depending on the value of this global variable (and have the main program decide how to set the variable through a flag that you would use in your crontab). This... | 0 | 2010-01-18T17:16:02Z | [
"python",
"unix",
"terminal",
"cron"
] |
Can I use `pip` instead of `easy_install` for `python setup.py install` dependency resolution? | 2,087,148 | <p><code>python setup.py install</code> will automatically install packages listed in <code>requires=[]</code> using <code>easy_install</code>. How do I get it to use <code>pip</code> instead?</p>
| 74 | 2010-01-18T15:40:17Z | 2,090,124 | <p>You can <code>pip install</code> a file perhaps by <code>python setup.py sdist</code> first. You can also <code>pip install -e .</code> which is like <code>python setup.py develop</code>.</p>
| 74 | 2010-01-19T00:05:39Z | [
"python",
"easy-install",
"pip"
] |
Can I use `pip` instead of `easy_install` for `python setup.py install` dependency resolution? | 2,087,148 | <p><code>python setup.py install</code> will automatically install packages listed in <code>requires=[]</code> using <code>easy_install</code>. How do I get it to use <code>pip</code> instead?</p>
| 74 | 2010-01-18T15:40:17Z | 24,000,174 | <p>Yes you can. You can install a package from a tarball or a folder, on the web or your computer. For example:</p>
<h3>Install from tarball on web</h3>
<pre><code>pip install https://pypi.python.org/packages/source/r/requests/requests-2.3.0.tar.gz
</code></pre>
<h3>Install from local tarball</h3>
<pre><code>wget h... | 50 | 2014-06-02T17:33:47Z | [
"python",
"easy-install",
"pip"
] |
Commit in git only if tests pass | 2,087,216 | <p>I've recently started using git, and also begun unit testing (using Python's <code>unittest</code> module). I'd like to run my tests each time I commit, and only commit if they pass.</p>
<p>I'm guessing I need to use <code>pre-commit</code> in <code>/hooks</code>, and I've managed to make it run the tests, but I ca... | 32 | 2010-01-18T15:47:51Z | 2,087,255 | <p>Could you parse the result of the python test session and make sure to exit your pre-commit hook with a non-zero status?</p>
<blockquote>
<p>The hook should exit with non-zero status after issuing an appropriate message if
it wants to stop the commit.</p>
</blockquote>
<p>So if your python script does not retu... | 6 | 2010-01-18T15:52:46Z | [
"python",
"unit-testing",
"git",
"githooks"
] |
Commit in git only if tests pass | 2,087,216 | <p>I've recently started using git, and also begun unit testing (using Python's <code>unittest</code> module). I'd like to run my tests each time I commit, and only commit if they pass.</p>
<p>I'm guessing I need to use <code>pre-commit</code> in <code>/hooks</code>, and I've managed to make it run the tests, but I ca... | 32 | 2010-01-18T15:47:51Z | 2,088,074 | <p>I would check to make sure that each step of the way, your script returns a non-zero exit code on failure. Check to see if your <code>python3.1 foo.py --test</code> returns a non-zero exit code if a test fails. Check to make sure your <code>make test</code> command returns a non-zero exit code. And finally, check th... | 26 | 2010-01-18T17:54:41Z | [
"python",
"unit-testing",
"git",
"githooks"
] |
Commit in git only if tests pass | 2,087,216 | <p>I've recently started using git, and also begun unit testing (using Python's <code>unittest</code> module). I'd like to run my tests each time I commit, and only commit if they pass.</p>
<p>I'm guessing I need to use <code>pre-commit</code> in <code>/hooks</code>, and I've managed to make it run the tests, but I ca... | 32 | 2010-01-18T15:47:51Z | 30,321,463 | <p>Another option, if you don't want to handle manually pre-commit's:
There is nice tool to run tests and syntax checks for Python, Ruby and so on: <a href="https://github.com/brigade/overcommit" rel="nofollow">github/overcommit</a></p>
| 0 | 2015-05-19T09:18:13Z | [
"python",
"unit-testing",
"git",
"githooks"
] |
Decode HTML entities in Python string? | 2,087,370 | <p>I'm parsing some HTML with Beautiful Soup 3, but it contains HTML entities which Beautiful Soup 3 doesn't automatically decode for me:</p>
<pre><code>>>> from BeautifulSoup import BeautifulSoup
>>> soup = BeautifulSoup("<p>&pound;682m</p>")
>>> text = soup.find("p").strin... | 128 | 2010-01-18T16:08:52Z | 2,087,433 | <h3>Python 3.4+</h3>
<p><code>HTMLParser.unescape</code> is deprecated, and <a href="https://github.com/python/cpython/blob/3.5/Lib/html/parser.py#L466-L470">was supposed to be removed in 3.5</a>, although it was left in by mistake. It will be removed from the language soon. Instead, use <code>html.unescape()</code>:<... | 252 | 2010-01-18T16:17:50Z | [
"python",
"html",
"html-entities"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.