title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
How do I send attachments using SMTP? | 1,966,073 | <p>I want to write a program that sends email using Python's <a href="http://docs.python.org/library/smtplib.html">smtplib</a>. I searched through the document and the RFCs, but couldn't find anything related to attachments. Thus, I'm sure there's some higher-level concept I'm missing out on. Can someone clue me in ... | 16 | 2009-12-27T14:31:19Z | 1,966,261 | <p>Here's an example I snipped out of a work application we did. It creates an HTML email with an Excel attachment.</p>
<pre><code> import smtplib,email,email.encoders,email.mime.text,email.mime.base
smtpserver = 'localhost'
to = ['email@somewhere.com']
fromAddr = 'automated@hi.com'
subject = "my subject"
... | 17 | 2009-12-27T16:03:46Z | [
"python",
"email",
"smtp",
"attachment",
"smtplib"
] |
How do I send attachments using SMTP? | 1,966,073 | <p>I want to write a program that sends email using Python's <a href="http://docs.python.org/library/smtplib.html">smtplib</a>. I searched through the document and the RFCs, but couldn't find anything related to attachments. Thus, I'm sure there's some higher-level concept I'm missing out on. Can someone clue me in ... | 16 | 2009-12-27T14:31:19Z | 2,161,217 | <p>Here's how to send e-mails with zip file attachments and utf-8 encoded subject+body.</p>
<p>It was not straightforward to figure this one out, due to lack of documentation and samples for this particular case.</p>
<p>Non-ascii characters in replyto needs to be encoded with, for instance, ISO-8859-1. There probably... | 0 | 2010-01-29T10:17:11Z | [
"python",
"email",
"smtp",
"attachment",
"smtplib"
] |
How do I send attachments using SMTP? | 1,966,073 | <p>I want to write a program that sends email using Python's <a href="http://docs.python.org/library/smtplib.html">smtplib</a>. I searched through the document and the RFCs, but couldn't find anything related to attachments. Thus, I'm sure there's some higher-level concept I'm missing out on. Can someone clue me in ... | 16 | 2009-12-27T14:31:19Z | 8,243,031 | <p>Here is an example of a message with a PDF attachment, a text "body" and sending via Gmail.</p>
<pre><code># Import smtplib for the actual sending function
import smtplib
# For guessing MIME type
import mimetypes
# Import the email modules we'll need
import email
import email.mime.application
# Create a text/pla... | 19 | 2011-11-23T13:32:07Z | [
"python",
"email",
"smtp",
"attachment",
"smtplib"
] |
Converting NumPy array into Python List structure? | 1,966,207 | <p>How do I convert a <a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> array to a Python List (for example <code>[[1,2,3],[4,5,6]]</code> ), and do it reasonably fast?</p>
| 112 | 2009-12-27T15:29:55Z | 1,966,210 | <p>Use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.tolist.html"><code>tolist()</code></a>:</p>
<pre><code>import numpy as np
>>> np.array([[1,2,3],[4,5,6]]).tolist()
[[1, 2, 3], [4, 5, 6]]
</code></pre>
| 164 | 2009-12-27T15:31:19Z | [
"python",
"numpy"
] |
Converting NumPy array into Python List structure? | 1,966,207 | <p>How do I convert a <a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> array to a Python List (for example <code>[[1,2,3],[4,5,6]]</code> ), and do it reasonably fast?</p>
| 112 | 2009-12-27T15:29:55Z | 1,966,212 | <p>NumPy arrays have a <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.tolist.html?highlight=tolist#numpy.ndarray.tolist">tolist method</a>: </p>
<pre><code>In [1]: arr=np.array([[1,2,3],[4,5,6]])
In [2]: arr.tolist()
Out[2]: [[1, 2, 3], [4, 5, 6]]
</code></pre>
| 31 | 2009-12-27T15:32:33Z | [
"python",
"numpy"
] |
Converting NumPy array into Python List structure? | 1,966,207 | <p>How do I convert a <a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> array to a Python List (for example <code>[[1,2,3],[4,5,6]]</code> ), and do it reasonably fast?</p>
| 112 | 2009-12-27T15:29:55Z | 38,522,435 | <p>You can also use the <strong>list</strong> keyword of Python to create a list from the numpy array:</p>
<pre><code>import numpy as np
nda = np.arange(10).reshape(2,5)
ndlist = list(nda)
</code></pre>
| 0 | 2016-07-22T09:04:54Z | [
"python",
"numpy"
] |
Converting NumPy array into Python List structure? | 1,966,207 | <p>How do I convert a <a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> array to a Python List (for example <code>[[1,2,3],[4,5,6]]</code> ), and do it reasonably fast?</p>
| 112 | 2009-12-27T15:29:55Z | 39,682,665 | <p>The numpy .tolist method produces nested arrays if the numpy array shape is 2D.</p>
<p>if flat lists are desired, the method below works.</p>
<pre><code>import numpy as np
from itertools import chain
a = [1,2,3,4,5,6,7,8,9]
print type(a), len(a), a
npa = np.asarray(a)
print type(npa), npa.shape, "\n", npa
npa = n... | 0 | 2016-09-25T01:49:57Z | [
"python",
"numpy"
] |
Converting arrays between NumPy and JPype? | 1,966,253 | <p>Does a library or script exist to convert between <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a> and <a href="http://jpype.sourceforge.net/" rel="nofollow">JPype</a> arrays?</p>
| 0 | 2009-12-27T16:00:03Z | 1,966,730 | <p>Doesn't </p>
<pre><code>JArray(float, 1)(numpyarray)
</code></pre>
<p>work?</p>
<p>At least</p>
<pre><code>JArray(float, 1)(numpyarray.tolist())
</code></pre>
<p>should work.</p>
| 1 | 2009-12-27T19:05:11Z | [
"java",
"python",
"numpy"
] |
mysql-python: building a completely standalone _mysql.so on Mac OS X? | 1,966,322 | <p>I'm running a database server in a Linux VM (Ubuntu 9.10) under VMware Fusion, but coding Django on the Mac side. Installing mysql-python requires that MySQL is installed on the Mac for compiling <code>_mysql.so</code> into <code>site-packages</code>.</p>
<p>However, after this is done, I have no further use for My... | 1 | 2009-12-27T16:30:30Z | 1,966,530 | <p>Never mind, found out myself after a bit more digging. It's pretty simple, actually; I'll record the solution here in case someone else needs it:</p>
<ol>
<li><p>Get the source tarball of MySQL from mysql.com (not the platform-specific binary tarball)</p></li>
<li><p>Unpack it, run <code>./configure</code> with wha... | 3 | 2009-12-27T17:48:03Z | [
"python",
"mysql",
"osx",
"static",
"compilation"
] |
mysql-python: building a completely standalone _mysql.so on Mac OS X? | 1,966,322 | <p>I'm running a database server in a Linux VM (Ubuntu 9.10) under VMware Fusion, but coding Django on the Mac side. Installing mysql-python requires that MySQL is installed on the Mac for compiling <code>_mysql.so</code> into <code>site-packages</code>.</p>
<p>However, after this is done, I have no further use for My... | 1 | 2009-12-27T16:30:30Z | 23,995,714 | <p>I landed here trying to build a static MySQLdb on an older linux. I found that MySQL had transitioned to cmake:</p>
<ul>
<li><a href="http://dev.mysql.com/doc/relnotes/mysql/5.5/en/news-5-5-8.html" rel="nofollow">http://dev.mysql.com/doc/relnotes/mysql/5.5/en/news-5-5-8.html</a></li>
<li><a href="http://dev.mysql.... | 1 | 2014-06-02T13:27:10Z | [
"python",
"mysql",
"osx",
"static",
"compilation"
] |
cut off empty spaces | 1,966,426 | <p>How can i cut off the last empty space?</p>
<pre><code>a = ['Hello ','everybody ','! ']
for i in range(len(a)):
a[i,-1]=''
print a
</code></pre>
| 1 | 2009-12-27T17:08:09Z | 1,966,431 | <p>Solution via <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a>:</p>
<pre><code>>>> a = ['Hello ','everybody ','! ']
>>> [ e.strip() for e in a ]
['Hello', 'everybody', '!']
</code></pre>
<p>Documentation: <a href="http://docs.p... | 5 | 2009-12-27T17:10:11Z | [
"python",
"string"
] |
cut off empty spaces | 1,966,426 | <p>How can i cut off the last empty space?</p>
<pre><code>a = ['Hello ','everybody ','! ']
for i in range(len(a)):
a[i,-1]=''
print a
</code></pre>
| 1 | 2009-12-27T17:08:09Z | 1,966,433 | <pre><code>print [x.strip() for x in a]
</code></pre>
<p>This is called <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a></p>
| 1 | 2009-12-27T17:10:42Z | [
"python",
"string"
] |
cut off empty spaces | 1,966,426 | <p>How can i cut off the last empty space?</p>
<pre><code>a = ['Hello ','everybody ','! ']
for i in range(len(a)):
a[i,-1]=''
print a
</code></pre>
| 1 | 2009-12-27T17:08:09Z | 1,966,440 | <p>To cut off only <em>last</em> (right) empty spaces, use <code>rstrip()</code> method. <code>strip()</code> removes spaces from both ends:</p>
<pre><code>>>> s = " abc "
>>> s.rstrip()
' abc'
>>> s.strip()
'abc'
</code></pre>
<p>In your example:</p>
<pre><code>>>> [s.rstrip() fo... | 10 | 2009-12-27T17:13:10Z | [
"python",
"string"
] |
cut off empty spaces | 1,966,426 | <p>How can i cut off the last empty space?</p>
<pre><code>a = ['Hello ','everybody ','! ']
for i in range(len(a)):
a[i,-1]=''
print a
</code></pre>
| 1 | 2009-12-27T17:08:09Z | 1,966,497 | <p>The list comprehension approaches mentioned above would be the Pythonic way to solve this problem but they don't alter the list itself (ie. a). If you want to change those, you'll have to iterate as you've done over the list and instead of your assignment do an </p>
<pre><code>a[i] = a[i].rstrip() # For stripping o... | 1 | 2009-12-27T17:39:35Z | [
"python",
"string"
] |
cut off empty spaces | 1,966,426 | <p>How can i cut off the last empty space?</p>
<pre><code>a = ['Hello ','everybody ','! ']
for i in range(len(a)):
a[i,-1]=''
print a
</code></pre>
| 1 | 2009-12-27T17:08:09Z | 1,967,450 | <pre><code>>>> a = ['Hello ','everybody ','! ']
>>> map(str.rstrip,a)
['Hello', 'everybody', '!']
>>> b = map(str.rstrip,a)
</code></pre>
| 0 | 2009-12-28T00:00:59Z | [
"python",
"string"
] |
python print statements fixes OverflowError | 1,966,456 | <p>I'm hacking a security system DVR so I can add motion capture and other fun features in python (version 2.6). One of the functions I was able to decompile from java and convert to python was the following:</p>
<pre><code>def ToInt(abyte0, i):
if(abyte0[i] >= 0):
j = abyte0[i]
print "A " + str(j)
... | 0 | 2009-12-27T17:21:57Z | 1,966,531 | <p>If you pass socket.recv() a value larger than 2147483647 (hex 0x7fffffff) Python will attempt to use a long integer instead of a regular integer. Clearly your value for DATA_SIZE is considered to be larger than that.</p>
<p>The ToInt() code appears to be trying to build up an integer out of individual bytes, and l... | 4 | 2009-12-27T17:48:09Z | [
"python",
"casting"
] |
python print statements fixes OverflowError | 1,966,456 | <p>I'm hacking a security system DVR so I can add motion capture and other fun features in python (version 2.6). One of the functions I was able to decompile from java and convert to python was the following:</p>
<pre><code>def ToInt(abyte0, i):
if(abyte0[i] >= 0):
j = abyte0[i]
print "A " + str(j)
... | 0 | 2009-12-27T17:21:57Z | 1,966,567 | <p>Here's an example of the problem</p>
<pre><code>if abyte0[i + 3] >= 0:
j = j + abyte0[i + 3] * 256 * 256 * 256
#print "A " + str(j)
else:
j = j + (256 + abyte0[i + 3]) * 256 * 256 * 256
</code></pre>
<p>Let's pretend <code>j == 0</code> and <code>abyte0 == ( 0, 0, 0, 0)</code> and <code>i == 0</code... | 0 | 2009-12-27T17:57:54Z | [
"python",
"casting"
] |
Delete the \n and following letters in the end of words in a list | 1,966,495 | <p>How can I delete the <code>\n</code> and the following letters? Thanks a lot.</p>
<pre><code>wordlist = ['Schreiben\nEs', 'Schreiben', 'Schreiben\nEventuell', 'Schreiben\nHaruki']
for x in wordlist:
...?
</code></pre>
| 0 | 2009-12-27T17:37:34Z | 1,966,504 | <pre><code>>>> import re
>>> wordlist = ['Schreiben\nEs', 'Schreiben', \
'Schreiben\nEventuell', 'Schreiben\nHaruki']
>>> [ re.sub("\n.*", "", word) for word in wordlist ]
['Schreiben', 'Schreiben', 'Schreiben', 'Schreiben']
</code></pre>
<p>Done via <code>re.sub</code>:</p>
<pre><code>... | 4 | 2009-12-27T17:40:56Z | [
"python",
"string"
] |
Delete the \n and following letters in the end of words in a list | 1,966,495 | <p>How can I delete the <code>\n</code> and the following letters? Thanks a lot.</p>
<pre><code>wordlist = ['Schreiben\nEs', 'Schreiben', 'Schreiben\nEventuell', 'Schreiben\nHaruki']
for x in wordlist:
...?
</code></pre>
| 0 | 2009-12-27T17:37:34Z | 1,966,510 | <p>You could use a regular expression to do so:</p>
<pre><code>import re
wordlist = [re.sub("\n.*", "", word) for word in wordlist]
</code></pre>
<p>The regular expression <code>\n.*</code> matches the first <code>\n</code> and anything that might follow (<code>.*</code>) and replaces it with nothing.</p>
| 1 | 2009-12-27T17:42:52Z | [
"python",
"string"
] |
Delete the \n and following letters in the end of words in a list | 1,966,495 | <p>How can I delete the <code>\n</code> and the following letters? Thanks a lot.</p>
<pre><code>wordlist = ['Schreiben\nEs', 'Schreiben', 'Schreiben\nEventuell', 'Schreiben\nHaruki']
for x in wordlist:
...?
</code></pre>
| 0 | 2009-12-27T17:37:34Z | 1,966,547 | <pre><code>[w[:w.find('\n')] fow w in wordlist]
</code></pre>
<p>few tests:</p>
<pre><code>$ python -m timeit -s "wordlist = ['Schreiben\nEs', 'Schreiben', 'Schreiben\nEventuell', 'Schreiben\nHaruki']" "[w[:w.find('\n')] for w in wordlist]"
100000 loops, best of 3: 2.03 usec per loop
$ python -m timeit -s "import re;... | 3 | 2009-12-27T17:52:58Z | [
"python",
"string"
] |
Delete the \n and following letters in the end of words in a list | 1,966,495 | <p>How can I delete the <code>\n</code> and the following letters? Thanks a lot.</p>
<pre><code>wordlist = ['Schreiben\nEs', 'Schreiben', 'Schreiben\nEventuell', 'Schreiben\nHaruki']
for x in wordlist:
...?
</code></pre>
| 0 | 2009-12-27T17:37:34Z | 1,967,437 | <pre><code>>>> wordlist = ['Schreiben\nEs', 'Schreiben', 'Schreiben\nEventuell', 'Schreiben\nHaruki']
>>> [ i.split("\n")[0] for i in wordlist ]
['Schreiben', 'Schreiben', 'Schreiben', 'Schreiben']
</code></pre>
| 0 | 2009-12-27T23:55:15Z | [
"python",
"string"
] |
hasNext in Python iterators? | 1,966,591 | <p>Haven't Python iterators got a <code>hasNext</code> method?</p>
| 59 | 2009-12-27T18:04:51Z | 1,966,602 | <p>No. The most similar concept is most likely a <a href="http://docs.python.org/library/exceptions.html#exceptions.StopIteration" rel="nofollow">StopIteration exception.</a> </p>
| 3 | 2009-12-27T18:07:34Z | [
"python",
"iterator"
] |
hasNext in Python iterators? | 1,966,591 | <p>Haven't Python iterators got a <code>hasNext</code> method?</p>
| 59 | 2009-12-27T18:04:51Z | 1,966,603 | <p>I believe python just has next() and according to the doc, it throws an exception is there are no more elements.</p>
<p><a href="http://docs.python.org/library/stdtypes.html#iterator-types" rel="nofollow">http://docs.python.org/library/stdtypes.html#iterator-types</a></p>
| 1 | 2009-12-27T18:07:34Z | [
"python",
"iterator"
] |
hasNext in Python iterators? | 1,966,591 | <p>Haven't Python iterators got a <code>hasNext</code> method?</p>
| 59 | 2009-12-27T18:04:51Z | 1,966,609 | <p>No, there is no such method. The end of iteration is indicated by an exception. See the <a href="http://docs.python.org/library/stdtypes.html#iterator-types">documentation</a>.</p>
| 43 | 2009-12-27T18:08:52Z | [
"python",
"iterator"
] |
hasNext in Python iterators? | 1,966,591 | <p>Haven't Python iterators got a <code>hasNext</code> method?</p>
| 59 | 2009-12-27T18:04:51Z | 1,966,615 | <p><code>hasNext</code> somewhat translates to the <code>StopIteration</code> exception, e.g.:</p>
<pre><code>>>> it = iter("hello")
>>> it.next()
'h'
>>> it.next()
'e'
>>> it.next()
'l'
>>> it.next()
'l'
>>> it.next()
'o'
>>> it.next()
Traceback (most rec... | 5 | 2009-12-27T18:11:10Z | [
"python",
"iterator"
] |
hasNext in Python iterators? | 1,966,591 | <p>Haven't Python iterators got a <code>hasNext</code> method?</p>
| 59 | 2009-12-27T18:04:51Z | 1,967,037 | <p>If you really <strong>need</strong> a <code>has-next</code> functionality (because you're just faithfully transcribing an algorithm from a reference implementation in Java, say, or because you're writing a prototype that <em>will</em> need to be easily transcribed to Java when it's finished), it's easy to obtain it ... | 27 | 2009-12-27T21:02:57Z | [
"python",
"iterator"
] |
hasNext in Python iterators? | 1,966,591 | <p>Haven't Python iterators got a <code>hasNext</code> method?</p>
| 59 | 2009-12-27T18:04:51Z | 1,967,798 | <p>In addition to all the mentions of StopIteration, the Python "for" loop simply does what you want:</p>
<pre><code>>>> it = iter("hello")
>>> for i in it:
... print i
...
h
e
l
l
o
</code></pre>
| 6 | 2009-12-28T02:52:55Z | [
"python",
"iterator"
] |
hasNext in Python iterators? | 1,966,591 | <p>Haven't Python iterators got a <code>hasNext</code> method?</p>
| 59 | 2009-12-27T18:04:51Z | 1,967,844 | <p>You can <code>tee</code> the iterator using, <code>itertools.tee</code>, and check for <code>StopIteration</code> on the teed iterator.</p>
| 2 | 2009-12-28T03:25:36Z | [
"python",
"iterator"
] |
hasNext in Python iterators? | 1,966,591 | <p>Haven't Python iterators got a <code>hasNext</code> method?</p>
| 59 | 2009-12-27T18:04:51Z | 1,983,220 | <p>Try the __length_hint__() method from any iterator object:</p>
<pre><code>iter(...).__length_hint__() > 0
</code></pre>
| 5 | 2009-12-31T00:06:15Z | [
"python",
"iterator"
] |
hasNext in Python iterators? | 1,966,591 | <p>Haven't Python iterators got a <code>hasNext</code> method?</p>
| 59 | 2009-12-27T18:04:51Z | 15,606,960 | <p>There's an alternative to the <code>StopIteration</code> by using <code>next(iterator, default_value)</code>.</p>
<p>For exapmle:</p>
<pre><code>>>> a = iter('hi')
>>> print next(a, None)
h
>>> print next(a, None)
i
>>> print next(a, None)
None
</code></pre>
<p>So you can detec... | 70 | 2013-03-25T03:05:16Z | [
"python",
"iterator"
] |
hasNext in Python iterators? | 1,966,591 | <p>Haven't Python iterators got a <code>hasNext</code> method?</p>
| 59 | 2009-12-27T18:04:51Z | 21,077,387 | <p>The use case that lead me to search for this is the following</p>
<pre><code>def setfrom(self,f):
"""Set from iterable f"""
fi = iter(f)
for i in range(self.n):
try:
x = next(fi)
except StopIteration:
fi = iter(f)
x = next(fi)
self.a[i] = x
</... | 1 | 2014-01-12T16:49:08Z | [
"python",
"iterator"
] |
hasNext in Python iterators? | 1,966,591 | <p>Haven't Python iterators got a <code>hasNext</code> method?</p>
| 59 | 2009-12-27T18:04:51Z | 21,875,957 | <p>good approach for such question/problems is check what we have in dir(object/method/iterator/type/class/ ...)</p>
<p>you will see that <code>dir(iterator)</code> return <code>__length_hint__</code></p>
<p>and <code>iterator.__length_hint__()</code> is positive until end of the iteration.</p>
<p>that's it.</p>
| 0 | 2014-02-19T09:21:06Z | [
"python",
"iterator"
] |
hasNext in Python iterators? | 1,966,591 | <p>Haven't Python iterators got a <code>hasNext</code> method?</p>
| 59 | 2009-12-27T18:04:51Z | 31,886,975 | <p>I like this:</p>
<pre><code>While(True):
try:
# Do something with the next value
iterator.next()
except StopIteration:
break
</code></pre>
| 0 | 2015-08-07T21:34:31Z | [
"python",
"iterator"
] |
In python is there any way I can obtain the arguments passed to a function as object? | 1,966,715 | <p>I don't want to use *args or **kwargs since I can't change function declaration.</p>
<p>For example:</p>
<pre><code>def foo( a, b, c ) """Lets say values passed to a, b and c are 1,2 and 3 respectively"""
...
...
""" I would like to generate an object preferably a dictionary such as {'a':1, 'b':2, 'c':3} ... | 1 | 2009-12-27T19:00:36Z | 1,966,723 | <p>If you can't change the function "declaration" (why not?) but you can change the contents of the function, then just create the dictionary as you want it:</p>
<pre><code>def foo(a, b, c):
mydict = {'a': a, 'b': b, 'c': c}
</code></pre>
<p>If that doesn't work, I think you need a better explanation of what you ... | 5 | 2009-12-27T19:02:36Z | [
"python",
"function",
"object",
"arguments"
] |
In python is there any way I can obtain the arguments passed to a function as object? | 1,966,715 | <p>I don't want to use *args or **kwargs since I can't change function declaration.</p>
<p>For example:</p>
<pre><code>def foo( a, b, c ) """Lets say values passed to a, b and c are 1,2 and 3 respectively"""
...
...
""" I would like to generate an object preferably a dictionary such as {'a':1, 'b':2, 'c':3} ... | 1 | 2009-12-27T19:00:36Z | 1,966,725 | <pre><code>def foo(a, b, c):
args = {"a": a, "b": b, "c": c}
</code></pre>
| 0 | 2009-12-27T19:03:03Z | [
"python",
"function",
"object",
"arguments"
] |
In python is there any way I can obtain the arguments passed to a function as object? | 1,966,715 | <p>I don't want to use *args or **kwargs since I can't change function declaration.</p>
<p>For example:</p>
<pre><code>def foo( a, b, c ) """Lets say values passed to a, b and c are 1,2 and 3 respectively"""
...
...
""" I would like to generate an object preferably a dictionary such as {'a':1, 'b':2, 'c':3} ... | 1 | 2009-12-27T19:00:36Z | 1,966,808 | <p>@Rohit, we do not understand what you mean when you say "the function declaration". If you mean you don't want to change the API of the function (the documented way the function is called), perhaps because you have existing code already calling an existing function, then you can still use the <code>**kwargs</code> ... | 1 | 2009-12-27T19:42:14Z | [
"python",
"function",
"object",
"arguments"
] |
In python is there any way I can obtain the arguments passed to a function as object? | 1,966,715 | <p>I don't want to use *args or **kwargs since I can't change function declaration.</p>
<p>For example:</p>
<pre><code>def foo( a, b, c ) """Lets say values passed to a, b and c are 1,2 and 3 respectively"""
...
...
""" I would like to generate an object preferably a dictionary such as {'a':1, 'b':2, 'c':3} ... | 1 | 2009-12-27T19:00:36Z | 1,972,103 | <p>By diligent searching of StackOverflow, I <a href="http://stackoverflow.com/questions/218616/getting-method-parameter-names-in-python">found out</a> how to do this. You use the <code>inspect</code> module.</p>
<pre><code>import inspect
def make_wrapper(fn):
arg_names = inspect.getargspec(fn)[0]
def wrappe... | 1 | 2009-12-28T23:28:43Z | [
"python",
"function",
"object",
"arguments"
] |
Measure time of a function with arguments in Python | 1,966,750 | <p>I am trying to measure the time of <code>raw_queries(...)</code>, unsuccessfully so far. I found that I should use the timeit module. The problem is that I can't (= I don't know how) pass the arguments to the function from the environment.</p>
<p>Important note: Before calling <code>raw_queries</code>, we have to e... | 2 | 2009-12-27T19:17:06Z | 1,966,766 | <p>I'm not sure about this, I've never used it, but from what I've read it should be something like this:</p>
<pre><code>....
t = Timer("raw_queries(queries, nlp)", "from __main__ import raw_queries")
print t.timeit()
</code></pre>
<p>I took this from <a href="http://docs.python.org/library/timeit.html" rel="nofollow... | 1 | 2009-12-27T19:23:46Z | [
"python",
"performance",
"time",
"arguments",
"timeit"
] |
Measure time of a function with arguments in Python | 1,966,750 | <p>I am trying to measure the time of <code>raw_queries(...)</code>, unsuccessfully so far. I found that I should use the timeit module. The problem is that I can't (= I don't know how) pass the arguments to the function from the environment.</p>
<p>Important note: Before calling <code>raw_queries</code>, we have to e... | 2 | 2009-12-27T19:17:06Z | 1,966,782 | <p>Custom timer function may be a solution:</p>
<pre><code>import time
def timer(fun,*args):
start = time.time()
ret = fun(*args)
end = time.time()
return (ret, end-start)
</code></pre>
<p>Using like this:</p>
<pre><code>>>> from math import sin
>>> timer(sin, 0.5)
(0.4794255386042... | 1 | 2009-12-27T19:30:58Z | [
"python",
"performance",
"time",
"arguments",
"timeit"
] |
Measure time of a function with arguments in Python | 1,966,750 | <p>I am trying to measure the time of <code>raw_queries(...)</code>, unsuccessfully so far. I found that I should use the timeit module. The problem is that I can't (= I don't know how) pass the arguments to the function from the environment.</p>
<p>Important note: Before calling <code>raw_queries</code>, we have to e... | 2 | 2009-12-27T19:17:06Z | 1,966,841 | <p>Normally, you would use <a href="http://docs.python.org/library/timeit.html#timeit.Timer.timeit" rel="nofollow">timeit</a>.</p>
<p>Examples are <a href="http://docs.python.org/library/timeit.html#examples" rel="nofollow">here</a> and <a href="http://diveintopython.net/performance_tuning/timeit.html" rel="nofollow">... | 2 | 2009-12-27T19:48:54Z | [
"python",
"performance",
"time",
"arguments",
"timeit"
] |
Measure time of a function with arguments in Python | 1,966,750 | <p>I am trying to measure the time of <code>raw_queries(...)</code>, unsuccessfully so far. I found that I should use the timeit module. The problem is that I can't (= I don't know how) pass the arguments to the function from the environment.</p>
<p>Important note: Before calling <code>raw_queries</code>, we have to e... | 2 | 2009-12-27T19:17:06Z | 1,966,914 | <p>First, never use the time module to time functions. It can easily lead to wrong conclusions. See <a href="http://stackoverflow.com/questions/1622943/timeit-versus-timing-decorator">http://stackoverflow.com/questions/1622943/timeit-versus-timing-decorator</a> for an example.</p>
<p>The easiest way to time a function... | 4 | 2009-12-27T20:13:11Z | [
"python",
"performance",
"time",
"arguments",
"timeit"
] |
Measure time of a function with arguments in Python | 1,966,750 | <p>I am trying to measure the time of <code>raw_queries(...)</code>, unsuccessfully so far. I found that I should use the timeit module. The problem is that I can't (= I don't know how) pass the arguments to the function from the environment.</p>
<p>Important note: Before calling <code>raw_queries</code>, we have to e... | 2 | 2009-12-27T19:17:06Z | 1,971,180 | <p>You don't say so, but are you by any chance trying to make the code go faster? If so, I suggest you not focus in on a particular routine and try to time it. Even if you get a number, it won't really tell you what to fix. If you can pause the program under the IDE several times and examine it's state, including the c... | 0 | 2009-12-28T19:46:32Z | [
"python",
"performance",
"time",
"arguments",
"timeit"
] |
Why I can't call packagename.modulename.foo()? | 1,966,783 | <p>In my working python directory I create:</p>
<pre><code>packagename/__init__.py
packagename/modulename.py
test.py
</code></pre>
<p>In modulename.py I create some empty class:</p>
<pre><code>class Someclass(object):
pass
</code></pre>
<p>in test.py:</p>
<pre><code>import packagename
packagename.modulename.Som... | 1 | 2009-12-27T19:32:06Z | 1,966,794 | <p>Some packages are very large and importing everything within them would take a lot of time. It's better to offer fine granularity for imports, so the user only imports what he really needs.</p>
| 0 | 2009-12-27T19:37:47Z | [
"python",
"import",
"package"
] |
Why I can't call packagename.modulename.foo()? | 1,966,783 | <p>In my working python directory I create:</p>
<pre><code>packagename/__init__.py
packagename/modulename.py
test.py
</code></pre>
<p>In modulename.py I create some empty class:</p>
<pre><code>class Someclass(object):
pass
</code></pre>
<p>in test.py:</p>
<pre><code>import packagename
packagename.modulename.Som... | 1 | 2009-12-27T19:32:06Z | 1,966,800 | <p>If you had 100 modules in the "packagename" package, would you want them all to be imported automatically when you imported just the top-level name? That wouldn't usually be a good idea, so Python doesn't do it.</p>
<p>If you want to have that particular module imported automatically, just include it in the <code>... | 1 | 2009-12-27T19:39:24Z | [
"python",
"import",
"package"
] |
Why I can't call packagename.modulename.foo()? | 1,966,783 | <p>In my working python directory I create:</p>
<pre><code>packagename/__init__.py
packagename/modulename.py
test.py
</code></pre>
<p>In modulename.py I create some empty class:</p>
<pre><code>class Someclass(object):
pass
</code></pre>
<p>in test.py:</p>
<pre><code>import packagename
packagename.modulename.Som... | 1 | 2009-12-27T19:32:06Z | 1,966,804 | <p>Python does not automatically recurse and import subpackages. When you say:</p>
<pre><code>import packagename
</code></pre>
<p>That is all it imports. If you say:</p>
<pre><code>import packagename.modulename
</code></pre>
<p>Then it first imports <code>packagename</code>, then imports <code>packagename.modulen... | 2 | 2009-12-27T19:40:41Z | [
"python",
"import",
"package"
] |
Tk treeview column sort | 1,966,929 | <p>Is there a way to sort the entries in a <a href="http://www.tkdocs.com/tutorial/tree.html">Tk Treeview</a> by clicking the column? Surprisingly, I could not find any documentation/tutorial for this.</p>
| 7 | 2009-12-27T20:18:33Z | 1,967,793 | <p><a href="http://www.patthoyts.tk/">patthoyts</a> from <code>#tcl</code> pointed out that the TreeView Tk demo program had the sort functionality. Here's the Python equivalent of it:</p>
<pre><code>def treeview_sort_column(tv, col, reverse):
l = [(tv.set(k, col), k) for k in tv.get_children('')]
l.sort(rever... | 15 | 2009-12-28T02:49:20Z | [
"python",
"sorting",
"treeview",
"tkinter"
] |
Tk treeview column sort | 1,966,929 | <p>Is there a way to sort the entries in a <a href="http://www.tkdocs.com/tutorial/tree.html">Tk Treeview</a> by clicking the column? Surprisingly, I could not find any documentation/tutorial for this.</p>
| 7 | 2009-12-27T20:18:33Z | 1,970,189 | <p>Along with #tcl, other apt resources for Tkinter research are the Tkinter mailing list and Wiki.</p>
| 1 | 2009-12-28T16:13:56Z | [
"python",
"sorting",
"treeview",
"tkinter"
] |
Tk treeview column sort | 1,966,929 | <p>Is there a way to sort the entries in a <a href="http://www.tkdocs.com/tutorial/tree.html">Tk Treeview</a> by clicking the column? Surprisingly, I could not find any documentation/tutorial for this.</p>
| 7 | 2009-12-27T20:18:33Z | 30,724,912 | <p>This did not work in python3. Since the Variable was passed by reference, all lambdas ended up refering to the same, last, element in columns.</p>
<p>This did the trick for me:</p>
<pre><code>for col in columns:
treeview.heading(col, text=col, command=lambda _col=col: \
treeview_sort_colum... | 4 | 2015-06-09T06:53:10Z | [
"python",
"sorting",
"treeview",
"tkinter"
] |
Google App Engine - How do I split code into multiple files? (webapp) | 1,966,974 | <p>I have a question about splitting up a main.py file.</p>
<p>right now, I have everything in my main.py. I have no other .py files. And I always have to scroll long lines of code before reaching the section I wish to edit.</p>
<p>How do I split it up?
(i'm going to have more than 20 pages, so that means the main.p... | 14 | 2009-12-27T20:40:01Z | 1,966,986 | <p>Define your classes in other .py files and use "import" to use them in your main.py. It is quite simple actually.</p>
| 2 | 2009-12-27T20:44:54Z | [
"python",
"google-app-engine",
"web-applications"
] |
Google App Engine - How do I split code into multiple files? (webapp) | 1,966,974 | <p>I have a question about splitting up a main.py file.</p>
<p>right now, I have everything in my main.py. I have no other .py files. And I always have to scroll long lines of code before reaching the section I wish to edit.</p>
<p>How do I split it up?
(i'm going to have more than 20 pages, so that means the main.p... | 14 | 2009-12-27T20:40:01Z | 1,966,990 | <p>Splitting the code is no different than splitting code for any Python app - find a bunch of related code that you want to move to another file, move it to that file, and import it into the main handler file.</p>
<p>For example, you could move the Page2 code to page2.py, put</p>
<pre><code>import page2
</code></pre... | 22 | 2009-12-27T20:45:50Z | [
"python",
"google-app-engine",
"web-applications"
] |
Google App Engine - How do I split code into multiple files? (webapp) | 1,966,974 | <p>I have a question about splitting up a main.py file.</p>
<p>right now, I have everything in my main.py. I have no other .py files. And I always have to scroll long lines of code before reaching the section I wish to edit.</p>
<p>How do I split it up?
(i'm going to have more than 20 pages, so that means the main.p... | 14 | 2009-12-27T20:40:01Z | 1,967,516 | <p>thx for the input, really appreciate them.</p>
<p>as for grouping imports together, i tried to keep all app-engine related imports into a .py file called ext.py</p>
<p>Then I called it anywhere I wanted to use it by this line:</p>
<pre><code>from ext import *
</code></pre>
<p>ext.py contains the following:</p>
... | 0 | 2009-12-28T00:25:51Z | [
"python",
"google-app-engine",
"web-applications"
] |
How can i create a melody? Is there any sound-module? | 1,967,040 | <p>I am confused because there are a lot of programms. But i am looking something like this. I will type a melody like "a4 c3 h3 a2" etc. and then i want to hear this. Does anybody know what i am looking for?
thanks in advance</p>
| 7 | 2009-12-27T21:04:34Z | 1,967,145 | <p>you could use any library that produces MIDI output, in case of .net I'd recommend
the one created by Stephen Toub from Microsoft(can't find from where i got it, but google for it.)</p>
| 2 | 2009-12-27T21:52:27Z | [
"python",
"audio"
] |
How can i create a melody? Is there any sound-module? | 1,967,040 | <p>I am confused because there are a lot of programms. But i am looking something like this. I will type a melody like "a4 c3 h3 a2" etc. and then i want to hear this. Does anybody know what i am looking for?
thanks in advance</p>
| 7 | 2009-12-27T21:04:34Z | 1,967,154 | <p>Check this out: <a href="http://www.algorithm.co.il/blogs/index.php/pytuner/" rel="nofollow">http://www.algorithm.co.il/blogs/index.php/pytuner/</a>
It's a very similar projet and looks like a very decent reference.</p>
| 1 | 2009-12-27T21:56:36Z | [
"python",
"audio"
] |
How can i create a melody? Is there any sound-module? | 1,967,040 | <p>I am confused because there are a lot of programms. But i am looking something like this. I will type a melody like "a4 c3 h3 a2" etc. and then i want to hear this. Does anybody know what i am looking for?
thanks in advance</p>
| 7 | 2009-12-27T21:04:34Z | 1,968,691 | <p>computing frequencies from note name is easy. each half-note is 2^(1/12) away from the preceding note, 440 Hz is A4. </p>
<p>if by any chance you are on windows, you may try this piece of code, which plays a song through the PC speaker:</p>
<pre><code>import math
import winsound
import time
labels = ['a','a#','b'... | 7 | 2009-12-28T09:36:38Z | [
"python",
"audio"
] |
How can i create a melody? Is there any sound-module? | 1,967,040 | <p>I am confused because there are a lot of programms. But i am looking something like this. I will type a melody like "a4 c3 h3 a2" etc. and then i want to hear this. Does anybody know what i am looking for?
thanks in advance</p>
| 7 | 2009-12-27T21:04:34Z | 1,968,890 | <p>One outside option is <a href="http://www.jfugue.org/" rel="nofollow">JFugue</a> as <a href="http://codetojoy.blogspot.com/2008/01/mytunes-groovy-and-jfugue.html" rel="nofollow">shown here</a> (with Groovy). Note that you would use <a href="http://www.jython.org/" rel="nofollow">Jython</a> instead of Python, which h... | 3 | 2009-12-28T10:45:39Z | [
"python",
"audio"
] |
Simulate mouse click/Detect color under cursor in Python | 1,967,096 | <p>I am very new to python. I am trying to write a program that will click the mouse at (x, y), move it to (a, b), and then wait until the color under the mouse is a certain color, lets say #fff. When it is that color, it clicks again and then repeats.</p>
<p>I cannot find a good API for mouse related stuff for python... | 5 | 2009-12-27T21:29:52Z | 1,967,169 | <p>The API for simulating mouse events depends on your platform. I don't know any cross-platform solution. </p>
<p>On Windows, you can access the Win32 API thanks to ctypes. see <a href="http://msdn.microsoft.com/en-us/library/ms646260%28VS.85%29.aspx">mouse_event on MSDN</a>. You may also be interested by <a href="ht... | 6 | 2009-12-27T22:03:42Z | [
"python",
"colors",
"mouse"
] |
Simulate mouse click/Detect color under cursor in Python | 1,967,096 | <p>I am very new to python. I am trying to write a program that will click the mouse at (x, y), move it to (a, b), and then wait until the color under the mouse is a certain color, lets say #fff. When it is that color, it clicks again and then repeats.</p>
<p>I cannot find a good API for mouse related stuff for python... | 5 | 2009-12-27T21:29:52Z | 1,967,998 | <p>if you're on Windows, then, for this kind of thing, you really want to try <a href="http://www.autohotkey.com" rel="nofollow">autohotkey</a>. It's not python, but it is <strong>extremely powerful</strong> for doing this kind of thing on a Windows machine. The user community is extremely helpful, also. Check out thei... | -2 | 2009-12-28T04:44:07Z | [
"python",
"colors",
"mouse"
] |
Python UDP socket port random, despite assignment | 1,967,188 | <p>I have two simple Python files: <em>client.py</em> and <em>server.py</em>. The client simply sends the text you type to the server, via UDP socket. </p>
<p>The port assigned and listened to is <strong>21567</strong>, BUT... the line reading:</p>
<pre><code>print "\nReceived message '", data,"' from ", addr
</code>... | 3 | 2009-12-27T22:13:17Z | 1,967,201 | <p>60471 is the client's port and 21567 is the server's port. They can't be the same: Any IP traffic has to declare its source address and port, and its destination address and port. The client port is usually a random number in the range 32768 to 65535. <code>addr</code> is telling you the client's address.</p>
<p... | 4 | 2009-12-27T22:17:11Z | [
"python",
"sockets",
"udp"
] |
Python UDP socket port random, despite assignment | 1,967,188 | <p>I have two simple Python files: <em>client.py</em> and <em>server.py</em>. The client simply sends the text you type to the server, via UDP socket. </p>
<p>The port assigned and listened to is <strong>21567</strong>, BUT... the line reading:</p>
<pre><code>print "\nReceived message '", data,"' from ", addr
</code>... | 3 | 2009-12-27T22:13:17Z | 1,967,203 | <p>The port you are printing is that of the sender. The client's port is always random, stardard operating system mechanism. Just like a web server's port is 80, but when your computer connects to a server, you exit with a random port every time.</p>
| 2 | 2009-12-27T22:18:08Z | [
"python",
"sockets",
"udp"
] |
Is there any Visual Studio-like tool for creating GUIs for Python? | 1,967,220 | <p>My girlfriend asked me if there was a tool (actually, an IDE) that would let her create her GUI visually and edit functions associated with GUI-related events with little effort.</p>
<p><strong>For example, she wants to double-click a button she just created and immediately see (and edit) the code associated with t... | 2 | 2009-12-27T22:25:54Z | 1,967,227 | <p><a href="http://www.codeplex.com/IronPythonStudio" rel="nofollow">http://www.codeplex.com/IronPythonStudio</a></p>
| 1 | 2009-12-27T22:28:17Z | [
"python",
"visual-studio",
"qt",
"gtk",
"wx"
] |
Is there any Visual Studio-like tool for creating GUIs for Python? | 1,967,220 | <p>My girlfriend asked me if there was a tool (actually, an IDE) that would let her create her GUI visually and edit functions associated with GUI-related events with little effort.</p>
<p><strong>For example, she wants to double-click a button she just created and immediately see (and edit) the code associated with t... | 2 | 2009-12-27T22:25:54Z | 1,967,269 | <p><a href="http://wxglade.sourceforge.net/" rel="nofollow">WxGlade</a>. I'm not sure if you can do the click and edit code thing, but it comes pretty close.</p>
| 0 | 2009-12-27T22:41:58Z | [
"python",
"visual-studio",
"qt",
"gtk",
"wx"
] |
Is there any Visual Studio-like tool for creating GUIs for Python? | 1,967,220 | <p>My girlfriend asked me if there was a tool (actually, an IDE) that would let her create her GUI visually and edit functions associated with GUI-related events with little effort.</p>
<p><strong>For example, she wants to double-click a button she just created and immediately see (and edit) the code associated with t... | 2 | 2009-12-27T22:25:54Z | 1,967,276 | <p>For GTK+ there is <a href="http://glade.gnome.org/" rel="nofollow">Glade</a>. Python can load interface files created with Glade. There are some tutorials on the net.</p>
<p><img src="http://glade.gnome.org/images/glade-main-page-thumb.png" alt="Glade"></p>
<p>For Qt there is <a href="http://doc.trolltech.com/4.3/... | 2 | 2009-12-27T22:44:29Z | [
"python",
"visual-studio",
"qt",
"gtk",
"wx"
] |
Is there any Visual Studio-like tool for creating GUIs for Python? | 1,967,220 | <p>My girlfriend asked me if there was a tool (actually, an IDE) that would let her create her GUI visually and edit functions associated with GUI-related events with little effort.</p>
<p><strong>For example, she wants to double-click a button she just created and immediately see (and edit) the code associated with t... | 2 | 2009-12-27T22:25:54Z | 1,967,280 | <p>I would recommend based on your needs:</p>
<ul>
<li>Qt Designer</li>
<li>wxGlade</li>
</ul>
<p>Check this out:
<a href="http://wiki.python.org/moin/GuiProgramming">http://wiki.python.org/moin/GuiProgramming</a></p>
| 5 | 2009-12-27T22:45:02Z | [
"python",
"visual-studio",
"qt",
"gtk",
"wx"
] |
Is there any Visual Studio-like tool for creating GUIs for Python? | 1,967,220 | <p>My girlfriend asked me if there was a tool (actually, an IDE) that would let her create her GUI visually and edit functions associated with GUI-related events with little effort.</p>
<p><strong>For example, she wants to double-click a button she just created and immediately see (and edit) the code associated with t... | 2 | 2009-12-27T22:25:54Z | 1,967,281 | <p><a href="http://qt.nokia.com/products/developer-tools" rel="nofollow">Qt Creator</a> is pretty slick. It's for C++ coding only, but Qt manages to make that a bit easier.</p>
| 0 | 2009-12-27T22:45:14Z | [
"python",
"visual-studio",
"qt",
"gtk",
"wx"
] |
Is there any Visual Studio-like tool for creating GUIs for Python? | 1,967,220 | <p>My girlfriend asked me if there was a tool (actually, an IDE) that would let her create her GUI visually and edit functions associated with GUI-related events with little effort.</p>
<p><strong>For example, she wants to double-click a button she just created and immediately see (and edit) the code associated with t... | 2 | 2009-12-27T22:25:54Z | 1,967,671 | <p><a href="https://code.google.com/p/pythonxy/" rel="nofollow">Python(x,y)</a> includes an installation of Eclipse with PyDev and QT Designer integrated. If you configure PyUIC to run from Eclipse (see <a href="http://groups.google.com/group/pythonxy/browse_thread/thread/5297a34dccc2c2" rel="nofollow">this brief HOWTO... | 2 | 2009-12-28T01:42:30Z | [
"python",
"visual-studio",
"qt",
"gtk",
"wx"
] |
How can you use a font file in GTK | 1,967,257 | <p>I'm writing an open source program (key-train) in Python and GTK (with Cairo) and I would like to use some more attractive fonts. I was hoping that it would be possible to load a ttf font from within the program and just use it (instead of installing it), but I haven't been able to figure out how to do this.</p>
| 3 | 2009-12-27T22:37:17Z | 1,967,464 | <p>You could use pango to set the ttf font:</p>
<pre><code>#!/usr/bin/env python
import pango
import gtk
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
main_vbox = gtk.VBox(homogeneous=False,spacing=0)
window.add(main_vbox)
textview = gtk.TextView()
main_vbox.pack_start(textview,expand=False,fill=True,padding=0)
textbuffer... | 0 | 2009-12-28T00:08:32Z | [
"python",
"linux",
"fonts",
"gtk"
] |
How can you use a font file in GTK | 1,967,257 | <p>I'm writing an open source program (key-train) in Python and GTK (with Cairo) and I would like to use some more attractive fonts. I was hoping that it would be possible to load a ttf font from within the program and just use it (instead of installing it), but I haven't been able to figure out how to do this.</p>
| 3 | 2009-12-27T22:37:17Z | 1,967,695 | <p>You might want to take a look at <a href="https://bugzilla.gnome.org/show%5Fbug.cgi?id=347237" rel="nofollow">this feature request</a> It shows a work-a-round if using cairo and freetype for the backend.</p>
| 3 | 2009-12-28T02:05:27Z | [
"python",
"linux",
"fonts",
"gtk"
] |
Why is "def InvalidArgsSpecified:" a syntax error? | 1,967,336 | <p>I'm just starting to learn python... so bear with me please</p>
<p>Why is it giving me a Invalid Syntax error with this block of code</p>
<pre><code>def InvalidArgsSpecified:
print ("*** Simtho Usage ***\n")
print ("-i Installs Local App,, include full path")
print ("-u Uninstalls Installed App,include... | 0 | 2009-12-27T23:09:56Z | 1,967,340 | <p>The syntax error is in the very first line, where you have:</p>
<pre><code>def InvalidArgsSpecified:
</code></pre>
<p>change it to:</p>
<pre><code>def InvalidArgsSpecified():
</code></pre>
<p>Those parentheses are mandatory in a <code>def</code>, even when there's nothing between them (just as parentheses are al... | 6 | 2009-12-27T23:12:13Z | [
"python",
"function",
"syntax-error"
] |
Why is "def InvalidArgsSpecified:" a syntax error? | 1,967,336 | <p>I'm just starting to learn python... so bear with me please</p>
<p>Why is it giving me a Invalid Syntax error with this block of code</p>
<pre><code>def InvalidArgsSpecified:
print ("*** Simtho Usage ***\n")
print ("-i Installs Local App,, include full path")
print ("-u Uninstalls Installed App,include... | 0 | 2009-12-27T23:09:56Z | 1,967,342 | <p>A function without arguments must still include brackets, e.g.:</p>
<pre><code>def InvalidArgsSpecified():
</code></pre>
| 2 | 2009-12-27T23:12:51Z | [
"python",
"function",
"syntax-error"
] |
How to get (and use) extended permissions in Facebook with Python/Django | 1,967,438 | <p>I'm trying to write a simple app that lets a user grant my code permission to write to her page's Facebook stream. As I understand it, it should be as easy as:</p>
<ol>
<li>Have the user click on a button that launches a popup containing the a page in my Facebook app.</li>
<li>In that page, they click on something... | 11 | 2009-12-27T23:56:17Z | 1,967,630 | <p>Have you looked at <a href="http://code.google.com/p/minifb/" rel="nofollow">minifb</a>? Their <a href="http://code.google.com/p/minifb/wiki/ExampleCode" rel="nofollow">examples page</a> shows basically everything you need to know to request authorization and receive a session key. (Also, the <a href="http://github.... | 3 | 2009-12-28T01:19:38Z | [
"python",
"django",
"facebook",
"pyfacebook"
] |
How to get (and use) extended permissions in Facebook with Python/Django | 1,967,438 | <p>I'm trying to write a simple app that lets a user grant my code permission to write to her page's Facebook stream. As I understand it, it should be as easy as:</p>
<ol>
<li>Have the user click on a button that launches a popup containing the a page in my Facebook app.</li>
<li>In that page, they click on something... | 11 | 2009-12-27T23:56:17Z | 1,994,829 | <p>After a lot of tinkering, I appear to have solved all of my problems in Facebookland:</p>
<ol>
<li>Turns out that having a user click on a button to grant permissions is as easy as Caio Romão said it was. For my part though, I found that directing them to the Facebook Desktop App link was way easier and more depe... | 1 | 2010-01-03T12:29:05Z | [
"python",
"django",
"facebook",
"pyfacebook"
] |
When are function local python variables created? | 1,967,454 | <p>When are function-local variables are created? For example, in the following code is dictionary d1 created each time the function f1 is called or only once when it is compiled?</p>
<pre><code>def f1():
d1 = {1: 2, 3: 4}
return id(d1)
d2 = {1: 2, 3: 4}
def f2():
return id(d2)
</code></pre>
<p>Is it fas... | 0 | 2009-12-28T00:03:52Z | 1,967,481 | <p>Local variables are created when assigned to, i.e., during the execution of the function.</p>
<p>If every execution of the function needs (and does not modify!-) the same dict, creating it once, before the function is ever called, is faster. As an alternative to a global variable, a fake argument with a default va... | 2 | 2009-12-28T00:14:43Z | [
"python"
] |
When are function local python variables created? | 1,967,454 | <p>When are function-local variables are created? For example, in the following code is dictionary d1 created each time the function f1 is called or only once when it is compiled?</p>
<pre><code>def f1():
d1 = {1: 2, 3: 4}
return id(d1)
d2 = {1: 2, 3: 4}
def f2():
return id(d2)
</code></pre>
<p>Is it fas... | 0 | 2009-12-28T00:03:52Z | 1,967,486 | <p>If you look at the disassembly with the <code>dis</code> module you'll see that the creation and filling of d1 is done on every execution. Given that dictionaries are mutable this is unlikely to change anytime soon, at least until good escape analysis comes to Python virtual machines. On the other hand lookup of glo... | 0 | 2009-12-28T00:16:42Z | [
"python"
] |
When are function local python variables created? | 1,967,454 | <p>When are function-local variables are created? For example, in the following code is dictionary d1 created each time the function f1 is called or only once when it is compiled?</p>
<pre><code>def f1():
d1 = {1: 2, 3: 4}
return id(d1)
d2 = {1: 2, 3: 4}
def f2():
return id(d2)
</code></pre>
<p>Is it fas... | 0 | 2009-12-28T00:03:52Z | 1,967,511 | <p>Speed is relative to what you're doing. If you're writing a database-intensive application, I doubt your application is going to suffer one way or another from your choice of global versus local variables. Use a profiler to be sure. ;-)</p>
<p>As Alex noted, the locals are initialized when the function is called. A... | 0 | 2009-12-28T00:24:21Z | [
"python"
] |
Return value of os.path in Python | 1,967,643 | <p>For this code:</p>
<pre><code>import os
a=os.path.join('dsa','wqqqq','ffff')
print a
print os.path.exists('dsa\wqqqq\ffff') #what situation this will be print True?
</code></pre>
<p>When will os.path.exists('what') print <code>True</code>?</p>
| 0 | 2009-12-28T01:27:05Z | 1,967,653 | <blockquote>
<p>Return True if path refers to an
existing path. Returns False for
broken symbolic links. On some
platforms, this function may return
False if permission is not granted to
execute os.stat() on the requested
file, even if the path physically
exists.</p>
</blockquote>
<p><a href="http://do... | 1 | 2009-12-28T01:32:34Z | [
"python",
"path"
] |
Return value of os.path in Python | 1,967,643 | <p>For this code:</p>
<pre><code>import os
a=os.path.join('dsa','wqqqq','ffff')
print a
print os.path.exists('dsa\wqqqq\ffff') #what situation this will be print True?
</code></pre>
<p>When will os.path.exists('what') print <code>True</code>?</p>
| 0 | 2009-12-28T01:27:05Z | 1,967,655 | <p><code>'dsa\wqqqq\ffff'</code> does not mean what you probably think it does: <code>\f</code>, within a string, is an escape sequence and expands to the same character as <code>chr(12)</code> (ASCII "form feed").</p>
<p>So <code>print os.path.exists('dsa\wqqqq\ffff')</code> will print True if:</p>
<ul>
<li>on Windo... | 8 | 2009-12-28T01:33:06Z | [
"python",
"path"
] |
Return value of os.path in Python | 1,967,643 | <p>For this code:</p>
<pre><code>import os
a=os.path.join('dsa','wqqqq','ffff')
print a
print os.path.exists('dsa\wqqqq\ffff') #what situation this will be print True?
</code></pre>
<p>When will os.path.exists('what') print <code>True</code>?</p>
| 0 | 2009-12-28T01:27:05Z | 1,967,657 | <p>It will print True if the path exists. Not sure what the confusion is, here. Not to be rude, but RTFM.</p>
<pre><code>% mkdir -p dsa/wqqqq/ffff
% cat <<EOF | python
> import os
> a=os.path.join('dsa','wqqqq','ffff')
> print a
> print os.path.exists('dsa/wqqqq/ffff')
> EOF
dsa/wqqqq/ffff
True
</... | 0 | 2009-12-28T01:33:44Z | [
"python",
"path"
] |
install pyquery on windows | 1,967,662 | <p>I want to install pyquery on windows. But i cant run setup.py install on the command line. Do you have any hint?</p>
| 3 | 2009-12-28T01:38:37Z | 1,967,687 | <p>I guess you don't have lxml or setuptools installed</p>
<p>setuptools
<a href="http://pypi.python.org/pypi/setuptools/0.6c11" rel="nofollow">http://pypi.python.org/pypi/setuptools/0.6c11</a></p>
<p>lxml
<a href="http://pypi.python.org/pypi/lxml/2.2.2" rel="nofollow">http://pypi.python.org/pypi/lxml/2.2.2</a></p>
... | 2 | 2009-12-28T01:57:00Z | [
"python",
"installation",
"python-3.x"
] |
install pyquery on windows | 1,967,662 | <p>I want to install pyquery on windows. But i cant run setup.py install on the command line. Do you have any hint?</p>
| 3 | 2009-12-28T01:38:37Z | 13,717,327 | <p>I could not install lxml on windows with either pip or easy_install. Complained "Unable to find vcvarsall.bat" </p>
<p>Tried installing Cygwin and MinGW but that was taking way too long</p>
<p>found out from <a href="http://stackoverflow.com/a/9819303/482053">raidsan's answer</a> about unofficial precompiled wind... | 0 | 2012-12-05T06:08:48Z | [
"python",
"installation",
"python-3.x"
] |
install pyquery on windows | 1,967,662 | <p>I want to install pyquery on windows. But i cant run setup.py install on the command line. Do you have any hint?</p>
| 3 | 2009-12-28T01:38:37Z | 39,308,363 | <p>SIMPLE WORKING SOLUTION:</p>
<p>I download the tar file here pyquery-1.2.13.tar.gz (<a href="https://pypi.python.org/pypi/pyquery#downloads" rel="nofollow">https://pypi.python.org/pypi/pyquery#downloads</a>)</p>
<p>I extracted them a folder pyquery-1.2.13 then i pasted myscript.py to this folder pyquery-1.2.13 in ... | 0 | 2016-09-03T15:07:44Z | [
"python",
"installation",
"python-3.x"
] |
How to install imagingft in OSX and Ubuntu? | 1,967,674 | <p>I'm using PIL 1.1.6 to render a truetype font on my local Windows machine. I'd like to be able to get the application running in OSX and Ubuntu (server). So far the instructions I've found all deal with specific ports repositories on OSX (Darwinports, Macports, etc.) or very outdated instructions for Linux.</p>
<... | 0 | 2009-12-28T01:44:21Z | 1,997,437 | <p>Long ago I'd switched my OSX (Snow Leopard) python version from the default 2.6 back to 2.5 for compatibility reasons on a project I had been working on. I switched it back to 2.6 and was then able to compile imagingft normally:</p>
<pre><code>./configure
make
make install
</code></pre>
<p>I was able to do the sa... | 0 | 2010-01-04T03:57:37Z | [
"python",
"osx",
"ubuntu",
"python-imaging-library"
] |
Accessing a file relatively in Python if you do not know your starting point? | 1,967,688 | <p>Hey. I've got a project in Python, whose directory layout is the following:</p>
<pre><code>root
|-bin
|-conf
|-[project]
</code></pre>
<p>Python files in [project] need to be able to read configuration data from the 'conf' directory, but I cannot guarantee the location of root, plus it may be used on both Li... | 0 | 2009-12-28T01:59:36Z | 1,967,692 | <p>Instead of:</p>
<pre><code>path = os.path.abspath(__file__)[:-8]
</code></pre>
<p>use:</p>
<pre><code>path = os.path.dirname(os.path.abspath(__file__))
</code></pre>
<p>See the docs <a href="http://docs.python.org/library/os.path.html?highlight=os.path.dirname#os.path.dirname" rel="nofollow">here</a>.</p>
| 2 | 2009-12-28T02:02:13Z | [
"python"
] |
Why doesn't my code print `os.path` | 1,967,702 | <p>For the code:</p>
<pre><code>def a(x):
if x=='s':
__import__('os') #I think __import__ == import
print os.path
</code></pre>
<p>Why doesn't <code>print a('os')</code> print os.path?</p>
<hr>
<p>My next question is: Why does the following code use <code>__import__('some')</code> instead of som... | 1 | 2009-12-28T02:09:58Z | 1,967,709 | <p><code>__import__</code> returns a module. It doesn't actually add anything to the current namespace.</p>
<p>You probably want to just use <code>import os</code>:</p>
<pre><code>def a(x):
if x=='s':
import os
print os.path
a('s')
</code></pre>
<p>Alternatively, if you want to import the module ... | 11 | 2009-12-28T02:13:26Z | [
"python",
"import",
"module"
] |
Why doesn't my code print `os.path` | 1,967,702 | <p>For the code:</p>
<pre><code>def a(x):
if x=='s':
__import__('os') #I think __import__ == import
print os.path
</code></pre>
<p>Why doesn't <code>print a('os')</code> print os.path?</p>
<hr>
<p>My next question is: Why does the following code use <code>__import__('some')</code> instead of som... | 1 | 2009-12-28T02:09:58Z | 1,967,718 | <p>@statictype.org's answer is correct (<code>__import__</code> does not bind any name in local namespace), but why ever do you want to print <code><module 'posixpath' from '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/posixpath.pyc'></code> or something equally weird depending on your p... | 4 | 2009-12-28T02:17:40Z | [
"python",
"import",
"module"
] |
Can a standalone web application built with cherrypy be compiled? | 1,967,705 | <p>I want to build a web application that stands completely by itself, apache not required. Is cherrypy a good solution, and can this be compiled with something like py2exe?</p>
| 0 | 2009-12-28T02:12:05Z | 1,967,760 | <p>Python is a scripting language and is not usually compiled. What you are talking about is packaging your scripts into an exe (via p2exe), bundled with the relative modules and an interpreter.</p>
<p>This is possible with many scripts, including CherryPy, as p2exe basically sticks all your scripts together in one pl... | 1 | 2009-12-28T02:36:47Z | [
"python",
"cherrypy"
] |
Can a standalone web application built with cherrypy be compiled? | 1,967,705 | <p>I want to build a web application that stands completely by itself, apache not required. Is cherrypy a good solution, and can this be compiled with something like py2exe?</p>
| 0 | 2009-12-28T02:12:05Z | 1,968,376 | <p>You are basically describing <a href="http://www.web2py.com/" rel="nofollow">web2py</a>.</p>
| 0 | 2009-12-28T07:29:38Z | [
"python",
"cherrypy"
] |
Python string concatenation Idiom. Need Clarification. | 1,967,723 | <p>From <a href="http://jaynes.colorado.edu/PythonIdioms.html" rel="nofollow">http://jaynes.colorado.edu/PythonIdioms.html</a></p>
<blockquote>
<p>"Build strings as a list and use
''.join at the end. join is a string
method called on the separator, not
the list. Calling it from the empty
string concatenates ... | 4 | 2009-12-28T02:20:20Z | 1,967,725 | <p>It's not obvious if you're referring to the same thing as other people. This optimization is important when you have <em>many</em> strings, say <em>M</em> of length <em>N</em>. Then </p>
<p><strong>A</strong> </p>
<pre><code>x = ''.join(strings) # Takes M*N operations
</code></pre>
<p><strong>B</strong></p>
<pr... | 0 | 2009-12-28T02:23:15Z | [
"python",
"performance",
"idioms"
] |
Python string concatenation Idiom. Need Clarification. | 1,967,723 | <p>From <a href="http://jaynes.colorado.edu/PythonIdioms.html" rel="nofollow">http://jaynes.colorado.edu/PythonIdioms.html</a></p>
<blockquote>
<p>"Build strings as a list and use
''.join at the end. join is a string
method called on the separator, not
the list. Calling it from the empty
string concatenates ... | 4 | 2009-12-28T02:20:20Z | 1,967,727 | <p>Repeated concatenation is quadratic because it's <a href="http://en.wikipedia.org/wiki/Schlemiel%5Fthe%5Fpainter%27s%5FAlgorithm" rel="nofollow">Schlemiel the Painter's Algorithm</a> (beware that some implementations will optimize this away so that it is not quadratic). <code>join</code> avoids this because it takes... | 6 | 2009-12-28T02:24:10Z | [
"python",
"performance",
"idioms"
] |
Python string concatenation Idiom. Need Clarification. | 1,967,723 | <p>From <a href="http://jaynes.colorado.edu/PythonIdioms.html" rel="nofollow">http://jaynes.colorado.edu/PythonIdioms.html</a></p>
<blockquote>
<p>"Build strings as a list and use
''.join at the end. join is a string
method called on the separator, not
the list. Calling it from the empty
string concatenates ... | 4 | 2009-12-28T02:20:20Z | 1,967,732 | <p>Yes. For the examples you chose the importance isn't clear because you only have two very short strings so the append would probably be faster.</p>
<p>But every time you do <code>a + b</code> with strings in Python it causes a new allocation and then copies all the bytes from a and b into the new string. If you do ... | 12 | 2009-12-28T02:27:02Z | [
"python",
"performance",
"idioms"
] |
Python string concatenation Idiom. Need Clarification. | 1,967,723 | <p>From <a href="http://jaynes.colorado.edu/PythonIdioms.html" rel="nofollow">http://jaynes.colorado.edu/PythonIdioms.html</a></p>
<blockquote>
<p>"Build strings as a list and use
''.join at the end. join is a string
method called on the separator, not
the list. Calling it from the empty
string concatenates ... | 4 | 2009-12-28T02:20:20Z | 1,967,734 | <p>When you code <code>s1 + s2</code>, Python needs to allocate a new string object, copy all characters of <code>s1</code> into it, then after that all characters of <code>s2</code>. This trivial operation does not bear quadratic time costs: the cost is <code>O(len(s1) + len(s2))</code> (plus a constant for allocatio... | 4 | 2009-12-28T02:28:58Z | [
"python",
"performance",
"idioms"
] |
Python string concatenation Idiom. Need Clarification. | 1,967,723 | <p>From <a href="http://jaynes.colorado.edu/PythonIdioms.html" rel="nofollow">http://jaynes.colorado.edu/PythonIdioms.html</a></p>
<blockquote>
<p>"Build strings as a list and use
''.join at the end. join is a string
method called on the separator, not
the list. Calling it from the empty
string concatenates ... | 4 | 2009-12-28T02:20:20Z | 1,967,752 | <p>Joel writes about this in <a href="http://www.joelonsoftware.com/articles/fog0000000319.html" rel="nofollow">Back to Basics</a>.</p>
| 1 | 2009-12-28T02:34:33Z | [
"python",
"performance",
"idioms"
] |
Are there other Type in addition to the class to be called by hasattr | 1,967,730 | <p>For code:</p>
<pre><code>class a(object):
a='aaa'
b=a()
print hasattr(a,'a')
print hasattr(b,'a')
</code></pre>
<p>who can be called by hasattr except 'class somebody'?</p>
<p>Thanks!</p>
| 0 | 2009-12-28T02:26:10Z | 1,967,744 | <p>You can call <code>hasattr</code> with any object as the first argument (and any string as the second argument): it just returns False if that object does not have an attribute by that name ("having" an attribute of course includes possibly inheriting or synthesizing it; <code>hasattr(x,'y')</code> is True if and on... | 1 | 2009-12-28T02:32:09Z | [
"python"
] |
Are there other Type in addition to the class to be called by hasattr | 1,967,730 | <p>For code:</p>
<pre><code>class a(object):
a='aaa'
b=a()
print hasattr(a,'a')
print hasattr(b,'a')
</code></pre>
<p>who can be called by hasattr except 'class somebody'?</p>
<p>Thanks!</p>
| 0 | 2009-12-28T02:26:10Z | 1,967,754 | <p>Accordingly to the Python documentation you must pass an object as parameter of the hasttr() function. </p>
<blockquote>
<p>hasattr(object, name): The arguments are an object and a string. The result is True if the string is the name of one of the objectâs attributes, False if not. (This is implemented by calli... | 0 | 2009-12-28T02:35:00Z | [
"python"
] |
How to use C++ lib from python | 1,967,755 | <p>I would like to know how to use python to make calls to a C++ library called <a href="http://libwpd.sourceforge.net/" rel="nofollow">libwpd</a> to read word perfect files and build python objects from them, but I have no experience with C++ or calling C++ functions from python, and I don't understand how to figure o... | 3 | 2009-12-28T02:35:24Z | 1,967,802 | <p>Checkout <a href="http://docs.python.org/library/ctypes.html" rel="nofollow">ctypes</a>. It's part of the standard Python library set. I can't speak to it's use with C++, but I suspect it will work nicely.</p>
| 2 | 2009-12-28T02:57:03Z | [
"python",
"swig",
"wordperfect"
] |
How to use C++ lib from python | 1,967,755 | <p>I would like to know how to use python to make calls to a C++ library called <a href="http://libwpd.sourceforge.net/" rel="nofollow">libwpd</a> to read word perfect files and build python objects from them, but I have no experience with C++ or calling C++ functions from python, and I don't understand how to figure o... | 3 | 2009-12-28T02:35:24Z | 1,967,845 | <p>The <a href="http://www.boost.org/doc/libs/1%5F41%5F0/libs/python/doc/index.html" rel="nofollow">Boost.Python</a> library allows easy interoperability between C++ and Python.</p>
<p>The <a href="http://www.boost.org/doc/libs/1%5F41%5F0/libs/python/doc/tutorial/doc/html/index.html" rel="nofollow">tutorial</a> shows ... | 2 | 2009-12-28T03:25:57Z | [
"python",
"swig",
"wordperfect"
] |
Parse Facebook feed datetime in python? | 1,967,801 | <ol>
<li>I am reading a Facebook updates feed using the python library 'feedparser'.</li>
<li>I loop through the collection of entries in my Django templates, and display the results.</li>
<li><p>The updated field is returned in a big long string, of some format I am unfamiliar with.</p>
<p>Tue, 01 Dec 2009 23:55:52 +... | 2 | 2009-12-28T02:56:46Z | 1,967,818 | <p>Use <code>entries[i].updated_parsed</code> instead of <code>entries[i].updated</code>, and <code>feedparser</code> will return a parsed 9-tuple for you. (<a href="http://feedparser.org/docs/date-parsing.html" rel="nofollow">Documentation</a>)</p>
<p>Then build a <code>datetime</code> object and pass it to Django or... | 4 | 2009-12-28T03:10:59Z | [
"python",
"django",
"datetime",
"facebook",
"feedparser"
] |
Parse Facebook feed datetime in python? | 1,967,801 | <ol>
<li>I am reading a Facebook updates feed using the python library 'feedparser'.</li>
<li>I loop through the collection of entries in my Django templates, and display the results.</li>
<li><p>The updated field is returned in a big long string, of some format I am unfamiliar with.</p>
<p>Tue, 01 Dec 2009 23:55:52 +... | 2 | 2009-12-28T02:56:46Z | 1,967,822 | <p><em>This worked but wasn't what my final solution ended up becoming.</em></p>
<p>This solution iterates over the feed entries collection I get back from Facebook. I then parse the datetime and set the updated property to that new datetime. (Also, ignoring the +0000)</p>
<pre><code>for entry in feed.entries:
... | 2 | 2009-12-28T03:14:18Z | [
"python",
"django",
"datetime",
"facebook",
"feedparser"
] |
Is it a bad idea to design and develop a python applications backend and then once finished try to apply a GUI to it? | 1,967,888 | <p>Is it better to do it all at once? I'm very new to wxPython and I'm thinking it would be better to write the program in a way familiar to me, then apply the wxPython gui to it after I'm satisfied with the overall design of the app. Any advice?</p>
| 12 | 2009-12-28T03:53:30Z | 1,967,900 | <p>This is a viable approach. In fact, some programmers use it for the advantages it brings:</p>
<ul>
<li>Modular non-GUI code can then be tied in with different GUIs, not just a single library</li>
<li>It can also be used for a command-line application (or a batch interface to a GUI one)</li>
<li>It can be reused for... | 16 | 2009-12-28T03:59:29Z | [
"python",
"wxpython"
] |
Is it a bad idea to design and develop a python applications backend and then once finished try to apply a GUI to it? | 1,967,888 | <p>Is it better to do it all at once? I'm very new to wxPython and I'm thinking it would be better to write the program in a way familiar to me, then apply the wxPython gui to it after I'm satisfied with the overall design of the app. Any advice?</p>
| 12 | 2009-12-28T03:53:30Z | 1,967,904 | <p>That depends on the problem domain. An image processing tool would be rather difficult to implement without reference to a GUI. For most apps, though, I would argue strongly in favour of separating the two parts. It is much, much easier to develop, test and evolve a UI-free back-end. The gains will vastly outweigh t... | 2 | 2009-12-28T04:02:03Z | [
"python",
"wxpython"
] |
Is it a bad idea to design and develop a python applications backend and then once finished try to apply a GUI to it? | 1,967,888 | <p>Is it better to do it all at once? I'm very new to wxPython and I'm thinking it would be better to write the program in a way familiar to me, then apply the wxPython gui to it after I'm satisfied with the overall design of the app. Any advice?</p>
| 12 | 2009-12-28T03:53:30Z | 1,967,905 | <p>IMHO, that would rather be a better idea. To keep the underlying business logic not tied down to the UI is a better approach that we can worry more about the underlying logic than bogging down too much about the interface. </p>
<p>At the same time, it is also important to have some basic design for your interface s... | 0 | 2009-12-28T04:02:36Z | [
"python",
"wxpython"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.