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 |
|---|---|---|---|---|---|---|---|---|---|
In Python, how do I find the date of the first Monday of a given week? | 396,913 | <p>If I have a certain week number (eg 51) and a given year (eg 2008), how do I find the date of the first Monday of that same week?</p>
<p>Many thanks</p>
| 26 | 2008-12-29T00:42:56Z | 3,314,360 | <pre><code>from datetime import date, timedelta
def first_monday(year, week):
d = date(year, 1, 4) # The Jan 4th must be in week 1 according to ISO
return d + timedelta(weeks=(week-1), days=-d.weekday())
</code></pre>
| 12 | 2010-07-22T23:36:23Z | [
"python",
"datetime"
] |
commands to send messages in Python via the Poplib module? | 396,991 | <p>I've found a number of tutorials online involving downloading messages via Poplib, but haven't been able to find anything explaining how to create new messages. Does this exist?</p>
| 1 | 2008-12-29T02:14:17Z | 396,994 | <p>Send yourself an email to create a message.</p>
<p>SMTP is the protocol the email uses to send. In Python, you'd find this in <a href="http://docs.python.org/library/smtplib.html" rel="nofollow">smtplib</a>.</p>
<p>There are numerous email RFC's. Here are a few.</p>
<p>SMTP - <a href="http://www.faqs.org/rfcs/r... | 2 | 2008-12-29T02:17:35Z | [
"python",
"email",
"poplib"
] |
commands to send messages in Python via the Poplib module? | 396,991 | <p>I've found a number of tutorials online involving downloading messages via Poplib, but haven't been able to find anything explaining how to create new messages. Does this exist?</p>
| 1 | 2008-12-29T02:14:17Z | 397,003 | <p>As S.Lott rightly says, you will want some smtp, but to create the actual email, use the <a href="http://docs.python.org/library/email" rel="nofollow">email</a> package from the standard library, then use an message's as_string method to send it.</p>
<p><a href="http://code.activestate.com/recipes/52243/" rel="nofo... | 3 | 2008-12-29T02:24:51Z | [
"python",
"email",
"poplib"
] |
Confusing [...] List in Python: What is it? | 397,034 | <p>So I was writing up a simple binary tree in Python and came across [...]</p>
<p>I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding whe... | 16 | 2008-12-29T02:46:31Z | 397,047 | <p>EDIT: As mentioned above, this isn't the Ellipsis object, but the result of a looped list. I jumped the gun here. Knowing about the Ellipsis object is a good bit of back shelf knowledge should you find an Ellipsis in some actual code, rather than the output.</p>
<p><hr /></p>
<p>The Ellipsis object in Python is ... | 2 | 2008-12-29T02:56:36Z | [
"python",
"recursion",
"list",
"recursive-datastructures"
] |
Confusing [...] List in Python: What is it? | 397,034 | <p>So I was writing up a simple binary tree in Python and came across [...]</p>
<p>I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding whe... | 16 | 2008-12-29T02:46:31Z | 397,054 | <p>It can also appear if you have a circular structure with a list pointing to itself. Like this:</p>
<pre><code>>>> a = [1,2]
>>> a.append(a)
>>> a
[1, 2, [...]]
>>>
</code></pre>
<p>Since python can't print out the structure (it would be an infinite loop) it uses the ellipsis to ... | 23 | 2008-12-29T03:02:35Z | [
"python",
"recursion",
"list",
"recursive-datastructures"
] |
Confusing [...] List in Python: What is it? | 397,034 | <p>So I was writing up a simple binary tree in Python and came across [...]</p>
<p>I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding whe... | 16 | 2008-12-29T02:46:31Z | 397,057 | <p>I don't understand your code above, but the [...] I think is the Python interpreter skipping infinite data structures. For example:</p>
<pre><code>>>> a = [0, 1]
>>> a[0] = a
>>> a
[[...], 1]
</code></pre>
<p>It looks like your tree structure is becoming looped.</p>
<p>The answers abou... | 5 | 2008-12-29T03:03:22Z | [
"python",
"recursion",
"list",
"recursive-datastructures"
] |
Confusing [...] List in Python: What is it? | 397,034 | <p>So I was writing up a simple binary tree in Python and came across [...]</p>
<p>I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding whe... | 16 | 2008-12-29T02:46:31Z | 397,062 | <p>I believe, that your 'tree' contains itself, therefore it contains cycles.</p>
<p>Try this code:</p>
<pre>
a = [1,2,3,4]
print a
a.append(a)
print a
</pre>
<p>The first print outputs:</p>
<pre>
[1,2,3,4]
</pre>
<p>while the second:
<pre>
[1,2,3,4, [...]]
</pre></p>
<p>The reason is using
<p... | 6 | 2008-12-29T03:08:33Z | [
"python",
"recursion",
"list",
"recursive-datastructures"
] |
Confusing [...] List in Python: What is it? | 397,034 | <p>So I was writing up a simple binary tree in Python and came across [...]</p>
<p>I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding whe... | 16 | 2008-12-29T02:46:31Z | 397,070 | <blockquote>
<p>I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding when accessed is something I'm completely lost to, however </p>
</blo... | 4 | 2008-12-29T03:15:38Z | [
"python",
"recursion",
"list",
"recursive-datastructures"
] |
Confusing [...] List in Python: What is it? | 397,034 | <p>So I was writing up a simple binary tree in Python and came across [...]</p>
<p>I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding whe... | 16 | 2008-12-29T02:46:31Z | 397,091 | <p>Ok, so in points:</p>
<ol>
<li><p>You're creating infinite data
structure: <pre>def Keys(x,y=[])</pre> will use the same 'y' in
each call. This just isn't correct.</p></li>
<li><p>The <code>print</code> statement, however, is clever enough not to print an infinite data, but to mark self-reference with a [...] (know... | 1 | 2008-12-29T03:46:18Z | [
"python",
"recursion",
"list",
"recursive-datastructures"
] |
Confusing [...] List in Python: What is it? | 397,034 | <p>So I was writing up a simple binary tree in Python and came across [...]</p>
<p>I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding whe... | 16 | 2008-12-29T02:46:31Z | 397,223 | <p>For the difference between the two versions of the function Keys, note the following difference:</p>
<pre><code>y+=[x[2]]+Keys(x[0],y)+Keys(x[1],y)
</code></pre>
<p>The right side value in this statement is a list which contains x[2], plus the ELEMENTS OF Keys(x[0],y) and the ELEMENTS OF Keys(x[1],y)</p>
<pre><co... | 1 | 2008-12-29T06:20:54Z | [
"python",
"recursion",
"list",
"recursive-datastructures"
] |
Confusing [...] List in Python: What is it? | 397,034 | <p>So I was writing up a simple binary tree in Python and came across [...]</p>
<p>I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding whe... | 16 | 2008-12-29T02:46:31Z | 15,325,426 | <p>If you would have used a PrettyPrinter, the output would had been self explanatory</p>
<pre><code>>>> l = [1,2,3,4]
>>> l[0]=l
>>> l
[[...], 2, 3, 4]
>>> pp = pprint.PrettyPrinter(indent = 4)
>>> pp.pprint(l)
[<Recursion on list with id=70327632>, 2, 3, 4]
>>... | 2 | 2013-03-10T17:47:02Z | [
"python",
"recursion",
"list",
"recursive-datastructures"
] |
Confusing [...] List in Python: What is it? | 397,034 | <p>So I was writing up a simple binary tree in Python and came across [...]</p>
<p>I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding whe... | 16 | 2008-12-29T02:46:31Z | 38,544,046 | <p>The issue is because one of the list element is referencing the list itself. So if an attempt to print all the elements is made then it would never end.</p>
<p><strong>Illustration:</strong></p>
<pre><code>x = range(3)
x.append(x)
x[3][3][3][3][3][0] = 5
print x
</code></pre>
<p>Output:</p>
<pre><code>[5, 1, 2, ... | 0 | 2016-07-23T16:35:28Z | [
"python",
"recursion",
"list",
"recursive-datastructures"
] |
Reading the target of a .lnk file in Python? | 397,125 | <p>I'm trying to read the target file/directory of a shortcut (<code>.lnk</code>) file from Python. Is there a headache-free way to do it? The <a href="http://www.i2s-lab.com/Papers/The_Windows_Shortcut_File_Format.pdf">.lnk spec [PDF]</a> is way over my head.
I don't mind using Windows-only APIs.</p>
<p>My ultimate g... | 16 | 2008-12-29T04:31:27Z | 397,137 | <p>Basically call the Windows API directly. Here is a good example found after Googling:</p>
<pre><code>import os, sys
import pythoncom
from win32com.shell import shell, shellcon
shortcut = pythoncom.CoCreateInstance (
shell.CLSID_ShellLink,
None,
pythoncom.CLSCTX_INPROC_SERVER,
shell.IID_IShellLink
)
desktop... | 6 | 2008-12-29T04:44:23Z | [
"python",
"directory",
"shortcut",
"target",
"lnk"
] |
Reading the target of a .lnk file in Python? | 397,125 | <p>I'm trying to read the target file/directory of a shortcut (<code>.lnk</code>) file from Python. Is there a headache-free way to do it? The <a href="http://www.i2s-lab.com/Papers/The_Windows_Shortcut_File_Format.pdf">.lnk spec [PDF]</a> is way over my head.
I don't mind using Windows-only APIs.</p>
<p>My ultimate g... | 16 | 2008-12-29T04:31:27Z | 397,147 | <p>Alternatively, you could try using <a href="http://msdn.microsoft.com/en-us/library/bb762181(VS.85).aspx" rel="nofollow">SHGetFolderPath()</a>. The following code might work, but I'm not on a Windows machine right now so I can't test it.</p>
<pre><code>import ctypes
shell32 = ctypes.windll.shell32
# allocate MAX... | 7 | 2008-12-29T04:53:05Z | [
"python",
"directory",
"shortcut",
"target",
"lnk"
] |
Reading the target of a .lnk file in Python? | 397,125 | <p>I'm trying to read the target file/directory of a shortcut (<code>.lnk</code>) file from Python. Is there a headache-free way to do it? The <a href="http://www.i2s-lab.com/Papers/The_Windows_Shortcut_File_Format.pdf">.lnk spec [PDF]</a> is way over my head.
I don't mind using Windows-only APIs.</p>
<p>My ultimate g... | 16 | 2008-12-29T04:31:27Z | 571,573 | <p><strong>Create a shortcut using Python (via WSH)</strong></p>
<pre><code>import sys
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut("t:\\test.lnk")
shortcut.Targetpath = "t:\\ftemp"
shortcut.save()
</code></pre>
<p><br></p>
<p><strong>Read the Target of a... | 23 | 2009-02-20T22:59:37Z | [
"python",
"directory",
"shortcut",
"target",
"lnk"
] |
Reading the target of a .lnk file in Python? | 397,125 | <p>I'm trying to read the target file/directory of a shortcut (<code>.lnk</code>) file from Python. Is there a headache-free way to do it? The <a href="http://www.i2s-lab.com/Papers/The_Windows_Shortcut_File_Format.pdf">.lnk spec [PDF]</a> is way over my head.
I don't mind using Windows-only APIs.</p>
<p>My ultimate g... | 16 | 2008-12-29T04:31:27Z | 28,952,464 | <p>I know this is an older thread but I feel that there isn't much information on the method that uses the link specification as noted in the original question. </p>
<p>My shortcut target implementation could not use the win32com module and after a lot of searching, decided to come up with my own. Nothing else seeme... | 2 | 2015-03-09T21:55:13Z | [
"python",
"directory",
"shortcut",
"target",
"lnk"
] |
Reading the target of a .lnk file in Python? | 397,125 | <p>I'm trying to read the target file/directory of a shortcut (<code>.lnk</code>) file from Python. Is there a headache-free way to do it? The <a href="http://www.i2s-lab.com/Papers/The_Windows_Shortcut_File_Format.pdf">.lnk spec [PDF]</a> is way over my head.
I don't mind using Windows-only APIs.</p>
<p>My ultimate g... | 16 | 2008-12-29T04:31:27Z | 36,706,549 | <p>I also realize this question is old, but I found the answers to be most relevant to my situation. </p>
<p>Like Jared's answer, I also could not use the win32com module. So Jared's use of the binary structure from <a href="https://msdn.microsoft.com/en-us/library/dd871305.aspx" rel="nofollow">MS-SHLLINK</a> got me... | 0 | 2016-04-19T00:37:09Z | [
"python",
"directory",
"shortcut",
"target",
"lnk"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 397,159 | <p>This likely goes back to the core concept that there should be one obvious way to do a task. Additional comment styles add unnecessary complications and could decrease readability.</p>
| 27 | 2008-12-29T05:04:11Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 397,160 | <p>Well, the triple-quotes are used as multiline comments in docstrings. And # comments are used as inline comments and people get use to it.</p>
<p>Most of script languages don't have multiline comments either. Maybe that's the cause?</p>
<p>See <a href="http://www.python.org/dev/peps/pep-0008/">PEP 0008</a>, sectio... | 11 | 2008-12-29T05:05:00Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 397,161 | <p>I doubt you'll get a better answer than, "Guido didn't feel the need for multi-line comments". </p>
<p>Guido has <a href="https://twitter.com/gvanrossum/status/112670605505077248">tweeted</a> about this,</p>
<blockquote>
<p>Python tip: You can use multi-line strings as multi-line comments. Unless used as docstri... | 223 | 2008-12-29T05:06:00Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 397,192 | <p>Assume that they were just considered unnecessary. Since it's so easy to just type <code>#a comment</code>, multiline comments can just consist of many single line comments.</p>
<p>For <a href="http://en.wikipedia.org/wiki/HTML" rel="nofollow">HTML</a>, on the other hand, there's more of a need for multiliners. It'... | 0 | 2008-12-29T05:35:39Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 397,194 | <p>This is just a guess .. but</p>
<p>Because they are strings, they have some semantic value (the compiler doesn't get rid of them), therefore it makes sense for them to be used as docstrings. They actually become part of the <a href="http://en.wikipedia.org/wiki/Abstract_syntax_tree" rel="nofollow">AST</a>, so extra... | 0 | 2008-12-29T05:38:01Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 397,216 | <p>Because the # convention is a common one, and there really isn't anything you can do with a multiline comment that you can't with a #-sign comment. It's a historical accident, like the ancestry of <code>/* ... */</code> comments going back to PL/I,</p>
| 0 | 2008-12-29T06:01:33Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 397,786 | <p>Triple-quoted text should NOT be considered multi-line comments; by convention, they are <a href="http://www.python.org/dev/peps/pep-0257/#rationale">docstrings</a>. They should describe what your code does and how to use it, but not for things like commenting out blocks of code. </p>
<p>According to Guido, <a hre... | 31 | 2008-12-29T14:16:05Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 397,889 | <pre><code># This
# is
# a
# multi-line
# comment
</code></pre>
<p>Use comment block or search and replace (s/^/#/g) in your editor to achieve this.</p>
| 3 | 2008-12-29T15:17:54Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 397,950 | <p>Multi-line comments are easily breakable. What if you have the following in a simple calculator program?</p>
<pre><code>operation = ''
print("Pick an operation: +-*/")
# Get user input here
</code></pre>
<p>Try to comment that with a multi-line comment:</p>
<pre><code>/*
operation = ''
print("Pick an operation:... | 59 | 2008-12-29T15:44:08Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 398,025 | <p>From <a href="http://www.python.org/dev/peps/pep-0020/">The Zen of Python</a>:</p>
<p>There should be one-- and preferably only one --obvious way to do it.</p>
| 8 | 2008-12-29T16:18:23Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 398,042 | <p>Personally my comment style in say Java is like</p>
<pre><code>/*
* My multi-line comment in Java
*/
</code></pre>
<p>So having single-line only comments isn't such a bad thing if your style is typical to the preceding example because in comparison you'd have</p>
<pre><code>#
# My multi-line comment in Python
#... | 4 | 2008-12-29T16:27:01Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 398,045 | <p>Besides, <a href="http://en.wikipedia.org/wiki/Amores_perros" rel="nofollow">multiline comments are a bitch</a>. Sorry to say, but regardless of the language, I don't use them for anything else than debugging purposes. Say you have code like this:</p>
<pre><code>void someFunction()
{
Something
/*Some commen... | 0 | 2008-12-29T16:28:12Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 6,402,964 | <p>I remember reading about one guy who would put his multi-line comments into a triple-quoted variable:</p>
<pre><code>x = '''
This is my
super-long mega-comment.
Wow there are a lot of lines
going on here!
'''
</code></pre>
<p>This does take up a bit of memory, but it gives you multi-line comment functionality, and... | -1 | 2011-06-19T14:27:14Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 13,395,008 | <p>I solved this by downloading a macro for my text editor (TextPad) that lets me highlight lines and it then inserts # at the first of each line. A similar macro removes the #'s. Some may ask why multiline is necessary but it comes in handy when you're trying to "turn off" a block of code for debugging purposes.</p>... | 2 | 2012-11-15T09:54:37Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 19,171,859 | <p>Multiline comments using <strong><a href="http://en.wikipedia.org/wiki/IDLE_%28Python%29" rel="nofollow">IDLE</a></strong> on:</p>
<ul>
<li><p><strong>Mac OS X</strong>, after code selection, comment a block of code with <kbd>Ctrl</kbd>+<kbd>3</kbd> and uncomment using <kbd>Ctrl</kbd>+<kbd>4</kbd>.</p></l... | 0 | 2013-10-04T01:45:06Z | [
"python",
"comments",
"multiline"
] |
Why doesn't Python have multiline comments? | 397,148 | <p>OK, I'm aware that triple-quotes strings can serve as multiline comments. For example,</p>
<pre><code>"""Hello, I am a
multiline comment"""
</code></pre>
<p>and </p>
<pre><code>'''Hello, I am a
multiline comment'''
</code></pre>
<p>But technically speaking these are strings, correct?</p>
<p>I've googled... | 194 | 2008-12-29T04:53:17Z | 29,478,739 | <p>To comment out a block of code in the <a href="https://www.jetbrains.com/pycharm/help/commenting-and-uncommenting-blocks-of-code.html" rel="nofollow">Pycharm</a> IDE:</p>
<ul>
<li>Code | Comment with Line Comment</li>
<li>Windows or Linux: <kbd>Ctrl</kbd> + <kbd>/</kbd></li>
<li>Mac OS: <kbd>Command</kbd> + <kbd>/<... | 2 | 2015-04-06T20:02:59Z | [
"python",
"comments",
"multiline"
] |
Fast file/directory scan method for windows? | 397,293 | <p>I'm looking for a high performance method or library for scanning all files on disk or in a given directory and grabbing their basic stats - filename, size, and modification date. </p>
<p>I've written a python program that uses <code>os.walk</code> along with <code>os.path.getsize</code> to get the file list, and i... | 3 | 2008-12-29T07:47:11Z | 397,305 | <p>The os.path module has a directory tree walking function as well. I've never run any sort of benchmarks on it, but you could give it a try. I'm not sure there's a faster way than os.walk/os.path.walk in Python, however.</p>
| 0 | 2008-12-29T08:01:08Z | [
"python",
"windows"
] |
Fast file/directory scan method for windows? | 397,293 | <p>I'm looking for a high performance method or library for scanning all files on disk or in a given directory and grabbing their basic stats - filename, size, and modification date. </p>
<p>I've written a python program that uses <code>os.walk</code> along with <code>os.path.getsize</code> to get the file list, and i... | 3 | 2008-12-29T07:47:11Z | 397,539 | <p>Well, I would expect this to be heavily I/O bound task.
As such, optimizations on python side would be quite ineffective; the only optimization I could think of is some different way of accessing/listing files, in order to reduce the actual read from the file system.
This of course requires a deep knowledge of the f... | 3 | 2008-12-29T11:21:56Z | [
"python",
"windows"
] |
Fast file/directory scan method for windows? | 397,293 | <p>I'm looking for a high performance method or library for scanning all files on disk or in a given directory and grabbing their basic stats - filename, size, and modification date. </p>
<p>I've written a python program that uses <code>os.walk</code> along with <code>os.path.getsize</code> to get the file list, and i... | 3 | 2008-12-29T07:47:11Z | 397,561 | <p>It seems as if os.walk has been <a href="http://mail.python.org/pipermail/python-list/2006-October/408667.html" rel="nofollow">considerably improved</a> in python 2.5, so you might check if you're running that version. </p>
<p>Other than that, <a href="http://randomfoo.net/blog/id/4214" rel="nofollow">someone has a... | 3 | 2008-12-29T11:36:25Z | [
"python",
"windows"
] |
Fast file/directory scan method for windows? | 397,293 | <p>I'm looking for a high performance method or library for scanning all files on disk or in a given directory and grabbing their basic stats - filename, size, and modification date. </p>
<p>I've written a python program that uses <code>os.walk</code> along with <code>os.path.getsize</code> to get the file list, and i... | 3 | 2008-12-29T07:47:11Z | 397,647 | <p>When you look at the code for <code>os.walk</code>, you'll see that there's not much fat to be trimmed.</p>
<p>For example, the following is only a hair faster than os.walk.</p>
<pre><code>import os
import stat
listdir= os.listdir
pathjoin= os.path.join
fstat= os.stat
is_dir= stat.S_ISDIR
is_reg= stat.S_ISREG
def... | 1 | 2008-12-29T12:38:38Z | [
"python",
"windows"
] |
Fast file/directory scan method for windows? | 397,293 | <p>I'm looking for a high performance method or library for scanning all files on disk or in a given directory and grabbing their basic stats - filename, size, and modification date. </p>
<p>I've written a python program that uses <code>os.walk</code> along with <code>os.path.getsize</code> to get the file list, and i... | 3 | 2008-12-29T07:47:11Z | 398,092 | <p>You might want to look at the code for some Python version control systems like Mercurial or Bazaar. They have devoted a lot of time to coming up with ways to quickly traverse a directory tree and detect changes (or "finding basic stats about the files").</p>
| 2 | 2008-12-29T16:48:42Z | [
"python",
"windows"
] |
Fast file/directory scan method for windows? | 397,293 | <p>I'm looking for a high performance method or library for scanning all files on disk or in a given directory and grabbing their basic stats - filename, size, and modification date. </p>
<p>I've written a python program that uses <code>os.walk</code> along with <code>os.path.getsize</code> to get the file list, and i... | 3 | 2008-12-29T07:47:11Z | 398,436 | <p>I'm wondering if you might want to group your I/O operations. </p>
<p>For instance, if you're walking a dense directory tree with thousands of files, you might try experimenting with walking the entire tree and storing all the file locations, and then looping through the (in-memory) locations and getting file stat... | 1 | 2008-12-29T19:33:44Z | [
"python",
"windows"
] |
Fast file/directory scan method for windows? | 397,293 | <p>I'm looking for a high performance method or library for scanning all files on disk or in a given directory and grabbing their basic stats - filename, size, and modification date. </p>
<p>I've written a python program that uses <code>os.walk</code> along with <code>os.path.getsize</code> to get the file list, and i... | 3 | 2008-12-29T07:47:11Z | 401,894 | <p>This is only partial help, more like pointers; however:</p>
<p>I believe you need to do the following:</p>
<pre><code>fp = open("C:/$MFT", "rb")
</code></pre>
<p>using an account that includes SYSTEM permissions, because even as an admin, you can't open the "Master File Table" (kind of an inode table) of an NTFS ... | 0 | 2008-12-31T00:00:04Z | [
"python",
"windows"
] |
Fast file/directory scan method for windows? | 397,293 | <p>I'm looking for a high performance method or library for scanning all files on disk or in a given directory and grabbing their basic stats - filename, size, and modification date. </p>
<p>I've written a python program that uses <code>os.walk</code> along with <code>os.path.getsize</code> to get the file list, and i... | 3 | 2008-12-29T07:47:11Z | 19,715,067 | <p>Use scandir python module (formerly betterwalk) on github by Ben Hoyt.</p>
<p><a href="http://github.com/benhoyt/scandir" rel="nofollow">http://github.com/benhoyt/scandir</a></p>
<p>It is much faster than python walk, but uses the same syntax. Just import scandir and change os.walk() to scandir.walk(). That's it... | 2 | 2013-10-31T19:29:49Z | [
"python",
"windows"
] |
Fast file/directory scan method for windows? | 397,293 | <p>I'm looking for a high performance method or library for scanning all files on disk or in a given directory and grabbing their basic stats - filename, size, and modification date. </p>
<p>I've written a python program that uses <code>os.walk</code> along with <code>os.path.getsize</code> to get the file list, and i... | 3 | 2008-12-29T07:47:11Z | 32,559,545 | <p>Python 3.5 just introduced <a href="https://docs.python.org/dev/library/os.html#os.scandir" rel="nofollow"><code>os.scandir</code></a> (see <a href="https://www.python.org/dev/peps/pep-0471/#abstract" rel="nofollow">PEP-0471</a>) which avoids a number of non-required system calls such as <code>stat()</code> and <cod... | 1 | 2015-09-14T07:42:06Z | [
"python",
"windows"
] |
Using external GUI libraries to make user interfaces in Autodesk Maya | 397,337 | <p>I develop tools in Autodesk Maya. Many of the tools I build have simple windowed GUIs for the animators and modellers to use. These GUIs often contain what you'd normally expect to see in any basic window; labels, lists, menus, buttons, textfields, etc. However, there are limitations to the complexity of the UIs ... | 7 | 2008-12-29T08:41:12Z | 398,469 | <p>I don't know if there is a way around a mainloop for the gui, since it is needed to handle all event chains and redraw queues. </p>
<p>But there are several means of inter-process communication, like pipes or semaphores. Maybe it is an option to split your Maya extension into the actual plugin, being tight into may... | 0 | 2008-12-29T19:41:38Z | [
"python",
"scripting",
"wxpython",
"wxwidgets",
"maya"
] |
Using external GUI libraries to make user interfaces in Autodesk Maya | 397,337 | <p>I develop tools in Autodesk Maya. Many of the tools I build have simple windowed GUIs for the animators and modellers to use. These GUIs often contain what you'd normally expect to see in any basic window; labels, lists, menus, buttons, textfields, etc. However, there are limitations to the complexity of the UIs ... | 7 | 2008-12-29T08:41:12Z | 399,413 | <p>I'm not sure if this is germane, but some googling turns up that PyQt is pretty popular inside of Maya. You could try the technique <a href="http://www.highend3d.com/boards/lofiversion/index.php/t236041.html" rel="nofollow">here</a> or <a href="http://www.highend3d.com/boards/index.php?showtopic=242116" rel="nofoll... | 2 | 2008-12-30T02:48:01Z | [
"python",
"scripting",
"wxpython",
"wxwidgets",
"maya"
] |
Using external GUI libraries to make user interfaces in Autodesk Maya | 397,337 | <p>I develop tools in Autodesk Maya. Many of the tools I build have simple windowed GUIs for the animators and modellers to use. These GUIs often contain what you'd normally expect to see in any basic window; labels, lists, menus, buttons, textfields, etc. However, there are limitations to the complexity of the UIs ... | 7 | 2008-12-29T08:41:12Z | 30,247,511 | <p>The best way to go is creating a QWidget with what you need, and using it from within a MPxCommand thru the C++ API. That way you also have the chance to inject complete custom editors into Maya via scriptedPanels.</p>
<p>But if you're bound to Python, pyQt is the way to go.</p>
| 0 | 2015-05-14T21:18:00Z | [
"python",
"scripting",
"wxpython",
"wxwidgets",
"maya"
] |
Python Proxy Script | 398,385 | <p>I'm writing a simple python script so I can test my websites from a different ip address.</p>
<p>The url of a page is given in the querystring, the script fetches the page and displays it to the user. The code below is used to rewrite the tags that contain urls but I don't think it's complete/totally correct.</p>
... | 0 | 2008-12-29T19:19:08Z | 398,536 | <p>Please read other postings here about parsing HTML. For example <a href="http://stackoverflow.com/questions/55391/python-regular-expression-for-html-parsing-beautifulsoup">http://stackoverflow.com/questions/55391/python-regular-expression-for-html-parsing-beautifulsoup</a> and <a href="http://stackoverflow.com/ques... | 3 | 2008-12-29T20:09:34Z | [
"python",
"proxy"
] |
Split by \b when your regex engine doesn't support it | 398,560 | <p>How can I split by word boundary in a regex engine that doesn't support it?</p>
<p>python's re can match on \b but doesn't seem to support splitting on it. I seem to recall dealing with other regex engines that had the same limitation.</p>
<p>example input:</p>
<pre><code>"hello, foo"
</code></pre>
<p>expected o... | 4 | 2008-12-29T20:22:14Z | 398,570 | <p>Try </p>
<pre><code>>>> re.compile(r'\W\b').split('hello, foo')
['hello,', 'foo']
</code></pre>
<p>This splits at the non-word characted before a boundry.
Your example has nothing to split on.</p>
| 0 | 2008-12-29T20:31:15Z | [
"python",
"regex"
] |
Split by \b when your regex engine doesn't support it | 398,560 | <p>How can I split by word boundary in a regex engine that doesn't support it?</p>
<p>python's re can match on \b but doesn't seem to support splitting on it. I seem to recall dealing with other regex engines that had the same limitation.</p>
<p>example input:</p>
<pre><code>"hello, foo"
</code></pre>
<p>expected o... | 4 | 2008-12-29T20:22:14Z | 398,584 | <p>(\W+) can give you the expected output:</p>
<pre><code>>>> re.compile(r'(\W+)').split('hello, foo')
['hello', ', ', 'foo']
</code></pre>
| 9 | 2008-12-29T20:38:26Z | [
"python",
"regex"
] |
Split by \b when your regex engine doesn't support it | 398,560 | <p>How can I split by word boundary in a regex engine that doesn't support it?</p>
<p>python's re can match on \b but doesn't seem to support splitting on it. I seem to recall dealing with other regex engines that had the same limitation.</p>
<p>example input:</p>
<pre><code>"hello, foo"
</code></pre>
<p>expected o... | 4 | 2008-12-29T20:22:14Z | 398,589 | <p>Ok I figured it out:</p>
<p>Put the split pattern in capturing parens and will be included in the output. You can use either \w+ or \W+:</p>
<pre><code>>>> re.compile(r'(\w+)').split('hello, foo')
['', 'hello', ', ', 'foo', '']
</code></pre>
<p>To get rid of the empty results, pass it through filter() wi... | 1 | 2008-12-29T20:39:05Z | [
"python",
"regex"
] |
Split by \b when your regex engine doesn't support it | 398,560 | <p>How can I split by word boundary in a regex engine that doesn't support it?</p>
<p>python's re can match on \b but doesn't seem to support splitting on it. I seem to recall dealing with other regex engines that had the same limitation.</p>
<p>example input:</p>
<pre><code>"hello, foo"
</code></pre>
<p>expected o... | 4 | 2008-12-29T20:22:14Z | 398,590 | <p>Interesting. So far most RE engines I tried do this split.</p>
<p>I played a bit and found that <code>re.compile(r'(\W+)').split('hello, foo')</code> is giving the output you expected... Not sure if that's reliable, though.</p>
| 0 | 2008-12-29T20:39:57Z | [
"python",
"regex"
] |
Split by \b when your regex engine doesn't support it | 398,560 | <p>How can I split by word boundary in a regex engine that doesn't support it?</p>
<p>python's re can match on \b but doesn't seem to support splitting on it. I seem to recall dealing with other regex engines that had the same limitation.</p>
<p>example input:</p>
<pre><code>"hello, foo"
</code></pre>
<p>expected o... | 4 | 2008-12-29T20:22:14Z | 398,768 | <p>One can also use re.findall() for this:</p>
<pre><code>>>> re.findall(r'.+?\b', 'hello, foo')
['hello', ', ', 'foo']
</code></pre>
| 2 | 2008-12-29T21:41:31Z | [
"python",
"regex"
] |
Why can't I subclass datetime.date? | 399,022 | <p>Why doesn't the following work (Python 2.5.2)?</p>
<pre><code>>>> import datetime
>>> class D(datetime.date):
def __init__(self, year):
datetime.date.__init__(self, year, 1, 1)
>>> D(2008)
Traceback (most recent call last):
File "<stdin>", line 1, in <module... | 15 | 2008-12-29T23:08:18Z | 399,033 | <p>Here's the answer, and a possible solution (use a function or strptime instead of subclassing)</p>
<p><a href="http://www.mail-archive.com/[email protected]/msg192783.html" rel="nofollow">http://www.mail-archive.com/[email protected]/msg192783.html</a></p>
| 3 | 2008-12-29T23:12:44Z | [
"python",
"oop",
"datetime",
"subclass"
] |
Why can't I subclass datetime.date? | 399,022 | <p>Why doesn't the following work (Python 2.5.2)?</p>
<pre><code>>>> import datetime
>>> class D(datetime.date):
def __init__(self, year):
datetime.date.__init__(self, year, 1, 1)
>>> D(2008)
Traceback (most recent call last):
File "<stdin>", line 1, in <module... | 15 | 2008-12-29T23:08:18Z | 399,061 | <p>You should probably use a factory function instead of creating a subclass:</p>
<pre><code>def first_day_of_the_year(year):
return datetime.date(year, 1, 1)
</code></pre>
| 0 | 2008-12-29T23:22:00Z | [
"python",
"oop",
"datetime",
"subclass"
] |
Why can't I subclass datetime.date? | 399,022 | <p>Why doesn't the following work (Python 2.5.2)?</p>
<pre><code>>>> import datetime
>>> class D(datetime.date):
def __init__(self, year):
datetime.date.__init__(self, year, 1, 1)
>>> D(2008)
Traceback (most recent call last):
File "<stdin>", line 1, in <module... | 15 | 2008-12-29T23:08:18Z | 399,418 | <p>You're function isn't being bypassed; Python just never gets to the point where it would call it. Since datetime is implemented in C, it does its initialization in <code>datetime.__new__</code> not <code>datetime.__init__</code>. This is because datetime is immutable. You could presumably get around this by overridi... | 1 | 2008-12-30T02:50:29Z | [
"python",
"oop",
"datetime",
"subclass"
] |
Why can't I subclass datetime.date? | 399,022 | <p>Why doesn't the following work (Python 2.5.2)?</p>
<pre><code>>>> import datetime
>>> class D(datetime.date):
def __init__(self, year):
datetime.date.__init__(self, year, 1, 1)
>>> D(2008)
Traceback (most recent call last):
File "<stdin>", line 1, in <module... | 15 | 2008-12-29T23:08:18Z | 399,712 | <p>You can <strong>wrap</strong> it and add extended functionality to your wrapper.</p>
<p>Here is an example:</p>
<pre><code>class D2(object):
def __init__(self, *args, **kwargs):
self.date_object = datetime.date(*args, **kwargs)
def __getattr__(self, name):
return getattr(self.date_object, ... | 0 | 2008-12-30T07:21:29Z | [
"python",
"oop",
"datetime",
"subclass"
] |
Why can't I subclass datetime.date? | 399,022 | <p>Why doesn't the following work (Python 2.5.2)?</p>
<pre><code>>>> import datetime
>>> class D(datetime.date):
def __init__(self, year):
datetime.date.__init__(self, year, 1, 1)
>>> D(2008)
Traceback (most recent call last):
File "<stdin>", line 1, in <module... | 15 | 2008-12-29T23:08:18Z | 400,583 | <p>Regarding several other answers, this doesn't have anything to do with dates being implemented in C per se. The <code>__init__</code> method does nothing because they are <em>immutable</em> objects, therefore the constructor (<code>__new__</code>) should do all the work. You would see the same behavior subclassing... | 31 | 2008-12-30T15:36:32Z | [
"python",
"oop",
"datetime",
"subclass"
] |
Why can't I subclass datetime.date? | 399,022 | <p>Why doesn't the following work (Python 2.5.2)?</p>
<pre><code>>>> import datetime
>>> class D(datetime.date):
def __init__(self, year):
datetime.date.__init__(self, year, 1, 1)
>>> D(2008)
Traceback (most recent call last):
File "<stdin>", line 1, in <module... | 15 | 2008-12-29T23:08:18Z | 402,024 | <p>Please read the Python reference on <a href="http://www.python.org/doc/current/reference/datamodel.html"><em>Data model</em></a>, especially about the <code>__new__</code> <a href="http://www.python.org/doc/current/reference/datamodel.html#object.__new__">special method</a>.</p>
<p>Excerpt from that page (my italic... | 8 | 2008-12-31T01:19:50Z | [
"python",
"oop",
"datetime",
"subclass"
] |
Extended slice that goes to beginning of sequence with negative stride | 399,067 | <p>Bear with me while I explain my question. Skip down to the bold heading if you already understand extended slice list indexing.</p>
<p>In python, you can index lists using slice notation. Here's an example:</p>
<pre><code>>>> A = list(range(10))
>>> A[0:5]
[0, 1, 2, 3, 4]
</code></pre>
<p>You c... | 11 | 2008-12-29T23:26:41Z | 399,082 | <pre><code>a[4::-1]
</code></pre>
<p>Example:</p>
<pre><code>Python 2.6 (r26:66714, Dec 4 2008, 11:34:15)
[GCC 4.0.1 (Apple Inc. build 5488)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = list(range(10))
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> a... | 0 | 2008-12-29T23:33:18Z | [
"python",
"list",
"slice"
] |
Extended slice that goes to beginning of sequence with negative stride | 399,067 | <p>Bear with me while I explain my question. Skip down to the bold heading if you already understand extended slice list indexing.</p>
<p>In python, you can index lists using slice notation. Here's an example:</p>
<pre><code>>>> A = list(range(10))
>>> A[0:5]
[0, 1, 2, 3, 4]
</code></pre>
<p>You c... | 11 | 2008-12-29T23:26:41Z | 399,089 | <p>I believe that the following doesn't satisfy you:</p>
<pre><code>def getReversedList(aList, end, start, step):
if step < 0 and start == 0:
return aList[end::step]
return aList[end:start:step]
</code></pre>
<p>or does it? :-)</p>
| 1 | 2008-12-29T23:38:30Z | [
"python",
"list",
"slice"
] |
Extended slice that goes to beginning of sequence with negative stride | 399,067 | <p>Bear with me while I explain my question. Skip down to the bold heading if you already understand extended slice list indexing.</p>
<p>In python, you can index lists using slice notation. Here's an example:</p>
<pre><code>>>> A = list(range(10))
>>> A[0:5]
[0, 1, 2, 3, 4]
</code></pre>
<p>You c... | 11 | 2008-12-29T23:26:41Z | 399,107 | <p>Ok, I think this is probably as good as I will get it. Thanks to Abgan for sparking the idea. This relies on the fact that None in a slice is treated as if it were a missing parameter. Anyone got anything better?</p>
<pre><code>def getReversedList(aList, end, start, step):
return aList[end:start if start!=-1... | 2 | 2008-12-29T23:44:35Z | [
"python",
"list",
"slice"
] |
Extended slice that goes to beginning of sequence with negative stride | 399,067 | <p>Bear with me while I explain my question. Skip down to the bold heading if you already understand extended slice list indexing.</p>
<p>In python, you can index lists using slice notation. Here's an example:</p>
<pre><code>>>> A = list(range(10))
>>> A[0:5]
[0, 1, 2, 3, 4]
</code></pre>
<p>You c... | 11 | 2008-12-29T23:26:41Z | 399,176 | <pre><code>[ A[b] for b in range(end,start,stride) ]
</code></pre>
<p>Slower, however you can use negative indices, so this should work:</p>
<pre><code>[ A[b] for b in range(9, -1, -1) ]
</code></pre>
<p>I realize this isn't using slices, but thought I'd offer the solution anyway if using slices specifically for get... | 2 | 2008-12-30T00:10:05Z | [
"python",
"list",
"slice"
] |
Extended slice that goes to beginning of sequence with negative stride | 399,067 | <p>Bear with me while I explain my question. Skip down to the bold heading if you already understand extended slice list indexing.</p>
<p>In python, you can index lists using slice notation. Here's an example:</p>
<pre><code>>>> A = list(range(10))
>>> A[0:5]
[0, 1, 2, 3, 4]
</code></pre>
<p>You c... | 11 | 2008-12-29T23:26:41Z | 400,080 | <blockquote>
<p><a href="http://stackoverflow.com/questions/399067/extended-slice-that-goes-to-beginning-of-sequence-with-negative-stride#399082">But</a> you can't use that if you are
storing your indices in variables for
example.</p>
</blockquote>
<p>Is this satisfactory?</p>
<pre><code>>>> a = range(... | 1 | 2008-12-30T11:41:43Z | [
"python",
"list",
"slice"
] |
Extended slice that goes to beginning of sequence with negative stride | 399,067 | <p>Bear with me while I explain my question. Skip down to the bold heading if you already understand extended slice list indexing.</p>
<p>In python, you can index lists using slice notation. Here's an example:</p>
<pre><code>>>> A = list(range(10))
>>> A[0:5]
[0, 1, 2, 3, 4]
</code></pre>
<p>You c... | 11 | 2008-12-29T23:26:41Z | 400,118 | <p>It is error-prone to change the semantics of <code>start</code> and <code>stop</code>. Use <code>None</code> or <code>-(len(a) + 1)</code> instead of <code>0</code> or <code>-1</code>. The semantics is not arbitrary. See Edsger W. Dijkstra's article <a href="http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx... | 5 | 2008-12-30T12:06:23Z | [
"python",
"list",
"slice"
] |
Extended slice that goes to beginning of sequence with negative stride | 399,067 | <p>Bear with me while I explain my question. Skip down to the bold heading if you already understand extended slice list indexing.</p>
<p>In python, you can index lists using slice notation. Here's an example:</p>
<pre><code>>>> A = list(range(10))
>>> A[0:5]
[0, 1, 2, 3, 4]
</code></pre>
<p>You c... | 11 | 2008-12-29T23:26:41Z | 400,473 | <p>As you say very few people fully understand everything that you can do with extended slicing, so unless you really need the extra performance I'd do it the "obvious" way:</p>
<p><code>
rev_subset = reversed(data[start:stop])
</code></p>
| 1 | 2008-12-30T15:01:08Z | [
"python",
"list",
"slice"
] |
Extended slice that goes to beginning of sequence with negative stride | 399,067 | <p>Bear with me while I explain my question. Skip down to the bold heading if you already understand extended slice list indexing.</p>
<p>In python, you can index lists using slice notation. Here's an example:</p>
<pre><code>>>> A = list(range(10))
>>> A[0:5]
[0, 1, 2, 3, 4]
</code></pre>
<p>You c... | 11 | 2008-12-29T23:26:41Z | 4,599,442 | <p>I know this is an old question, but in case someone like me is looking for answers:</p>
<pre><code>>>> A[5-1::-1]
[4, 3, 2, 1, 0]
>>> A[4:1:-1]
[4, 3, 2]
</code></pre>
| 0 | 2011-01-04T23:17:45Z | [
"python",
"list",
"slice"
] |
Extended slice that goes to beginning of sequence with negative stride | 399,067 | <p>Bear with me while I explain my question. Skip down to the bold heading if you already understand extended slice list indexing.</p>
<p>In python, you can index lists using slice notation. Here's an example:</p>
<pre><code>>>> A = list(range(10))
>>> A[0:5]
[0, 1, 2, 3, 4]
</code></pre>
<p>You c... | 11 | 2008-12-29T23:26:41Z | 4,599,638 | <p>You can use a <code>slice(start, stop, step)</code> object, which is such that</p>
<pre><code>s=slice(start, stop, step)
print a[s]
</code></pre>
<p>is the same as</p>
<pre><code>print a[start : stop : step]
</code></pre>
<p>and, moreover, you can set any of the arguments to <code>None</code> to indicate nothing... | 0 | 2011-01-04T23:52:24Z | [
"python",
"list",
"slice"
] |
Failing to send email with the Python example | 399,129 | <p>I've been trying (and failing) to figure out how to send email via Python.</p>
<p>Trying the example from here:
<a href="http://docs.python.org/library/smtplib.html#smtplib.SMTP">http://docs.python.org/library/smtplib.html#smtplib.SMTP</a></p>
<p>but added the line <code>server = smtplib.SMTP_SSL('smtp.gmail.com',... | 18 | 2008-12-29T23:51:33Z | 399,140 | <p>Incorrect port maybe? I'm using <strong>587</strong> for <strong>smtp.gmail.com</strong> and it works.</p>
| 1 | 2008-12-29T23:59:19Z | [
"python",
"email",
"smtplib"
] |
Failing to send email with the Python example | 399,129 | <p>I've been trying (and failing) to figure out how to send email via Python.</p>
<p>Trying the example from here:
<a href="http://docs.python.org/library/smtplib.html#smtplib.SMTP">http://docs.python.org/library/smtplib.html#smtplib.SMTP</a></p>
<p>but added the line <code>server = smtplib.SMTP_SSL('smtp.gmail.com',... | 18 | 2008-12-29T23:51:33Z | 399,142 | <p>You should check your port, I'm not sure that google's SMTP port is 65, that would explain the timeout. </p>
<p>Modify your sources as such:</p>
<p>smtplib.SMTP_SSL('smtp.google.com', 465)</p>
<p>If, however, you are certain that it ought to work and it doesn't, it appears that there are some problems with smtpli... | 0 | 2008-12-29T23:59:31Z | [
"python",
"email",
"smtplib"
] |
Failing to send email with the Python example | 399,129 | <p>I've been trying (and failing) to figure out how to send email via Python.</p>
<p>Trying the example from here:
<a href="http://docs.python.org/library/smtplib.html#smtplib.SMTP">http://docs.python.org/library/smtplib.html#smtplib.SMTP</a></p>
<p>but added the line <code>server = smtplib.SMTP_SSL('smtp.gmail.com',... | 18 | 2008-12-29T23:51:33Z | 399,240 | <p>The following code works for me:</p>
<pre><code>import smtplib
FROMADDR = "[email protected]"
LOGIN = FROMADDR
PASSWORD = "my.real.password"
TOADDRS = ["[email protected]"]
SUBJECT = "Test"
msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
% (FROMADDR, ", ".join(TOADDRS), SUBJECT) )
m... | 25 | 2008-12-30T00:48:19Z | [
"python",
"email",
"smtplib"
] |
Failing to send email with the Python example | 399,129 | <p>I've been trying (and failing) to figure out how to send email via Python.</p>
<p>Trying the example from here:
<a href="http://docs.python.org/library/smtplib.html#smtplib.SMTP">http://docs.python.org/library/smtplib.html#smtplib.SMTP</a></p>
<p>but added the line <code>server = smtplib.SMTP_SSL('smtp.gmail.com',... | 18 | 2008-12-29T23:51:33Z | 399,587 | <p>Here's a simple throw away solution. Meant to paste this earlier, but fell asleep at my chair.</p>
<pre><code>
import smtplib
import email
import os
username = "[email protected]"
passwd = "password"
def mail(to, subject, text, attach):
msg = MIMEMultipart()
msg['From'] = username
msg['To'] = to
msg['Su... | 6 | 2008-12-30T05:35:03Z | [
"python",
"email",
"smtplib"
] |
Failing to send email with the Python example | 399,129 | <p>I've been trying (and failing) to figure out how to send email via Python.</p>
<p>Trying the example from here:
<a href="http://docs.python.org/library/smtplib.html#smtplib.SMTP">http://docs.python.org/library/smtplib.html#smtplib.SMTP</a></p>
<p>but added the line <code>server = smtplib.SMTP_SSL('smtp.gmail.com',... | 18 | 2008-12-29T23:51:33Z | 400,930 | <p>Okay, found out that this line of code does the trick!</p>
<p>server = smtplib.SMTP('smtp.gmail.com', 587 )</p>
<p>Turned out to be GMAIL didn't support SSL on port 25 (and port 465 caused a hang for some reason).</p>
<p>Thanks guys!</p>
| 2 | 2008-12-30T17:30:53Z | [
"python",
"email",
"smtplib"
] |
Failing to send email with the Python example | 399,129 | <p>I've been trying (and failing) to figure out how to send email via Python.</p>
<p>Trying the example from here:
<a href="http://docs.python.org/library/smtplib.html#smtplib.SMTP">http://docs.python.org/library/smtplib.html#smtplib.SMTP</a></p>
<p>but added the line <code>server = smtplib.SMTP_SSL('smtp.gmail.com',... | 18 | 2008-12-29T23:51:33Z | 402,054 | <p>The correct way to connect to GMail using SSL is:</p>
<pre><code>server = smtplib.SMTP('smtp.gmail.com', 587)
</code></pre>
<p>Port 465 seems to cause delays. Both ports are specified in a <a href="http://mail.google.com/support/bin/answer.py?hl=en&answer=78799">GMail FAQ</a>.</p>
<p>Note that use of port 587... | 6 | 2008-12-31T01:41:13Z | [
"python",
"email",
"smtplib"
] |
Failing to send email with the Python example | 399,129 | <p>I've been trying (and failing) to figure out how to send email via Python.</p>
<p>Trying the example from here:
<a href="http://docs.python.org/library/smtplib.html#smtplib.SMTP">http://docs.python.org/library/smtplib.html#smtplib.SMTP</a></p>
<p>but added the line <code>server = smtplib.SMTP_SSL('smtp.gmail.com',... | 18 | 2008-12-29T23:51:33Z | 955,323 | <p>The problem is due to <a href="http://bugs.python.org/issue4066">a bug in Python</a>. Trying to create a connection with SMTP_SSL will fail with "SMTPServerDisconnected: please run connect() first."</p>
<p>A fix has been committed, so you can patch your local copy. See the attachment named "smtplib_72551.diff".</p>... | 6 | 2009-06-05T11:01:06Z | [
"python",
"email",
"smtplib"
] |
Failing to send email with the Python example | 399,129 | <p>I've been trying (and failing) to figure out how to send email via Python.</p>
<p>Trying the example from here:
<a href="http://docs.python.org/library/smtplib.html#smtplib.SMTP">http://docs.python.org/library/smtplib.html#smtplib.SMTP</a></p>
<p>but added the line <code>server = smtplib.SMTP_SSL('smtp.gmail.com',... | 18 | 2008-12-29T23:51:33Z | 21,589,598 | <pre><code>import smtplib
content = 'example email stuff here'
mail = smtplib.SMTP('smtp.gmail.com', 587)
mail.ehlo()
mail.starttls()
mail.login('[email protected]','password')
mail.sendmail('[email protected]', '[email protected]', content)
mail.close()
</code></pre>
| 0 | 2014-02-05T22:08:59Z | [
"python",
"email",
"smtplib"
] |
Failing to send email with the Python example | 399,129 | <p>I've been trying (and failing) to figure out how to send email via Python.</p>
<p>Trying the example from here:
<a href="http://docs.python.org/library/smtplib.html#smtplib.SMTP">http://docs.python.org/library/smtplib.html#smtplib.SMTP</a></p>
<p>but added the line <code>server = smtplib.SMTP_SSL('smtp.gmail.com',... | 18 | 2008-12-29T23:51:33Z | 30,595,598 | <pre><code>from smtplib import SMTP_SSL as SMTP
from email.mime.text import MIMEText
HOST = 'smtp.gmail.com'
PORT = 465
USERNAME = '[email protected]'
PASSWORD = ''
SENDER = '[email protected]'
RECIPIENT = '[email protected]'
text_subtype = 'plain'
with open('textfile', 'rb') as f:
msg = MIMEText(f.read(... | 1 | 2015-06-02T12:04:50Z | [
"python",
"email",
"smtplib"
] |
Tix and Python 3.0 | 399,326 | <p>Has anyone seen anything in Tix work under python 3.0? I've tried to work through the examples but when creating anything it states that cnf is unsubscriptable.</p>
<p>I also noticed that none of the Dir Select stuff (DirList DirTree) works under 2.6.1.</p>
<p>Why doesn't Python either dump Tix or support it? It... | 0 | 2008-12-30T01:57:34Z | 399,400 | <p>Likely what happened is that no one noticed the bug. (It's very hard to automatically test GUI libraries like Tix and Tkinter.) You should report bugs as you find them to <a href="http://bugs.python.org" rel="nofollow">http://bugs.python.org</a>.</p>
| 1 | 2008-12-30T02:41:54Z | [
"python",
"python-3.x",
"tix"
] |
Tix and Python 3.0 | 399,326 | <p>Has anyone seen anything in Tix work under python 3.0? I've tried to work through the examples but when creating anything it states that cnf is unsubscriptable.</p>
<p>I also noticed that none of the Dir Select stuff (DirList DirTree) works under 2.6.1.</p>
<p>Why doesn't Python either dump Tix or support it? It... | 0 | 2008-12-30T01:57:34Z | 400,066 | <p>Generally speaking, if you're using third-party modules, you're better off avoiding Python 3.0 for now. If you're working on a third-party module yourself, porting forward to Python 3.0 is a good idea, but for the time being general development in it is just going to be a recipe for pain.</p>
| 0 | 2008-12-30T11:31:40Z | [
"python",
"python-3.x",
"tix"
] |
Tix and Python 3.0 | 399,326 | <p>Has anyone seen anything in Tix work under python 3.0? I've tried to work through the examples but when creating anything it states that cnf is unsubscriptable.</p>
<p>I also noticed that none of the Dir Select stuff (DirList DirTree) works under 2.6.1.</p>
<p>Why doesn't Python either dump Tix or support it? It... | 0 | 2008-12-30T01:57:34Z | 1,333,329 | <p>See this: <a href="http://docs.python.org/3.1/library/tkinter.tix.html?highlight=tix#module-tkinter.tix" rel="nofollow">http://docs.python.org/3.1/library/tkinter.tix.html?highlight=tix#module-tkinter.tix</a></p>
| 0 | 2009-08-26T09:02:40Z | [
"python",
"python-3.x",
"tix"
] |
Programming a Logitech G15 using python | 399,624 | <p>I'd like to be able to write apps for my G15 keyboard using python. There seems to be a few people out there who have done it in the past, but I'm not sure what packages I need to install or where I should start. Does anyone have any experience with this?</p>
| 1 | 2008-12-30T06:14:00Z | 399,904 | <p>There's actually a couple of ways. You can use <a href="http://www.g15tools.com/" rel="nofollow">G15Tools</a>, of course. But the best solution would be <a href="https://launchpad.net/pyg15/" rel="nofollow">PyG15</a>.</p>
| 2 | 2008-12-30T10:00:43Z | [
"python",
"logitech",
"g15"
] |
How to integrate pep8.py in Eclipse? | 399,956 | <p>A little background:</p>
<ul>
<li><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> is the <em>Style Guide for Python Code</em>. It contains the conventions all python programmers should follow.</li>
<li><a href="http://pypi.python.org/pypi/pep8">pep8.py</a> is a (very useful) script that checks the code... | 82 | 2008-12-30T10:39:53Z | 403,262 | <p>That does not yet appear to be fully integrated into Pydev.</p>
<p>As suggested in <a href="http://osdir.com/ml/ide.eclipse.plugins.pydev.user/2007-01/msg00011.html" rel="nofollow">this post</a>, </p>
<blockquote>
<p>[it] would require changing the code within pydev -- a flexible option would be adding preferen... | 5 | 2008-12-31T15:47:42Z | [
"python",
"eclipse",
"pydev",
"pep8"
] |
How to integrate pep8.py in Eclipse? | 399,956 | <p>A little background:</p>
<ul>
<li><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> is the <em>Style Guide for Python Code</em>. It contains the conventions all python programmers should follow.</li>
<li><a href="http://pypi.python.org/pypi/pep8">pep8.py</a> is a (very useful) script that checks the code... | 82 | 2008-12-30T10:39:53Z | 2,296,249 | <p>I don't know how to integrate it for whole project, but I have used it as an external tool to analyze an individual file.</p>
<p>Note that the <a href="https://pypi.python.org/pypi/pycodestyle/" rel="nofollow"><code>pycodestyle</code></a> package is the official replacement for and is the newer version of the <a hr... | 23 | 2010-02-19T12:36:16Z | [
"python",
"eclipse",
"pydev",
"pep8"
] |
How to integrate pep8.py in Eclipse? | 399,956 | <p>A little background:</p>
<ul>
<li><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> is the <em>Style Guide for Python Code</em>. It contains the conventions all python programmers should follow.</li>
<li><a href="http://pypi.python.org/pypi/pep8">pep8.py</a> is a (very useful) script that checks the code... | 82 | 2008-12-30T10:39:53Z | 7,947,400 | <p>You don't :) Instead you take advantage of very good integration with PyLint and configure PyLint to check all things PEP8 checks. See <a href="http://stackoverflow.com/questions/6879640/">How to configure PyLint to check all things PEP8 checks?</a></p>
| -1 | 2011-10-30T19:53:36Z | [
"python",
"eclipse",
"pydev",
"pep8"
] |
How to integrate pep8.py in Eclipse? | 399,956 | <p>A little background:</p>
<ul>
<li><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> is the <em>Style Guide for Python Code</em>. It contains the conventions all python programmers should follow.</li>
<li><a href="http://pypi.python.org/pypi/pep8">pep8.py</a> is a (very useful) script that checks the code... | 82 | 2008-12-30T10:39:53Z | 8,532,188 | <p>As of PyDev 2.3.0, <code>pep8</code> is integrated in PyDev by default, even shipping with a default version of it.</p>
<p>Open Window > Preferences</p>
<p>It must be enabled in PyDev > Editor > Code Analysis > pep8.py</p>
<p>Errors/Warnings should be shown as markers (as other things in the regular code analysis... | 75 | 2011-12-16T09:32:19Z | [
"python",
"eclipse",
"pydev",
"pep8"
] |
How to integrate pep8.py in Eclipse? | 399,956 | <p>A little background:</p>
<ul>
<li><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> is the <em>Style Guide for Python Code</em>. It contains the conventions all python programmers should follow.</li>
<li><a href="http://pypi.python.org/pypi/pep8">pep8.py</a> is a (very useful) script that checks the code... | 82 | 2008-12-30T10:39:53Z | 8,830,316 | <ol>
<li>Open your Eclipse</li>
<li>Go to Help and select Install New Software</li>
<li>Click the Add button and a "Add Repository" Dialog box will appear</li>
<li>You can use any name you like for it. (I used PyDev)</li>
<li>For the location, enter "http://pydev.org/updates"</li>
<li>Click Ok.</li>
<li>You are now in ... | 10 | 2012-01-12T04:55:42Z | [
"python",
"eclipse",
"pydev",
"pep8"
] |
How to integrate pep8.py in Eclipse? | 399,956 | <p>A little background:</p>
<ul>
<li><a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> is the <em>Style Guide for Python Code</em>. It contains the conventions all python programmers should follow.</li>
<li><a href="http://pypi.python.org/pypi/pep8">pep8.py</a> is a (very useful) script that checks the code... | 82 | 2008-12-30T10:39:53Z | 33,952,133 | <p><strong>CODE ANALYSIS :</strong></p>
<p>In Eclipse (<strong>PyDev</strong>), if you want to <strong>code analysis</strong> using pep8 style then</p>
<p>Go to:Windows -> Preferences -> PyDev -> Editor -> Code Analysis -> <strong>pep8.py</strong> tab and select <strong>Warning</strong> click Apply and OK button.</p>... | 3 | 2015-11-27T07:19:03Z | [
"python",
"eclipse",
"pydev",
"pep8"
] |
Need help on selecting items in simple database in python | 399,957 | <p>I'm trying to write a circuit schematic drawing tool in Python. I'm creating a simple database based on dictionaries which holds all the components and their properties. I'm also trying to create a simple query language where you can select, for example, all resistors with value>100ohms or footprint='0402' </p>
... | 2 | 2008-12-30T10:40:07Z | 399,997 | <p>It really depends on how you've implemented this "simple database based on dictionaries" as to why straight negation isn't working - you'll have to give us some more clues.</p>
<p>There's no reason why a straightforward negation match <em>shouldn't</em> work in Python, e.g.:</p>
<pre><code>components = [
{ 'na... | 3 | 2008-12-30T10:58:05Z | [
"python",
"sql",
"circuit",
"eda"
] |
Need help on selecting items in simple database in python | 399,957 | <p>I'm trying to write a circuit schematic drawing tool in Python. I'm creating a simple database based on dictionaries which holds all the components and their properties. I'm also trying to create a simple query language where you can select, for example, all resistors with value>100ohms or footprint='0402' </p>
... | 2 | 2008-12-30T10:40:07Z | 400,058 | <p>You'll be a lot happier with a proper database.</p>
<p>You have SQLite with your Python distribution. Simply define tables instead of dictionaries and use SQL. </p>
<p>If you need more power and sophistication, you can add <a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a> (or <a href="http://www... | 5 | 2008-12-30T11:26:39Z | [
"python",
"sql",
"circuit",
"eda"
] |
Need help on selecting items in simple database in python | 399,957 | <p>I'm trying to write a circuit schematic drawing tool in Python. I'm creating a simple database based on dictionaries which holds all the components and their properties. I'm also trying to create a simple query language where you can select, for example, all resistors with value>100ohms or footprint='0402' </p>
... | 2 | 2008-12-30T10:40:07Z | 400,137 | <p>I agree with S.Lott that you would be happier with a real DB. SQLite is really light and fast, almost no drawbacks on using it.</p>
<p>if you really need to expose a simpler, yet complete, query language to the user, check <a href="http://goessner.net/articles/JsonPath/" rel="nofollow">JSONPath</a> or <a href="htt... | 1 | 2008-12-30T12:18:40Z | [
"python",
"sql",
"circuit",
"eda"
] |
Ignoring XML errors in Python | 399,980 | <p>I am using XML minidom (xml.dom.minidom) in Python, but any error in the XML will kill the parser.
Is it possible to ignore them, like a browser for example?
I am trying to write a browser in Python, but it just throws an exception if the tags aren't fully compatible.</p>
| 5 | 2008-12-30T10:48:33Z | 399,996 | <p>There is a library called <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a>, I think it's what you're looking for.
As you're trying to parse a invalid XML, the normal XML parser won't work. BeautifulSoup is more fail-tolerant, it can still extract information from invalid XML.</p>
<blockquot... | 10 | 2008-12-30T10:57:54Z | [
"python",
"xml",
"minidom"
] |
Ignoring XML errors in Python | 399,980 | <p>I am using XML minidom (xml.dom.minidom) in Python, but any error in the XML will kill the parser.
Is it possible to ignore them, like a browser for example?
I am trying to write a browser in Python, but it just throws an exception if the tags aren't fully compatible.</p>
| 5 | 2008-12-30T10:48:33Z | 400,001 | <p>See, for example, <a href="http://stackoverflow.com/questions/328356/extracting-text-from-html-file-using-python">extracting-text-from-html-file-using-python</a> for suggestions regarding ways for parsing HTML in Python.</p>
| 0 | 2008-12-30T10:58:44Z | [
"python",
"xml",
"minidom"
] |
Ignoring XML errors in Python | 399,980 | <p>I am using XML minidom (xml.dom.minidom) in Python, but any error in the XML will kill the parser.
Is it possible to ignore them, like a browser for example?
I am trying to write a browser in Python, but it just throws an exception if the tags aren't fully compatible.</p>
| 5 | 2008-12-30T10:48:33Z | 400,669 | <p>It should be noted that while HTML looks like XML it is not XML. XHTML is an XML form of HTML.</p>
| 3 | 2008-12-30T16:05:16Z | [
"python",
"xml",
"minidom"
] |
How do you get Python to write down the code of a function it has in memory? | 399,991 | <p>When I pass the options in the program (a computational biology experiment) I usually pass them through a .py file.<br>
So I have this .py file that reads like:</p>
<pre><code>starting_length=9
starting_cell_size=1000
LengthofExperiments=5000000
</code></pre>
<p>Then I execute the file and get the data. Since the ... | 4 | 2008-12-30T10:55:43Z | 400,040 | <pre>
vinko@mithril$ more a.py
def foo(a):
print a
vinko@mithril$ more b.py
import a
import inspect
a.foo(89)
print inspect.getsource(a.foo)
vinko@mithril$ python b.py
89
def foo(a):
print a
</pre>
| 12 | 2008-12-30T11:18:39Z | [
"python",
"artificial-intelligence"
] |
How do you get Python to write down the code of a function it has in memory? | 399,991 | <p>When I pass the options in the program (a computational biology experiment) I usually pass them through a .py file.<br>
So I have this .py file that reads like:</p>
<pre><code>starting_length=9
starting_cell_size=1000
LengthofExperiments=5000000
</code></pre>
<p>Then I execute the file and get the data. Since the ... | 4 | 2008-12-30T10:55:43Z | 400,046 | <p>Are you asking about this?</p>
<pre><code>def writeoptions(directory):
options=""
options+="starting_length=%s%s"%(starting_length,os.linesep)
options+="starting_cell_size=%s%s"%(starting_cell_size,os.linesep)
options+="LengthofExperiments=%s%s"%(LengthofExperiments,os.linesep)
options+="def pip... | 0 | 2008-12-30T11:21:05Z | [
"python",
"artificial-intelligence"
] |
How do you get Python to write down the code of a function it has in memory? | 399,991 | <p>When I pass the options in the program (a computational biology experiment) I usually pass them through a .py file.<br>
So I have this .py file that reads like:</p>
<pre><code>starting_length=9
starting_cell_size=1000
LengthofExperiments=5000000
</code></pre>
<p>Then I execute the file and get the data. Since the ... | 4 | 2008-12-30T10:55:43Z | 400,052 | <p>While it is possible to do what you ask (as Vinko has shown), I'd say it is cleaner to <em>share code</em>. Put <code>pippo</code> and his buddies in a submodule that both programs can access.</p>
| 0 | 2008-12-30T11:24:44Z | [
"python",
"artificial-intelligence"
] |
How do you get Python to write down the code of a function it has in memory? | 399,991 | <p>When I pass the options in the program (a computational biology experiment) I usually pass them through a .py file.<br>
So I have this .py file that reads like:</p>
<pre><code>starting_length=9
starting_cell_size=1000
LengthofExperiments=5000000
</code></pre>
<p>Then I execute the file and get the data. Since the ... | 4 | 2008-12-30T10:55:43Z | 400,054 | <p>Instead of diving into the subject of <a href="http://docs.python.org/library/dis.html" rel="nofollow">disassemblers</a> and bytecodes (e.g <a href="http://docs.python.org/library/inspect.html" rel="nofollow">inspect</a>), why don't you just save the generated Python source in a module (<em>file.py</em>), and later,... | 0 | 2008-12-30T11:25:27Z | [
"python",
"artificial-intelligence"
] |
How do you get Python to write down the code of a function it has in memory? | 399,991 | <p>When I pass the options in the program (a computational biology experiment) I usually pass them through a .py file.<br>
So I have this .py file that reads like:</p>
<pre><code>starting_length=9
starting_cell_size=1000
LengthofExperiments=5000000
</code></pre>
<p>Then I execute the file and get the data. Since the ... | 4 | 2008-12-30T10:55:43Z | 400,349 | <p>You might also consider some other means of data persistence. In my own (astronomy) research, I've been experimenting with two different means of storing scripts for reproducibility. The first is to have them exclusively inside a subversion repository, and then have the job submission script automatically commit t... | 1 | 2008-12-30T14:12:54Z | [
"python",
"artificial-intelligence"
] |
Reading and running a mathematical expression in Python | 400,050 | <p>Using Python, how would I go about reading in (be from a string, file or url) a mathematical expression (1 + 1 is a good start) and executing it? </p>
<p>Aside from grabbing a string, file or url I have no idea of where to start with this.</p>
| 5 | 2008-12-30T11:22:43Z | 400,060 | <p>If you are receiving an expression as a string you'll need to parse it into its operators and operands and then process the resulting tree. This isn't a python problem per se. but a general issue of how to deal with mathematical expressions delivered as strings.</p>
<p>A quick google reveals a bunch of lexical par... | 2 | 2008-12-30T11:28:02Z | [
"python"
] |
Reading and running a mathematical expression in Python | 400,050 | <p>Using Python, how would I go about reading in (be from a string, file or url) a mathematical expression (1 + 1 is a good start) and executing it? </p>
<p>Aside from grabbing a string, file or url I have no idea of where to start with this.</p>
| 5 | 2008-12-30T11:22:43Z | 400,062 | <p>Perhaps <code>eval</code> is what you're after?</p>
<pre><code>>>> eval('1+1')
2
</code></pre>
| 1 | 2008-12-30T11:28:51Z | [
"python"
] |
Reading and running a mathematical expression in Python | 400,050 | <p>Using Python, how would I go about reading in (be from a string, file or url) a mathematical expression (1 + 1 is a good start) and executing it? </p>
<p>Aside from grabbing a string, file or url I have no idea of where to start with this.</p>
| 5 | 2008-12-30T11:22:43Z | 400,070 | <p>Read about the <a href="http://docs.python.org/library/functions.html#input" rel="nofollow">input</a> function.</p>
| 1 | 2008-12-30T11:32:25Z | [
"python"
] |
Reading and running a mathematical expression in Python | 400,050 | <p>Using Python, how would I go about reading in (be from a string, file or url) a mathematical expression (1 + 1 is a good start) and executing it? </p>
<p>Aside from grabbing a string, file or url I have no idea of where to start with this.</p>
| 5 | 2008-12-30T11:22:43Z | 400,081 | <p>Because python supports some algebraic forms, you could do:</p>
<pre><code>eval("1 + 1")
</code></pre>
<p>But this allows the input to execute about anything defined in your env:</p>
<pre><code>eval("__import__('sys').exit(1)")
</code></pre>
<p>Also, if you want to support something python doesn't support, the a... | 7 | 2008-12-30T11:43:43Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.