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
Is it a bad idea to design and develop a python applications backend and then once finished try to apply a GUI to it?
1,967,888
<p>Is it better to do it all at once? I'm very new to wxPython and I'm thinking it would be better to write the program in a way familiar to me, then apply the wxPython gui to it after I'm satisfied with the overall design of the app. Any advice?</p>
12
2009-12-28T03:53:30Z
1,967,968
<p>What level of interactivity do you need? If you need rich feedback and interaction, then you need an OO program model, then you can ad the GUI on top of the objects.</p> <p>If you just have filters and functions (no real feedback, or just a results window) than a library or component model would be better.</p> <p>...
-1
2009-12-28T04:31:16Z
[ "python", "wxpython" ]
Is it a bad idea to design and develop a python applications backend and then once finished try to apply a GUI to it?
1,967,888
<p>Is it better to do it all at once? I'm very new to wxPython and I'm thinking it would be better to write the program in a way familiar to me, then apply the wxPython gui to it after I'm satisfied with the overall design of the app. Any advice?</p>
12
2009-12-28T03:53:30Z
1,967,976
<p>If you're used to a more command line approach, this would be a bad idea. Responding to user input is a completely different paradigm, and you're not likely to get it right the first time.</p> <p>If you're just talking about the difference between wxPython and another GUI, don't worry about it.</p>
-1
2009-12-28T04:35:20Z
[ "python", "wxpython" ]
Is it a bad idea to design and develop a python applications backend and then once finished try to apply a GUI to it?
1,967,888
<p>Is it better to do it all at once? I'm very new to wxPython and I'm thinking it would be better to write the program in a way familiar to me, then apply the wxPython gui to it after I'm satisfied with the overall design of the app. Any advice?</p>
12
2009-12-28T03:53:30Z
1,968,045
<p>Separation of the user interface from the engine code is the unixy way to do it and there's a lot of merit to doing it that way. It results in modular re-usable programs and code that can play nicely with other programs and fit into a larger tool chain.</p> <p>Having said that, such an approach tends to discount th...
1
2009-12-28T05:03:21Z
[ "python", "wxpython" ]
Is it a bad idea to design and develop a python applications backend and then once finished try to apply a GUI to it?
1,967,888
<p>Is it better to do it all at once? I'm very new to wxPython and I'm thinking it would be better to write the program in a way familiar to me, then apply the wxPython gui to it after I'm satisfied with the overall design of the app. Any advice?</p>
12
2009-12-28T03:53:30Z
1,970,144
<p>Since you are new to GUI programming, your approach is perfectly valid. It will likely result in a less than optimal UI, but that's OK for now. And in fact, there are some very successful multi-million dollar commercial projects that are built this way.</p> <p>Arguably a better approach is to first design the UI si...
0
2009-12-28T16:03:49Z
[ "python", "wxpython" ]
How to parse/extract data from a mediawiki marked-up article via python
1,968,132
<p><a href="http://en.wikipedia.org/w/api.php?action=query&amp;prop=revisions&amp;titles=Foobar&amp;redirects&amp;rvprop=content&amp;format=xml">Source Mediawiki markup</a></p> <p>Right now I'm using a variety of regexes to "parse" the data in the mediawiki mark-up into lists/dictionaries, so that elements within the ...
10
2009-12-28T05:44:48Z
1,968,139
<h2>mwlib - MediaWiki parser and utility library</h2> <p><a href="https://github.com/pediapress/mwlib" rel="nofollow">pediapress/mwlib</a>:</p> <blockquote> <p>mwlib provides a library for parsing MediaWiki articles and converting them to different output formats. mwlib is used by wikipedia's "Print/export" feature...
8
2009-12-28T05:47:56Z
[ "python", "api", "parsing", "mediawiki", "extraction" ]
How to parse/extract data from a mediawiki marked-up article via python
1,968,132
<p><a href="http://en.wikipedia.org/w/api.php?action=query&amp;prop=revisions&amp;titles=Foobar&amp;redirects&amp;rvprop=content&amp;format=xml">Source Mediawiki markup</a></p> <p>Right now I'm using a variety of regexes to "parse" the data in the mediawiki mark-up into lists/dictionaries, so that elements within the ...
10
2009-12-28T05:44:48Z
10,144,875
<p>This question is old, but for others coming here: There is a <a href="https://github.com/erikrose/mediawiki-parser" rel="nofollow">mediawiki parser written in Python on github</a>. It seems very easy to transform articles into pure plain text, something I, if I remember correctly, couldn't solve in the past with mwl...
4
2012-04-13T16:40:38Z
[ "python", "api", "parsing", "mediawiki", "extraction" ]
How to parse/extract data from a mediawiki marked-up article via python
1,968,132
<p><a href="http://en.wikipedia.org/w/api.php?action=query&amp;prop=revisions&amp;titles=Foobar&amp;redirects&amp;rvprop=content&amp;format=xml">Source Mediawiki markup</a></p> <p>Right now I'm using a variety of regexes to "parse" the data in the mediawiki mark-up into lists/dictionaries, so that elements within the ...
10
2009-12-28T05:44:48Z
28,219,964
<p><a href="https://dizzylogic.com/wikiparser" rel="nofollow">Wiki Parser</a> parses Wikipedia dumps into XML that preserves all content and article structure. Use that, and then process the resulting XML with your python program.</p>
0
2015-01-29T16:41:24Z
[ "python", "api", "parsing", "mediawiki", "extraction" ]
How to parse/extract data from a mediawiki marked-up article via python
1,968,132
<p><a href="http://en.wikipedia.org/w/api.php?action=query&amp;prop=revisions&amp;titles=Foobar&amp;redirects&amp;rvprop=content&amp;format=xml">Source Mediawiki markup</a></p> <p>Right now I'm using a variety of regexes to "parse" the data in the mediawiki mark-up into lists/dictionaries, so that elements within the ...
10
2009-12-28T05:44:48Z
30,521,529
<p>I was searching for simillar solution to parse certain wiki , and stumbled upon <a href="http://pandoc.org/" rel="nofollow">Pandoc</a> which takes multiple input formats and generates multiple too.</p> <p>From the site:</p> <blockquote> <p>Pandoc - a universal document converter</p> <p>If you need to conver...
4
2015-05-29T05:08:15Z
[ "python", "api", "parsing", "mediawiki", "extraction" ]
i don't know why django do this,it is about os.stat
1,968,272
<p>What is the benefits of doing so:</p> <pre><code>import os ST_MODE = 0 ST_INO = 1 ST_DEV = 2 ST_NLINK = 3 ST_UID = 4 ST_GID = 5 ST_SIZE = 6 ST_ATIME = 7 ST_MTIME = 8 ST_CTIME = 9 # Extract bits from the mode def S_IMODE(mode): return mode &amp; 07777 def S_IFMT(mode): return mode &amp; 0170000 ...
0
2009-12-28T06:44:52Z
1,968,285
<p>The benefits? I imagine one of them (a 'negative' one) is to stop the code from trying to process directories as regular files. If you run code such as:</p> <pre><code>myprog * </code></pre> <p>the shell will change that <code>*</code> into a list of all files within the current directory (including subdirectories...
2
2009-12-28T06:52:48Z
[ "python" ]
How can I tell if a field has changed value in an AT object in plone?
1,968,343
<p>I have an AT content type in Plone. It has a number of fields, including a file field. When the user edits an object of this type, how can I tell if a new file was uploaded? </p> <p>For that matter, how can I tell if any of the fields have been changed?</p> <p>I am currently using subscribers to hook into the IObj...
2
2009-12-28T07:16:13Z
1,977,227
<p>Yes, <code>IObjectEditedEvent</code> (a direct subclass of <code>IObjectModifiedEvent</code>) is emitted when an Archetypes content object is being changed.</p> <p>However, the event itself will not tell you if a new file was uploaded. It should be possible however, to obtain the request (context.REQUEST should giv...
1
2009-12-29T22:05:51Z
[ "python", "plone", "zope", "archetypes" ]
How can I tell if a field has changed value in an AT object in plone?
1,968,343
<p>I have an AT content type in Plone. It has a number of fields, including a file field. When the user edits an object of this type, how can I tell if a new file was uploaded? </p> <p>For that matter, how can I tell if any of the fields have been changed?</p> <p>I am currently using subscribers to hook into the IObj...
2
2009-12-28T07:16:13Z
18,729,659
<p>Here is what I tied to the IObjectEditedEvent:</p> <p>Using the default form created from subclassing ATBlob, implementing (IATBlobFile, IATFile, IFileContent)</p> <pre><code>def editObjectEvent(context, event): status = context.REQUEST.form.get('file_delete') if status in ("nochange", NONE): prin...
0
2013-09-10T22:15:43Z
[ "python", "plone", "zope", "archetypes" ]
How to detect flash drive plug-in in Windows using Python?
1,968,539
<p>I want to make my Windows computer run a Python script when it detects that a flash drive which has a particular name (for example "My drive") has been plugged in.</p> <p>How can I achieve this? </p> <p>Should I use some tool in Windows or is there a way to write another Python script to detect the presence of a f...
5
2009-12-28T08:26:50Z
1,968,733
<p>Well, if you're on a Linux distribution, then <a href="http://stackoverflow.com/questions/469243/">this question</a> on SO would have the answer.</p> <p>I can think of a round-about (not elegant) solution for your problem, but at the very least it would WORK.</p> <p>Every time you insert your flash drive into a US...
2
2009-12-28T09:50:42Z
[ "python", "windows", "usb-drive" ]
How to detect flash drive plug-in in Windows using Python?
1,968,539
<p>I want to make my Windows computer run a Python script when it detects that a flash drive which has a particular name (for example "My drive") has been plugged in.</p> <p>How can I achieve this? </p> <p>Should I use some tool in Windows or is there a way to write another Python script to detect the presence of a f...
5
2009-12-28T08:26:50Z
1,969,531
<p>Though you can use a similar method as 'inpectorG4dget' suggested but that will be a lot inefficient.</p> <p>You need to use Win API for this. This page might be of use to you: <a href="http://msdn.microsoft.com/en-us/library/aa364975%28VS.85%29.aspx">Link</a></p> <p>And to use Win API's in python check this link ...
4
2009-12-28T13:43:48Z
[ "python", "windows", "usb-drive" ]
How to detect flash drive plug-in in Windows using Python?
1,968,539
<p>I want to make my Windows computer run a Python script when it detects that a flash drive which has a particular name (for example "My drive") has been plugged in.</p> <p>How can I achieve this? </p> <p>Should I use some tool in Windows or is there a way to write another Python script to detect the presence of a f...
5
2009-12-28T08:26:50Z
9,578,439
<p>Building on the "CD" approach, what if your script enumerated the list of drives, waited a few seconds for Windows to assign the drive letter, then re-enumerated the list? A python set could tell you what changed, no? The following worked for me:</p> <pre><code># building on above and http://stackoverflow.com/quest...
3
2012-03-06T05:36:43Z
[ "python", "windows", "usb-drive" ]
PyWin32: Windows Classic theme
1,969,041
<p>In the PyWin32 demos folder, the <strong>win32gui_dialog.py</strong> sample uses the <em>classic windows</em> controls. Can the <strong>Windows Vista</strong> themed buttons also be displayed using PyWin32, and if so, how? I'm using ActivePython 3.1, if that makes any difference.</p> <p>Sample:</p> <p><img src="h...
1
2009-12-28T11:28:01Z
1,969,050
<p>Short answer: a resounding YES.</p> <p>I know that this is possible because I have seen it being done before. but I am not entirely certain as to how it is done.</p> <p>At the very least, you can use <a href="http://ironpython.net/" rel="nofollow">IronPython</a> and use Windows' builtin .NET framework by wielding ...
2
2009-12-28T11:32:14Z
[ "python", "windows", "windows-vista", "python-3.x", "pywin32" ]
PyWin32: Windows Classic theme
1,969,041
<p>In the PyWin32 demos folder, the <strong>win32gui_dialog.py</strong> sample uses the <em>classic windows</em> controls. Can the <strong>Windows Vista</strong> themed buttons also be displayed using PyWin32, and if so, how? I'm using ActivePython 3.1, if that makes any difference.</p> <p>Sample:</p> <p><img src="h...
1
2009-12-28T11:28:01Z
1,969,231
<p>You'll need to add a side-by-side manifest specifying a correct version of ComCtl32.dll to the Python interpreter. Fortunately there is no need to change the interpreter executable itself.</p> <ul> <li>Create a file named <code>python.exe.manifest</code> in the directory containing <code>python.exe</code>.</li> <li...
2
2009-12-28T12:21:37Z
[ "python", "windows", "windows-vista", "python-3.x", "pywin32" ]
PyWin32: Windows Classic theme
1,969,041
<p>In the PyWin32 demos folder, the <strong>win32gui_dialog.py</strong> sample uses the <em>classic windows</em> controls. Can the <strong>Windows Vista</strong> themed buttons also be displayed using PyWin32, and if so, how? I'm using ActivePython 3.1, if that makes any difference.</p> <p>Sample:</p> <p><img src="h...
1
2009-12-28T11:28:01Z
1,994,329
<p>Have you tried using '<code>winxpgui</code>' module instead of '<code>win32gui</code>' module? </p> <p>I'm not sure if there's a '<code>winvistagui</code>' or '<code>win7gui</code>' module, but '<code>winxpgui</code>' does exist and may work, as it has a manifest included.</p>
0
2010-01-03T08:29:17Z
[ "python", "windows", "windows-vista", "python-3.x", "pywin32" ]
Cant get __import__() to dynamically import a module in python - I know this cause it doesn't show up in sys.modules
1,969,097
<p>Wrote a small script - just trying to get used to the os, sys, and some other common modules/libraries available to python at install. The gist: The script is designed to search the python directory for all available modules (whether they are installed or not), then it is suppose to check what modules are currentl...
1
2009-12-28T11:43:38Z
1,969,318
<p>Nascent_Notes, nice script! I tried loading <code>uu</code> (command 3) and printing the list of loaded modules (command 2) and they both seem to work fine. </p> <p>However, if I try to "browse the module" (command 4), I get the following error:</p> <pre><code>HlpWiz&gt;&gt;&gt; 4 What module do you want to look ...
1
2009-12-28T12:48:13Z
[ "python", "import", "operating-system", "sys" ]
My path to learn Python/Django
1,969,159
<p>I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess.</p> <p>In order to improve my skills I began reading and coding the projects of Django Practical P...
14
2009-12-28T12:00:29Z
1,969,175
<p>I think that you've read a lot of very interesting stuff and now it's time to start your own path. Feel free to ask on SO when you have a question</p>
2
2009-12-28T12:04:03Z
[ "python", "django" ]
My path to learn Python/Django
1,969,159
<p>I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess.</p> <p>In order to improve my skills I began reading and coding the projects of Django Practical P...
14
2009-12-28T12:00:29Z
1,969,182
<p>From your position, the best way to learn would be trying to make something that you've always wanted to make, but didn't make it before.</p> <p>I wouldn't worry much about learning CSS/Javascript. You can learn those as need-to-know basis while working on your project. Modern javascript frameworks like jQuery make...
7
2009-12-28T12:06:02Z
[ "python", "django" ]
My path to learn Python/Django
1,969,159
<p>I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess.</p> <p>In order to improve my skills I began reading and coding the projects of Django Practical P...
14
2009-12-28T12:00:29Z
1,969,192
<p>Dive Into Python is a great start for learning python, although you can get pretty far in django without knowing much python.</p> <p>After you've read <a href="http://djangobook.com/" rel="nofollow">http://djangobook.com/</a> and went through the original tutorial there isn't more left for you to do outside of work...
1
2009-12-28T12:08:20Z
[ "python", "django" ]
My path to learn Python/Django
1,969,159
<p>I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess.</p> <p>In order to improve my skills I began reading and coding the projects of Django Practical P...
14
2009-12-28T12:00:29Z
1,969,193
<p>Make a project for yourself, try something that is not in the book. This will give you some real life experience, let you make yours the concepts you've learned, stumble on real-life problems. Books are good to begin with, but you've got to jump in at some point.</p> <p>You could also play with tools that use Pytho...
7
2009-12-28T12:08:49Z
[ "python", "django" ]
My path to learn Python/Django
1,969,159
<p>I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess.</p> <p>In order to improve my skills I began reading and coding the projects of Django Practical P...
14
2009-12-28T12:00:29Z
1,969,363
<p>The best kind of learning is learning by doing. Try to start your project. If possible, choose a small part to deploy first just to keep you motivated. If you get stuck somewhere:</p> <ol> <li>Search Google</li> <li>Go back to the reference sites that you have already found</li> <li>Ask SO :-)</li> </ol>
8
2009-12-28T13:01:21Z
[ "python", "django" ]
My path to learn Python/Django
1,969,159
<p>I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess.</p> <p>In order to improve my skills I began reading and coding the projects of Django Practical P...
14
2009-12-28T12:00:29Z
1,969,540
<p><strong>"Perhaps it would be better to start my own project right away, and learn by practice"</strong></p> <p>This is what you are already doing. It's what you <em>are</em> doing right now.</p> <p><strong>"It worked fine but the code was a total mess."</strong></p> <p>This is the results of doing what you are a...
6
2009-12-28T13:46:31Z
[ "python", "django" ]
My path to learn Python/Django
1,969,159
<p>I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess.</p> <p>In order to improve my skills I began reading and coding the projects of Django Practical P...
14
2009-12-28T12:00:29Z
1,969,677
<p>Learning by practice is essential. You won’t know how to write an application until you’ve written a few badly.</p> <p>But learning by reading is also essential. Once you’ve made the mistakes, knowledge from others will show you ways to avoid those mistakes.</p> <p>If you’re writing Django apps, you need t...
6
2009-12-28T14:20:41Z
[ "python", "django" ]
My path to learn Python/Django
1,969,159
<p>I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess.</p> <p>In order to improve my skills I began reading and coding the projects of Django Practical P...
14
2009-12-28T12:00:29Z
1,969,951
<p>There are a few ways to be able to write clean code:</p> <ol> <li><p><strong>Ask</strong></p> <p>If you have a piece of code that you think could or should be written better, don't be afraid to ask for help. Put your sample of code up on a website (like stackoverflow) and ask "Can this be done better?" This has he...
2
2009-12-28T15:20:54Z
[ "python", "django" ]
My path to learn Python/Django
1,969,159
<p>I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess.</p> <p>In order to improve my skills I began reading and coding the projects of Django Practical P...
14
2009-12-28T12:00:29Z
1,973,145
<p>Have a look at one of the library modules (python's difflib.py is nice, I don't know any good django modules but the sessions module looks promising) and try to figure out how they tick.</p> <p>Look at the tests (and write a couple of additional tests yourself), draw up the architecture, see how the sessions module...
1
2009-12-29T06:04:32Z
[ "python", "django" ]
My path to learn Python/Django
1,969,159
<p>I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess.</p> <p>In order to improve my skills I began reading and coding the projects of Django Practical P...
14
2009-12-28T12:00:29Z
1,974,335
<p>For your question, How to learn to program, the Truth, I have found is as follows,</p> <p>Use git, branch, try new stuff, don't worry about screwing up. In fact, screw it up. Get stuff to work. Understand that you code is bad, read up on how to do that better, browse through github to find patterns to do that. For ...
3
2009-12-29T12:12:16Z
[ "python", "django" ]
My path to learn Python/Django
1,969,159
<p>I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess.</p> <p>In order to improve my skills I began reading and coding the projects of Django Practical P...
14
2009-12-28T12:00:29Z
4,333,135
<p>No one has mentioned the <a href="http://docs.python.org/tutorial/" rel="nofollow">Python Tutorial by Guido</a>. It's a pretty good overview of the language features (but maybe too complex for those new to programming). I would suggest that it is a mandatory read for those working with Python.</p>
0
2010-12-02T08:43:53Z
[ "python", "django" ]
My path to learn Python/Django
1,969,159
<p>I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess.</p> <p>In order to improve my skills I began reading and coding the projects of Django Practical P...
14
2009-12-28T12:00:29Z
4,767,746
<p>I think that the most important thing to hold to during a learning process is "to stick to the plan" what ever happens. Choose simple introductory materials to Python, then to Django and stick to them until you finish them. Start right after that with your project. You'll learn a lot by applying your basic knowledge...
-1
2011-01-22T12:15:17Z
[ "python", "django" ]
My path to learn Python/Django
1,969,159
<p>I began learning Python with Dive into Python(I read some chapters), then I switched to Django using The Django Book and the Django Documentation. I made a simple web app, It worked fine but the code was a total mess.</p> <p>In order to improve my skills I began reading and coding the projects of Django Practical P...
14
2009-12-28T12:00:29Z
4,767,903
<p>Django for e-commerce is not very useful for e-commerce, learning how to use Satchmo will be more rewardful i think. It contains good programmation patterns, but, again, you will better understand them if you go through errors yourself trying to do it...</p>
-1
2011-01-22T12:54:19Z
[ "python", "django" ]
Mapping a range of values to another
1,969,240
<p>I am looking for ideas on how to translate one range values to another in Python. I am working on hardware project and am reading data from a sensor that can return a range of values, I am then using that data to drive an actuator that requires a different range of values.</p> <p>For example lets say that the senso...
25
2009-12-28T12:24:01Z
1,969,274
<p>One solution would be:</p> <pre><code>def translate(value, leftMin, leftMax, rightMin, rightMax): # Figure out how 'wide' each range is leftSpan = leftMax - leftMin rightSpan = rightMax - rightMin # Convert the left range into a 0-1 range (float) valueScaled = float(value - leftMin) / float(lef...
49
2009-12-28T12:33:45Z
[ "python", "algorithm" ]
Mapping a range of values to another
1,969,240
<p>I am looking for ideas on how to translate one range values to another in Python. I am working on hardware project and am reading data from a sensor that can return a range of values, I am then using that data to drive an actuator that requires a different range of values.</p> <p>For example lets say that the senso...
25
2009-12-28T12:24:01Z
1,969,295
<pre><code>def translate(sensor_val, in_from, in_to, out_from, out_to): out_range = out_to - out_from in_range = in_to - in_from in_val = sensor_val - in_from val=(float(in_val)/in_range)*out_range out_val = out_from+val return out_val </code></pre>
4
2009-12-28T12:39:59Z
[ "python", "algorithm" ]
Mapping a range of values to another
1,969,240
<p>I am looking for ideas on how to translate one range values to another in Python. I am working on hardware project and am reading data from a sensor that can return a range of values, I am then using that data to drive an actuator that requires a different range of values.</p> <p>For example lets say that the senso...
25
2009-12-28T12:24:01Z
1,969,296
<h3>Using scipy.interpolate.interp1d</h3> <p>You can also use <code>scipy.interpolate</code> package to do such conversions (if you don't mind dependency on SciPy):</p> <pre><code>&gt;&gt;&gt; from scipy.interpolate import interp1d &gt;&gt;&gt; m = interp1d([1,512],[5,10]) &gt;&gt;&gt; m(256) array(7.4951076320939336...
31
2009-12-28T12:40:10Z
[ "python", "algorithm" ]
Mapping a range of values to another
1,969,240
<p>I am looking for ideas on how to translate one range values to another in Python. I am working on hardware project and am reading data from a sensor that can return a range of values, I am then using that data to drive an actuator that requires a different range of values.</p> <p>For example lets say that the senso...
25
2009-12-28T12:24:01Z
1,970,037
<p>This would actually be a good case for creating a closure, that is write a function that returns a function. Since you probably have many of these values, there is little value in calculating and recalculating these value spans and factors for every value, nor for that matter, in passing those min/max limits around...
10
2009-12-28T15:40:24Z
[ "python", "algorithm" ]
Pygame in Windows: ImportError: DLL load failed
1,969,426
<p>I just installed PyGame 1.9.1 (onto an existing python 2.6.4). Python and it standard libraries work, however, there is a problem with python even being able to find the pygame modules (correctly).</p> <pre><code>Traceback (most recent call last): File "C:\foo\bar\firstGame.py", line 2, in &lt;module&gt; impo...
6
2009-12-28T13:17:38Z
1,969,718
<p>Are you sure you have got pygame for Python 2.6? The version for 2.5 wont work and produce this error msg, because the pyd file wont find the python 2.5 dll.</p>
4
2009-12-28T14:32:47Z
[ "python", "windows", "dll", "import", "pygame" ]
Pygame in Windows: ImportError: DLL load failed
1,969,426
<p>I just installed PyGame 1.9.1 (onto an existing python 2.6.4). Python and it standard libraries work, however, there is a problem with python even being able to find the pygame modules (correctly).</p> <pre><code>Traceback (most recent call last): File "C:\foo\bar\firstGame.py", line 2, in &lt;module&gt; impo...
6
2009-12-28T13:17:38Z
1,970,440
<p>To check exactly which DLL's are missing use the CMD like python console. It will show a pop-up message indicating the missing DLL. Pygame works for me.</p>
0
2009-12-28T17:05:16Z
[ "python", "windows", "dll", "import", "pygame" ]
Pygame in Windows: ImportError: DLL load failed
1,969,426
<p>I just installed PyGame 1.9.1 (onto an existing python 2.6.4). Python and it standard libraries work, however, there is a problem with python even being able to find the pygame modules (correctly).</p> <pre><code>Traceback (most recent call last): File "C:\foo\bar\firstGame.py", line 2, in &lt;module&gt; impo...
6
2009-12-28T13:17:38Z
4,176,094
<p>This actually happened to my installation as well. I have Python 2.6.6 installed, but the installation did not include Pygame. I downloaded Pygame 1.9.1 with Python 2.6, and identified where the directory was located, the installation seemed to work. However, from the IDLE, I entered import pygame, and received the ...
1
2010-11-14T03:38:14Z
[ "python", "windows", "dll", "import", "pygame" ]
Pygame in Windows: ImportError: DLL load failed
1,969,426
<p>I just installed PyGame 1.9.1 (onto an existing python 2.6.4). Python and it standard libraries work, however, there is a problem with python even being able to find the pygame modules (correctly).</p> <pre><code>Traceback (most recent call last): File "C:\foo\bar\firstGame.py", line 2, in &lt;module&gt; impo...
6
2009-12-28T13:17:38Z
9,712,802
<p>If you are running a 64 bit version of windows, with a 64 bit python, the default installers on the Pygame site don't seem to work.</p> <p>The pygame website led me there: There are some pre release binaries for 64bit windows, and for python 2.7 at <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame" rel="no...
0
2012-03-15T01:28:20Z
[ "python", "windows", "dll", "import", "pygame" ]
Pygame in Windows: ImportError: DLL load failed
1,969,426
<p>I just installed PyGame 1.9.1 (onto an existing python 2.6.4). Python and it standard libraries work, however, there is a problem with python even being able to find the pygame modules (correctly).</p> <pre><code>Traceback (most recent call last): File "C:\foo\bar\firstGame.py", line 2, in &lt;module&gt; impo...
6
2009-12-28T13:17:38Z
17,688,452
<p>I had the exact same error however i ran a small program i found the used pygame without the IDLE(by saving the code and then just double clicking on the .py file) and it worked 100% fine.</p>
0
2013-07-16T23:08:01Z
[ "python", "windows", "dll", "import", "pygame" ]
Pygame in Windows: ImportError: DLL load failed
1,969,426
<p>I just installed PyGame 1.9.1 (onto an existing python 2.6.4). Python and it standard libraries work, however, there is a problem with python even being able to find the pygame modules (correctly).</p> <pre><code>Traceback (most recent call last): File "C:\foo\bar\firstGame.py", line 2, in &lt;module&gt; impo...
6
2009-12-28T13:17:38Z
24,917,891
<p>I have faced this error on a Windows 64 bit. I have uninstalled my python 3.4.1 and I have installed: python-3.4.1.amd64.msi then pygame-1.9.2a0.win-amd64-py3.4.exe from link mentioned above. And it worked.</p>
3
2014-07-23T18:13:37Z
[ "python", "windows", "dll", "import", "pygame" ]
Pygame in Windows: ImportError: DLL load failed
1,969,426
<p>I just installed PyGame 1.9.1 (onto an existing python 2.6.4). Python and it standard libraries work, however, there is a problem with python even being able to find the pygame modules (correctly).</p> <pre><code>Traceback (most recent call last): File "C:\foo\bar\firstGame.py", line 2, in &lt;module&gt; impo...
6
2009-12-28T13:17:38Z
24,950,519
<p>I had this error and after much digging discovered that the version of python interpreter MUST match the version of pygame installed.</p> <p>If you have an erroneous combination, your best bet is to uninstall what you have via Start -> Control Panel -> Uninstall Programs.</p> <p>A combination that works (Install i...
0
2014-07-25T07:42:23Z
[ "python", "windows", "dll", "import", "pygame" ]
Shortest way to find if a string matchs an object's attribute value in a list of objects of that type in Python
1,969,490
<p>I have a list with objects of x type. Those objects have an attribute name. I want to find if a string matchs any of those object names. If I would have a list with the object names I just would do <code>if string in list</code>, so I was wondering given the current situation if there is a way to do it without hav...
1
2009-12-28T13:33:53Z
1,969,504
<p>if string in [x.name for x in list_of_x]</p>
1
2009-12-28T13:37:50Z
[ "algorithm", "python" ]
Shortest way to find if a string matchs an object's attribute value in a list of objects of that type in Python
1,969,490
<p>I have a list with objects of x type. Those objects have an attribute name. I want to find if a string matchs any of those object names. If I would have a list with the object names I just would do <code>if string in list</code>, so I was wondering given the current situation if there is a way to do it without hav...
1
2009-12-28T13:33:53Z
1,969,510
<pre><code>any(obj for obj in objs if obj.name==name) </code></pre> <p>Note, that it will stop looping after first match found.</p>
5
2009-12-28T13:40:01Z
[ "algorithm", "python" ]
Shortest way to find if a string matchs an object's attribute value in a list of objects of that type in Python
1,969,490
<p>I have a list with objects of x type. Those objects have an attribute name. I want to find if a string matchs any of those object names. If I would have a list with the object names I just would do <code>if string in list</code>, so I was wondering given the current situation if there is a way to do it without hav...
1
2009-12-28T13:33:53Z
1,969,526
<p>Here's another</p> <pre><code>dict( (o.name,o) for o in obj_list )[name] </code></pre> <p>The trick, though, is avoid creating a list <code>obj_list</code> in the first place.</p> <p>Since you know that you're going to fetch objects by the string value of an attribute, do not use a list, use a dictionary instead ...
4
2009-12-28T13:43:04Z
[ "algorithm", "python" ]
Shortest way to find if a string matchs an object's attribute value in a list of objects of that type in Python
1,969,490
<p>I have a list with objects of x type. Those objects have an attribute name. I want to find if a string matchs any of those object names. If I would have a list with the object names I just would do <code>if string in list</code>, so I was wondering given the current situation if there is a way to do it without hav...
1
2009-12-28T13:33:53Z
1,969,533
<p>What do you want to do if the string matches? Do you just want to return True/False, or return a list of objects that match? To return a boolean:</p> <pre><code>any(obj.name == name for obj in objs) </code></pre> <p>(I find this slightly more readable than Denis Otkidach's version).</p> <p>to filter the list:</p...
4
2009-12-28T13:45:13Z
[ "algorithm", "python" ]
Shortest way to find if a string matchs an object's attribute value in a list of objects of that type in Python
1,969,490
<p>I have a list with objects of x type. Those objects have an attribute name. I want to find if a string matchs any of those object names. If I would have a list with the object names I just would do <code>if string in list</code>, so I was wondering given the current situation if there is a way to do it without hav...
1
2009-12-28T13:33:53Z
1,969,536
<pre><code>for i in listOfItemsOfTypeX: if i.name == myString: return True return False </code></pre>
0
2009-12-28T13:45:37Z
[ "algorithm", "python" ]
Problem with python-proxy for mp3-streams
1,969,621
<p>I am trying to make a proxy for internet-radio in mp3. It is working fine when accessing mp3-files, but not for mp3-streams.</p> <p>I suppose I am missing some very basic difference but could not find a hint.</p> <p>Best regards, wolf</p> <p>My test code:</p> <pre><code>#!/usr/local/bin/python2.5 import urllib; ...
0
2009-12-28T14:05:24Z
1,969,702
<p>The problem is that you are reading not mp3 stream but <a href="http://en.wikipedia.org/wiki/M3U" rel="nofollow">M3U playlist file</a>. This file doesn't contain any mp3 data itself.</p> <p>The content of your file is simple text:</p> <pre><code>http://zlz-stream10.streamserver.ch/1/drs3/mp3_128 http://glb-stream1...
0
2009-12-28T14:27:41Z
[ "python", "audio", "mp3", "stream" ]
Iteration WAS working in my script, now I cant get python to iterate - what happened?
1,969,937
<p>Did my python ide break or something?</p> <pre><code>import sys i = 0 sample = ("this", "is", "Annoying!") for line in sample: print i, line i + 1 </code></pre> <p>Now gives me...</p> <pre> 0 this 0 is 0 Annoying! </pre> <p>I THOUGHT, it would give me:</p> <pre> 1 this 2 is 3 Annoying </pre> <p>I...
0
2009-12-28T15:18:04Z
1,969,949
<p>You're not incrementing the variable <code>i</code> in your code, you'd need to do something like:</p> <pre><code>for line in sample: i = i + 1 print i, line </code></pre>
2
2009-12-28T15:20:39Z
[ "python" ]
Iteration WAS working in my script, now I cant get python to iterate - what happened?
1,969,937
<p>Did my python ide break or something?</p> <pre><code>import sys i = 0 sample = ("this", "is", "Annoying!") for line in sample: print i, line i + 1 </code></pre> <p>Now gives me...</p> <pre> 0 this 0 is 0 Annoying! </pre> <p>I THOUGHT, it would give me:</p> <pre> 1 this 2 is 3 Annoying </pre> <p>I...
0
2009-12-28T15:18:04Z
1,969,960
<p>The problem is you're doing "i + 1", not "i=i+1"</p>
3
2009-12-28T15:22:38Z
[ "python" ]
Iteration WAS working in my script, now I cant get python to iterate - what happened?
1,969,937
<p>Did my python ide break or something?</p> <pre><code>import sys i = 0 sample = ("this", "is", "Annoying!") for line in sample: print i, line i + 1 </code></pre> <p>Now gives me...</p> <pre> 0 this 0 is 0 Annoying! </pre> <p>I THOUGHT, it would give me:</p> <pre> 1 this 2 is 3 Annoying </pre> <p>I...
0
2009-12-28T15:18:04Z
1,969,964
<p>You are calculating <code>i+1</code> but are not storing the result of that anywhere. Specifically you are not updating <code>i</code> to contain the new value. Use <code>i = i + 1</code> or <code>i += 1</code> instead.</p>
7
2009-12-28T15:23:06Z
[ "python" ]
Iteration WAS working in my script, now I cant get python to iterate - what happened?
1,969,937
<p>Did my python ide break or something?</p> <pre><code>import sys i = 0 sample = ("this", "is", "Annoying!") for line in sample: print i, line i + 1 </code></pre> <p>Now gives me...</p> <pre> 0 this 0 is 0 Annoying! </pre> <p>I THOUGHT, it would give me:</p> <pre> 1 this 2 is 3 Annoying </pre> <p>I...
0
2009-12-28T15:18:04Z
1,969,965
<p>This works just fine for me:</p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; i = 0 &gt;&gt;&gt; sample = ("abc", "def", "ghi") &gt;&gt;&gt; for line in sample: ... i = i + 1 ... print i, line ... 1 abc 2 def 3 ghi </code></pre> <p>Are you sure you're incrementing and storing the value <code>i</code>? (You...
4
2009-12-28T15:23:35Z
[ "python" ]
Iteration WAS working in my script, now I cant get python to iterate - what happened?
1,969,937
<p>Did my python ide break or something?</p> <pre><code>import sys i = 0 sample = ("this", "is", "Annoying!") for line in sample: print i, line i + 1 </code></pre> <p>Now gives me...</p> <pre> 0 this 0 is 0 Annoying! </pre> <p>I THOUGHT, it would give me:</p> <pre> 1 this 2 is 3 Annoying </pre> <p>I...
0
2009-12-28T15:18:04Z
1,969,970
<p>While the other answers are correct, this is how you usually do this in python:</p> <pre><code>sample = ("this", "is", "Annoying!") for i, line in enumerate(sample): print i, line </code></pre> <p>The <code>enumerate</code> function does exactly what you want: Iterating through your tuple, while at the same t...
10
2009-12-28T15:24:15Z
[ "python" ]
Iteration WAS working in my script, now I cant get python to iterate - what happened?
1,969,937
<p>Did my python ide break or something?</p> <pre><code>import sys i = 0 sample = ("this", "is", "Annoying!") for line in sample: print i, line i + 1 </code></pre> <p>Now gives me...</p> <pre> 0 this 0 is 0 Annoying! </pre> <p>I THOUGHT, it would give me:</p> <pre> 1 this 2 is 3 Annoying </pre> <p>I...
0
2009-12-28T15:18:04Z
1,969,971
<p>The result that you expect would be obtained by using enumerate:</p> <pre><code>sample = ("this", "is", "Annoying!") for index, line in enumerate(sample): print index, line </code></pre> <p>I don't see how the code that you posted ever would have worked in any version of Python.</p>
2
2009-12-28T15:24:43Z
[ "python" ]
Iteration WAS working in my script, now I cant get python to iterate - what happened?
1,969,937
<p>Did my python ide break or something?</p> <pre><code>import sys i = 0 sample = ("this", "is", "Annoying!") for line in sample: print i, line i + 1 </code></pre> <p>Now gives me...</p> <pre> 0 this 0 is 0 Annoying! </pre> <p>I THOUGHT, it would give me:</p> <pre> 1 this 2 is 3 Annoying </pre> <p>I...
0
2009-12-28T15:18:04Z
1,969,972
<p>I suspect you have an indentation problem, that perhaps the i = i + 1 statement is somehow not part of the for-loop. </p> <p>But Instead of doing your own counter incrementing, better practice is to use enumerate:</p> <pre><code>for i,line in enumerate(sample): print i,line </code></pre>
4
2009-12-28T15:24:49Z
[ "python" ]
Iteration WAS working in my script, now I cant get python to iterate - what happened?
1,969,937
<p>Did my python ide break or something?</p> <pre><code>import sys i = 0 sample = ("this", "is", "Annoying!") for line in sample: print i, line i + 1 </code></pre> <p>Now gives me...</p> <pre> 0 this 0 is 0 Annoying! </pre> <p>I THOUGHT, it would give me:</p> <pre> 1 this 2 is 3 Annoying </pre> <p>I...
0
2009-12-28T15:18:04Z
1,969,974
<p>Just step through debugger to see the execution.</p>
0
2009-12-28T15:25:15Z
[ "python" ]
Python regexp find two keywords in a line
1,970,028
<p>I'm having a hard time understanding this regex stuff...</p> <p>I have a string like this:</p> <pre><code>&lt;wn20schema:NounSynset rdf:about="&amp;dn;synset-56242" rdfs:label="{saddelmageri_1}"&gt; </code></pre> <p>I want to use findall() and groups to get this:</p> <pre><code>['56242','saddelmageri'] </code></...
1
2009-12-28T15:38:12Z
1,970,069
<p>Please see the <strong>top answer</strong> to <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags">this question</a>. It is generally a terrible idea to parse xml with regular expressions. XML parsers are built for this purpose.</p> <p>The quickest way to do ...
2
2009-12-28T15:46:58Z
[ "python", "regex", "findall" ]
Python regexp find two keywords in a line
1,970,028
<p>I'm having a hard time understanding this regex stuff...</p> <p>I have a string like this:</p> <pre><code>&lt;wn20schema:NounSynset rdf:about="&amp;dn;synset-56242" rdfs:label="{saddelmageri_1}"&gt; </code></pre> <p>I want to use findall() and groups to get this:</p> <pre><code>['56242','saddelmageri'] </code></...
1
2009-12-28T15:38:12Z
1,970,077
<p>Since this appears to be xml data, you would be better off using an xml parser, since parsing xml with regular expressions is very, very difficult to do right.</p> <p>However, since you specifically asked for a regular expression...</p> <p>Your specifications are a bit imprecise, and with regular expressions you n...
1
2009-12-28T15:47:40Z
[ "python", "regex", "findall" ]
Python regexp find two keywords in a line
1,970,028
<p>I'm having a hard time understanding this regex stuff...</p> <p>I have a string like this:</p> <pre><code>&lt;wn20schema:NounSynset rdf:about="&amp;dn;synset-56242" rdfs:label="{saddelmageri_1}"&gt; </code></pre> <p>I want to use findall() and groups to get this:</p> <pre><code>['56242','saddelmageri'] </code></...
1
2009-12-28T15:38:12Z
1,970,291
<p>If you do a lot with this data, consider even a specialized RDF library (e.g. RDFLib). If not, an XML parser is definitely the way to go!</p> <ul> <li>What if tomorrow it won't be on a single line?</li> <li>What if tomorrow the <code>label</code> will come before the <code>about</code>?</li> <li>There are at a leas...
1
2009-12-28T16:36:44Z
[ "python", "regex", "findall" ]
Python regexp find two keywords in a line
1,970,028
<p>I'm having a hard time understanding this regex stuff...</p> <p>I have a string like this:</p> <pre><code>&lt;wn20schema:NounSynset rdf:about="&amp;dn;synset-56242" rdfs:label="{saddelmageri_1}"&gt; </code></pre> <p>I want to use findall() and groups to get this:</p> <pre><code>['56242','saddelmageri'] </code></...
1
2009-12-28T15:38:12Z
1,970,397
<p>You're doing two different kinds of parsing here, and you'll need to use two different tools.</p> <p>First, you're parsing XML. For that, you're going to need to use an XML parser, not regular expressions. Because these elements are functionally identical XML:</p> <pre><code>&lt;wn20schema:NounSynset rdf:about="...
1
2009-12-28T16:55:36Z
[ "python", "regex", "findall" ]
Django-registration - some activation
1,970,185
<p>How can I force resending activation e-mail to user? E.g. when he accidentaly deletes the mail, he clicks in link in my website, and django will send him new activation e-mail.</p>
5
2009-12-28T16:12:45Z
1,970,231
<p>There's an <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/">admin action</a> for doing that. From the <a href="http://docs.b-list.org/django-registration/0.8/faq.html#tips-and-tricks">django-registration docs</a>:</p> <blockquote> <p><strong>How do I re-send an activation email?</strong><...
8
2009-12-28T16:22:56Z
[ "python", "django" ]
Django-registration - some activation
1,970,185
<p>How can I force resending activation e-mail to user? E.g. when he accidentaly deletes the mail, he clicks in link in my website, and django will send him new activation e-mail.</p>
5
2009-12-28T16:12:45Z
4,940,881
<p>My (ugly) solution was to create my own login view:</p> <pre><code>from django.contrib.auth.views import login as django_login def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME, redirect_authenticated=None, authentication_form=Authenti...
0
2011-02-09T02:58:45Z
[ "python", "django" ]
Django-registration - some activation
1,970,185
<p>How can I force resending activation e-mail to user? E.g. when he accidentaly deletes the mail, he clicks in link in my website, and django will send him new activation e-mail.</p>
5
2009-12-28T16:12:45Z
5,667,780
<p>The following view function will render a form with single email field, then check if there are any users with this email not activated yet, recreate activation code if expired (hashing stuff was copypasted from RegistrationProfile) and finally send activation email. </p> <pre><code>class ResendActivationEmailFor...
5
2011-04-14T18:23:27Z
[ "python", "django" ]
Django-registration - some activation
1,970,185
<p>How can I force resending activation e-mail to user? E.g. when he accidentaly deletes the mail, he clicks in link in my website, and django will send him new activation e-mail.</p>
5
2009-12-28T16:12:45Z
22,146,250
<p>I updated the ilya b. method resend_activation_email. The old method show error of sha deprecation in python >= 2.5</p> <pre><code>def resend_activation_email(request): if not request.user.is_anonymous(): return HttpResponseRedirect('/') context = Context() form = None if request.method =...
0
2014-03-03T12:01:40Z
[ "python", "django" ]
django's UserCreationForm problem
1,970,218
<p>I have got problem with django's UserCreationForm. It's very strange because ween I:</p> <p>view:</p> <pre><code>from django.contrib.auth.forms import UserCreationForm from django.shortcuts import render_to_response form = UserCreationForm() context = {'form' : form} render_to_response('something.html', context...
-1
2009-12-28T16:21:04Z
1,970,527
<p>You should have missed something in the code.</p> <p>What must had lead you to this error is:</p> <pre><code>form = UserCreationForm {% for field in form1 %}{{ field }}{% endfor %} </code></pre> <p>Here the error is that you missed the parentheses after <code>UserCreationForm</code></p>
2
2009-12-28T17:25:53Z
[ "python", "django", "authentication", "django-forms" ]
django's UserCreationForm problem
1,970,218
<p>I have got problem with django's UserCreationForm. It's very strange because ween I:</p> <p>view:</p> <pre><code>from django.contrib.auth.forms import UserCreationForm from django.shortcuts import render_to_response form = UserCreationForm() context = {'form' : form} render_to_response('something.html', context...
-1
2009-12-28T16:21:04Z
1,970,542
<p>Could you post the code of the view you're actually trying? It seems as if you've written:</p> <pre><code>form = UserCreationForm </code></pre> <p>rather than</p> <pre><code>form = UserCreationForm() </code></pre>
1
2009-12-28T17:28:00Z
[ "python", "django", "authentication", "django-forms" ]
Imported functioning is not iterating "TypeError: 'NoneType' object > is not iterable"... how do I make this work?
1,970,317
<p>This is a snip-it of python I am working on right now - I did not list all of this code, so I apologize if something you need is "missing" - I think I can explain it well enough without the rest of it...</p> <p>Below there is a function <code>main()</code> - this is not explicitly defined in my script - it is impor...
0
2009-12-28T16:41:14Z
1,970,337
<p>The function <code>main</code> <em>prints</em> the lines to standard output; it doesn't return anything. More precisely it returns the <code>None</code> object, so <code>all_mods is None</code>. That's the cause for "'NoneType' object is not iterable", because you're trying to iterate over it with <code>for x in all...
2
2009-12-28T16:44:46Z
[ "python" ]
Imported functioning is not iterating "TypeError: 'NoneType' object > is not iterable"... how do I make this work?
1,970,317
<p>This is a snip-it of python I am working on right now - I did not list all of this code, so I apologize if something you need is "missing" - I think I can explain it well enough without the rest of it...</p> <p>Below there is a function <code>main()</code> - this is not explicitly defined in my script - it is impor...
0
2009-12-28T16:41:14Z
1,970,579
<p>I'd recommend <strong>refactoring <code>list_all_mods()</code>, if at all possible</strong>. In particular, change it to return a list of values, rather than printing them; or turn it into a new function <code>find_all_mods()</code> that returns a list, and redefine <code>list_all_mods()</code>:</p> <pre><code>def...
0
2009-12-28T17:36:48Z
[ "python" ]
Imported functioning is not iterating "TypeError: 'NoneType' object > is not iterable"... how do I make this work?
1,970,317
<p>This is a snip-it of python I am working on right now - I did not list all of this code, so I apologize if something you need is "missing" - I think I can explain it well enough without the rest of it...</p> <p>Below there is a function <code>main()</code> - this is not explicitly defined in my script - it is impor...
0
2009-12-28T16:41:14Z
1,970,593
<p>The <code>nl</code> command does this for you. </p> <pre><code>python the_existing_program.py | nl </code></pre> <p>Should do what you want.</p> <p>If you're working in windows, then you can write a version of <code>nl</code> very easily.</p> <pre><code>import fileinput for n, line in enumerate( fileinput.input...
0
2009-12-28T17:40:41Z
[ "python" ]
How do I sudo the current process?
1,970,329
<p>Is it possible to use a sudo frontend (like gksudo) to elevate the privileges of the <em>current</em> process? I know I can do the following:</p> <pre><code>sudo cat /etc/passwd- </code></pre> <p>But I'm interested in doing this:</p> <pre><code>sudo-become-root # magic function/command cat /etc/passwd- </code></...
8
2009-12-28T16:43:43Z
1,970,373
<p>Your <strong>magic function/command</strong> could be</p> <pre><code>sudo su </code></pre>
0
2009-12-28T16:51:55Z
[ "python", "linux", "root", "gksudo" ]
How do I sudo the current process?
1,970,329
<p>Is it possible to use a sudo frontend (like gksudo) to elevate the privileges of the <em>current</em> process? I know I can do the following:</p> <pre><code>sudo cat /etc/passwd- </code></pre> <p>But I'm interested in doing this:</p> <pre><code>sudo-become-root # magic function/command cat /etc/passwd- </code></...
8
2009-12-28T16:43:43Z
1,970,396
<pre><code>echo 'echo tee; echo hee'|sudo -s </code></pre> <p>The output is:</p> <pre><code>tee hee </code></pre>
0
2009-12-28T16:55:21Z
[ "python", "linux", "root", "gksudo" ]
How do I sudo the current process?
1,970,329
<p>Is it possible to use a sudo frontend (like gksudo) to elevate the privileges of the <em>current</em> process? I know I can do the following:</p> <pre><code>sudo cat /etc/passwd- </code></pre> <p>But I'm interested in doing this:</p> <pre><code>sudo-become-root # magic function/command cat /etc/passwd- </code></...
8
2009-12-28T16:43:43Z
1,970,418
<p>If you want to deal cleanly with administrative rights inside a program, you might want to use <a href="http://en.wikipedia.org/wiki/PolicyKit" rel="nofollow">PolicyKit</a> rather than sudo, depending on the OS you plan to run your program on.</p> <p>For PolicyKit for Python, see <a href="https://fedorahosted.org/p...
2
2009-12-28T17:00:12Z
[ "python", "linux", "root", "gksudo" ]
How do I sudo the current process?
1,970,329
<p>Is it possible to use a sudo frontend (like gksudo) to elevate the privileges of the <em>current</em> process? I know I can do the following:</p> <pre><code>sudo cat /etc/passwd- </code></pre> <p>But I'm interested in doing this:</p> <pre><code>sudo-become-root # magic function/command cat /etc/passwd- </code></...
8
2009-12-28T16:43:43Z
1,970,424
<p>Aptitude has a "become root" option. You may wish to see what the author did there.</p>
2
2009-12-28T17:01:26Z
[ "python", "linux", "root", "gksudo" ]
How do I sudo the current process?
1,970,329
<p>Is it possible to use a sudo frontend (like gksudo) to elevate the privileges of the <em>current</em> process? I know I can do the following:</p> <pre><code>sudo cat /etc/passwd- </code></pre> <p>But I'm interested in doing this:</p> <pre><code>sudo-become-root # magic function/command cat /etc/passwd- </code></...
8
2009-12-28T16:43:43Z
1,970,435
<p>I don't like the idea of being able to run arbitrary commands as root from a lower privileged process. However, since you want it, one of the ideas that comes to mind is to keep a <a href="http://en.wikipedia.org/wiki/Setuid" rel="nofollow">setuid</a> <a href="http://www.faqs.org/docs/bashman/bashref%5F75.html" rel=...
0
2009-12-28T17:03:16Z
[ "python", "linux", "root", "gksudo" ]
How do I sudo the current process?
1,970,329
<p>Is it possible to use a sudo frontend (like gksudo) to elevate the privileges of the <em>current</em> process? I know I can do the following:</p> <pre><code>sudo cat /etc/passwd- </code></pre> <p>But I'm interested in doing this:</p> <pre><code>sudo-become-root # magic function/command cat /etc/passwd- </code></...
8
2009-12-28T16:43:43Z
1,970,665
<p>I wonder if this would work:</p> <p>Add another group to your system, install the script as a root program and have the sudoers file contain a line that allows the script to be executed by this group. Finally add the group to the list of accounts that need to run the script.</p> <p>Then the script can only be run...
0
2009-12-28T17:52:39Z
[ "python", "linux", "root", "gksudo" ]
How do I sudo the current process?
1,970,329
<p>Is it possible to use a sudo frontend (like gksudo) to elevate the privileges of the <em>current</em> process? I know I can do the following:</p> <pre><code>sudo cat /etc/passwd- </code></pre> <p>But I'm interested in doing this:</p> <pre><code>sudo-become-root # magic function/command cat /etc/passwd- </code></...
8
2009-12-28T16:43:43Z
1,970,914
<p>Unfortunately, I'm not aware of a way to do what you want to do cleanly. I think your best bet is to make the program setuid (or run it under sudo) and then either do your dirty work and drop permissions, or fork() and drop permissions from one process and keep the other one around to do your root work.</p> <p>Wha...
1
2009-12-28T18:45:27Z
[ "python", "linux", "root", "gksudo" ]
How do I sudo the current process?
1,970,329
<p>Is it possible to use a sudo frontend (like gksudo) to elevate the privileges of the <em>current</em> process? I know I can do the following:</p> <pre><code>sudo cat /etc/passwd- </code></pre> <p>But I'm interested in doing this:</p> <pre><code>sudo-become-root # magic function/command cat /etc/passwd- </code></...
8
2009-12-28T16:43:43Z
1,971,638
<p>You want to authenticate with PAM. There's an <a href="http://www.ejabberd.im/ejabberd%5Fpam%5Fauthentication" rel="nofollow">example here</a>.</p>
0
2009-12-28T21:27:08Z
[ "python", "linux", "root", "gksudo" ]
Django: Is there a way to have the "through" model in a ManyToManyField in a different app to the model containing the ManyToManyField?
1,970,365
<p>Lets say I have two django apps:</p> <ul> <li><strong>competitions</strong> - which will handle competition data</li> <li><strong>entries</strong> - which will handle functionality relating to entering competitors into competitions</li> </ul> <p>In the competitions app I have a model which represents a section of ...
8
2009-12-28T16:50:16Z
1,970,427
<p>sometimes, <code>django.db.models.get_model</code> helps to work around circular imports. In your example, try to import <code>Entry</code> normally and chage the <code>division</code> FK definition in <code>Entry</code> to this:</p> <pre><code>from django.db.models import get_model class Entry(models.Model): ...
5
2009-12-28T17:01:47Z
[ "python", "django", "django-models", "django-apps", "manytomanyfield" ]
Django: Is there a way to have the "through" model in a ManyToManyField in a different app to the model containing the ManyToManyField?
1,970,365
<p>Lets say I have two django apps:</p> <ul> <li><strong>competitions</strong> - which will handle competition data</li> <li><strong>entries</strong> - which will handle functionality relating to entering competitors into competitions</li> </ul> <p>In the competitions app I have a model which represents a section of ...
8
2009-12-28T16:50:16Z
2,000,070
<p>It seems like I've found an answer, which works more consistently :)</p> <p>The <a href="http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey">Django documentation on the ForeignKey class</a> says:</p> <blockquote> <p>To refer to models defined in another application, you can explicitly specify...
16
2010-01-04T15:04:46Z
[ "python", "django", "django-models", "django-apps", "manytomanyfield" ]
What is the best way to profile a view in Django?
1,970,495
<p>I have developed an application using Django and everything is working fine but I don't know what's going on behind the scenes. I would like to know:</p> <ul> <li>How many times the database is being hit for each request?</li> <li>What was the execution time for each query?</li> <li>How long it took to render the t...
2
2009-12-28T17:18:48Z
1,970,554
<pre><code>{% if debug %} &lt;div id="debug"&gt; &lt;h2&gt;Queries&lt;/h2&gt; &lt;p&gt; {{ sql_queries|length }} Quer{{ sql_queries|pluralize:"y,ies" }} {% ifnotequal sql_queries|length 0 %} (&lt;span style="cursor: pointer;" onclick="var s=document.getElementById('debugQueryTable')....
0
2009-12-28T17:31:00Z
[ "python", "django", "optimization", "profiling" ]
What is the best way to profile a view in Django?
1,970,495
<p>I have developed an application using Django and everything is working fine but I don't know what's going on behind the scenes. I would like to know:</p> <ul> <li>How many times the database is being hit for each request?</li> <li>What was the execution time for each query?</li> <li>How long it took to render the t...
2
2009-12-28T17:18:48Z
1,970,571
<p>three words: <a href="http://github.com/robhudson/django-debug-toolbar" rel="nofollow">Django Debug Toolbar</a></p>
2
2009-12-28T17:35:01Z
[ "python", "django", "optimization", "profiling" ]
What is the best way to profile a view in Django?
1,970,495
<p>I have developed an application using Django and everything is working fine but I don't know what's going on behind the scenes. I would like to know:</p> <ul> <li>How many times the database is being hit for each request?</li> <li>What was the execution time for each query?</li> <li>How long it took to render the t...
2
2009-12-28T17:18:48Z
1,970,629
<p>The one project that meets all your requirements, with the exception of profiling, is the excellent <a href="http://github.com/robhudson/django-debug-toolbar" rel="nofollow">django debug toolbar</a>.</p> <p>For standard profiling you need to use <a href="http://svn.repoze.org/repoze.profile/trunk/" rel="nofollow">r...
2
2009-12-28T17:46:54Z
[ "python", "django", "optimization", "profiling" ]
Integer overflow in numpy arrays
1,970,680
<pre><code>import numpy as np a = np.arange(1000000).reshape(1000,1000) print(a**2) </code></pre> <p>With this code I get this answer. Why do I get negative values?</p> <pre><code>[[ 0 1 4 ..., 994009 996004 998001] [ 1000000 1002001 1004004 ..., 3988009 3992004 ...
5
2009-12-28T17:56:07Z
1,970,697
<p>np.arange returns an array of dtype 'int32' :</p> <pre><code>In [1]: np.arange(1000000).dtype Out[1]: dtype('int32') </code></pre> <p>Each element of the array is a 32-bit integer. Squaring leads to a result which does not fit in 32-bits. The result is cropped to 32-bits and still interpreted as a 32-bit integer, ...
12
2009-12-28T17:58:54Z
[ "python", "numpy" ]
Integer overflow in numpy arrays
1,970,680
<pre><code>import numpy as np a = np.arange(1000000).reshape(1000,1000) print(a**2) </code></pre> <p>With this code I get this answer. Why do I get negative values?</p> <pre><code>[[ 0 1 4 ..., 994009 996004 998001] [ 1000000 1002001 1004004 ..., 3988009 3992004 ...
5
2009-12-28T17:56:07Z
1,970,703
<p>numpy integer types are fixed width and you are seeing the results of integer overflow.</p>
2
2009-12-28T18:00:18Z
[ "python", "numpy" ]
Integer overflow in numpy arrays
1,970,680
<pre><code>import numpy as np a = np.arange(1000000).reshape(1000,1000) print(a**2) </code></pre> <p>With this code I get this answer. Why do I get negative values?</p> <pre><code>[[ 0 1 4 ..., 994009 996004 998001] [ 1000000 1002001 1004004 ..., 3988009 3992004 ...
5
2009-12-28T17:56:07Z
6,477,543
<p>python integers don't have this problem, since they automatically upgrade to python long integers when they overflow.</p> <p>so if you do manage to overflow the int64's, one solution is to use python int's in the numpy array:</p> <p><pre><code>import numpy a=numpy.arange(1000,dtype=object) a**20 </pre></code></p>
3
2011-06-25T11:50:59Z
[ "python", "numpy" ]
Integer overflow in numpy arrays
1,970,680
<pre><code>import numpy as np a = np.arange(1000000).reshape(1000,1000) print(a**2) </code></pre> <p>With this code I get this answer. Why do I get negative values?</p> <pre><code>[[ 0 1 4 ..., 994009 996004 998001] [ 1000000 1002001 1004004 ..., 3988009 3992004 ...
5
2009-12-28T17:56:07Z
15,482,831
<p>A solution to this problem is as follows (taken from <a href="http://mail.scipy.org/pipermail/numpy-tickets/2012-November/006888.html" rel="nofollow">here</a>):</p> <blockquote> <p>...change in class StringConverter._mapper (numpy/lib/_iotools.py) from:</p> </blockquote> <pre><code>{{{ _mapper = [(nx.bool_, str...
0
2013-03-18T17:13:19Z
[ "python", "numpy" ]
Django specific sql query
1,970,718
<p>how can I execute such query in django:</p> <pre><code>SELECT * FROM keywords_keyword WHERE id not in (SELECT keyword_id FROM sites_pagekeyword) </code></pre> <p>In the latest SVN release we can use:</p> <pre><code>keywords = Keyword.objects.raw('SELECT * FROM keywords_keyword WHERE id not in (SELECT keyword_id F...
0
2009-12-28T18:03:32Z
1,970,739
<blockquote> <p><strike>Keyword.objects.exclude(id__in=PageKeyword.objects.all()</strike></p> </blockquote> <pre><code>Keyword.objects.exclude(id__in=PageKeyword.objects.values('keyword_id')) </code></pre> <p>For future reference, <a href="http://docs.djangoproject.com/en/dev/topics/db/queries/#retrieving-specific-...
8
2009-12-28T18:07:47Z
[ "python", "sql", "django", "django-models" ]
Django specific sql query
1,970,718
<p>how can I execute such query in django:</p> <pre><code>SELECT * FROM keywords_keyword WHERE id not in (SELECT keyword_id FROM sites_pagekeyword) </code></pre> <p>In the latest SVN release we can use:</p> <pre><code>keywords = Keyword.objects.raw('SELECT * FROM keywords_keyword WHERE id not in (SELECT keyword_id F...
0
2009-12-28T18:03:32Z
1,971,510
<p>I've tested your code and it works not as expected, here is the right solution for my task:</p> <pre><code>Keyword.objects.exclude(id__in=PageKeyword.objects.values('keyword_id')) </code></pre>
1
2009-12-28T20:55:14Z
[ "python", "sql", "django", "django-models" ]
Center-/middle-align text with PIL?
1,970,807
<p>How would I center-align (and middle-vertical-align) text when using PIL?</p>
18
2009-12-28T18:21:20Z
1,970,893
<p>Use the <code>textsize</code> method (see <a href="http://effbot.org/imagingbook/imagedraw.htm#tag-ImageDraw.Draw.textsize" rel="nofollow">docs</a>) to figure out the dimensions of your text object before actually drawing it. Then draw it starting at the appropriate coordinates.</p>
1
2009-12-28T18:40:43Z
[ "python", "python-imaging-library" ]
Center-/middle-align text with PIL?
1,970,807
<p>How would I center-align (and middle-vertical-align) text when using PIL?</p>
18
2009-12-28T18:21:20Z
1,970,930
<p>Use <a href="http://effbot.org/imagingbook/imagedraw.htm#tag-ImageDraw.Draw.textsize"><code>Draw.textsize</code> method</a> to calculate text size and re-calculate position accordingly.</p> <p>Here is an example:</p> <pre><code>from PIL import Image, ImageDraw W, H = (300,200) msg = "hello" im = Image.new("RGBA"...
34
2009-12-28T18:49:48Z
[ "python", "python-imaging-library" ]
Center-/middle-align text with PIL?
1,970,807
<p>How would I center-align (and middle-vertical-align) text when using PIL?</p>
18
2009-12-28T18:21:20Z
1,970,942
<p>Here is some example code which uses textwrap to split a long line into pieces, and then uses the <code>textsize</code> method to compute the positions.</p> <pre><code>from PIL import Image, ImageDraw, ImageFont import textwrap astr = '''The rain in Spain falls mainly on the plains.''' para = textwrap.wrap(astr, w...
23
2009-12-28T18:53:56Z
[ "python", "python-imaging-library" ]
Center-/middle-align text with PIL?
1,970,807
<p>How would I center-align (and middle-vertical-align) text when using PIL?</p>
18
2009-12-28T18:21:20Z
18,807,482
<p>You could find an implementation of this at <a href="http://tools.jedutils.com/tools/center-text-image" rel="nofollow">http://tools.jedutils.com/tools/center-text-image</a></p> <p>You could use that page for creating the image right there instead of implementing the routine yourself but the code used is included on...
1
2013-09-14T23:44:43Z
[ "python", "python-imaging-library" ]
Center-/middle-align text with PIL?
1,970,807
<p>How would I center-align (and middle-vertical-align) text when using PIL?</p>
18
2009-12-28T18:21:20Z
25,444,782
<p>One shall note that the Draw.textsize method is unaccurate. I was working with low pixels images, and after some testing, it turned out that textsize considers every character to be 6 pixel wide, whereas an "I" takes max. 2 pixels and a "W" takes min. 8 pixels (in my case). And so, depending on my text, it was or wa...
5
2014-08-22T10:22:01Z
[ "python", "python-imaging-library" ]
How to set element's id in Python's xml.dom.minidom?
1,971,186
<p>How to? Created a document and an element:</p> <pre><code>import xml.dom.minidom as d a=d.Document() b=a.createElement('test') </code></pre> <p>setIdAttribute doesn't work :(</p> <pre><code>b.setIdAttribute('something') Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/...
1
2009-12-28T19:48:30Z
1,971,258
<p>Two things are wrong here.</p> <ol> <li><p><code>Document.getElementById</code> will only find elements that are actually in the document. Here you've created <code>b</code> but not actually added it to the document. (It's exactly the same in JavaScript.)</p></li> <li><p>You have to mark <code>id</code> as an ID at...
6
2009-12-28T20:02:00Z
[ "python", "xml", "dom", "minidom" ]
How to set element's id in Python's xml.dom.minidom?
1,971,186
<p>How to? Created a document and an element:</p> <pre><code>import xml.dom.minidom as d a=d.Document() b=a.createElement('test') </code></pre> <p>setIdAttribute doesn't work :(</p> <pre><code>b.setIdAttribute('something') Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/...
1
2009-12-28T19:48:30Z
3,107,071
<p>Adding the name of the id attribute to the DTD should help. For example, if you want every to set the <code>id</code> as the id attribute for all <code>&lt;div&gt;</code> elements, you can set up your DTD as follows:</p> <p><code>&lt;!DOCTYPE div [&lt;!ATTLIST div id ID #IMPLIED&gt;]&gt;</code></p> <p>This is a wo...
2
2010-06-24T03:38:01Z
[ "python", "xml", "dom", "minidom" ]
Python seek on remote file using HTTP
1,971,240
<p>How do I seek to a particular position on a remote (HTTP) file so I can download only that part?</p> <p>Lets say the bytes on a remote file were: 1234567890</p> <p>I wanna seek to 4 and download 3 bytes from there so I would have: 456</p> <p>and also, how do I check if a remote file exists? I tried, os.path.isfil...
8
2009-12-28T19:57:07Z
1,971,294
<p>If you are downloading the remote file through HTTP, you need to set the <code>Range</code> header.</p> <p>Check <a href="http://code.activestate.com/recipes/83208/" rel="nofollow">in this example</a> how it can be done. Looks like this:</p> <pre><code>myUrlclass.addheader("Range","bytes=%s-" % (existSize)) </code...
15
2009-12-28T20:08:44Z
[ "python", "http", "seek" ]
Python seek on remote file using HTTP
1,971,240
<p>How do I seek to a particular position on a remote (HTTP) file so I can download only that part?</p> <p>Lets say the bytes on a remote file were: 1234567890</p> <p>I wanna seek to 4 and download 3 bytes from there so I would have: 456</p> <p>and also, how do I check if a remote file exists? I tried, os.path.isfil...
8
2009-12-28T19:57:07Z
1,971,306
<p>I think the key to your question is that you said "remote file url". This implies that you are using an HTTP URL to download a file with an HTTP "get" operation.</p> <p>So I just did a Google search for "HTTP get" and I found this for you:</p> <p><a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec...
1
2009-12-28T20:11:12Z
[ "python", "http", "seek" ]
Python seek on remote file using HTTP
1,971,240
<p>How do I seek to a particular position on a remote (HTTP) file so I can download only that part?</p> <p>Lets say the bytes on a remote file were: 1234567890</p> <p>I wanna seek to 4 and download 3 bytes from there so I would have: 456</p> <p>and also, how do I check if a remote file exists? I tried, os.path.isfil...
8
2009-12-28T19:57:07Z
1,971,383
<p>AFAIK, this is not possible using fseek() or similar. You need to use the HTTP Range header to achieve this. This header may or may not be supported by the server, so your mileage may vary.</p> <pre><code>import urllib2 myHeaders = {'Range':'bytes=0-9'} req = urllib2.Request('http://www.promotionalpromos.com/mirr...
4
2009-12-28T20:26:50Z
[ "python", "http", "seek" ]
Python seek on remote file using HTTP
1,971,240
<p>How do I seek to a particular position on a remote (HTTP) file so I can download only that part?</p> <p>Lets say the bytes on a remote file were: 1234567890</p> <p>I wanna seek to 4 and download 3 bytes from there so I would have: 456</p> <p>and also, how do I check if a remote file exists? I tried, os.path.isfil...
8
2009-12-28T19:57:07Z
27,091,799
<p>I highly recommend using the <a href="http://docs.python-requests.org/en/latest/">requests</a> library. It is easily the best HTTP library I have ever used. In particular, to accomplish what you have described, you would do something like:</p> <pre><code>import requests url = "http://www.sffaudio.com/podcasts/Shel...
5
2014-11-23T17:12:57Z
[ "python", "http", "seek" ]
Python seek on remote file using HTTP
1,971,240
<p>How do I seek to a particular position on a remote (HTTP) file so I can download only that part?</p> <p>Lets say the bytes on a remote file were: 1234567890</p> <p>I wanna seek to 4 and download 3 bytes from there so I would have: 456</p> <p>and also, how do I check if a remote file exists? I tried, os.path.isfil...
8
2009-12-28T19:57:07Z
33,984,648
<p>I did not find any existing implementations of a file-like interface with seek() to HTTP URLs, so I rolled my own simple version: <a href="https://github.com/valgur/pyhttpio" rel="nofollow">https://github.com/valgur/pyhttpio</a>. It depends on <code>urllib.request</code> but could probably easily be modified to use ...
0
2015-11-29T15:46:26Z
[ "python", "http", "seek" ]