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
listlengths
1
5
Downloading file using IE from python
1,398,780
<p>I'm trying to download file with Python using IE:</p> <pre><code>from win32com.client import DispatchWithEvents class EventHandler(object): def OnDownloadBegin(self): pass ie = DispatchWithEvents("InternetExplorer.Application", EventHandler) ie.Visible = 0 ie.Navigate('http://website/file.xml') </co...
7
2009-09-09T10:18:42Z
4,571,068
<p>One option could also be to embed your own browser.</p> <p>Thats e.g. possible with Qt via <a href="http://www.riverbankcomputing.co.uk/software/pyqt/intro" rel="nofollow">PyQt</a> (GPL) or <a href="http://www.pyside.org/" rel="nofollow">PySide</a> (LGPL). There you could embed the WebKit engine. You could then eit...
1
2010-12-31T16:12:17Z
[ "python", "internet-explorer", "com" ]
Downloading file using IE from python
1,398,780
<p>I'm trying to download file with Python using IE:</p> <pre><code>from win32com.client import DispatchWithEvents class EventHandler(object): def OnDownloadBegin(self): pass ie = DispatchWithEvents("InternetExplorer.Application", EventHandler) ie.Visible = 0 ie.Navigate('http://website/file.xml') </co...
7
2009-09-09T10:18:42Z
4,573,966
<p><a href="http://pamie.sourceforge.net/" rel="nofollow">pamie</a> perhaps</p> <blockquote> <p>P.A.M.I.E. - stands for Python Automated Module For I.E.</p> <p>Pamie's main use is for testing web sites by which you automate the Internet Explorer client using the Pamie scripting language. PAMIE is no...
2
2011-01-01T11:54:16Z
[ "python", "internet-explorer", "com" ]
Downloading file using IE from python
1,398,780
<p>I'm trying to download file with Python using IE:</p> <pre><code>from win32com.client import DispatchWithEvents class EventHandler(object): def OnDownloadBegin(self): pass ie = DispatchWithEvents("InternetExplorer.Application", EventHandler) ie.Visible = 0 ie.Navigate('http://website/file.xml') </co...
7
2009-09-09T10:18:42Z
4,590,561
<p>This works for me as long as the IE dialogs are in the foreground and the downloaded file does not already exist in the "Save As" directory:</p> <pre><code>import time import threading import win32ui, win32gui, win32com, pythoncom, win32con from win32com.client import Dispatch class IeThread(threading.Thread): ...
7
2011-01-04T04:08:48Z
[ "python", "internet-explorer", "com" ]
Downloading file using IE from python
1,398,780
<p>I'm trying to download file with Python using IE:</p> <pre><code>from win32com.client import DispatchWithEvents class EventHandler(object): def OnDownloadBegin(self): pass ie = DispatchWithEvents("InternetExplorer.Application", EventHandler) ie.Visible = 0 ie.Navigate('http://website/file.xml') </co...
7
2009-09-09T10:18:42Z
17,243,096
<p>This is definitely absolutely the last way I would normally do this but today I did have to resort to banging away to get something working. I have IE 10 so @cgohlke's answer won't work (no window text). All attempts to get a proper version of Client Authentication working were failing so had to fall back on this. M...
0
2013-06-21T19:40:35Z
[ "python", "internet-explorer", "com" ]
The Assignment Problem, a numpy function?
1,398,822
<p>Since an <a href="http://en.wikipedia.org/wiki/Assignment%5Fproblem">assignment problem</a> can be posed in the form of a single matrix, I am wandering if numpy has a function to solve such a matrix. So far I have found none. Maybe one of you guys know if numpy/scipy has an assignment-problem-solve function?</p> <p...
6
2009-09-09T10:28:36Z
1,436,399
<p>No, NumPy contains no such function. Combinatorial optimization is outside of NumPy's scope. It may be possible to do it with one of the optimizers in <code>scipy.optimize</code> but I have a feeling that the constraints may not be of the right form.</p> <p><a href="http://networkx.lanl.gov/" rel="nofollow">Network...
3
2009-09-17T02:09:07Z
[ "python", "numpy", "scipy" ]
The Assignment Problem, a numpy function?
1,398,822
<p>Since an <a href="http://en.wikipedia.org/wiki/Assignment%5Fproblem">assignment problem</a> can be posed in the form of a single matrix, I am wandering if numpy has a function to solve such a matrix. So far I have found none. Maybe one of you guys know if numpy/scipy has an assignment-problem-solve function?</p> <p...
6
2009-09-09T10:28:36Z
1,510,183
<p>There is an implementation of the <a href="http://pypi.python.org/pypi/hungarian/0.2" rel="nofollow">Munkres' algorithm</a> as a python extension module which has numpy support. I've used it successfully on my old laptop. However, it does not work on my new machine - I assume there is a problem with "new" numpy vers...
2
2009-10-02T15:16:38Z
[ "python", "numpy", "scipy" ]
The Assignment Problem, a numpy function?
1,398,822
<p>Since an <a href="http://en.wikipedia.org/wiki/Assignment%5Fproblem">assignment problem</a> can be posed in the form of a single matrix, I am wandering if numpy has a function to solve such a matrix. So far I have found none. Maybe one of you guys know if numpy/scipy has an assignment-problem-solve function?</p> <p...
6
2009-09-09T10:28:36Z
22,773,632
<p>There is now a numpy implementation of the munkres algorithm in scikit-learn under <a href="https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/utils/linear_assignment_.py">sklearn/utils/linear_assignment_.py</a> its only dependency is numpy. I tried it with some approximately 20x20 matrices, and it see...
10
2014-03-31T22:44:35Z
[ "python", "numpy", "scipy" ]
The Assignment Problem, a numpy function?
1,398,822
<p>Since an <a href="http://en.wikipedia.org/wiki/Assignment%5Fproblem">assignment problem</a> can be posed in the form of a single matrix, I am wandering if numpy has a function to solve such a matrix. So far I have found none. Maybe one of you guys know if numpy/scipy has an assignment-problem-solve function?</p> <p...
6
2009-09-09T10:28:36Z
36,044,076
<p>I was hoping that the newer <code>scipy.optimize.linear_sum_assignment</code> would be fastest, but (perhaps not surprisingly) the <a href="https://github.com/jfrelinger/cython-munkres-wrapper" rel="nofollow">Cython library</a> (which does not have pip support) is significantly faster, at least for my use case:</p> ...
1
2016-03-16T18:29:58Z
[ "python", "numpy", "scipy" ]
Is it possible to intercept attribute getting/setting in ActionScript 3?
1,398,890
<p>When developing in ActionScript 3, I often find myself looking for a way to achieve something similar to what is offered by python's <code>__getattr__</code> / <code>__setattr__</code> magic methods i.e. to be able to intercept attribute lookup on an instance, and do something custom. </p> <p>Is there some acceptab...
-1
2009-09-09T10:44:49Z
1,399,375
<p>Look a the <code>flash.utils.Proxy</code> object.</p> <blockquote> <p>The Proxy class lets you override the default behavior of ActionScript operations (such as retrieving and modifying properties) on an object.</p> </blockquote>
0
2009-09-09T12:22:50Z
[ "actionscript-3", "python" ]
Is it possible to intercept attribute getting/setting in ActionScript 3?
1,398,890
<p>When developing in ActionScript 3, I often find myself looking for a way to achieve something similar to what is offered by python's <code>__getattr__</code> / <code>__setattr__</code> magic methods i.e. to be able to intercept attribute lookup on an instance, and do something custom. </p> <p>Is there some acceptab...
-1
2009-09-09T10:44:49Z
1,405,155
<p>in as3 you can code explicit variables' accessors. ex Class1:</p> <p>private var __myvar:String;</p> <p>public function get myvar():String { return __myvar; } public function set myvar(value:String):void { __myvar = value; }</p> <p>now as you create an instance of Class1 you can access __myvar through the accesso...
0
2009-09-10T13:01:02Z
[ "actionscript-3", "python" ]
Django : import problem with python-twitter module
1,399,478
<p>When I try to import python-twitter module in my app, django tries to import django.templatetags.twitter instead of python-twitter module (in /usr/lib/python2.5/site-packages/twitter.py), but I don't know why. :s</p> <p>For example:</p> <pre><code>myproject/ myapp/ templatetags/ file.py </c...
2
2009-09-09T12:47:15Z
1,399,576
<blockquote> <p>The submodules often need to refer to each other. For example, the surround module might use the echo module. In fact, such references are so common that the import statement first looks in the containing package before looking in the standard module search path. <a href="http://docs.python.org/tutori...
1
2009-09-09T13:04:54Z
[ "python", "django", "import", "twitter" ]
Store django forms.MultipleChoiceField in Models directly
1,399,622
<p>Say I have choices defined as follows:</p> <pre><code>choices = (('1','a'), ('2','b'), ('3','c')) </code></pre> <p>And a form that renders and inputs these values in a MultipleChoiceField,</p> <pre><code>class Form1(forms.Form): field = forms.MultipleChoiceField(choices=choices) </code><...
1
2009-09-09T13:14:55Z
1,400,531
<p>The first thing I would consider is better normalization of your database schema; if a single instance of your model can have multiple values for this field, the field perhaps should be a linked model with a ForeignKey instead.</p> <p>If you're using Postgres, you could also use an ARRAY field; Django now has <a hr...
8
2009-09-09T15:53:43Z
[ "python", "django", "django-models", "django-forms" ]
Store django forms.MultipleChoiceField in Models directly
1,399,622
<p>Say I have choices defined as follows:</p> <pre><code>choices = (('1','a'), ('2','b'), ('3','c')) </code></pre> <p>And a form that renders and inputs these values in a MultipleChoiceField,</p> <pre><code>class Form1(forms.Form): field = forms.MultipleChoiceField(choices=choices) </code><...
1
2009-09-09T13:14:55Z
7,157,811
<p>I just had this same problem and the solution (to me) because as Carl Meyer put it. I don't want a normalized version of this "list of strings" is to just have a CharField in the model. This way your model will store the normalized list of items. In my case this is countries.</p> <p>So the model declaration is just...
1
2011-08-23T07:52:32Z
[ "python", "django", "django-models", "django-forms" ]
Python datatype suitable for my cache
1,399,717
<p>I'm searching for the a datatype for a cache, basically I need the functionality of a dict, i.e. random access based on a key, which has a limited number of entries so that when the limit is reached the oldest item gets automatically removed. Furthermore I need to be able to store it via shelve or pickle and rely on...
1
2009-09-09T13:33:40Z
1,399,804
<p>I think you answered the question yourself. You need to subclass a dict. And you also of course needs to have a list of the keys, so when the list gets too long you can purge the oldest one.</p> <p>I would however possibly look into memcached or similar.</p>
1
2009-09-09T13:50:22Z
[ "python" ]
Python datatype suitable for my cache
1,399,717
<p>I'm searching for the a datatype for a cache, basically I need the functionality of a dict, i.e. random access based on a key, which has a limited number of entries so that when the limit is reached the oldest item gets automatically removed. Furthermore I need to be able to store it via shelve or pickle and rely on...
1
2009-09-09T13:33:40Z
1,400,249
<p>You probably want an LRU cache (one where "oldest" is measured by "least recently accessed" as opposed to "least recently obtained") -- for most access patterns it performs MUCH better than a naive "oldest goes first" cache (an extremely popular item may easily be the oldest one obtained, but half the recent hits go...
1
2009-09-09T14:56:10Z
[ "python" ]
Python: convert free text to date
1,399,727
<p>Assuming the text is typed at the same time in the same (Israeli) timezone, The following free text lines are equivalent:</p> <pre><code>Wed Sep 9 16:26:57 IDT 2009 2009-09-09 16:26:57 16:26:57 September 9th, 16:26:57 </code></pre> <p>Is there a python module that would convert all these text-dates to an (identic...
4
2009-09-09T13:35:46Z
1,399,760
<p>The <a href="http://labix.org/python-dateutil">python-dateutil</a> package sounds like it would be helpful. Your examples only use simple HH:MM timestamps with a (magically shortened) city identifier, but it seems able to handle more complicated formats like those earlier in the question, too.</p>
6
2009-09-09T13:43:57Z
[ "python", "time", "parsing", "freetext" ]
Python: convert free text to date
1,399,727
<p>Assuming the text is typed at the same time in the same (Israeli) timezone, The following free text lines are equivalent:</p> <pre><code>Wed Sep 9 16:26:57 IDT 2009 2009-09-09 16:26:57 16:26:57 September 9th, 16:26:57 </code></pre> <p>Is there a python module that would convert all these text-dates to an (identic...
4
2009-09-09T13:35:46Z
1,399,789
<p>You could you <a href="http://docs.python.org/library/time.html#time.strptime" rel="nofollow"><code>time.strptime</code></a></p> <p>Like this : </p> <pre><code>time.strptime("2009-09-09 16:26:57", "%Y-%m-%d %H:%M:%S") </code></pre> <p>It will return a struct_time value (more info on the python doc page).</p>
0
2009-09-09T13:48:42Z
[ "python", "time", "parsing", "freetext" ]
Python: convert free text to date
1,399,727
<p>Assuming the text is typed at the same time in the same (Israeli) timezone, The following free text lines are equivalent:</p> <pre><code>Wed Sep 9 16:26:57 IDT 2009 2009-09-09 16:26:57 16:26:57 September 9th, 16:26:57 </code></pre> <p>Is there a python module that would convert all these text-dates to an (identic...
4
2009-09-09T13:35:46Z
1,400,141
<p><a href="http://code.google.com/p/parsedatetime/" rel="nofollow">parsedatetime</a> seems to be a very capable module for this specific task.</p>
3
2009-09-09T14:39:12Z
[ "python", "time", "parsing", "freetext" ]
Django and monkey patching issue
1,399,746
<p>I have recently started experimenting with Django for some web applications in my spare time. While designing the data model for one, I came across the dilemma of using inheritance to define a user of the website or using a technique known as monkey patching with the User class already supplied by the framework.</p>...
4
2009-09-09T13:40:39Z
1,399,775
<p>Djangos framework uses metaclasses to initialize the tables. That means you can't monkey-patch in new columns, unless you also re-initialize the class, which I'm not sure is even possible. (It may be).</p> <p>See <a href="http://stackoverflow.com/questions/1251294/difference-between-returning-modified-class-and-usi...
0
2009-09-09T13:46:48Z
[ "python", "django", "monkeypatching" ]
Django and monkey patching issue
1,399,746
<p>I have recently started experimenting with Django for some web applications in my spare time. While designing the data model for one, I came across the dilemma of using inheritance to define a user of the website or using a technique known as monkey patching with the User class already supplied by the framework.</p>...
4
2009-09-09T13:40:39Z
1,399,777
<p>I guess you might run into problems regarding where is your monkeypatch defined. I guess django syncdb creates databse tables only from the "pure" auth application, so your model will then be without "location", and then your site with the patch will look for the field.</p> <p>Probably less painful way of adding ad...
0
2009-09-09T13:47:22Z
[ "python", "django", "monkeypatching" ]
Django and monkey patching issue
1,399,746
<p>I have recently started experimenting with Django for some web applications in my spare time. While designing the data model for one, I came across the dilemma of using inheritance to define a user of the website or using a technique known as monkey patching with the User class already supplied by the framework.</p>...
4
2009-09-09T13:40:39Z
1,399,788
<p>Here's a <a href="http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/" rel="nofollow">(slightly older) way of extending the <code>User</code> model</a>.</p> <p>Here's <a href="http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users" rel="nofollow">what the...
2
2009-09-09T13:48:40Z
[ "python", "django", "monkeypatching" ]
Django and monkey patching issue
1,399,746
<p>I have recently started experimenting with Django for some web applications in my spare time. While designing the data model for one, I came across the dilemma of using inheritance to define a user of the website or using a technique known as monkey patching with the User class already supplied by the framework.</p>...
4
2009-09-09T13:40:39Z
1,399,813
<p>When you add a field to any model, even if you do it the 'official' way, you need to migrate the database - Django doesn't do it for you. Drop the table and run <code>./manage.py syncdb</code> again.</p> <p>You might want to investigate one of the migrations frameworks, such as <code>south</code>, which will manage...
7
2009-09-09T13:52:26Z
[ "python", "django", "monkeypatching" ]
Django and monkey patching issue
1,399,746
<p>I have recently started experimenting with Django for some web applications in my spare time. While designing the data model for one, I came across the dilemma of using inheritance to define a user of the website or using a technique known as monkey patching with the User class already supplied by the framework.</p>...
4
2009-09-09T13:40:39Z
1,399,843
<p>There's an alternative to both approaches, which is to simply use <a href="http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/">a related profile model</a>. This also happens to be a well-documented, highly recommended approach. Perhaps the reason that the add_to_class approach is not well-doc...
13
2009-09-09T13:55:48Z
[ "python", "django", "monkeypatching" ]
Import failed when the module is already in the sys.path
1,399,896
<p>It's weird to me that the import fails even when it's in the <code>sys.path</code>.</p> <p>today, I set up a google app engine django environment on ubuntu in my lab's pc. And it works fine when I checked out the code and ran it in windows(same pc in the lab).</p> <p>But when I went to the dorm, and checked out th...
0
2009-09-09T14:03:57Z
1,399,918
<p>Sometimes you can get an import error for a module when the error is something different, like a syntax error. Try putting </p> <pre><code>import pdb;pdb.set_trace() </code></pre> <p>just before the import and then s(tep) into the import, and n(ext) thruogh the module in question to see of you get an error.</p>
0
2009-09-09T14:07:04Z
[ "python", "django" ]
Import failed when the module is already in the sys.path
1,399,896
<p>It's weird to me that the import fails even when it's in the <code>sys.path</code>.</p> <p>today, I set up a google app engine django environment on ubuntu in my lab's pc. And it works fine when I checked out the code and ran it in windows(same pc in the lab).</p> <p>But when I went to the dorm, and checked out th...
0
2009-09-09T14:03:57Z
1,400,006
<p>Can you import <code>google</code> and <code>google.appengine</code>? Are you sure interpreter has read and traverse access rights to the module tree?</p>
2
2009-09-09T14:20:13Z
[ "python", "django" ]
Import failed when the module is already in the sys.path
1,399,896
<p>It's weird to me that the import fails even when it's in the <code>sys.path</code>.</p> <p>today, I set up a google app engine django environment on ubuntu in my lab's pc. And it works fine when I checked out the code and ran it in windows(same pc in the lab).</p> <p>But when I went to the dorm, and checked out th...
0
2009-09-09T14:03:57Z
1,400,120
<p>Looks like you're getting a module (or package) called 'google' from elsewhere -- perhaps <code>/home/tower/googlecode/mygae</code> -- and THAT google module has no <code>appengine</code> in it. To check, print <code>google.__file__</code> and if possible <code>google.__path__</code>; that should be informative.</p>...
1
2009-09-09T14:35:42Z
[ "python", "django" ]
Import failed when the module is already in the sys.path
1,399,896
<p>It's weird to me that the import fails even when it's in the <code>sys.path</code>.</p> <p>today, I set up a google app engine django environment on ubuntu in my lab's pc. And it works fine when I checked out the code and ran it in windows(same pc in the lab).</p> <p>But when I went to the dorm, and checked out th...
0
2009-09-09T14:03:57Z
14,343,216
<p>I had the same problem on <strong>Ubuntu</strong> when I wanted to play with <strong>google.appengine</strong> in console. First I tried to fix it by removing the <code>/usr/lib/python2.7/dist-packages/google</code> package altogether but <strong>Ubuntu One</strong> complained. Finally I resolved it by merging the <...
2
2013-01-15T17:21:52Z
[ "python", "django" ]
Endianness of integers in Python
1,400,012
<p>I'm working on a program where I store some data in an integer and process it bitwise. For example, I might receive the number 48, which I will process bit-by-bit. In general the endianness of integers depends on the machine representation of integers, but does Python do anything to guarantee that the ints will al...
12
2009-09-09T14:20:42Z
1,400,026
<p>Python's <code>int</code> has the same endianness as the processor it runs on. The <a href="http://docs.python.org/library/struct.html"><code>struct</code></a> module lets you convert byte blobs to ints (and viceversa, and some other data types too) in either native, little-endian, or big-endian ways, depending on t...
15
2009-09-09T14:23:14Z
[ "python", "integer", "endianness" ]
Endianness of integers in Python
1,400,012
<p>I'm working on a program where I store some data in an integer and process it bitwise. For example, I might receive the number 48, which I will process bit-by-bit. In general the endianness of integers depends on the machine representation of integers, but does Python do anything to guarantee that the ints will al...
12
2009-09-09T14:20:42Z
1,400,069
<p>If you need to process your data 'bitwise' then the <a href="http://code.google.com/p/python-bitstring/"><code>bitstring</code></a> module might be of help to you. It can also deal with endianness between platforms (on the latest trunk build at least - to be released in the next few days). </p> <p>The <a href="http...
13
2009-09-09T14:27:59Z
[ "python", "integer", "endianness" ]
Endianness of integers in Python
1,400,012
<p>I'm working on a program where I store some data in an integer and process it bitwise. For example, I might receive the number 48, which I will process bit-by-bit. In general the endianness of integers depends on the machine representation of integers, but does Python do anything to guarantee that the ints will al...
12
2009-09-09T14:20:42Z
1,400,075
<p>Check when?</p> <p>When doing bitwise operations, the int in will have the same endianess as the ints you put in. You don't need to check that. You only need to care about this when converting to/from sequences of bytes, in both languages, afaik.</p> <p>In Python you use the struct module for this, most commonly s...
2
2009-09-09T14:28:26Z
[ "python", "integer", "endianness" ]
Endianness of integers in Python
1,400,012
<p>I'm working on a program where I store some data in an integer and process it bitwise. For example, I might receive the number 48, which I will process bit-by-bit. In general the endianness of integers depends on the machine representation of integers, but does Python do anything to guarantee that the ints will al...
12
2009-09-09T14:20:42Z
20,535,615
<p>The following snippet will tell you if your system default is little endian (otherwise it is big-endian)</p> <pre><code>import struct little_endian = (struct.unpack('&lt;I', struct.pack('=I', 1))[0] == 1) </code></pre> <p>Note, however, this will not affect the behavior of bitwise operators: <code>1&lt;&lt;1</code...
1
2013-12-12T05:18:00Z
[ "python", "integer", "endianness" ]
Multi-line Pattern and tag search
1,400,136
<p>I'm trying to make a pattern for tags, but the sub method just replaces the first char and 3 at the end of the line, im trying to replace all tags on the line and with multiline</p> <pre><code>p=re.compile('&lt;img=([^}]*)&gt;([^}]*)&lt;/img&gt;', re.S) p.sub(r'[img=\1]\2[/img]','&lt;img="test"&gt;dsad&lt;/img&gt; ...
0
2009-09-09T14:38:31Z
1,400,202
<p>You're using towards the start of your re's pattern:</p> <pre><code>&lt;img=([^}]*)&gt; </code></pre> <p>this will gobble up (as group 1) all characters after the leading <code>&lt;img=</code>, <strong>including other tags!!!</strong>, up to the last <code>&gt;</code> it can possibly gobble; <code>*</code> is GREE...
1
2009-09-09T14:48:59Z
[ "python", "regex", "multiline" ]
How do I scroll a wxPython wx.html.HtmlWindow back down to where it was when the user clicked a link?
1,400,179
<p>I am using a wxPython wx.html.HtmlWindow to display part of my interface. The user can scroll down a list of links in a window smaller than the list. When they click on a link, I need to repaint the web page, but I want to return the page position back to where they clicked it. </p> <p>I've tried MouseEvent.GetLogi...
2
2009-09-09T14:45:57Z
1,401,438
<p>how about having a look at the <a href="http://svn.wxwidgets.org/viewvc/wx/wxWidgets/trunk/src/html/htmlwin.cpp?annotate=61772" rel="nofollow">source of wxHtmlWindow</a> for inspiration? for example at <a href="http://svn.wxwidgets.org/viewvc/wx/wxWidgets/trunk/src/html/htmlwin.cpp?annotate=61772#l487" rel="nofollow...
2
2009-09-09T18:55:35Z
[ "python", "wxpython" ]
How do I scroll a wxPython wx.html.HtmlWindow back down to where it was when the user clicked a link?
1,400,179
<p>I am using a wxPython wx.html.HtmlWindow to display part of my interface. The user can scroll down a list of links in a window smaller than the list. When they click on a link, I need to repaint the web page, but I want to return the page position back to where they clicked it. </p> <p>I've tried MouseEvent.GetLogi...
2
2009-09-09T14:45:57Z
1,579,014
<p>Usually, click events are trigged by MouseUp events. If you track the mouse position by capturing any MouseDown events, you will know where the last click (MouseUp) happened, and that should allow you to reconstruct things.</p> <p>For this particular problem, you might have to do a bit more work in MouseDown like c...
0
2009-10-16T16:17:26Z
[ "python", "wxpython" ]
How do I scroll a wxPython wx.html.HtmlWindow back down to where it was when the user clicked a link?
1,400,179
<p>I am using a wxPython wx.html.HtmlWindow to display part of my interface. The user can scroll down a list of links in a window smaller than the list. When they click on a link, I need to repaint the web page, but I want to return the page position back to where they clicked it. </p> <p>I've tried MouseEvent.GetLogi...
2
2009-09-09T14:45:57Z
2,850,055
<p>Maybe a bit late, but with some tips from ax, and some hints from <a href="http://stackoverflow.com/questions/1871405/how-do-i-keep-a-wx-html-htmlwindow-at-the-same-position-during-resize-without-fl">here</a>, I think that calling:</p> <pre><code>scrollpos = wx.html.HtmlWindow.GetViewStart()[1] </code></pre> <p>an...
1
2010-05-17T14:53:00Z
[ "python", "wxpython" ]
How do I scroll a wxPython wx.html.HtmlWindow back down to where it was when the user clicked a link?
1,400,179
<p>I am using a wxPython wx.html.HtmlWindow to display part of my interface. The user can scroll down a list of links in a window smaller than the list. When they click on a link, I need to repaint the web page, but I want to return the page position back to where they clicked it. </p> <p>I've tried MouseEvent.GetLogi...
2
2009-09-09T14:45:57Z
8,591,447
<p>Here is what I am doing to scroll page to previous position. I do this to avoid blinking.</p> <pre><code> pos = self.GetViewStart()[1] self.Freeze() self.SetPage(src) if save_scroll_pos: self.Scroll(0, pos) self.Thaw() </code></pre>
1
2011-12-21T14:31:01Z
[ "python", "wxpython" ]
Python class for pickle- and copy-persistent object?
1,400,295
<p>I'm trying to write a class for a read-only object which will not be really copied with the <code>copy</code> module, and when it will be pickled to be transferred between processes each process will maintain no more than one copy of it, no matter how many times it will be passed around as a "new" object. Is there a...
4
2009-09-09T15:05:31Z
1,400,366
<p>I don't know of any such functionality already implemented. The interesting problem is as follows, and needs precise specs as to what's to happen in this case...:</p> <ul> <li>process A makes the obj and sends it to B which unpickles it, so far so good</li> <li>A makes change X to the obj, meanwhile B makes change ...
1
2009-09-09T15:20:17Z
[ "python", "persistence", "pickle" ]
Python class for pickle- and copy-persistent object?
1,400,295
<p>I'm trying to write a class for a read-only object which will not be really copied with the <code>copy</code> module, and when it will be pickled to be transferred between processes each process will maintain no more than one copy of it, no matter how many times it will be passed around as a "new" object. Is there a...
4
2009-09-09T15:05:31Z
1,401,887
<p>you could use simply a dictionnary with the key and the values the same in the receiver. And to avoid a memory leak use a WeakKeyDictionary. </p>
0
2009-09-09T20:25:42Z
[ "python", "persistence", "pickle" ]
Python class for pickle- and copy-persistent object?
1,400,295
<p>I'm trying to write a class for a read-only object which will not be really copied with the <code>copy</code> module, and when it will be pickled to be transferred between processes each process will maintain no more than one copy of it, no matter how many times it will be passed around as a "new" object. Is there a...
4
2009-09-09T15:05:31Z
1,445,790
<p>I made an attempt to implement this. @Alex Martelli and anyone else, please give me comments/improvements. I think this will eventually end up on GitHub.</p> <pre><code>""" todo: need to lock library to avoid thread trouble? todo: need to raise an exception if we're getting pickled with an old protocol? todo: mak...
2
2009-09-18T17:10:58Z
[ "python", "persistence", "pickle" ]
Dictionary of tags in declarative SQLAlchemy?
1,400,537
<p>I am working on a quite large code base that has been implemented using <code>sqlalchemy.ext.declarative</code>, and I need to add a dict-like property to one of the classes. What I need is the same as in <a href="http://stackoverflow.com/questions/780774/sqlalchemy-dictionary-of-tags">this question</a>, but in a de...
6
2009-09-09T15:54:37Z
1,400,881
<p>Declarative is just another way of defining things. Virtually you end up with the exact same environment than if you used separated mapping.</p> <p>Since I answered the other question, I'll try this one as well. Hope it gives more upvotes ;)</p> <p>Well, first we define the classes</p> <pre><code>from sqlalchemy ...
13
2009-09-09T17:04:33Z
[ "python", "sqlalchemy", "declarative" ]
How to empty a list in Python?
1,400,608
<p>It seems so "dirty" emptying a list in this way:</p> <pre><code>while len(alist) &gt; 0 : alist.pop() </code></pre> <p>Does a clear way exist to do that?</p>
215
2009-09-09T16:08:21Z
1,400,614
<pre><code>list = [] </code></pre> <p>will reset <code>list</code> to an empty list.</p> <p>Note that you generally should not shadow reserved function names, such as <code>list</code>, which is the constructor for a list object -- you could use <code>lst</code> or <code>list_</code> instead, for instance.</p>
-1
2009-09-09T16:09:46Z
[ "python", "list" ]
How to empty a list in Python?
1,400,608
<p>It seems so "dirty" emptying a list in this way:</p> <pre><code>while len(alist) &gt; 0 : alist.pop() </code></pre> <p>Does a clear way exist to do that?</p>
215
2009-09-09T16:08:21Z
1,400,622
<p>This actually removes the contents from the list, not replaces the old label with a new empty list</p> <pre><code>del lst[:] </code></pre> <p>example:</p> <pre><code>lst1 = [1, 2, 3] lst2 = lst1 del lst1[:] print(lst2) </code></pre> <p>For the sake of completeness, slice assignment achieves the same effect:</p> ...
366
2009-09-09T16:10:40Z
[ "python", "list" ]
How to empty a list in Python?
1,400,608
<p>It seems so "dirty" emptying a list in this way:</p> <pre><code>while len(alist) &gt; 0 : alist.pop() </code></pre> <p>Does a clear way exist to do that?</p>
215
2009-09-09T16:08:21Z
1,400,624
<p>You could try:</p> <pre><code>alist[:] = [] </code></pre> <p>Which means: Splice in the list <code>[]</code> (0 elements) at the location <code>[:]</code> (all indexes from start to finish)</p> <p>The [:] is the slice operator. See <a href="http://stackoverflow.com/questions/509211/good-primer-for-python-slice-no...
37
2009-09-09T16:10:52Z
[ "python", "list" ]
How to empty a list in Python?
1,400,608
<p>It seems so "dirty" emptying a list in this way:</p> <pre><code>while len(alist) &gt; 0 : alist.pop() </code></pre> <p>Does a clear way exist to do that?</p>
215
2009-09-09T16:08:21Z
8,239,837
<p>it turns out that with python 2.5.2, <code>del l[:]</code> is slightly slower than <code>l[:] = []</code> by 1.1 usec.</p> <pre><code>$ python -mtimeit "l=list(range(1000))" "b=l[:];del b[:]" 10000 loops, best of 3: 29.8 usec per loop $ python -mtimeit "l=list(range(1000))" "b=l[:];b[:] = []" 10000 loops, best of 3...
23
2011-11-23T09:30:17Z
[ "python", "list" ]
How to empty a list in Python?
1,400,608
<p>It seems so "dirty" emptying a list in this way:</p> <pre><code>while len(alist) &gt; 0 : alist.pop() </code></pre> <p>Does a clear way exist to do that?</p>
215
2009-09-09T16:08:21Z
25,275,196
<p>Another simple code you could use (depending on your situation) is:</p> <pre><code>index=len(list)-1 while index&gt;=0: del list[index] index-=1 </code></pre> <p>You have to start index at the length of the list and go backwards versus index at 0, forwards because that would end you up with index equal to...
1
2014-08-12T22:34:31Z
[ "python", "list" ]
How to empty a list in Python?
1,400,608
<p>It seems so "dirty" emptying a list in this way:</p> <pre><code>while len(alist) &gt; 0 : alist.pop() </code></pre> <p>Does a clear way exist to do that?</p>
215
2009-09-09T16:08:21Z
30,087,221
<p>If you have Python 3.3 or better, you could use the <a href="https://docs.python.org/dev/library/stdtypes.html#typesseq-mutable"><code>clear()</code></a> method of <code>list</code>:</p> <pre><code>alist.clear() # removes all items from alist (equivalent to del alist[:]) </code></pre> <p>As per the linked page, t...
15
2015-05-06T20:46:24Z
[ "python", "list" ]
How to create QString in PyQt4?
1,400,858
<pre><code>str = QtCore.QString('Hello') AttributeError: 'module' object has no attribute 'QString' QtCore.QString._init_(self) AttributeError: 'module' object has no attribute 'QString' </code></pre> <p>Yes, I'm read <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qstring.html" rel="nofollow">QString Class Referen...
9
2009-09-09T17:00:03Z
1,400,885
<pre><code>In [1]: from PyQt4 import QtCore In [2]: s = QtCore.QString('foo') In [3]: s Out[3]: PyQt4.QtCore.QString(u'foo') </code></pre>
6
2009-09-09T17:06:04Z
[ "python", "user-interface", "pyqt" ]
How to create QString in PyQt4?
1,400,858
<pre><code>str = QtCore.QString('Hello') AttributeError: 'module' object has no attribute 'QString' QtCore.QString._init_(self) AttributeError: 'module' object has no attribute 'QString' </code></pre> <p>Yes, I'm read <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qstring.html" rel="nofollow">QString Class Referen...
9
2009-09-09T17:00:03Z
1,485,652
<p>It depends on your import statement.</p> <p>If you write</p> <pre><code>from PyQt4 import QtGui, QtCore </code></pre> <p>you must call QString with</p> <pre><code>yourstr = QtCore.QString('foo') </code></pre> <p>I think you've written this :</p> <pre><code>from PyQt4.QtGui import * from PyQt4.QtCore import * <...
1
2009-09-28T06:12:06Z
[ "python", "user-interface", "pyqt" ]
How to create QString in PyQt4?
1,400,858
<pre><code>str = QtCore.QString('Hello') AttributeError: 'module' object has no attribute 'QString' QtCore.QString._init_(self) AttributeError: 'module' object has no attribute 'QString' </code></pre> <p>Yes, I'm read <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qstring.html" rel="nofollow">QString Class Referen...
9
2009-09-09T17:00:03Z
2,595,514
<p>In Python 3, QString is automatically mapped to the native Python string by default:</p> <blockquote> <p>The QString class is implemented as a mapped type that is automatically converted to and from a Python string. In addition a None is converted to a null QString. However, a null QString is converted to an empt...
14
2010-04-07T20:04:01Z
[ "python", "user-interface", "pyqt" ]
How to create QString in PyQt4?
1,400,858
<pre><code>str = QtCore.QString('Hello') AttributeError: 'module' object has no attribute 'QString' QtCore.QString._init_(self) AttributeError: 'module' object has no attribute 'QString' </code></pre> <p>Yes, I'm read <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qstring.html" rel="nofollow">QString Class Referen...
9
2009-09-09T17:00:03Z
3,982,776
<p>From PyQt4 4.6+ in Python3 QString doesn't exist and you are supposed to use ordinary Python3 unicode objects (string literals). To do this so that your code will work in both Python 2.x AND Python 3.x you can do following:</p> <pre><code>try: from PyQt4.QtCore import QString except ImportError: # we are us...
9
2010-10-20T22:14:36Z
[ "python", "user-interface", "pyqt" ]
How to get Django admin.TabularInline to NOT require some items
1,400,981
<pre><code>class LineItemInline(admin.TabularInline): model = LineItem extra = 10 class InvoiceAdmin(admin.ModelAdmin): model = Invoice inlines = (LineItemInline,) </code></pre> <p>and</p> <pre><code>class LineItem(models.Model): invoice = models.ForeignKey(Invoice) item_product_code = models...
0
2009-09-09T17:27:57Z
1,401,171
<p>That's strange, it's supposed not to do that - it shouldn't require any data in a row if you haven't entered anything.</p> <p>I wonder if the <code>default</code> options are causing it to get confused. Again, Django should cope with this, but try removing those and see what happens.</p> <p>Also note that this:</p...
1
2009-09-09T18:08:18Z
[ "python", "django" ]
How to get Django admin.TabularInline to NOT require some items
1,400,981
<pre><code>class LineItemInline(admin.TabularInline): model = LineItem extra = 10 class InvoiceAdmin(admin.ModelAdmin): model = Invoice inlines = (LineItemInline,) </code></pre> <p>and</p> <pre><code>class LineItem(models.Model): invoice = models.ForeignKey(Invoice) item_product_code = models...
0
2009-09-09T17:27:57Z
1,402,180
<p>Turns out the problem is default values. The one pointed out above about UnitOfMeasure isn't the actual problem though, any field with a default= causes it to require the rest of the data to be present. This to me seems like a bug since a default value should be subtracted out when determining if there is anything...
0
2009-09-09T21:23:07Z
[ "python", "django" ]
Python with matplotlib - drawing multiple figures in parallel
1,401,102
<p>I have functions that contribute to small parts of a figure generation. I'm trying to use these functions to generate multiple figures? So something like this:</p> <ol> <li>work with Figure 1</li> <li>do something else</li> <li>work with Figure 2</li> <li>do something else</li> <li>work with Figure 1</li> <li>do so...
29
2009-09-09T17:57:12Z
1,401,191
<p>There are several ways to do this, and the simplest is to use the figure numbers. The code below makes two figures, #0 and #1, each with two lines. #0 has the points 1,2,3,4,5,6, and #2 has the points 10,20,30,40,50,60.</p> <pre><code>from pylab import * figure(0) plot([1,2,3]) figure(1) plot([10, 20, 30]) fi...
33
2009-09-09T18:11:15Z
[ "python", "matplotlib", "figures" ]
Python with matplotlib - drawing multiple figures in parallel
1,401,102
<p>I have functions that contribute to small parts of a figure generation. I'm trying to use these functions to generate multiple figures? So something like this:</p> <ol> <li>work with Figure 1</li> <li>do something else</li> <li>work with Figure 2</li> <li>do something else</li> <li>work with Figure 1</li> <li>do so...
29
2009-09-09T17:57:12Z
1,401,686
<p>For a more general answer to this question and to questions you may soon have, I would recommend the <a href="http://matplotlib.sourceforge.net/users/artists.html">official tutorial</a>.</p>
6
2009-09-09T19:44:20Z
[ "python", "matplotlib", "figures" ]
Python with matplotlib - drawing multiple figures in parallel
1,401,102
<p>I have functions that contribute to small parts of a figure generation. I'm trying to use these functions to generate multiple figures? So something like this:</p> <ol> <li>work with Figure 1</li> <li>do something else</li> <li>work with Figure 2</li> <li>do something else</li> <li>work with Figure 1</li> <li>do so...
29
2009-09-09T17:57:12Z
14,591,411
<p>The best way to show multiple figures is use matplotlib or pylab. (for windows) with matplotlib you can prepare the figures and then when you finish the process with them you can show with the comand "matplotlib.show()" and all figures should be shown.</p> <p>(on linux) you don´t have problems adding changes to fi...
0
2013-01-29T20:13:49Z
[ "python", "matplotlib", "figures" ]
CRC32 to make short URL for web
1,401,218
<p>I am trying to understand crc32 to generate the unique url for web page.</p> <p>If we use the crc32, what is the maximum number of urls can be used so that we can avoid duplicates?</p> <p>What could be the approximative string length to keep the checksum to be 2^32?</p> <p>When I tried UUID for an url and convert...
4
2009-09-09T18:16:32Z
1,401,231
<p>There is no such number as the "maximum number of urls can be used so that we can avoid duplicates" for CRC32.</p> <p>The problem is that CRC32 can produce duplicates, and it's not a function of how many values you throw at it, it's a function of what those values look like.</p> <p>So you might have a collision on...
6
2009-09-09T18:18:45Z
[ "c#", "python", "url", "crc32", "short-url" ]
CRC32 to make short URL for web
1,401,218
<p>I am trying to understand crc32 to generate the unique url for web page.</p> <p>If we use the crc32, what is the maximum number of urls can be used so that we can avoid duplicates?</p> <p>What could be the approximative string length to keep the checksum to be 2^32?</p> <p>When I tried UUID for an url and convert...
4
2009-09-09T18:16:32Z
1,401,237
<p>If you're already storing the full URL in a database table, an integer ID is pretty short, and can be made shorter by converting it to base 16, 64, or 85. If you can use a UUID, you can use an integer, and you may as well, since it's shorter and I don't see what benefit a UUID would provide in your lookup table.</p>...
4
2009-09-09T18:19:55Z
[ "c#", "python", "url", "crc32", "short-url" ]
CRC32 to make short URL for web
1,401,218
<p>I am trying to understand crc32 to generate the unique url for web page.</p> <p>If we use the crc32, what is the maximum number of urls can be used so that we can avoid duplicates?</p> <p>What could be the approximative string length to keep the checksum to be 2^32?</p> <p>When I tried UUID for an url and convert...
4
2009-09-09T18:16:32Z
1,401,243
<p>CRC32 means <em>cyclic redundancy check</em> with 32 bits where any arbitrary amount of bits is summed up to a 32 bit check sum. And check sum functions are surjective, that means multiple input values have the same output value. So you cannot inverse the function.</p>
1
2009-09-09T18:20:37Z
[ "c#", "python", "url", "crc32", "short-url" ]
CRC32 to make short URL for web
1,401,218
<p>I am trying to understand crc32 to generate the unique url for web page.</p> <p>If we use the crc32, what is the maximum number of urls can be used so that we can avoid duplicates?</p> <p>What could be the approximative string length to keep the checksum to be 2^32?</p> <p>When I tried UUID for an url and convert...
4
2009-09-09T18:16:32Z
1,401,286
<p>No, even you use md5, or any other check sum, the URL CAN BE duplicate, it all depends on your luck.</p> <p>So don't make an unique url base on those check sum</p>
0
2009-09-09T18:27:37Z
[ "c#", "python", "url", "crc32", "short-url" ]
CRC32 to make short URL for web
1,401,218
<p>I am trying to understand crc32 to generate the unique url for web page.</p> <p>If we use the crc32, what is the maximum number of urls can be used so that we can avoid duplicates?</p> <p>What could be the approximative string length to keep the checksum to be 2^32?</p> <p>When I tried UUID for an url and convert...
4
2009-09-09T18:16:32Z
1,401,331
<p>The right way to make a short URL is to store the full one in the database and publish something that maps to the row index. A compact way is to use the Base64 of the row ID, for example. Or you could use a UID for the primary key and show that.</p> <p>Do not use a checksum, because it's too small and very likely...
1
2009-09-09T18:36:24Z
[ "c#", "python", "url", "crc32", "short-url" ]
CRC32 to make short URL for web
1,401,218
<p>I am trying to understand crc32 to generate the unique url for web page.</p> <p>If we use the crc32, what is the maximum number of urls can be used so that we can avoid duplicates?</p> <p>What could be the approximative string length to keep the checksum to be 2^32?</p> <p>When I tried UUID for an url and convert...
4
2009-09-09T18:16:32Z
1,401,384
<p>The quickest (and perhaps best!) way to solve things may be to simply use a hash of the local path and query of a given URI, as follows:</p> <pre><code>using System; namespace HashSample { class Program { static void Main(string[] args) { Uri uri = new Uri( "http...
-1
2009-09-09T18:45:42Z
[ "c#", "python", "url", "crc32", "short-url" ]
Return the number of affected rows from a MERGE with cx_oracle
1,401,328
<p>How can you get the number of affected rows from executing a "MERGE INTO..." sql command within CX_Oracle?<br /> When ever I execute the MERGE SQL on cx_oracle, I get a cursor.rowcount of -1. Is there a way to get the number of rows affected by the merge?</p>
3
2009-09-09T18:36:10Z
1,401,442
<p>Since cx_oracle follows the python DBAPI specification (I presume), this is expected 'behaviour'. The exact same problem was discussed <a href="http://stackoverflow.com/questions/839069/cursor-rowcount-always-1-in-sqlite3-in-python3k">here on stackoverflow</a> before.</p> <p>Some more links with possible solutions:...
1
2009-09-09T18:56:30Z
[ "python", "oracle", "cx-oracle" ]
Performance lost when open a db multiple times in BerkeleyDB
1,401,497
<p>I'm using BerkeleyDB to develop a small app. And I have a question about opening a database multiple time in BDB.</p> <p>I have a large set of text ( corpus ), and I want to load a part of it to do the calculation. I have two pseudo-code (mix with python) here</p> <p>@1</p> <pre><code>def getCorpus(token): DB...
0
2009-09-09T19:09:06Z
1,401,546
<p>If you aren't caching the opened file you will always get performance lost because:</p> <ul> <li>you call open() and close() multiple times which are quite expensive,</li> <li>you lose all potential buffers (both system buffers and bdb internal buffers).</li> </ul> <p>But I wouldn't care too much about the perform...
3
2009-09-09T19:19:15Z
[ "python", "database", "performance", "berkeley-db" ]
How do I programmatically check whether an image (PNG, JPEG, or GIF) is corrupted?
1,401,527
<p>Okay. So I have about 250,000 high resolution images. What I want to do is go through all of them and find ones that are corrupted. If you know what 4scrape is, then you know the nature of the images I.</p> <p>Corrupted, to me, is the image is loaded into Firefox and it says</p> <blockquote> <p><code>The image â...
14
2009-09-09T19:15:41Z
1,401,544
<p>i suggest you check out imagemagick for this: <a href="http://www.imagemagick.org/">http://www.imagemagick.org/</a></p> <p>there you have a tool called identify which you can either use in combination with a script/stdout or you can use the programming interface provided</p>
6
2009-09-09T19:18:41Z
[ "php", "python", "image" ]
How do I programmatically check whether an image (PNG, JPEG, or GIF) is corrupted?
1,401,527
<p>Okay. So I have about 250,000 high resolution images. What I want to do is go through all of them and find ones that are corrupted. If you know what 4scrape is, then you know the nature of the images I.</p> <p>Corrupted, to me, is the image is loaded into Firefox and it says</p> <blockquote> <p><code>The image â...
14
2009-09-09T19:15:41Z
1,401,565
<p>An easy way would be to try loading and verifying the files with PIL (Python Imaging Library).</p> <pre><code>from PIL import Image v_image = Image.open(file) v_image.verify() </code></pre> <p>Catch the exceptions...</p> <p>From <a href="http://effbot.org/imagingbook/image.htm">the documentation</a>:</p> <p><st...
20
2009-09-09T19:24:10Z
[ "php", "python", "image" ]
How do I programmatically check whether an image (PNG, JPEG, or GIF) is corrupted?
1,401,527
<p>Okay. So I have about 250,000 high resolution images. What I want to do is go through all of them and find ones that are corrupted. If you know what 4scrape is, then you know the nature of the images I.</p> <p>Corrupted, to me, is the image is loaded into Firefox and it says</p> <blockquote> <p><code>The image â...
14
2009-09-09T19:15:41Z
1,401,566
<p>If your exact requirements are that it show correctly <em>in FireFox</em> you may have a difficult time - the only way to be sure would be to link to the exact same image loading source code as FireFox.</p> <p>Basic image corruption (file is incomplete) can be detected simply by trying to open the file using any nu...
3
2009-09-09T19:24:44Z
[ "php", "python", "image" ]
How do I programmatically check whether an image (PNG, JPEG, or GIF) is corrupted?
1,401,527
<p>Okay. So I have about 250,000 high resolution images. What I want to do is go through all of them and find ones that are corrupted. If you know what 4scrape is, then you know the nature of the images I.</p> <p>Corrupted, to me, is the image is loaded into Firefox and it says</p> <blockquote> <p><code>The image â...
14
2009-09-09T19:15:41Z
1,402,740
<p>In PHP, with <a href="http://php.net/manual/en/function.exif-imagetype.php" rel="nofollow">exif_imagetype()</a>:</p> <pre><code>if (exif_imagetype($filename) === false) { unlink($filename); // image is corrupted } </code></pre> <p><strong>EDIT</strong>: Or you can try to fully load the image with <a href="http...
4
2009-09-09T23:50:44Z
[ "php", "python", "image" ]
How do I programmatically check whether an image (PNG, JPEG, or GIF) is corrupted?
1,401,527
<p>Okay. So I have about 250,000 high resolution images. What I want to do is go through all of them and find ones that are corrupted. If you know what 4scrape is, then you know the nature of the images I.</p> <p>Corrupted, to me, is the image is loaded into Firefox and it says</p> <blockquote> <p><code>The image â...
14
2009-09-09T19:15:41Z
2,335,797
<p>You could use imagemagick if it is available:</p> <p>if you want to do a whole folder</p> <pre><code>identify "./myfolder/*" &gt;log.txt 2&gt;&amp;1 </code></pre> <p>if you want to just check a file:</p> <pre><code>identify myfile.jpg </code></pre>
0
2010-02-25T16:45:55Z
[ "php", "python", "image" ]
Python: copy.deepcopy produces an error
1,401,610
<p>I have been using this copy method for quite a while, in lots of classes that needed it.</p> <pre><code>class population (list): def __init__ (self): pass def copy(self): return copy.deepcopy(self) </code></pre> <p>It has suddenly started producing this error:</p> <pre><code> File "C:\Python26\lib\co...
2
2009-09-09T19:32:40Z
1,401,640
<p>Are you cloning a generator? <a href="https://mail.python.org/pipermail/python-list/2009-March/539759.html" rel="nofollow">Generators can't be cloned.</a></p> <p>Copying answer by Gabriel Genellina here:</p> <hr> <p>There is no way of "cloning" a generator:</p> <pre><code>py&gt; g = (i for i in [1,2,3]) py&gt; t...
9
2009-09-09T19:38:33Z
[ "python", "generator" ]
Problem with list of strings in python
1,401,650
<p>Why on Earth doesn't the interpreter raise SyntaxError everytime I do this:</p> <pre><code>my_abc = ['a', 'b', 'c' 'd',] </code></pre> <p>I just wanted to add 'c' to the list of strings, and forgot to append the comma. I would expect this to cause some kind of error, as it's cleary in...
5
2009-09-09T19:40:07Z
1,401,670
<p>It's by design. It allows, for example, writing long string literals in several lines without using +.</p>
6
2009-09-09T19:42:38Z
[ "python", "list" ]
Problem with list of strings in python
1,401,650
<p>Why on Earth doesn't the interpreter raise SyntaxError everytime I do this:</p> <pre><code>my_abc = ['a', 'b', 'c' 'd',] </code></pre> <p>I just wanted to add 'c' to the list of strings, and forgot to append the comma. I would expect this to cause some kind of error, as it's cleary in...
5
2009-09-09T19:40:07Z
1,401,677
<p>Because two string literals side-by-side, delimited by whitespace, are concatenated. Since the strings are within a list, they are 'side-by-side'.</p> <p>See: <a href="http://docs.python.org/reference/lexical%5Fanalysis.html#string-literal-concatenation" rel="nofollow">http://docs.python.org/reference/lexical%5Fana...
3
2009-09-09T19:43:21Z
[ "python", "list" ]
Problem with list of strings in python
1,401,650
<p>Why on Earth doesn't the interpreter raise SyntaxError everytime I do this:</p> <pre><code>my_abc = ['a', 'b', 'c' 'd',] </code></pre> <p>I just wanted to add 'c' to the list of strings, and forgot to append the comma. I would expect this to cause some kind of error, as it's cleary in...
5
2009-09-09T19:40:07Z
1,401,685
<p>Because often people want to do something like this:</p> <pre><code>line = ("Here's a very long line, with no line breaks," " which should be displayed to the user (perhaps" " as an error message or question box).") </code></pre> <p>It's easier to write this without having to manually concatenate s...
2
2009-09-09T19:44:20Z
[ "python", "list" ]
Problem with list of strings in python
1,401,650
<p>Why on Earth doesn't the interpreter raise SyntaxError everytime I do this:</p> <pre><code>my_abc = ['a', 'b', 'c' 'd',] </code></pre> <p>I just wanted to add 'c' to the list of strings, and forgot to append the comma. I would expect this to cause some kind of error, as it's cleary in...
5
2009-09-09T19:40:07Z
1,401,691
<p>Is called "Implicit String Concatenation" and a PEP that proposed its removal was rejected: <a href="http://www.python.org/dev/peps/pep-3126/">http://www.python.org/dev/peps/pep-3126/</a></p>
12
2009-09-09T19:45:15Z
[ "python", "list" ]
Problem with list of strings in python
1,401,650
<p>Why on Earth doesn't the interpreter raise SyntaxError everytime I do this:</p> <pre><code>my_abc = ['a', 'b', 'c' 'd',] </code></pre> <p>I just wanted to add 'c' to the list of strings, and forgot to append the comma. I would expect this to cause some kind of error, as it's cleary in...
5
2009-09-09T19:40:07Z
1,402,033
<p>As others said, it's by design.</p> <p>Why is it so ? Mostly for historical reasons : C also does it.</p> <p>In some cases it's handy because it reduce syntaxic noise and avoid adding unwanted spaces (inline SQL queries, complexes regexpes, etc).</p> <p>What you can do about it ? Not much, but if it really happen...
2
2009-09-09T20:54:48Z
[ "python", "list" ]
Python: List all base classes in a hierarchy of given class
1,401,661
<p>Given a class <code>Foo</code> (whether it is a <a href="http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes">new-style</a> class or not), how do you generate <strong>all</strong> the base classes - anywhere in the inheritance hierarchy - it <a href="http://docs.python.org/library/functions...
65
2009-09-09T19:41:52Z
1,401,706
<p>you can use the <code>__bases__</code> tuple of the class object:</p> <pre><code>class A(object, B, C): def __init__(self): pass print A.__bases__ </code></pre> <p>The tuple returned by <code>__bases__</code> has all its base classes.</p> <p>Hope it helps!</p>
12
2009-09-09T19:47:49Z
[ "python", "class", "inheritance", "oop", "introspection" ]
Python: List all base classes in a hierarchy of given class
1,401,661
<p>Given a class <code>Foo</code> (whether it is a <a href="http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes">new-style</a> class or not), how do you generate <strong>all</strong> the base classes - anywhere in the inheritance hierarchy - it <a href="http://docs.python.org/library/functions...
65
2009-09-09T19:41:52Z
1,401,707
<p><code>inspect.getclasstree()</code> will create a nested list of classes and their bases. Usage:</p> <pre><code>inspect.getclasstree(inspect.getmro(IOError)) # Insert your Class instead of IOError. </code></pre>
19
2009-09-09T19:47:54Z
[ "python", "class", "inheritance", "oop", "introspection" ]
Python: List all base classes in a hierarchy of given class
1,401,661
<p>Given a class <code>Foo</code> (whether it is a <a href="http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes">new-style</a> class or not), how do you generate <strong>all</strong> the base classes - anywhere in the inheritance hierarchy - it <a href="http://docs.python.org/library/functions...
65
2009-09-09T19:41:52Z
1,401,708
<p>See the <a href="http://docs.python.org/library/stdtypes.html#special-attributes"><code>__bases__</code> property</a> available on a python <code>class</code>, which contains a tuple of the bases classes:</p> <pre><code>&gt;&gt;&gt; def classlookup(cls): ... c = list(cls.__bases__) ... for base in c: ... ...
23
2009-09-09T19:48:12Z
[ "python", "class", "inheritance", "oop", "introspection" ]
Python: List all base classes in a hierarchy of given class
1,401,661
<p>Given a class <code>Foo</code> (whether it is a <a href="http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes">new-style</a> class or not), how do you generate <strong>all</strong> the base classes - anywhere in the inheritance hierarchy - it <a href="http://docs.python.org/library/functions...
65
2009-09-09T19:41:52Z
1,401,900
<p><code>inspect.getmro(cls)</code> works for both new and old style classes and returns the same as <code>NewClass.mro()</code>: a list of the class and all its base classes.</p> <pre><code>&gt;&gt;&gt; class A(object): &gt;&gt;&gt; pass &gt;&gt;&gt; &gt;&gt;&gt; class B(A): &gt;&gt;&gt; pass &gt;&gt;&gt; &gt...
102
2009-09-09T20:28:21Z
[ "python", "class", "inheritance", "oop", "introspection" ]
How can the euclidean distance be calculated with numpy?
1,401,712
<p>I have two points in 3D:</p> <pre><code>(xa, ya, za) (xb, yb, zb) </code></pre> <p>And I want to calculate the distance:</p> <pre><code>dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (za-zb)^2) </code></pre> <p>What's the best way to do this with Numpy, or with Python in general? I have:</p> <pre><code>a = numpy.array((x...
150
2009-09-09T19:48:49Z
1,401,755
<p>Another instance of <a href="http://stackoverflow.com/questions/13289/can-you-share-your-secrets-or-best-practices-for-problem-solving/13336#13336">this problem solving method</a>. As soon as I submitted the question I got it:</p> <pre><code>def dist(x,y): return numpy.sqrt(numpy.sum((x-y)**2)) a = numpy.a...
16
2009-09-09T19:56:36Z
[ "python", "numpy", "euclidean-distance" ]
How can the euclidean distance be calculated with numpy?
1,401,712
<p>I have two points in 3D:</p> <pre><code>(xa, ya, za) (xb, yb, zb) </code></pre> <p>And I want to calculate the distance:</p> <pre><code>dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (za-zb)^2) </code></pre> <p>What's the best way to do this with Numpy, or with Python in general? I have:</p> <pre><code>a = numpy.array((x...
150
2009-09-09T19:48:49Z
1,401,828
<p>Use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.norm.html"><code>numpy.linalg.norm</code></a>:</p> <pre><code>dist = numpy.linalg.norm(a-b) </code></pre>
265
2009-09-09T20:12:50Z
[ "python", "numpy", "euclidean-distance" ]
How can the euclidean distance be calculated with numpy?
1,401,712
<p>I have two points in 3D:</p> <pre><code>(xa, ya, za) (xb, yb, zb) </code></pre> <p>And I want to calculate the distance:</p> <pre><code>dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (za-zb)^2) </code></pre> <p>What's the best way to do this with Numpy, or with Python in general? I have:</p> <pre><code>a = numpy.array((x...
150
2009-09-09T19:48:49Z
4,169,284
<pre><code>dist = numpy.linalg.norm(a-b) </code></pre> <p>Is a nice one line answer. However, if speed is a concern I would recommend experimenting on your machine. I found that using the <code>math</code> library's <code>sqrt</code> with the <code>**</code> operator for the square is much faster on my machine than ...
3
2010-11-12T21:40:53Z
[ "python", "numpy", "euclidean-distance" ]
How can the euclidean distance be calculated with numpy?
1,401,712
<p>I have two points in 3D:</p> <pre><code>(xa, ya, za) (xb, yb, zb) </code></pre> <p>And I want to calculate the distance:</p> <pre><code>dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (za-zb)^2) </code></pre> <p>What's the best way to do this with Numpy, or with Python in general? I have:</p> <pre><code>a = numpy.array((x...
150
2009-09-09T19:48:49Z
7,373,947
<p>You can just substract the vectors and then innerproduct.</p> <p>Following your example</p> <pre><code>a = numpy.array((xa,ya,za)) b = numpy.array((xb,yb,zb)) tmp = a - b sum_squared = numpy.dot(tmp.T , tmp) result sqrt(sum_squared) </code></pre> <p>Simple Code an easy to understand.</p>
2
2011-09-10T19:08:12Z
[ "python", "numpy", "euclidean-distance" ]
How can the euclidean distance be calculated with numpy?
1,401,712
<p>I have two points in 3D:</p> <pre><code>(xa, ya, za) (xb, yb, zb) </code></pre> <p>And I want to calculate the distance:</p> <pre><code>dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (za-zb)^2) </code></pre> <p>What's the best way to do this with Numpy, or with Python in general? I have:</p> <pre><code>a = numpy.array((x...
150
2009-09-09T19:48:49Z
13,155,932
<p>Can be done like this, don't know how fast it is but its no numpy.</p> <pre><code>from math import sqrt a = (1,2,3) #data point 1 b = (4,5,6) #data point 2 print sqrt(sum( (a - b)**2 for a, b in zip(a, b))) </code></pre>
6
2012-10-31T10:33:48Z
[ "python", "numpy", "euclidean-distance" ]
How can the euclidean distance be calculated with numpy?
1,401,712
<p>I have two points in 3D:</p> <pre><code>(xa, ya, za) (xb, yb, zb) </code></pre> <p>And I want to calculate the distance:</p> <pre><code>dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (za-zb)^2) </code></pre> <p>What's the best way to do this with Numpy, or with Python in general? I have:</p> <pre><code>a = numpy.array((x...
150
2009-09-09T19:48:49Z
20,943,162
<p>I find a 'dist' function in matplotlib.mlab, but i don't think it's handy enough. I'm posting it here just for reference.</p> <pre><code>import numpy as np import matplotlib as plt a = np.array([1,2,3]) b = np.array([2,3,4]) # distance between a and b dis = plt.mlab.dist(a,b) </code></pre>
5
2014-01-06T04:46:53Z
[ "python", "numpy", "euclidean-distance" ]
How can the euclidean distance be calculated with numpy?
1,401,712
<p>I have two points in 3D:</p> <pre><code>(xa, ya, za) (xb, yb, zb) </code></pre> <p>And I want to calculate the distance:</p> <pre><code>dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (za-zb)^2) </code></pre> <p>What's the best way to do this with Numpy, or with Python in general? I have:</p> <pre><code>a = numpy.array((x...
150
2009-09-09T19:48:49Z
21,986,532
<p>There's a function for that in SciPy, it's called <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.euclidean.html#scipy.spatial.distance.euclidean">Euclidean</a></p> <p>example:</p> <pre><code>from scipy.spatial import distance a = (1,2,3) b = (4,5,6) dst = distance.euclidean(a,b...
41
2014-02-24T11:32:29Z
[ "python", "numpy", "euclidean-distance" ]
How can the euclidean distance be calculated with numpy?
1,401,712
<p>I have two points in 3D:</p> <pre><code>(xa, ya, za) (xb, yb, zb) </code></pre> <p>And I want to calculate the distance:</p> <pre><code>dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (za-zb)^2) </code></pre> <p>What's the best way to do this with Numpy, or with Python in general? I have:</p> <pre><code>a = numpy.array((x...
150
2009-09-09T19:48:49Z
37,283,639
<p>Here's some concise code for Euclidean distance in Python given two points represented as lists in Python.</p> <pre><code>def distance(v1,v2): return sum([(x-y)**2 for (x,y) in zip(v1,v2)])**(0.5) </code></pre>
1
2016-05-17T18:22:33Z
[ "python", "numpy", "euclidean-distance" ]
How can the euclidean distance be calculated with numpy?
1,401,712
<p>I have two points in 3D:</p> <pre><code>(xa, ya, za) (xb, yb, zb) </code></pre> <p>And I want to calculate the distance:</p> <pre><code>dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (za-zb)^2) </code></pre> <p>What's the best way to do this with Numpy, or with Python in general? I have:</p> <pre><code>a = numpy.array((x...
150
2009-09-09T19:48:49Z
39,301,337
<p>I like np.dot (dot product): </p> <pre><code>a = numpy.array((xa,ya,za)) b = numpy.array((xb,yb,zb)) distance = (np.dot(a-b,a-b))**.5 </code></pre>
1
2016-09-02T22:14:11Z
[ "python", "numpy", "euclidean-distance" ]
Convert list of objects to a list of integers and a lookup table
1,401,721
<p>To illustrate what I mean by this, here is an example</p> <pre><code>messages = [ ('Ricky', 'Steve', 'SMS'), ('Steve', 'Karl', 'SMS'), ('Karl', 'Nora', 'Email') ] </code></pre> <p>I want to convert this list and a definition of groups to a list of integers and a lookup dictionary so that each elemen...
4
2009-09-09T19:50:22Z
1,401,738
<p>Here is my own solution - I doubt it's the best</p> <pre><code>def create_lookup_list(input_list, groups): # use a dictionary for the indices so that the index lookup # is fast (not necessarily a requirement) indices = dict((group, {}) for group in groups) output = [] # assign indices by iter...
1
2009-09-09T19:53:48Z
[ "python", "lookup" ]
Convert list of objects to a list of integers and a lookup table
1,401,721
<p>To illustrate what I mean by this, here is an example</p> <pre><code>messages = [ ('Ricky', 'Steve', 'SMS'), ('Steve', 'Karl', 'SMS'), ('Karl', 'Nora', 'Email') ] </code></pre> <p>I want to convert this list and a definition of groups to a list of integers and a lookup dictionary so that each elemen...
4
2009-09-09T19:50:22Z
1,401,852
<p>Mine's about the same length and complexity:</p> <pre><code>import collections def create_lookup_list(messages, labels): # Collect all the values lookup = collections.defaultdict(set) for msg in messages: for l, v in zip(labels, msg): lookup[l].add(v) # Make the value sets lis...
2
2009-09-09T20:17:44Z
[ "python", "lookup" ]
Convert list of objects to a list of integers and a lookup table
1,401,721
<p>To illustrate what I mean by this, here is an example</p> <pre><code>messages = [ ('Ricky', 'Steve', 'SMS'), ('Steve', 'Karl', 'SMS'), ('Karl', 'Nora', 'Email') ] </code></pre> <p>I want to convert this list and a definition of groups to a list of integers and a lookup dictionary so that each elemen...
4
2009-09-09T19:50:22Z
1,401,862
<p>Here is my solution, it's not better - it's just different :)</p> <pre><code>def create_lookup_list(data, keys): encoded = [] table = dict([(key, []) for key in keys]) for record in data: msg_int = [] for key, value in zip(keys, record): if value not in table[key]: table[k...
0
2009-09-09T20:20:25Z
[ "python", "lookup" ]
Convert list of objects to a list of integers and a lookup table
1,401,721
<p>To illustrate what I mean by this, here is an example</p> <pre><code>messages = [ ('Ricky', 'Steve', 'SMS'), ('Steve', 'Karl', 'SMS'), ('Karl', 'Nora', 'Email') ] </code></pre> <p>I want to convert this list and a definition of groups to a list of integers and a lookup dictionary so that each elemen...
4
2009-09-09T19:50:22Z
1,401,890
<p>This is a bit simpler, and more direct.</p> <pre><code>from collections import defaultdict def create_lookup_list( messages, schema ): def mapped_rows( messages ): for row in messages: newRow= [] for col, value in zip(schema,row): if value not in lookups[col]: ...
1
2009-09-09T20:26:21Z
[ "python", "lookup" ]
Convert list of objects to a list of integers and a lookup table
1,401,721
<p>To illustrate what I mean by this, here is an example</p> <pre><code>messages = [ ('Ricky', 'Steve', 'SMS'), ('Steve', 'Karl', 'SMS'), ('Karl', 'Nora', 'Email') ] </code></pre> <p>I want to convert this list and a definition of groups to a list of integers and a lookup dictionary so that each elemen...
4
2009-09-09T19:50:22Z
1,402,043
<p>Here is mine, the inner function lets me write the index-tuple as a generator.</p> <pre><code>def create_lookup_list( data, format): table = {} indices = [] def get_index( item, form ): row = table.setdefault( form, [] ) try: return row.index( item ) except ValueError...
0
2009-09-09T20:55:53Z
[ "python", "lookup" ]
Convert list of objects to a list of integers and a lookup table
1,401,721
<p>To illustrate what I mean by this, here is an example</p> <pre><code>messages = [ ('Ricky', 'Steve', 'SMS'), ('Steve', 'Karl', 'SMS'), ('Karl', 'Nora', 'Email') ] </code></pre> <p>I want to convert this list and a definition of groups to a list of integers and a lookup dictionary so that each elemen...
4
2009-09-09T19:50:22Z
1,402,079
<p>In Otto's answer (or anyone else's with string->id dicts), I'd replace (if obsessing over speed is your thing):</p> <pre><code># create the lookup table lookup_dict = {} for group in indices: lookup_dict[group] = sorted(indices[group].keys(), lambda e1, e2: indices[group][e1]-indices[group][e2]) </c...
2
2009-09-09T21:01:32Z
[ "python", "lookup" ]
Convert list of objects to a list of integers and a lookup table
1,401,721
<p>To illustrate what I mean by this, here is an example</p> <pre><code>messages = [ ('Ricky', 'Steve', 'SMS'), ('Steve', 'Karl', 'SMS'), ('Karl', 'Nora', 'Email') ] </code></pre> <p>I want to convert this list and a definition of groups to a list of integers and a lookup dictionary so that each elemen...
4
2009-09-09T19:50:22Z
1,402,381
<p><code>defaultdict</code> combined with the <code>itertools.count().next</code> method is a good way to assign identifiers to unique items. Here's an example of how to apply this in your case:</p> <pre><code>from itertools import count from collections import defaultdict def create_lookup_list(data, domains): d...
3
2009-09-09T22:04:41Z
[ "python", "lookup" ]
Why is there no list.clear() method in python?
1,401,933
<p>Inspired by <a href="http://stackoverflow.com/questions/1400608/how-to-empty-a-list-in-python">this question.</a></p> <p>Why is there no list.clear() method in python? I've found several questions here that say the correct way to do it is one of the following, but no one has said why there isn't just a method for i...
36
2009-09-09T20:34:42Z
1,402,256
<p>In the threads you linked <a href="https://mail.python.org/pipermail/python-list/2006-April/384992.html" rel="nofollow">Raymond Hettinger pretty much sums up the pros and cons</a> of adding that method. When it comes to language design, it's really important to be conservative. See for example the <a href="http://bl...
18
2009-09-09T21:40:04Z
[ "python", "list", "clear" ]
Why is there no list.clear() method in python?
1,401,933
<p>Inspired by <a href="http://stackoverflow.com/questions/1400608/how-to-empty-a-list-in-python">this question.</a></p> <p>Why is there no list.clear() method in python? I've found several questions here that say the correct way to do it is one of the following, but no one has said why there isn't just a method for i...
36
2009-09-09T20:34:42Z
1,402,334
<p>I can't answer to the why; but there absolutely should be one, so different types of objects can be cleared with the same interface.</p> <p>An obvious, simple example:</p> <pre><code>def process_and_clear_requests(reqs): for r in reqs: do_req(r) reqs.clear() </code></pre> <p>This only requires tha...
6
2009-09-09T21:51:57Z
[ "python", "list", "clear" ]
Why is there no list.clear() method in python?
1,401,933
<p>Inspired by <a href="http://stackoverflow.com/questions/1400608/how-to-empty-a-list-in-python">this question.</a></p> <p>Why is there no list.clear() method in python? I've found several questions here that say the correct way to do it is one of the following, but no one has said why there isn't just a method for i...
36
2009-09-09T20:34:42Z
6,675,045
<p>While there was no <code>list.clear()</code> when this question was asked, 3.3 now has one (as requested in <a href="http://bugs.python.org/issue10516">http://bugs.python.org/issue10516</a>). Additionally, <code>clear()</code> methods have been added to <a href="http://docs.python.org/dev/library/functions.html#byte...
13
2011-07-13T06:43:22Z
[ "python", "list", "clear" ]
Why is there no list.clear() method in python?
1,401,933
<p>Inspired by <a href="http://stackoverflow.com/questions/1400608/how-to-empty-a-list-in-python">this question.</a></p> <p>Why is there no list.clear() method in python? I've found several questions here that say the correct way to do it is one of the following, but no one has said why there isn't just a method for i...
36
2009-09-09T20:34:42Z
13,714,092
<p>The question should be why <code>clear</code> was deemed necessary in the first place. The following works to clear any Python collection that I can think of.</p> <pre><code>def clear(x): return type(x)() &gt;&gt;&gt; s = {1, 2, 3} &gt;&gt;&gt; s set([1, 2, 3]) &gt;&gt;&gt; s = clear(s) &gt;&gt;&gt; s set([]) ...
-6
2012-12-04T23:54:39Z
[ "python", "list", "clear" ]
Why is there no list.clear() method in python?
1,401,933
<p>Inspired by <a href="http://stackoverflow.com/questions/1400608/how-to-empty-a-list-in-python">this question.</a></p> <p>Why is there no list.clear() method in python? I've found several questions here that say the correct way to do it is one of the following, but no one has said why there isn't just a method for i...
36
2009-09-09T20:34:42Z
27,305,592
<p>When testing, it is often useful to setup the data forming the domain of the tests in global variables, so that tests can build on one another if necessary/simpler. In such cases, having a method to clear the list would allow you to do it without the need to declare those variables as global within a function (i.e. ...
0
2014-12-04T22:43:18Z
[ "python", "list", "clear" ]
Script to connect to a web page
1,401,941
<p>Looking for a python script that would simply connect to a web page (maybe some querystring parameters).</p> <p>I am going to run this script as a batch job in unix.</p>
1
2009-09-09T20:35:44Z
1,401,954
<p><a href="http://docs.python.org/library/urllib2.html">urllib2</a> will do what you want and it's pretty simple to use.</p> <pre><code>import urllib import urllib2 params = {'param1': 'value1'} req = urllib2.Request("http://someurl", urllib.urlencode(params)) res = urllib2.urlopen(req) data = res.read() </code></...
9
2009-09-09T20:39:36Z
[ "python" ]