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
on click event in wx.Panel?
2,367,076
<p>how can I click on a wx.Panel and that changes its color? What is the name of the event.</p> <p>(I want to do a similar thing as Firefox Extras)</p> <p>Thanks in advance! :)</p>
8
2010-03-02T21:49:51Z
2,367,509
<p>A quick google for wxpython mouse events turns up <a href="http://www.wxpython.org/docs/api/wx.MouseEvent-class.html">http://www.wxpython.org/docs/api/wx.MouseEvent-class.html</a></p> <p>So using this, you could do something like:</p> <pre><code>class MyFrame(wx.Frame): def __init__(self): wx.Frame.__i...
6
2010-03-02T22:54:44Z
[ "python", "wxpython", "panel" ]
Is there a way to create a python object that will be not sortable?
2,367,119
<p>Is there a possibility to create any python object that will be not sortable? So that will be an exception when trying to sort a list of that objects? I created a very simple class, didn't define any comparison methods, but still instances of this class are comparable and thus sortable. Maybe, my class inherits comp...
8
2010-03-02T21:55:28Z
2,367,139
<p>You could define a <code>__cmp__</code> method on the class and always raise an exception when it is called. That might do the trick.</p> <p>Out of curiosity, why?</p>
7
2010-03-02T21:58:48Z
[ "python" ]
Is there a way to create a python object that will be not sortable?
2,367,119
<p>Is there a possibility to create any python object that will be not sortable? So that will be an exception when trying to sort a list of that objects? I created a very simple class, didn't define any comparison methods, but still instances of this class are comparable and thus sortable. Maybe, my class inherits comp...
8
2010-03-02T21:55:28Z
2,367,189
<p>Why don't you just write a class that contains a list object and provides methods to access the data inside? By doing that you would effectively hide the list and therefore prevent them from sorting it.</p>
0
2010-03-02T22:07:07Z
[ "python" ]
Is there a way to create a python object that will be not sortable?
2,367,119
<p>Is there a possibility to create any python object that will be not sortable? So that will be an exception when trying to sort a list of that objects? I created a very simple class, didn't define any comparison methods, but still instances of this class are comparable and thus sortable. Maybe, my class inherits comp...
8
2010-03-02T21:55:28Z
2,367,223
<p>As Will McCutchen has mentioned, you can define a <code>__cmp__</code> method that raises an exception to prevent garden variety sorting. Something like this:</p> <pre><code>class Foo(object): def __cmp__(self, other): raise Exception() a = [Foo(), Foo(), Foo()] a.sort() Traceback (most recent call las...
1
2010-03-02T22:10:51Z
[ "python" ]
Is there a way to create a python object that will be not sortable?
2,367,119
<p>Is there a possibility to create any python object that will be not sortable? So that will be an exception when trying to sort a list of that objects? I created a very simple class, didn't define any comparison methods, but still instances of this class are comparable and thus sortable. Maybe, my class inherits comp...
8
2010-03-02T21:55:28Z
2,367,228
<p>The default list sorting uses the built-in <code>cmp()</code> function on its elements. The <code>cmp()</code> function checks if its arguments (2 elements from your list) have a <code>__cmp__()</code> method. If yes, this method is used for comparison. Otherwise, as in your case, the argument object IDs (return val...
1
2010-03-02T22:12:02Z
[ "python" ]
Is there a way to create a python object that will be not sortable?
2,367,119
<p>Is there a possibility to create any python object that will be not sortable? So that will be an exception when trying to sort a list of that objects? I created a very simple class, didn't define any comparison methods, but still instances of this class are comparable and thus sortable. Maybe, my class inherits comp...
8
2010-03-02T21:55:28Z
2,367,277
<p>Sets don't have a total ordering</p> <pre><code>&gt;&gt;&gt; s=set((1,2,3)) &gt;&gt;&gt; t=set("abc") &gt;&gt;&gt; s&lt;t False &gt;&gt;&gt; t&lt;s False &gt;&gt;&gt; </code></pre> <p>But no exception is raise when you try to sort them</p> <pre><code>&gt;&gt;&gt; sorted([s,t]) [set([1, 2, 3]), set(['a', 'c', 'b'...
0
2010-03-02T22:18:27Z
[ "python" ]
Is there a way to create a python object that will be not sortable?
2,367,119
<p>Is there a possibility to create any python object that will be not sortable? So that will be an exception when trying to sort a list of that objects? I created a very simple class, didn't define any comparison methods, but still instances of this class are comparable and thus sortable. Maybe, my class inherits comp...
8
2010-03-02T21:55:28Z
2,383,476
<p>For what it's worth, in Python 3 the default will be for new items to not be comparable (and hence not sortable). In Python 2, you have to explicitly create a <code>__cmp__</code> or <code>__lt__</code> method, as others have said.</p>
1
2010-03-04T23:22:39Z
[ "python" ]
Is there a way to create a python object that will be not sortable?
2,367,119
<p>Is there a possibility to create any python object that will be not sortable? So that will be an exception when trying to sort a list of that objects? I created a very simple class, didn't define any comparison methods, but still instances of this class are comparable and thus sortable. Maybe, my class inherits comp...
8
2010-03-02T21:55:28Z
2,527,793
<p>The python sort algorithms use the <code>__lt__</code> special method. Keeping in mind that using the <code>cmp</code> and <code>key</code> arguments of the sorting function and methods, it is suggested that your class defines a method:</p> <pre><code>def __lt__(self, other): raise NotImplementedError </code></...
0
2010-03-27T01:28:31Z
[ "python" ]
Sed script to edit csv file Or Python
2,367,338
<p>In our project we need to import the csv file to postgres. There are multiple types of files meaning the length of the file changes as some files are with fewer columns and some with all of them.</p> <p>We need a fast way to import this file to postgres. I want to use COPY FROM of the postgres since the speed requi...
5
2010-03-02T22:28:05Z
2,367,352
<p>To answer your first question, <code>sed</code> would have less overhead, but might be painful. <code>awk</code> would be a little better (it's more powerful). Perl or Python have more overhead, but would be easier to work with (regarding Perl, that's maybe a little subjective ;). Personally, I'd use Perl).</p> <p>...
2
2010-03-02T22:30:45Z
[ "python", "sed", "awk", "text-processing" ]
Sed script to edit csv file Or Python
2,367,338
<p>In our project we need to import the csv file to postgres. There are multiple types of files meaning the length of the file changes as some files are with fewer columns and some with all of them.</p> <p>We need a fast way to import this file to postgres. I want to use COPY FROM of the postgres since the speed requi...
5
2010-03-02T22:28:05Z
2,367,390
<pre><code>sed 's/^([^,]*,){4}/&amp;,/' &lt;original.csv &gt;output.csv </code></pre> <p>Will add a comma after the 4th comma separated field (by matching 4 repetitions of <code>&lt;anything&gt;,</code> and then adding a comma after that). Note that there is a catch; make sure none of these values are quoted strings w...
0
2010-03-02T22:34:57Z
[ "python", "sed", "awk", "text-processing" ]
Sed script to edit csv file Or Python
2,367,338
<p>In our project we need to import the csv file to postgres. There are multiple types of files meaning the length of the file changes as some files are with fewer columns and some with all of them.</p> <p>We need a fast way to import this file to postgres. I want to use COPY FROM of the postgres since the speed requi...
5
2010-03-02T22:28:05Z
2,367,397
<p>Don't know regarding speed, but here is sed expr that should do the job:</p> <pre><code>sed -i 's/\(\([^,]*,\)\{4\}\)/\1,/' file_name </code></pre> <p>Just replace 4 by desured number of columns</p>
0
2010-03-02T22:35:52Z
[ "python", "sed", "awk", "text-processing" ]
Sed script to edit csv file Or Python
2,367,338
<p>In our project we need to import the csv file to postgres. There are multiple types of files meaning the length of the file changes as some files are with fewer columns and some with all of them.</p> <p>We need a fast way to import this file to postgres. I want to use COPY FROM of the postgres since the speed requi...
5
2010-03-02T22:28:05Z
2,367,408
<p>Depending on your requirements, consider using <a href="http://en.wikipedia.org/wiki/Etl" rel="nofollow">ETL</a> software for this and future tasks. Tools like <a href="http://www.pentaho.com/" rel="nofollow">Pentaho</a> and <a href="http://www.talend.com/index.php" rel="nofollow">Talend</a> offer you a great deal ...
0
2010-03-02T22:37:36Z
[ "python", "sed", "awk", "text-processing" ]
Sed script to edit csv file Or Python
2,367,338
<p>In our project we need to import the csv file to postgres. There are multiple types of files meaning the length of the file changes as some files are with fewer columns and some with all of them.</p> <p>We need a fast way to import this file to postgres. I want to use COPY FROM of the postgres since the speed requi...
5
2010-03-02T22:28:05Z
2,367,565
<p>Are you aware of the fact that <a href="http://www.postgresql.org/docs/8.3/static/sql-copy.html" rel="nofollow"><code>COPY FROM</code></a> lets you specify which columns (as well as in which order they) are to be imported?</p> <pre><code>COPY tablename ( column1, column2, ... ) FROM ... </code></pre> <p>Specifying...
3
2010-03-02T23:03:10Z
[ "python", "sed", "awk", "text-processing" ]
Sed script to edit csv file Or Python
2,367,338
<p>In our project we need to import the csv file to postgres. There are multiple types of files meaning the length of the file changes as some files are with fewer columns and some with all of them.</p> <p>We need a fast way to import this file to postgres. I want to use COPY FROM of the postgres since the speed requi...
5
2010-03-02T22:28:05Z
2,367,845
<p>@OP, you are processing a csv file, which have distinct fields and delimiters. Use a tool that can split on delimiters and give you fields to work with easily. sed is not one of them, although it can be done, as some of the answers suggested, but you will get sed regex that is hard to read when it gets complicated. ...
2
2010-03-02T23:56:21Z
[ "python", "sed", "awk", "text-processing" ]
In Django, how do I make my sessions persist through http://mydomain.com and http://www.mydomain.com?
2,367,448
<p>If I set a session in mydomain.com, it doesn't work on www.mydomain.com. I'd like all subdomains, and all www, to be treated as one big thing.</p> <p>mydomain.com and all its subdomains should have all the session cookies of everything.</p> <p>Do I change this in Apache2? </p> <p>edit I think I found the solution...
2
2010-03-02T22:44:07Z
2,367,519
<p>I think I found the solution: SESSION_COOKIE_DOMAIN = ".mydomain.com" </p>
2
2010-03-02T22:56:20Z
[ "python", "django", "apache", "session" ]
In mako, how can I cycle through a list and display each value?
2,367,682
<p>I have a Python list that I'm supplying to the template:</p> <pre><code>{'error_name':'Please enter a name', 'error_email':'Please enter an email'} </code></pre> <p>And would like to display:</p> <pre><code>&lt;ul&gt; &lt;li&gt;Please enter a name&lt;/li&gt; &lt;li&gt;Please enter an email&lt;/li&gt; &lt;/ul&gt;...
3
2010-03-02T23:22:08Z
2,368,108
<pre><code>&lt;ul&gt; % for prompt in whateveryoucalledit.values(): &lt;li&gt;${prompt}&lt;/li&gt; % endfor &lt;/ul&gt; </code></pre> <p>where <code>whateveryoucalledit</code> it is the name under which you chose to pass that container (which, as a comment noticed, is a dict, not a list). The nice thing about mako,...
3
2010-03-03T00:59:07Z
[ "python", "templates", "pylons", "mako" ]
How to convert from unicode with python
2,367,744
<p>In database I have saved string in which the problem word is: za\u0161\u010diten. </p> <p>[ed.: the "problem word" seems to have changed]</p> <p>When I want to present this string on my page (with <strong>req.write(string)</strong>). I get this error: <strong>UnicodeEncodeError: 'ascii' codec can't encode characte...
1
2010-03-02T23:33:21Z
2,367,754
<pre><code>req.write(string.encode(encoding)) </code></pre> <p>where <code>encoding</code> is the charset you declared in the <code>Content-Type</code> header.</p>
2
2010-03-02T23:36:13Z
[ "python", "unicode" ]
How to convert from unicode with python
2,367,744
<p>In database I have saved string in which the problem word is: za\u0161\u010diten. </p> <p>[ed.: the "problem word" seems to have changed]</p> <p>When I want to present this string on my page (with <strong>req.write(string)</strong>). I get this error: <strong>UnicodeEncodeError: 'ascii' codec can't encode characte...
1
2010-03-02T23:33:21Z
2,368,191
<p>If <code>string</code> refers to the <code>string</code> module, then yes that <code>string</code> doesn't have <code>encode</code>. If <code>string</code> is in fact a <code>unicode</code> object, then it does have an <code>encode</code> but perhaps <code>string</code> may in fact be an <code>str</code> object.</p>...
0
2010-03-03T01:20:08Z
[ "python", "unicode" ]
Django - Get Foreign key objects in single query?
2,367,747
<p>I'm finding django foreign keys a bit confusing, is there any way to do the view below, using a single query?</p> <pre><code># Model class Programme(models.Model): name = models.CharField(max_length = 64) class Actor(models.Model): programme = models.ForeignKey(Programme) name = models.CharField(max_le...
5
2010-03-02T23:34:23Z
2,367,782
<p>You query <code>Programme</code> and assign to <code>programme</code>, but you never use the result anywhere. Just remove that line.</p>
8
2010-03-02T23:42:21Z
[ "python", "django", "foreign-key-relationship" ]
Django - Get Foreign key objects in single query?
2,367,747
<p>I'm finding django foreign keys a bit confusing, is there any way to do the view below, using a single query?</p> <pre><code># Model class Programme(models.Model): name = models.CharField(max_length = 64) class Actor(models.Model): programme = models.ForeignKey(Programme) name = models.CharField(max_le...
5
2010-03-02T23:34:23Z
11,628,949
<p>I think you are looking to something like that:</p> <p><a href="https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related" rel="nofollow">https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related</a></p> <p>which are select_related, you put before final get. That is your line: </p...
4
2012-07-24T10:30:49Z
[ "python", "django", "foreign-key-relationship" ]
How do I implement polymorphic arithmetic operators pythonicly?
2,367,753
<p>I'm trying to create a class that will allow me to add/multiply/divide objects of the same class together or add/multiply numeric arguments to each member of the class</p> <p>So my class is for coordinates (I am aware there are great packages out there that do everything I want better than I could ever hope to on m...
4
2010-03-02T23:36:12Z
2,367,775
<p>You are going to have to try to determine what type <code>other</code> is, at least to the extent that it's compatible with <code>GpsPoint</code>. If you can't figure it out then just return <code>NotImplemented</code> and the interpreter will try to handle it from there.</p>
2
2010-03-02T23:39:47Z
[ "python", "polymorphism", "type-conversion" ]
How do I implement polymorphic arithmetic operators pythonicly?
2,367,753
<p>I'm trying to create a class that will allow me to add/multiply/divide objects of the same class together or add/multiply numeric arguments to each member of the class</p> <p>So my class is for coordinates (I am aware there are great packages out there that do everything I want better than I could ever hope to on m...
4
2010-03-02T23:36:12Z
2,367,780
<p>Short answer: use isinstance().</p> <p>There is no other way to dermine the type of "other" in your methods. Also, if you check the sources of many python libraries you will find that there are lots of places where isinstance() is used. So this is just the state of art in python:-). </p>
0
2010-03-02T23:41:44Z
[ "python", "polymorphism", "type-conversion" ]
How do I implement polymorphic arithmetic operators pythonicly?
2,367,753
<p>I'm trying to create a class that will allow me to add/multiply/divide objects of the same class together or add/multiply numeric arguments to each member of the class</p> <p>So my class is for coordinates (I am aware there are great packages out there that do everything I want better than I could ever hope to on m...
4
2010-03-02T23:36:12Z
2,367,793
<p>The "Pythonic" way is to "ask forgiveness rather than permission" - that is, instead of checking the type beforehand, try to add and, if it fails, catch the exception and deal with it, like so:</p> <pre><code>class GpsPoint(object): """A class for representing gps coordinates""" def __init__(self, x, y, z):...
6
2010-03-02T23:44:55Z
[ "python", "polymorphism", "type-conversion" ]
How do I know if jobs have been/are performing? - Crontab
2,367,892
<p>I have followed the suggestion in <a href="http://stackoverflow.com/questions/2339725/creating-a-cron-job-linux-python">this question</a></p> <p>as I am using Django, I have set the script to store date and time of each run of the script in the db, but no entry has been stored yet in the database.</p> <hr> <p>Is ...
3
2010-03-03T00:06:27Z
2,367,954
<p>First, I would probably configure cron to mail yourself any output by using <code>MAILTO</code>:</p> <p>In /etc/crontab:</p> <pre><code>MAILTO=username </code></pre> <p>Second, I usually add something to my script that (almost) cannot possibly fail, like the following:</p> <pre><code>#!/bin/sh echo "$0 ran on `d...
5
2010-03-03T00:20:01Z
[ "python", "linux", "django", "crontab" ]
How do I know if jobs have been/are performing? - Crontab
2,367,892
<p>I have followed the suggestion in <a href="http://stackoverflow.com/questions/2339725/creating-a-cron-job-linux-python">this question</a></p> <p>as I am using Django, I have set the script to store date and time of each run of the script in the db, but no entry has been stored yet in the database.</p> <hr> <p>Is ...
3
2010-03-03T00:06:27Z
2,368,517
<p>If you have sendmail installed, you can add the following to '/etc/aliases'</p> <p>root: your_name@domain.com</p> <p>After you do that, update the aliases running this command:</p> <pre><code>sudo newaliases </code></pre> <p>Cron will automatically email you every time a job is run. No need to specify that in t...
2
2010-03-03T03:15:39Z
[ "python", "linux", "django", "crontab" ]
How do I know if jobs have been/are performing? - Crontab
2,367,892
<p>I have followed the suggestion in <a href="http://stackoverflow.com/questions/2339725/creating-a-cron-job-linux-python">this question</a></p> <p>as I am using Django, I have set the script to store date and time of each run of the script in the db, but no entry has been stored yet in the database.</p> <hr> <p>Is ...
3
2010-03-03T00:06:27Z
2,369,004
<p>In addition to setting up cron to send email, you can send the output of cron to a seperate syslog log facility by adding the following to your <code>/etc/syslog.conf</code>.</p> <pre> # Log cron stuff cron.* /var/log/cron.log </pre> <p>This should log a message t...
1
2010-03-03T05:37:05Z
[ "python", "linux", "django", "crontab" ]
Django url.py Different view functions with the same regex name pattern
2,367,918
<p>I'm filtering a few categories (cat1, cat2, cat3) to be rendered by different views then all the rest by other view functions. It is getting unwieldy to keep adding category slugs to the urlpatterns each time one is added. Can I factor that part out of the regex some how?</p> <pre><code>urlpatterns = patterns('ca...
2
2010-03-03T00:11:47Z
2,367,992
<p>I'd personally put this logic in the view rather than the urlspatterns.</p> <p>I would create a list of all the special categories so for this:</p> <pre><code>special_cats = ['cat1','cat2','cat3'] </code></pre> <p>Then for you view you can do something like this:</p> <pre><code>def generic_cat_view(request, cat_...
4
2010-03-03T00:27:58Z
[ "python", "django", "django-urls" ]
Passing JSON to Python script via AJAX
2,368,001
<p>What's the ideal way to pass a large JSON data object from Javascript through AJAX to a Python script?</p>
1
2010-03-03T00:29:34Z
2,368,063
<p>Are you using some web framework? <a href="http://docs.djangoproject.com/en/1.1/" rel="nofollow">Django</a> has pretty decent support for JSON decoding/encoding.</p>
1
2010-03-03T00:47:10Z
[ "javascript", "python", "ajax", "json" ]
Installing easy_install... to get to installing lxml
2,368,008
<p>I've come to grips with the fact that ElementTree isn't going to do what I want it to do. I've checked out the documentation for lxml, and it appears that it will serve my purposes. To get lxml, I need to get easy_install. So I downloaded it from <a href="http://pypi.python.org/pypi/setuptools#cygwin-mac-os-x-linux-...
21
2010-03-03T00:31:19Z
2,368,022
<p>It looks like <code>lxml</code> wants to build an extension that requires access to a C compiler. You will need <code>gcc</code> for that. Try running <code>sudo apt-get install build-essential</code> and that should fix this particular issue.</p>
2
2010-03-03T00:36:51Z
[ "python", "lxml", "easy-install" ]
Installing easy_install... to get to installing lxml
2,368,008
<p>I've come to grips with the fact that ElementTree isn't going to do what I want it to do. I've checked out the documentation for lxml, and it appears that it will serve my purposes. To get lxml, I need to get easy_install. So I downloaded it from <a href="http://pypi.python.org/pypi/setuptools#cygwin-mac-os-x-linux-...
21
2010-03-03T00:31:19Z
2,368,892
<p>First off we don't use easy_install anymore. We use <a href="https://pip.pypa.io/" rel="nofollow">pip</a>. Please use pip instead.</p> <p>To get to your particular troubles, as the comments point out, you're missing GCC. On OS X, <a href="http://developer.apple.com/tools/xcode/" rel="nofollow">Xcode</a> Command Lin...
23
2010-03-03T05:04:57Z
[ "python", "lxml", "easy-install" ]
Installing easy_install... to get to installing lxml
2,368,008
<p>I've come to grips with the fact that ElementTree isn't going to do what I want it to do. I've checked out the documentation for lxml, and it appears that it will serve my purposes. To get lxml, I need to get easy_install. So I downloaded it from <a href="http://pypi.python.org/pypi/setuptools#cygwin-mac-os-x-linux-...
21
2010-03-03T00:31:19Z
4,026,935
<p>Ensure you have libxml2-dev and libxslt1-dev installed</p> <pre><code>apt-get install libxml2-dev apt-get install libxslt1-dev </code></pre> <p>Then your installation should build properly.</p>
13
2010-10-26T18:46:54Z
[ "python", "lxml", "easy-install" ]
Installing easy_install... to get to installing lxml
2,368,008
<p>I've come to grips with the fact that ElementTree isn't going to do what I want it to do. I've checked out the documentation for lxml, and it appears that it will serve my purposes. To get lxml, I need to get easy_install. So I downloaded it from <a href="http://pypi.python.org/pypi/setuptools#cygwin-mac-os-x-linux-...
21
2010-03-03T00:31:19Z
4,205,580
<p>try: <code>sudo apt-get install python-lxml</code></p>
10
2010-11-17T14:51:00Z
[ "python", "lxml", "easy-install" ]
Installing easy_install... to get to installing lxml
2,368,008
<p>I've come to grips with the fact that ElementTree isn't going to do what I want it to do. I've checked out the documentation for lxml, and it appears that it will serve my purposes. To get lxml, I need to get easy_install. So I downloaded it from <a href="http://pypi.python.org/pypi/setuptools#cygwin-mac-os-x-linux-...
21
2010-03-03T00:31:19Z
4,233,083
<p>Make sure that all the following packages are installed on your system first:</p> <pre><code>gcc gcc-c++ python-devel libxml2 libxml2-dev libxslt libxslt-dev </code></pre> <p>You should be able to install them using some variant of: sudo apt-get install sudo yum install </p> <p>Only after all of the above have b...
2
2010-11-20T14:01:29Z
[ "python", "lxml", "easy-install" ]
What are some good ways (quick to implement and easy to tweak) to create an ajax-enabled form in Pylons?
2,368,256
<p>Are there alternatives to manually coding the JS and HTML?</p> <p>Is there a Pylons-way to do this?</p> <p>Sample code is appreciated.</p>
0
2010-03-03T01:45:21Z
2,378,507
<p>Pylons way is to code it yourself or use third-party library. Maybe take a look at tw.forms</p>
1
2010-03-04T10:36:45Z
[ "python", "pylons", "mako" ]
2D integrals in SciPy
2,368,337
<p>I am trying to integrate a multivariable function in <a href="http://en.wikipedia.org/wiki/SciPy">SciPy</a> over a 2D area. What would be the equivalent of the following <a href="http://en.wikipedia.org/wiki/Mathematica">Mathematica</a> code?</p> <pre><code>In[1]:= F[x_, y_] := Cos[x] + Cos[y] In[2]:= Integrate[F...
10
2010-03-03T02:17:10Z
2,368,412
<p>I think it would work something like this:</p> <pre><code>def func(x,y): return cos(x) + cos(y) def func2(y, a, b): return integrate.quad(func, a, b, args=(y,))[0] print integrate.quad(func2, -pi/2, pi/2, args=(-pi/2, pi/2))[0] </code></pre> <p><a href="http://www.wolframalpha.com/input/?i=int+cos%28x%29...
11
2010-03-03T02:43:16Z
[ "python", "integration", "wolfram-mathematica", "scipy", "multidimensional-array" ]
2D integrals in SciPy
2,368,337
<p>I am trying to integrate a multivariable function in <a href="http://en.wikipedia.org/wiki/SciPy">SciPy</a> over a 2D area. What would be the equivalent of the following <a href="http://en.wikipedia.org/wiki/Mathematica">Mathematica</a> code?</p> <pre><code>In[1]:= F[x_, y_] := Cos[x] + Cos[y] In[2]:= Integrate[F...
10
2010-03-03T02:17:10Z
2,374,686
<p>If you want to do symbolic integration, have a look at sympy (<a href="http://code.google.com/p/sympy/" rel="nofollow">code.google.com/p/sympy</a>):</p> <pre><code>import sympy as s x, y = s.symbols('x, y') expr = s.cos(x) + s.sin(y) expr.integrate((x, -s.pi, s.pi), (y, -s.pi, s.pi)) </code></pre>
8
2010-03-03T20:27:55Z
[ "python", "integration", "wolfram-mathematica", "scipy", "multidimensional-array" ]
mod_wsgi excessively slow at startup?
2,368,357
<p>I'm developing a django website which for production uses mod_wsgi - there are barely any visitors so anytime I visit it seems mod wsgi starts up and opens the python processes - it takes about 1-2 entire minutes for it to fully load.</p> <p>Is there anything I could do to not make it slow on initial startup? Is th...
2
2010-03-03T02:26:22Z
2,368,428
<p>It shouldn't take that long even if you used a suboptimal configuration of using embedded mode and Apache prefork MPM. Although, you could make things worse if you had MaxRequestsPerChild set to 1 for Apache processes.</p> <p>Suggestions are, make sure you are using mod_wsgi daemon mode and run with a single multit...
4
2010-03-03T02:49:43Z
[ "python", "django", "apache2", "mod-wsgi" ]
Google App Engine: How can I DRY this basic request handling?
2,368,417
<p>I'm just getting started with Google App Engine. Currently, my app has two pages: one lists all the inventory currently in stock, and the other is a detail page for a given item. I feel that my coding could be much more DRY. (I'm making all the calls to print headers and footers twice, for instance.)</p> <p>Here is...
2
2010-03-03T02:44:42Z
2,368,498
<p>You could make <code>MainPage</code> and <code>Detail</code> be subclasses of <code>MyRequestHandler</code>, and then use a hook to modify the behavior of <code>get</code>:</p> <pre><code>class MyRequestHandler(webapp.RequestHandler): def get(self,*args,**kws): self.response.headers['Content-Type'] = 't...
1
2010-03-03T03:10:56Z
[ "python", "google-app-engine", "code-review", "dry" ]
Google App Engine: How can I DRY this basic request handling?
2,368,417
<p>I'm just getting started with Google App Engine. Currently, my app has two pages: one lists all the inventory currently in stock, and the other is a detail page for a given item. I feel that my coding could be much more DRY. (I'm making all the calls to print headers and footers twice, for instance.)</p> <p>Here is...
2
2010-03-03T02:44:42Z
2,368,533
<p>Here's one possible refactoring:</p> <pre><code>class BaseHandler(webapp.RequestHandler): def get(self, CSIN=None): self.response.headers['Content-Type'] = 'text/html' render('Views/header.html', self, {'title' : 'Store'}) self.response.out.write('&lt;h1&gt;%s&lt;/h1&gt; '% self.h1(CSIN...
6
2010-03-03T03:21:10Z
[ "python", "google-app-engine", "code-review", "dry" ]
Getting info from all related objects in django
2,368,465
<p>I'm trying to do something pretty simple, but I'm new to Django. I have a quiz system set up for an experiment I'm running. </p> <p>The relevant entries in models.py follow:</p> <pre><code>class Flavor(models.Model): name = models.CharField(max_length=100) def __unicode__(self): return self.name class Pa...
0
2010-03-03T02:59:47Z
2,368,591
<p>Well, since no one has helped you yet, here:</p> <pre><code># *snip* -- view: context = { 'test_subjects' : TestSubject.objects.all() } return render_to_response('Template', context) # *snip* # *snip* -- template: {% for test_subject in test_subjects %} {{ test_subject.ip }} {# ... snip ... #} {% empty %} There ar...
0
2010-03-03T03:41:27Z
[ "python", "django", "templates", "object", "views" ]
Why does python + pylons "remember" previously specified class variables?
2,368,482
<p>I have a simple form in python + pylons that submits to a controller. However, each page load doesn't seem to be a fresh instantiation of the class. Rather, class variables specified on the previous page load are still accessible. </p> <p>What's going on here? And what's the solution?</p>
1
2010-03-03T03:07:38Z
2,368,513
<p>Pylons uses a multi-threaded application server and variables are not cleared from request to request. This is a performance issue, as re-instantiating entire class trees would be expensive. Instead of storing the data returned by the user in a class, use a sessions system (<a href="http://pylonshq.com/docs/en/0.9...
1
2010-03-03T03:14:41Z
[ "python", "pylons" ]
Why does python + pylons "remember" previously specified class variables?
2,368,482
<p>I have a simple form in python + pylons that submits to a controller. However, each page load doesn't seem to be a fresh instantiation of the class. Rather, class variables specified on the previous page load are still accessible. </p> <p>What's going on here? And what's the solution?</p>
1
2010-03-03T03:07:38Z
2,368,555
<p>A common programmer oversight is that defining a list [] as a default argument or class initialiser is evaluated only once. If you have class variables such as lists, I recommend you initialise them in <strong>init</strong>. I'll give you an example.</p> <pre><code>&gt;&gt;&gt; class Example(object): ... a = ...
1
2010-03-03T03:26:57Z
[ "python", "pylons" ]
How can I remove a column from a sparse matrix efficiently?
2,368,544
<p>If I am using the sparse.lil_matrix format, how can I remove a column from the matrix easily and efficiently?</p>
10
2010-03-03T03:25:01Z
2,369,121
<p>I've been wanting this myself and in truth there isn't a great built-in way to do it yet. Here's a way to do it. I chose to make a subclass of lil_matrix and add the remove_col function. If you want, you can instead add the removecol function to the lil_matrix class in your <code>lib/site-packages/scipy/sparse/lil.p...
6
2010-03-03T06:10:03Z
[ "python", "matrix", "numpy", "scipy", "algebra" ]
How can I remove a column from a sparse matrix efficiently?
2,368,544
<p>If I am using the sparse.lil_matrix format, how can I remove a column from the matrix easily and efficiently?</p>
10
2010-03-03T03:25:01Z
2,965,954
<pre><code> def removecols(W, col_list): if min(col_list) = W.shape[1]: raise IndexError('column index out of bounds') rows = W.rows data = W.data for i in xrange(M.shape[0]): for j in col_list: pos = bisect_left(rows[i], j) if ...
0
2010-06-03T12:39:45Z
[ "python", "matrix", "numpy", "scipy", "algebra" ]
How can I remove a column from a sparse matrix efficiently?
2,368,544
<p>If I am using the sparse.lil_matrix format, how can I remove a column from the matrix easily and efficiently?</p>
10
2010-03-03T03:25:01Z
10,825,050
<p>I'm new to python so my answer is probably wrong, but I was wondering why something like the following won't be efficient?</p> <p>Lets say your lil_matrix is called mat and that you want to remove the i-th column:</p> <pre><code>mat=hstack( [ mat[:,0:i] , mat[:,i+1:] ] ) </code></pre> <p>Now the matrix will turn ...
0
2012-05-30T22:18:31Z
[ "python", "matrix", "numpy", "scipy", "algebra" ]
How can I remove a column from a sparse matrix efficiently?
2,368,544
<p>If I am using the sparse.lil_matrix format, how can I remove a column from the matrix easily and efficiently?</p>
10
2010-03-03T03:25:01Z
17,202,875
<p>Much simpler and faster. You might not even need the conversion to csr, but I just know for sure that it works with csr sparse matrices and converting between shouldn't be an issue.</p> <pre><code>from scipy import sparse x_new = sparse.lil_matrix(sparse.csr_matrix(x)[:,col_list]) </code></pre>
6
2013-06-19T23:14:18Z
[ "python", "matrix", "numpy", "scipy", "algebra" ]
How can I remove a column from a sparse matrix efficiently?
2,368,544
<p>If I am using the sparse.lil_matrix format, how can I remove a column from the matrix easily and efficiently?</p>
10
2010-03-03T03:25:01Z
31,122,486
<p>For a sparse csr matrix (X) and a list of indices to drop (index_to_drop):</p> <pre><code>to_keep = list(set(xrange(X.shape[1]))-set(index_to_drop)) new_X = X[:,to_keep] </code></pre> <p>It is easy to convert lil_matrices to csr_matrices. Check tocsr() in <a href="http://docs.scipy.org/doc/scipy-0.14.0/refere...
0
2015-06-29T18:00:36Z
[ "python", "matrix", "numpy", "scipy", "algebra" ]
I want my Python script to detect the version and quit gracefully in case of a mismatch
2,368,574
<p>I'd like to make it as general as possible - e.g. handle as many versions as possible.</p> <p>Since version 3 is not backwards compatible with version 2, I want to make sure that I use the right print statement.</p> <p>Please let me know if you have questions and feel free to share related knowledge having to do w...
3
2010-03-03T03:34:36Z
2,368,590
<p>In order to get around syntax errors you would have to use conditional imports, if you want to mix syntax between versions 2 and 3.</p> <pre><code># just psuedocode if version is x: import lib_x # contains version x implementation else: import lib_y # contains version y compatible implementation </code></pre>...
7
2010-03-03T03:41:10Z
[ "python", "version" ]
I want my Python script to detect the version and quit gracefully in case of a mismatch
2,368,574
<p>I'd like to make it as general as possible - e.g. handle as many versions as possible.</p> <p>Since version 3 is not backwards compatible with version 2, I want to make sure that I use the right print statement.</p> <p>Please let me know if you have questions and feel free to share related knowledge having to do w...
3
2010-03-03T03:34:36Z
2,368,596
<p>FYI, if you ever want to port 2.x scripts to 3.x, you can use <a href="http://docs.python.org/library/2to3.html" rel="nofollow">2to3 source conversion tool</a>.</p>
2
2010-03-03T03:42:48Z
[ "python", "version" ]
I want my Python script to detect the version and quit gracefully in case of a mismatch
2,368,574
<p>I'd like to make it as general as possible - e.g. handle as many versions as possible.</p> <p>Since version 3 is not backwards compatible with version 2, I want to make sure that I use the right print statement.</p> <p>Please let me know if you have questions and feel free to share related knowledge having to do w...
3
2010-03-03T03:34:36Z
2,368,609
<p>The <code>sys</code> module also contains the version info (first available in version 2.0):</p> <pre><code>import sys if sys.version_info[0] == 2: print("You are using Python 2.x") elif sys.version_info[0] == 3: print("You are using Python 3.x") </code></pre>
7
2010-03-03T03:48:45Z
[ "python", "version" ]
I want my Python script to detect the version and quit gracefully in case of a mismatch
2,368,574
<p>I'd like to make it as general as possible - e.g. handle as many versions as possible.</p> <p>Since version 3 is not backwards compatible with version 2, I want to make sure that I use the right print statement.</p> <p>Please let me know if you have questions and feel free to share related knowledge having to do w...
3
2010-03-03T03:34:36Z
2,368,677
<p>If the only issue is that you want to use the right print statement to avoid syntax errors, you can avoid the problem altogether by using the <code>print()</code> function in Python 2.6:</p> <pre><code>if sys.version_info[0:2] == (2,6): # Or you could use try/except here from __future__ import print_f...
2
2010-03-03T04:08:11Z
[ "python", "version" ]
I want my Python script to detect the version and quit gracefully in case of a mismatch
2,368,574
<p>I'd like to make it as general as possible - e.g. handle as many versions as possible.</p> <p>Since version 3 is not backwards compatible with version 2, I want to make sure that I use the right print statement.</p> <p>Please let me know if you have questions and feel free to share related knowledge having to do w...
3
2010-03-03T03:34:36Z
2,368,749
<ul> <li><p><s>If you want to maintain a codebase that works with Python 2 and 3, you wouldn't try to make code that will run in both, which will be awkward and ugly and bugprone, you would write in Python 2 and use <code>2to3</code> to convert. (You can also write in Python 3 and use <code>3to2</code> to convert, but ...
3
2010-03-03T04:21:37Z
[ "python", "version" ]
I want my Python script to detect the version and quit gracefully in case of a mismatch
2,368,574
<p>I'd like to make it as general as possible - e.g. handle as many versions as possible.</p> <p>Since version 3 is not backwards compatible with version 2, I want to make sure that I use the right print statement.</p> <p>Please let me know if you have questions and feel free to share related knowledge having to do w...
3
2010-03-03T03:34:36Z
2,368,754
<p>On Linux, Mac etc, you should use the standard first line:</p> <pre><code>#!/usr/bin/env python2 </code></pre> <p>or</p> <pre><code>#!/usr/bin/env python2.6 </code></pre> <p>or</p> <pre><code>#!/usr/bin/env python3 </code></pre> <p>On Windows, having such a first line is useful from a documentation point of vi...
2
2010-03-03T04:22:59Z
[ "python", "version" ]
python file manipulation
2,368,618
<p>I have a file with entries such as: 26 1 33 2 . . .</p> <p>and another file with sentences in english</p> <p>I have to write a script to print the 1st word in sentence number 26 and the 2nd word in sentence 33. How do I do it?</p>
0
2010-03-03T03:50:15Z
2,368,630
<p>Here's a general sketch:</p> <ul> <li>Read the first file into a list (a numeric entry in each element)</li> <li>Read the second file into a list (a sentence in each element)</li> <li>Iterate over the entry list, for each number find the sentence and print its relevant word</li> </ul> <p>Now, if you show some effo...
1
2010-03-03T03:53:42Z
[ "python", "string", "file" ]
python file manipulation
2,368,618
<p>I have a file with entries such as: 26 1 33 2 . . .</p> <p>and another file with sentences in english</p> <p>I have to write a script to print the 1st word in sentence number 26 and the 2nd word in sentence 33. How do I do it?</p>
0
2010-03-03T03:50:15Z
2,368,716
<p>The following code should do the task. With assumptions that files are not too large. You may have to do some modification to deal with edge cases (like double space, etc)</p> <pre><code># Get numers from file num = [] with open('1.txt') as file: num = file.readlines() # Get text from file text = [] with o...
2
2010-03-03T04:14:47Z
[ "python", "string", "file" ]
python file manipulation
2,368,618
<p>I have a file with entries such as: 26 1 33 2 . . .</p> <p>and another file with sentences in english</p> <p>I have to write a script to print the 1st word in sentence number 26 and the 2nd word in sentence 33. How do I do it?</p>
0
2010-03-03T03:50:15Z
2,368,740
<p>The big issue is that you have to decide what separates "sentences". For example, is a <code>'.'</code> the end of a sentence? Or maybe part of an abbreviation, e.g. the one I've just used?-) Secondarily, and less difficult, what separates "words", e.g., is "TCP/IP" one word, or two?</p> <p>Once you have sharply...
0
2010-03-03T04:19:05Z
[ "python", "string", "file" ]
python file manipulation
2,368,618
<p>I have a file with entries such as: 26 1 33 2 . . .</p> <p>and another file with sentences in english</p> <p>I have to write a script to print the 1st word in sentence number 26 and the 2nd word in sentence 33. How do I do it?</p>
0
2010-03-03T03:50:15Z
2,368,869
<p>In the following code, I am assuming that sentences end with <code>'. '</code>. You can modify it easily to accommodate other sentence delimiters as well. Note that abbreviations will therefore be a source of bugs.</p> <p>Also, I am going to assume that words are delimited by spaces.</p> <pre><code>sentences = [] ...
0
2010-03-03T04:57:08Z
[ "python", "string", "file" ]
Python:Which way gives better precision
2,368,626
<p>Is there any difference in precision between one time assignment: </p> <pre><code>res=n/k </code></pre> <p>and multiple assignment in for cycle:</p> <pre><code>for i in range(n): res+=1/k </code></pre> <p>?</p>
0
2010-03-03T03:52:52Z
2,368,643
<p>Sure, they are different, because of how floating point division works.</p> <pre><code>&gt;&gt;&gt; res = 0 &gt;&gt;&gt; for x in xrange(5000): res += 0.1 ... &gt;&gt;&gt; res == 5000 * 0.1 False </code></pre> <p>There's <a href="http://docs.python.org/tutorial/floatingpoint.html" rel="nofollow">a good explanatio...
3
2010-03-03T03:56:56Z
[ "python", "precision" ]
Python:Which way gives better precision
2,368,626
<p>Is there any difference in precision between one time assignment: </p> <pre><code>res=n/k </code></pre> <p>and multiple assignment in for cycle:</p> <pre><code>for i in range(n): res+=1/k </code></pre> <p>?</p>
0
2010-03-03T03:52:52Z
2,368,644
<p>Well if <code>k</code> divides <code>n</code> then definitely the first one is more precise :-) To be serious, if the division is floating point and <code>n &gt; 1</code> then the first one will be more precise anyway though they will probably give different results, as nosklo said.</p> <p>BTW, in Python 2.6 the di...
1
2010-03-03T03:57:00Z
[ "python", "precision" ]
Python:Which way gives better precision
2,368,626
<p>Is there any difference in precision between one time assignment: </p> <pre><code>res=n/k </code></pre> <p>and multiple assignment in for cycle:</p> <pre><code>for i in range(n): res+=1/k </code></pre> <p>?</p>
0
2010-03-03T03:52:52Z
2,368,663
<p>Floating point arithmetic has representation and roundoff errors. For the types of data floating point numbers are intended to represent, real numbers of reasonable size, these errors are generally acceptable. </p> <p>If you want to calculate the quotient of two numbers, the right way is simply to say <code>result ...
0
2010-03-03T04:03:10Z
[ "python", "precision" ]
Python:Which way gives better precision
2,368,626
<p>Is there any difference in precision between one time assignment: </p> <pre><code>res=n/k </code></pre> <p>and multiple assignment in for cycle:</p> <pre><code>for i in range(n): res+=1/k </code></pre> <p>?</p>
0
2010-03-03T03:52:52Z
2,368,709
<p>Even if we charitably assume a floating-point division, there's very definitely a difference in precision; the <code>for</code> loop is executed <code>n - 1</code> times!</p> <pre><code>assert (n-1) / k != n / k </code></pre> <p>Also depends on what <code>res</code> is initialised to in the second case :-)</p>
0
2010-03-03T04:13:26Z
[ "python", "precision" ]
Python:Which way gives better precision
2,368,626
<p>Is there any difference in precision between one time assignment: </p> <pre><code>res=n/k </code></pre> <p>and multiple assignment in for cycle:</p> <pre><code>for i in range(n): res+=1/k </code></pre> <p>?</p>
0
2010-03-03T03:52:52Z
2,370,725
<p>Floating-point division <code>a/b</code> is not mathematical division <em>a</em> ÷ <em>b</em>, except in very rare* circumstances. </p> <p>Generally, floating point division <code>a/b</code> is <em>a</em> ÷ <em>b</em> + ε. </p> <p>This is true for two reasons.</p> <ol> <li><p>Float numbers (except in rare ca...
8
2010-03-03T11:25:59Z
[ "python", "precision" ]
Python:Which way gives better precision
2,368,626
<p>Is there any difference in precision between one time assignment: </p> <pre><code>res=n/k </code></pre> <p>and multiple assignment in for cycle:</p> <pre><code>for i in range(n): res+=1/k </code></pre> <p>?</p>
0
2010-03-03T03:52:52Z
2,376,316
<p>Certainly there is a difference if you use floating point numbers, unless the Python interpreter/compiler you are using is capable of optimizing away the loop (Maybe Jython or IronPython might be able to? C compilers are pretty good at this).</p> <p>If you actually want these two approaches to be the same precision...
0
2010-03-04T01:31:28Z
[ "python", "precision" ]
Google App Engine: Basic Django Issue
2,368,651
<p>I'm using Django templating with Google App Engine. I'm trying unsuccessfully to print out a menu.</p> <p><strong>The controller:</strong></p> <pre><code>menu_items = { 'menu_items': [ { 'href': '/', 'name': 'Home' }, { 'href': '/cart', 'name': 'Cart' } ...
0
2010-03-03T03:59:41Z
2,368,676
<pre><code>menu_items = {'menu_items': [{'href': '/', 'name': 'Home'}, {'href': '/cart', 'name': 'Cart'}], } render('Views/menu.html', self, {'menu_items': menu_items}) </code></pre> <p>Look at these lines carefully. menu_items (dictionary) has a key menu_items with a value h...
5
2010-03-03T04:07:53Z
[ "python", "django", "google-app-engine" ]
Simulation of molecular dynamics in Python
2,368,671
<p>I am searching for a python package that I can use to simulate molecular dynamics in non-equilibrium situations. I need a setup that can handle a fairly large number of molecules in a primarily kinetic theory manner, and that can handle having solid surfaces present. With regards to the surfaces, I would need to be ...
7
2010-03-03T04:06:08Z
2,368,710
<p>Have you considered <a href="http://simpy.sourceforge.net/simpy_overview.htm" rel="nofollow"><strong>SimPy</strong></a>? SimPy is a rather generic Discrete Event Simulation package, but could feasibly meet your needs.</p> <p>Better yet the <a href="http://dirac.cnrs-orleans.fr/MMTK/" rel="nofollow"><strong>Molecul...
4
2010-03-03T04:13:26Z
[ "python", "packages", "simulation", "physics", "kinematics" ]
Simulation of molecular dynamics in Python
2,368,671
<p>I am searching for a python package that I can use to simulate molecular dynamics in non-equilibrium situations. I need a setup that can handle a fairly large number of molecules in a primarily kinetic theory manner, and that can handle having solid surfaces present. With regards to the surfaces, I would need to be ...
7
2010-03-03T04:06:08Z
2,368,730
<p>I don't know if that programs does all the features you need but there is avogadro in the kde programs, i think it is extendable and since it is open source you could do anything with it. <a href="http://www.kde-apps.org/content/show.php/Avogadro?content=59521" rel="nofollow">http://www.kde-apps.org/content/show.php...
0
2010-03-03T04:16:40Z
[ "python", "packages", "simulation", "physics", "kinematics" ]
Simulation of molecular dynamics in Python
2,368,671
<p>I am searching for a python package that I can use to simulate molecular dynamics in non-equilibrium situations. I need a setup that can handle a fairly large number of molecules in a primarily kinetic theory manner, and that can handle having solid surfaces present. With regards to the surfaces, I would need to be ...
7
2010-03-03T04:06:08Z
2,369,508
<p>Lampps and gromacs are two well known molecular dynamics codes. These codes both have some python based wrapper stuff, but I am not sure how much functionality the wrappers expose. They may not give you enough control over the simulation.</p> <p>Google for "GromacsWrapper" or google for "lammps" and "pizza.py"</p> ...
2
2010-03-03T07:47:44Z
[ "python", "packages", "simulation", "physics", "kinematics" ]
Simulation of molecular dynamics in Python
2,368,671
<p>I am searching for a python package that I can use to simulate molecular dynamics in non-equilibrium situations. I need a setup that can handle a fairly large number of molecules in a primarily kinetic theory manner, and that can handle having solid surfaces present. With regards to the surfaces, I would need to be ...
7
2010-03-03T04:06:08Z
2,369,630
<p>I second MMTK, but take a look at <a href="http://www.ks.uiuc.edu/Research/vmd/" rel="nofollow">VMD</a>, which is the best MD software I'm aware of, and is Python-scriptable (in addition to Tk). See <a href="http://www.google.com/search?sitesearch=www.ks.uiuc.edu%2FResearch%2Fvmd%2F&amp;q=python&amp;btnG=Google" rel...
0
2010-03-03T08:11:51Z
[ "python", "packages", "simulation", "physics", "kinematics" ]
Simulation of molecular dynamics in Python
2,368,671
<p>I am searching for a python package that I can use to simulate molecular dynamics in non-equilibrium situations. I need a setup that can handle a fairly large number of molecules in a primarily kinetic theory manner, and that can handle having solid surfaces present. With regards to the surfaces, I would need to be ...
7
2010-03-03T04:06:08Z
2,721,014
<p>Another generic simulations framework is my own <a href="http://garlicsim.org" rel="nofollow">GarlicSim</a>. You can try that. I could help you get a simpack up if you're serious about it.</p>
1
2010-04-27T12:14:13Z
[ "python", "packages", "simulation", "physics", "kinematics" ]
Simulation of molecular dynamics in Python
2,368,671
<p>I am searching for a python package that I can use to simulate molecular dynamics in non-equilibrium situations. I need a setup that can handle a fairly large number of molecules in a primarily kinetic theory manner, and that can handle having solid surfaces present. With regards to the surfaces, I would need to be ...
7
2010-03-03T04:06:08Z
36,561,161
<p>I recommend to use molecular dynamics software to run MD simulations like Gromacs. This software is highly optimized for that particular purpose. You can also run on GPU's and you will be able to run larger systems in less time.</p> <p>Afterwards, you run only the analysis with python packages using the generated t...
0
2016-04-11T23:41:58Z
[ "python", "packages", "simulation", "physics", "kinematics" ]
Simulation of molecular dynamics in Python
2,368,671
<p>I am searching for a python package that I can use to simulate molecular dynamics in non-equilibrium situations. I need a setup that can handle a fairly large number of molecules in a primarily kinetic theory manner, and that can handle having solid surfaces present. With regards to the surfaces, I would need to be ...
7
2010-03-03T04:06:08Z
36,759,118
<p>The following <strong>programs</strong> can be used to run MD symulations:</p> <ul> <li><a href="http://www.gromacs.org/" rel="nofollow">Gromacs</a></li> <li><a href="http://ambermd.org/" rel="nofollow">AMBER</a></li> <li><a href="https://www.charmm.org/charmm/showcase/news/free-charmm/" rel="nofollow">charmm</a></...
0
2016-04-21T03:32:14Z
[ "python", "packages", "simulation", "physics", "kinematics" ]
Can generateDS be used like xsd.exe
2,368,857
<p>Can I use generateDS.py in python in a similar way that I would use xsd.exe to create C# classes from xsd?</p> <p>Basically, given an xsd schema I want to create a data structure, in python, fill its data in, and then render it into an xml string.</p> <p>perhaps pyXSD is better?</p> <p>oh, and yes, I'm a python n...
1
2010-03-03T04:55:37Z
2,473,082
<p>generateDS did exactly what I wanted it to, a way to deal with a object graph of data, rather than a node graph</p> <p>ran</p> <pre><code>python generateDS.py -o MedicationDS.py medication.xsd </code></pre> <p>gave me a python Class I could instantiate and populate with data, then render to a stream.</p> <pre><c...
2
2010-03-18T20:17:21Z
[ "python", "xsd" ]
How do I drop a bash shell from within Python?
2,368,872
<p>i'm working on a python tcp shell; I'd like to be able to telnet to a port, and have it prompt me with a shell: ex. </p> <pre><code>$ telnet localhost 5555 Connected to localhost. Escape character is '^]'. $ </code></pre> <p>The answer below was quite helpful in getting me on my way. Here's the working code. </p> ...
1
2010-03-03T04:57:29Z
2,368,887
<pre><code>import os os.system('sh') # or bash, tcsh, zsh, whatever. :-P </code></pre>
6
2010-03-03T05:01:45Z
[ "python" ]
List fields present in a table
2,368,948
<p>Is there any way to to list out the fields present in a table in django models</p> <pre><code> class Profile(models.Model): user = models.ForeignKey(User, unique=True) name = models.ForeignKey(School) emp = models.ForeignKey(User, unique=True) </code></pre> <p>How to list out the filed names from the t...
7
2010-03-03T05:18:59Z
2,368,971
<p><code>Profile._meta.fields</code> will get you a list of fields. The <code>name</code> property of the field object contains the name of the field. <code>Profile._meta.get_fields_with_model()</code> will return a list of 2-tuples of <code>(field, model)</code>, with <code>model</code> being <code>None</code> if the ...
10
2010-03-03T05:26:31Z
[ "python", "django" ]
Bad file descriptor error
2,368,967
<p>If I try executing the following code</p> <pre><code>f = file('test','rb') fout = file('test.out','wb') for i in range(10): a = f.read(1) fout.write(a) f.close() f = fout f.seek(4) print f.read(4) </code></pre> <p>Where <code>'test'</code> is any arbitrary file, I get:</p> <pre><code>Traceback (most re...
11
2010-03-03T05:23:06Z
2,368,969
<p>you've only opened the file <code>fout</code> for writing, not reading. To open for both use</p> <pre><code>fout = file('test.out','r+b') </code></pre>
26
2010-03-03T05:24:28Z
[ "python", "file" ]
xhtml/rst to excel conversion
2,369,230
<p>I am working on a reporting tool and need to generate reports in various formats including pdf, html and excel(.xls or any format which can be easily opened in excel)</p> <p>I am thinking of generating basic report in xhtml or restructuredtext(rst) and then converting it to other formats, I can use xhtml2pdf or rst...
0
2010-03-03T06:37:45Z
2,369,270
<p>For converting a dataset in XML (or XHTML) to Excel -</p> <p>I haven't done this myself, but MSDN provides an example <a href="http://support.microsoft.com/kb/319180" rel="nofollow">XSLT</a> (plus some irrelevant .NET code) for converting a sample dataset to Excel. It should not be too difficult, as the output is t...
1
2010-03-03T06:47:01Z
[ "python", "excel", "xhtml", "xls", "restructuredtext" ]
Python: Get system calendar format
2,369,332
<p>Is it possible to return the current system calendar format using Python? For example non-Gregorian calendar formats such as the Thai Buddhist calendar.</p>
0
2010-03-03T07:02:35Z
2,371,914
<p>Under windows?...for this approach you'll need to get the <a href="http://starship.python.net/~skippy/win32/" rel="nofollow">win32api package from here</a>, here's a quick script to read the registry key that holds the default calendar type for the system, but each user has their own key as well, so you may have to ...
1
2010-03-03T14:11:45Z
[ "python", "internationalization", "calendar" ]
how to geocode phone number
2,369,340
<p>I have a list of phone numbers with area code prefixes that I want to find a latitude/longitude location for.</p> <p>Is there a library (ideally Python) or service that can do this?</p>
3
2010-03-03T07:03:52Z
2,369,535
<p>You may be able to obtain limited free information (e.g. town) or, for a hefty fee, some relatively more detailed information (address), from various Whitepages-like providers. This should cover <strong>landlines</strong> as well as, to some degree, <strong>mobile (cell) lines</strong>. Be aware that in the case o...
1
2010-03-03T07:54:57Z
[ "python", "geocoding", "phone-number" ]
How can I build a regular expression which has options part
2,369,346
<p>How can I build a regular expression in python which can match all the following? where it is a "string (a-zA-Z)" follow by a space follow by 1 or multiple 4 integers which separates by a comma:</p> <p>Example:<br> <code>someotherstring 42 1 48 17,</code><br> <code>somestring 363 1 46 17,363 1 34 17,401 3 8 14,</co...
1
2010-03-03T07:05:10Z
2,370,023
<p>As your data units (as I called them above) are separated by a comma AND a whitespace, you could still use <code>split</code> :)</p> <pre><code>data = "someotherstring 42 1 48 17, somestring 363 1 46 17,363 1 34 17,401 3 8 14, otherstring 42 1 48 17,363 1 34 17" data_items = data.split(', ') for item in data_items...
0
2010-03-03T09:30:10Z
[ "python", "regex" ]
How can I build a regular expression which has options part
2,369,346
<p>How can I build a regular expression in python which can match all the following? where it is a "string (a-zA-Z)" follow by a space follow by 1 or multiple 4 integers which separates by a comma:</p> <p>Example:<br> <code>someotherstring 42 1 48 17,</code><br> <code>somestring 363 1 46 17,363 1 34 17,401 3 8 14,</co...
1
2010-03-03T07:05:10Z
2,370,037
<pre><code>import re str_in = "someotherstring 42 1 48 17, somestring 363 1 46 17,363 1 34 17,401 3 8 14, otherstring 42 1 48 17,363 1 34 17," list_out = re.split("[\\s,]", str_in) </code></pre> <p><code>list_out</code> then contains a list where the name of each section is followed by all the integers (still as strin...
0
2010-03-03T09:33:46Z
[ "python", "regex" ]
How can I build a regular expression which has options part
2,369,346
<p>How can I build a regular expression in python which can match all the following? where it is a "string (a-zA-Z)" follow by a space follow by 1 or multiple 4 integers which separates by a comma:</p> <p>Example:<br> <code>someotherstring 42 1 48 17,</code><br> <code>somestring 363 1 46 17,363 1 34 17,401 3 8 14,</co...
1
2010-03-03T07:05:10Z
2,371,353
<pre><code>&gt;&gt;&gt; test = "somestring 363 1 46 17,363 1 34 17,401 3 8 14," </code></pre> <p>Here is a pyparsing processor for your input string:</p> <pre><code>&gt;&gt;&gt; from pyparsing import * &gt;&gt;&gt; integer = Word(nums) &gt;&gt;&gt; patt = Word(alphas) + OneOrMore(Group(integer*4 + Suppress(','))) </c...
1
2010-03-03T12:58:24Z
[ "python", "regex" ]
How to delete all blank lines in the file with the help of python?
2,369,440
<p>For example, we have some file like that:</p> <blockquote> <p>first line<br> second line <br><br> third line</p> </blockquote> <p>And in result we have to get:</p> <blockquote> <p>first line<br> second line<br> third line</p> </blockquote> <p>Use ONLY python</p>
7
2010-03-03T07:29:14Z
2,369,449
<pre><code>&gt;&gt;&gt; s = """first line ... second line ... ... third line ... """ &gt;&gt;&gt; print '\n'.join([i for i in s.split('\n') if len(i) &gt; 0]) first line second line third line &gt;&gt;&gt; </code></pre>
1
2010-03-03T07:31:48Z
[ "python" ]
How to delete all blank lines in the file with the help of python?
2,369,440
<p>For example, we have some file like that:</p> <blockquote> <p>first line<br> second line <br><br> third line</p> </blockquote> <p>And in result we have to get:</p> <blockquote> <p>first line<br> second line<br> third line</p> </blockquote> <p>Use ONLY python</p>
7
2010-03-03T07:29:14Z
2,369,474
<pre><code>import fileinput for line in fileinput.FileInput("file",inplace=1): if line.rstrip(): print line </code></pre>
10
2010-03-03T07:39:05Z
[ "python" ]
How to delete all blank lines in the file with the help of python?
2,369,440
<p>For example, we have some file like that:</p> <blockquote> <p>first line<br> second line <br><br> third line</p> </blockquote> <p>And in result we have to get:</p> <blockquote> <p>first line<br> second line<br> third line</p> </blockquote> <p>Use ONLY python</p>
7
2010-03-03T07:29:14Z
2,369,533
<p>I know you asked about Python, but your comment about Win and Linux indicates that you're after cross-platform-ness, and Perl is at least as cross-platform as Python. You can do this easily with one line of Perl on the command line, no scripts necessary: <code>perl -ne 'print if /\S/' foo.txt</code></p> <p>(I love...
2
2010-03-03T07:54:45Z
[ "python" ]
How to delete all blank lines in the file with the help of python?
2,369,440
<p>For example, we have some file like that:</p> <blockquote> <p>first line<br> second line <br><br> third line</p> </blockquote> <p>And in result we have to get:</p> <blockquote> <p>first line<br> second line<br> third line</p> </blockquote> <p>Use ONLY python</p>
7
2010-03-03T07:29:14Z
2,369,538
<p>The <code>with</code> statement is excellent for automatically opening and closing files.</p> <pre><code>with open('myfile','rw') as file: for line in file: if line.strip(): file.write(line) </code></pre>
9
2010-03-03T07:55:21Z
[ "python" ]
How to delete all blank lines in the file with the help of python?
2,369,440
<p>For example, we have some file like that:</p> <blockquote> <p>first line<br> second line <br><br> third line</p> </blockquote> <p>And in result we have to get:</p> <blockquote> <p>first line<br> second line<br> third line</p> </blockquote> <p>Use ONLY python</p>
7
2010-03-03T07:29:14Z
2,369,546
<pre><code>import sys with open("file.txt") as f: for line in f: if not line.isspace(): sys.stdout.write(line) </code></pre> <p>Another way is</p> <pre><code>with open("file.txt") as f: print "".join(line for line in f if not line.isspace()) </code></pre>
5
2010-03-03T07:56:12Z
[ "python" ]
How to delete all blank lines in the file with the help of python?
2,369,440
<p>For example, we have some file like that:</p> <blockquote> <p>first line<br> second line <br><br> third line</p> </blockquote> <p>And in result we have to get:</p> <blockquote> <p>first line<br> second line<br> third line</p> </blockquote> <p>Use ONLY python</p>
7
2010-03-03T07:29:14Z
2,375,998
<p>Have you tried something like the program below?</p> <pre><code>for line in open(filename): if len(line) &gt; 1 or line != '\n': print(line, end='') </code></pre>
0
2010-03-04T00:01:50Z
[ "python" ]
Generate a heatmap in MatPlotLib using a scatter data set
2,369,492
<p>I have a set of X,Y data points (about 10k) that are easy to plot as a scatter plot but that I would like to represent as a heatmap.</p> <p>I looked through the examples in MatPlotLib and they all seem to already start with heatmap cell values to generate the image.</p> <p>Is there a method that converts a bunch o...
92
2010-03-03T07:42:17Z
2,371,227
<p>Make a 2-dimensional array that corresponds to the cells in your final image, called say <code>heatmap_cells</code> and instantiate it as all zeroes.</p> <p>Choose two scaling factors that define the difference between each array element in real units, for each dimension, say <code>x_scale</code> and <code>y_scale<...
2
2010-03-03T12:37:50Z
[ "python", "matplotlib" ]
Generate a heatmap in MatPlotLib using a scatter data set
2,369,492
<p>I have a set of X,Y data points (about 10k) that are easy to plot as a scatter plot but that I would like to represent as a heatmap.</p> <p>I looked through the examples in MatPlotLib and they all seem to already start with heatmap cell values to generate the image.</p> <p>Is there a method that converts a bunch o...
92
2010-03-03T07:42:17Z
2,371,812
<p>In <em>Matplotlib</em> lexicon, i think you want a <strong>hexbin</strong> plot. </p> <p>If you're not familiar with this type of plot, it's just a <em>bivariate histogram</em> in which the xy-plane is tessellated by a regular grid of hexagons. </p> <p>So from a histogram, you can just count the number of points f...
83
2010-03-03T13:55:43Z
[ "python", "matplotlib" ]
Generate a heatmap in MatPlotLib using a scatter data set
2,369,492
<p>I have a set of X,Y data points (about 10k) that are easy to plot as a scatter plot but that I would like to represent as a heatmap.</p> <p>I looked through the examples in MatPlotLib and they all seem to already start with heatmap cell values to generate the image.</p> <p>Is there a method that converts a bunch o...
92
2010-03-03T07:42:17Z
2,461,029
<p>If you don't want hexagons, you can use numpy's <code>histogram2d</code> function:</p> <pre><code>import numpy as np import numpy.random import matplotlib.pyplot as plt # Generate some test data x = np.random.randn(8873) y = np.random.randn(8873) heatmap, xedges, yedges = np.histogram2d(x, y, bins=50) extent = [x...
101
2010-03-17T09:25:51Z
[ "python", "matplotlib" ]
Generate a heatmap in MatPlotLib using a scatter data set
2,369,492
<p>I have a set of X,Y data points (about 10k) that are easy to plot as a scatter plot but that I would like to represent as a heatmap.</p> <p>I looked through the examples in MatPlotLib and they all seem to already start with heatmap cell values to generate the image.</p> <p>Is there a method that converts a bunch o...
92
2010-03-03T07:42:17Z
13,233,972
<p>If you are using 1.2.x</p> <pre> x = randn(100000) y = randn(100000) hist2d(x,y,bins=100); </pre> <p><img src="http://i.stack.imgur.com/yj9ku.png" alt="enter image description here"></p>
10
2012-11-05T14:19:29Z
[ "python", "matplotlib" ]
Generate a heatmap in MatPlotLib using a scatter data set
2,369,492
<p>I have a set of X,Y data points (about 10k) that are easy to plot as a scatter plot but that I would like to represent as a heatmap.</p> <p>I looked through the examples in MatPlotLib and they all seem to already start with heatmap cell values to generate the image.</p> <p>Is there a method that converts a bunch o...
92
2010-03-03T07:42:17Z
20,822,144
<p>this answer <a href="http://stackoverflow.com/questions/6652671/efficient-method-of-calculating-density-of-irregularly-spaced-points">Efficient method of calculating density of irregularly spaced points</a> introduced more methods about how to do it more efficiently and precisely. hope it can helps</p>
3
2013-12-29T04:25:35Z
[ "python", "matplotlib" ]
Generate a heatmap in MatPlotLib using a scatter data set
2,369,492
<p>I have a set of X,Y data points (about 10k) that are easy to plot as a scatter plot but that I would like to represent as a heatmap.</p> <p>I looked through the examples in MatPlotLib and they all seem to already start with heatmap cell values to generate the image.</p> <p>Is there a method that converts a bunch o...
92
2010-03-03T07:42:17Z
36,515,364
<p>Instead of using np.hist2d, which in general produces quite ugly histograms, I would like to recycle <a href="https://github.com/alejandrobll/py-sphviewer">py-sphviewer</a>, a python package for rendering particle simulations using an adaptive smoothing kernel and that can be easily installed from pip (see webpage d...
8
2016-04-09T10:06:31Z
[ "python", "matplotlib" ]
How do I use Python's httplib to send a POST to a URL, with a dictionary of parameters?
2,370,003
<p>I just want a function that can take 2 parameters:</p> <ul> <li>the URL to POST to</li> <li>a dictionary of parameters</li> </ul> <p>How can this be done with httplib? thanks.</p>
15
2010-03-03T09:27:35Z
2,370,057
<p>From the <a href="https://docs.python.org/release/2.7/library/httplib.html#examples" rel="nofollow">Python documentation</a>:</p> <pre><code>&gt;&gt;&gt; import httplib, urllib &gt;&gt;&gt; params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) &gt;&gt;&gt; headers = {"Content-type": "application/x-www-form-...
31
2010-03-03T09:38:18Z
[ "python", "api", "post", "httplib" ]
How do I use Python's httplib to send a POST to a URL, with a dictionary of parameters?
2,370,003
<p>I just want a function that can take 2 parameters:</p> <ul> <li>the URL to POST to</li> <li>a dictionary of parameters</li> </ul> <p>How can this be done with httplib? thanks.</p>
15
2010-03-03T09:27:35Z
15,160,434
<p>A simpler one, using just urllib:</p> <pre><code>import urllib params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) f = urllib.urlopen("http://www.example.org/cgi-bin/query", params) print f.read() </code></pre> <p>Found in Python docs for <a href="http://docs.python.org/2/library/urllib.html#examples">ur...
7
2013-03-01T14:44:40Z
[ "python", "api", "post", "httplib" ]
Arguments in the middle of a string to be localized
2,370,309
<p>I'm a beginner in Python. My problem is pretty simple. I have a string to be localized in a python application containing parameters :</p> <pre><code>print _('Hello dear user, your name is ') + params['first_name'] + ' ' + params['last_name'] + _(' and blah blah blah') </code></pre> <p>This actually does the job, ...
1
2010-03-03T10:17:31Z
2,370,326
<blockquote> <p>I thought about placing custom tags like {{fn}} or {{ln}} in the translation string and replacing them by the actual values before displaying them.</p> </blockquote> <p>That's what I would do. Placeholders in the right places for each language versions should do the job.</p> <p>One thing to mention ...
0
2010-03-03T10:19:36Z
[ "python", "internationalization" ]
Arguments in the middle of a string to be localized
2,370,309
<p>I'm a beginner in Python. My problem is pretty simple. I have a string to be localized in a python application containing parameters :</p> <pre><code>print _('Hello dear user, your name is ') + params['first_name'] + ' ' + params['last_name'] + _(' and blah blah blah') </code></pre> <p>This actually does the job, ...
1
2010-03-03T10:17:31Z
2,370,339
<p>Something like this should do the trick :</p> <pre><code>print _('Hello dear user, your name is %s %s and blah blah blah') % (params['first_name'], params['last_name']) </code></pre>
1
2010-03-03T10:21:05Z
[ "python", "internationalization" ]
Arguments in the middle of a string to be localized
2,370,309
<p>I'm a beginner in Python. My problem is pretty simple. I have a string to be localized in a python application containing parameters :</p> <pre><code>print _('Hello dear user, your name is ') + params['first_name'] + ' ' + params['last_name'] + _(' and blah blah blah') </code></pre> <p>This actually does the job, ...
1
2010-03-03T10:17:31Z
2,370,380
<p>I'd suggest </p> <pre><code>print 'Hello dear user, your name is %(first_name)s %(last_name)s' % params </code></pre>
3
2010-03-03T10:28:02Z
[ "python", "internationalization" ]
Arguments in the middle of a string to be localized
2,370,309
<p>I'm a beginner in Python. My problem is pretty simple. I have a string to be localized in a python application containing parameters :</p> <pre><code>print _('Hello dear user, your name is ') + params['first_name'] + ' ' + params['last_name'] + _(' and blah blah blah') </code></pre> <p>This actually does the job, ...
1
2010-03-03T10:17:31Z
2,370,390
<p>I would go with templates if I were you. That would let you have a separate template for each language. For example:</p> <pre><code>from string import Template s_en = Template('Hello dear user, your name is $first_name $last_name and blah blah blah') s_sco = Template('Hello, $first_name of the clan Mac$last_name......
1
2010-03-03T10:29:49Z
[ "python", "internationalization" ]
How do I ensure I always get a list of matches from Python's Regular Expressions?
2,370,369
<p>I'm trying to pull some information (no recursion necessary) from a jsp page (malformed xml) similar to this:</p> <pre><code>&lt;td&gt; &lt;html:button ...&gt;&lt;/html:button&gt; &lt;html:submit ...&gt;&lt;/html:submit&gt;&lt;/td&gt; </code></pre> <p>And a regex:</p> <pre><code>&lt;html:(button|submit|cancel)[\s...
0
2010-03-03T10:26:03Z
2,370,393
<p>Aside from the fact that a regex probably isn't what you want to do this with, you want to put the bit you want in groups using parentheses. If you want everything up to the closing <code>&lt;/html:whatever&gt;</code> tag, then you want something like this:</p> <pre><code>(&lt;html:(button|submit|cancel)[\s\S]*?)&l...
3
2010-03-03T10:30:06Z
[ "python", "regex", "tuples", "findall" ]