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 |
|---|---|---|---|---|---|---|---|---|---|
Python linked list O(1) insert/remove | 2,154,946 | <p>I am looking for a linked list and related algorithms implementation for Python. Everyone I ask just recommends using built in Python lists, but performance measurements indicate that list insertion and removal is a bottleneck for our application. It's trivial to implement a simple linked list, but I wonder if there... | 4 | 2010-01-28T13:55:37Z | 11,097,246 | <p>How about using any of data structures which provide sorted data access? Binary (AVL trees, AVL, Red-black), for instance? These guarantee O(log(N)) insertion complexity. Not O(1), but better than what you have.</p>
| 0 | 2012-06-19T08:30:32Z | [
"python",
"algorithm",
"list",
"linked-list"
] |
Change process name of Python script | 2,155,042 | <p>Windows Task Manager lists all running processes in the "Processes" tab.
The image name of Python scripts is always <code>python.exe</code>, or <code>pythonw.exe</code>, or the name of the Python interpreter.</p>
<p>Is there a nice way to change the image name of a Python script, other than changing the name of the... | 9 | 2010-01-28T14:11:07Z | 2,155,073 | <p>You could use py2exe to turn your Python program into a self-contained executable with whatever name that you choose to give it.</p>
| 1 | 2010-01-28T14:16:59Z | [
"python",
"windows",
"process"
] |
Change process name of Python script | 2,155,042 | <p>Windows Task Manager lists all running processes in the "Processes" tab.
The image name of Python scripts is always <code>python.exe</code>, or <code>pythonw.exe</code>, or the name of the Python interpreter.</p>
<p>Is there a nice way to change the image name of a Python script, other than changing the name of the... | 9 | 2010-01-28T14:11:07Z | 2,606,257 | <p>There's no nice way that I've found to change the name of a running process in Windows, but you can create small .exe stubs with <a href="http://effbot.org/zone/exemaker.htm" rel="nofollow"><strong>ExeMaker</strong></a> rather than resorting to py2exe packaging or copying the interpreter</p>
<p>The exe stub uses it... | 1 | 2010-04-09T09:25:44Z | [
"python",
"windows",
"process"
] |
python dictionary question | 2,155,246 | <p>All,</p>
<p>This is the request from the template that i get</p>
<pre><code>u'subjects': [u'7', u'4', u'5', u'3', u'2', u'1']
</code></pre>
<p>In my views how to extract the values like <code>7 4 5 3 2 1</code></p>
<p>How do i extract the above sequence from </p>
<pre><code>new_subjects=request.POST.get('subjec... | 0 | 2010-01-28T14:42:51Z | 2,155,264 | <p>Something like the following:</p>
<pre><code>try:
int_subjects = [int(x) for x in new_subjects]
except ValueError:
#There was an error parsing.
</code></pre>
| 5 | 2010-01-28T14:45:01Z | [
"python",
"django"
] |
python dictionary question | 2,155,246 | <p>All,</p>
<p>This is the request from the template that i get</p>
<pre><code>u'subjects': [u'7', u'4', u'5', u'3', u'2', u'1']
</code></pre>
<p>In my views how to extract the values like <code>7 4 5 3 2 1</code></p>
<p>How do i extract the above sequence from </p>
<pre><code>new_subjects=request.POST.get('subjec... | 0 | 2010-01-28T14:42:51Z | 2,155,345 | <pre><code>try:
int_subjects = map(int, new_subjects)
except ValueError:
#There was an error parsing.
</code></pre>
<p>Using timeit in ipython shows that map is slightly faster than the comprehension in this case</p>
<pre><code>In [99]: timeit map(int,new_subjects)
100000 loops, best of 3: 7.81 µs per loop
... | 3 | 2010-01-28T14:55:38Z | [
"python",
"django"
] |
python dictionary question | 2,155,246 | <p>All,</p>
<p>This is the request from the template that i get</p>
<pre><code>u'subjects': [u'7', u'4', u'5', u'3', u'2', u'1']
</code></pre>
<p>In my views how to extract the values like <code>7 4 5 3 2 1</code></p>
<p>How do i extract the above sequence from </p>
<pre><code>new_subjects=request.POST.get('subjec... | 0 | 2010-01-28T14:42:51Z | 2,155,486 | <p><code>request.POST</code> is an instance of <a href="http://docs.djangoproject.com/en/1.1/ref/request-response/#querydict-objects" rel="nofollow">QueryDict</a> which have a method named <a href="http://docs.djangoproject.com/en/1.1/ref/request-response/#django.http.QueryDict.getlist" rel="nofollow">getlist</a> that ... | 4 | 2010-01-28T15:12:14Z | [
"python",
"django"
] |
How to launch winpdb from a Python script? | 2,155,375 | <p>When I have to deal with bugs in Python code, I often insert breakpoints so during execution I'm being dropped into the debuger when a breakpoint is reached. I've been mostly using pdb (command line) and pudb (ncurses interface).</p>
<p>Is it possible to launch winpdb instead in such situation? What's the breakpoin... | 5 | 2010-01-28T14:59:22Z | 2,155,912 | <p>Winpdb is normally used so that you run the script with winpdb:</p>
<pre><code> winpdb myscript.py
</code></pre>
<p>If you want to start it from "inside" python instead, the documentation on how to do that is here: <a href="http://winpdb.org/docs/embedded-debugging/" rel="nofollow">http://winpdb.org/docs/embedded-... | 4 | 2010-01-28T16:06:39Z | [
"python",
"debugging"
] |
Use getControl to control objects other than the name variable | 2,155,403 | <p>I am using the Zope testbrowser which has been recommended in my last question. The problem that I am facing is that I can use the getControl function to control different objects like: password, username etc.</p>
<p>I am trying to submit the page to get to the next page but the submit button has no 'name' variable... | 1 | 2010-01-28T15:01:59Z | 2,157,193 | <p>I assume that, for one reason or another, you can't add a 'name' attribute to your tag, but if it's only a 'name' that you can't add, you can explicitly set a 'value=Submit' (instead of relying on the default one, which is Submit) and then use browser.getControl('Submit')</p>
<p>Failing that, you can do something ... | 0 | 2010-01-28T19:11:31Z | [
"python",
"testing",
"https",
"mechanize",
"zope"
] |
Basics of string based protocol security | 2,155,509 | <p>I wasn't sure how to phrase this question, so apologies in advance if it's a duplicate of something else.</p>
<p>I wanted to sanity check how I've secured my twisted based application and think I've done a good job at it, but it's been over a decade since I've written anything that uses raw or managed sockets.</p>
... | 5 | 2010-01-28T15:14:47Z | 2,155,815 | <p>Your authentication seems solid but prone to <a href="http://en.wikipedia.org/wiki/Man-in-the-middle_attack" rel="nofollow">man in the middle attacks</a> as it does not ensure the integrity of the connection to the server.</p>
<p>I'd suggest to implement the <a href="http://en.wikipedia.org/wiki/Secure_remote_passw... | 1 | 2010-01-28T15:54:50Z | [
"python",
"networking",
"encryption",
"cryptography",
"twisted"
] |
Basics of string based protocol security | 2,155,509 | <p>I wasn't sure how to phrase this question, so apologies in advance if it's a duplicate of something else.</p>
<p>I wanted to sanity check how I've secured my twisted based application and think I've done a good job at it, but it's been over a decade since I've written anything that uses raw or managed sockets.</p>
... | 5 | 2010-01-28T15:14:47Z | 2,155,905 | <p>The protocol you described addresses one attack, that is the a replay attack. However, you are very vulnerable to MITM attacks. The TCP connection won't drop when the attacker moves in on the protocol. Further more anything transferred over this system can be sniffed. If you are on the wireless at a cafe everyo... | 6 | 2010-01-28T16:05:58Z | [
"python",
"networking",
"encryption",
"cryptography",
"twisted"
] |
Is AMQP production ready? | 2,155,759 | <p>I'd like to use AMQP to join two services one written in C# and other written in python.
I'm expecting quite large volume of messages per second. </p>
<ul>
<li>Is there any AMQP Broker that is production ready?</li>
<li>Are the python & .net bindings good enough?</li>
</ul>
| 10 | 2010-01-28T15:46:06Z | 2,155,805 | <p>Yes: <a href="http://www.rabbitmq.com/">RabbitMQ</a></p>
| 12 | 2010-01-28T15:53:13Z | [
".net",
"python",
"rabbitmq",
"amqp"
] |
Is AMQP production ready? | 2,155,759 | <p>I'd like to use AMQP to join two services one written in C# and other written in python.
I'm expecting quite large volume of messages per second. </p>
<ul>
<li>Is there any AMQP Broker that is production ready?</li>
<li>Are the python & .net bindings good enough?</li>
</ul>
| 10 | 2010-01-28T15:46:06Z | 4,276,595 | <p>It seams that reddit said that rabbitMQ isn't ready as of may 2010.
<a href="http://blog.reddit.com/2010/05/reddits-may-2010-state-of-servers.html" rel="nofollow">http://blog.reddit.com/2010/05/reddits-may-2010-state-of-servers.html</a></p>
<p>On the other hand the article is about rabbitMQ < 2.0 which was crash... | 3 | 2010-11-25T11:36:57Z | [
".net",
"python",
"rabbitmq",
"amqp"
] |
Is AMQP production ready? | 2,155,759 | <p>I'd like to use AMQP to join two services one written in C# and other written in python.
I'm expecting quite large volume of messages per second. </p>
<ul>
<li>Is there any AMQP Broker that is production ready?</li>
<li>Are the python & .net bindings good enough?</li>
</ul>
| 10 | 2010-01-28T15:46:06Z | 29,035,471 | <p>I would recommend <strong>robomq.io</strong>. It is built on RabbitMQ core and has more extensions, e.g. messaging dashboard, realtime analytics, data-driven alerts, big data storage... </p>
<p>If you like high throughput, the record of <strong>robomq.io</strong> is 170 billion messages per day. </p>
<p>I'm not ... | 0 | 2015-03-13T14:58:30Z | [
".net",
"python",
"rabbitmq",
"amqp"
] |
Passing multiple arguments to C function within Python | 2,155,808 | <p>Let's say I have a c library that manipulates a world somehow.</p>
<p>I want to use this library with python. I want to be able to write simple python scripts that represent different scenarios of world management.</p>
<p>I have functions that create and destroy a world:
void* create(void);
int destroy(void* world... | 1 | 2010-01-28T15:53:53Z | 2,155,963 | <p>When you do:</p>
<pre><code>def create_world():
return _create
</code></pre>
<p>You don't call <code>_create</code>, so <code>create_world</code> returns the function pointer. If you want the pointer to your world instance you should write instead:</p>
<pre><code>def create_world():
return _create()
</cod... | 1 | 2010-01-28T16:13:23Z | [
"python",
"arguments",
"ctypes"
] |
Mac 10.6 Universal Binary scipy: cephes/specfun "_aswfa_" symbol not found | 2,155,986 | <p>I can't get scipy to function in 32 bit mode when compiled as a i386/x86_64 universal binary, and executed on my 64 bit 10.6.2 MacPro1,1.</p>
<h3>My python setup</h3>
<p>With the help of <a href="http://stackoverflow.com/questions/1654837/run-an-os-x-universal-binary-in-32-bit-mode/1654855#1654855">this answer</a>... | 6 | 2010-01-28T16:16:33Z | 2,182,515 | <p>How did you install scipy, for which python version, and with which fortran compiler ?</p>
<p>You may also want to check that the missing symbol is indeed in both archs (I don't remember off-hand where the function is, but you should be able to find ti by yourself pretty easily using a combination of nm/otool).</p>... | 1 | 2010-02-02T07:43:23Z | [
"python",
"architecture",
"osx-snow-leopard",
"scipy",
"universal-binary"
] |
Mac 10.6 Universal Binary scipy: cephes/specfun "_aswfa_" symbol not found | 2,155,986 | <p>I can't get scipy to function in 32 bit mode when compiled as a i386/x86_64 universal binary, and executed on my 64 bit 10.6.2 MacPro1,1.</p>
<h3>My python setup</h3>
<p>With the help of <a href="http://stackoverflow.com/questions/1654837/run-an-os-x-universal-binary-in-32-bit-mode/1654855#1654855">this answer</a>... | 6 | 2010-01-28T16:16:33Z | 2,213,391 | <p>Have you tried using scipy compiled using macports?</p>
<pre><code>sudo port install scipy +universal
</code></pre>
<p>(of course you must have the rest of the chain, <code>python</code>, <code>py26-numpy</code>compiled with the same option)</p>
<p>I get:</p>
<pre><code>$ arch -x86_64 /opt/local/bin/python -c "i... | 3 | 2010-02-06T14:22:44Z | [
"python",
"architecture",
"osx-snow-leopard",
"scipy",
"universal-binary"
] |
Python: Need to replace a series of different substrings in HTML template with additional HTML or database results | 2,156,045 | <h2>Situation:</h2>
<p>I am writing a basic templating system in Python/mod_python that reads in a main HTML template and replaces instances of ":value:" throughout the document with additional HTML or db results and then returns it as a view to the user. </p>
<p>I am not trying to replace all instances of 1 substri... | 1 | 2010-01-28T16:24:25Z | 2,156,092 | <p>There are dozens of templating options that already exist. Consider <a href="http://genshi.edgewall.org/" rel="nofollow">genshi</a>, <a href="http://www.makotemplates.org/" rel="nofollow">mako</a>, <a href="http://jinja.pocoo.org/2/" rel="nofollow">jinja2</a>, <a href="http://www.djangoproject.com/documentation/0.96... | 4 | 2010-01-28T16:30:14Z | [
"python",
"replace",
"mod-python",
"templating",
"substrings"
] |
Python: Need to replace a series of different substrings in HTML template with additional HTML or database results | 2,156,045 | <h2>Situation:</h2>
<p>I am writing a basic templating system in Python/mod_python that reads in a main HTML template and replaces instances of ":value:" throughout the document with additional HTML or db results and then returns it as a view to the user. </p>
<p>I am not trying to replace all instances of 1 substri... | 1 | 2010-01-28T16:24:25Z | 2,156,138 | <p>If you can't use an existing templating system for whatever reason, your problem seems best tackled with regular expressions:</p>
<pre><code>import re
valre = re.compile(r':\w+:')
def dosub(correspvals, correspfuns, lastditch):
def f(value):
v = value.group()[1:-1]
if v in correspvals:
return corr... | 1 | 2010-01-28T16:36:07Z | [
"python",
"replace",
"mod-python",
"templating",
"substrings"
] |
Python: Need to replace a series of different substrings in HTML template with additional HTML or database results | 2,156,045 | <h2>Situation:</h2>
<p>I am writing a basic templating system in Python/mod_python that reads in a main HTML template and replaces instances of ":value:" throughout the document with additional HTML or db results and then returns it as a view to the user. </p>
<p>I am not trying to replace all instances of 1 substri... | 1 | 2010-01-28T16:24:25Z | 2,156,560 | <p>This is probably a job for a templating engine and for Python there are a number of <a href="http://wiki.python.org/moin/Templating" rel="nofollow">choices</a>. In this stackoveflow question people have listed their favourites and some helpfully explain why: <a href="http://stackoverflow.com/questions/98245/what-is-... | 1 | 2010-01-28T17:36:06Z | [
"python",
"replace",
"mod-python",
"templating",
"substrings"
] |
Django thumbnails from urls | 2,156,553 | <p>I have this <a href="http://wpthemes1.wordpress.com/" rel="nofollow">Wordpress.com site</a> with thumbnails of themes. I thought about creating a similar site with Django. Instead of using the thumbnail images from the Wordpress gallery as in the page above, I want to have thumbnails of actual blogs. Is there a way ... | 0 | 2010-01-28T17:34:54Z | 2,156,857 | <p>There's nothing django-related here, consider this question
<a href="http://stackoverflow.com/questions/1197172/how-to-get-a-website-screenshot-in-python">http://stackoverflow.com/questions/1197172/how-to-get-a-website-screenshot-in-python</a></p>
| 2 | 2010-01-28T18:23:08Z | [
"python",
"thumbnails"
] |
Django Haystack exact filtering | 2,156,559 | <p>I have a haystack search which has the following SearchIndex:</p>
<pre>
class GrantIndex(indexes.SearchIndex):
"""
This provides the search index for the Grant application.
"""
text = indexes.CharField(document=True, use_template=True)
year = indexes.IntegerField(model_attr='year__year')
dat... | 5 | 2010-01-28T17:35:54Z | 2,156,838 | <p>you can use field lookups as described <a href="http://haystacksearch.org/docs/searchqueryset_api.html#id1" rel="nofollow">here</a>.</p>
<pre><code>sqs = sqs.filter(program__exact='Health')
</code></pre>
| 0 | 2010-01-28T18:21:20Z | [
"python",
"django",
"xapian",
"django-haystack"
] |
Django Haystack exact filtering | 2,156,559 | <p>I have a haystack search which has the following SearchIndex:</p>
<pre>
class GrantIndex(indexes.SearchIndex):
"""
This provides the search index for the Grant application.
"""
text = indexes.CharField(document=True, use_template=True)
year = indexes.IntegerField(model_attr='year__year')
dat... | 5 | 2010-01-28T17:35:54Z | 2,990,433 | <p>You've problably solved the problem already, but I just stumbled over the same problem with the Whoosh backend. Maybe the Xapian and Whoosh backends behave the same? Seems Whoosh is stemming all CharFields by default, and searching inside them with some kind of contains-query. Switching to a custom backend, without ... | 3 | 2010-06-07T14:38:29Z | [
"python",
"django",
"xapian",
"django-haystack"
] |
Django Haystack exact filtering | 2,156,559 | <p>I have a haystack search which has the following SearchIndex:</p>
<pre>
class GrantIndex(indexes.SearchIndex):
"""
This provides the search index for the Grant application.
"""
text = indexes.CharField(document=True, use_template=True)
year = indexes.IntegerField(model_attr='year__year')
dat... | 5 | 2010-01-28T17:35:54Z | 8,370,572 | <p>use "prepare_data" for program field and get rid of health\blabla things</p>
| 0 | 2011-12-03T20:02:54Z | [
"python",
"django",
"xapian",
"django-haystack"
] |
Django Haystack exact filtering | 2,156,559 | <p>I have a haystack search which has the following SearchIndex:</p>
<pre>
class GrantIndex(indexes.SearchIndex):
"""
This provides the search index for the Grant application.
"""
text = indexes.CharField(document=True, use_template=True)
year = indexes.IntegerField(model_attr='year__year')
dat... | 5 | 2010-01-28T17:35:54Z | 18,338,048 | <p>For solr backend I need to use <code>_exact</code> (just one underline instead of two).</p>
| 0 | 2013-08-20T14:45:08Z | [
"python",
"django",
"xapian",
"django-haystack"
] |
Django Haystack exact filtering | 2,156,559 | <p>I have a haystack search which has the following SearchIndex:</p>
<pre>
class GrantIndex(indexes.SearchIndex):
"""
This provides the search index for the Grant application.
"""
text = indexes.CharField(document=True, use_template=True)
year = indexes.IntegerField(model_attr='year__year')
dat... | 5 | 2010-01-28T17:35:54Z | 23,825,327 | <p>Disclaimer: I'm the maintainer of Xapian-Haystack.</p>
<p>I believe this happens because Xapian-Haystack was using a term generator that was escaping special characters like <code>/</code>.</p>
<p>So, in your case, <code>"Health\Other"</code> was being indexed as <code>"health"</code> and <code>"other"</code>. Thi... | 0 | 2014-05-23T09:15:59Z | [
"python",
"django",
"xapian",
"django-haystack"
] |
How to create a django model field that has a default value if ever set to null | 2,156,585 | <p>Given a model</p>
<pre><code>class Template(models.Model):
colour = models.CharField(default="red", blank = True, null=True)
</code></pre>
<p>How can I arrange it so that any access to colour either returns the value stored in the field, or if the field is blank/null then it returns red?</p>
<p>The <pre>defau... | 1 | 2010-01-28T17:40:06Z | 2,156,738 | <p>Use the <code>save</code> method to implement this.</p>
<pre><code>def save( self, *args, **kw ):
if self.colour is None:
self.colour= 'red'
super( ThisModel, self ).save( *args, **kw )
</code></pre>
| 1 | 2010-01-28T18:04:59Z | [
"python",
"django",
"django-models"
] |
How to create a django model field that has a default value if ever set to null | 2,156,585 | <p>Given a model</p>
<pre><code>class Template(models.Model):
colour = models.CharField(default="red", blank = True, null=True)
</code></pre>
<p>How can I arrange it so that any access to colour either returns the value stored in the field, or if the field is blank/null then it returns red?</p>
<p>The <pre>defau... | 1 | 2010-01-28T17:40:06Z | 2,157,059 | <p>You can create a separate method instead:</p>
<pre><code>def get_colour(self):
if not self.colour:
return 'red'
else:
return self.colour
</code></pre>
<p>An alternative is to use property.</p>
<p><a href="http://www.djangoproject.com/documentation/models/properties/" rel="nofollow">http://... | 4 | 2010-01-28T18:51:19Z | [
"python",
"django",
"django-models"
] |
How to create a django model field that has a default value if ever set to null | 2,156,585 | <p>Given a model</p>
<pre><code>class Template(models.Model):
colour = models.CharField(default="red", blank = True, null=True)
</code></pre>
<p>How can I arrange it so that any access to colour either returns the value stored in the field, or if the field is blank/null then it returns red?</p>
<p>The <pre>defau... | 1 | 2010-01-28T17:40:06Z | 2,158,272 | <p>Here's how I ended up solving this problem.</p>
<p>First some preconditions: I have existing code that accesses these field names (e.g. 'colour') and the field is also serialised (by django-rest-interface) as part of an API. Neither of these things can be changed.</p>
<p>Trying the properties method worked fine, ... | 0 | 2010-01-28T21:55:53Z | [
"python",
"django",
"django-models"
] |
exe generated with py2exe can't find pywinauto | 2,156,875 | <p>I've been trying to pack my app with py2exe. The application works fine but it keeps failing to find/use pywinauto. I been googling but I get nothing, I'm now I'm totally lost...</p>
<p>Here's the packing script:</p>
<pre>
from distutils.core import setup
setup(
windows = ["mainForm.py"],
data_files=[
... | 1 | 2010-01-28T18:25:48Z | 2,157,563 | <p>From my experience, py2exe handles imports in a weird way. Sometimes it has trouble finding linked-imports (like you import <code>WindowHandler</code>, which imports <code>pywinauto</code>).</p>
<p>I would start with this in <strong>mainForm.py</strong>:</p>
<pre><code>import sys
import WordOps
import Voice
imp... | 1 | 2010-01-28T20:02:39Z | [
"python",
"py2exe"
] |
Python: How can I increment a char? | 2,156,892 | <p>I'm new to Python, coming from Java and C. How can I increment a char? In Java or C, chars and ints are practically interchangeable, and in certain loops, it's very useful to me to be able to do increment chars, and index arrays by chars. </p>
<p>How can I do this in Python? It's bad enough not having a traditional... | 50 | 2010-01-28T18:28:20Z | 2,156,898 | <p>In Python 2.x, just use the <code>ord</code> and <code>chr</code> functions:</p>
<pre><code>>>> ord('c')
99
>>> ord('c') + 1
100
>>> chr(ord('c') + 1)
'd'
>>>
</code></pre>
<p>Python 3.x makes this more organized and interesting, due to its clear distinction between bytes and u... | 98 | 2010-01-28T18:28:50Z | [
"python",
"char",
"increment"
] |
Python: How can I increment a char? | 2,156,892 | <p>I'm new to Python, coming from Java and C. How can I increment a char? In Java or C, chars and ints are practically interchangeable, and in certain loops, it's very useful to me to be able to do increment chars, and index arrays by chars. </p>
<p>How can I do this in Python? It's bad enough not having a traditional... | 50 | 2010-01-28T18:28:20Z | 2,156,970 | <p>"bad enough not having a traditional for(;;) looper"?? What? </p>
<p>Are you trying to do </p>
<pre><code>import string
for c in string.lowercase:
...do something with c...
</code></pre>
<p>Or perhaps you're using <code>string.uppercase</code> or <code>string.letters</code>?</p>
<p>Python doesn't have <cod... | 11 | 2010-01-28T18:38:50Z | [
"python",
"char",
"increment"
] |
Python: Accessing an attribute using a variable | 2,157,035 | <p>How do I reference <code>this_prize.left</code> or <code>this_prize.right</code> using a variable?</p>
<pre><code>from collections import namedtuple
import random
Prize = namedtuple("Prize", ["left", "right"])
this_prize = Prize("FirstPrize", "SecondPrize")
if random.random() > .5:
choice = "left"
else... | 21 | 2010-01-28T18:47:40Z | 2,157,049 | <pre><code>getattr(this_prize,choice)
</code></pre>
<p><a href="http://docs.python.org/library/functions.html#getattr">http://docs.python.org/library/functions.html#getattr</a></p>
| 38 | 2010-01-28T18:49:38Z | [
"python"
] |
Python: Accessing an attribute using a variable | 2,157,035 | <p>How do I reference <code>this_prize.left</code> or <code>this_prize.right</code> using a variable?</p>
<pre><code>from collections import namedtuple
import random
Prize = namedtuple("Prize", ["left", "right"])
this_prize = Prize("FirstPrize", "SecondPrize")
if random.random() > .5:
choice = "left"
else... | 21 | 2010-01-28T18:47:40Z | 2,157,125 | <p>The expression <code>this_prize.choice</code> is telling the interpreter that you want to access an attribute of this_prize with the name "choice". But this attribute does not exist in this_prize.</p>
<p>What you actually want is to return the attribute of this_prize identified by the <strong><em>value</em></stron... | 35 | 2010-01-28T19:01:14Z | [
"python"
] |
Calling An Inherited Class Method From Java | 2,157,159 | <p>In Python, class methods can be inherited. e.g.</p>
<pre><code>>>> class A:
... @classmethod
... def main(cls):
... return cls()
...
>>> class B(A): pass
...
>>> b=B.main()
>>> b
<__main__.B instance at 0x00A6FA58>
</code></pre>
<p>How would you do the equivalent in Ja... | 1 | 2010-01-28T19:06:43Z | 2,157,271 | <p>I think this isn't possible. Here's why:</p>
<p>In Java, the implementation of a method is determined by the instance's run-time type. So, to execute <code>B.show()</code>, you need to have an instance of <code>B</code>. The only way I could see to do this, if the method that constructs the instance is supposed ... | 0 | 2010-01-28T19:20:33Z | [
"java",
"python",
"inheritance",
"class-method"
] |
Calling An Inherited Class Method From Java | 2,157,159 | <p>In Python, class methods can be inherited. e.g.</p>
<pre><code>>>> class A:
... @classmethod
... def main(cls):
... return cls()
...
>>> class B(A): pass
...
>>> b=B.main()
>>> b
<__main__.B instance at 0x00A6FA58>
</code></pre>
<p>How would you do the equivalent in Ja... | 1 | 2010-01-28T19:06:43Z | 2,157,300 | <p>In your example I wouldn't put your main method inside of A. This is setup as the entry point into the system (you can't be in B if you are specifically entering into A).</p>
<p>In the example below I created class A, B, and C. Class C instantiates A and B and runs them. Notice that in C I created an A, a B, and... | 0 | 2010-01-28T19:23:32Z | [
"java",
"python",
"inheritance",
"class-method"
] |
Calling An Inherited Class Method From Java | 2,157,159 | <p>In Python, class methods can be inherited. e.g.</p>
<pre><code>>>> class A:
... @classmethod
... def main(cls):
... return cls()
...
>>> class B(A): pass
...
>>> b=B.main()
>>> b
<__main__.B instance at 0x00A6FA58>
</code></pre>
<p>How would you do the equivalent in Ja... | 1 | 2010-01-28T19:06:43Z | 2,157,335 | <p>Your class <code>B</code> does not have a <code>main</code> method and static methods are <strong>not</strong> inherited.</p>
| 1 | 2010-01-28T19:28:29Z | [
"java",
"python",
"inheritance",
"class-method"
] |
Calling An Inherited Class Method From Java | 2,157,159 | <p>In Python, class methods can be inherited. e.g.</p>
<pre><code>>>> class A:
... @classmethod
... def main(cls):
... return cls()
...
>>> class B(A): pass
...
>>> b=B.main()
>>> b
<__main__.B instance at 0x00A6FA58>
</code></pre>
<p>How would you do the equivalent in Ja... | 1 | 2010-01-28T19:06:43Z | 2,157,358 | <p>The only way I can see this happening is to find whatever is calling <code>A.main( String[] arg )</code> and change it to call <code>B.main</code> instead.</p>
<p>B.main:</p>
<pre><code> public static void main( String[] arg ) {
new B().run();
}
</code></pre>
<p>How is your program started? Is there... | 1 | 2010-01-28T19:31:08Z | [
"java",
"python",
"inheritance",
"class-method"
] |
Calling An Inherited Class Method From Java | 2,157,159 | <p>In Python, class methods can be inherited. e.g.</p>
<pre><code>>>> class A:
... @classmethod
... def main(cls):
... return cls()
...
>>> class B(A): pass
...
>>> b=B.main()
>>> b
<__main__.B instance at 0x00A6FA58>
</code></pre>
<p>How would you do the equivalent in Ja... | 1 | 2010-01-28T19:06:43Z | 2,157,464 | <p>Static methods in java are not <code>classmethod</code>s they are <code>staticmethod</code>s. In general it is not possible to know which class reference the static method was called from.</p>
| 1 | 2010-01-28T19:48:20Z | [
"java",
"python",
"inheritance",
"class-method"
] |
Python GIL and globals | 2,157,208 | <p>In python, I have a global variable defined that gets read/incremented by different threads. Because of the GIL, will this ever cause problems without using any kind of locking mechanism?</p>
| 4 | 2010-01-28T19:13:13Z | 2,157,256 | <p>Yes, multithreading without locking almost always causes problems, with or without a GIL.</p>
| 3 | 2010-01-28T19:19:22Z | [
"python",
"gil"
] |
Python GIL and globals | 2,157,208 | <p>In python, I have a global variable defined that gets read/incremented by different threads. Because of the GIL, will this ever cause problems without using any kind of locking mechanism?</p>
| 4 | 2010-01-28T19:13:13Z | 2,157,415 | <p>The GIL only requires that the interpreter completely executes a single bytecode instruction before another thread can take over. However, there is no reason to assume that an increment operation is a single instruction. For example:</p>
<pre><code>>>> import dis
>>> dis.dis(compile("x=753","","ex... | 6 | 2010-01-28T19:40:46Z | [
"python",
"gil"
] |
In ASP - Why is it that I can call python functions from vbscript but not vice-versa? | 2,157,241 | <p>I'm planning on writting some new code for a legacy ASP application in Python, and I ran into some odd behavior. If I write a function in python I can easily call it from a VBScript block. However, if I try to call a function defined in VBScript from python, I get an error:</p>
<pre><code>Python ActiveX Scripting... | 2 | 2010-01-28T19:17:04Z | 2,157,758 | <p>It probably has to do with the <a href="http://msdn.microsoft.com/en-us/library/aa260861%28VS.60%29.aspx#vbnjscrpt_servscript" rel="nofollow">order in which the script tags are processed</a>.</p>
<p>In this case, it seems that the script tags containing python code are processed first, and then the ones with vbscri... | 3 | 2010-01-28T20:35:25Z | [
"python",
"vbscript",
"asp-classic"
] |
In ASP - Why is it that I can call python functions from vbscript but not vice-versa? | 2,157,241 | <p>I'm planning on writting some new code for a legacy ASP application in Python, and I ran into some odd behavior. If I write a function in python I can easily call it from a VBScript block. However, if I try to call a function defined in VBScript from python, I get an error:</p>
<pre><code>Python ActiveX Scripting... | 2 | 2010-01-28T19:17:04Z | 4,894,047 | <p>I'm doing the same thing. I seem to be having success by registering a callback with Python (i.e. explicitly telling Python about the function). The trick is that VBScript must call into Python for Python to be able to call back out into VBScript.</p>
<pre><code><%@LANGUAGE="VBSCRIPT"%>
<script language="P... | 1 | 2011-02-04T02:42:41Z | [
"python",
"vbscript",
"asp-classic"
] |
Change the color of a node or an edge | 2,157,530 | <p>I want to redraw a Graph g with only the color of a node or edge changed.
How do I do that?</p>
| 0 | 2010-01-28T19:58:26Z | 2,157,985 | <p>Your version of networkx is too old.</p>
<p>try</p>
<pre><code>$ easy_install networkx
</code></pre>
<p>to get the current version</p>
| 1 | 2010-01-28T21:11:50Z | [
"python",
"networkx"
] |
Python code for determining which normal form tabular data is in | 2,157,531 | <p>I'm looking for Python code that can take tabular data and establish which normal form(s) it is in (if any) and show any functional dependencies, etc.</p>
| 2 | 2010-01-28T19:58:44Z | 2,157,695 | <p>I think that this code will be really hard to implement.</p>
<p>Look at <a href="http://stackoverflow.com/questions/542866/database-schema-normalization-checker">this question</a> about normalization algorithms of databases.</p>
| 0 | 2010-01-28T20:24:57Z | [
"python",
"normalization",
"relational-algebra",
"database-normalization"
] |
Python code for determining which normal form tabular data is in | 2,157,531 | <p>I'm looking for Python code that can take tabular data and establish which normal form(s) it is in (if any) and show any functional dependencies, etc.</p>
| 2 | 2010-01-28T19:58:44Z | 2,158,174 | <p>There are logical tests for "normalization". However, they're not trivial exercises in programming; they're relationships in the metadata that are imposed on the data. They require "thinking".</p>
<p>1NF -- no repeating groups. How does one identify a "repeating group"? It would be an array structure imposed on... | 2 | 2010-01-28T21:39:05Z | [
"python",
"normalization",
"relational-algebra",
"database-normalization"
] |
Python code for determining which normal form tabular data is in | 2,157,531 | <p>I'm looking for Python code that can take tabular data and establish which normal form(s) it is in (if any) and show any functional dependencies, etc.</p>
| 2 | 2010-01-28T19:58:44Z | 4,699,477 | <p>Not python code, but at first glance this article looks useful.</p>
<p><a href="http://profdoc.um.ac.ir/articles/a/1007113.pdf" rel="nofollow">Automatic Database Normalization and Primary Key Generation</a></p>
| 0 | 2011-01-15T12:02:21Z | [
"python",
"normalization",
"relational-algebra",
"database-normalization"
] |
Python: Using namedtuple._replace with a variable as a fieldname | 2,157,561 | <p>Can I reference a namedtuple fieldame using a variable?</p>
<pre><code>from collections import namedtuple
import random
Prize = namedtuple("Prize", ["left", "right"])
this_prize = Prize("FirstPrize", "SecondPrize")
if random.random() > .5:
choice = "left"
else:
choice = "right"
#retrieve the value ... | 7 | 2010-01-28T20:02:00Z | 2,157,650 | <pre><code>>>> choice = 'left'
>>> this_prize._replace(**{choice: 'Yay'}) # you need to assign this to this_prize if you want
Prize(left='Yay', right='SecondPrize')
>>> this_prize
Prize(left='FirstPrize', right='SecondPrize') # doesn't modify this_prize in place
</code></pre>
| 2 | 2010-01-28T20:18:23Z | [
"python",
"namedtuple"
] |
Python: Using namedtuple._replace with a variable as a fieldname | 2,157,561 | <p>Can I reference a namedtuple fieldame using a variable?</p>
<pre><code>from collections import namedtuple
import random
Prize = namedtuple("Prize", ["left", "right"])
this_prize = Prize("FirstPrize", "SecondPrize")
if random.random() > .5:
choice = "left"
else:
choice = "right"
#retrieve the value ... | 7 | 2010-01-28T20:02:00Z | 2,157,742 | <p>Tuples are immutable, and so are NamedTuples. They are not supposed to be changed!</p>
<p><code>this_prize._replace(choice = "Yay")</code> calls <code>_replace</code> with the keyword argument <code>"choice"</code>. It doesn't use <code>choice</code> as a variable and tries to replace a field by the name of <code>... | 14 | 2010-01-28T20:32:48Z | [
"python",
"namedtuple"
] |
How do I access a python list from a django templatetag? | 2,157,665 | <p>I have created a templatetag that loads a yaml document into a python list. In my template I have <code>{% get_content_set %}</code>, this dumps the raw list data. What I want to be able to do is something like </p>
<pre><code>{% for items in get_content_list %}
<h2>{{items.title}}</h2>
{% en... | 1 | 2010-01-28T20:20:37Z | 2,157,699 | <p>If the list is in a python variable X, then add it to the template context <code>context['X'] = X</code> and then you can do</p>
<pre><code>{% for items in X %}
{{ items.title }}
{% endfor %}
</code></pre>
<p>A template tag is designed to render output, so won't provide an iterable list for you to use. But... | 3 | 2010-01-28T20:25:34Z | [
"python",
"django",
"templates",
"django-templates",
"yaml"
] |
How do I access a python list from a django templatetag? | 2,157,665 | <p>I have created a templatetag that loads a yaml document into a python list. In my template I have <code>{% get_content_set %}</code>, this dumps the raw list data. What I want to be able to do is something like </p>
<pre><code>{% for items in get_content_list %}
<h2>{{items.title}}</h2>
{% en... | 1 | 2010-01-28T20:20:37Z | 2,158,490 | <p>Since writing complex templatetags is not an easy task (well documented though) i would take {% with %} tag source and adapt it for my needs, so it looks like </p>
<pre><code>{% get_content_list as content %
{% for items in content %}
<h2>{{items.title}}</h2>
{% endfor %}`
</code></pre>
| -1 | 2010-01-28T22:30:02Z | [
"python",
"django",
"templates",
"django-templates",
"yaml"
] |
How do I build an WSGI apps built with CherryPyWSGIServer that support both HTTP and HTTPS? | 2,157,708 | <p>I built a WSGI app and created a standalone wrapper using CherryPyWSGIServer. I see that CherryPyWSGIServer supports HTTPS but I am not sure how to support both HTTP and HTTPS <em>together</em> as it looks like the first <code>server.start()</code> blocks. How would I create two servers, one HTTP and one HTTPS, and ... | 2 | 2010-01-28T20:26:45Z | 2,157,871 | <p>Whenever I have done this in the past, I have used Apache or Nginx in front of the webserver, and let those handle the https.</p>
| 2 | 2010-01-28T20:55:05Z | [
"python",
"wsgi",
"cherrypy"
] |
How do I build an WSGI apps built with CherryPyWSGIServer that support both HTTP and HTTPS? | 2,157,708 | <p>I built a WSGI app and created a standalone wrapper using CherryPyWSGIServer. I see that CherryPyWSGIServer supports HTTPS but I am not sure how to support both HTTP and HTTPS <em>together</em> as it looks like the first <code>server.start()</code> blocks. How would I create two servers, one HTTP and one HTTPS, and ... | 2 | 2010-01-28T20:26:45Z | 8,210,479 | <p>Use a batch file to run your normal HTTP server on port 80 and a separate HTTPS instance on port 443.</p>
| 0 | 2011-11-21T10:40:07Z | [
"python",
"wsgi",
"cherrypy"
] |
How do I build an WSGI apps built with CherryPyWSGIServer that support both HTTP and HTTPS? | 2,157,708 | <p>I built a WSGI app and created a standalone wrapper using CherryPyWSGIServer. I see that CherryPyWSGIServer supports HTTPS but I am not sure how to support both HTTP and HTTPS <em>together</em> as it looks like the first <code>server.start()</code> blocks. How would I create two servers, one HTTP and one HTTPS, and ... | 2 | 2010-01-28T20:26:45Z | 8,900,257 | <p>Maybe this helps:
<a href="http://docs.cherrypy.org/stable/refman/process/servers.html#multiple-servers-ports" rel="nofollow">http://docs.cherrypy.org/stable/refman/process/servers.html#multiple-servers-ports</a></p>
| 0 | 2012-01-17T19:09:02Z | [
"python",
"wsgi",
"cherrypy"
] |
Python regex split, integer of arbitrary length | 2,157,894 | <p>I'm trying to do a simple regex split in Python. The string is in the form of FooX where Foo is some string and X is an arbitrary integer. I have a feeling this should be really simple, but I can't quite get it to work.</p>
<p>On that note, can anyone recommend some good Regex reading materials?</p>
| 3 | 2010-01-28T21:00:28Z | 2,157,923 | <p>Assuming you want to split between the "Foo" and the number, you'd want something like:</p>
<pre><code>r/(?<=\D)(?=\d)/
</code></pre>
<p>Which will match at a point between a nondigit and a digit, without consuming any characters in the split.</p>
| 0 | 2010-01-28T21:03:52Z | [
"python",
"regex"
] |
Python regex split, integer of arbitrary length | 2,157,894 | <p>I'm trying to do a simple regex split in Python. The string is in the form of FooX where Foo is some string and X is an arbitrary integer. I have a feeling this should be really simple, but I can't quite get it to work.</p>
<p>On that note, can anyone recommend some good Regex reading materials?</p>
| 3 | 2010-01-28T21:00:28Z | 2,157,949 | <p>Using groups:</p>
<pre><code>import re
m=re.match('^(?P<first>[A-Za-z]+)(?P<second>[0-9]+)$',"Foo9")
print m.group('first')
print m.group('second')
</code></pre>
<p>Using search:</p>
<pre><code>import re
s='Foo9'
m=re.search('(?<=\D)(?=\d)',s)
first=s[:m.start()]
second=s[m.end():]
print first, ... | 1 | 2010-01-28T21:07:24Z | [
"python",
"regex"
] |
Python regex split, integer of arbitrary length | 2,157,894 | <p>I'm trying to do a simple regex split in Python. The string is in the form of FooX where Foo is some string and X is an arbitrary integer. I have a feeling this should be really simple, but I can't quite get it to work.</p>
<p>On that note, can anyone recommend some good Regex reading materials?</p>
| 3 | 2010-01-28T21:00:28Z | 2,157,982 | <p>You can't use <code>split()</code> since that has to consume some characters, but you can use normal matching to do it.</p>
<pre><code>>>> import re
>>> r = re.compile(r'(\D+)(\d+)')
>>> r.match('abc444').groups()
('abc', '444')
</code></pre>
| 5 | 2010-01-28T21:11:23Z | [
"python",
"regex"
] |
Python regex split, integer of arbitrary length | 2,157,894 | <p>I'm trying to do a simple regex split in Python. The string is in the form of FooX where Foo is some string and X is an arbitrary integer. I have a feeling this should be really simple, but I can't quite get it to work.</p>
<p>On that note, can anyone recommend some good Regex reading materials?</p>
| 3 | 2010-01-28T21:00:28Z | 2,158,025 | <pre><code>>>> import re
>>> s="gnibbler1234"
>>> re.findall(r'(\D+)(\d+)',s)[0]
('gnibbler', '1234')
</code></pre>
<p>In the regex, \D means anything that is not a digit, so \D+ matches one or more things that are not digits.</p>
<p>Likewise \d means anything that is a digit, so \d+ matche... | 0 | 2010-01-28T21:19:08Z | [
"python",
"regex"
] |
Python regex split, integer of arbitrary length | 2,157,894 | <p>I'm trying to do a simple regex split in Python. The string is in the form of FooX where Foo is some string and X is an arbitrary integer. I have a feeling this should be really simple, but I can't quite get it to work.</p>
<p>On that note, can anyone recommend some good Regex reading materials?</p>
| 3 | 2010-01-28T21:00:28Z | 2,158,082 | <p>Keeping it simple:</p>
<pre><code>>>> import re
>>> a = "Foo1String12345"
>>> re.split(r'(\d+)$', a)[0:2]
['Foo1String', '12345']
</code></pre>
| 1 | 2010-01-28T21:25:22Z | [
"python",
"regex"
] |
drop into python interpreter while executing function | 2,158,097 | <p>i have a python module with a function:</p>
<pre><code>def do_stuff(param1 = 'a'):
if type(param1) == int:
# enter python interpreter here
do_something()
else:
do_something_else()
</code></pre>
<p>is there a way to drop into the command line interpreter where i have the comment? so... | 51 | 2010-01-28T21:27:44Z | 2,158,119 | <p>Inserting</p>
<pre><code>import pdb; pdb.set_trace()
</code></pre>
<p>will enter the python debugger at that point</p>
<p>See here:
<a href="http://docs.python.org/library/pdb.html">http://docs.python.org/library/pdb.html</a></p>
| 30 | 2010-01-28T21:30:17Z | [
"python"
] |
drop into python interpreter while executing function | 2,158,097 | <p>i have a python module with a function:</p>
<pre><code>def do_stuff(param1 = 'a'):
if type(param1) == int:
# enter python interpreter here
do_something()
else:
do_something_else()
</code></pre>
<p>is there a way to drop into the command line interpreter where i have the comment? so... | 51 | 2010-01-28T21:27:44Z | 2,158,266 | <p>If you want a standard interactive prompt (instead of the debugger, as shown by prestomation), you can do this:</p>
<pre><code>import code
code.interact(local=locals())
</code></pre>
<p>See: the <a href="http://docs.python.org/library/code.html#code.interact">code module</a>.</p>
<p>If you have IPython installed,... | 90 | 2010-01-28T21:53:57Z | [
"python"
] |
drop into python interpreter while executing function | 2,158,097 | <p>i have a python module with a function:</p>
<pre><code>def do_stuff(param1 = 'a'):
if type(param1) == int:
# enter python interpreter here
do_something()
else:
do_something_else()
</code></pre>
<p>is there a way to drop into the command line interpreter where i have the comment? so... | 51 | 2010-01-28T21:27:44Z | 32,960,430 | <p>If you want a default Python interpreter, you can do</p>
<pre><code>import code
code.interact(local=dict(globals(), **locals()))
</code></pre>
<p>This will allow access to both locals and globals.</p>
<p>If you want to drop into an IPython interpreter, the <code>IPShellEmbed</code> solution is <strong>outdated</s... | 11 | 2015-10-06T01:43:55Z | [
"python"
] |
Setting the RGB levels of pixels (Python, Jython) | 2,158,228 | <pre><code> For each pixel in pic:
r= random()
if r < 0.25:
set the red level to randrange(0,256),
set the green level to randrange(0,256)
set the blue level to randrange(0,256)
</code></pre>
<p>The rest of the unseen code is correct, I just can't figure out how to phrase this f... | 1 | 2010-01-28T21:47:48Z | 2,179,872 | <p>I don't know anything about the rest of your code, but it would be something like this:</p>
<pre><code>import random
for pixel in pic.get_pixels(): # Replace with appropiate way of getting the pixels
if random.random() < 0.25:
pixel.red = random.randint(256)
pixel.green = random.randint(256)... | 1 | 2010-02-01T20:36:10Z | [
"python",
"jython"
] |
Setting the RGB levels of pixels (Python, Jython) | 2,158,228 | <pre><code> For each pixel in pic:
r= random()
if r < 0.25:
set the red level to randrange(0,256),
set the green level to randrange(0,256)
set the blue level to randrange(0,256)
</code></pre>
<p>The rest of the unseen code is correct, I just can't figure out how to phrase this f... | 1 | 2010-01-28T21:47:48Z | 2,184,811 | <p>Are you using PIL?</p>
<p>If so one option is to do something like this</p>
<pre><code>
your_image = Image.new("RGB", (512, 512), "white")
for x in xrange(your_image.size[0]):
for y in xrange(your_image.size[1]):
your_image.putpixel((x,y),(random.randint(256), random.randint(256), random.randint(256))
... | 0 | 2010-02-02T14:41:05Z | [
"python",
"jython"
] |
How do I turn a python datetime into a string, with readable format date? | 2,158,347 | <pre><code>t = e['updated_parsed']
dt = datetime.datetime(t[0],t[1],t[2],t[3],t[4],t[5],t[6]
print dt
>>>2010-01-28 08:39:49.000003
</code></pre>
<p>How do I turn that into a string?:</p>
<pre><code>"January 28, 2010"
</code></pre>
| 65 | 2010-01-28T22:08:27Z | 2,158,364 | <p>Read this: <a href="http://docs.python.org/library/datetime.html#datetime.datetime.strftime">http://docs.python.org/library/datetime.html#datetime.datetime.strftime</a></p>
| 5 | 2010-01-28T22:10:13Z | [
"python",
"datetime",
"string-formatting"
] |
How do I turn a python datetime into a string, with readable format date? | 2,158,347 | <pre><code>t = e['updated_parsed']
dt = datetime.datetime(t[0],t[1],t[2],t[3],t[4],t[5],t[6]
print dt
>>>2010-01-28 08:39:49.000003
</code></pre>
<p>How do I turn that into a string?:</p>
<pre><code>"January 28, 2010"
</code></pre>
| 65 | 2010-01-28T22:08:27Z | 2,158,454 | <p>The datetime class has a method strftime. <a href="https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior">strftime() Behavior</a> in the Python docs documents the different formats it accepts. </p>
<p>For this specific example, it would look something like:</p>
<pre><code>my_datetime.strftime(... | 87 | 2010-01-28T22:23:44Z | [
"python",
"datetime",
"string-formatting"
] |
How do I turn a python datetime into a string, with readable format date? | 2,158,347 | <pre><code>t = e['updated_parsed']
dt = datetime.datetime(t[0],t[1],t[2],t[3],t[4],t[5],t[6]
print dt
>>>2010-01-28 08:39:49.000003
</code></pre>
<p>How do I turn that into a string?:</p>
<pre><code>"January 28, 2010"
</code></pre>
| 65 | 2010-01-28T22:08:27Z | 22,842,734 | <p>Here is how you can accomplish the same using python's general formatting function...</p>
<pre><code>>>>from datetime import datetime
>>>"{:%B %d, %Y}".format(datetime.now())
</code></pre>
<p>The formatting characters used here are the same as those used by <a href="https://docs.python.org/3/libr... | 52 | 2014-04-03T15:49:16Z | [
"python",
"datetime",
"string-formatting"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 2,158,522 | <p>My solution:</p>
<pre><code>def flatten(x):
if isinstance(x, collections.Iterable):
return [a for i in x for a in flatten(i)]
else:
return [x]
</code></pre>
<p>A little more concise, but pretty much the same.</p>
| 28 | 2010-01-28T22:34:45Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 2,158,532 | <p>Using generator functions can make your example a little easier to read and probably boost the performance.</p>
<h2>Python 2</h2>
<pre><code>def flatten(l):
for el in l:
if isinstance(el, collections.Iterable) and not isinstance(el, basestring):
for sub in flatten(el):
yield... | 221 | 2010-01-28T22:35:51Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 2,158,562 | <p>This version of <code>flatten</code> avoids python's recursion limit (and thus works with arbitrarily deep, nested iterables). It is a generator which can handle strings and arbitrary iterables (even infinite ones).</p>
<pre><code>import itertools as IT
import collections
def flatten(iterable, ltypes=collections.I... | 17 | 2010-01-28T22:42:07Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 2,159,079 | <p>Generator version of @unutbu's non-recursive solution, as requested by @Andrew in a comment:</p>
<pre><code>def genflat(l, ltypes=collections.Sequence):
l = list(l)
i = 0
while i < len(l):
while isinstance(l[i], ltypes):
if not l[i]:
l.pop(i)
i -= 1... | 29 | 2010-01-29T00:27:22Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 2,170,065 | <p>If you like recursion, this might be a solution of interest to you:</p>
<pre><code>def f(E):
if E==[]:
return []
elif type(E) != list:
return [E]
else:
a = f(E[0])
b = f(E[1:])
a.extend(b)
return a
</code></pre>
<p>I actually adapted this from some prac... | 0 | 2010-01-31T00:19:36Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 4,494,994 | <p>I'm new to python and come from a lisp background. This is what I came up with (check out the var names for lulz):</p>
<pre><code>def flatten(lst):
if lst:
car,*cdr=lst
if isinstance(car,(list,tuple)):
if cdr: return flatten(car) + flatten(cdr)
return flatten(car)
... | 1 | 2010-12-20T23:24:37Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 4,590,652 | <pre><code>def flatten(xs):
res = []
def loop(ys):
for i in ys:
if isinstance(i, list):
loop(i)
else:
res.append(i)
loop(xs)
return res
</code></pre>
| 8 | 2011-01-04T04:29:07Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 4,676,482 | <p>I prefer simple answers. No generators. No recursion or recursion limits. Just iteration:</p>
<pre><code>def flatten(TheList):
listIsNested = True
while listIsNested: #outer loop
keepChecking = False
Temp = []
for element in TheList: #inner loop
... | 3 | 2011-01-13T03:19:39Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 4,694,575 | <p>Here's another answer that is even more interesting...</p>
<pre><code>import re
def Flatten(TheList):
a = str(TheList)
b,crap = re.subn(r'[\[,\]]', ' ', a)
c = b.split()
d = [int(x) for x in c]
return(d)
</code></pre>
<p>Basically, it converts the nested list to a string, uses a regex to stri... | 10 | 2011-01-14T18:31:33Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 5,226,060 | <p>Although an elegant and very pythonic answer has been selected I would present my solution just for the review:</p>
<pre><code>def flat(l):
ret = []
for i in l:
if isinstance(i, list) or isinstance(i, tuple):
ret.extend(flat(i))
else:
ret.append(i)
return ret
</co... | 5 | 2011-03-07T22:32:07Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 5,409,395 | <p>Here is my functional version of recursive flatten which handles both tuples and lists, and lets you throw in any mix of positional arguments. Returns a generator which produces the entire sequence in order, arg by arg:</p>
<pre><code>flatten = lambda *n: (e for a in n
for e in (flatten(*a) if isinstance(a, (tu... | 16 | 2011-03-23T17:42:24Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 7,037,726 | <p>I don't see anything like this posted around here and just got here from a closed question on the same subject, but why not just do something like this(if you know the type of the list you want to split):</p>
<pre><code>>>> a = [1, 2, 3, 5, 10, [1, 25, 11, [1, 0]]]
>>> g = str(a).replace('[', ... | 1 | 2011-08-12T08:51:28Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 14,491,059 | <p>Generator using recursion and duck typing (updated for Python 3):</p>
<pre><code>def flatten(L):
for item in L:
try:
yield from flatten(item)
except TypeError:
yield item
list(flatten([[[1, 2, 3], [4, 5]], 6]))
>>>[1, 2, 3, 4, 5, 6]
</code></pre>
| 19 | 2013-01-23T23:04:43Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 14,781,252 | <p>You could simply use the flatten function in the <a href="http://docs.python.org/2/library/compiler.html#module-compiler.ast"><code>compiler.ast</code></a> module.</p>
<pre><code>>>> from compiler.ast import flatten
>>> flatten([0, [1, 2], [3, 4, [5, 6]], 7])
[0, 1, 2, 3, 4, 5, 6, 7]
</code></pre>... | 56 | 2013-02-08T20:59:02Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 17,427,599 | <pre><code>L2 = [o for k in [[j] if not isinstance(j,list) else j for j in [k for i in [[m] if not
isinstance(m,list) else m for m in L] for k in i]] for o in k]
</code></pre>
| 1 | 2013-07-02T13:59:14Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 17,868,434 | <p>It was fun trying to create a function that could flatten irregular list in Python, but of course that is what Python is for (to make programming fun). The following generator works fairly well with some caveats:</p>
<pre><code>def flatten(iterable):
try:
for item in iterable:
yield from fla... | 6 | 2013-07-25T20:46:26Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 18,466,318 | <p>Here's the <code>compiler.ast.flatten</code> implementation in 2.7.5:</p>
<pre><code>def flatten(seq):
l = []
for elt in seq:
t = type(elt)
if t is tuple or t is list:
for elt2 in flatten(elt):
l.append(elt2)
else:
l.append(elt)
return l
</... | 3 | 2013-08-27T13:05:57Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 20,495,215 | <p>Here's a simple function that flattens lists of arbitrary depth. No recursion, to avoid stack overflow.</p>
<pre><code>from copy import deepcopy
def flatten_list(nested_list):
"""Flatten an arbitrarily nested list, without recursion (to avoid
stack overflows). Returns a new list, the original list is uncha... | 3 | 2013-12-10T12:56:51Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 23,918,614 | <p>totally hacky but I think it would work (depending on your data_type)</p>
<pre><code>flat_list = ast.literal_eval("[%s]"%re.sub("[\[\]]","",str(the_list)))
</code></pre>
| 1 | 2014-05-28T17:54:20Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 25,353,058 | <p>Here is another py2 approach, Im not sure if its the fastest or the most elegant nor safest ...</p>
<pre><code>from collections import Iterable
from itertools import imap, repeat, chain
def flat(seqs, ignore=(int, long, float, basestring)):
return repeat(seqs, 1) if any(imap(isinstance, repeat(seqs), ignore))... | 0 | 2014-08-17T19:52:51Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 26,130,883 | <p>I used recursive to solve <strong><em>nested list with any depth</em></strong></p>
<pre><code>def combine_nlist(nlist,init=0,combiner=lambda x,y: x+y):
'''
apply function: combiner to a nested list element by element(treated as flatten list)
'''
current_value=init
for each_item in nlist:
... | 1 | 2014-09-30T22:02:25Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 27,340,134 | <p>Without using any library:</p>
<pre><code>def flat(l):
def _flat(l, r):
if type(l) is not list:
r.append(l)
else:
for i in l:
r = r + flat(i)
return r
return _flat(l, [])
# example
test = [[1], [[2]], [3], [['a','b','c'] , [['z','x','y']... | 0 | 2014-12-07T06:06:19Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 28,756,609 | <p>Using <code>itertools.chain</code>:</p>
<pre><code>import itertools
from collections import Iterable
def list_flatten(lst):
flat_lst = []
for item in itertools.chain(lst):
if isinstance(item, Iterable):
item = list_flatten(item)
flat_lst.extend(item)
else:
... | 0 | 2015-02-27T02:38:33Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 33,113,831 | <p>Shamelessly taken from my own answer to <a href="http://stackoverflow.com/a/33109485/418374">another question</a>.</p>
<p>This function</p>
<ul>
<li>Does not use <code>isinstance</code>, because it's evil and breaks duck typing.</li>
<li>Uses <code>reduce</code> recursively. There has to be an answer using <code>... | 0 | 2015-10-13T22:41:14Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 33,705,609 | <p>I'm surprised no one has thought of this. Damn recursion I don't get the recursive answers that the advanced people here made. anyway here is my attempt on this. caveat is it's very specific to the OP's use case</p>
<pre><code>import re
L = [[[1, 2, 3], [4, 5]], 6]
flattened_list = re.sub("[\[\]]", "", str(L)).rep... | 0 | 2015-11-14T05:59:47Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 34,298,369 | <p>The easiest way is to use the <a href="https://github.com/metagriffin/morph" rel="nofollow">morph</a> library using <code>pip install morph</code>.</p>
<p>The code is:</p>
<pre><code>import morph
list = [[[1, 2, 3], [4, 5]], 6]
flattened_list = morph.flatten(list) # returns [1, 2, 3, 4, 5, 6]
</code></pre>
| 0 | 2015-12-15T20:03:50Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 36,156,346 | <p>We can also use the 'type' function of python. When iterating the list we check if the item is a list or not. If not we 'append' it else we 'extend' it. Here is a sample code - </p>
<pre><code>l=[1,2,[3,4],5,[6,7,8]]
x=[]
for i in l:
if type(i) is list:
x.extend(i)
else:
x.append(i)
print x
... | 0 | 2016-03-22T13:55:38Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 36,412,443 | <p>this might be an old question i'd like to take a shot at this.</p>
<p>I am a dumb guy so I'll give a "dumb" solution. all that recursion hurts my brain.</p>
<pre><code>flattened_list = []
nested_list =[[[1, 2, 3], [4, 5]], 6]
def flatten(nested_list, container):
for item in nested_list:
if isintance(... | 0 | 2016-04-04T20:38:15Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 36,500,762 | <p>I didn't go through all the already available answers here, but here is a one liner I came up with, borrowing from lisp's way of first and rest list processing </p>
<pre><code>def flatten(l): return flatten(l[0]) + (flatten(l[1:]) if len(l) > 1 else []) if type(l) is list else [l]
</code></pre>
<p>here is one s... | 1 | 2016-04-08T13:24:02Z | [
"python",
"list",
"optimization",
"flatten"
] |
Flatten (an irregular) list of lists in Python | 2,158,395 | <p>Yes, I know this subject has been covered before (<a href="http://stackoverflow.com/questions/120886">here</a>, <a href="http://stackoverflow.com/questions/406121">here</a>, <a href="http://stackoverflow.com/questions/457215">here</a>, <a href="http://stackoverflow.com/questions/952914">here</a>), but as far as I kn... | 256 | 2010-01-28T22:15:42Z | 39,835,505 | <p>I am aware that there are already many awesome answers but i wanted to add an answer that uses the functional programming method of solving the question. In this answer i make use of double recursion :</p>
<pre><code>def flatten_list(seq):
if not seq:
return []
elif isinstance(seq[0],list):
... | 1 | 2016-10-03T15:46:27Z | [
"python",
"list",
"optimization",
"flatten"
] |
Easy way to upload files to S3 via HTTP Form | 2,158,871 | <p>I have written a tiny web appication in python that allows me to browse my S3 buckets.
The web appication runs inside the Google App Engine.</p>
<p>Now, I want to create a html form for this web appication that allows me to upload a file into the bucket.</p>
<p>These information are already inside the form: AWSAc... | 2 | 2010-01-28T23:45:32Z | 2,159,030 | <p>Read the developer documentation from Amazon: <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1434" rel="nofollow">Browser Uploads to S3 using HTML POST Forms</a></p>
<p>There is Python examples in there to get you started.</p>
| 4 | 2010-01-29T00:19:05Z | [
"python",
"html",
"google-app-engine",
"amazon-s3"
] |
How do I create a script that appends the file create date to filename using python? | 2,158,961 | <p>I would like to create a python script that
appends the file created date to the end of the filename while retaining the oringinal file name ("Report") for a batch of pdf documents.</p>
<pre><code>directory = T:\WISAARD_Web Portal Projects\PortalLogging\WebLogExpert
filenames = Report.pdf
</code></pre>
<p>Thank yo... | 1 | 2010-01-29T00:05:01Z | 2,159,237 | <pre><code>import os,time
root="/home"
path=os.path.join(root,"dir1")
os.chdir(path)
for files in os.listdir("."):
if files.endswith(".pdf"):
f,ext = os.path.splitext(files)
d=time.ctime(os.path.getmtime(files)).split() #here is just example. you can use strftime, strptime etc to format your... | 1 | 2010-01-29T01:05:20Z | [
"python"
] |
Use distribute/setuptools to create symlink (or run script)? | 2,159,211 | <p>As part of my project's setup process, I need to symlink one of the packages to a specified directory so an init.d script can find it. Is there any way to add this as a post-processing command to <code>setup()</code>? I would even settle for creating another file that creates the link and pass it to <code>setup()</c... | 9 | 2010-01-29T00:57:31Z | 2,163,846 | <p>Currently, only platform-specific package management tools (e.g. RPM, deb, win32 installers) have the ability to run post-install steps: the distutils, setuptools, etc. do not support this directly. (Except to the extent of allowing you to build the RPM, windows installer, etc.)</p>
<p>So, the simplest way to do t... | 4 | 2010-01-29T17:36:42Z | [
"python",
"symlink",
"setuptools",
"distribute"
] |
Use distribute/setuptools to create symlink (or run script)? | 2,159,211 | <p>As part of my project's setup process, I need to symlink one of the packages to a specified directory so an init.d script can find it. Is there any way to add this as a post-processing command to <code>setup()</code>? I would even settle for creating another file that creates the link and pass it to <code>setup()</c... | 9 | 2010-01-29T00:57:31Z | 15,523,570 | <p><strike>Expanding on @pjeby's answer, you can also extend the install command to add your own custom postinstall steps. However that will only work when installing from source (i.e. running setup.py) and other installers like RPM and MSI will silently ignore your changes.</strike></p>
<p><strong>EDIT</strong>: Foun... | 0 | 2013-03-20T12:28:27Z | [
"python",
"symlink",
"setuptools",
"distribute"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.