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
Recommendations for Python development on a Mac?
601,236
<p>I bought a low-end MacBook about a month ago and am finally getting around to configuring it for Python. I've done most of my Python work in Windows up until now, and am finding the choices for OS X a little daunting. It looks like there are at least five options to use for Python development:</p> <ul> <li>"Stock" ...
8
2009-03-02T04:04:06Z
601,287
<p>I recommend python (any python?) plus the ipython shell. My most recent experience with MacPython was MacPython 2.5, and I found IDLE frustrating to use as an editor. It's not very featureful, and its' very slow to scroll large quantities of output.</p>
0
2009-03-02T04:37:03Z
[ "python", "osx" ]
Recommendations for Python development on a Mac?
601,236
<p>I bought a low-end MacBook about a month ago and am finally getting around to configuring it for Python. I've done most of my Python work in Windows up until now, and am finding the choices for OS X a little daunting. It looks like there are at least five options to use for Python development:</p> <ul> <li>"Stock" ...
8
2009-03-02T04:04:06Z
601,844
<p>Depends what you are using python for. If you are using MacOS funitionality and things like PyObjC you are probably best of with MacPython or the python provided by Apple. </p> <p>I use Python on my Mac mostly for development of server side applications which later will run on FreeBSD &amp; Linux boxes. For that I ...
3
2009-03-02T10:10:18Z
[ "python", "osx" ]
Recommendations for Python development on a Mac?
601,236
<p>I bought a low-end MacBook about a month ago and am finally getting around to configuring it for Python. I've done most of my Python work in Windows up until now, and am finding the choices for OS X a little daunting. It looks like there are at least five options to use for Python development:</p> <ul> <li>"Stock" ...
8
2009-03-02T04:04:06Z
602,013
<p>I would highly recommend using <a href="http://www.macports.org/" rel="nofollow">MacPorts</a> with <a href="http://porticus.alittledrop.com/" rel="nofollow">Porticus</a> for managing your Python installation. It takes a while to build everything, but the advantage is that whatever you build yourself will be built ag...
4
2009-03-02T11:38:41Z
[ "python", "osx" ]
Recommendations for Python development on a Mac?
601,236
<p>I bought a low-end MacBook about a month ago and am finally getting around to configuring it for Python. I've done most of my Python work in Windows up until now, and am finding the choices for OS X a little daunting. It looks like there are at least five options to use for Python development:</p> <ul> <li>"Stock" ...
8
2009-03-02T04:04:06Z
602,025
<p>In my windows environment I use Eclipse and PyDev, which works quite well together, even if it's a bit sparse. Apparently the exact same environment is available for the Mac as well, so I suggest downloading <a href="http://www.eclipse.org" rel="nofollow">Eclipse</a> and using the internal update software function t...
1
2009-03-02T11:44:02Z
[ "python", "osx" ]
Recommendations for Python development on a Mac?
601,236
<p>I bought a low-end MacBook about a month ago and am finally getting around to configuring it for Python. I've done most of my Python work in Windows up until now, and am finding the choices for OS X a little daunting. It looks like there are at least five options to use for Python development:</p> <ul> <li>"Stock" ...
8
2009-03-02T04:04:06Z
604,338
<p>Apple's supplied python is quite old – my tiger install has 2.3.5. This may not be a problem for you, but you would be missing out on a lot. Also, there is a risk that Apple will update it. I'm not sure if moving from 2.3.5 to (say) 2.4 would cause code to break, but I guess it's possible. This happened to per...
1
2009-03-02T22:32:54Z
[ "python", "osx" ]
Recommendations for Python development on a Mac?
601,236
<p>I bought a low-end MacBook about a month ago and am finally getting around to configuring it for Python. I've done most of my Python work in Windows up until now, and am finding the choices for OS X a little daunting. It looks like there are at least five options to use for Python development:</p> <ul> <li>"Stock" ...
8
2009-03-02T04:04:06Z
613,677
<p>Based on the number of bugs and omissions people have been encountering in Leopard python (<em>just here on SO</em>!), I couldn't recommend that version. e.g., see:</p> <ul> <li><a href="http://stackoverflow.com/questions/613111/different-results-for-hmac-in-python-and-perl">http://stackoverflow.com/questions/6131...
2
2009-03-05T05:37:09Z
[ "python", "osx" ]
Recommendations for Python development on a Mac?
601,236
<p>I bought a low-end MacBook about a month ago and am finally getting around to configuring it for Python. I've done most of my Python work in Windows up until now, and am finding the choices for OS X a little daunting. It looks like there are at least five options to use for Python development:</p> <ul> <li>"Stock" ...
8
2009-03-02T04:04:06Z
618,078
<p>How about EPD from Enthought? Yes, it's large but it is a framework build and includes things like wxPython, vtk, numpy, scipy, and ipython built-in.</p>
3
2009-03-06T08:39:57Z
[ "python", "osx" ]
Recommendations for Python development on a Mac?
601,236
<p>I bought a low-end MacBook about a month ago and am finally getting around to configuring it for Python. I've done most of my Python work in Windows up until now, and am finding the choices for OS X a little daunting. It looks like there are at least five options to use for Python development:</p> <ul> <li>"Stock" ...
8
2009-03-02T04:04:06Z
5,541,640
<p>And guess what was forgotten by every answer here ... <a href="http://code.activestate.com/pypm/psyco/" rel="nofollow"><strong>ActivePython</strong></a>.</p> <p>No compilation required, even for third-party modules such as <a href="http://code.activestate.com/pypm/numpy/" rel="nofollow">numpy</a>, <a href="http://c...
1
2011-04-04T16:45:14Z
[ "python", "osx" ]
Should I use GeoDjango for mapping a floor plan?
601,442
<p>I want to create a floor plan map of an interior space that has clickable regions. My first thought was to investigate GeoDjango since its <em>the</em> mapping app for Django. But considering the dependencies, the learning curve and overall complexity, I'm concerned that I may be trying to swat a fly with a bazook...
6
2009-03-02T06:34:21Z
612,487
<p>IMHO using GeoDjango for a floor plan isn't a bad idea. But if your data does not change much and the amount of data (rooms, areas, workstation, ...) isn't very large, then you might not need a database and a full GeoDjango stack.</p> <p>A simpler solution would be using <a href="http://www.openlayers.org" rel="nof...
3
2009-03-04T21:23:00Z
[ "python", "django", "mapping", "geodjango" ]
Should I use GeoDjango for mapping a floor plan?
601,442
<p>I want to create a floor plan map of an interior space that has clickable regions. My first thought was to investigate GeoDjango since its <em>the</em> mapping app for Django. But considering the dependencies, the learning curve and overall complexity, I'm concerned that I may be trying to swat a fly with a bazook...
6
2009-03-02T06:34:21Z
613,955
<p>I'd say that using GeoDjango for this purpose is definitely overkill. </p> <p>It could be implemented simply with an image map, or Canvas/SVG or Flash for extra pretty-points :)</p>
4
2009-03-05T08:20:04Z
[ "python", "django", "mapping", "geodjango" ]
Should I use GeoDjango for mapping a floor plan?
601,442
<p>I want to create a floor plan map of an interior space that has clickable regions. My first thought was to investigate GeoDjango since its <em>the</em> mapping app for Django. But considering the dependencies, the learning curve and overall complexity, I'm concerned that I may be trying to swat a fly with a bazook...
6
2009-03-02T06:34:21Z
614,489
<p>How often will the floor plan change? From your description a simple image with a imagemap would suffice.</p>
1
2009-03-05T12:02:39Z
[ "python", "django", "mapping", "geodjango" ]
Should I use GeoDjango for mapping a floor plan?
601,442
<p>I want to create a floor plan map of an interior space that has clickable regions. My first thought was to investigate GeoDjango since its <em>the</em> mapping app for Django. But considering the dependencies, the learning curve and overall complexity, I'm concerned that I may be trying to swat a fly with a bazook...
6
2009-03-02T06:34:21Z
29,847,935
<p>One good motivation for using of GeoDjango may be:</p> <pre><code>the access to the geographical cooridinates backend, </code></pre> <p>and you won't produce just beauty looking images with arbitrary scale, but objects which will be <strong><code>geo-oriented</code></strong>, what is cruciall if you will plane to...
0
2015-04-24T12:47:46Z
[ "python", "django", "mapping", "geodjango" ]
Best way to create a NumPy array from a dictionary?
601,477
<p>I'm just starting with NumPy so I may be missing some core concepts...</p> <p>What's the best way to create a NumPy array from a dictionary whose values are lists?</p> <p>Something like this:</p> <pre><code>d = { 1: [10,20,30] , 2: [50,60], 3: [100,200,300,400,500] } </code></pre> <p>Should turn into something l...
8
2009-03-02T06:57:43Z
601,582
<p>You don't need to create numpy arrays to call numpy.std(). You can call numpy.std() in a loop over all the values of your dictionary. The list will be converted to a numpy array on the fly to compute the standard variation.</p> <p>The downside of this method is that the main loop will be in python and not in C. But...
8
2009-03-02T08:02:56Z
[ "python", "numpy" ]
Best way to create a NumPy array from a dictionary?
601,477
<p>I'm just starting with NumPy so I may be missing some core concepts...</p> <p>What's the best way to create a NumPy array from a dictionary whose values are lists?</p> <p>Something like this:</p> <pre><code>d = { 1: [10,20,30] , 2: [50,60], 3: [100,200,300,400,500] } </code></pre> <p>Should turn into something l...
8
2009-03-02T06:57:43Z
603,892
<p>While there are already some pretty reasonable ideas present here, I believe following is worth mentioning.</p> <p>Filling missing data with any default value would spoil the statistical characteristics (std, etc). Evidently that's why Mapad proposed the nice trick with grouping same sized records. The problem with...
2
2009-03-02T20:36:03Z
[ "python", "numpy" ]
Best way to create a NumPy array from a dictionary?
601,477
<p>I'm just starting with NumPy so I may be missing some core concepts...</p> <p>What's the best way to create a NumPy array from a dictionary whose values are lists?</p> <p>Something like this:</p> <pre><code>d = { 1: [10,20,30] , 2: [50,60], 3: [100,200,300,400,500] } </code></pre> <p>Should turn into something l...
8
2009-03-02T06:57:43Z
11,619,778
<p><strong>numpy dictionary</strong></p> <p>You can use a structured array to preserve the ability to address a numpy object by a key, like a dictionary.</p> <pre><code>import numpy as np dd = {'a':1,'b':2,'c':3} dtype = eval('[' + ','.join(["('%s', float)" % key for key in dd.keys()]) + ']') values = [tuple(dd.val...
0
2012-07-23T20:11:50Z
[ "python", "numpy" ]
Python Table engine binding for Tokyo Cabinet
601,865
<p>I am looking for python bindings for Table engine of Tokyo cabinet. I tried <a href="http://pypi.python.org/pypi/pytc" rel="nofollow">Pytc</a> but can only find Hash and B-tree engine support. Is there any other bindings available?</p>
12
2009-03-02T10:18:23Z
601,920
<p>The only other one I know of is a fork of pytc but it looks like they have only done some refactoring and documentation work, so probably still only hash and b-tree support:</p> <p><a href="http://github.com/rsms/tc/tree/master" rel="nofollow">tc</a></p> <p>If this doesn't work you are probably out of luck. I thi...
1
2009-03-02T10:49:03Z
[ "python", "tokyo-cabinet" ]
Python Table engine binding for Tokyo Cabinet
601,865
<p>I am looking for python bindings for Table engine of Tokyo cabinet. I tried <a href="http://pypi.python.org/pypi/pytc" rel="nofollow">Pytc</a> but can only find Hash and B-tree engine support. Is there any other bindings available?</p>
12
2009-03-02T10:18:23Z
732,178
<p>I was in contact with the author of tc and he told me the following:</p> <blockquote> <p>Currently, the table (tdb) driver exist in the <a href="http://github.com/rsms/tc/blob/master/src/TDB.c" rel="nofollow">master branch</a> (<a href="http://github.com/rsms/tc/blob/master/lib/tc/test/tdb.py" rel="nofollow">un...
4
2009-04-08T22:41:45Z
[ "python", "tokyo-cabinet" ]
Python Table engine binding for Tokyo Cabinet
601,865
<p>I am looking for python bindings for Table engine of Tokyo cabinet. I tried <a href="http://pypi.python.org/pypi/pytc" rel="nofollow">Pytc</a> but can only find Hash and B-tree engine support. Is there any other bindings available?</p>
12
2009-03-02T10:18:23Z
897,843
<p>Here is an implementation of search of table engine using PyTyrant:</p> <p><a href="http://github.com/ericflo/pytyrant/tree/master" rel="nofollow">http://github.com/ericflo/pytyrant/tree/master</a></p>
7
2009-05-22T13:25:52Z
[ "python", "tokyo-cabinet" ]
Python Table engine binding for Tokyo Cabinet
601,865
<p>I am looking for python bindings for Table engine of Tokyo cabinet. I tried <a href="http://pypi.python.org/pypi/pytc" rel="nofollow">Pytc</a> but can only find Hash and B-tree engine support. Is there any other bindings available?</p>
12
2009-03-02T10:18:23Z
1,312,908
<p>I've been monitoring (and sometimes improving) various Python bindings for TC for more than a year, so here's an updated list of best bindings matching your criteria.</p> <ul> <li>For Tokyo Cabinet, including Tyrant: <a href="http://pypi.python.org/pypi/tokyo-python/" rel="nofollow">tokyo-python</a></li> <li>For To...
2
2009-08-21T16:18:21Z
[ "python", "tokyo-cabinet" ]
Python Table engine binding for Tokyo Cabinet
601,865
<p>I am looking for python bindings for Table engine of Tokyo cabinet. I tried <a href="http://pypi.python.org/pypi/pytc" rel="nofollow">Pytc</a> but can only find Hash and B-tree engine support. Is there any other bindings available?</p>
12
2009-03-02T10:18:23Z
1,526,460
<p>My branch of pytc called "tc" do have support for tables (TDB) <a href="http://github.com/rsms/tc" rel="nofollow">http://github.com/rsms/tc</a></p> <p>Basic example:</p> <pre><code>&gt;&gt;&gt; import tc &gt;&gt;&gt; db = tc.TDB("slab.tdb", tc.TDBOWRITER | tc.TDBOCREAT) &gt;&gt;&gt; db.put('some key', {'name': 'Jo...
2
2009-10-06T15:46:35Z
[ "python", "tokyo-cabinet" ]
Digital Image cropping in Python
601,874
<p>Got this question from a professor, a physicist.</p> <p>I am a beginner in Python programming. I am not a computer professional I am a physicist. I was trying to write a code in python for my own research which involves a little image processing.</p> <p>All I need to do is to display an image and then select a reg...
4
2009-03-02T10:23:37Z
601,922
<p>Image.show() just calls whatever simple picture viewer it can find on the current platform, one that may or may not have a crop-and-save facility.</p> <p>If you are on a Windows box and you just need to make it work on your machine, set the ‘Open with...’ association to make it so running an image loads it into...
2
2009-03-02T10:49:56Z
[ "python", "image-processing" ]
Digital Image cropping in Python
601,874
<p>Got this question from a professor, a physicist.</p> <p>I am a beginner in Python programming. I am not a computer professional I am a physicist. I was trying to write a code in python for my own research which involves a little image processing.</p> <p>All I need to do is to display an image and then select a reg...
4
2009-03-02T10:23:37Z
601,942
<p>For what it's worth (coming from another physicist), I would just do this in an image processing program like <a href="http://www.gimp.org" rel="nofollow">the GIMP</a>. The main benefit of doing this task in Python (or any language) would be to save time by automating the process, but unless you - well, the professo...
4
2009-03-02T10:56:21Z
[ "python", "image-processing" ]
Digital Image cropping in Python
601,874
<p>Got this question from a professor, a physicist.</p> <p>I am a beginner in Python programming. I am not a computer professional I am a physicist. I was trying to write a code in python for my own research which involves a little image processing.</p> <p>All I need to do is to display an image and then select a reg...
4
2009-03-02T10:23:37Z
602,383
<p>While I agree with David that you should probably just use GIMP or some other image manipulation program, here is a script (as I took it to be an exercise to the reader) using <a href="http://www.pygame.org/">pygame</a> that does what you want. You will need to install pygame as well as the PIL, usage would be:</p>...
6
2009-03-02T13:39:00Z
[ "python", "image-processing" ]
Digital Image cropping in Python
601,874
<p>Got this question from a professor, a physicist.</p> <p>I am a beginner in Python programming. I am not a computer professional I am a physicist. I was trying to write a code in python for my own research which involves a little image processing.</p> <p>All I need to do is to display an image and then select a reg...
4
2009-03-02T10:23:37Z
6,654,047
<p>Is there a script in python like a library to auto crop images : <a href="http://codeunivers.com/source-codes/python/automatically_crop_image" rel="nofollow">Automatically crop image</a></p>
2
2011-07-11T17:34:31Z
[ "python", "image-processing" ]
Digital Image cropping in Python
601,874
<p>Got this question from a professor, a physicist.</p> <p>I am a beginner in Python programming. I am not a computer professional I am a physicist. I was trying to write a code in python for my own research which involves a little image processing.</p> <p>All I need to do is to display an image and then select a reg...
4
2009-03-02T10:23:37Z
6,880,221
<p>What you are looking for is the module: matplotlib, it emulates Matlab. See the ginput() function. That allow you to find the bounding box, then you can use crop from PIL. </p> <p><a href="http://matplotlib.sourceforge.net/api/figure_api.html" rel="nofollow">http://matplotlib.sourceforge.net/api/figure_api.html</a>...
0
2011-07-30T00:12:17Z
[ "python", "image-processing" ]
How to write meaningful docstrings?
601,900
<p>What, in Your opinion is a meaningful docstring? What do You expect to be described there?</p> <p>For example, consider this Python class's <code>__init__</code>:</p> <pre><code>def __init__(self, name, value, displayName=None, matchingRule="strict"): """ name - field name value - field value displ...
23
2009-03-02T10:39:52Z
601,909
<p>What should go there:</p> <p>Anything that you can't tell from the method's signature. In this case the only bit useful is: displayName - if empty will be set to field name.</p>
6
2009-03-02T10:44:16Z
[ "python", "comments", "docstring" ]
How to write meaningful docstrings?
601,900
<p>What, in Your opinion is a meaningful docstring? What do You expect to be described there?</p> <p>For example, consider this Python class's <code>__init__</code>:</p> <pre><code>def __init__(self, name, value, displayName=None, matchingRule="strict"): """ name - field name value - field value displ...
23
2009-03-02T10:39:52Z
601,960
<p>I like to use the documentation to describe in as much detail as possible what the function does, especially the behavior at corner cases (a.k.a. edge cases). Ideally, a programmer using the function should never have to look at the source code - in practice, that means that whenever another programmer does have to ...
1
2009-03-02T11:06:44Z
[ "python", "comments", "docstring" ]
How to write meaningful docstrings?
601,900
<p>What, in Your opinion is a meaningful docstring? What do You expect to be described there?</p> <p>For example, consider this Python class's <code>__init__</code>:</p> <pre><code>def __init__(self, name, value, displayName=None, matchingRule="strict"): """ name - field name value - field value displ...
23
2009-03-02T10:39:52Z
601,991
<p>I agree with "Anything that you can't tell from the method's signature". It might also mean to explain what a method/function returns.</p> <p>You might also want to use <a href="http://sphinx.pocoo.org/">Sphinx</a> (and reStructuredText syntax) for documentation purposes inside your docstrings. That way you can inc...
12
2009-03-02T11:25:15Z
[ "python", "comments", "docstring" ]
How to write meaningful docstrings?
601,900
<p>What, in Your opinion is a meaningful docstring? What do You expect to be described there?</p> <p>For example, consider this Python class's <code>__init__</code>:</p> <pre><code>def __init__(self, name, value, displayName=None, matchingRule="strict"): """ name - field name value - field value displ...
23
2009-03-02T10:39:52Z
602,160
<p>The most striking things I can think of to include in a docstring are the things that aren't obvious. Usually this includes type information, or capability requirements - eg. "Requires a file-like object". In some cases this will be evident from the signature, not so in other cases.</p> <p>Another useful thing you ...
2
2009-03-02T12:34:34Z
[ "python", "comments", "docstring" ]
How to write meaningful docstrings?
601,900
<p>What, in Your opinion is a meaningful docstring? What do You expect to be described there?</p> <p>For example, consider this Python class's <code>__init__</code>:</p> <pre><code>def __init__(self, name, value, displayName=None, matchingRule="strict"): """ name - field name value - field value displ...
23
2009-03-02T10:39:52Z
602,224
<p>From <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a>:</p> <blockquote> <p>Conventions for writing good documentation strings (a.k.a. "docstrings") are immortalized in <a href="http://www.python.org/dev/peps/pep-0257/" rel="nofollow">PEP 257</a>.</p> <ul> <li>Write docstrings f...
8
2009-03-02T12:51:32Z
[ "python", "comments", "docstring" ]
How to write meaningful docstrings?
601,900
<p>What, in Your opinion is a meaningful docstring? What do You expect to be described there?</p> <p>For example, consider this Python class's <code>__init__</code>:</p> <pre><code>def __init__(self, name, value, displayName=None, matchingRule="strict"): """ name - field name value - field value displ...
23
2009-03-02T10:39:52Z
4,690,279
<p>Check out numpy's docstrings for good examples (e.g. <a href="http://github.com/numpy/numpy/blob/master/numpy/core/numeric.py" rel="nofollow">http://github.com/numpy/numpy/blob/master/numpy/core/numeric.py</a>).</p> <p>The docstrings are split into several sections and look like this:</p> <pre><code>Compute the su...
4
2011-01-14T10:56:25Z
[ "python", "comments", "docstring" ]
Solution basis of underdetermined equation set in python
601,941
<p>I have an underdetermined equation set (m equations of n variables, m smaller than n). As such, if it is solvable then the set of solutions are a linear space (if it is a homogenic set) or affine space (non-homogenic).</p> <p>Is there an easy way in Python (possibly with other libraries) to obtain this space - for ...
2
2009-03-02T10:56:21Z
601,950
<p>Use <a href="http://docs.scipy.org/doc/scipy/reference/linalg.html" rel="nofollow">linalg</a> package from <a href="http://www.scipy.org" rel="nofollow">SciPy</a></p>
4
2009-03-02T11:01:32Z
[ "python", "linear-equation" ]
Solution basis of underdetermined equation set in python
601,941
<p>I have an underdetermined equation set (m equations of n variables, m smaller than n). As such, if it is solvable then the set of solutions are a linear space (if it is a homogenic set) or affine space (non-homogenic).</p> <p>Is there an easy way in Python (possibly with other libraries) to obtain this space - for ...
2
2009-03-02T10:56:21Z
602,113
<p>Like the previous poster said, you'll want linalg from SciPy, but focus on the <a href="http://en.wikipedia.org/wiki/Singular%5Fvalue%5Fdecomposition" rel="nofollow">Singular Value Decomposition</a> solution. The matrix U is the basis for the output vectors.</p>
2
2009-03-02T12:19:30Z
[ "python", "linear-equation" ]
Store last created model's row in memory
602,030
<p>I am working on ajax-game. The abstract: 2+ gamers(browsers) change a variable which is saved to DB through json. All gamers are synchronized by javascript-timer+json - periodically reading that variable from DB. </p> <p>In general, all changes are stored in DB as history, but I want the recent change duplicated in...
0
2009-03-02T11:46:17Z
603,121
<p>You can use the cache system:</p> <p><a href="http://docs.djangoproject.com/en/dev/topics/cache/#topics-cache" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/cache/#topics-cache</a></p>
0
2009-03-02T17:11:29Z
[ "python", "django" ]
Store last created model's row in memory
602,030
<p>I am working on ajax-game. The abstract: 2+ gamers(browsers) change a variable which is saved to DB through json. All gamers are synchronized by javascript-timer+json - periodically reading that variable from DB. </p> <p>In general, all changes are stored in DB as history, but I want the recent change duplicated in...
0
2009-03-02T11:46:17Z
603,202
<p>Unfortunately I don't believe you can do this unless you only have one instance of Python running, in which case you can use a global variable. With most web implementations you have a threaded server so this would not work. You would have to do a fetch from the database to get the latest copy of the record.</p> ...
0
2009-03-02T17:30:43Z
[ "python", "django" ]
Store last created model's row in memory
602,030
<p>I am working on ajax-game. The abstract: 2+ gamers(browsers) change a variable which is saved to DB through json. All gamers are synchronized by javascript-timer+json - periodically reading that variable from DB. </p> <p>In general, all changes are stored in DB as history, but I want the recent change duplicated in...
0
2009-03-02T11:46:17Z
603,637
<p>You'd either have to use a cache, or fetch the most recent change on each request (since you can't persist objects between requests in-memory).</p> <p>From what you describe, it sounds as if it's being hit fairly frequently, so the cache is probably the way to go.</p>
0
2009-03-02T19:27:43Z
[ "python", "django" ]
Store last created model's row in memory
602,030
<p>I am working on ajax-game. The abstract: 2+ gamers(browsers) change a variable which is saved to DB through json. All gamers are synchronized by javascript-timer+json - periodically reading that variable from DB. </p> <p>In general, all changes are stored in DB as history, but I want the recent change duplicated in...
0
2009-03-02T11:46:17Z
723,413
<p>Would something like <a href="http://www.danga.com/memcached/" rel="nofollow"><code>memcached</code></a> be suitable?</p>
0
2009-04-06T21:57:34Z
[ "python", "django" ]
Should I check the types of constructor arguments (and at other places too)?
602,046
<p>Python discourages checking the types. But in many cases this may be useful:</p> <ol> <li><p>Checking constructor arguments. e.g. checking foe Boolean, string, dict etc. If I don't and set the object's members to the arguments it will cause problems later.</p></li> <li><p>Checking functions arguments.</p></li> <li>...
9
2009-03-02T11:55:04Z
602,078
<p>The simple answer is <strong>No</strong>, use Polymorphism, Exceptions etc. </p> <ol> <li><p>In the case of constructor arguments being of the wrong type, an exception will be thrown when executing code that depend s on the parameter being of a particular type. If it is a weird, domain specific thing, raise your ow...
8
2009-03-02T12:04:19Z
[ "python", "typechecking" ]
Should I check the types of constructor arguments (and at other places too)?
602,046
<p>Python discourages checking the types. But in many cases this may be useful:</p> <ol> <li><p>Checking constructor arguments. e.g. checking foe Boolean, string, dict etc. If I don't and set the object's members to the arguments it will cause problems later.</p></li> <li><p>Checking functions arguments.</p></li> <li>...
9
2009-03-02T11:55:04Z
602,087
<p>Check all you like, you just have to be explicit. The following example is a constructor from <a href="http://svn.python.org/view/python/trunk/Lib/csv.py?view=markup" rel="nofollow">a module</a> in the standard library - it checks the <code>extrasaction</code> arg:</p> <pre><code>class DictWriter: def __init__(se...
3
2009-03-02T12:06:35Z
[ "python", "typechecking" ]
Should I check the types of constructor arguments (and at other places too)?
602,046
<p>Python discourages checking the types. But in many cases this may be useful:</p> <ol> <li><p>Checking constructor arguments. e.g. checking foe Boolean, string, dict etc. If I don't and set the object's members to the arguments it will cause problems later.</p></li> <li><p>Checking functions arguments.</p></li> <li>...
9
2009-03-02T11:55:04Z
602,097
<p>The answer is almost always "no". The general idea in Python, Ruby, and some other languages us called "<a href="http://en.wikipedia.org/wiki/Duck%5Ftyping">Duck Typing</a>". You shouldn't care what something is, only how it works. In other words, "if all you want is something that quacks, you don't need to check th...
11
2009-03-02T12:12:01Z
[ "python", "typechecking" ]
Should I check the types of constructor arguments (and at other places too)?
602,046
<p>Python discourages checking the types. But in many cases this may be useful:</p> <ol> <li><p>Checking constructor arguments. e.g. checking foe Boolean, string, dict etc. If I don't and set the object's members to the arguments it will cause problems later.</p></li> <li><p>Checking functions arguments.</p></li> <li>...
9
2009-03-02T11:55:04Z
602,391
<p>"If I don't and set the object's members to the arguments it will cause problems later."</p> <p>Please be very clear on the exact list of "problems" which will be caused later.</p> <ul> <li><p>Will it not work at all? That what try/except blocks are for.</p></li> <li><p>Will it behave "oddly"? This is really rar...
0
2009-03-02T13:41:16Z
[ "python", "typechecking" ]
Should I check the types of constructor arguments (and at other places too)?
602,046
<p>Python discourages checking the types. But in many cases this may be useful:</p> <ol> <li><p>Checking constructor arguments. e.g. checking foe Boolean, string, dict etc. If I don't and set the object's members to the arguments it will cause problems later.</p></li> <li><p>Checking functions arguments.</p></li> <li>...
9
2009-03-02T11:55:04Z
602,395
<p>It is often a good thing to do. Checking for explicit types is probably not so useful in Python (as others have said), but checking for legal values can be a good idea. The reason it's a good idea is that the software will fail closer to the source of the bug (it follows the Fail Fast Principle). Also, the checks ac...
1
2009-03-02T13:42:06Z
[ "python", "typechecking" ]
Should I check the types of constructor arguments (and at other places too)?
602,046
<p>Python discourages checking the types. But in many cases this may be useful:</p> <ol> <li><p>Checking constructor arguments. e.g. checking foe Boolean, string, dict etc. If I don't and set the object's members to the arguments it will cause problems later.</p></li> <li><p>Checking functions arguments.</p></li> <li>...
9
2009-03-02T11:55:04Z
604,568
<p>AFAIU, you want to make sure that some objects behave ("follow an interface") at an earlier time than that of the actual use. In your example, you want to know that objects are appropriate at instance creation time, not when they will actually be used.</p> <p>Keeping in mind that we're talking Python here, I won't ...
0
2009-03-03T00:02:14Z
[ "python", "typechecking" ]
Should I check the types of constructor arguments (and at other places too)?
602,046
<p>Python discourages checking the types. But in many cases this may be useful:</p> <ol> <li><p>Checking constructor arguments. e.g. checking foe Boolean, string, dict etc. If I don't and set the object's members to the arguments it will cause problems later.</p></li> <li><p>Checking functions arguments.</p></li> <li>...
9
2009-03-02T11:55:04Z
604,615
<p>As dalke says, the answer is almost always "no". In Python, you generally do not care that a a parameter <em>is</em> a certain type but rather that it <em>behaves</em> like a certain type. This is known as "<a href="http://en.wikipedia.org/wiki/Duck%5Ftyping" rel="nofollow">Duck Typing</a>". There are two ways to te...
0
2009-03-03T00:14:47Z
[ "python", "typechecking" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
602,111
<p>nikow: I can only answer for myself, most of my Python (and PHP or Ruby, all dynamic "scripting" languages) work is done <em>just for me</em> - but I always release it on my personal site if anyone else finds it useful, but I never go through any documentation or QA process because as long as it works for me I'm hap...
0
2009-03-02T12:18:28Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
602,116
<p>PEP8 is a style <strong>guide</strong>, not a style requirement. It even states that you should "know when to be inconsistent".</p> <p>Personally, I don't like some of the guidelines in it. I prefer tabs to spaces (but still abhor the mixing of the two).</p> <p>And, to be brutal, I don't often look at the source c...
4
2009-03-02T12:21:19Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
602,128
<p>Well, they <strong>are</strong> open source. As such they will also evolve over time, if they are good enough. </p> <p>That's one of the many beauties of open source.</p> <p>Often there is little sense in writing lot of documentation and "good" code if you don't know whether the project will live on. That would ju...
0
2009-03-02T12:24:54Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
602,137
<p>PEP8 is just that, a convention, not a requirement. It would be really sad if all python programmers <em>had</em> to adhere to a common set of rules, we lose enthusiasm over the slightest of issues.</p> <p>As far as missing docstrings are concerned - yes, they can help when using interactive help - but I generally ...
1
2009-03-02T12:26:34Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
602,139
<p>Regarding documentation, it's not just Python. If there is one single factor that is preventing the wider adoption of OSS it is, IMHO, the truly dreadful level of documentation of most OSS projects. This starts at the code level and extends to the user docs. Can I just say to anyone working on OSS:</p> <p>a) Commen...
21
2009-03-02T12:26:45Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
602,172
<blockquote> <p>Instead the authors each seem to follow their own glorious convention. And sometimes the conventions are not even consistent with the same file of a library</p> </blockquote> <p>Welcome to the wonderful code of the real world!</p> <p>FWIW Python code I have met is no better or worse than that in any...
7
2009-03-02T12:37:26Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
602,217
<p>This is because Python is not backed up by the corporate world like Java or .Net .</p> <p>If I want my Java library to be promoted by Sun I will follow their guidelines. This is not the case with Python. I write my code, people find it better and it has to evolve on its own.</p> <p>Also most Python developers are ...
5
2009-03-02T12:49:15Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
602,220
<p>As for matplotlib, there is project to improve it's "pythoness" - <a href="http://www.scipy.org/PyLab" rel="nofollow">http://www.scipy.org/PyLab</a></p> <p>The thing about scientific libraries, is that they are written by scientist, no by professional software developers. Moveover, those scientist are used to write...
4
2009-03-02T12:50:09Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
602,236
<p>Quality of code * number of comments * time = constant</p> <p>Pick two !</p> <p>I never had any problem using matplotlib; can't say I looked at the code much - it is a fine library. Does what it is supposed to do (for free !)</p>
0
2009-03-02T12:55:10Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
602,280
<p>PEP 8 has changed over time. Some modules follow older recommendations. You can see that with PIL, which uses modules like "Image" where the module contains a single main class, instead of the recommended lowercase for module names, and in C extensions which use the "c" prefix, rather than the more modern "_" prefix...
6
2009-03-02T13:05:08Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
602,406
<blockquote> <p>Ninety percent of [python libraries] are crud, but ninety percent of everything is crud</p> </blockquote> <p>-- Sturgeons law (paraphrased)</p>
5
2009-03-02T13:45:32Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
602,703
<p>I believe that Python suffers from being hoisted too eagerly on people who are not programmers (by schooling or trade) as a solution for "need some programming done? Here, try this easy and mature tool". </p> <p>Similarly to how PHP became such a huge success and with so many libraries with abysmal code quality (ev...
4
2009-03-02T15:19:13Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
603,218
<p>It sounds like you have come to find that code quality does not meet the expectations you were set up to expect. Perhaps from school, or best practices books or senior developers.</p> <p>After having worked at several companies, I found myself regularly advised to do unit tests, document code, use version/source co...
5
2009-03-02T17:32:58Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
603,336
<p>Regarding comparison with other languages, I think that language design plays a big part here. For example, in a strong-typed language like Java, even if the library is missing good documentation, you can still deduce much of the functionality from the method signatures. No <code>*args</code> to contend with.</p>
1
2009-03-02T17:56:35Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
603,872
<p>The first thing you need to realize is that Python did not spring, fully formed, from the head of Guido sometime around version 2.x. It's grown over the course of the past twenty years.</p> <p>In fact, a number of the things you mention (unittest, for example, and PEP-8), didn't even exist when some of the standar...
7
2009-03-02T20:27:56Z
[ "python", "conventions" ]
Do many Python libraries have relatively low code quality?
602,096
<p><strong>Edit:</strong> Since this question was asked a lot of improvement has happened in the standard Python scientific libraries (which was the targeted area). For example the numpy project has made a big effort to improve the docstrings. One can still argue if it would have been possible to address these issues c...
14
2009-03-02T12:11:56Z
653,944
<p>How about a collection of examples of good software doc ?<br /> Good examples might lead to overall improvement a bit faster than random walk.<br /> The collection could be split into categories such as:<br /> inline doc / help page / tutorial / reference manual, web page / paper, pictures / none.<br /> Each entry s...
1
2009-03-17T12:06:57Z
[ "python", "conventions" ]
Differential AJAX updates for HTML table?
602,322
<p>I have a <a href="http://conquer-on-contact.bthomson.com" rel="nofollow">game</a> on Google App Engine that's based on a 25x20 HTML table (the game board). Every 3 seconds the user can "move," which sends an AJAX request to the server, at which time the server rerenders the entire HTML table and sends it to the user...
2
2009-03-02T13:17:57Z
602,381
<p>Without thinking of deltas:</p> <p>You can use JSON quite easily to do this sort of thing. You can roll out your own compressed format, too.</p> <p>I think compressing the data using gzip would help a lot. Most browsers nowadays support it, and it will greatly reduce the size of your responses.</p>
1
2009-03-02T13:38:00Z
[ "jquery", "python", "html", "google-app-engine", "dhtml" ]
Differential AJAX updates for HTML table?
602,322
<p>I have a <a href="http://conquer-on-contact.bthomson.com" rel="nofollow">game</a> on Google App Engine that's based on a 25x20 HTML table (the game board). Every 3 seconds the user can "move," which sends an AJAX request to the server, at which time the server rerenders the entire HTML table and sends it to the user...
2
2009-03-02T13:17:57Z
602,396
<p>If you known the state between refreshes on the server side (see comment on question), you an send the data using JSON like so (not sure about exact syntax):</p> <pre><code>[ { x: 3, y: 5, class: "asdf", content: "1234" }, { x: 6, y: 5, class: "asdf", content: "8156" }, { x: 2, y: 2, class: "qwer", cont...
2
2009-03-02T13:42:54Z
[ "jquery", "python", "html", "google-app-engine", "dhtml" ]
Differential AJAX updates for HTML table?
602,322
<p>I have a <a href="http://conquer-on-contact.bthomson.com" rel="nofollow">game</a> on Google App Engine that's based on a 25x20 HTML table (the game board). Every 3 seconds the user can "move," which sends an AJAX request to the server, at which time the server rerenders the entire HTML table and sends it to the user...
2
2009-03-02T13:17:57Z
603,701
<p>You can model your game board as a multidimensional javascript array:</p> <pre><code>[[x0, x1, x2, x3 ... xn], ..... .....] </code></pre> <p>each entry is an array representing a row. Each cell holds the numerical value of the game piece/square.</p> <p>This model can be the "contract" you send to the server via a...
2
2009-03-02T19:47:12Z
[ "jquery", "python", "html", "google-app-engine", "dhtml" ]
Evil code from the Python standard library
602,445
<p>So, we have had this: <a href="http://lucumr.pocoo.org/2009/3/1/the-1000-speedup-or-the-stdlib-sucks" rel="nofollow">http://lucumr.pocoo.org/2009/3/1/the-1000-speedup-or-the-stdlib-sucks</a>. It demonstrates a rather bad bug that is probably costing the universe a load of cycles even as we speak. It's fixed now, whi...
7
2009-03-02T14:03:39Z
602,460
<p>Never attribute to malice that which can be adequately explained by stupidity.</p>
10
2009-03-02T14:12:17Z
[ "python", "std" ]
Evil code from the Python standard library
602,445
<p>So, we have had this: <a href="http://lucumr.pocoo.org/2009/3/1/the-1000-speedup-or-the-stdlib-sucks" rel="nofollow">http://lucumr.pocoo.org/2009/3/1/the-1000-speedup-or-the-stdlib-sucks</a>. It demonstrates a rather bad bug that is probably costing the universe a load of cycles even as we speak. It's fixed now, whi...
7
2009-03-02T14:03:39Z
602,474
<p>The <a href="http://docs.python.org/library/rexec.html" rel="nofollow">rexec</a> module has so many security holes in it that it's almost useless.</p>
3
2009-03-02T14:15:54Z
[ "python", "std" ]
Evil code from the Python standard library
602,445
<p>So, we have had this: <a href="http://lucumr.pocoo.org/2009/3/1/the-1000-speedup-or-the-stdlib-sucks" rel="nofollow">http://lucumr.pocoo.org/2009/3/1/the-1000-speedup-or-the-stdlib-sucks</a>. It demonstrates a rather bad bug that is probably costing the universe a load of cycles even as we speak. It's fixed now, whi...
7
2009-03-02T14:03:39Z
602,525
<p>(since this is a different module, placing it in a different answer)</p> <p><a href="http://docs.python.org/library/cgitb.html" rel="nofollow">cgitb</a> has some weird threading issues. See <a href="http://bugs.python.org/issue1665206" rel="nofollow">this bug report</a>.</p>
2
2009-03-02T14:27:51Z
[ "python", "std" ]
How can I use C++ class in Python?
602,580
<p>I have implemented a class in C++. I want to use it with Python. <strong>Please suggest step by step method and elaborate each step.</strong> Somthing like this...</p> <pre><code>class Test{ private: int n; public: Test(int k){ n=k; } void setInt(int k){ ...
27
2009-03-02T14:47:11Z
602,592
<p>I would suggest you try SWIG or sip (KDE/PyQt).</p> <p>SWIG link : <a href="http://www.swig.org/">http://www.swig.org/</a><br /> SIP link: <a href="http://freshmeat.net/projects/python-sip/">http://freshmeat.net/projects/python-sip/</a></p> <p>These can be used to wrap C++ classes and provide a Pythonic interface ...
6
2009-03-02T14:49:39Z
[ "c++", "python", "class" ]
How can I use C++ class in Python?
602,580
<p>I have implemented a class in C++. I want to use it with Python. <strong>Please suggest step by step method and elaborate each step.</strong> Somthing like this...</p> <pre><code>class Test{ private: int n; public: Test(int k){ n=k; } void setInt(int k){ ...
27
2009-03-02T14:47:11Z
602,594
<p>Look into <a href="http://www.boost.org/doc/libs/1%5F38%5F0/libs/python/doc/index.html">Boost.Python</a>. It's a library to write python modules with C++.</p> <p>Also look into <a href="http://www.swig.org/">SWIG</a> which can also handle modules for other scripting languages. I've used it in the past to write modu...
21
2009-03-02T14:49:48Z
[ "c++", "python", "class" ]
How can I use C++ class in Python?
602,580
<p>I have implemented a class in C++. I want to use it with Python. <strong>Please suggest step by step method and elaborate each step.</strong> Somthing like this...</p> <pre><code>class Test{ private: int n; public: Test(int k){ n=k; } void setInt(int k){ ...
27
2009-03-02T14:47:11Z
602,666
<p><a href="https://docs.python.org/2/library/ctypes.html" rel="nofollow">ctypes</a> is good. It is really easy to use, and it comes standard with Python. Unfortunately it can only talk to shared libraries (Unix) or DLLs (Windows) that have a C-style interface, which means you can't directly interface to a C++ object. ...
8
2009-03-02T15:06:33Z
[ "c++", "python", "class" ]
How to show the output of 'l' in python pdb after every command entered
602,599
<p>I would like to have the output of the python pdb 'l' command printed to the screen after every command I enter in an interactive debugging session.</p> <p>Is there a way to setup python pdb to do this?</p>
4
2009-03-02T14:51:11Z
602,733
<p>';;' allow to separate commands</p> <pre> <code> [crchemist@test tmp]$ python t.py > /home/crchemist/tmp/t.py(7)() -> a() (Pdb) p a ;; l function a at 0xb7e96df4 2 b = 49 + 45 3 v = 'fff' 4 return v 5 6 import pdb; pdb.set_trace() 7 -> a() [EOF] (Pdb) s ;; l --Call-- > /home...
2
2009-03-02T15:25:19Z
[ "python", "debugging", "pdb" ]
How to show the output of 'l' in python pdb after every command entered
602,599
<p>I would like to have the output of the python pdb 'l' command printed to the screen after every command I enter in an interactive debugging session.</p> <p>Is there a way to setup python pdb to do this?</p>
4
2009-03-02T14:51:11Z
602,750
<p>One way to do this is to alias your favourite commands to run the command and then l.</p> <p>e.g.</p> <pre><code>(Pdb) alias s step ;; l (Pdb) s &gt; /usr/lib/python2.5/distutils/core.py(14)&lt;module&gt;() -&gt; from types import * 9 # This module should be kept compatible with Python 2.1. 10 11 ...
5
2009-03-02T15:29:38Z
[ "python", "debugging", "pdb" ]
How can I access the current executing module or class name in Python?
602,846
<p>I would like to be able to dynamically retrieve the current executing module or class name from within an imported module. Here is some code:</p> <p><strong>foo.py:</strong></p> <pre><code>def f(): print __name__ </code></pre> <p><strong>bar.py:</strong></p> <pre><code>from foo import f def b(): f() </code...
15
2009-03-02T15:55:53Z
602,859
<p>I don't believe that's possible since that's out of <code>foo</code>'s scope. foo will only be aware of its internal scope since it may be being called by countless other modules and applications.</p>
2
2009-03-02T15:59:54Z
[ "python", "module" ]
How can I access the current executing module or class name in Python?
602,846
<p>I would like to be able to dynamically retrieve the current executing module or class name from within an imported module. Here is some code:</p> <p><strong>foo.py:</strong></p> <pre><code>def f(): print __name__ </code></pre> <p><strong>bar.py:</strong></p> <pre><code>from foo import f def b(): f() </code...
15
2009-03-02T15:55:53Z
602,881
<p>I think what you want to use is the <a href="http://docs.python.org/library/inspect.html" rel="nofollow">inspect</a> module, to inspect the python runtime stack. Check out this <a href="http://telin.ugent.be/~slippens/drupal/node/148" rel="nofollow">tutorial</a>. I think it provides an almost exact example of what...
9
2009-03-02T16:04:33Z
[ "python", "module" ]
How can I access the current executing module or class name in Python?
602,846
<p>I would like to be able to dynamically retrieve the current executing module or class name from within an imported module. Here is some code:</p> <p><strong>foo.py:</strong></p> <pre><code>def f(): print __name__ </code></pre> <p><strong>bar.py:</strong></p> <pre><code>from foo import f def b(): f() </code...
15
2009-03-02T15:55:53Z
602,967
<p>The "currently executing module" clearly is foo, as that's what contains the function currently running - I think a better description as to what you want is the module of foo's immediate caller (which may itself be foo if you're calling a f() from a function in foo called by a function in bar. How far you want to ...
10
2009-03-02T16:27:58Z
[ "python", "module" ]
How can I access the current executing module or class name in Python?
602,846
<p>I would like to be able to dynamically retrieve the current executing module or class name from within an imported module. Here is some code:</p> <p><strong>foo.py:</strong></p> <pre><code>def f(): print __name__ </code></pre> <p><strong>bar.py:</strong></p> <pre><code>from foo import f def b(): f() </code...
15
2009-03-02T15:55:53Z
602,968
<p>It's been a while since I've done python, but I believe that you can get access to the globals and locals of a caller through its <a href="http://docs.python.org/library/traceback.html" rel="nofollow">traceback</a>.</p>
0
2009-03-02T16:28:00Z
[ "python", "module" ]
How can I access the current executing module or class name in Python?
602,846
<p>I would like to be able to dynamically retrieve the current executing module or class name from within an imported module. Here is some code:</p> <p><strong>foo.py:</strong></p> <pre><code>def f(): print __name__ </code></pre> <p><strong>bar.py:</strong></p> <pre><code>from foo import f def b(): f() </code...
15
2009-03-02T15:55:53Z
603,460
<p>From the comment -- not the question.</p> <p>"I am simply curious to see if what I am trying to do is possible."</p> <p>The answer to "is it possible" is always "yes". Always. Unless your question involves time travel, anti-gravity or perpetual motion. </p> <p>Since the answer is always "yes", your question is...
26
2009-03-02T18:36:31Z
[ "python", "module" ]
How can I access the current executing module or class name in Python?
602,846
<p>I would like to be able to dynamically retrieve the current executing module or class name from within an imported module. Here is some code:</p> <p><strong>foo.py:</strong></p> <pre><code>def f(): print __name__ </code></pre> <p><strong>bar.py:</strong></p> <pre><code>from foo import f def b(): f() </code...
15
2009-03-02T15:55:53Z
603,503
<p><code>__file__</code> is the path of current module the call is made.</p>
2
2009-03-02T18:49:32Z
[ "python", "module" ]
How can I access the current executing module or class name in Python?
602,846
<p>I would like to be able to dynamically retrieve the current executing module or class name from within an imported module. Here is some code:</p> <p><strong>foo.py:</strong></p> <pre><code>def f(): print __name__ </code></pre> <p><strong>bar.py:</strong></p> <pre><code>from foo import f def b(): f() </code...
15
2009-03-02T15:55:53Z
7,810,592
<p>This should work for referencing the current module:</p> <pre><code>import sys sys.modules[__name__] </code></pre>
13
2011-10-18T16:27:55Z
[ "python", "module" ]
python opens text file with a space between every character
603,115
<p>Whenever I try to open a .csv file with the python command <code>fread = open('input.csv', 'r')</code> it always opens the file with spaces between every single character. I'm guessing it's something wrong with the text file because I can open other text files with the same command and they are loaded correctly. D...
8
2009-03-02T17:09:38Z
603,122
<p>First of all, use an hex-editor to view the file, see if there is anything irregular about it.</p> <p>Secondly, please post the code you are using.</p>
1
2009-03-02T17:11:52Z
[ "python", "csv", "text-files" ]
python opens text file with a space between every character
603,115
<p>Whenever I try to open a .csv file with the python command <code>fread = open('input.csv', 'r')</code> it always opens the file with spaces between every single character. I'm guessing it's something wrong with the text file because I can open other text files with the same command and they are loaded correctly. D...
8
2009-03-02T17:09:38Z
603,135
<p>It did never ocurred to me, but as truppo said, it must be something wrong with the file.</p> <p>Try to open the file in Excel/BrOffice Calc and Save As the file as Csv again.</p> <p>If the problem persists, try a subset of the data: fist 10/last 10/intermediate 10 lines of the file.</p>
0
2009-03-02T17:15:28Z
[ "python", "csv", "text-files" ]
python opens text file with a space between every character
603,115
<p>Whenever I try to open a .csv file with the python command <code>fread = open('input.csv', 'r')</code> it always opens the file with spaces between every single character. I'm guessing it's something wrong with the text file because I can open other text files with the same command and they are loaded correctly. D...
8
2009-03-02T17:09:38Z
603,152
<p>Isn't csv a simple txt file with values separated with comma. Just try to open it with a text editor to see if the file is correctly formed.</p>
1
2009-03-02T17:18:54Z
[ "python", "csv", "text-files" ]
python opens text file with a space between every character
603,115
<p>Whenever I try to open a .csv file with the python command <code>fread = open('input.csv', 'r')</code> it always opens the file with spaces between every single character. I'm guessing it's something wrong with the text file because I can open other text files with the same command and they are loaded correctly. D...
8
2009-03-02T17:09:38Z
603,157
<p>You might as well upload the file in question to a site like <a href="http://drop.io/" rel="nofollow">http://drop.io/</a> and give us a link.</p>
0
2009-03-02T17:20:43Z
[ "python", "csv", "text-files" ]
python opens text file with a space between every character
603,115
<p>Whenever I try to open a .csv file with the python command <code>fread = open('input.csv', 'r')</code> it always opens the file with spaces between every single character. I'm guessing it's something wrong with the text file because I can open other text files with the same command and they are loaded correctly. D...
8
2009-03-02T17:09:38Z
603,162
<p>The file is encoded in some unicode encoding, but you are reading it as ascii. Try to convert the file to ascii before using it in python.</p>
7
2009-03-02T17:22:06Z
[ "python", "csv", "text-files" ]
python opens text file with a space between every character
603,115
<p>Whenever I try to open a .csv file with the python command <code>fread = open('input.csv', 'r')</code> it always opens the file with spaces between every single character. I'm guessing it's something wrong with the text file because I can open other text files with the same command and they are loaded correctly. D...
8
2009-03-02T17:09:38Z
603,233
<p>The post by recursive is probably right... the contents of the file are likely encoded with a multi-byte charset. If this is, in fact, the case you can likely read the file in python itself without having to convert it first outside of python.</p> <p>Try something like:</p> <pre><code>fread = open('input.csv', 'rb...
12
2009-03-02T17:36:55Z
[ "python", "csv", "text-files" ]
python opens text file with a space between every character
603,115
<p>Whenever I try to open a .csv file with the python command <code>fread = open('input.csv', 'r')</code> it always opens the file with spaces between every single character. I'm guessing it's something wrong with the text file because I can open other text files with the same command and they are loaded correctly. D...
8
2009-03-02T17:09:38Z
603,321
<p>Ok, I got it with the help of Jarret Hardie's post</p> <p>this is the code that I used to convert the file to ascii</p> <pre><code>fread = open('input.csv', 'rb').read() mytext = fread.decode('utf-16') mytext = mytext.encode('ascii', 'ignore') fwrite = open('input-ascii.csv', 'wb') fwrite.write(mytext) </code></pr...
1
2009-03-02T17:54:02Z
[ "python", "csv", "text-files" ]
python opens text file with a space between every character
603,115
<p>Whenever I try to open a .csv file with the python command <code>fread = open('input.csv', 'r')</code> it always opens the file with spaces between every single character. I'm guessing it's something wrong with the text file because I can open other text files with the same command and they are loaded correctly. D...
8
2009-03-02T17:09:38Z
603,331
<p>Open the file in binary mode, 'rb'. Check it in a HEX Editor and check for null padding '00'. Open the file in something like Scintilla Text Editor to check the characters present in the file.</p>
0
2009-03-02T17:55:56Z
[ "python", "csv", "text-files" ]
python opens text file with a space between every character
603,115
<p>Whenever I try to open a .csv file with the python command <code>fread = open('input.csv', 'r')</code> it always opens the file with spaces between every single character. I'm guessing it's something wrong with the text file because I can open other text files with the same command and they are loaded correctly. D...
8
2009-03-02T17:09:38Z
874,253
<p>To read an encoded file, you can simply replace <code>open</code> with <code>codecs.open</code>.</p> <pre><code>fread = codecs.open('input.csv', 'r', 'utf-16') </code></pre>
1
2009-05-17T09:39:21Z
[ "python", "csv", "text-files" ]
python opens text file with a space between every character
603,115
<p>Whenever I try to open a .csv file with the python command <code>fread = open('input.csv', 'r')</code> it always opens the file with spaces between every single character. I'm guessing it's something wrong with the text file because I can open other text files with the same command and they are loaded correctly. D...
8
2009-03-02T17:09:38Z
10,708,164
<p>Here's the quick and easy way, esp if python won't parse the input correctly</p> <pre><code>sed 's/ \(.\)/\1/g' </code></pre>
0
2012-05-22T18:48:31Z
[ "python", "csv", "text-files" ]
Finding anchor text when there are tags there
603,199
<p>I want to find the text between a pair of &lt;a&gt; tags that link to a given site</p> <p>Here's the re string that I'm using to find the content:</p> <pre><code>r'''(&lt;a([^&lt;&gt;]*)href=("|')(http://)?(www\.)?%s([^'"]*)("|')([^&lt;&gt;]*)&gt;([^&lt;]*))&lt;/a&gt;''' % our_url </code></pre> <p>The result will...
3
2009-03-02T17:29:43Z
603,211
<p>I would not use a regex - use an HTML parser like <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a>.</p>
2
2009-03-02T17:32:17Z
[ "python", "regex" ]
Finding anchor text when there are tags there
603,199
<p>I want to find the text between a pair of &lt;a&gt; tags that link to a given site</p> <p>Here's the re string that I'm using to find the content:</p> <pre><code>r'''(&lt;a([^&lt;&gt;]*)href=("|')(http://)?(www\.)?%s([^'"]*)("|')([^&lt;&gt;]*)&gt;([^&lt;]*))&lt;/a&gt;''' % our_url </code></pre> <p>The result will...
3
2009-03-02T17:29:43Z
603,216
<p>Do a non greedy search i.e. </p> <pre><code>(.*?) </code></pre>
1
2009-03-02T17:32:35Z
[ "python", "regex" ]
Finding anchor text when there are tags there
603,199
<p>I want to find the text between a pair of &lt;a&gt; tags that link to a given site</p> <p>Here's the re string that I'm using to find the content:</p> <pre><code>r'''(&lt;a([^&lt;&gt;]*)href=("|')(http://)?(www\.)?%s([^'"]*)("|')([^&lt;&gt;]*)&gt;([^&lt;]*))&lt;/a&gt;''' % our_url </code></pre> <p>The result will...
3
2009-03-02T17:29:43Z
603,235
<p>Instead of:</p> <pre><code>[^&lt;&gt;]* </code></pre> <p>Try:</p> <pre><code>((?!&lt;/a).)* </code></pre> <p>In other words, match any character that isn't the start of a <code>&lt;/a</code> sequence.</p>
3
2009-03-02T17:37:13Z
[ "python", "regex" ]
Finding anchor text when there are tags there
603,199
<p>I want to find the text between a pair of &lt;a&gt; tags that link to a given site</p> <p>Here's the re string that I'm using to find the content:</p> <pre><code>r'''(&lt;a([^&lt;&gt;]*)href=("|')(http://)?(www\.)?%s([^'"]*)("|')([^&lt;&gt;]*)&gt;([^&lt;]*))&lt;/a&gt;''' % our_url </code></pre> <p>The result will...
3
2009-03-02T17:29:43Z
604,606
<pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; pattern = re.compile(r'&lt;a.+href=[\'|\"](.+)[\'|\"].*?&gt;(.+)&lt;/a&gt;', re.IGNORECASE) &gt;&gt;&gt; link = '&lt;a href="http://stackoverflow.com/questions/603199/finding-anchor-text-when-there-are-tags-there"&gt;Finding anchor text when there are tags there&lt;/a&gt;'...
3
2009-03-03T00:13:46Z
[ "python", "regex" ]
Need python lxml syntax help for parsing html
603,287
<p>I am brand new to python, and I need some help with the syntax for finding and iterating through html tags using lxml. Here are the use-cases I am dealing with:</p> <p>HTML file is fairly well formed (but not perfect). Has multiple tables on screen, one containing a set of search results, and one each for a heade...
16
2009-03-02T17:48:28Z
603,308
<p>Is there a reason you're not using <a href="http://www.crummy.com/software/BeautifulSoup/">Beautiful Soup</a> for this project? It will make dealing with imperfectly formed documents much easier.</p>
5
2009-03-02T17:51:14Z
[ "python", "html-parsing", "lxml" ]
Need python lxml syntax help for parsing html
603,287
<p>I am brand new to python, and I need some help with the syntax for finding and iterating through html tags using lxml. Here are the use-cases I am dealing with:</p> <p>HTML file is fairly well formed (but not perfect). Has multiple tables on screen, one containing a set of search results, and one each for a heade...
16
2009-03-02T17:48:28Z
603,630
<p>Okay, first, in regards to parsing the HTML: if you follow the recommendation of zweiterlinde and S.Lott at least use the version of <a href="http://lxml.de/elementsoup.html" rel="nofollow">beautifulsoup included with lxml</a>. That way you will also reap the benefit of a nice xpath or css selector interface.</p> ...
27
2009-03-02T19:27:20Z
[ "python", "html-parsing", "lxml" ]
Using PyQT, how do you filter mousePressEvent for a QComboBox with custom list
603,528
<p>I've got a <code>QComboBox</code> with a custom list object. </p> <p><img src="http://i.stack.imgur.com/r71L2.png" alt="Screenshot."></p> <p>The custom list object has a custom <code>mousePressEvent</code> so that when the user click on one of the circles with a +/- (a twisty), the list is expanded/collapsed. </p>...
3
2009-03-02T18:55:19Z
605,260
<p>Off the top of my head, you could subclass <code>QComboBox</code> and override <code>hideEvent(QHideEvent)</code> (inherited from <code>QWidget</code>)</p> <pre><code>def hideEvent(self, event): if self.OkToHide(): event.accept() else: event.ignore() </code></pre> <p>Your screenshot looks like an inter...
1
2009-03-03T05:55:00Z
[ "python", "qt", "qt4", "pyqt", "qcombobox" ]
Using PyQT, how do you filter mousePressEvent for a QComboBox with custom list
603,528
<p>I've got a <code>QComboBox</code> with a custom list object. </p> <p><img src="http://i.stack.imgur.com/r71L2.png" alt="Screenshot."></p> <p>The custom list object has a custom <code>mousePressEvent</code> so that when the user click on one of the circles with a +/- (a twisty), the list is expanded/collapsed. </p>...
3
2009-03-02T18:55:19Z
664,455
<p>QT has a <code>eventFilter</code> that "captures" <code>QEvent.MouseButtonRelease</code>. So what I have done is installed my own <code>eventFilter</code> that filters <code>QEvent.MouseButtonRelease</code> events if the user click on a node. </p> <p>In my list object I have the following method:</p> <pre><code>de...
1
2009-03-19T23:32:48Z
[ "python", "qt", "qt4", "pyqt", "qcombobox" ]
What is the proper way to address permissions?
603,595
<p>I added a new model with one permission, and now I need to add that permission to a few users on the production machine after deploying the code and running syncdb for the new app involved. I haven't found the correct way to do this. The auth docs mention User.user_permissions.add(permission), but never tell me what...
3
2009-03-02T19:18:05Z
603,620
<p><code>Permission</code> (which lives in <code>django.contrib.auth.models</code>) is a database object. You'll be able to see all of them with <code>Permission.objects.all()</code>. They are created automatically by a post-sync signal for each model (and <a href="http://docs.djangoproject.com/en/dev/topics/auth/#id1"...
4
2009-03-02T19:25:26Z
[ "python", "django" ]
Using for...else in Python generators
603,641
<p>I'm a big fan of Python's <a href="http://docs.python.org/reference/compound_stmts.html#the-for-statement">for...else syntax</a> - it's surprising how often it's applicable, and how effectively it can simplify code.</p> <p>However, I've not figured out a nice way to use it in a generator, for example:</p> <pre><co...
7
2009-03-02T19:28:09Z
603,651
<p>You're breaking the definition of a generator, which should throw a StopIteration exception when iteration is complete (which is automatically handled by a return statement in a generator function)</p> <p>So:</p> <pre><code>def iterate(i): for value in i: yield value return </code></pre> <p>Best t...
11
2009-03-02T19:32:18Z
[ "python", "syntax", "for-loop", "generator", "yield" ]
Using for...else in Python generators
603,641
<p>I'm a big fan of Python's <a href="http://docs.python.org/reference/compound_stmts.html#the-for-statement">for...else syntax</a> - it's surprising how often it's applicable, and how effectively it can simplify code.</p> <p>However, I've not figured out a nice way to use it in a generator, for example:</p> <pre><co...
7
2009-03-02T19:28:09Z
603,666
<p>What about simple if-else?</p> <pre><code>def iterate(i): if len(i) == 0: print 'i is empty' else: for value in i: yield value </code></pre>
-2
2009-03-02T19:36:27Z
[ "python", "syntax", "for-loop", "generator", "yield" ]
Using for...else in Python generators
603,641
<p>I'm a big fan of Python's <a href="http://docs.python.org/reference/compound_stmts.html#the-for-statement">for...else syntax</a> - it's surprising how often it's applicable, and how effectively it can simplify code.</p> <p>However, I've not figured out a nice way to use it in a generator, for example:</p> <pre><co...
7
2009-03-02T19:28:09Z
603,691
<p>There are a couple ways of doing this. You could always use the <code>Iterator</code> directly:</p> <pre><code>def iterate(i): try: i_iter = iter(i) next = i_iter.next() except StopIteration: print 'i is empty' return while True: yield next next = i_iter...
5
2009-03-02T19:44:40Z
[ "python", "syntax", "for-loop", "generator", "yield" ]