title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Python: Split by 1 or more occurrences of a delimiter
2,492,415
<p>I have a formatted string from a log file, which looks like:</p> <pre><code>&gt;&gt;&gt; a="test result" </code></pre> <p>That is, the test and the result are split by some spaces - it was probably created using formatted string which gave <code>test</code> some constant spacing.</p> <p...
14
2010-03-22T13:12:16Z
2,492,435
<p>Any problem with simple <code>a.split()</code>?</p>
2
2010-03-22T13:15:23Z
[ "python", "string", "split", "delimiter" ]
Python: Split by 1 or more occurrences of a delimiter
2,492,415
<p>I have a formatted string from a log file, which looks like:</p> <pre><code>&gt;&gt;&gt; a="test result" </code></pre> <p>That is, the test and the result are split by some spaces - it was probably created using formatted string which gave <code>test</code> some constant spacing.</p> <p...
14
2010-03-22T13:12:16Z
2,492,447
<p>Just do not give any delimeter?</p> <pre><code>&gt;&gt;&gt; a="test result" &gt;&gt;&gt; a.split() ['test', 'result'] </code></pre>
26
2010-03-22T13:16:16Z
[ "python", "string", "split", "delimiter" ]
Python XML + Java XML interoperability
2,492,490
<p>I need a recommendation for a pythonic library that can marshall python objects to XML(let it be a file). I need to be able read that XML later on with Java (JAXB) and unmarshall it. I know JAXB has some issues that makes it not play nice with .NET XML libraries so a recommendation on something that actually works w...
2
2010-03-22T13:23:06Z
2,492,599
<p>As Ignacio says, XML is XML. On the python side, I recommend using <code>lxml</code>, unless you have more specific needs that are better met by another library. If you are restricted to the standard library, look at <code>ElementTree</code> or <code>cElementTree</code>, which are also excellent, and which inspire...
1
2010-03-22T13:38:28Z
[ "java", "python", "xml", "marshalling", "interop" ]
Python XML + Java XML interoperability
2,492,490
<p>I need a recommendation for a pythonic library that can marshall python objects to XML(let it be a file). I need to be able read that XML later on with Java (JAXB) and unmarshall it. I know JAXB has some issues that makes it not play nice with .NET XML libraries so a recommendation on something that actually works w...
2
2010-03-22T13:23:06Z
2,492,603
<p>The issue your are probably having is the default format of the Python and Java libraries you are using to marshal your objects. Any decent libraries including <a href="http://java.sun.com/webservices/docs/2.0/tutorial/doc/JAXBUsing4.html#wp148715" rel="nofollow"><strong>JAXB allows customisation</strong></a> of how...
0
2010-03-22T13:38:43Z
[ "java", "python", "xml", "marshalling", "interop" ]
Renaming a pylons controller
2,492,692
<p>Is there an automatic way I can use to rename a pylons controller? If I have to rename the controller manually which all files and filenames do I have to change. Thank you much!</p>
2
2010-03-22T13:51:19Z
2,493,390
<p>You need to rename the file containing the controller, as well as the name of the controller class itself within the file. As far as I know there is no automatic way to do this, although if you have many controllers to rename it might be worth the time to write a special script to do it for you.</p> <p>As discussed...
1
2010-03-22T15:19:19Z
[ "python", "pylons" ]
django / python get image from url and display on site
2,492,703
<p>Given a url to an image is there a way in Django/Python to pull this image in and then display it on my site (resized if possible)</p> <p>Thanks</p>
2
2010-03-22T13:52:38Z
2,492,758
<p>If you just want to hotlink it print out the html snippet(<code>&lt;img src="http://example.com/img.png" width="100" height="100" /&gt;</code>).</p> <p>If you want to store in at your server and resize it on the server-side you might want to look into <a href="http://wiki.python.org/moin/ImageMagick" rel="nofollow"...
4
2010-03-22T14:02:13Z
[ "python", "django", "python-imaging-library" ]
GAE AttributeError
2,493,072
<p>My GAE app runs fine from my computer, but when I upload it, I start getting an AttributeError, specifically:</p> <pre><code>AttributeError: 'dict' object has no attribute 'item' </code></pre> <p>I am using the pylast interface (an API for last.fm--<a href="http://code.google.com/p/pylast/" rel="nofollow">link</a>...
2
2010-03-22T14:44:34Z
2,493,207
<p>Python 2.5 doesn't have <code>namedtuple</code>. It was added in 2.6. </p> <p><strong>Edit:</strong> It looks like the <code>_namedtuple</code> function is provided by <code>pylast</code> and will use a real <code>namedtuple</code> in Python 2.6+ but will fall back to a plain old <code>dict</code> in Python 2.5 o...
3
2010-03-22T14:58:14Z
[ "python", "google-app-engine", "attributeerror" ]
GAE AttributeError
2,493,072
<p>My GAE app runs fine from my computer, but when I upload it, I start getting an AttributeError, specifically:</p> <pre><code>AttributeError: 'dict' object has no attribute 'item' </code></pre> <p>I am using the pylast interface (an API for last.fm--<a href="http://code.google.com/p/pylast/" rel="nofollow">link</a>...
2
2010-03-22T14:44:34Z
2,493,369
<p>Yep, Python 2.6 is mostly <strong>backwards</strong>-compatible to 2.5 -- this means that what runs in 2.5 will mostly run in 2.6. But you seem to misunderstand what <strong>backwards</strong> <em>means</em> -- it's the antonym of <strong>forwards</strong>, meaning that it's perfectly possible that what runs in 2.6...
4
2010-03-22T15:17:25Z
[ "python", "google-app-engine", "attributeerror" ]
Determine cluster size of file system in Python
2,493,172
<p>I would like to calculate the "<strong><em>size on disk</em></strong>" of a file in Python. Therefore I would like to determine the cluster size of the file system where the file is stored.</p> <p>How do I determine the cluster size in Python? Or another built-in method that calculates the "<strong><em>size on dis...
6
2010-03-22T14:54:53Z
2,493,196
<p>Use <a href="http://docs.python.org/library/statvfs.html" rel="nofollow">statvfs</a>, at least if you're aiming for a pre-3.0 version of Python. Not sure what it has been replaced with.</p> <p>I also think you're going to have to do the maths yourself, Python doesn't seem to expose the "size in blocks" of files.</p...
2
2010-03-22T14:57:23Z
[ "python", "filesystems" ]
Determine cluster size of file system in Python
2,493,172
<p>I would like to calculate the "<strong><em>size on disk</em></strong>" of a file in Python. Therefore I would like to determine the cluster size of the file system where the file is stored.</p> <p>How do I determine the cluster size in Python? Or another built-in method that calculates the "<strong><em>size on dis...
6
2010-03-22T14:54:53Z
2,494,346
<p>On UNIX/Linux platforms, use Python's built-in <a href="http://docs.python.org/library/os.html#os.statvfs" rel="nofollow">os.statvfs</a>. On Windows, unless you can find a third-party library that does it, you'll need to use ctypes to call the Win32 function <a href="http://msdn.microsoft.com/en-us/library/aa364935...
3
2010-03-22T17:25:08Z
[ "python", "filesystems" ]
How can you do Co-routines using C#?
2,493,294
<p>In python the yield keyword can be used in both push and pull contexts, I know how to do the pull context in c# but how would I achieve the push. I post the code I am trying to replicate in c# from python:</p> <pre><code>def coroutine(func): def start(*args,**kwargs): cr = func(*args,**kwargs) cr.next() ...
9
2010-03-22T15:07:51Z
2,493,319
<p>Maybe this will help.</p> <p><a href="http://blogs.msdn.com/ericlippert/archive/2009/07/23/iterator-blocks-part-five-push-vs-pull.aspx" rel="nofollow">http://blogs.msdn.com/ericlippert/archive/2009/07/23/iterator-blocks-part-five-push-vs-pull.aspx</a></p>
3
2010-03-22T15:12:31Z
[ "c#", "python", "system.reactive", "coroutine" ]
How can you do Co-routines using C#?
2,493,294
<p>In python the yield keyword can be used in both push and pull contexts, I know how to do the pull context in c# but how would I achieve the push. I post the code I am trying to replicate in c# from python:</p> <pre><code>def coroutine(func): def start(*args,**kwargs): cr = func(*args,**kwargs) cr.next() ...
9
2010-03-22T15:07:51Z
2,493,436
<p>thanks @NickLarsen, you helped me remember the new stuff that MS have introduced, the IObservable interface.</p> <p>link <a href="http://msdn.microsoft.com/en-us/library/dd783449%28VS.100%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/dd783449(VS.100).aspx</a></p>
3
2010-03-22T15:24:26Z
[ "c#", "python", "system.reactive", "coroutine" ]
How can you do Co-routines using C#?
2,493,294
<p>In python the yield keyword can be used in both push and pull contexts, I know how to do the pull context in c# but how would I achieve the push. I post the code I am trying to replicate in c# from python:</p> <pre><code>def coroutine(func): def start(*args,**kwargs): cr = func(*args,**kwargs) cr.next() ...
9
2010-03-22T15:07:51Z
2,493,580
<p>C# does not have <em>general</em> co-routines. A general co-routine is where the co-routine has its own stack, i.e. it can invoke other methods and those methods can "yield" values. Implementation of general co-routines requires making some smart things with stacks, possibly up to and including allocating stack fram...
6
2010-03-22T15:41:04Z
[ "c#", "python", "system.reactive", "coroutine" ]
How can you do Co-routines using C#?
2,493,294
<p>In python the yield keyword can be used in both push and pull contexts, I know how to do the pull context in c# but how would I achieve the push. I post the code I am trying to replicate in c# from python:</p> <pre><code>def coroutine(func): def start(*args,**kwargs): cr = func(*args,**kwargs) cr.next() ...
9
2010-03-22T15:07:51Z
2,494,660
<p>If what you want is an "observable collection" -- that is, a collection which pushes results at you rather than letting the consumer pull them -- then you probably want to look into the Reactive Framework extensions. Here's an article on it:</p> <p><a href="http://www.infoq.com/news/2009/07/Reactive-Framework-LINQ-...
13
2010-03-22T18:12:39Z
[ "c#", "python", "system.reactive", "coroutine" ]
How can you do Co-routines using C#?
2,493,294
<p>In python the yield keyword can be used in both push and pull contexts, I know how to do the pull context in c# but how would I achieve the push. I post the code I am trying to replicate in c# from python:</p> <pre><code>def coroutine(func): def start(*args,**kwargs): cr = func(*args,**kwargs) cr.next() ...
9
2010-03-22T15:07:51Z
3,173,880
<p>I would love to see a fiber-based API for .Net.</p> <p>I attempted to use the native fiber API in C# through p/invoke a while back, but because the runtime's exception handling (incorrectly) makes thread-based assumptions, things broke (badly) when exceptions happened.</p> <p>One "killer app" for a fiber-based cor...
0
2010-07-04T05:58:49Z
[ "c#", "python", "system.reactive", "coroutine" ]
How can you do Co-routines using C#?
2,493,294
<p>In python the yield keyword can be used in both push and pull contexts, I know how to do the pull context in c# but how would I achieve the push. I post the code I am trying to replicate in c# from python:</p> <pre><code>def coroutine(func): def start(*args,**kwargs): cr = func(*args,**kwargs) cr.next() ...
9
2010-03-22T15:07:51Z
3,199,292
<p>Actually .NET does not make "incorrect assumptions" about thread affinity, in fact it totally decouples the notion of a .NET level thread from the OS level thread. </p> <p>What you have to do is associate a logical .NET thread state with your fiber ( for that you need the CLR Hosting API's but you don'T need to wri...
1
2010-07-07T22:08:14Z
[ "c#", "python", "system.reactive", "coroutine" ]
How can you do Co-routines using C#?
2,493,294
<p>In python the yield keyword can be used in both push and pull contexts, I know how to do the pull context in c# but how would I achieve the push. I post the code I am trying to replicate in c# from python:</p> <pre><code>def coroutine(func): def start(*args,**kwargs): cr = func(*args,**kwargs) cr.next() ...
9
2010-03-22T15:07:51Z
23,227,272
<p>Well, i gave a try developing a full library to manage coroutines with only a single thread. The hard part was to call coroutines inside coroutines...and to return parameters, but finally i reached a pretty good result <a href="http://www.kendar.org/?p=/dotnet/helpers/concurrencyhelpers" rel="nofollow">here</a>. The...
0
2014-04-22T18:18:01Z
[ "c#", "python", "system.reactive", "coroutine" ]
download mbox files over https using python
2,493,394
<p>I was trying to find the right module for downloading kernel patches from kernel.org site</p> <p>For example,to download the file at <a href="https://patchwork.kernel.org/patch/62948/mbox/" rel="nofollow">https://patchwork.kernel.org/patch/62948/mbox/</a></p> <p>I understand urlgrabber has a problem with https on...
1
2010-03-22T15:19:31Z
2,493,410
<p>Hmm, maybe you need redirect handling?</p>
0
2010-03-22T15:22:18Z
[ "python", "urllib2" ]
download mbox files over https using python
2,493,394
<p>I was trying to find the right module for downloading kernel patches from kernel.org site</p> <p>For example,to download the file at <a href="https://patchwork.kernel.org/patch/62948/mbox/" rel="nofollow">https://patchwork.kernel.org/patch/62948/mbox/</a></p> <p>I understand urlgrabber has a problem with https on...
1
2010-03-22T15:19:31Z
2,493,448
<p>Curious, this url should work fine (though I've tried it on Mac OS X only). I used this very simple test in my code:</p> <pre><code>import urllib get_url = lambda url : urllib.urlopen(url).read() data = get_url('https://patchwork.kernel.org/patch/62948/mbox/') </code></pre> <p>Of course, this loads the result into...
1
2010-03-22T15:25:16Z
[ "python", "urllib2" ]
complex if statement in python
2,493,404
<p>I need to realize a <em>complex</em> if-elif-else statement in Python but I don't get it working.</p> <p>The elif line I need has to check a variable for this conditions:</p> <p><strong>80, 443 or 1024-65535 inclusive</strong></p> <p>I tried </p> <pre><code>if ... # several checks ... elif (var1 &gt; 65535...
17
2010-03-22T15:21:27Z
2,493,420
<p>It's often easier to think in the positive sense, and wrap it in a not:</p> <pre><code>elif not (var1 == 80 or var1 == 443 or (1024 &lt;= var1 &lt;= 65535)): # fail </code></pre> <p>You could of course also go all out and be a bit more object-oriented:</p> <pre><code>class PortValidator(object): @staticmethod...
14
2010-03-22T15:23:16Z
[ "python" ]
complex if statement in python
2,493,404
<p>I need to realize a <em>complex</em> if-elif-else statement in Python but I don't get it working.</p> <p>The elif line I need has to check a variable for this conditions:</p> <p><strong>80, 443 or 1024-65535 inclusive</strong></p> <p>I tried </p> <pre><code>if ... # several checks ... elif (var1 &gt; 65535...
17
2010-03-22T15:21:27Z
2,493,421
<pre><code>if x == 80 or x == 443 or 1024 &lt;= x &lt;= 65535 </code></pre> <p>should definitely do</p>
6
2010-03-22T15:23:17Z
[ "python" ]
complex if statement in python
2,493,404
<p>I need to realize a <em>complex</em> if-elif-else statement in Python but I don't get it working.</p> <p>The elif line I need has to check a variable for this conditions:</p> <p><strong>80, 443 or 1024-65535 inclusive</strong></p> <p>I tried </p> <pre><code>if ... # several checks ... elif (var1 &gt; 65535...
17
2010-03-22T15:21:27Z
2,493,428
<pre><code>if ... # several checks ... elif not (1024&lt;=var&lt;=65535 or var == 80 or var == 443) # fail else ... </code></pre>
2
2010-03-22T15:23:53Z
[ "python" ]
complex if statement in python
2,493,404
<p>I need to realize a <em>complex</em> if-elif-else statement in Python but I don't get it working.</p> <p>The elif line I need has to check a variable for this conditions:</p> <p><strong>80, 443 or 1024-65535 inclusive</strong></p> <p>I tried </p> <pre><code>if ... # several checks ... elif (var1 &gt; 65535...
17
2010-03-22T15:21:27Z
2,493,434
<p>This should do it:</p> <pre><code>elif var == 80 or var == 443 or 1024 &lt;= var &lt;= 65535: </code></pre>
26
2010-03-22T15:24:20Z
[ "python" ]
complex if statement in python
2,493,404
<p>I need to realize a <em>complex</em> if-elif-else statement in Python but I don't get it working.</p> <p>The elif line I need has to check a variable for this conditions:</p> <p><strong>80, 443 or 1024-65535 inclusive</strong></p> <p>I tried </p> <pre><code>if ... # several checks ... elif (var1 &gt; 65535...
17
2010-03-22T15:21:27Z
2,493,444
<pre><code>if ... # several checks ... elif ((var1 &gt; 65535) or ((var1 &lt; 1024)) and (var1 != 80) and (var1 != 443)): # fail else ... </code></pre> <p>you missed a quote</p>
0
2010-03-22T15:24:50Z
[ "python" ]
complex if statement in python
2,493,404
<p>I need to realize a <em>complex</em> if-elif-else statement in Python but I don't get it working.</p> <p>The elif line I need has to check a variable for this conditions:</p> <p><strong>80, 443 or 1024-65535 inclusive</strong></p> <p>I tried </p> <pre><code>if ... # several checks ... elif (var1 &gt; 65535...
17
2010-03-22T15:21:27Z
2,493,590
<p>I think the most pythonic way to do this for me, will be</p> <pre><code>elif var in [80,443] + range(1024,65535): </code></pre> <p>although it could take a little time and memory (it's generating numbers from 1024 to 65535). If there's a problem with that, I'll do:</p> <pre><code>elif 1024 &lt;= var &lt;= 65535 o...
4
2010-03-22T15:41:53Z
[ "python" ]
Dictionaries with tuples that have lists as values
2,493,425
<p>How can i have a tuple that has a list as a value.</p> <p>F.x. if i want to have a structure like this.</p> <p>( Somechar , Somelist[] )</p> <p>And how would i iterate through a dictionary of these things?</p>
0
2010-03-22T15:23:49Z
2,493,462
<p>A tuple can contain anything you like. It just works the same as a nested list.</p> <pre><code>&gt;&gt;&gt; myvar = ('d', [1, 2]) &gt;&gt;&gt; myvar[0] 'd' &gt;&gt;&gt; myvar[1] [1, 2] &gt;&gt;&gt; myvar[1][1] 2 </code></pre>
0
2010-03-22T15:27:02Z
[ "python", "list", "dictionary", "tuples" ]
Dictionaries with tuples that have lists as values
2,493,425
<p>How can i have a tuple that has a list as a value.</p> <p>F.x. if i want to have a structure like this.</p> <p>( Somechar , Somelist[] )</p> <p>And how would i iterate through a dictionary of these things?</p>
0
2010-03-22T15:23:49Z
2,493,499
<p>You can add a list to a tuple just like any other element. From a dictionary, you can access each element of the tuple by indexing it like so: <code>d[key][0]</code> and <code>d[key][1]</code>. Here is an example:</p> <pre> >>> d = {} >>> d["b"] = ('b', [2]) >>> d["a"] = ('a', [1]) >>> for k in d: ... print(d[k...
2
2010-03-22T15:30:55Z
[ "python", "list", "dictionary", "tuples" ]
Dictionaries with tuples that have lists as values
2,493,425
<p>How can i have a tuple that has a list as a value.</p> <p>F.x. if i want to have a structure like this.</p> <p>( Somechar , Somelist[] )</p> <p>And how would i iterate through a dictionary of these things?</p>
0
2010-03-22T15:23:49Z
2,493,505
<p>Here's a simple example:</p> <pre><code>&gt;&gt; a = ('a', ['a list']) &gt;&gt; a ('a', ['a list']) &gt;&gt; b = dict((a,)) {'a': ['a list']} for i, j in b.iteritems(): print i, j a ['a list'] </code></pre> <p>Does that answer your question? The dict constructor takes a list/tuple of (key, value) tuples. Als...
0
2010-03-22T15:31:22Z
[ "python", "list", "dictionary", "tuples" ]
How to make Twisted use Python logging?
2,493,644
<p>I've got a project where I'm using Twisted for my web server. When exceptions occur (such as network errors), it's printing to the console.</p> <p>I've already got logging through Python's built-in log module - is there any way to tell the reactor to use that instead?</p> <p>What's the usual pattern for this?</p>...
20
2010-03-22T15:51:43Z
2,493,725
<p>Found it. It's actually quite easy:</p> <pre><code>from twisted.python import log observer = log.PythonLoggingObserver(loggerName='logname') observer.start() </code></pre> <p>You just set loggerName to the same logger name that you're using in logging.getLogger().</p>
22
2010-03-22T16:01:20Z
[ "python", "twisted" ]
How to make Twisted use Python logging?
2,493,644
<p>I've got a project where I'm using Twisted for my web server. When exceptions occur (such as network errors), it's printing to the console.</p> <p>I've already got logging through Python's built-in log module - is there any way to tell the reactor to use that instead?</p> <p>What's the usual pattern for this?</p>...
20
2010-03-22T15:51:43Z
2,493,728
<p>You can use <a href="http://twistedmatrix.com/documents/current/core/howto/logging.html" rel="nofollow">twisted.python.log</a>. For example:</p> <pre><code>from twisted.python import log log.msg('Hello, world.') </code></pre>
1
2010-03-22T16:01:26Z
[ "python", "twisted" ]
How to implement a hub in Python
2,493,888
<p>Dear all, I need to implement a TCP server in Python which receives some data from a client and then sends this data to another client. I've tried many different implementations but no way to make it run. Any help would be really appreciated.<br> Below is my code:</p> <pre><code>import SocketServer import sys impor...
0
2010-03-22T16:21:15Z
2,493,924
<p>Can you be more specific about what you tried and what didn't work? There are lots of ways to do this. Probably the easiest would be to use the socket library - maybe looking at some examples will help:</p> <p><a href="http://docs.python.org/library/socket.html#example" rel="nofollow">http://docs.python.org/libra...
0
2010-03-22T16:25:42Z
[ "python", "tcp", "sockets", "client" ]
How to implement a hub in Python
2,493,888
<p>Dear all, I need to implement a TCP server in Python which receives some data from a client and then sends this data to another client. I've tried many different implementations but no way to make it run. Any help would be really appreciated.<br> Below is my code:</p> <pre><code>import SocketServer import sys impor...
0
2010-03-22T16:21:15Z
2,494,753
<p>See the <a href="http://twistedmatrix.com/documents/current/core/howto/tutorial/index.html" rel="nofollow">Twisted tutorial</a>, and also <a href="http://twistedmatrix.com/trac/browser/tags/releases/twisted-10.0.0//twisted/protocols/portforward.py" rel="nofollow"><code>twisted.protocols.portforward</code></a>. I th...
1
2010-03-22T18:28:16Z
[ "python", "tcp", "sockets", "client" ]
How to switch position of two items in a Python list?
2,493,920
<p>I haven’t been able to find a good solution for this problem on the net (probably because switch, position, list and Python are all such overloaded words).</p> <p>It’s rather simple – I have this list:</p> <pre><code>['title', 'email', 'password2', 'password1', 'first_name', 'last_name', 'next', 'newsletter...
81
2010-03-22T16:25:14Z
2,493,942
<p>How can it ever be longer than</p> <pre><code>tmp = my_list[indexOfPwd2] my_list[indexOfPwd2] = my_list[indexOfPwd2 + 1] my_list[indexOfPwd2 + 1] = tmp </code></pre> <p>That's just a plain swap using temporary storage.</p>
4
2010-03-22T16:27:40Z
[ "python", "list", "order" ]
How to switch position of two items in a Python list?
2,493,920
<p>I haven’t been able to find a good solution for this problem on the net (probably because switch, position, list and Python are all such overloaded words).</p> <p>It’s rather simple – I have this list:</p> <pre><code>['title', 'email', 'password2', 'password1', 'first_name', 'last_name', 'next', 'newsletter...
81
2010-03-22T16:25:14Z
2,493,962
<p>The simple Python swap looks like this:</p> <pre><code>foo[i], foo[j] = foo[j], foo[i] </code></pre> <p>Now all you need to do is figure what <code>i</code> is, and that can easily be done with <code>index</code>:</p> <pre><code>i = foo.index("password2") </code></pre>
69
2010-03-22T16:30:05Z
[ "python", "list", "order" ]
How to switch position of two items in a Python list?
2,493,920
<p>I haven’t been able to find a good solution for this problem on the net (probably because switch, position, list and Python are all such overloaded words).</p> <p>It’s rather simple – I have this list:</p> <pre><code>['title', 'email', 'password2', 'password1', 'first_name', 'last_name', 'next', 'newsletter...
81
2010-03-22T16:25:14Z
2,493,980
<pre><code> i = ['title', 'email', 'password2', 'password1', 'first_name', 'last_name', 'next', 'newsletter'] a, b = i.index('password2'), i.index('password1') i[b], i[a] = i[a], i[b] </code></pre>
161
2010-03-22T16:31:49Z
[ "python", "list", "order" ]
How to switch position of two items in a Python list?
2,493,920
<p>I haven’t been able to find a good solution for this problem on the net (probably because switch, position, list and Python are all such overloaded words).</p> <p>It’s rather simple – I have this list:</p> <pre><code>['title', 'email', 'password2', 'password1', 'first_name', 'last_name', 'next', 'newsletter...
81
2010-03-22T16:25:14Z
2,494,003
<p>Given your specs, I'd use slice-assignment:</p> <pre><code>&gt;&gt;&gt; L = ['title', 'email', 'password2', 'password1', 'first_name', 'last_name', 'next', 'newsletter'] &gt;&gt;&gt; i = L.index('password2') &gt;&gt;&gt; L[i:i+2] = L[i+1:i-1:-1] &gt;&gt;&gt; L ['title', 'email', 'password1', 'password2', 'first_nam...
11
2010-03-22T16:35:28Z
[ "python", "list", "order" ]
How to switch position of two items in a Python list?
2,493,920
<p>I haven’t been able to find a good solution for this problem on the net (probably because switch, position, list and Python are all such overloaded words).</p> <p>It’s rather simple – I have this list:</p> <pre><code>['title', 'email', 'password2', 'password1', 'first_name', 'last_name', 'next', 'newsletter...
81
2010-03-22T16:25:14Z
36,111,460
<p>you can use for example:</p> <pre><code>&gt;&gt;&gt; test_list = ['title', 'email', 'password2', 'password1', 'first_name', 'last_name', 'next', 'newsletter'] &gt;&gt;&gt; reorder_func = lambda x: x.insert(x.index('password2'), x.pop(x.index('password2')+1)) &gt;&gt;&gt; reorder_func(test_list) &g...
0
2016-03-20T07:58:10Z
[ "python", "list", "order" ]
How to switch position of two items in a Python list?
2,493,920
<p>I haven’t been able to find a good solution for this problem on the net (probably because switch, position, list and Python are all such overloaded words).</p> <p>It’s rather simple – I have this list:</p> <pre><code>['title', 'email', 'password2', 'password1', 'first_name', 'last_name', 'next', 'newsletter...
81
2010-03-22T16:25:14Z
38,803,587
<p>I am not an expert in python but you could try: say </p> <pre><code>i = (1,2) res = lambda i: (i[1],i[0]) print 'res(1, 2) = {0}'.format(res(1, 2)) </code></pre> <p>above would give o/p as:</p> <pre><code>res(1, 2) = (2,1) </code></pre>
-2
2016-08-06T11:09:07Z
[ "python", "list", "order" ]
Properly using subprocess.PIPE in python?
2,493,976
<p>I'm trying to use <code>subprocess.Popen</code> to construct a sequence to grab the duration of a video file. I've been searching for 3 days, and can't find any reason online as to why this code isn't working, but it keeps giving me a blank result:</p> <pre><code>import sys import os import subprocess def main(): ...
13
2010-03-22T16:31:27Z
2,494,023
<p>Using <code>subprocess.PIPE</code> will not magically wire the correct pipes for you.</p> <p>You must pass the output pipe of the first process as the value for the parameter <code>stdin</code> of the second process. <a href="http://docs.python.org/library/subprocess.html#replacing-shell-pipeline">See the docs for ...
13
2010-03-22T16:38:22Z
[ "python", "subprocess" ]
Properly using subprocess.PIPE in python?
2,493,976
<p>I'm trying to use <code>subprocess.Popen</code> to construct a sequence to grab the duration of a video file. I've been searching for 3 days, and can't find any reason online as to why this code isn't working, but it keeps giving me a blank result:</p> <pre><code>import sys import os import subprocess def main(): ...
13
2010-03-22T16:31:27Z
2,494,046
<p>Python can't "build a whole pipeline" in this way -- it could delegate the task to the shell, or glue it up more directly using the <code>stdout</code> attributes of previous subprocess objects in the line, but there's really no reason for that in this specific case, since you can code it directly in Python pretty e...
2
2010-03-22T16:41:21Z
[ "python", "subprocess" ]
Properly using subprocess.PIPE in python?
2,493,976
<p>I'm trying to use <code>subprocess.Popen</code> to construct a sequence to grab the duration of a video file. I've been searching for 3 days, and can't find any reason online as to why this code isn't working, but it keeps giving me a blank result:</p> <pre><code>import sys import os import subprocess def main(): ...
13
2010-03-22T16:31:27Z
2,494,110
<p>stderr needs to be redirected to stdout. Also, there's no need to call other tools like <code>cut/sed</code> etc. do your string manipulation in Python</p> <pre><code>import subprocess .... the_file = "/Volumes/Footage/Acura/MDX/2001/Crash Test/01 Acura MDX Front Crash.mov" ffmpeg = subprocess.Popen(['/usr/bin/ffmp...
12
2010-03-22T16:49:56Z
[ "python", "subprocess" ]
Properly using subprocess.PIPE in python?
2,493,976
<p>I'm trying to use <code>subprocess.Popen</code> to construct a sequence to grab the duration of a video file. I've been searching for 3 days, and can't find any reason online as to why this code isn't working, but it keeps giving me a blank result:</p> <pre><code>import sys import os import subprocess def main(): ...
13
2010-03-22T16:31:27Z
18,070,129
<p>As others have pointed out, you need to pass the PIPE from one process to the next. The stdout (PIPE) from one process becomes the stdin for the following task.</p> <p>Something like this (starting from your example):</p> <pre><code>import sys import os import subprocess def main(): the_file = "/Volumes/Footage...
19
2013-08-06T00:51:45Z
[ "python", "subprocess" ]
Evaluating for loops in python, containing an array with an embedded for loop
2,494,141
<p>I was looking at the following code in python:</p> <pre><code>for ob in [ob for ob in context.scene.objects if ob.is_visible()]: pass </code></pre> <p>Obviously, it's a for each loop, saying for each object in foo array. However, I'm having a bit of trouble reading the array. If it just had:</p> <pre><code>...
1
2010-03-22T16:57:10Z
2,494,166
<p>That is the syntax for <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a>.</p>
1
2010-03-22T17:01:20Z
[ "python", "arrays", "list", "foreach" ]
Evaluating for loops in python, containing an array with an embedded for loop
2,494,141
<p>I was looking at the following code in python:</p> <pre><code>for ob in [ob for ob in context.scene.objects if ob.is_visible()]: pass </code></pre> <p>Obviously, it's a for each loop, saying for each object in foo array. However, I'm having a bit of trouble reading the array. If it just had:</p> <pre><code>...
1
2010-03-22T16:57:10Z
2,494,184
<p>The first <code>ob</code> is an expression, take this simple example:</p> <pre><code>&gt;&gt;&gt;&gt; [ x**2 for x in range(10) if x%2 == 0 ] [0, 4, 16, 36, 64] </code></pre> <p>Which reads, create a list from <code>range(10)</code>, if <code>x</code> is even then square it. Discard any odd value of <code>x</code...
0
2010-03-22T17:03:30Z
[ "python", "arrays", "list", "foreach" ]
Evaluating for loops in python, containing an array with an embedded for loop
2,494,141
<p>I was looking at the following code in python:</p> <pre><code>for ob in [ob for ob in context.scene.objects if ob.is_visible()]: pass </code></pre> <p>Obviously, it's a for each loop, saying for each object in foo array. However, I'm having a bit of trouble reading the array. If it just had:</p> <pre><code>...
1
2010-03-22T16:57:10Z
2,494,200
<p>It's a list comprehension. You can read it as:</p> <p><em>create a list with</em> <code>[some_new_value for the_current_value in source_list_of_values if matches_criteria]</code></p> <p>Think of:</p> <pre><code>[n*2 for n in [1,2,3,4]] </code></pre> <p>This means, for every item, <code>n</code>, create an entry...
0
2010-03-22T17:05:41Z
[ "python", "arrays", "list", "foreach" ]
Evaluating for loops in python, containing an array with an embedded for loop
2,494,141
<p>I was looking at the following code in python:</p> <pre><code>for ob in [ob for ob in context.scene.objects if ob.is_visible()]: pass </code></pre> <p>Obviously, it's a for each loop, saying for each object in foo array. However, I'm having a bit of trouble reading the array. If it just had:</p> <pre><code>...
1
2010-03-22T16:57:10Z
2,494,373
<p>It might help you see what's going on to rewrite your example code into this equivalent code:</p> <pre><code>temp_list = [ob for ob in context.scene.objects if ob.is_visible()] for ob in temp_list: pass </code></pre>
0
2010-03-22T17:30:48Z
[ "python", "arrays", "list", "foreach" ]
ctypes and pointer manipulation
2,494,288
<p>I am dealing with image buffers, and I want to be able to access data a few lines into my image for analysis with a c library. I have created my 8-bit pixel buffer in Python using create_string_buffer. Is there a way to get a pointer to a location within that buffer without re-creating a new buffer? My goal is to...
5
2010-03-22T17:18:04Z
2,494,481
<p><a href="http://docs.python.org/library/ctypes.html?highlight=ctypes#ctypes.create_string_buffer">create_string_buffer</a> gives you a ctypes object (an array of chars), then <a href="http://docs.python.org/library/ctypes.html?highlight=ctypes#ctypes.byref">byref</a>, and I quote,</p> <blockquote> <p>Returns a li...
8
2010-03-22T17:45:57Z
[ "python", "ctypes" ]
ctypes and pointer manipulation
2,494,288
<p>I am dealing with image buffers, and I want to be able to access data a few lines into my image for analysis with a c library. I have created my 8-bit pixel buffer in Python using create_string_buffer. Is there a way to get a pointer to a location within that buffer without re-creating a new buffer? My goal is to...
5
2010-03-22T17:18:04Z
2,494,539
<p>You can also use <code>ctypes.cast(buf, ctypes.c_void_p)</code></p>
0
2010-03-22T17:54:20Z
[ "python", "ctypes" ]
ssh-rsa public key validation using a regular expression
2,494,450
<p>What regular expression can I use (if any) to validate that a given string is a legal ssh rsa public key?</p> <p>I only need to validate the actual key - I don't care about the key type the precedes it or the username comment after it.</p> <p>Ideally, someone will also provide the python code to run the regex vali...
7
2010-03-22T17:41:02Z
2,494,599
<p>Based on the references to "key type that precedes it" and "username comment after it", I assume you're talking about public keys stored in ssh2 keyfile format.</p> <p>In that format, the key is stored in <a href="http://en.wikipedia.org/wiki/Base64" rel="nofollow">base64</a> format, so a simple check would be to v...
1
2010-03-22T18:02:30Z
[ "python", "regex", "validation", "ssh-keys" ]
ssh-rsa public key validation using a regular expression
2,494,450
<p>What regular expression can I use (if any) to validate that a given string is a legal ssh rsa public key?</p> <p>I only need to validate the actual key - I don't care about the key type the precedes it or the username comment after it.</p> <p>Ideally, someone will also provide the python code to run the regex vali...
7
2010-03-22T17:41:02Z
2,494,645
<p>A "good enough" check is to see if the key starts with the correct header.</p> <p>The data portion of the keyfile should decode from base64, or it will fail with a base64.binascii.Error</p> <p>Unpack the first 4 bytes (an int), which should be 7. This is the length of the following string (I guess this could be di...
9
2010-03-22T18:10:07Z
[ "python", "regex", "validation", "ssh-keys" ]
How to create an application which embeds and runs Python code without local Python installation?
2,494,468
<p>Hello fellow software developers.</p> <p>I want to distribute a C program which is scriptable by embedding the Python interpreter.<br> The C program uses Py_Initialize, PyImport_Import and so on to accomplish Python embedding.</p> <p>I'm looking for a solution where I distribute only the following components: </p...
7
2010-03-22T17:43:59Z
2,494,848
<p>Did you take a look at <a href="http://www.portablepython.com/" rel="nofollow">Portable Python</a> ? No need to install anything. Just copy the included files to use the interpreter. </p> <p>Edit : This is a Windows only solution.</p>
1
2010-03-22T18:42:09Z
[ "python", "c", "dll", "distribution" ]
How to create an application which embeds and runs Python code without local Python installation?
2,494,468
<p>Hello fellow software developers.</p> <p>I want to distribute a C program which is scriptable by embedding the Python interpreter.<br> The C program uses Py_Initialize, PyImport_Import and so on to accomplish Python embedding.</p> <p>I'm looking for a solution where I distribute only the following components: </p...
7
2010-03-22T17:43:59Z
2,494,972
<p>Have you looked at <a href="http://docs.python.org/extending/embedding.html" rel="nofollow">Embedding Python in Another Application</a> in the Python documentation?</p> <p>Once you have that, you can use an import hook (see <a href="http://www.python.org/dev/peps/pep-0302/" rel="nofollow">PEP 302</a>) to have your ...
0
2010-03-22T19:04:49Z
[ "python", "c", "dll", "distribution" ]
How to create an application which embeds and runs Python code without local Python installation?
2,494,468
<p>Hello fellow software developers.</p> <p>I want to distribute a C program which is scriptable by embedding the Python interpreter.<br> The C program uses Py_Initialize, PyImport_Import and so on to accomplish Python embedding.</p> <p>I'm looking for a solution where I distribute only the following components: </p...
7
2010-03-22T17:43:59Z
2,495,001
<p>Have you looked at Python's official documentation : <a href="http://docs.python.org/extending/embedding.html">Embedding Python into another application</a>?</p> <p>There's also this really nice PDF by IBM : <a href="https://www6.software.ibm.com/developerworks/education/l-pythonscript/l-pythonscript-ltr.pdf">Embed...
5
2010-03-22T19:12:00Z
[ "python", "c", "dll", "distribution" ]
How to create an application which embeds and runs Python code without local Python installation?
2,494,468
<p>Hello fellow software developers.</p> <p>I want to distribute a C program which is scriptable by embedding the Python interpreter.<br> The C program uses Py_Initialize, PyImport_Import and so on to accomplish Python embedding.</p> <p>I'm looking for a solution where I distribute only the following components: </p...
7
2010-03-22T17:43:59Z
2,540,589
<p>I simply tested my executable on a computer which hasn't Python installed and it worked.</p> <p>When you link Python to your executable (no matter if dynamically or statically) your executable already gains basic Python language functionality (operators, methods, basic structures like string, list, tuple, dict, etc...
1
2010-03-29T19:13:32Z
[ "python", "c", "dll", "distribution" ]
How to create an application which embeds and runs Python code without local Python installation?
2,494,468
<p>Hello fellow software developers.</p> <p>I want to distribute a C program which is scriptable by embedding the Python interpreter.<br> The C program uses Py_Initialize, PyImport_Import and so on to accomplish Python embedding.</p> <p>I'm looking for a solution where I distribute only the following components: </p...
7
2010-03-22T17:43:59Z
2,540,638
<p>There's a program called py2exe. I don't know if it's only available for Windows. Also, the latest version that I used does not wrap everything up into one .exe file. It creates a bunch of stuff that has to be distributed - a zip file, etc..</p>
0
2010-03-29T19:21:29Z
[ "python", "c", "dll", "distribution" ]
How to create an application which embeds and runs Python code without local Python installation?
2,494,468
<p>Hello fellow software developers.</p> <p>I want to distribute a C program which is scriptable by embedding the Python interpreter.<br> The C program uses Py_Initialize, PyImport_Import and so on to accomplish Python embedding.</p> <p>I'm looking for a solution where I distribute only the following components: </p...
7
2010-03-22T17:43:59Z
22,499,189
<p>I think here is the answer you want <a href="http://stackoverflow.com/questions/18428600/unable-to-get-python-embedded-to-work-with-zipd-library">Unable to get python embedded to work with zip&#39;d library</a></p> <p>Basically, you need:</p> <pre><code>Py_NoSiteFlag=1; Py_SetProgramName(argv[0]); Py_SetPythonHome...
0
2014-03-19T07:36:05Z
[ "python", "c", "dll", "distribution" ]
Modify default queryset in django
2,494,501
<p>I have added a 'cancelled' field to my model, is there a way to modify the model default query to something like cancelled=False ? without having to modify all my filter/exclude queries ?</p>
14
2010-03-22T17:48:12Z
2,494,558
<p>You can do this with a custom model manager and override the <code>get_query_set</code> function to always filter canceled=False.</p> <pre><code>class CustomManager(models.Manager): def get_query_set(self): return super(CustomManager, self).get_queryset().filter(canceled=False) class MyModel(models.Mod...
21
2010-03-22T17:56:29Z
[ "python", "django", "django-models", "metaprogramming" ]
Modify default queryset in django
2,494,501
<p>I have added a 'cancelled' field to my model, is there a way to modify the model default query to something like cancelled=False ? without having to modify all my filter/exclude queries ?</p>
14
2010-03-22T17:48:12Z
2,494,567
<p>You could write custom <a href="http://www.djangoproject.com/documentation/models/custom_managers/" rel="nofollow">query manager</a>, but I don't believe this is the right way to go. This would make an implicit, hidden condition for a filter, which would make code unreadable. Remember Zen of Python: <code>Explicit i...
3
2010-03-22T17:57:16Z
[ "python", "django", "django-models", "metaprogramming" ]
Sort a list of tuples without case sensitivity
2,494,740
<p>How can I efficiently and easily sort a list of tuples <em>without</em> being sensitive to case?</p> <p>For example this:</p> <pre><code>[('a', 'c'), ('A', 'b'), ('a', 'a'), ('a', 5)] </code></pre> <p>Should look like this once sorted:</p> <pre><code>[('a', 5), ('a', 'a'), ('A', 'b'), ('a', 'c')] </code></pre> ...
4
2010-03-22T18:26:30Z
2,494,764
<p>You can use <code>sort</code>'s <code>key</code> argument to define how you wish to regard each element with respect to sorting:</p> <pre><code>def lower_if_possible(x): try: return x.lower() except AttributeError: return x L=[('a', 'c'), ('A', 'b'), ('a', 'a'), ('a', 5)] L.sort(key=lambda...
9
2010-03-22T18:30:44Z
[ "python", "sorting", "tuples", "case-insensitive" ]
Sort a list of tuples without case sensitivity
2,494,740
<p>How can I efficiently and easily sort a list of tuples <em>without</em> being sensitive to case?</p> <p>For example this:</p> <pre><code>[('a', 'c'), ('A', 'b'), ('a', 'a'), ('a', 5)] </code></pre> <p>Should look like this once sorted:</p> <pre><code>[('a', 5), ('a', 'a'), ('A', 'b'), ('a', 'c')] </code></pre> ...
4
2010-03-22T18:26:30Z
2,494,768
<p>Something like this should work:</p> <pre><code>def sort_ci(items): def sort_tuple(tuple): return ([lower(x) for x in tuple],) + tuple temp = [sort_tuple(tuple) for tuple in items] temp.sort() return [tuple[1:] for tuple in temp] </code></pre> <p>In other words, create a new list, where eac...
0
2010-03-22T18:31:40Z
[ "python", "sorting", "tuples", "case-insensitive" ]
Sort a list of tuples without case sensitivity
2,494,740
<p>How can I efficiently and easily sort a list of tuples <em>without</em> being sensitive to case?</p> <p>For example this:</p> <pre><code>[('a', 'c'), ('A', 'b'), ('a', 'a'), ('a', 5)] </code></pre> <p>Should look like this once sorted:</p> <pre><code>[('a', 5), ('a', 'a'), ('A', 'b'), ('a', 'c')] </code></pre> ...
4
2010-03-22T18:26:30Z
2,494,775
<pre><code>list_of_tuples.sort(key=lambda t : tuple(s.lower() if isinstance(s,basestring) else s for s in t)) </code></pre>
2
2010-03-22T18:32:26Z
[ "python", "sorting", "tuples", "case-insensitive" ]
Sort a list of tuples without case sensitivity
2,494,740
<p>How can I efficiently and easily sort a list of tuples <em>without</em> being sensitive to case?</p> <p>For example this:</p> <pre><code>[('a', 'c'), ('A', 'b'), ('a', 'a'), ('a', 5)] </code></pre> <p>Should look like this once sorted:</p> <pre><code>[('a', 5), ('a', 'a'), ('A', 'b'), ('a', 'c')] </code></pre> ...
4
2010-03-22T18:26:30Z
2,494,783
<p>Here's a solution which uses the decorator idea illustrated in the "sorted by keys" section of a Python wiki article (http://wiki.python.org/moin/HowTo/Sorting/).</p> <pre><code># Create a list of new tuples whose first element is lowercase # version of the original tuple. I use an extra function to # handle tuple...
0
2010-03-22T18:33:59Z
[ "python", "sorting", "tuples", "case-insensitive" ]
Sort a list of tuples without case sensitivity
2,494,740
<p>How can I efficiently and easily sort a list of tuples <em>without</em> being sensitive to case?</p> <p>For example this:</p> <pre><code>[('a', 'c'), ('A', 'b'), ('a', 'a'), ('a', 5)] </code></pre> <p>Should look like this once sorted:</p> <pre><code>[('a', 5), ('a', 'a'), ('A', 'b'), ('a', 'c')] </code></pre> ...
4
2010-03-22T18:26:30Z
3,117,759
<p>A simplified version of Paul McGuires works:</p> <pre><code>list_of_tuples.sort(key=lambda t : tuple(t[0].lower())) </code></pre> <p>(where t[0] references which tuple element you want to use, in this case the first)</p>
0
2010-06-25T11:57:51Z
[ "python", "sorting", "tuples", "case-insensitive" ]
Django URL regex question
2,494,821
<p>I had a quick question about Django URL configuration, and I guess REGEX as well. I have a small configuration application that takes in environments and artifacts in the following way:</p> <pre><code>url(r'^env/(?P&lt;env&gt;\w+)/artifact/(?P&lt;artifact&gt;\w+)/$', 'config.views.ipview', name="bothlist"), </code>...
1
2010-03-22T18:38:10Z
2,494,863
<p>I wouldn't put such options into the URL. As you said, these are optional options, they might only change the output. They don't belong in an URL.</p> <p>Your initial regex should match URLs like:</p> <pre><code>/env/&lt;env&gt;/artifact/&lt;artifact&gt;?verbose=1&amp;noformat=1 </code></pre> <p>Imho this is a mu...
9
2010-03-22T18:45:28Z
[ "python", "regex", "django" ]
Displaying a list of items vertically in a table instead of horizonally
2,495,046
<p>I have a list of items sorted alphabetically:</p> <pre><code>mylist = [a,b,c,d,e,f,g,h,i,j] </code></pre> <p>I'm able to output the list in an html table horizonally like so:</p> <pre><code>| a , b , c , d | | e , f , g , h | | i , j , , | </code></pre> <p>What's the algorithm to create the table vertically ...
4
2010-03-22T19:18:41Z
2,495,072
<p>Here's a rough solution that works (prints numbers from 0 to N-1 inclusive):</p> <pre><code>import math NROWS = 3 N = 22 for nr in xrange(NROWS): for nc in xrange(int(math.ceil(1.0 * N/NROWS))): num = nc * NROWS + nr if num &lt; N: print num, print '' </code></pre> <p>This jus...
0
2010-03-22T19:21:56Z
[ "python", "html", "table" ]
Displaying a list of items vertically in a table instead of horizonally
2,495,046
<p>I have a list of items sorted alphabetically:</p> <pre><code>mylist = [a,b,c,d,e,f,g,h,i,j] </code></pre> <p>I'm able to output the list in an html table horizonally like so:</p> <pre><code>| a , b , c , d | | e , f , g , h | | i , j , , | </code></pre> <p>What's the algorithm to create the table vertically ...
4
2010-03-22T19:18:41Z
2,495,103
<pre><code>int array_size = 26; int col_size = 4; for (int i = 0; i &lt;= array_size/col_size; ++i) { for (int j = i; j &lt; array_size; j += col_size-1) { print (a[j]); } print("\n"); } </code></pre>
0
2010-03-22T19:29:51Z
[ "python", "html", "table" ]
Displaying a list of items vertically in a table instead of horizonally
2,495,046
<p>I have a list of items sorted alphabetically:</p> <pre><code>mylist = [a,b,c,d,e,f,g,h,i,j] </code></pre> <p>I'm able to output the list in an html table horizonally like so:</p> <pre><code>| a , b , c , d | | e , f , g , h | | i , j , , | </code></pre> <p>What's the algorithm to create the table vertically ...
4
2010-03-22T19:18:41Z
2,495,133
<pre><code>&gt;&gt;&gt; l = [1,2,3,4,5,6,7,8,9,10] &gt;&gt;&gt; [l[i::3] for i in xrange(3)] [[1, 4, 7, 10], [2, 5, 8], [3, 6, 9]] </code></pre> <p>Replace <code>3</code> by the number of lines you want as a result:</p> <pre><code>&gt;&gt;&gt; [l[i::5] for i in xrange(5)] [[1, 6], [2, 7], [3, 8], [4, 9], [5, 10]] </c...
9
2010-03-22T19:34:15Z
[ "python", "html", "table" ]
Displaying a list of items vertically in a table instead of horizonally
2,495,046
<p>I have a list of items sorted alphabetically:</p> <pre><code>mylist = [a,b,c,d,e,f,g,h,i,j] </code></pre> <p>I'm able to output the list in an html table horizonally like so:</p> <pre><code>| a , b , c , d | | e , f , g , h | | i , j , , | </code></pre> <p>What's the algorithm to create the table vertically ...
4
2010-03-22T19:18:41Z
2,495,145
<p>This is how I'd do it. Given the list of <code>l</code> (of integers, in the example).</p> <ul> <li>Decide the number of columns (or rows) and,</li> <li>Calculate the number of rows (or columns) needed.</li> <li>Then loop through them, row by row and print the corresponding value.</li> </ul> <p>See code below:</p>...
0
2010-03-22T19:36:38Z
[ "python", "html", "table" ]
Displaying a list of items vertically in a table instead of horizonally
2,495,046
<p>I have a list of items sorted alphabetically:</p> <pre><code>mylist = [a,b,c,d,e,f,g,h,i,j] </code></pre> <p>I'm able to output the list in an html table horizonally like so:</p> <pre><code>| a , b , c , d | | e , f , g , h | | i , j , , | </code></pre> <p>What's the algorithm to create the table vertically ...
4
2010-03-22T19:18:41Z
2,495,160
<pre><code>import itertools def grouper(n, iterable, fillvalue=None): # Source: http://docs.python.org/library/itertools.html#recipes "grouper(3, 'ABCDEFG', 'x') --&gt; ABC DEF Gxx" return itertools.izip_longest(*[iter(iterable)]*n,fillvalue=fillvalue) def format_table(L): result=[] for row in L: ...
1
2010-03-22T19:40:55Z
[ "python", "html", "table" ]
Displaying a list of items vertically in a table instead of horizonally
2,495,046
<p>I have a list of items sorted alphabetically:</p> <pre><code>mylist = [a,b,c,d,e,f,g,h,i,j] </code></pre> <p>I'm able to output the list in an html table horizonally like so:</p> <pre><code>| a , b , c , d | | e , f , g , h | | i , j , , | </code></pre> <p>What's the algorithm to create the table vertically ...
4
2010-03-22T19:18:41Z
2,495,979
<pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; L=['a','b','c','d','e','f','g','h','i','j'] &gt;&gt;&gt; width=4 &gt;&gt;&gt; height = (len(L)-1)/width+1 &gt;&gt;&gt; L=L+[' ']*(width*height-len(L)) #Pad to be even multiple of width &gt;&gt;&gt; A = np.array([L]) &gt;&gt;&gt; A.shape=(width,height) &gt;&gt;...
0
2010-03-22T21:41:16Z
[ "python", "html", "table" ]
How to reproduce System.Security.Cryptography.SHA1Managed result in Python
2,495,283
<p>Here's the deal: I'm moving a .NET website to Python. I have a database with passwords hashed using the System.Security.Cryptography.SHA1Managed utility. </p> <p>I'm creating the hash in .NET with the following code:</p> <pre><code>string hashedPassword = Cryptographer.CreateHash("MYHasher", userInfo.Password); </...
0
2010-03-22T19:58:13Z
2,495,413
<p>According to <a href="http://stackoverflow.com/questions/126148/what-is-the-salt-in-enterprise-library-hashprovider-saltenabled-key">this previous thread</a>, this should be something like sha1(password+salt)+salt. SHA-1 output is twenty bytes, so for 48 bytes this should be a 28-byte salt, not an 8-byte salt, unles...
1
2010-03-22T20:18:49Z
[ "c#", ".net", "python", "cryptography" ]
How to reproduce System.Security.Cryptography.SHA1Managed result in Python
2,495,283
<p>Here's the deal: I'm moving a .NET website to Python. I have a database with passwords hashed using the System.Security.Cryptography.SHA1Managed utility. </p> <p>I'm creating the hash in .NET with the following code:</p> <pre><code>string hashedPassword = Cryptographer.CreateHash("MYHasher", userInfo.Password); </...
0
2010-03-22T19:58:13Z
2,498,020
<p>When you use the <code>string CreateHash(string, string)</code> overload, the following occurs:</p> <ol> <li>The string is converted to bytes using UTF16 (using Encoding.Unicode.GetBytes()).</li> <li>A random 16-byte salt is generated.</li> <li>The salt is appended to the converted string and hashed.</li> <li>The s...
1
2010-03-23T06:37:54Z
[ "c#", ".net", "python", "cryptography" ]
How to reproduce System.Security.Cryptography.SHA1Managed result in Python
2,495,283
<p>Here's the deal: I'm moving a .NET website to Python. I have a database with passwords hashed using the System.Security.Cryptography.SHA1Managed utility. </p> <p>I'm creating the hash in .NET with the following code:</p> <pre><code>string hashedPassword = Cryptographer.CreateHash("MYHasher", userInfo.Password); </...
0
2010-03-22T19:58:13Z
27,247,012
<p>Sorry for the late reply, but I've just come across a similar situation while trying to replicate the SHA1 hashing logic used in the Enterprise Library's Cryptography Block, but with using Java.</p> <p>To answer each of your questions:</p> <ol> <li><p><strong>How are the public keys being used?</strong></p> <p>Th...
3
2014-12-02T10:24:27Z
[ "c#", ".net", "python", "cryptography" ]
Writing Strings to files in python
2,495,290
<p>I'm getting the following error when trying to write a string to a file in pythion:</p> <pre><code>Traceback (most recent call last): File "export_off.py", line 264, in execute save_off(self.properties.path, context) File "export_off.py", line 244, in save_off primary.write(file) File "export_off.py",...
3
2010-03-22T19:58:51Z
2,495,320
<p>I see in you comment you mentioned that you did</p> <pre><code>file = open('xxx.xxx' ,'wb') </code></pre> <p>That means you're opening the file to write in binary (so just leave out the <code>b</code> flag).</p>
1
2010-03-22T20:02:16Z
[ "python", "string", "file", "io", "python-3.x" ]
Writing Strings to files in python
2,495,290
<p>I'm getting the following error when trying to write a string to a file in pythion:</p> <pre><code>Traceback (most recent call last): File "export_off.py", line 264, in execute save_off(self.properties.path, context) File "export_off.py", line 244, in save_off primary.write(file) File "export_off.py",...
3
2010-03-22T19:58:51Z
2,495,325
<p>I'm not seeing you open the file first:</p> <pre><code>file_handler = open(path) file_handler.write(string) file_handler.close() </code></pre>
2
2010-03-22T20:03:41Z
[ "python", "string", "file", "io", "python-3.x" ]
Writing Strings to files in python
2,495,290
<p>I'm getting the following error when trying to write a string to a file in pythion:</p> <pre><code>Traceback (most recent call last): File "export_off.py", line 264, in execute save_off(self.properties.path, context) File "export_off.py", line 244, in save_off primary.write(file) File "export_off.py",...
3
2010-03-22T19:58:51Z
2,495,327
<p>What version of Python are you using? In Python 3.x a string contains Unicode text in no particular encoding. To write it out to a stream of bytes (a file) you must convert it to a byte encoding such as UTF-8, UTF-16, and so on. Fortunately this is easily done with the <code>encode()</code> method:</p> <pre><code>P...
13
2010-03-22T20:04:46Z
[ "python", "string", "file", "io", "python-3.x" ]
Writing Strings to files in python
2,495,290
<p>I'm getting the following error when trying to write a string to a file in pythion:</p> <pre><code>Traceback (most recent call last): File "export_off.py", line 264, in execute save_off(self.properties.path, context) File "export_off.py", line 244, in save_off primary.write(file) File "export_off.py",...
3
2010-03-22T19:58:51Z
2,495,347
<p>I suspect you are using Python 3 and have opened the file in binary mode, which will only accept bytes or buffers to be written into it.</p> <p>Any chance we could see the code that opens up the file for writing?</p> <hr> <p><strong>edit:</strong> Looks like that is indeed the culprit.</p>
5
2010-03-22T20:08:43Z
[ "python", "string", "file", "io", "python-3.x" ]
Writing Strings to files in python
2,495,290
<p>I'm getting the following error when trying to write a string to a file in pythion:</p> <pre><code>Traceback (most recent call last): File "export_off.py", line 264, in execute save_off(self.properties.path, context) File "export_off.py", line 244, in save_off primary.write(file) File "export_off.py",...
3
2010-03-22T19:58:51Z
2,495,358
<p>How did you open the file ?</p> <p>According to the error message, I'll guess :</p> <pre><code>f = open("file", "wb") # b for binary mode </code></pre> <p>If you want to use strings, you must use :</p> <pre><code>f = open("file", "w") </code></pre> <p>If you use "b", files will expect binary data, and you are ...
0
2010-03-22T20:10:05Z
[ "python", "string", "file", "io", "python-3.x" ]
Help finding longest non-repeating path through connected nodes - Python
2,495,306
<p>I've been working on this for a couple of days now without success. Basically, I have a bunch of nodes arranged in a 2D matrix. Every node has four neighbors, except for the nodes on the sides and corners of the matrix, which have 3 and 2 neighbors, respectively. Imagine a bunch of square cards laid out side by side...
1
2010-03-22T20:00:48Z
2,495,401
<p>Brute force method:</p> <ol> <li><p>Create a depth first connected list. Store List L and its Length T.</p></li> <li><p>For each connection of this list:</p> <ul> <li>Push Whole Diagram</li> <li>Delete connection.</li> <li>Create a depth first connected list.</li> <li>If list is longer than T: set T to length and ...
0
2010-03-22T20:16:24Z
[ "python", "pygame" ]
Help finding longest non-repeating path through connected nodes - Python
2,495,306
<p>I've been working on this for a couple of days now without success. Basically, I have a bunch of nodes arranged in a 2D matrix. Every node has four neighbors, except for the nodes on the sides and corners of the matrix, which have 3 and 2 neighbors, respectively. Imagine a bunch of square cards laid out side by side...
1
2010-03-22T20:00:48Z
2,495,462
<p>You do know the <a href="http://en.wikipedia.org/wiki/Longest_path_problem" rel="nofollow">longest path problem</a> in a graph with cycles is NP-hard?</p>
6
2010-03-22T20:26:09Z
[ "python", "pygame" ]
Help finding longest non-repeating path through connected nodes - Python
2,495,306
<p>I've been working on this for a couple of days now without success. Basically, I have a bunch of nodes arranged in a 2D matrix. Every node has four neighbors, except for the nodes on the sides and corners of the matrix, which have 3 and 2 neighbors, respectively. Imagine a bunch of square cards laid out side by side...
1
2010-03-22T20:00:48Z
2,495,880
<blockquote> <p>...Romania has been added to the processed_countries list by Ukraine. </p> </blockquote> <p>Use separate processed_countries lists for each graph path. They say one code example is worth thousand words, so I've changed your code a little (untested):</p> <pre><code>def get_longest_trip(self, board, p...
2
2010-03-22T21:27:17Z
[ "python", "pygame" ]
Python or Ruby for webbased Artificial Intelligence?
2,495,350
<p>A new web application may require adding Artificial Intelligence (AI) in the future, e.g. using ProLog. I know it can be done from a Java environment, but I am wondering about the opportunities with modern web languages like Ruby or Python. The latter is considered to be "more scientific" (at least used in that envi...
4
2010-03-22T20:09:21Z
2,495,421
<p>If you used <a href="http://jruby.org/" rel="nofollow">JRuby</a> or <a href="http://www.jython.org/" rel="nofollow">Jython</a> you can make use of the existing Java libraries and use either Ruby or Python for the web app. Rails works on JRuby and I have used it to write apps that reuse existing Java code. Not sure o...
0
2010-03-22T20:19:40Z
[ "python", "ruby-on-rails", "artificial-intelligence", "prolog" ]
Python or Ruby for webbased Artificial Intelligence?
2,495,350
<p>A new web application may require adding Artificial Intelligence (AI) in the future, e.g. using ProLog. I know it can be done from a Java environment, but I am wondering about the opportunities with modern web languages like Ruby or Python. The latter is considered to be "more scientific" (at least used in that envi...
4
2010-03-22T20:09:21Z
2,496,553
<p>You might also find <a href="http://pyke.sourceforge.net/" rel="nofollow">PyKE</a> useful.</p> <p>Edit:</p> <blockquote> <p>"Pyke introduces a form of Logic Programming (inspired by Prolog) to the Python community by providing a knowledge-based inference engine (expert system) written in 100% Python.</p> ...
0
2010-03-22T23:43:15Z
[ "python", "ruby-on-rails", "artificial-intelligence", "prolog" ]
Python or Ruby for webbased Artificial Intelligence?
2,495,350
<p>A new web application may require adding Artificial Intelligence (AI) in the future, e.g. using ProLog. I know it can be done from a Java environment, but I am wondering about the opportunities with modern web languages like Ruby or Python. The latter is considered to be "more scientific" (at least used in that envi...
4
2010-03-22T20:09:21Z
2,497,026
<p>The selection of language is completely irrelevant, all other things being equal.</p> <p>If you're trying to do X and there's a library for it in language Y and meshes well with your Web-based framework, then use it.</p> <p>Without knowing more about what specific areas of AI you're interested in, the question is ...
8
2010-03-23T01:46:14Z
[ "python", "ruby-on-rails", "artificial-intelligence", "prolog" ]
Python or Ruby for webbased Artificial Intelligence?
2,495,350
<p>A new web application may require adding Artificial Intelligence (AI) in the future, e.g. using ProLog. I know it can be done from a Java environment, but I am wondering about the opportunities with modern web languages like Ruby or Python. The latter is considered to be "more scientific" (at least used in that envi...
4
2010-03-22T20:09:21Z
2,498,323
<p>You could also use Scala (which is a bit functional and runs on the JVW) and the existing Lift framework for web-stuff.</p>
0
2010-03-23T08:00:32Z
[ "python", "ruby-on-rails", "artificial-intelligence", "prolog" ]
Python or Ruby for webbased Artificial Intelligence?
2,495,350
<p>A new web application may require adding Artificial Intelligence (AI) in the future, e.g. using ProLog. I know it can be done from a Java environment, but I am wondering about the opportunities with modern web languages like Ruby or Python. The latter is considered to be "more scientific" (at least used in that envi...
4
2010-03-22T20:09:21Z
6,489,161
<p>If you like <a href="http://en.wikipedia.org/wiki/Prolog" rel="nofollow">Prolog</a>, then check out <a href="http://code.google.com/p/pyswip/" rel="nofollow">PySWIP</a>. It integrates the declarative logic language Prolog with the procedural general purpose language Python, which lets you write webapps procedurally ...
1
2011-06-27T06:04:51Z
[ "python", "ruby-on-rails", "artificial-intelligence", "prolog" ]
pyenchant RPM for alt-install of python2.6. ELF class error
2,495,428
<p>I know what my problem is with this issue, but I'm a little confused about how to best go about fixing it.</p> <p>I have a RHEL 5.4 system, with Python2.6 alt-installed (via the geekymedia RPMS). everything seems to be working. As I tweak a spec file, I'm able to build out RPMs to work with this new Python instal...
0
2010-03-22T20:20:12Z
2,512,643
<p>Just in case someone else runs into this:</p> <ol> <li>I removed the RHEL versions of enchant</li> <li>downloaded the RHEL source RPM for enchant (same version)</li> <li>built my own 64-bit only RPM for enchant</li> <li>installed that</li> </ol> <p>my Py2.6 altinstall python-enchant package now works.</p>
1
2010-03-25T01:43:30Z
[ "python", "install", "pyenchant" ]
Number Sequence in MySQL
2,495,487
<p>In Python if I wanted a sequence from 0 - 9 (inclusive) I would use xrange(0,10) . Is there a way I can do this in MySQL?</p>
1
2010-03-22T20:30:08Z
2,495,534
<p>You can use LAST_INSERT_ID() to simulate sequences in MySQL.</p> <blockquote> <p>If expr is given as an argument to LAST_INSERT_ID(), the value of the argument is returned by the function and is remembered as the next value to be returned by LAST_INSERT_ID(). This can be used to simulate sequences:</p> ...
0
2010-03-22T20:36:49Z
[ "python", "sql", "mysql", "sequence", "xrange" ]
Number Sequence in MySQL
2,495,487
<p>In Python if I wanted a sequence from 0 - 9 (inclusive) I would use xrange(0,10) . Is there a way I can do this in MySQL?</p>
1
2010-03-22T20:30:08Z
2,495,567
<p>Try an <a href="http://searchoracle.techtarget.com/answer/The-integers-table" rel="nofollow">integers table</a> variant. This one is taken from <a href="http://www.xaprb.com/blog/2005/12/07/the-integers-table/" rel="nofollow">Xaprb</a>:</p> <pre><code>create table integers(i int unsigned not null); insert into int...
0
2010-03-22T20:41:10Z
[ "python", "sql", "mysql", "sequence", "xrange" ]
Number Sequence in MySQL
2,495,487
<p>In Python if I wanted a sequence from 0 - 9 (inclusive) I would use xrange(0,10) . Is there a way I can do this in MySQL?</p>
1
2010-03-22T20:30:08Z
2,495,631
<p>If Python is your programming language, you can map that same Python range to create an INSERT statement of the form:</p> <pre><code>INSERT INTO Table (IDCol) VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9) </code></pre> <p>Not exactly what you asked for, but a single line of Python code that will handle any ra...
0
2010-03-22T20:50:23Z
[ "python", "sql", "mysql", "sequence", "xrange" ]
Number Sequence in MySQL
2,495,487
<p>In Python if I wanted a sequence from 0 - 9 (inclusive) I would use xrange(0,10) . Is there a way I can do this in MySQL?</p>
1
2010-03-22T20:30:08Z
2,514,498
<p>Since there is no such thing as xrange, one could use a separate table stored with integer (as previously answered), or just make a stored procedure to do the job:</p> <pre><code>DROP PROCEDURE IF EXISTS xrange; DELIMITER // CREATE PROCEDURE xrange(x INT, y INT) BEGIN DECLARE i INT DEFAULT x; CREATE TEMPORARY T...
2
2010-03-25T09:59:26Z
[ "python", "sql", "mysql", "sequence", "xrange" ]
Python.expat can't parse XML file with bad symbols. How to go around?
2,495,538
<p>I'm trying to parse an XML file (OSM data) with expat, and there are lines with some Unicode characters that expat can't parse:</p> <pre><code>&lt;tag k="name" v="абвгдежзиклмнопр�?туфхцчшщьыъ�?ю�?�?БВГДЕЖЗИКЛМ�?ОПРСТУФХЦЧШЩЬЫЪЭЮЯ" /&gt; &lt;tag k=...
0
2010-03-22T20:37:12Z
2,496,922
<p>Not sure if '�' characters were introduced by copy-pasting string here, but if you have them in original data, then it seems to be generator problem which introduced \uFFFD charactes as:</p> <p>"used to replace an incoming character whose value is unknown or unrepresentable in Unicode"</p> <p>citied from: <a hre...
1
2010-03-23T01:17:05Z
[ "python", "xml", "unicode", "expat-parser" ]
Variable alpha blending in pylab
2,495,656
<p>How does one control the transparency over a 2D image in pylab? I'd like to give two sets of values <code>(X,Y,Z,T)</code> where <code>X,Y</code> are arrays of positions, <code>Z</code> is the color value, and <code>T</code> is the transparency to a function like <code>imshow</code> but it seems that the function on...
7
2010-03-22T20:52:46Z
2,495,884
<p>One thing that you can do is modify what you put into imshow. The first variable can be grayscale values as you have used or it can be RGB or RGBA values. If you RGB/RGBA values then the cmap is ignored. So for instance,</p> <pre><code>imshow(Z1, cmap=cm.hsv, alpha=.6, extent=extent) </code></pre> <p>will generate...
7
2010-03-22T21:27:34Z
[ "python", "alphablending", "matplotlib" ]
SelfReferenceProperty vs. ListProperty Google App Engine
2,495,709
<p>I am experimenting with the Google App Engine and have a question. </p> <p>For the sake of simplicity, let's say my app is modeling a computer network (a fairly large corporate network with 10,000 nodes). I am trying to model my Node class as follows:</p> <pre><code>class Node(db.Model): name = db.StringProper...
2
2010-03-22T21:01:34Z
2,496,574
<p>Re 1, yes (if I understand correctly what you're asking): for each property in a model, each instance of the model (AKA "entity") has <em>one</em> value for that property. So e.g. an <code>IntegerProperty</code> has <em>one</em> integer value for a given entity, a <code>SelfReferenceProperty</code> has <em>one</em>...
1
2010-03-22T23:48:45Z
[ "python", "google-app-engine" ]
Filtering documents against a dictionary key in MongoDB
2,495,932
<p>I have a collection of articles in MongoDB that has the following structure:</p> <pre><code>{ 'category': 'Legislature', 'updated': datetime.datetime(2010, 3, 19, 15, 32, 22, 107000), 'byline': None, 'tags': { 'party': ['Peter Hoekstra', 'Virg Bernero', 'Alma Smith', 'Mike Bouchard', 'Tom...
3
2010-03-22T21:33:50Z
2,496,018
<p>If the "geography" field doesn't exist when there aren't any tags in it (i.e., it's created when you add a location), you could do:</p> <pre><code>db.articles.find({tags.geography : {$exists : true}}) </code></pre> <p>If it does exists and is empty (i.e., <code>"geography" : []</code>) you should add a <code>geogr...
7
2010-03-22T21:48:51Z
[ "python", "mongodb", "pymongo" ]
Django - provide additional information in template
2,495,985
<p>I am building an app to learn Django and have started with a Contact system that currently stores Contacts and Addresses. C's are a many to many relationship with A's, but rather than use Django's <code>models.ManyToManyField()</code> I've created my own link-table providing additional information about the link, su...
2
2010-03-22T21:42:16Z
2,496,021
<p>In order to add extra information, you should use a ManyToMany relationship with a 'trough' extra-field : <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-rela...
3
2010-03-22T21:49:11Z
[ "python", "django", "django-templates", "django-views" ]
Exception_Record in python2.5 problem
2,496,258
<p>I'm using Python2.5 &amp; the following code produce 2 errors. Can any body help me?</p> <pre><code>class EXCEPTION_RECORD(Structure): _fields_ = [ ("ExceptionCode", DWORD), ("ExceptionFlags", DWORD), ("ExceptionRecord", POINTER(EXCEPTION_RECORD)), ("ExceptionAddress", LPVOID), ...
1
2010-03-22T22:35:48Z
2,496,289
<p>Apparently, you can't refer to a class type while defining a class, e.g.:</p> <pre><code>&gt;&gt;&gt; class C: f = C Traceback (most recent call last): File "&lt;pyshell#17&gt;", line 1, in &lt;module&gt; class C: File "&lt;pyshell#17&gt;", line 2, in C f = C NameError: name 'C' is not defined </...
2
2010-03-22T22:44:03Z
[ "python", "winapi" ]
Exception_Record in python2.5 problem
2,496,258
<p>I'm using Python2.5 &amp; the following code produce 2 errors. Can any body help me?</p> <pre><code>class EXCEPTION_RECORD(Structure): _fields_ = [ ("ExceptionCode", DWORD), ("ExceptionFlags", DWORD), ("ExceptionRecord", POINTER(EXCEPTION_RECORD)), ("ExceptionAddress", LPVOID), ...
1
2010-03-22T22:35:48Z
2,496,362
<p>A class can reference itself in the <code>__new__</code> or <code>__init__</code> methods.</p> <pre><code>class Test(object): def __new__(cls): inst = object.__new__(cls) inst.me = Test return inst </code></pre> <p>or:</p> <pre><code>class Test(object): def __init__(self): ...
0
2010-03-22T22:58:48Z
[ "python", "winapi" ]
Exception_Record in python2.5 problem
2,496,258
<p>I'm using Python2.5 &amp; the following code produce 2 errors. Can any body help me?</p> <pre><code>class EXCEPTION_RECORD(Structure): _fields_ = [ ("ExceptionCode", DWORD), ("ExceptionFlags", DWORD), ("ExceptionRecord", POINTER(EXCEPTION_RECORD)), ("ExceptionAddress", LPVOID), ...
1
2010-03-22T22:35:48Z
2,496,513
<p>Looks like you've done a <code>from ctypes import *</code> (terrible practice, as one is reduced to guess where all those identifiers like <code>DWORD</code> are actually coming from!-) but missed a crucial short passage in <a href="http://docs.python.org/library/ctypes.html#ctypes.Structure" rel="nofollow">ctypes.S...
2
2010-03-22T23:33:05Z
[ "python", "winapi" ]
Pylons error "No object (name: request) has been registered for this thread" with debug = false
2,496,347
<p>I'm unable to access the <code>request</code> object in my Pylons 0.9.7 controller when I set <code>debug = false</code> in the .ini file. I have the following code:</p> <pre><code>def run_something(self): print('!!! request = %r' % request) print('!!! request.params = %r' % request.params) yield 'Stuff...
0
2010-03-22T22:55:24Z
2,503,383
<p>You should not yield from action directly. Try making inner function and returning func():</p> <pre><code>def run_something(self): request = pylons.request._current_obj() def func(): print('!!! request = %r' % request) print('!!! request.params = %r' % request.params) yield 'Stuff' ...
2
2010-03-23T20:32:38Z
[ "python", "debugging", "pylons" ]