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 |
|---|---|---|---|---|---|---|---|---|---|
Making Python Interactive Mode of Emacs Highlight and Indent | 2,063,343 | <p>I am using Emacs 23 with python-mode 5.1.0 to edit my python programs. Sometimes when writing a program I want to run a small throwaway python script and so I run the interactive move (C-c !). This is fine, but it neither indents nor highlights the code, and if I try running python mode while in it, it no longer eva... | 6 | 2010-01-14T10:09:49Z | 2,068,761 | <p>Adding these to my .emacs seems to have done it.</p>
<p>The bit where it checks the buffer name in the advice would probably be better as a test on a buffer-local variable set by set-pycomint-keywords, but you get the idea.</p>
<pre><code>(defun set-pycomint-keywords ()
(setq font-lock-keywords python-font-... | 3 | 2010-01-15T01:03:13Z | [
"python",
"emacs"
] |
Making Python Interactive Mode of Emacs Highlight and Indent | 2,063,343 | <p>I am using Emacs 23 with python-mode 5.1.0 to edit my python programs. Sometimes when writing a program I want to run a small throwaway python script and so I run the interactive move (C-c !). This is fine, but it neither indents nor highlights the code, and if I try running python mode while in it, it no longer eva... | 6 | 2010-01-14T10:09:49Z | 2,184,434 | <p>I don't have time to try it now, but i found you can replace python shell when you press C-c
with this that should be more powerful:</p>
<p><a href="http://ipython.scipy.org/moin/" rel="nofollow">http://ipython.scipy.org/moin/</a></p>
<p>When i'll have time I'll give it a try</p>
| -1 | 2010-02-02T13:48:38Z | [
"python",
"emacs"
] |
Cambodian keyboard for Windows and Linux? | 2,063,412 | <p>Before I created <a href="http://khmerlc.org/khmerkeyweb/" rel="nofollow">http://khmerlc.org/khmerkeyweb/</a> with javascript that allow user input
cambodia unicode user can switch from English to khmer(cambodia)</p>
<p>I am going to build an application called khmerkey for desktop (both can run window,linux).
I w... | 0 | 2010-01-14T10:24:40Z | 2,063,448 | <p>Hooking keys and sendkeys is different way for Windows and Linux, so you have to do it seperately.</p>
<p>In Windows, you can use combination of <a href="http://sourceforge.net/apps/mediawiki/pyhook/index.php?title=Main_Page" rel="nofollow">PyHook</a> and <a href="http://www.rutherfurd.net/python/sendkeys/" rel="no... | 1 | 2010-01-14T10:32:49Z | [
"python"
] |
Python elegant inverse function of int(string,base) | 2,063,425 | <p>python allows conversions from string to integer using any base in the range [2,36] using:</p>
<pre><code>int(string,base)
</code></pre>
<p>im looking for an elegant inverse function that takes an integer and a base and returns a string</p>
<p>for example</p>
<pre><code>>>> str_base(224,15)
'ee'
</code>... | 32 | 2010-01-14T10:28:03Z | 2,063,475 | <p>A little googling brings <a href="http://www.daniweb.com/forums/thread159163.html#" rel="nofollow">this</a>. One of the comments talks about Python builtin functions:</p>
<pre><code>int(x [,base]) converts x to an integer
long(x [,base]) converts x to a long integer
float(x) converts x to a floating-point number
co... | 1 | 2010-01-14T10:38:35Z | [
"python"
] |
Python elegant inverse function of int(string,base) | 2,063,425 | <p>python allows conversions from string to integer using any base in the range [2,36] using:</p>
<pre><code>int(string,base)
</code></pre>
<p>im looking for an elegant inverse function that takes an integer and a base and returns a string</p>
<p>for example</p>
<pre><code>>>> str_base(224,15)
'ee'
</code>... | 32 | 2010-01-14T10:28:03Z | 2,063,535 | <p><a href="http://code.activestate.com/recipes/65212/">This thread</a> has some example implementations.</p>
<p>Actually I think your solution looks rather nice, it's even recursive which is somehow pleasing here.</p>
<p>I'd still simplify it to remove the <code>else</code>, but that's probably a personal style thin... | 9 | 2010-01-14T10:48:34Z | [
"python"
] |
Python elegant inverse function of int(string,base) | 2,063,425 | <p>python allows conversions from string to integer using any base in the range [2,36] using:</p>
<pre><code>int(string,base)
</code></pre>
<p>im looking for an elegant inverse function that takes an integer and a base and returns a string</p>
<p>for example</p>
<pre><code>>>> str_base(224,15)
'ee'
</code>... | 32 | 2010-01-14T10:28:03Z | 2,063,540 | <p><code>digit_to_char</code> could be implemented like this:</p>
<pre><code>def digit_to_char(digit):
return (string.digits + string.lowercase)[digit]
</code></pre>
| 2 | 2010-01-14T10:49:44Z | [
"python"
] |
Python elegant inverse function of int(string,base) | 2,063,425 | <p>python allows conversions from string to integer using any base in the range [2,36] using:</p>
<pre><code>int(string,base)
</code></pre>
<p>im looking for an elegant inverse function that takes an integer and a base and returns a string</p>
<p>for example</p>
<pre><code>>>> str_base(224,15)
'ee'
</code>... | 32 | 2010-01-14T10:28:03Z | 4,665,054 | <p>review this.</p>
<pre><code>def int2str(num, base=16, sbl=None):
if not sbl:
sbl = '0123456789abcdefghijklmnopqrstuvwxyz'
if len(sbl) < 2:
raise ValueError, 'size of symbols should be >= 2'
if base < 2 or base > len(sbl):
raise ValueError, 'base must be in range 2-%d'... | 3 | 2011-01-12T03:20:57Z | [
"python"
] |
Python elegant inverse function of int(string,base) | 2,063,425 | <p>python allows conversions from string to integer using any base in the range [2,36] using:</p>
<pre><code>int(string,base)
</code></pre>
<p>im looking for an elegant inverse function that takes an integer and a base and returns a string</p>
<p>for example</p>
<pre><code>>>> str_base(224,15)
'ee'
</code>... | 32 | 2010-01-14T10:28:03Z | 15,140,779 | <p>Maybe this shouldn't be an answer, but it could be helpful for some: the built-in <a href="http://docs.python.org/2/library/string.html#format-specification-mini-language"><code>format</code></a> function does convert numbers to string in a few bases:</p>
<pre><code>>>> format(255, 'b') # base 2
'11111111'... | 16 | 2013-02-28T16:35:07Z | [
"python"
] |
Python elegant inverse function of int(string,base) | 2,063,425 | <p>python allows conversions from string to integer using any base in the range [2,36] using:</p>
<pre><code>int(string,base)
</code></pre>
<p>im looking for an elegant inverse function that takes an integer and a base and returns a string</p>
<p>for example</p>
<pre><code>>>> str_base(224,15)
'ee'
</code>... | 32 | 2010-01-14T10:28:03Z | 23,926,613 | <p>If you use Numpy, there is <code>numpy.base_repr</code>. </p>
<p>You can read the code under <code>numpy/core/numeric.py</code>. Short and elegant</p>
| 8 | 2014-05-29T05:54:59Z | [
"python"
] |
Python elegant inverse function of int(string,base) | 2,063,425 | <p>python allows conversions from string to integer using any base in the range [2,36] using:</p>
<pre><code>int(string,base)
</code></pre>
<p>im looking for an elegant inverse function that takes an integer and a base and returns a string</p>
<p>for example</p>
<pre><code>>>> str_base(224,15)
'ee'
</code>... | 32 | 2010-01-14T10:28:03Z | 24,763,277 | <p>The above answers are really nice. It helped me a lot to prototype an algortithm I had to implement in C </p>
<p>I'd like to come up with a little change (I used) to convert decimal to a base of symbolspace</p>
<p>I also ignored negativ values just for shortness and the fact that's mathematical incorrect
--> othe... | 3 | 2014-07-15T16:19:03Z | [
"python"
] |
Python elegant inverse function of int(string,base) | 2,063,425 | <p>python allows conversions from string to integer using any base in the range [2,36] using:</p>
<pre><code>int(string,base)
</code></pre>
<p>im looking for an elegant inverse function that takes an integer and a base and returns a string</p>
<p>for example</p>
<pre><code>>>> str_base(224,15)
'ee'
</code>... | 32 | 2010-01-14T10:28:03Z | 36,875,504 | <p>Here's my soulotion</p>
<pre><code>def int2base(a, base, numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
baseit = lambda a=a, b=base: (not a) and numerals[0] or baseit(a-a%b,b*base)+numerals[a%b%(base-1) or (a%b) and (base-1)]
return baseit()
</code></pre>
<hr>
<h2>explanation</h2>
<p>In any base ev... | 0 | 2016-04-26T20:52:13Z | [
"python"
] |
Python elegant inverse function of int(string,base) | 2,063,425 | <p>python allows conversions from string to integer using any base in the range [2,36] using:</p>
<pre><code>int(string,base)
</code></pre>
<p>im looking for an elegant inverse function that takes an integer and a base and returns a string</p>
<p>for example</p>
<pre><code>>>> str_base(224,15)
'ee'
</code>... | 32 | 2010-01-14T10:28:03Z | 39,818,927 | <p>I had once written my own function with the same goal but is now embarrassingly complicated.</p>
<pre><code>from math import log, ceil, floor
from collections import deque
from itertools import repeat
from string import uppercase, digits
import re
__alphanumerals = (digits + uppercase)
class InvalidBaseError(Valu... | 2 | 2016-10-02T16:06:38Z | [
"python"
] |
Find system folder locations in Python | 2,063,508 | <p>I am trying to find out the location of system folders with Python 3.1. For example "My Documents" = "C:\Documents and Settings\User\My Documents", "Program Files" = "C:\Program Files" etc etc.</p>
| 8 | 2010-01-14T10:44:07Z | 2,063,531 | <p>To get the "My Documents" folder, you can use:</p>
<pre><code>from win32com.shell import shell
df = shell.SHGetDesktopFolder()
pidl = df.ParseDisplayName(0, None,
"::{450d8fba-ad25-11d0-98a8-0800361b1103}")[1]
mydocs = shell.SHGetPathFromIDList(pidl)
print mydocs
</code></pre>
<p>From <a href="http://snippet... | 4 | 2010-01-14T10:47:49Z | [
"python",
"windows",
"path",
"special-folders"
] |
Find system folder locations in Python | 2,063,508 | <p>I am trying to find out the location of system folders with Python 3.1. For example "My Documents" = "C:\Documents and Settings\User\My Documents", "Program Files" = "C:\Program Files" etc etc.</p>
| 8 | 2010-01-14T10:44:07Z | 2,063,795 | <p>I found <a href="http://mail.python.org/pipermail/python-win32/2005-September/003738.html">a slightly different way of doing it</a>. This way will give you the location of various system folders and uses real words instead of CLSIDs.</p>
<pre><code>import win32com.client
objShell = win32com.client.Dispatch("WScript... | 8 | 2010-01-14T11:46:33Z | [
"python",
"windows",
"path",
"special-folders"
] |
Find system folder locations in Python | 2,063,508 | <p>I am trying to find out the location of system folders with Python 3.1. For example "My Documents" = "C:\Documents and Settings\User\My Documents", "Program Files" = "C:\Program Files" etc etc.</p>
| 8 | 2010-01-14T10:44:07Z | 8,259,996 | <p>In Windows 7 I can use the following environment variables to access the folders I need: </p>
<pre><code>>>> import os
>>> os.environ['USERPROFILE']
'C:\\Users\\digginc'
>>> os.environ['PROGRAMFILES']
'C:\\Program Files'
</code></pre>
| 4 | 2011-11-24T16:23:08Z | [
"python",
"windows",
"path",
"special-folders"
] |
Find system folder locations in Python | 2,063,508 | <p>I am trying to find out the location of system folders with Python 3.1. For example "My Documents" = "C:\Documents and Settings\User\My Documents", "Program Files" = "C:\Program Files" etc etc.</p>
| 8 | 2010-01-14T10:44:07Z | 30,540,388 | <p>The Windows API call for doing this, from Vista on, is <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb762188%28v=vs.85%29.aspx" rel="nofollow">SHGetKnownFolderPath</a>. There is an MIT-licensed wrapper (using ctypes, so no dependencies on pywin32) <a href="https://gist.github.com/mkropat/7550097... | 0 | 2015-05-29T23:07:24Z | [
"python",
"windows",
"path",
"special-folders"
] |
What is returned by wave.readframes? | 2,063,565 | <p>I assign a value to a variable <code>x</code> in the following way:</p>
<pre><code>import wave
w = wave.open('/usr/share/sounds/ekiga/voicemail.wav', 'r')
x = w.readframes(1)
</code></pre>
<p>When I type x I get:</p>
<pre><code>'\x1e\x00'
</code></pre>
<p>So <code>x</code> got a value. But what is that? Is it he... | 9 | 2010-01-14T10:54:25Z | 2,063,582 | <p>This strings represent bytes. I guess you can turn them into an integer with <a href="http://docs.python.org/library/struct.html" rel="nofollow">struct</a> package, which allows interpreting strings of bytes.</p>
| 0 | 2010-01-14T10:57:29Z | [
"python",
"wave"
] |
What is returned by wave.readframes? | 2,063,565 | <p>I assign a value to a variable <code>x</code> in the following way:</p>
<pre><code>import wave
w = wave.open('/usr/share/sounds/ekiga/voicemail.wav', 'r')
x = w.readframes(1)
</code></pre>
<p>When I type x I get:</p>
<pre><code>'\x1e\x00'
</code></pre>
<p>So <code>x</code> got a value. But what is that? Is it he... | 9 | 2010-01-14T10:54:25Z | 2,063,590 | <p>The interactive interpreter echoes unprintable characters like that. The string contains two bytes, 0x1E and 0x00. You can convert it to an (WORD-size) integer with <code>struct.unpack("<H", x)</code> (little endian!).</p>
| 7 | 2010-01-14T10:58:07Z | [
"python",
"wave"
] |
What is returned by wave.readframes? | 2,063,565 | <p>I assign a value to a variable <code>x</code> in the following way:</p>
<pre><code>import wave
w = wave.open('/usr/share/sounds/ekiga/voicemail.wav', 'r')
x = w.readframes(1)
</code></pre>
<p>When I type x I get:</p>
<pre><code>'\x1e\x00'
</code></pre>
<p>So <code>x</code> got a value. But what is that? Is it he... | 9 | 2010-01-14T10:54:25Z | 2,063,604 | <p>It's a two byte string:</p>
<pre><code>>>> x='\x1e\x00'
>>> map(ord, list(x))
[30, 0]
>>> [ord(i) for i in x]
[30, 0]
</code></pre>
| 1 | 2010-01-14T11:00:18Z | [
"python",
"wave"
] |
What is returned by wave.readframes? | 2,063,565 | <p>I assign a value to a variable <code>x</code> in the following way:</p>
<pre><code>import wave
w = wave.open('/usr/share/sounds/ekiga/voicemail.wav', 'r')
x = w.readframes(1)
</code></pre>
<p>When I type x I get:</p>
<pre><code>'\x1e\x00'
</code></pre>
<p>So <code>x</code> got a value. But what is that? Is it he... | 9 | 2010-01-14T10:54:25Z | 20,026,364 | <p>Yes, it is in hexadecimal, but what it means depends on the other outputs of the wav file e.g. the sample width and number of channels. Your data could be read in two ways, 2 channels and 1 byte sample width (stereo sound) or 1 channel and 2 byte sample width (mono sound). Use <code>x.getparams()</code>: the first n... | 0 | 2013-11-17T02:12:23Z | [
"python",
"wave"
] |
Qt Python: QTextEdit - display input | 2,063,633 | <p>I have a QTextEdit... it works with 'clear()' when a pushbutton calls 'CleanComments' to clean the input done by the user. Here is the code:</p>
<pre><code>def CleanComments(self):
self.textEditInput.clear()
def showInput(self):
print "show input: %s" % self.textEditInput.show()
def buildEditInput(self):
... | 0 | 2010-01-14T11:06:54Z | 2,063,649 | <p>Your showInput method is printing the return from the show() method, which returns None. If you want to print the current text in the edit, use:</p>
<pre><code>print "show input: %s" % self.textEditInput.text()
</code></pre>
| 0 | 2010-01-14T11:12:16Z | [
"python",
"qt",
"qtextedit"
] |
Qt Python: QTextEdit - display input | 2,063,633 | <p>I have a QTextEdit... it works with 'clear()' when a pushbutton calls 'CleanComments' to clean the input done by the user. Here is the code:</p>
<pre><code>def CleanComments(self):
self.textEditInput.clear()
def showInput(self):
print "show input: %s" % self.textEditInput.show()
def buildEditInput(self):
... | 0 | 2010-01-14T11:06:54Z | 2,063,669 | <p>Method show from widget is used to display the widget on a screen. For example if you have main window, you call show to display it to user. If you wish to retrieve data from some edit, be it line edit or text edit, you should use text() method. Like this:</p>
<pre><code>def showInput(self):
print "show input: ... | 0 | 2010-01-14T11:15:44Z | [
"python",
"qt",
"qtextedit"
] |
Qt Python: QTextEdit - display input | 2,063,633 | <p>I have a QTextEdit... it works with 'clear()' when a pushbutton calls 'CleanComments' to clean the input done by the user. Here is the code:</p>
<pre><code>def CleanComments(self):
self.textEditInput.clear()
def showInput(self):
print "show input: %s" % self.textEditInput.show()
def buildEditInput(self):
... | 0 | 2010-01-14T11:06:54Z | 2,063,780 | <p>To get the contents of a <code>QTextEdit</code> as a simple string, use the <code>toPlainText()</code> method.</p>
<pre><code>print "show input: %s" % self.textEditInput.toPlainText()
</code></pre>
<p>There is also the <code>toHtml()</code> method. For even more options, you can work directly with the <code>QTextD... | 3 | 2010-01-14T11:43:13Z | [
"python",
"qt",
"qtextedit"
] |
Using SUDS to test WSDL | 2,063,720 | <p>Does anyone know about a good SUDS tutorial. I am trying to run tests on WSDL files and I am having trouble finding any imformation on how to do this. Is SUDS much different to SOAPy and would anyone recommend it to run smoke tests on functions stored in WSDL files.</p>
<p>I have read that SOAPAy is no longer suppo... | 5 | 2010-01-14T11:27:58Z | 2,063,758 | <p>Suds is very simple to use.</p>
<pre><code>from suds.client import Client
client = Client("http://example.com/foo.wsdl")
client.service.someMethod(someParameter)
</code></pre>
<p><code>someMethod</code> is the name of a method as described in the WSDL.</p>
| 14 | 2010-01-14T11:36:40Z | [
"python",
"soap",
"suds"
] |
Using SUDS to test WSDL | 2,063,720 | <p>Does anyone know about a good SUDS tutorial. I am trying to run tests on WSDL files and I am having trouble finding any imformation on how to do this. Is SUDS much different to SOAPy and would anyone recommend it to run smoke tests on functions stored in WSDL files.</p>
<p>I have read that SOAPAy is no longer suppo... | 5 | 2010-01-14T11:27:58Z | 2,063,880 | <p>Connection refused indicates that the server isn't there. Can you access <a href="http://10.51.54.50/ptz.wsdl" rel="nofollow">http://10.51.54.50/ptz.wsdl</a> in a browser or via curl? If not, start by getting the SOAP service running first then try again.</p>
| 2 | 2010-01-14T12:01:59Z | [
"python",
"soap",
"suds"
] |
Using SUDS to test WSDL | 2,063,720 | <p>Does anyone know about a good SUDS tutorial. I am trying to run tests on WSDL files and I am having trouble finding any imformation on how to do this. Is SUDS much different to SOAPy and would anyone recommend it to run smoke tests on functions stored in WSDL files.</p>
<p>I have read that SOAPAy is no longer suppo... | 5 | 2010-01-14T11:27:58Z | 20,093,623 | <p>In my case it was a stupid mistake ( just like any other bug).</p>
<p>The URL that I had used to initialize my service was something like </p>
<pre><code>Uri httpUri = new Uri("http://localhost:8000/CalculatorService");
</code></pre>
<p>I could access this service from a python client running on the same machine ... | 1 | 2013-11-20T10:40:23Z | [
"python",
"soap",
"suds"
] |
How should Django Apps bundle static media? | 2,063,923 | <p><strong>Background:</strong> </p>
<p>I'm starting to use Django for the first time, which is also my first foray into web development. I just got stuck on the whole "serving static media" problem. After spending a while looking at all the documentation and StackOverflow questions, I think I understand how it's supp... | 13 | 2010-01-14T12:15:55Z | 2,064,018 | <p>The only app I know of that deals with this without any intervention is the rather wonderful <a href="http://github.com/robhudson/django-debug-toolbar" rel="nofollow">django-debug-toolbar</a>, though it's arguable that this isn't a great example, since it's an app specifically designed for debug mode only.</p>
<p>T... | 2 | 2010-01-14T12:33:04Z | [
"python",
"django",
"web-applications"
] |
How should Django Apps bundle static media? | 2,063,923 | <p><strong>Background:</strong> </p>
<p>I'm starting to use Django for the first time, which is also my first foray into web development. I just got stuck on the whole "serving static media" problem. After spending a while looking at all the documentation and StackOverflow questions, I think I understand how it's supp... | 13 | 2010-01-14T12:15:55Z | 2,064,078 | <p>i usually put apps media in ./apps/appname/static (my apps resides in an apps subfolder)</p>
<p>then i have something similar in the vhost in apache :</p>
<pre><code>AliasMatch ^/apps/([^/]+)/static/(.*) /home/django/projectname/apps/$1/static/$2
<DirectoryMatch "^/home/django/projectname/apps/([^/]+)/static/*"... | 2 | 2010-01-14T12:43:29Z | [
"python",
"django",
"web-applications"
] |
How should Django Apps bundle static media? | 2,063,923 | <p><strong>Background:</strong> </p>
<p>I'm starting to use Django for the first time, which is also my first foray into web development. I just got stuck on the whole "serving static media" problem. After spending a while looking at all the documentation and StackOverflow questions, I think I understand how it's supp... | 13 | 2010-01-14T12:15:55Z | 2,065,389 | <p>Convention is to put static media in either media/appname/ or static/appname/ within the app (similar to templates).</p>
<p>For using apps in your project that come with media, I strongly recommend using <a href="http://pypi.python.org/pypi/django-staticfiles" rel="nofollow">django-staticfiles</a>. It will automati... | 9 | 2010-01-14T15:49:56Z | [
"python",
"django",
"web-applications"
] |
"Parseltongue": get Ruby to Speak a bit of Python? | 2,063,962 | <p>Just for interest really - community wiki - how much Python can we get Ruby to understand ?
[ Probably be just as interesting to do the reverse as well].</p>
<p>The experiment (such as it is) perhaps to see how much can be written in Ruby-Cross-Python scripts that will result in identical outputs. The only 'cheat' ... | 1 | 2010-01-14T12:22:44Z | 2,064,854 | <p>To answer the question fully would probably need a bit of analysis. The control structures in both languages are defined to make our lives easier and the codes more readable when we program, but they could be realised with methods like it was in smalltalk. Iterations and conditionals (except the "case" statement) si... | 1 | 2010-01-14T14:43:01Z | [
"python",
"ruby",
"multilingual"
] |
Remove lines from textfile with python | 2,064,184 | <p>I have a textfile.txt like this:</p>
<pre><code>First Line
Second Line
Third Line
Fourth Line
Fifth Line
Sixth Line
</code></pre>
<p>How can I remove the first three lines and the last line most comfortable?
Thanks!</p>
| 10 | 2010-01-14T13:04:03Z | 2,064,216 | <pre><code>data="".join(open("textfile.txt").readlines()[3:-1])
open("newfile.txt","wb").write(data)
</code></pre>
| 4 | 2010-01-14T13:08:46Z | [
"python"
] |
Remove lines from textfile with python | 2,064,184 | <p>I have a textfile.txt like this:</p>
<pre><code>First Line
Second Line
Third Line
Fourth Line
Fifth Line
Sixth Line
</code></pre>
<p>How can I remove the first three lines and the last line most comfortable?
Thanks!</p>
| 10 | 2010-01-14T13:04:03Z | 2,064,238 | <pre><code>lines = open('textfile.txt').readlines()
open('newfile.txt', 'w').writelines(lines[3:-1])
</code></pre>
| 27 | 2010-01-14T13:11:48Z | [
"python"
] |
Remove lines from textfile with python | 2,064,184 | <p>I have a textfile.txt like this:</p>
<pre><code>First Line
Second Line
Third Line
Fourth Line
Fifth Line
Sixth Line
</code></pre>
<p>How can I remove the first three lines and the last line most comfortable?
Thanks!</p>
| 10 | 2010-01-14T13:04:03Z | 2,064,239 | <p>No Python solution but since your problem is a classic, I present you a sed solution.</p>
<pre><code>$ sed -n -e "4,5p" textfile.txt
</code></pre>
<p>Of course the address <code>4,5</code> only works for exactly your input and required output :)</p>
| -2 | 2010-01-14T13:11:50Z | [
"python"
] |
Remove lines from textfile with python | 2,064,184 | <p>I have a textfile.txt like this:</p>
<pre><code>First Line
Second Line
Third Line
Fourth Line
Fifth Line
Sixth Line
</code></pre>
<p>How can I remove the first three lines and the last line most comfortable?
Thanks!</p>
| 10 | 2010-01-14T13:04:03Z | 2,064,437 | <p>This one doesn't use readlines() so it is ideal for bigger sized files.</p>
<pre><code>numline=3 #3 lines to skip
p=""
o=open("output.txt","a")
f=open("file")
for i in range(numline):
f.next()
for line in f:
if p:
o.write(p)
p=line
f.close()
o.close()
</code></pre>
<p>Since there's a sed answer... | 7 | 2010-01-14T13:44:47Z | [
"python"
] |
private members in python | 2,064,202 | <p>How can I make methods and data members private in Python? Or doesn't python support private members?</p>
| 32 | 2010-01-14T13:06:19Z | 2,064,209 | <blockquote>
<p><strong>If the name of a Python function,
class method, or attribute starts with
(but doesn't end with) two
underscores, it's private;</strong> everything
else is public. Python has no concept
of protected class methods (accessible
only in their own class and descendant
classes). Class m... | 6 | 2010-01-14T13:07:57Z | [
"python",
"oop",
"class"
] |
private members in python | 2,064,202 | <p>How can I make methods and data members private in Python? Or doesn't python support private members?</p>
| 32 | 2010-01-14T13:06:19Z | 2,064,212 | <blockquote>
<p><a href="http://docs.python.org/tutorial/classes.html#private-variables-and-class-local-references"><strong>9.6. Private Variables</strong></a></p>
<p>âPrivateâ instance variables that
cannot be accessed except from inside
an object, donât exist in Python.
However, there is a conventi... | 38 | 2010-01-14T13:08:13Z | [
"python",
"oop",
"class"
] |
private members in python | 2,064,202 | <p>How can I make methods and data members private in Python? Or doesn't python support private members?</p>
| 32 | 2010-01-14T13:06:19Z | 2,064,400 | <p>The other answers provide the technical details. I'd like to emphasise the difference in philosophy between Python on one hand and languages like C++/Java (which I presume you're familiar with based on your question). </p>
<p>The general attitude in Python (and Perl for that matter) is that the 'privacy' of an attr... | 23 | 2010-01-14T13:39:09Z | [
"python",
"oop",
"class"
] |
private members in python | 2,064,202 | <p>How can I make methods and data members private in Python? Or doesn't python support private members?</p>
| 32 | 2010-01-14T13:06:19Z | 2,064,413 | <p>There are no <code>private</code> of any other access protection mechanisms in Python. There is a convention documented in the <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">Python style guide</a> for indicating to the users of your your class that they should not be accessing certain attribute.</... | 3 | 2010-01-14T13:41:07Z | [
"python",
"oop",
"class"
] |
private members in python | 2,064,202 | <p>How can I make methods and data members private in Python? Or doesn't python support private members?</p>
| 32 | 2010-01-14T13:06:19Z | 20,795,539 | <p>Python does not support privacy directly . Programmer need to know when it is safe to modify attribute from outside but anyway with python you can achieve something like private with little tricks.
Now let's see a person can put anything private to it or not.</p>
<pre>
class Person(object):
def __priva(self):
... | 2 | 2013-12-27T05:51:38Z | [
"python",
"oop",
"class"
] |
private members in python | 2,064,202 | <p>How can I make methods and data members private in Python? Or doesn't python support private members?</p>
| 32 | 2010-01-14T13:06:19Z | 33,261,169 | <p>if you want to make a methods or data members private in Python,
use __setattr __</p>
<pre><code>class Number:
def __init__(self,value):
self.my_private = value
def __setattr__(self, my_private, value):
# the default behavior
# self.__dict__[my_private] = value
raise Excep... | -2 | 2015-10-21T13:50:46Z | [
"python",
"oop",
"class"
] |
Python C-API Making len(...) work with extension class | 2,064,276 | <p>When creating a class in Python, I can simply make a <code>def __len__(self):</code> method to make the <code>len(InstanceOfMyClass)</code> work, however I can't find out how to do this with an extension class via the C-API.</p>
<p>I tried adding a <code>__len__</code> method, but that appears to not work</p>
<pre... | 4 | 2010-01-14T13:18:56Z | 2,064,373 | <p>As Igniacio says, the correct way is to fill the <code>tp_as_sequence</code> member of your typeobject. Here is a minimal example:</p>
<pre><code>#include <Python.h>
/**
* C structure and methods definitions
*/
typedef struct {
PyObject_HEAD;
} TestObject;
static Py_ssize_t
TestClass_len(TestObject* ... | 3 | 2010-01-14T13:34:35Z | [
"python",
"c",
"python-c-api"
] |
Python C-API Making len(...) work with extension class | 2,064,276 | <p>When creating a class in Python, I can simply make a <code>def __len__(self):</code> method to make the <code>len(InstanceOfMyClass)</code> work, however I can't find out how to do this with an extension class via the C-API.</p>
<p>I tried adding a <code>__len__</code> method, but that appears to not work</p>
<pre... | 4 | 2010-01-14T13:18:56Z | 2,077,110 | <p>The <code>tp_as_sequence</code> member of the typeobject structure should be filled in with something that has its <code>sq_length</code> member populated.</p>
| 3 | 2010-01-16T11:11:25Z | [
"python",
"c",
"python-c-api"
] |
how to avoid storing different type of objects in the same place when they represent the same but with a different data structure | 2,064,284 | <p>This is in my opinion an abstract problem and I hope I can explain it well. I happened to find the same kind of problem in a completely different project and now I have it again and I would like to avoid it if possible.</p>
<p>I'm creating some classes to simplify some tasks for some specific requirements we have i... | 0 | 2010-01-14T13:20:20Z | 2,064,760 | <p>I'm not sure I understand your question, but maybe <a href="http://en.wikipedia.org/wiki/Visitor_pattern" rel="nofollow">Visitor pattern</a> is what you are looking for?</p>
| 1 | 2010-01-14T14:31:05Z | [
"asp.net",
"python",
"algorithm",
"design-patterns",
"ironpython"
] |
how to avoid storing different type of objects in the same place when they represent the same but with a different data structure | 2,064,284 | <p>This is in my opinion an abstract problem and I hope I can explain it well. I happened to find the same kind of problem in a completely different project and now I have it again and I would like to avoid it if possible.</p>
<p>I'm creating some classes to simplify some tasks for some specific requirements we have i... | 0 | 2010-01-14T13:20:20Z | 2,065,047 | <p>Sounds like composite pattern to me. Composite will provide an interface for treating containers of objects and leaf objects (those that are not containers) the same.</p>
| 1 | 2010-01-14T15:12:24Z | [
"asp.net",
"python",
"algorithm",
"design-patterns",
"ironpython"
] |
how to avoid storing different type of objects in the same place when they represent the same but with a different data structure | 2,064,284 | <p>This is in my opinion an abstract problem and I hope I can explain it well. I happened to find the same kind of problem in a completely different project and now I have it again and I would like to avoid it if possible.</p>
<p>I'm creating some classes to simplify some tasks for some specific requirements we have i... | 0 | 2010-01-14T13:20:20Z | 2,065,921 | <p>This is the Polymorphism problem.</p>
<p>"sometimes I have to store a non container object in a ... an object's attribute and sometimes I have to a store a container object in the same place"</p>
<p>You have two things which should be made polymorphic.</p>
<p>The easiest way to fix this is to use a container alwa... | 1 | 2010-01-14T17:00:40Z | [
"asp.net",
"python",
"algorithm",
"design-patterns",
"ironpython"
] |
Why python does not allow hyphens | 2,064,329 | <p>I have always wondered why can't we use hyphens in between function names and variable names in python</p>
<p>Having tried functional programming languages like Lisp and Clojure, where hyphens are allowed. Why python doesn't do that.</p>
<pre><code># This won't work -- SyntaxError
def is-even(num):
return num ... | 10 | 2010-01-14T13:27:44Z | 2,064,346 | <p>Because it would make the parser even more complicated. It would be confusing too for the programmers.</p>
<p>Consider <code>def is-even(num):</code> : now, if <code>is</code> is a global variable, what happens?</p>
<p>Also note that the <code>-</code> is the subtraction operator in Python, hence would further com... | 6 | 2010-01-14T13:29:57Z | [
"python"
] |
Why python does not allow hyphens | 2,064,329 | <p>I have always wondered why can't we use hyphens in between function names and variable names in python</p>
<p>Having tried functional programming languages like Lisp and Clojure, where hyphens are allowed. Why python doesn't do that.</p>
<pre><code># This won't work -- SyntaxError
def is-even(num):
return num ... | 10 | 2010-01-14T13:27:44Z | 2,064,358 | <p>Because hyphen is used as the subtraction operator. Imagine that you <em>could</em> have an <code>is-even</code> function, and then you had code like this:</p>
<pre><code>my_var = is-even(another_var)
</code></pre>
<p>Is <code>is-even(another_var)</code> a call to the function <code>is-even</code>, or is it subtra... | 29 | 2010-01-14T13:32:14Z | [
"python"
] |
Why python does not allow hyphens | 2,064,329 | <p>I have always wondered why can't we use hyphens in between function names and variable names in python</p>
<p>Having tried functional programming languages like Lisp and Clojure, where hyphens are allowed. Why python doesn't do that.</p>
<pre><code># This won't work -- SyntaxError
def is-even(num):
return num ... | 10 | 2010-01-14T13:27:44Z | 2,064,359 | <pre><code>is-even(num)
</code></pre>
<p>contains a hyphen ? I thought it was a subtraction of the value returned by function even with argument num from the value of is.</p>
<p>As @jdupont says, parsing can be tricky.</p>
<p>Mark</p>
| 0 | 2010-01-14T13:32:14Z | [
"python"
] |
Why python does not allow hyphens | 2,064,329 | <p>I have always wondered why can't we use hyphens in between function names and variable names in python</p>
<p>Having tried functional programming languages like Lisp and Clojure, where hyphens are allowed. Why python doesn't do that.</p>
<pre><code># This won't work -- SyntaxError
def is-even(num):
return num ... | 10 | 2010-01-14T13:27:44Z | 2,064,376 | <p>Because Python uses infix notation to represent calculations and a hyphen and a minus has the exact same ascii code. You can have ambiguous cases such as:</p>
<pre><code>a-b = 10
a = 1
b = 1
c = a-b
</code></pre>
<p>What is the answer? 0 or 10?</p>
| 8 | 2010-01-14T13:35:08Z | [
"python"
] |
Python not all in operation | 2,064,389 | <p>How do I check if a list is a subset of a bigger list.</p>
<p>i.e. </p>
<p><code>a = [1,2,3]</code> is a subset of <code>b = [1,2,3,4,5,6]</code></p>
<p>Can I do something like </p>
<pre><code>if a all in b
</code></pre>
| 3 | 2010-01-14T13:37:39Z | 2,064,404 | <p><a href="http://docs.python.org/library/stdtypes.html#set.issubset" rel="nofollow">http://docs.python.org/library/stdtypes.html#set.issubset</a></p>
<pre><code>set(a).issubset(set(b))
</code></pre>
| 12 | 2010-01-14T13:39:46Z | [
"python",
"set"
] |
Python not all in operation | 2,064,389 | <p>How do I check if a list is a subset of a bigger list.</p>
<p>i.e. </p>
<p><code>a = [1,2,3]</code> is a subset of <code>b = [1,2,3,4,5,6]</code></p>
<p>Can I do something like </p>
<pre><code>if a all in b
</code></pre>
| 3 | 2010-01-14T13:37:39Z | 2,064,414 | <pre><code>>>> a = set([1, 2, 3])
>>> b = set([1, 2, 3, 4, 5, 6])
>>> a.issubset(b)
True
</code></pre>
<p>or</p>
<pre><code>>>> a = [1, 2, 3]
>>> b = [1, 2, 3, 4, 5, 6]
>>> all(map(lambda x: x in b, a))
True
>>> a = [1, 2, 3, 9]
>>> all(map(lambd... | 5 | 2010-01-14T13:41:16Z | [
"python",
"set"
] |
Python not all in operation | 2,064,389 | <p>How do I check if a list is a subset of a bigger list.</p>
<p>i.e. </p>
<p><code>a = [1,2,3]</code> is a subset of <code>b = [1,2,3,4,5,6]</code></p>
<p>Can I do something like </p>
<pre><code>if a all in b
</code></pre>
| 3 | 2010-01-14T13:37:39Z | 2,064,898 | <p>mostly like the other answers, but I do prefer the generator syntax here, seems more natural and it's lazily evaluated:</p>
<pre><code>if all(x in b for x in a):
pass
</code></pre>
<p>if you care about the number of repeated elements, this option seems nice, and you could optimize it sorting c and using bisect... | 2 | 2010-01-14T14:49:57Z | [
"python",
"set"
] |
Executing python code from script and getting interpreter-style output | 2,064,491 | <p>I need to execute code from my python script and take interpreter-style output like it's done <a href="http://pythonregex.com" rel="nofollow">here</a>.</p>
<p>I am creating website on GAE using django, it must run user-entered code and print interpreter-style output as text. </p>
| 0 | 2010-01-14T13:56:02Z | 2,064,866 | <p>There is an open-source console for app engine that does what you want (if I understood the question correctly). Have a look at it: <a href="http://con.appspot.com/console/" rel="nofollow">http://con.appspot.com/console/</a></p>
<p>Instructions to integrate it with your application are available <a href="http://con... | 0 | 2010-01-14T14:45:31Z | [
"python"
] |
Executing python code from script and getting interpreter-style output | 2,064,491 | <p>I need to execute code from my python script and take interpreter-style output like it's done <a href="http://pythonregex.com" rel="nofollow">here</a>.</p>
<p>I am creating website on GAE using django, it must run user-entered code and print interpreter-style output as text. </p>
| 0 | 2010-01-14T13:56:02Z | 2,064,888 | <p>there is <code>code.InteractiveInterpreter</code> available, but I think you can take an inspiration in the following simpler example:</p>
<pre><code>import code
exprs = [
'd = {}',
'd',
'd["x"] = 1',
'd',
]
for e in exprs:
print '>>> %s' % e
cmd = code.compile_command(e)
r... | 1 | 2010-01-14T14:48:06Z | [
"python"
] |
multiprocessing.Process subclass works on Linux but not Windows | 2,064,533 | <p>I'm trying to get <a href="https://edge.launchpad.net/gasp-core" rel="nofollow">python-gasp</a> working on Windows, but when I do <code>import gasp; gasp.begin_graphics()</code> I get the following traceback:</p>
<pre><code> File "C:\Python26\lib\site-packages\gasp\backend.py", line 142, in create_screen
scre... | 1 | 2010-01-14T14:01:52Z | 2,064,984 | <p>Your <code>Updater</code> class has a member <code>screen</code>, which itself has a member <code>process</code> which receives the value of <code>multiprocessing.current_process()</code>.</p>
<p>When you call <code>updater.start()</code>, it tries to pickle the updater. This only happens on Windows because Linux u... | 2 | 2010-01-14T15:04:08Z | [
"python",
"windows",
"multiprocessing",
"pickle",
"gasp"
] |
Facebook connect on Google App Engine with Django Patch | 2,064,673 | <p>We are building a website on Google App Engine, using django patch.
We would like to use Facebook connect for two purposes:</p>
<ol>
<li>Authenticate users. </li>
<li>Access user's social data.</li>
</ol>
<p>Searching for a solution in the usual places (google, FB, SO) brigs up a lot of noise, many partial solutio... | 0 | 2010-01-14T14:19:45Z | 2,674,304 | <p>Have you seen this?</p>
<p><a href="http://code.google.com/p/simplefacebook/" rel="nofollow">http://code.google.com/p/simplefacebook/</a></p>
<p>It looks pretty easy to implement.</p>
| 0 | 2010-04-20T10:35:34Z | [
"python",
"django",
"google-app-engine",
"facebook"
] |
Facebook connect on Google App Engine with Django Patch | 2,064,673 | <p>We are building a website on Google App Engine, using django patch.
We would like to use Facebook connect for two purposes:</p>
<ol>
<li>Authenticate users. </li>
<li>Access user's social data.</li>
</ol>
<p>Searching for a solution in the usual places (google, FB, SO) brigs up a lot of noise, many partial solutio... | 0 | 2010-01-14T14:19:45Z | 2,681,563 | <p>Honza: we where looking for something that also does authentication Django style.
We ended up doing the login on the client side than sending an AJAX request to Django and wrote our own authenticate/login logic.
Once we get the user's credentials, we use PyFacebook for FB connectivity.</p>
| 0 | 2010-04-21T09:10:08Z | [
"python",
"django",
"google-app-engine",
"facebook"
] |
Facebook connect on Google App Engine with Django Patch | 2,064,673 | <p>We are building a website on Google App Engine, using django patch.
We would like to use Facebook connect for two purposes:</p>
<ol>
<li>Authenticate users. </li>
<li>Access user's social data.</li>
</ol>
<p>Searching for a solution in the usual places (google, FB, SO) brigs up a lot of noise, many partial solutio... | 0 | 2010-01-14T14:19:45Z | 18,203,175 | <p>Check out this link: <a href="http://pythonforfacebook.com" rel="nofollow">python for facebook</a> all python codes for facebook is available here Django inclusive. </p>
| 0 | 2013-08-13T07:33:36Z | [
"python",
"django",
"google-app-engine",
"facebook"
] |
wxFrame with title bar but non resizable | 2,064,856 | <p>I need to create a login window
for that window i need a title bar for dragging but it should not be a resized
I need a fixed size for this window</p>
| 0 | 2010-01-14T14:43:25Z | 2,065,968 | <pre><code>frame = wx.Frame(self, title="something", size=(480, 320), style=wx.CAPTION)
</code></pre>
<p>You can "mix and match" styles, which can be seen here: <a href="http://docs.wxwidgets.org/2.6/wx_wxframe.html" rel="nofollow">http://docs.wxwidgets.org/2.6/wx_wxframe.html</a></p>
<p>e.g. in my example, no "close... | 3 | 2010-01-14T17:06:49Z | [
"python",
"wxpython"
] |
Python: Best method to reload class in XMLRPC Server | 2,064,935 | <p>I have a multit-threaded xmlrpc service running which stores a huge amount of data ~2G in memory. Currently, if I want to update a method the server exposes I have to restart the service. The problem here is that if I restart the service it needs to load all of the data it had in memory back into memory by using a... | 1 | 2010-01-14T14:56:00Z | 2,126,742 | <p>You could use the <a href="http://docs.python.org/library/functions.html#reload" rel="nofollow">reload</a> method. You would need to write some code to check the last modified time of the modules file.</p>
| 4 | 2010-01-24T10:52:54Z | [
"python",
"xml-rpc"
] |
Python: Best method to reload class in XMLRPC Server | 2,064,935 | <p>I have a multit-threaded xmlrpc service running which stores a huge amount of data ~2G in memory. Currently, if I want to update a method the server exposes I have to restart the service. The problem here is that if I restart the service it needs to load all of the data it had in memory back into memory by using a... | 1 | 2010-01-14T14:56:00Z | 2,132,280 | <p>If reload doesn't work, you could try <code><a href="http://twistedmatrix.com/documents/current/api/twisted.python.rebuild.html" rel="nofollow">twisted.python.rebuild</a></code>; your application need not be written in Twisted to use this twisted.python utility.</p>
<p>I also recently saw this <a href="http://code.... | 1 | 2010-01-25T12:48:52Z | [
"python",
"xml-rpc"
] |
Jinja-like for Pdf in Python | 2,064,936 | <p>I am looking for the best accurate tool for PDF in Python that works like Jinja does for HTML. </p>
<p>What are your suggestions? </p>
| 11 | 2010-01-14T14:56:04Z | 2,064,959 | <p>Have a look at <a href="http://www.reportlab.com/opensource/" rel="nofollow">ReportLab Toolkit</a>. </p>
<p>You can use templates only with the commercial version, though.</p>
| 4 | 2010-01-14T14:59:41Z | [
"python",
"pdf-generation",
"jinja2"
] |
Jinja-like for Pdf in Python | 2,064,936 | <p>I am looking for the best accurate tool for PDF in Python that works like Jinja does for HTML. </p>
<p>What are your suggestions? </p>
| 11 | 2010-01-14T14:56:04Z | 2,066,042 | <p>As answered by jbochi, ReportLab is the foundation for almost all Python projects that generate PDF.</p>
<p>But for your needs you might want to check out <a href="http://www.xhtml2pdf.com/">Pisa / xhtml2pdf</a>. You would generate your HTML with a Jinja template and then use Pisa to convert the HTML to PDF. Pisa ... | 9 | 2010-01-14T17:16:59Z | [
"python",
"pdf-generation",
"jinja2"
] |
Jinja-like for Pdf in Python | 2,064,936 | <p>I am looking for the best accurate tool for PDF in Python that works like Jinja does for HTML. </p>
<p>What are your suggestions? </p>
| 11 | 2010-01-14T14:56:04Z | 9,234,000 | <p>There's now a new kid on the block called <a href="http://weasyprint.org/" rel="nofollow">WeasyPrint</a>.</p>
| 2 | 2012-02-10T19:55:41Z | [
"python",
"pdf-generation",
"jinja2"
] |
Jinja-like for Pdf in Python | 2,064,936 | <p>I am looking for the best accurate tool for PDF in Python that works like Jinja does for HTML. </p>
<p>What are your suggestions? </p>
| 11 | 2010-01-14T14:56:04Z | 10,657,728 | <p>What about python/jinja to rst/html and html/rst to pdf using either <a href="http://code.google.com/p/rst2pdf/" rel="nofollow">rst2pdf</a> or <a href="http://johnmacfarlane.net/pandoc/" rel="nofollow">pandoc</a>. </p>
<p>Both of these have worked well for me but. like plaes, I may try <a href="http://weasyprint.o... | 1 | 2012-05-18T18:15:10Z | [
"python",
"pdf-generation",
"jinja2"
] |
Jinja-like for Pdf in Python | 2,064,936 | <p>I am looking for the best accurate tool for PDF in Python that works like Jinja does for HTML. </p>
<p>What are your suggestions? </p>
| 11 | 2010-01-14T14:56:04Z | 11,544,804 | <p>I had exactly the same requirement as the OP. Unfortunately WeasyPrint wasn't a viable solution, because I needed very exact positioning and barcode support. After a few days of work I finished a reportlab XML wrapper with Jinja2 support.</p>
<p>The code can be found on GitHub
including an example <a href="https://... | 2 | 2012-07-18T15:22:51Z | [
"python",
"pdf-generation",
"jinja2"
] |
Jinja-like for Pdf in Python | 2,064,936 | <p>I am looking for the best accurate tool for PDF in Python that works like Jinja does for HTML. </p>
<p>What are your suggestions? </p>
| 11 | 2010-01-14T14:56:04Z | 24,802,475 | <p>If you want to use existing PDF as template, without altering original document, you can use Dhek template editor, which allows to define area (bounds, name, type) in a separate template file.</p>
<p>Template is saved in JSON format so that it can be parsed in Python, to fill areas over PDF and generate the final d... | 0 | 2014-07-17T11:37:40Z | [
"python",
"pdf-generation",
"jinja2"
] |
Using wget with subprocess | 2,065,060 | <p>I'm trying to use wget with <code>subprocess</code>.</p>
<p>my attempts worked until I tried to download the page to a specified directory with this code:</p>
<pre><code>url = 'google.com'
location = '/home/patrick/downloads'
args = ['wget', 'r', 'l 1' 'p' 'P %s' % location, url]
output = Popen(args, stdout=PIPE)... | 1 | 2010-01-14T15:14:19Z | 2,065,094 | <p>You need to have hyphens and <code>location</code> should be just another argument:</p>
<pre><code>args = ['wget', '-r', '-l', '1', '-p', '-P', location, url]
</code></pre>
| 4 | 2010-01-14T15:17:16Z | [
"python",
"subprocess"
] |
Using wget with subprocess | 2,065,060 | <p>I'm trying to use wget with <code>subprocess</code>.</p>
<p>my attempts worked until I tried to download the page to a specified directory with this code:</p>
<pre><code>url = 'google.com'
location = '/home/patrick/downloads'
args = ['wget', 'r', 'l 1' 'p' 'P %s' % location, url]
output = Popen(args, stdout=PIPE)... | 1 | 2010-01-14T15:14:19Z | 2,065,187 | <p><strong>Edit:</strong> <code>popen</code> from <code>os</code> intends to <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">replace</a> <code>os.popen</code> module. Hence, using <code>os.popen</code> is not recommended</p>
<p>Initially I thought it was <code>popen</code> from <code>os</code>.... | 0 | 2010-01-14T15:27:45Z | [
"python",
"subprocess"
] |
Passing arguments into SUDS client statement | 2,065,088 | <p>I am using SUDS (Like SOAP) to test WSDL files. The methods contain types that are linked to further functions. I am not sure how to access the variables stored in the types that are displayed. Some sample code is below:</p>
<pre><code>from suds.client import Client
client=Client('http://eample.wsdl')
print client
... | 2 | 2010-01-14T15:16:34Z | 2,068,858 | <p>Try to invoke the method on the service:</p>
<pre><code>from suds.client import Client
client=Client('http://eample.wsdl')
res = client.service.AbsoluteMove(profile_token, destination, speed)
print res
</code></pre>
<p>You'll need to determine what values to put in for those arguments to the AbsoluteMove method.</... | 2 | 2010-01-15T01:26:44Z | [
"python",
"soap",
"suds"
] |
Passing arguments into SUDS client statement | 2,065,088 | <p>I am using SUDS (Like SOAP) to test WSDL files. The methods contain types that are linked to further functions. I am not sure how to access the variables stored in the types that are displayed. Some sample code is below:</p>
<pre><code>from suds.client import Client
client=Client('http://eample.wsdl')
print client
... | 2 | 2010-01-14T15:16:34Z | 2,068,880 | <p><code>Client.factory.create</code> is for the instantiation of object types that are internal to the service you are utilizing. If you're just doing a method call (which it seems you are), invoke it directly.</p>
| 1 | 2010-01-15T01:33:19Z | [
"python",
"soap",
"suds"
] |
Python equivalent of pointers | 2,065,105 | <p>In python everything works by reference:</p>
<pre><code>>>> a = 1
>>> d = {'a':a}
>>> d['a']
1
>>> a = 2
>>> d['a']
1
</code></pre>
<p>I want something like this</p>
<pre><code>>>> a = 1
>>> d = {'a':magical pointer to a}
>>> d['a']
1
>>... | 2 | 2010-01-14T15:18:49Z | 2,065,142 | <p>What about a mutable data structure?</p>
<pre><code>>>> a = mutable_structure(1)
>>> d = {'a':a}
>>> d['a']
1
>>> a.setValue(2)
>>> d['a']
2
</code></pre>
<p>An implementation might look like</p>
<pre><code>class mutable_structure:
def __init__(self, val):
self.v... | 3 | 2010-01-14T15:23:00Z | [
"python",
"pointers",
"reference"
] |
Python equivalent of pointers | 2,065,105 | <p>In python everything works by reference:</p>
<pre><code>>>> a = 1
>>> d = {'a':a}
>>> d['a']
1
>>> a = 2
>>> d['a']
1
</code></pre>
<p>I want something like this</p>
<pre><code>>>> a = 1
>>> d = {'a':magical pointer to a}
>>> d['a']
1
>>... | 2 | 2010-01-14T15:18:49Z | 2,065,247 | <p>This is because 1 is a immutable datatype in python, i.e. you can't change the value of it. </p>
<p>To make it work like a pointer, you need a mutable datatype as storage, which you can do yourself with a class definition</p>
<pre><code>class Mutable(object):
pass
a = Mutable()
a.value = 1
d = {'a':a}
a.valu... | 0 | 2010-01-14T15:35:05Z | [
"python",
"pointers",
"reference"
] |
Python equivalent of pointers | 2,065,105 | <p>In python everything works by reference:</p>
<pre><code>>>> a = 1
>>> d = {'a':a}
>>> d['a']
1
>>> a = 2
>>> d['a']
1
</code></pre>
<p>I want something like this</p>
<pre><code>>>> a = 1
>>> d = {'a':magical pointer to a}
>>> d['a']
1
>>... | 2 | 2010-01-14T15:18:49Z | 2,065,359 | <p>The standard solution is to just use a list; it's the easiest mutable structure.</p>
<pre><code>a = [1]
d = {'a': a}
a[0] = 2
print d['a'][0]
</code></pre>
| 1 | 2010-01-14T15:46:42Z | [
"python",
"pointers",
"reference"
] |
Python equivalent of pointers | 2,065,105 | <p>In python everything works by reference:</p>
<pre><code>>>> a = 1
>>> d = {'a':a}
>>> d['a']
1
>>> a = 2
>>> d['a']
1
</code></pre>
<p>I want something like this</p>
<pre><code>>>> a = 1
>>> d = {'a':magical pointer to a}
>>> d['a']
1
>>... | 2 | 2010-01-14T15:18:49Z | 2,065,958 | <p>If you're working in a class you could do something like this:</p>
<pre><code>class DRefsA(object):
a = 4
@property
def d(self):
return self.a
@d.setter
def d(self, value):
self.a = value
</code></pre>
| 0 | 2010-01-14T17:05:54Z | [
"python",
"pointers",
"reference"
] |
python parent class 'wrapping' child-class methods | 2,065,112 | <p><br>
I have the following situation in my python code:</p>
<pre><code>class Parent(object):
def run(self):
print "preparing for run"
self.runImpl()
print "run done"
class Child(Parent):
def runImpl(self):
print "child running"
</code></pre>
<p>However, I have several such '... | 5 | 2010-01-14T15:19:37Z | 2,065,179 | <h3>Don't use inheritance here</h3>
<p>Invert your design. Instead of a parent-child implementation which is a "is-a" relationship why not just have a composition so you get a "has-a" relationship? You could define classes which implement the methods you'd like while your previous parent class would be instantiated ... | 2 | 2010-01-14T15:26:50Z | [
"python",
"inheritance",
"implementation",
"decorator",
"wrapper"
] |
python parent class 'wrapping' child-class methods | 2,065,112 | <p><br>
I have the following situation in my python code:</p>
<pre><code>class Parent(object):
def run(self):
print "preparing for run"
self.runImpl()
print "run done"
class Child(Parent):
def runImpl(self):
print "child running"
</code></pre>
<p>However, I have several such '... | 5 | 2010-01-14T15:19:37Z | 2,065,545 | <p>Yonatan, your question isn't clear! Depending on the situation you could use many different designs.</p>
<p>One solution would be to have explicit setup() and teardown() methods which are called by the run() method before calling runImpl(). This would allow subclasses to wrap/override these as needed.</p>
<pre><co... | 1 | 2010-01-14T16:11:41Z | [
"python",
"inheritance",
"implementation",
"decorator",
"wrapper"
] |
python parent class 'wrapping' child-class methods | 2,065,112 | <p><br>
I have the following situation in my python code:</p>
<pre><code>class Parent(object):
def run(self):
print "preparing for run"
self.runImpl()
print "run done"
class Child(Parent):
def runImpl(self):
print "child running"
</code></pre>
<p>However, I have several such '... | 5 | 2010-01-14T15:19:37Z | 16,613,285 | <p>You can get this:</p>
<pre><code>class Parent(object):
def run(self, func_impl, *args, **kwargs):
print "preparing for run"
func_impl(*args, **kwargs)
print "run done"
class Child(Parent):
@wrapped_in_parent_call
def run(self):
print "child running"
</code></pre>
<p>Wit... | 1 | 2013-05-17T15:52:06Z | [
"python",
"inheritance",
"implementation",
"decorator",
"wrapper"
] |
UDP packet encryption | 2,065,218 | <p>This appears to be reasonably trivial if using the ssl module for TCP communication, but how would encrypted communication be done via UDP? </p>
<p>Can the ssl module still be used? if so, what steps would need to be performed for the client and server to be in a position where data can be sent to-and-fro as normal... | 2 | 2010-01-14T15:32:51Z | 2,065,344 | <p><a href="http://en.wikipedia.org/wiki/Datagram_Transport_Layer_Security" rel="nofollow">DTLS</a> is a TLS (aka SSL) derivative designed for use over datagram transports, like UDP.</p>
<p><a href="http://www.openssl.org/" rel="nofollow">OpenSSL</a> supports DTLS starting in 0.9.8, using <code>DTLSv1_METHOD</code> in... | 4 | 2010-01-14T15:45:24Z | [
"python",
"ssl",
"udp"
] |
UDP packet encryption | 2,065,218 | <p>This appears to be reasonably trivial if using the ssl module for TCP communication, but how would encrypted communication be done via UDP? </p>
<p>Can the ssl module still be used? if so, what steps would need to be performed for the client and server to be in a position where data can be sent to-and-fro as normal... | 2 | 2010-01-14T15:32:51Z | 2,065,378 | <p>You could use pyCrypto or <a href="http://www.freenet.org.nz/ezPyCrypto/" rel="nofollow">ezPyCrypto</a> to manually encrypt/decrypt the packets.</p>
| 1 | 2010-01-14T15:48:56Z | [
"python",
"ssl",
"udp"
] |
Parsing, securing python expression before passing it to eval() | 2,065,331 | <p>I want to take an input from the user may be like <code>foo() > 90 and boo() == 9 or do() > 100</code> and use eval on the server side to to evaluate this expression.</p>
<p>For security I want to restrict user to add limited functions and operators by keeping a check (against some data-structure) before I pa... | 4 | 2010-01-14T15:43:52Z | 2,065,418 | <p>the more secure way is to do everything at the back end. Users just key in the necessary parameters. For example you can prompt them to key in numeric values for foo(), boo() and do(). Then at the back end, pass these values to appropriate functions to do the calculations. </p>
| 1 | 2010-01-14T15:54:29Z | [
"python"
] |
Parsing, securing python expression before passing it to eval() | 2,065,331 | <p>I want to take an input from the user may be like <code>foo() > 90 and boo() == 9 or do() > 100</code> and use eval on the server side to to evaluate this expression.</p>
<p>For security I want to restrict user to add limited functions and operators by keeping a check (against some data-structure) before I pa... | 4 | 2010-01-14T15:43:52Z | 2,065,474 | <p>Perhaps the simplest check would be to look at all the words in the expression, and check them against a whitelist. Reject the expression if any of the words isn't on the whitelist.</p>
<pre><code>import re
expr = "foo() > 90 and boo() == 9 or do() > 100"
whitelist = "and or foo boo do".split()
for word in ... | 1 | 2010-01-14T16:01:07Z | [
"python"
] |
Parsing, securing python expression before passing it to eval() | 2,065,331 | <p>I want to take an input from the user may be like <code>foo() > 90 and boo() == 9 or do() > 100</code> and use eval on the server side to to evaluate this expression.</p>
<p>For security I want to restrict user to add limited functions and operators by keeping a check (against some data-structure) before I pa... | 4 | 2010-01-14T15:43:52Z | 2,065,491 | <p>You need to lock down the input format, or it will be a gaping security hole. Either implement a full blown parser, as lpthnc suggests, with a reasonable set of operations (but no more), or at least use a regular expression (or several regex patterns in a matching hierarchy and/or loop) to strip out recognized patt... | 1 | 2010-01-14T16:02:45Z | [
"python"
] |
Parsing, securing python expression before passing it to eval() | 2,065,331 | <p>I want to take an input from the user may be like <code>foo() > 90 and boo() == 9 or do() > 100</code> and use eval on the server side to to evaluate this expression.</p>
<p>For security I want to restrict user to add limited functions and operators by keeping a check (against some data-structure) before I pa... | 4 | 2010-01-14T15:43:52Z | 2,065,591 | <p>Basically the only way to do this is to parse it yourself. You navigate the parse tree to guarantee that each part is in a whitelist of perfectly benign and safe operations, making the entire expression safe by construction. Ned Batchelder's answer is actually a (simple) form of this. You could pass it to <code>eval... | 3 | 2010-01-14T16:17:47Z | [
"python"
] |
Linear Fit to Planet Positions | 2,065,550 | <p>An astounding alignment occurs 2048/5/28 with the inner 5 planets
having heliocentric longitudes (in degrees):
248.229, 66.631, 246.967, 249.605, 67.684.</p>
<p>The planets are at most 0.875 degrees from the line (through Sol)
with slope 67.823 degrees. In this case, the method sought (PA) would give:
PA(248.... | 0 | 2010-01-14T16:12:30Z | 2,065,978 | <p>Dumb as dirt method didn't work for reasons that should have been obvious: your data can be pathological for any choice of half-plane to map to. I'm going to recommend a <a href="http://mathworld.wolfram.com/LeastSquaresFitting.html" rel="nofollow">least squares approach</a>, but you do need to deal with the radial ... | 0 | 2010-01-14T17:08:00Z | [
"javascript",
"python"
] |
Get all numbers that add up to a number | 2,065,553 | <p>I'm trying to find a way to display all the possible sets of X integers that add up to a given integer. for example to get all 2 integer sets that make 5 I would have:</p>
<pre><code>1, 4
2, 3
</code></pre>
<p>Or for 3 integers that make 6:</p>
<pre><code>1, 1, 4
1, 2, 3
2, 2, 2
</code></pre>
<p>I only need whol... | 11 | 2010-01-14T16:12:49Z | 2,065,576 | <p><a href="http://en.wikipedia.org/wiki/Partition_(number_theory)">http://en.wikipedia.org/wiki/Partition_(number_theory)</a></p>
<p><a href="http://mathworld.wolfram.com/Partition.html">http://mathworld.wolfram.com/Partition.html</a></p>
<p><a href="http://code.activestate.com/recipes/218332/">http://code.activesta... | 14 | 2010-01-14T16:15:42Z | [
"python",
"math"
] |
Get all numbers that add up to a number | 2,065,553 | <p>I'm trying to find a way to display all the possible sets of X integers that add up to a given integer. for example to get all 2 integer sets that make 5 I would have:</p>
<pre><code>1, 4
2, 3
</code></pre>
<p>Or for 3 integers that make 6:</p>
<pre><code>1, 1, 4
1, 2, 3
2, 2, 2
</code></pre>
<p>I only need whol... | 11 | 2010-01-14T16:12:49Z | 2,065,624 | <p>There's a snippet <a href="http://wordaligned.org/articles/partitioning-with-python">here</a>:</p>
<pre><code>from itertools import combinations, chain
def sum_to_n(n):
'Generate the series of +ve integer lists which sum to a +ve integer, n.'
from operator import sub
b, mid, e = [0], list(range(1, n)),... | 6 | 2010-01-14T16:22:01Z | [
"python",
"math"
] |
Get all numbers that add up to a number | 2,065,553 | <p>I'm trying to find a way to display all the possible sets of X integers that add up to a given integer. for example to get all 2 integer sets that make 5 I would have:</p>
<pre><code>1, 4
2, 3
</code></pre>
<p>Or for 3 integers that make 6:</p>
<pre><code>1, 1, 4
1, 2, 3
2, 2, 2
</code></pre>
<p>I only need whol... | 11 | 2010-01-14T16:12:49Z | 2,068,008 | <p>These are called partitions of the integer in question. Others have provided links to define them.</p>
<p>A trick to do these things is often to do them recursively. For example, suppose I wanted to form all distinct ways to build 10 as the sum of exactly three integers, none of which appears more than once.</p>
<... | 0 | 2010-01-14T22:26:12Z | [
"python",
"math"
] |
Get all numbers that add up to a number | 2,065,553 | <p>I'm trying to find a way to display all the possible sets of X integers that add up to a given integer. for example to get all 2 integer sets that make 5 I would have:</p>
<pre><code>1, 4
2, 3
</code></pre>
<p>Or for 3 integers that make 6:</p>
<pre><code>1, 1, 4
1, 2, 3
2, 2, 2
</code></pre>
<p>I only need whol... | 11 | 2010-01-14T16:12:49Z | 2,074,693 | <p>Here is one way to solve this problem:</p>
<pre><code>def sum_to_n(n, size, limit=None):
"""Produce all lists of `size` positive integers in decreasing order
that add up to `n`."""
if size == 1:
yield [n]
return
if limit is None:
limit = n
start = (n + size - 1) // size
... | 8 | 2010-01-15T20:49:59Z | [
"python",
"math"
] |
Get all numbers that add up to a number | 2,065,553 | <p>I'm trying to find a way to display all the possible sets of X integers that add up to a given integer. for example to get all 2 integer sets that make 5 I would have:</p>
<pre><code>1, 4
2, 3
</code></pre>
<p>Or for 3 integers that make 6:</p>
<pre><code>1, 1, 4
1, 2, 3
2, 2, 2
</code></pre>
<p>I only need whol... | 11 | 2010-01-14T16:12:49Z | 10,244,575 | <p>Your question can be rephrased like this :</p>
<blockquote>
<p>Given a number N, find all sets [S1, S2, S3 .....] where the sum of each set equals N. The size of the sets are given by the number L.</p>
</blockquote>
<hr>
<p>First let's consider the case of <code>L=2</code>.This means that you can have the follo... | 0 | 2012-04-20T10:34:02Z | [
"python",
"math"
] |
Unknown Authn provider: wsgi ... fail! | 2,065,761 | <p>I have working wsgi authentication on another server, however a second server is not accepting the same configuration and errors upon reload with the message:</p>
<pre><code>Syntax error on line 12 of /etc/apache2/sites-enabled/mydomain.com
Unknown Authn provider: wsgi
... fail
</code></pre>
<p>Here is the rel... | 1 | 2010-01-14T16:39:03Z | 2,066,826 | <p>It turned out to be a wsgi version difference.</p>
| 1 | 2010-01-14T19:12:32Z | [
"python",
"apache",
"mod-wsgi",
"wsgi"
] |
A clean algorithm for sorting a objects according to defined dependencies? | 2,065,897 | <p>Given a list of classes inheriting from this base:</p>
<pre><code>class Plugin(object):
run_after_plugins = ()
run_before_plugins = ()
</code></pre>
<p>...and the following rules:</p>
<ul>
<li>Plugins can provide a list of plugins that they must run after.</li>
<li>Plugins can provide a list of plugins th... | 5 | 2010-01-14T16:58:01Z | 2,065,910 | <p>This is called <a href="http://en.wikipedia.org/wiki/Topological_sorting" rel="nofollow">topological sorting</a>.</p>
<blockquote>
<p>The canonical application of
topological sorting (topological
order) is in scheduling a sequence of
jobs or tasks; topological sorting
algorithms were first studied in the
... | 8 | 2010-01-14T16:59:19Z | [
"python",
"algorithm",
"order"
] |
A clean algorithm for sorting a objects according to defined dependencies? | 2,065,897 | <p>Given a list of classes inheriting from this base:</p>
<pre><code>class Plugin(object):
run_after_plugins = ()
run_before_plugins = ()
</code></pre>
<p>...and the following rules:</p>
<ul>
<li>Plugins can provide a list of plugins that they must run after.</li>
<li>Plugins can provide a list of plugins th... | 5 | 2010-01-14T16:58:01Z | 2,065,972 | <p>This is called <a href="http://en.wikipedia.org/wiki/Topological_sorting" rel="nofollow">topological sorting</a>.</p>
<p>Doing this involves several steps:</p>
<p>First build a graph of all choosen plugins as vertices and their dependencies as edges. Run before/after deps boil down to the same type of edges.</p>
... | 1 | 2010-01-14T17:07:28Z | [
"python",
"algorithm",
"order"
] |
A clean algorithm for sorting a objects according to defined dependencies? | 2,065,897 | <p>Given a list of classes inheriting from this base:</p>
<pre><code>class Plugin(object):
run_after_plugins = ()
run_before_plugins = ()
</code></pre>
<p>...and the following rules:</p>
<ul>
<li>Plugins can provide a list of plugins that they must run after.</li>
<li>Plugins can provide a list of plugins th... | 5 | 2010-01-14T16:58:01Z | 2,065,975 | <p>If you define the <code>__lt__</code> and associated methods on Plugin based on whether or not they should be run before or after then it could be possible to find a sane ordering with <code>sorted()</code>. Cycles would still be a problem though.</p>
| 0 | 2010-01-14T17:07:38Z | [
"python",
"algorithm",
"order"
] |
A clean algorithm for sorting a objects according to defined dependencies? | 2,065,897 | <p>Given a list of classes inheriting from this base:</p>
<pre><code>class Plugin(object):
run_after_plugins = ()
run_before_plugins = ()
</code></pre>
<p>...and the following rules:</p>
<ul>
<li>Plugins can provide a list of plugins that they must run after.</li>
<li>Plugins can provide a list of plugins th... | 5 | 2010-01-14T16:58:01Z | 2,067,212 | <p>If you want to give good diagnostics for the case that there are cycles, have a look at <a href="http://en.wikipedia.org/wiki/Strongly_connected_component" rel="nofollow">http://en.wikipedia.org/wiki/Strongly_connected_component</a>. I think that if you use a version of a Strongly connected component like the one ou... | 0 | 2010-01-14T20:05:03Z | [
"python",
"algorithm",
"order"
] |
A clean algorithm for sorting a objects according to defined dependencies? | 2,065,897 | <p>Given a list of classes inheriting from this base:</p>
<pre><code>class Plugin(object):
run_after_plugins = ()
run_before_plugins = ()
</code></pre>
<p>...and the following rules:</p>
<ul>
<li>Plugins can provide a list of plugins that they must run after.</li>
<li>Plugins can provide a list of plugins th... | 5 | 2010-01-14T16:58:01Z | 2,070,934 | <p><a href="http://www.bitformation.com/art/python_toposort.html" rel="nofollow">Here</a> is Python code that does topological sorting.</p>
| 2 | 2010-01-15T10:54:23Z | [
"python",
"algorithm",
"order"
] |
Making a PythonCard File Dialog single select? | 2,065,934 | <p>I'm working on a python application and have chosen to build the gui with PythonCard. I have need to have the user select a file to open, and in the context, selecting more than 1 file doesn't make sense. I can successfully create a file dioalog with</p>
<pre><code>dialog.fileDialog(self, 'Open Input File', '', '... | 0 | 2010-01-14T17:02:15Z | 2,066,058 | <p>Try setting the last line to wx.OPEN - that should be it. It seems that PythonCard specifies a dialog's main style as wx.OPEN | wx.MULTIPLE, so overriding it to just open should do the trick.</p>
| 1 | 2010-01-14T17:19:13Z | [
"python",
"pythoncard"
] |
Making a PythonCard File Dialog single select? | 2,065,934 | <p>I'm working on a python application and have chosen to build the gui with PythonCard. I have need to have the user select a file to open, and in the context, selecting more than 1 file doesn't make sense. I can successfully create a file dioalog with</p>
<pre><code>dialog.fileDialog(self, 'Open Input File', '', '... | 0 | 2010-01-14T17:02:15Z | 3,568,896 | <p>Here's a reference for PythonCard dialogs:
<a href="http://pythoncard.sourceforge.net/dialogs/index.html" rel="nofollow">pythoncard.sourceforge.net/dialogs</a></p>
<p>It provides an explanation of the arguments for each dialog type along with examples.</p>
| 0 | 2010-08-25T18:03:34Z | [
"python",
"pythoncard"
] |
How to capture keystrokes with a Python daemon? | 2,066,049 | <p>I'm trying to write a POS-style application for a <a href="http://en.wikipedia.org/wiki/SheevaPlug" rel="nofollow">Sheevaplug</a> that does the following:</p>
<ol>
<li>Captures input from a card reader (as I understand, most mag card readers emulate keyboard input, so basically I'm looking to capture that)</li>
<li... | 3 | 2010-01-14T17:18:14Z | 2,066,116 | <p>the format is explained in the <a href="http://www.mjmwired.net/kernel/Documentation/input/" rel="nofollow">kernel documentation</a> in section <em>5. Event Interface</em>.</p>
| 0 | 2010-01-14T17:27:25Z | [
"python",
"linux",
"keyboard",
"capture"
] |
How to capture keystrokes with a Python daemon? | 2,066,049 | <p>I'm trying to write a POS-style application for a <a href="http://en.wikipedia.org/wiki/SheevaPlug" rel="nofollow">Sheevaplug</a> that does the following:</p>
<ol>
<li>Captures input from a card reader (as I understand, most mag card readers emulate keyboard input, so basically I'm looking to capture that)</li>
<li... | 3 | 2010-01-14T17:18:14Z | 2,066,118 | <p>Section 5 of the Linux kernel <a href="http://www.kernel.org/doc/Documentation/input/input.txt" rel="nofollow">input documentation</a> describes what each of the values in the event interface means.</p>
| 2 | 2010-01-14T17:27:43Z | [
"python",
"linux",
"keyboard",
"capture"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.