title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
Django payment proccessing
772,240
<p>Can anyone suggest any good payment processing libraries for python/django?</p>
22
2009-04-21T12:05:31Z
850,508
<p>Django paypal is very cool. I've used in on couple of my projects. It is relatively easy to integrate with an existing website. Satchmo is good, if you want a full internet store, but if you want to sell just couple items from your website, which is devoted to something else, you will find Satchmo to be very heavy ...
2
2009-05-11T23:22:33Z
[ "python", "django" ]
Django payment proccessing
772,240
<p>Can anyone suggest any good payment processing libraries for python/django?</p>
22
2009-04-21T12:05:31Z
3,851,479
<p>There is <a href="http://github.com/emesik/mamona" rel="nofollow">Django payments application called Mamona</a> which currently supports only PayPal. It can be used with any existing application without changing it's code. Basically, it can use <strong>any exiting model</strong> as order.</p>
3
2010-10-03T20:27:59Z
[ "python", "django" ]
Django payment proccessing
772,240
<p>Can anyone suggest any good payment processing libraries for python/django?</p>
22
2009-04-21T12:05:31Z
5,317,978
<p>You may want to take a look at <a href="https://github.com/bkeating/python-payflowpro/" rel="nofollow">https://github.com/bkeating/python-payflowpro/</a> which isn't django-specific but works nicely with it or in plain ole python.</p>
0
2011-03-15T20:58:39Z
[ "python", "django" ]
Django payment proccessing
772,240
<p>Can anyone suggest any good payment processing libraries for python/django?</p>
22
2009-04-21T12:05:31Z
13,676,998
<p>I created Paython: <a href="https://github.com/abunsen/Paython" rel="nofollow">https://github.com/abunsen/Paython</a></p> <p>Supports a few different processors:</p> <ol> <li>Stripe</li> <li>Authorize.net</li> <li>First Data / Linkpoint</li> <li>Innovative Gateway (from intuit)</li> <li>Plugnpay</li> <li>Samurai</...
0
2012-12-03T04:10:03Z
[ "python", "django" ]
Oracle / Python Converting to string -> HEX (for RAW column) -> varchar2
772,518
<p>I have a table with a RAW column for holding an encrypted string.</p> <p>I have the PL/SQL code for encrypting from plain text into this field.</p> <p>I wish to create a trigger containg the encryption code.</p> <p>I wish to 'misuse' the RAW field to pass the plain text into the trigger. (I can't modify the schem...
1
2009-04-21T13:12:06Z
772,611
<p>Do you have to encode to hex?</p> <p>I think there is a package (<a href="http://download.oracle.com/docs/cd/B19306%5F01/appdev.102/b14258/u%5Fencode.htm" rel="nofollow">utl_encode</a>) available for PL/SQL to decode Base64 for instance, you could use that? </p>
2
2009-04-21T13:34:03Z
[ "python", "oracle" ]
How to create a password protected zipfile with python?
772,814
<p>Since python2.6, it's now easier to extract data from a password protected zip. But how to create a password protected zipfile in pure python ?</p>
3
2009-04-21T14:20:48Z
772,842
<p>I've looked for this in the past and been unsuccessful. (I'd love to see a solution get posted!)</p> <p>One option is a commercial package from chilkatsoft that will do this, but at $150. Makes sense if you are doing a commercial app, but tough to swallow otherwise.</p> <p>I wound up calling out to the system fo...
3
2009-04-21T14:26:39Z
[ "python", "zip" ]
Why are 0d arrays in Numpy not considered scalar?
773,030
<p>Surely a 0d array is scalar, but Numpy does not seem to think so... am I missing something or am I just misunderstanding the concept? </p> <pre><code>&gt;&gt;&gt; foo = numpy.array(1.11111111111, numpy.float64) &gt;&gt;&gt; numpy.ndim(foo) 0 &gt;&gt;&gt; numpy.isscalar(foo) False &gt;&gt;&gt; foo.item() 1.111111111...
41
2009-04-21T15:02:51Z
773,125
<p>You have to create the scalar array a little bit differently:</p> <pre><code>&gt;&gt;&gt; x = numpy.float64(1.111) &gt;&gt;&gt; x 1.111 &gt;&gt;&gt; numpy.isscalar(x) True &gt;&gt;&gt; numpy.ndim(x) 0 </code></pre> <p>It looks like <a href="http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html" rel="nofoll...
4
2009-04-21T15:20:27Z
[ "python", "numpy" ]
Why are 0d arrays in Numpy not considered scalar?
773,030
<p>Surely a 0d array is scalar, but Numpy does not seem to think so... am I missing something or am I just misunderstanding the concept? </p> <pre><code>&gt;&gt;&gt; foo = numpy.array(1.11111111111, numpy.float64) &gt;&gt;&gt; numpy.ndim(foo) 0 &gt;&gt;&gt; numpy.isscalar(foo) False &gt;&gt;&gt; foo.item() 1.111111111...
41
2009-04-21T15:02:51Z
794,812
<p>One should not think too hard about it. It's ultimately better for the mental health and longevity of the individual.</p> <p>The curious situation with Numpy scalar-types was bore out of the fact that there is no graceful and consistent way to degrade the 1x1 matrix to scalar types. Even though mathematically they ...
76
2009-04-27T18:55:32Z
[ "python", "numpy" ]
Updating tkinter labels in python
773,797
<p>I'm working on giving a python server a GUI with tkinter by passing the Server's root instance to the Tkinter window. The problem is in keeping information in the labels up to date.</p> <p>For instance, the server has a Users list, containing the users that are logged on. It's simple enough to do this for an initia...
2
2009-04-21T17:54:18Z
773,846
<p>You could use callbacks on the server instance. Install a callback that updates the label whenever the user-list changes.</p> <p>If you can't change the server code, you would need to poll the list for updates every few seconds. You could use the Tkinter event system to keep track of the updates.</p> <pre><code>de...
3
2009-04-21T18:06:49Z
[ "python", "tkinter" ]
Updating tkinter labels in python
773,797
<p>I'm working on giving a python server a GUI with tkinter by passing the Server's root instance to the Tkinter window. The problem is in keeping information in the labels up to date.</p> <p>For instance, the server has a Users list, containing the users that are logged on. It's simple enough to do this for an initia...
2
2009-04-21T17:54:18Z
790,423
<p>You change the text of a <code>Label</code> by setting the text of its corresponding <code>StringVar</code> object, for example:</p> <pre><code>from tkinter import * root = Tk() string = StringVar() lab = Label(root, textvariable=string) lab.pack() string.set('Changing the text displayed in the Label') root.mainlo...
2
2009-04-26T07:35:22Z
[ "python", "tkinter" ]
Plot logarithmic axes with matplotlib in python
773,814
<p>I want to plot a graph with one logarithmic axis using matplotlib. </p> <p>I've been reading the docs, but can't figure out the syntax. I know that it's probably something simple like 'scale=linear' in the plot arguments, but I can't seem to get it right</p> <p>Sample program: </p> <pre><code>from pylab import * ...
188
2009-04-21T18:00:26Z
773,850
<p>You simply need to use <a href="http://matplotlib.sourceforge.net/api/pyplot%5Fapi.html#matplotlib.pyplot.semilogy">semilogy</a> instead of plot:</p> <pre><code>from pylab import * import matplotlib.pyplot as pyplot a = [ pow(10,i) for i in range(10) ] fig = pyplot.figure() ax = fig.add_subplot(2,1,1) line, = ax....
48
2009-04-21T18:07:42Z
[ "python", "matplotlib", "scale", "logarithm" ]
Plot logarithmic axes with matplotlib in python
773,814
<p>I want to plot a graph with one logarithmic axis using matplotlib. </p> <p>I've been reading the docs, but can't figure out the syntax. I know that it's probably something simple like 'scale=linear' in the plot arguments, but I can't seem to get it right</p> <p>Sample program: </p> <pre><code>from pylab import * ...
188
2009-04-21T18:00:26Z
1,183,415
<p>You can use the <a href="http://matplotlib.sourceforge.net/api/axes%5Fapi.html#matplotlib.axes.Axes.set%5Fyscale">Axes.set_yscale</a> method. That allows you to change the scale after the Axes object is created. That would also allow you to build a control to let the user pick the scale if you needed to.</p> <p>The...
201
2009-07-26T00:14:42Z
[ "python", "matplotlib", "scale", "logarithm" ]
Plot logarithmic axes with matplotlib in python
773,814
<p>I want to plot a graph with one logarithmic axis using matplotlib. </p> <p>I've been reading the docs, but can't figure out the syntax. I know that it's probably something simple like 'scale=linear' in the plot arguments, but I can't seem to get it right</p> <p>Sample program: </p> <pre><code>from pylab import * ...
188
2009-04-21T18:00:26Z
3,513,577
<p>First of all, it's not very tidy to mix <code>pylab</code> and <code>pyplot</code> code. What's more, <a href="http://matplotlib.org/faq/usage_faq.html#matplotlib-pyplot-and-pylab-how-are-they-related">pyplot style is preferred over using pylab</a>.</p> <p>Here is a slightly cleaned up code, using only <code>pyplot...
175
2010-08-18T15:10:32Z
[ "python", "matplotlib", "scale", "logarithm" ]
Plot logarithmic axes with matplotlib in python
773,814
<p>I want to plot a graph with one logarithmic axis using matplotlib. </p> <p>I've been reading the docs, but can't figure out the syntax. I know that it's probably something simple like 'scale=linear' in the plot arguments, but I can't seem to get it right</p> <p>Sample program: </p> <pre><code>from pylab import * ...
188
2009-04-21T18:00:26Z
22,945,052
<p>I know this is slightly off-topic, since some comments mentioned the <code>ax.set_yscale('log')</code> to be "nicest" solution I thought a rebuttal could be due. I would not recommend using <code>ax.set_yscale('log')</code> for histograms and bar plots. In my version (0.99.1.1) i run into some rendering problems - n...
5
2014-04-08T18:14:47Z
[ "python", "matplotlib", "scale", "logarithm" ]
Python +sockets
773,869
<p>i have to create connecting server&lt;=>client. I use this code: Server:</p> <pre><code>import socket HOST = 'localhost' PORT = 50007 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr while 1: data = conn.recv(1024) ...
5
2009-04-21T18:12:19Z
773,920
<p>The question is a little confusing, but I will try to help out. Basically, if the port (50007) is blocked on the server machine by a firewall, you will NOT be able to make a tcp connection to it from the client. That is the purpose of the firewall. A lot of protocols (SIP and bittorrent for example) do use firewall ...
7
2009-04-21T18:21:56Z
[ "python", "sockets", "ports" ]
Python +sockets
773,869
<p>i have to create connecting server&lt;=>client. I use this code: Server:</p> <pre><code>import socket HOST = 'localhost' PORT = 50007 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr while 1: data = conn.recv(1024) ...
5
2009-04-21T18:12:19Z
773,939
<p>Very difficult to understand your question...</p> <blockquote> <p>(...) Torrent-clients do it somehow.</p> </blockquote> <p>The Torrent-clients can do this only when the router -- Internet gateway device (IGD) -- supports the <a href="http://en.wikipedia.org/wiki/Universal%5FPlug%5Fand%5FPlay" rel="nofollow">uPN...
2
2009-04-21T18:26:43Z
[ "python", "sockets", "ports" ]
SFTP listing directory
774,039
<p>I'm trying to make a connection to a secure sftp site, however I'm not able to list the directory,however, it's possible to connect using python "expect" or php"ssh2_connect" but it gives me the following mesg: Received disconnect from xx.xx.xx.</p> <p>If I use a GUI appliction like winscp I'm able to go to the sft...
0
2009-04-21T18:49:03Z
774,195
<p>You can do this easily with <a href="http://www.lag.net/paramiko" rel="nofollow">paramiko</a>, checkout <a href="http://commandline.org.uk/python/sftp-python/" rel="nofollow">SFTP with Python</a></p>
3
2009-04-21T19:25:30Z
[ "php", "python", "sftp" ]
Business rules for calculating prices
774,245
<p>The business I work for is an on-line retailer, I'm currently working on a project that among other things involves calculating the customer prices for products. We will probably create a service that looks something like...</p> <pre><code>public interface IPriceService { decimal CalculateCustomerPrice(ISupplierP...
0
2009-04-21T19:34:36Z
774,289
<p>It definitely sounds like a sane idea to me. You can trivially access CLR internals (objects and return values) from IronPython, I don't know about IronRuby. Chapters 1 and 7 of <a href="http://www.ironpythoninaction.com" rel="nofollow">IronPython in Action</a> are available online and would probably be helpful. ...
1
2009-04-21T19:43:49Z
[ "python", "ruby", "scripting", "rules", "dynamic-language-runtime" ]
Python difflib: highlighting differences inline?
774,316
<p>When comparing similar lines, I want to highlight the differences on the same line:</p> <pre><code>a) lorem ipsum dolor sit amet b) lorem foo ipsum dolor amet lorem &lt;ins&gt;foo&lt;/ins&gt; ipsum dolor &lt;del&gt;sit&lt;/del&gt; amet </code></pre> <p>While difflib.HtmlDiff appears to do this sort of inline high...
15
2009-04-21T19:57:32Z
774,338
<p><a href="http://docs.python.org/library/difflib.html#sequencematcher-objects" rel="nofollow">difflib.SequenceMatcher</a> will operate on single lines. You can use the "opcodes" to determine how to change the first line to make it the second line.</p>
2
2009-04-21T20:04:02Z
[ "python", "diff" ]
Python difflib: highlighting differences inline?
774,316
<p>When comparing similar lines, I want to highlight the differences on the same line:</p> <pre><code>a) lorem ipsum dolor sit amet b) lorem foo ipsum dolor amet lorem &lt;ins&gt;foo&lt;/ins&gt; ipsum dolor &lt;del&gt;sit&lt;/del&gt; amet </code></pre> <p>While difflib.HtmlDiff appears to do this sort of inline high...
15
2009-04-21T19:57:32Z
788,780
<p>For your simple example:</p> <pre><code>import difflib def show_diff(seqm): """Unify operations between two compared strings seqm is a difflib.SequenceMatcher instance whose a &amp; b are strings""" output= [] for opcode, a0, a1, b0, b1 in seqm.get_opcodes(): if opcode == 'equal': ou...
28
2009-04-25T12:05:12Z
[ "python", "diff" ]
Python scripted mp3 database, with a php front end
774,502
<p>So, here's the deal. I am attempting to write a quick python script that reads the basic id3 tags from an mp3 (artist, album, songname, genre, etc). The python script will use most likely the mutagen library (unless you know of a better one). I'm not sure how to recursively scan through a directory to get each mp...
2
2009-04-21T20:44:08Z
774,547
<p>To get started with extracting ID3 tags in Python, there's a module for that.</p> <pre><code>from ID3 import ID3 mp3_filepath = r'/music/song.mp3' id3_data = ID3(mp3_filepath) print 'Artist:', id3_data['ARTIST'] print 'Title:', id3_data['TITLE'] </code></pre> <p><a href="http://id3-py.sourceforge.net/" rel="nofol...
4
2009-04-21T20:53:35Z
[ "php", "python", "database", "mp3", "id3" ]
Is it possible to overload ++ operators in Python?
774,784
<p>Is it possible to overload ++ operators in Python?</p>
0
2009-04-21T21:49:16Z
774,791
<p>Nope, it is not possible to overload the unary ++ operator, because it is not an operator at all in Python.</p> <p>Only (a subset of) the operators that are allowed by the Python syntax (those operators that already have one or more uses in the language) may be overloaded.</p> <p><a href="http://docs.python.org/re...
16
2009-04-21T21:51:54Z
[ "python", "operator-overloading" ]
Is it possible to overload ++ operators in Python?
774,784
<p>Is it possible to overload ++ operators in Python?</p>
0
2009-04-21T21:49:16Z
774,792
<p>There is no <code>++</code> operator in Python (nor '--'). Incrementing is usually done with the <code>+=</code> operator instead.</p>
17
2009-04-21T21:52:13Z
[ "python", "operator-overloading" ]
Is it possible to overload ++ operators in Python?
774,784
<p>Is it possible to overload ++ operators in Python?</p>
0
2009-04-21T21:49:16Z
774,794
<p>Well, the ++ operator doesn't exist in Python, so you really can't overload it.</p> <p>What happens when you do something like:</p> <pre>1 ++ 2</pre> <p>is actually</p> <pre>1 + (+2)</pre>
5
2009-04-21T21:53:05Z
[ "python", "operator-overloading" ]
Is it possible to overload ++ operators in Python?
774,784
<p>Is it possible to overload ++ operators in Python?</p>
0
2009-04-21T21:49:16Z
774,843
<p>Everyone makes good points, I'd just like to clear up one other thing. Open up a Python interpreter and check this out:</p> <pre><code>&gt;&gt;&gt; i = 1 &gt;&gt;&gt; ++i 1 &gt;&gt;&gt; i 1 </code></pre> <p>There is no ++ (or --) operator in Python. The reason it behaves as it did (instead of a syntax error) is th...
7
2009-04-21T22:05:23Z
[ "python", "operator-overloading" ]
Is it possible to overload ++ operators in Python?
774,784
<p>Is it possible to overload ++ operators in Python?</p>
0
2009-04-21T21:49:16Z
1,197,174
<p>You could hack it, though this introduces some undesirable consequences:</p> <pre><code>class myint_plus: def __init__(self,myint_instance): self.myint_instance = myint_instance def __pos__(self): self.myint_instance.i += 1 return self.myint_instance class myint: def __init__(s...
5
2009-07-28T22:49:21Z
[ "python", "operator-overloading" ]
Explain Python entry points?
774,824
<p>I've read the documentation on egg entry points in Pylons and on the Peak pages, and I still don't really understand. Could someone explain them to me, or point me at an article or book that does?</p>
107
2009-04-21T21:59:55Z
774,859
<p>From abstract point of view, entry points are used to create a system-wide registry of Python callables that implement certain interfaces. There are APIs in pkg_resources to see which entry points are advertised by a given package as well as APIs to determine which packages advertise a certain entry point.</p> <p>...
16
2009-04-21T22:10:16Z
[ "python", "setuptools" ]
Explain Python entry points?
774,824
<p>I've read the documentation on egg entry points in Pylons and on the Peak pages, and I still don't really understand. Could someone explain them to me, or point me at an article or book that does?</p>
107
2009-04-21T21:59:55Z
782,984
<p>An "entry point" is typically a function (or other callable function-like object) that a developer or user of your Python package might want to use, though a non-callable object can be supplied as an entry point as well (as correctly pointed out in the comments!).</p> <p>The most popular kind of entry point is the ...
90
2009-04-23T18:37:08Z
[ "python", "setuptools" ]
Explain Python entry points?
774,824
<p>I've read the documentation on egg entry points in Pylons and on the Peak pages, and I still don't really understand. Could someone explain them to me, or point me at an article or book that does?</p>
107
2009-04-21T21:59:55Z
9,615,473
<p><a href="https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points">EntryPoints</a> provide a persistent, filesystem-based object name registration and name-based direct object import mechanism (implemented by the <a href="http://pypi.python.org/pypi/setuptools">setuptools</a> package). </p> <p>Th...
115
2012-03-08T09:39:04Z
[ "python", "setuptools" ]
Multiple statements in list compherensions in Python?
774,876
<p>Is it possible to have something like:</p> <pre><code>list1 = ... currentValue = 0 list2 = [currentValue += i, i for i in list1] </code></pre> <p>I tried that but didn't work? What's the proper syntax to write those?</p> <p>EDIT: the print statement was an example. Actually I am incrementing a value outside the ...
6
2009-04-21T22:14:48Z
774,889
<p>First of all, you likely don't want to use <code>print</code>. It doesn't return anything, so use a conventional <code>for</code> loop if you just want to print out stuff. What you are looking for is:</p> <pre><code>&gt;&gt;&gt; list1 = (1,2,3,4) &gt;&gt;&gt; list2 = [(i, i*2) for i in list1] # Notice the braces ar...
0
2009-04-21T22:18:18Z
[ "python", "list-comprehension" ]
Multiple statements in list compherensions in Python?
774,876
<p>Is it possible to have something like:</p> <pre><code>list1 = ... currentValue = 0 list2 = [currentValue += i, i for i in list1] </code></pre> <p>I tried that but didn't work? What's the proper syntax to write those?</p> <p>EDIT: the print statement was an example. Actually I am incrementing a value outside the ...
6
2009-04-21T22:14:48Z
774,892
<p>I'm not quite sure what you're trying to do but it's probably something like</p> <pre><code>list2 = [(i, i*2, i) for i in list1] print list2 </code></pre> <p>The statement in the list comprehension has to be a single statement, but you could always make it a function call:</p> <pre><code>def foo(i): print i ...
2
2009-04-21T22:18:46Z
[ "python", "list-comprehension" ]
Multiple statements in list compherensions in Python?
774,876
<p>Is it possible to have something like:</p> <pre><code>list1 = ... currentValue = 0 list2 = [currentValue += i, i for i in list1] </code></pre> <p>I tried that but didn't work? What's the proper syntax to write those?</p> <p>EDIT: the print statement was an example. Actually I am incrementing a value outside the ...
6
2009-04-21T22:14:48Z
774,896
<p>Here's an example from <a href="http://stackoverflow.com/questions/364621/python-get-position-in-list/364769#364769">another question</a>:</p> <pre><code>[i for i,x in enumerate(testlist) if x == 1] </code></pre> <p>the enumerate generator returns a 2-tuple which goes into i,x.</p>
2
2009-04-21T22:20:33Z
[ "python", "list-comprehension" ]
Multiple statements in list compherensions in Python?
774,876
<p>Is it possible to have something like:</p> <pre><code>list1 = ... currentValue = 0 list2 = [currentValue += i, i for i in list1] </code></pre> <p>I tried that but didn't work? What's the proper syntax to write those?</p> <p>EDIT: the print statement was an example. Actually I am incrementing a value outside the ...
6
2009-04-21T22:14:48Z
774,921
<p>Print is a weird thing to call in a list comprehension. It'd help if you showed us what output you want, not just the code that doesn't work.</p> <p>Here are two guesses for you. Either way, the important point is that the value statement in a list comprehension has to be a <em>single</em> value. You can't insert m...
1
2009-04-21T22:25:15Z
[ "python", "list-comprehension" ]
Multiple statements in list compherensions in Python?
774,876
<p>Is it possible to have something like:</p> <pre><code>list1 = ... currentValue = 0 list2 = [currentValue += i, i for i in list1] </code></pre> <p>I tried that but didn't work? What's the proper syntax to write those?</p> <p>EDIT: the print statement was an example. Actually I am incrementing a value outside the ...
6
2009-04-21T22:14:48Z
774,968
<p>You can't do multiple statements, but you can do a function call. To do what you seem to want above, you could do:</p> <pre><code>list1 = ... list2 = [ (sum(list1[:i], i) for i in list1 ] </code></pre> <p>in general, since list comprehensions are part of the 'functional' part of python, you're restricted to... fu...
0
2009-04-21T22:36:57Z
[ "python", "list-comprehension" ]
Multiple statements in list compherensions in Python?
774,876
<p>Is it possible to have something like:</p> <pre><code>list1 = ... currentValue = 0 list2 = [currentValue += i, i for i in list1] </code></pre> <p>I tried that but didn't work? What's the proper syntax to write those?</p> <p>EDIT: the print statement was an example. Actually I am incrementing a value outside the ...
6
2009-04-21T22:14:48Z
774,987
<p>Statements <em>cannot</em> go inside of expressions in Python; it was a complication that was deliberately designed out of the language. For this problem, try using a complication that <strong>did</strong> make it into the language: generators. Watch:</p> <pre><code>def total_and_item(sequence): total = 0 ...
18
2009-04-21T22:45:01Z
[ "python", "list-comprehension" ]
Multiple statements in list compherensions in Python?
774,876
<p>Is it possible to have something like:</p> <pre><code>list1 = ... currentValue = 0 list2 = [currentValue += i, i for i in list1] </code></pre> <p>I tried that but didn't work? What's the proper syntax to write those?</p> <p>EDIT: the print statement was an example. Actually I am incrementing a value outside the ...
6
2009-04-21T22:14:48Z
775,157
<p>For your edited example:</p> <pre><code>currentValue += sum(list1) </code></pre> <p>or:</p> <pre><code>for x in list1: currentValue += x </code></pre> <p>List comprehensions are great, I love them, but there's nothing wrong with the humble <code>for</code> loop and you shouldn't be afraid to use it :-)</p> ...
1
2009-04-21T23:46:55Z
[ "python", "list-comprehension" ]
Multiple statements in list compherensions in Python?
774,876
<p>Is it possible to have something like:</p> <pre><code>list1 = ... currentValue = 0 list2 = [currentValue += i, i for i in list1] </code></pre> <p>I tried that but didn't work? What's the proper syntax to write those?</p> <p>EDIT: the print statement was an example. Actually I am incrementing a value outside the ...
6
2009-04-21T22:14:48Z
784,688
<p>Why would you create a duplicate list. It seems like all that list comprehension would do is just sum the contents.</p> <p>Why not just.</p> <pre><code>list2 = list(list1) #this makes a copy currentValue = sum(list2) </code></pre>
1
2009-04-24T06:02:04Z
[ "python", "list-comprehension" ]
Multiple statements in list compherensions in Python?
774,876
<p>Is it possible to have something like:</p> <pre><code>list1 = ... currentValue = 0 list2 = [currentValue += i, i for i in list1] </code></pre> <p>I tried that but didn't work? What's the proper syntax to write those?</p> <p>EDIT: the print statement was an example. Actually I am incrementing a value outside the ...
6
2009-04-21T22:14:48Z
1,166,538
<p>As pjz said, you can use functions, so here you can use a closure to keep track of the counter value:</p> <pre><code># defines a closure to enclose the sum variable def make_counter(init_value=0): sum = [init_value] def inc(x=0): sum[0] += x return sum[0] return inc </code></pre> <p>The...
2
2009-07-22T16:33:03Z
[ "python", "list-comprehension" ]
Python Time Seconds to h:m:s
775,049
<p>I have a function that returns information in seconds, but I need to store that information in hours:minutes:seconds. Is there an easy way to convert the seconds to this format in python?</p>
178
2009-04-21T23:08:16Z
775,075
<p>By using the <a href="http://docs.python.org/library/functions.html#divmod"><code>divmod()</code></a> function, which does only a single division to produce both the quotient and the remainder, you can have the result very quickly with only two mathematical operations:</p> <pre><code>m, s = divmod(seconds, 60) h, m...
284
2009-04-21T23:15:54Z
[ "python" ]
Python Time Seconds to h:m:s
775,049
<p>I have a function that returns information in seconds, but I need to store that information in hours:minutes:seconds. Is there an easy way to convert the seconds to this format in python?</p>
178
2009-04-21T23:08:16Z
775,095
<p>or you can do</p> <pre><code>&gt;&gt;&gt; import datetime &gt;&gt;&gt; str(datetime.timedelta(seconds=666)) '0:11:06' </code></pre>
344
2009-04-21T23:22:15Z
[ "python" ]
Python Time Seconds to h:m:s
775,049
<p>I have a function that returns information in seconds, but I need to store that information in hours:minutes:seconds. Is there an easy way to convert the seconds to this format in python?</p>
178
2009-04-21T23:08:16Z
24,507,708
<p>I can hardly name that an easy way (at least I can't remember the syntax), but it is possible to use <a href="https://docs.python.org/2/library/time.html#time.strftime">time.strftime</a>, which gives more control over formatting:</p> <pre><code>&gt;&gt;&gt; import time &gt;&gt;&gt; time.strftime("%H:%M:%S", time.gm...
22
2014-07-01T10:13:42Z
[ "python" ]
Python Time Seconds to h:m:s
775,049
<p>I have a function that returns information in seconds, but I need to store that information in hours:minutes:seconds. Is there an easy way to convert the seconds to this format in python?</p>
178
2009-04-21T23:08:16Z
31,946,730
<pre><code>&gt;&gt;&gt; "{:0&gt;8}".format(datetime.timedelta(seconds=66)) &gt;&gt;&gt; '00:01:06' # good </code></pre> <p>and:</p> <pre><code>&gt;&gt;&gt; "{:0&gt;8}".format(datetime.timedelta(seconds=666777) &gt;&gt;&gt; '7 days, 17:12:57' # nice </code></pre> <p>without ':0>8':</p> <pre><code>&gt;&gt;&gt; "{}".f...
8
2015-08-11T16:06:05Z
[ "python" ]
Python Time Seconds to h:m:s
775,049
<p>I have a function that returns information in seconds, but I need to store that information in hours:minutes:seconds. Is there an easy way to convert the seconds to this format in python?</p>
178
2009-04-21T23:08:16Z
33,504,562
<p>This is how I got it.</p> <pre><code>def sec2time(sec, n_msec=3): ''' Convert seconds to 'D days, HH:MM:SS.FFF' ''' if hasattr(sec,'__len__'): return [sec2time(s) for s in sec] m, s = divmod(sec, 60) h, m = divmod(m, 60) d, h = divmod(h, 24) if n_msec &gt; 0: pattern = '%%02d...
0
2015-11-03T16:42:14Z
[ "python" ]
Python Time Seconds to h:m:s
775,049
<p>I have a function that returns information in seconds, but I need to store that information in hours:minutes:seconds. Is there an easy way to convert the seconds to this format in python?</p>
178
2009-04-21T23:08:16Z
37,368,085
<p>If you need to get <code>datetime.time</code> value, you can use this trick:</p> <pre><code>my_time = (datetime(1970,1,1) + timedelta(seconds=my_seconds)).time() </code></pre> <p>You cannot add <code>timedelta</code> to <code>time</code>, but can add it to <code>datetime</code>.</p>
1
2016-05-21T21:14:33Z
[ "python" ]
Efficiently determining if a business is open or not based on store hours
775,161
<p>Given a time (eg. currently 4:24pm on Tuesday), I'd like to be able to select all businesses that are currently open out of a set of businesses. </p> <ul> <li>I have the open and close times for every business for every day of the week</li> <li>Let's assume a business can open/close only on 00, 15, 30, 45 minute ma...
6
2009-04-21T23:48:14Z
775,175
<p>Sorry I don't have an easy answer, but I can tell you that as the manager of a development team at a company in the late 90's we were tasked with solving this very problem and it was HARD.</p> <p>It's not the weekly hours that's tough, that can be done with a relatively small bitmask (168 bits = 1 per hour of the w...
3
2009-04-21T23:52:58Z
[ "python", "mysql", "performance", "solr" ]
Efficiently determining if a business is open or not based on store hours
775,161
<p>Given a time (eg. currently 4:24pm on Tuesday), I'd like to be able to select all businesses that are currently open out of a set of businesses. </p> <ul> <li>I have the open and close times for every business for every day of the week</li> <li>Let's assume a business can open/close only on 00, 15, 30, 45 minute ma...
6
2009-04-21T23:48:14Z
775,211
<p>The bitmap field mentioned by another respondent would be incredibly efficient, but gets messy if you want to be able to handle half-hour or quarter-hour times, since you have to increase arithmetically the number of bits and the design of the field each time you encounter a new resolution that you have to match.</p...
5
2009-04-22T00:08:07Z
[ "python", "mysql", "performance", "solr" ]
Efficiently determining if a business is open or not based on store hours
775,161
<p>Given a time (eg. currently 4:24pm on Tuesday), I'd like to be able to select all businesses that are currently open out of a set of businesses. </p> <ul> <li>I have the open and close times for every business for every day of the week</li> <li>Let's assume a business can open/close only on 00, 15, 30, 45 minute ma...
6
2009-04-21T23:48:14Z
775,247
<p>If you are willing to just look at single week at a time, you can canonicalize all opening/closing times to be set numbers of minutes since the start of the week, say Sunday 0 hrs. For each store, you create a number of tuples of the form [startTime, endTime, storeId]. (For hours that spanned Sunday midnight, you'd ...
8
2009-04-22T00:25:59Z
[ "python", "mysql", "performance", "solr" ]
Efficiently determining if a business is open or not based on store hours
775,161
<p>Given a time (eg. currently 4:24pm on Tuesday), I'd like to be able to select all businesses that are currently open out of a set of businesses. </p> <ul> <li>I have the open and close times for every business for every day of the week</li> <li>Let's assume a business can open/close only on 00, 15, 30, 45 minute ma...
6
2009-04-21T23:48:14Z
775,354
<p>You say you're using SOLR, don't care about storage, and want the lookups to be fast. Then instead of storing open/close tuples, index an entry for every open block of time at the level of granularity you need (15 mins). For the encoding itself, you could use just cumulative hours:minutes.</p> <p>For example, a s...
4
2009-04-22T01:13:48Z
[ "python", "mysql", "performance", "solr" ]
Efficiently determining if a business is open or not based on store hours
775,161
<p>Given a time (eg. currently 4:24pm on Tuesday), I'd like to be able to select all businesses that are currently open out of a set of businesses. </p> <ul> <li>I have the open and close times for every business for every day of the week</li> <li>Let's assume a business can open/close only on 00, 15, 30, 45 minute ma...
6
2009-04-21T23:48:14Z
775,364
<p>If you can control your data well, I see a simple solution, similar to @Sebastian's. Follow the advice of creating the tuples, except create them of the form [time=startTime, storeId] and [time=endTime, storeId], then sort these in a list. To find out if a store is open, simply do a query like:</p> <pre><code>selec...
0
2009-04-22T01:18:43Z
[ "python", "mysql", "performance", "solr" ]
Efficiently determining if a business is open or not based on store hours
775,161
<p>Given a time (eg. currently 4:24pm on Tuesday), I'd like to be able to select all businesses that are currently open out of a set of businesses. </p> <ul> <li>I have the open and close times for every business for every day of the week</li> <li>Let's assume a business can open/close only on 00, 15, 30, 45 minute ma...
6
2009-04-21T23:48:14Z
775,459
<p>Have you looked at how many unique open/close time combinations there are? If there are not that many, make a reference table of the unique combinations and store the index of the appropriate entry against each business. Then you only have to search the reference table and then find the business with those indices....
0
2009-04-22T02:03:30Z
[ "python", "mysql", "performance", "solr" ]
Efficiently determining if a business is open or not based on store hours
775,161
<p>Given a time (eg. currently 4:24pm on Tuesday), I'd like to be able to select all businesses that are currently open out of a set of businesses. </p> <ul> <li>I have the open and close times for every business for every day of the week</li> <li>Let's assume a business can open/close only on 00, 15, 30, 45 minute ma...
6
2009-04-21T23:48:14Z
777,443
<p>In your Solr index, instead of indexing each business as one document with hours, index every "retail session" for every business during the course of a week. </p> <p>For example if Joe's coffee is open Mon-Sat 6am-9pm and closed on Sunday, you would index six distinct documents, each with two indexed fields, "ope...
1
2009-04-22T14:18:22Z
[ "python", "mysql", "performance", "solr" ]
Directory Walker for Python
775,231
<p>I am currently using the directory walker from <a href="http://effbot.org/librarybook/os-path-walk-example-3.py" rel="nofollow">Here</a></p> <pre><code>import os class DirectoryWalker: # a forward iterator that traverses a directory tree def __init__(self, directory): self.stack = [directory] self.files = ...
4
2009-04-22T00:19:13Z
775,249
<p>Rather than using '.' as your directory, refer to its absolute path:</p> <pre><code>for file in DirectoryWalker(os.path.abspath('.')): print file </code></pre> <p>Also, I'd recommend using a word other than 'file', because it means something in the python language. Not a keyword, though so it still runs.</p> ...
6
2009-04-22T00:26:32Z
[ "python", "directory-listing" ]
Directory Walker for Python
775,231
<p>I am currently using the directory walker from <a href="http://effbot.org/librarybook/os-path-walk-example-3.py" rel="nofollow">Here</a></p> <pre><code>import os class DirectoryWalker: # a forward iterator that traverses a directory tree def __init__(self, directory): self.stack = [directory] self.files = ...
4
2009-04-22T00:19:13Z
775,252
<p>Just prepend the current directory path to the "./foo" path returned:</p> <pre><code>print os.path.join(os.getcwd(), file) </code></pre>
0
2009-04-22T00:27:16Z
[ "python", "directory-listing" ]
Directory Walker for Python
775,231
<p>I am currently using the directory walker from <a href="http://effbot.org/librarybook/os-path-walk-example-3.py" rel="nofollow">Here</a></p> <pre><code>import os class DirectoryWalker: # a forward iterator that traverses a directory tree def __init__(self, directory): self.stack = [directory] self.files = ...
4
2009-04-22T00:19:13Z
775,253
<p>os.path.dirname()? os.path.normpath()? os.path.abspath()?</p> <p>This would also be a lovely place to think recursion.</p>
1
2009-04-22T00:27:32Z
[ "python", "directory-listing" ]
Directory Walker for Python
775,231
<p>I am currently using the directory walker from <a href="http://effbot.org/librarybook/os-path-walk-example-3.py" rel="nofollow">Here</a></p> <pre><code>import os class DirectoryWalker: # a forward iterator that traverses a directory tree def __init__(self, directory): self.stack = [directory] self.files = ...
4
2009-04-22T00:19:13Z
778,377
<p>Why do you want to do such boring thing yourself?</p> <pre><code>for path, directories, files in os.walk('.'): print 'ls %r' % path for directory in directories: print ' d%r' % directory for filename in files: print ' -%r' % filename </code></pre> <p>Output:</p> <pre><code>'.' ...
12
2009-04-22T17:40:32Z
[ "python", "directory-listing" ]
Python MySQL Parameterized Queries
775,296
<p>I am having a hard time using the MySQLdb module to insert information into my database. I need to insert 6 variables into the table. </p> <pre><code>cursor.execute (""" INSERT INTO Songs (SongName, SongArtist, SongAlbum, SongGenre, SongLength, SongLocation) VALUES (var1, var2, var3, var4, var5, v...
44
2009-04-22T00:43:21Z
775,320
<p>The linked docs give the following example:</p> <pre><code> cursor.execute (""" UPDATE animal SET name = %s WHERE name = %s """, ("snake", "turtle")) print "Number of rows updated: %d" % cursor.rowcount </code></pre> <p>So you just need to adapt this to your own code - example:</p> <...
10
2009-04-22T00:53:31Z
[ "python", "mysql" ]
Python MySQL Parameterized Queries
775,296
<p>I am having a hard time using the MySQLdb module to insert information into my database. I need to insert 6 variables into the table. </p> <pre><code>cursor.execute (""" INSERT INTO Songs (SongName, SongArtist, SongAlbum, SongGenre, SongLength, SongLocation) VALUES (var1, var2, var3, var4, var5, v...
44
2009-04-22T00:43:21Z
775,344
<p>You have a few options available. You'll want to get comfortable with python's string iterpolation. Which is a term you might have more success searching for in the future when you want to know stuff like this.</p> <p>Better for queries:</p> <pre><code>some_dictionary_with_the_data = { 'name': 'awesome song',...
21
2009-04-22T01:04:31Z
[ "python", "mysql" ]
Python MySQL Parameterized Queries
775,296
<p>I am having a hard time using the MySQLdb module to insert information into my database. I need to insert 6 variables into the table. </p> <pre><code>cursor.execute (""" INSERT INTO Songs (SongName, SongArtist, SongAlbum, SongGenre, SongLength, SongLocation) VALUES (var1, var2, var3, var4, var5, v...
44
2009-04-22T00:43:21Z
775,399
<p>Beware of using string interpolation for SQL queries, since it won't escape the input parameters correctly and will leave your application open to SQL injection vulnerabilities. <strong>The difference might seem trivial, but in reality it's huge</strong>.</p> <h3>Incorrect (with security issues)</h3> <pre><code>c....
167
2009-04-22T01:35:26Z
[ "python", "mysql" ]
Python MySQL Parameterized Queries
775,296
<p>I am having a hard time using the MySQLdb module to insert information into my database. I need to insert 6 variables into the table. </p> <pre><code>cursor.execute (""" INSERT INTO Songs (SongName, SongArtist, SongAlbum, SongGenre, SongLength, SongLocation) VALUES (var1, var2, var3, var4, var5, v...
44
2009-04-22T00:43:21Z
5,448,353
<p>Actually, even if your variable (SongLength) is numeric, you will still have to format it with %s in order to bind the parameter correctly. If you try to use %d, you will get an error. Here's a small excerpt from this link <a href="http://mysql-python.sourceforge.net/MySQLdb.html" rel="nofollow">http://mysql-pytho...
4
2011-03-27T09:31:30Z
[ "python", "mysql" ]
Python MySQL Parameterized Queries
775,296
<p>I am having a hard time using the MySQLdb module to insert information into my database. I need to insert 6 variables into the table. </p> <pre><code>cursor.execute (""" INSERT INTO Songs (SongName, SongArtist, SongAlbum, SongGenre, SongLength, SongLocation) VALUES (var1, var2, var3, var4, var5, v...
44
2009-04-22T00:43:21Z
15,980,304
<p>As an alternative to the chosen answer, and with the same safe semantics of Marcel's, here is a compact way of using a Python dictionary to specify the values. It has the benefit of being easy to modify as you add or remove columns to insert:</p> <pre><code> meta_cols=('SongName','SongArtist','SongAlbum','SongGenr...
1
2013-04-12T20:28:19Z
[ "python", "mysql" ]
os.path.exists() for files in your Path?
775,351
<p>I commonly use os.path.exists() to check if a file is there before doing anything with it.</p> <p>I've run across a situation where I'm calling a executable that's in the configured env path, so it can be called without specifying the abspath.</p> <p>Is there something that can be done to check if the file exists ...
11
2009-04-22T01:09:31Z
775,360
<p>You could get the PATH environment variable, and try "exists()" for the .exe in each dir in the path. But that could perform horribly.</p> <p>example for finding notepad.exe:</p> <pre><code>import os for p in os.environ["PATH"].split(os.pathsep): print os.path.exists(os.path.join(p, 'notepad.exe')) </code></pr...
12
2009-04-22T01:16:08Z
[ "python", "windows" ]
os.path.exists() for files in your Path?
775,351
<p>I commonly use os.path.exists() to check if a file is there before doing anything with it.</p> <p>I've run across a situation where I'm calling a executable that's in the configured env path, so it can be called without specifying the abspath.</p> <p>Is there something that can be done to check if the file exists ...
11
2009-04-22T01:09:31Z
777,010
<p>On Unix you have to split the PATH var.</p> <pre><code>if any([os.path.exists(os.path.join(p,progname)) for p in os.environ["PATH"].split(":")]): do_something() </code></pre>
0
2009-04-22T12:37:50Z
[ "python", "windows" ]
os.path.exists() for files in your Path?
775,351
<p>I commonly use os.path.exists() to check if a file is there before doing anything with it.</p> <p>I've run across a situation where I'm calling a executable that's in the configured env path, so it can be called without specifying the abspath.</p> <p>Is there something that can be done to check if the file exists ...
11
2009-04-22T01:09:31Z
777,067
<p>Please note that checking for existance and then opening is always open to race-conditions. The file can disappear between your program's check and its next access of the file, since other programs continue to run on the machine.</p> <p>Thus there might still be an exception being thrown, even though your code is "...
2
2009-04-22T12:51:26Z
[ "python", "windows" ]
os.path.exists() for files in your Path?
775,351
<p>I commonly use os.path.exists() to check if a file is there before doing anything with it.</p> <p>I've run across a situation where I'm calling a executable that's in the configured env path, so it can be called without specifying the abspath.</p> <p>Is there something that can be done to check if the file exists ...
11
2009-04-22T01:09:31Z
777,961
<p>You generally shouldn't should os.path.exists to try to figure out if something is going to succeed. You should just try it and if you want you can handle the exception if it fails.</p>
2
2009-04-22T15:53:31Z
[ "python", "windows" ]
os.path.exists() for files in your Path?
775,351
<p>I commonly use os.path.exists() to check if a file is there before doing anything with it.</p> <p>I've run across a situation where I'm calling a executable that's in the configured env path, so it can be called without specifying the abspath.</p> <p>Is there something that can be done to check if the file exists ...
11
2009-04-22T01:09:31Z
1,322,060
<p>Extending Trey Stout's search with Carl Meyer's comment on PATHEXT:</p> <pre><code>import os def exists_in_path(cmd): # can't search the path if a directory is specified assert not os.path.dirname(cmd) extensions = os.environ.get("PATHEXT", "").split(os.pathsep) for directory in os.environ.get("PATH", "")....
3
2009-08-24T12:25:35Z
[ "python", "windows" ]
how can I decode the REG_BINARY value HKLM\Software\Microsoft\Ole\DefaultLaunchPermission to see which users have permission?
775,365
<p>I am trying to find a way to decode the REG_BINARY value for "<strong>HKLM\Software\Microsoft\Ole\DefaultLaunchPermission</strong>" to see which users have permissions by default, and if possible, a method in which I can also append other users by their username. </p> <p>At work we make use of DCOM and for the most...
1
2009-04-22T01:19:40Z
775,410
<p>Well REG_BINARY isn't any particular format, it's just a way to tell the registry the data is a custom binary format. So you're right about needing to find out what's in there.</p> <p>Also, what do you mean by converting the data from hex? Are you unpacking it? I doubt you're interpreting it correctly until you kno...
0
2009-04-22T01:39:33Z
[ "python", "binary", "wmi", "registry", "decode" ]
how can I decode the REG_BINARY value HKLM\Software\Microsoft\Ole\DefaultLaunchPermission to see which users have permission?
775,365
<p>I am trying to find a way to decode the REG_BINARY value for "<strong>HKLM\Software\Microsoft\Ole\DefaultLaunchPermission</strong>" to see which users have permissions by default, and if possible, a method in which I can also append other users by their username. </p> <p>At work we make use of DCOM and for the most...
1
2009-04-22T01:19:40Z
775,461
<p>We came across similar issues when installing a COM server that was hosted by our .NET service, i.e. we wanted to programmatically alter the the COM ACLs in our install logic. I think you'll find that it's just a binary ACL format that you can manipulate in .NET using the class:</p> <p><a href="http://msdn.microsof...
2
2009-04-22T02:04:35Z
[ "python", "binary", "wmi", "registry", "decode" ]
How to catch POST using WSGIREF
775,396
<p>I am trying to catch POST data from a simple form.</p> <p>This is the first time I am playing around with WSGIREF and I can't seem to find the correct way to do this.</p> <pre><code>This is the form: &lt;form action="test" method="POST"&gt; &lt;input type="text" name="name"&gt; &lt;input type="submit"&gt;&lt;/form...
0
2009-04-22T01:34:39Z
775,698
<p>You should be reading responses from the server.</p> <p>From <a href="http://stackoverflow.com/questions/394465/python-post-data-using-modwsgi">nosklo's answer</a> to a similar problem: "<a href="http://www.python.org/dev/peps/pep-0333/" rel="nofollow">PEP 333</a> says <a href="http://www.python.org/dev/peps/pep-0...
3
2009-04-22T04:37:13Z
[ "python", "wsgi", "wsgiref" ]
How do you transfer binary data with Python?
775,482
<p>I'm working on a client-server program for the first time, and I'm feeling woefully inadequate on where to begin for what I'm doing.</p> <p>I'm going to use <a href="http://code.google.com/p/protobuf/" rel="nofollow">Google Protocol Buffers</a> to transfer binary data between my client and my server. I'm going to ...
3
2009-04-22T02:11:12Z
775,515
<p>Any time you're going to move binary data from one system to another there a couple of things to keep in mind.</p> <p>Different machines store the same information differently. This has implication both in memory and on the network. More info here (<a href="http://en.wikipedia.org/wiki/Endianness" rel="nofollow">ht...
4
2009-04-22T02:28:37Z
[ "python", "http", "file", "client-server", "protocol-buffers" ]
How do you transfer binary data with Python?
775,482
<p>I'm working on a client-server program for the first time, and I'm feeling woefully inadequate on where to begin for what I'm doing.</p> <p>I'm going to use <a href="http://code.google.com/p/protobuf/" rel="nofollow">Google Protocol Buffers</a> to transfer binary data between my client and my server. I'm going to ...
3
2009-04-22T02:11:12Z
775,550
<p>I'm not sure I got your question right, but maybe you can take a look at the <a href="http://twistedmatrix.com/trac/" rel="nofollow">twisted project</a>.</p> <p>As you can see in the FAQ, "Twisted is a networking engine written in Python, supporting numerous protocols. It contains a web server, numerous chat client...
3
2009-04-22T02:50:27Z
[ "python", "http", "file", "client-server", "protocol-buffers" ]
How do you transfer binary data with Python?
775,482
<p>I'm working on a client-server program for the first time, and I'm feeling woefully inadequate on where to begin for what I'm doing.</p> <p>I'm going to use <a href="http://code.google.com/p/protobuf/" rel="nofollow">Google Protocol Buffers</a> to transfer binary data between my client and my server. I'm going to ...
3
2009-04-22T02:11:12Z
775,576
<p>I guess it depends on how tied you are to Google Protocol Buffers, but you might like to check out <a href="http://incubator.apache.org/thrift/" rel="nofollow"><strong>Thrift</strong></a>.</p> <blockquote> <p><strong>Thrift</strong> is a software framework for scalable cross-language services development. It ...
1
2009-04-22T03:19:03Z
[ "python", "http", "file", "client-server", "protocol-buffers" ]
How do you transfer binary data with Python?
775,482
<p>I'm working on a client-server program for the first time, and I'm feeling woefully inadequate on where to begin for what I'm doing.</p> <p>I'm going to use <a href="http://code.google.com/p/protobuf/" rel="nofollow">Google Protocol Buffers</a> to transfer binary data between my client and my server. I'm going to ...
3
2009-04-22T02:11:12Z
775,585
<p>One quick question: why binary? Is the payload itself binary, or do you just prefer a binary format? If former, it's possible to use base64 encoding with JSON or XML too; it does use more space (~34%), and bit more processing overhead, but not necessarily enough to matter for many use cases.</p>
0
2009-04-22T03:24:39Z
[ "python", "http", "file", "client-server", "protocol-buffers" ]
Sorted collections: How do i get (extended) slices right?
775,490
<p>How can I resolve this?</p> <pre><code>&gt;&gt;&gt; class unslice: ... def __getitem__(self, item): print type(item), ":", item ... &gt;&gt;&gt; u = unslice() &gt;&gt;&gt; u[1,2] # using an extended slice &lt;type 'tuple'&gt; : (1, 2) &gt;&gt;&gt; t = (1, 2) &gt;&gt;&gt; u[t] # or passing a plain tuple &lt;...
2
2009-04-22T02:14:31Z
775,559
<p>Since there is no way to differentiate between the calls u[x,y] and u[(x,y)], you should shift one of the two operations you are trying to define off to an actual method. You know, something named u.slice() or u.range() or u.getslice() or u.getrange() or something like that.</p> <p>Actually, when writing my <em>ow...
5
2009-04-22T03:01:14Z
[ "python" ]
Sorted collections: How do i get (extended) slices right?
775,490
<p>How can I resolve this?</p> <pre><code>&gt;&gt;&gt; class unslice: ... def __getitem__(self, item): print type(item), ":", item ... &gt;&gt;&gt; u = unslice() &gt;&gt;&gt; u[1,2] # using an extended slice &lt;type 'tuple'&gt; : (1, 2) &gt;&gt;&gt; t = (1, 2) &gt;&gt;&gt; u[t] # or passing a plain tuple &lt;...
2
2009-04-22T02:14:31Z
775,598
<p>From <a href="http://docs.python.org/reference/expressions.html#index-917" rel="nofollow">the docs</a>:</p> <blockquote> <p>There is ambiguity in the formal syntax here: anything that looks like an expression list also looks like a slice list, so any subscription can be interpreted as a slicing. Rather th...
0
2009-04-22T03:30:54Z
[ "python" ]
Sorted collections: How do i get (extended) slices right?
775,490
<p>How can I resolve this?</p> <pre><code>&gt;&gt;&gt; class unslice: ... def __getitem__(self, item): print type(item), ":", item ... &gt;&gt;&gt; u = unslice() &gt;&gt;&gt; u[1,2] # using an extended slice &lt;type 'tuple'&gt; : (1, 2) &gt;&gt;&gt; t = (1, 2) &gt;&gt;&gt; u[t] # or passing a plain tuple &lt;...
2
2009-04-22T02:14:31Z
775,607
<p>My current thinking about this is to simply let the types that normally associate with slices be uncollectable. I can't think of any sane reason why anyone would want to do anything with a <code>slice</code> value or <code>Ellipsis</code> except to use them in subscript expressions. </p> <p>On the off chance a use...
0
2009-04-22T03:40:00Z
[ "python" ]
drawing a pixbuf onto a drawing area using pygtk and glade
775,528
<p>i'm trying to make a GTK application in python where I can just draw a loaded image onto the screen where I click on it. The way I am trying to do this is by loading the image into a pixbuf file, and then drawing that pixbuf onto a drawing area.</p> <p>the main line of code is here:</p> <pre><code>def drawing_refr...
1
2009-04-22T02:34:43Z
776,067
<p>I found out I just need to get the function to call another expose event with <code>widget.queue_draw()</code> at the end of the function. The function was only being called once at the start, and there were no nodes available at this point so nothing was being drawn.</p>
2
2009-04-22T07:46:15Z
[ "python", "drawing", "pygtk", "glade" ]
drawing a pixbuf onto a drawing area using pygtk and glade
775,528
<p>i'm trying to make a GTK application in python where I can just draw a loaded image onto the screen where I click on it. The way I am trying to do this is by loading the image into a pixbuf file, and then drawing that pixbuf onto a drawing area.</p> <p>the main line of code is here:</p> <pre><code>def drawing_refr...
1
2009-04-22T02:34:43Z
900,800
<p>You can make use of cairo to do this. First, create a gtk.DrawingArea based class, and connect the expose-event to your expose func.</p> <pre><code>class draw(gtk.gdk.DrawingArea): def __init__(self): self.connect('expose-event', self._do_expose) self.pixbuf = self.gen_pixbuf_from_file(PATH_TO_T...
1
2009-05-23T03:41:31Z
[ "python", "drawing", "pygtk", "glade" ]
Python bindings for libparted?
775,580
<p>I'm looking for a way to interact with the GNU <code>libparted</code> library from Python, but so far what I've found, a <a href="http://code.google.com/soc" rel="nofollow">GSOC</a> <a href="http://pylibparted.tigris.org" rel="nofollow">project from 2005</a> and an <a href="https://edge.launchpad.net/ubuntu/+source/...
2
2009-04-22T03:21:06Z
775,639
<p>The reason debian dropped the package is lack of a maintainer. If you are willing (and able) to maintain the existing package and become their maintainer that would be a great contribution to FOSS.</p>
2
2009-04-22T04:06:01Z
[ "python" ]
Python bindings for libparted?
775,580
<p>I'm looking for a way to interact with the GNU <code>libparted</code> library from Python, but so far what I've found, a <a href="http://code.google.com/soc" rel="nofollow">GSOC</a> <a href="http://pylibparted.tigris.org" rel="nofollow">project from 2005</a> and an <a href="https://edge.launchpad.net/ubuntu/+source/...
2
2009-04-22T03:21:06Z
775,764
<p>You can try using <a href="http://www.riverbankcomputing.co.uk/software/sip/intro" rel="nofollow">SIP</a> to generate a Python binding for it. It works for QT so it may work for libparted.</p>
1
2009-04-22T05:03:14Z
[ "python" ]
Python bindings for libparted?
775,580
<p>I'm looking for a way to interact with the GNU <code>libparted</code> library from Python, but so far what I've found, a <a href="http://code.google.com/soc" rel="nofollow">GSOC</a> <a href="http://pylibparted.tigris.org" rel="nofollow">project from 2005</a> and an <a href="https://edge.launchpad.net/ubuntu/+source/...
2
2009-04-22T03:21:06Z
775,903
<p>You mean like the <a href="https://github.com/rhinstaller/pyparted" rel="nofollow">pyparted</a> library?</p>
3
2009-04-22T06:13:13Z
[ "python" ]
Python bindings for libparted?
775,580
<p>I'm looking for a way to interact with the GNU <code>libparted</code> library from Python, but so far what I've found, a <a href="http://code.google.com/soc" rel="nofollow">GSOC</a> <a href="http://pylibparted.tigris.org" rel="nofollow">project from 2005</a> and an <a href="https://edge.launchpad.net/ubuntu/+source/...
2
2009-04-22T03:21:06Z
10,078,403
<p>Old thread, but you can also checkout <a href="http://pypi.python.org/pypi/reparted/" rel="nofollow">reparted</a>, it's a ctypes python binding.</p>
0
2012-04-09T19:11:17Z
[ "python" ]
Filetype information
775,674
<p>I'm in the process of writing a python script, and I want to find out information about a file, such as for example a mime-type (or any useful depiction of what a file contains).</p> <p>I've heard about python-magic, but I'm really looking for <em>the</em> solution that will allow me to find this information, witho...
0
2009-04-22T04:28:18Z
775,786
<p>The standard library has support for <a href="http://docs.python.org/library/mimetypes.html#module-mimetypes" rel="nofollow">mapping filenames to mimetypes</a>.</p> <p>Your question also sounds like you are interested in other information besides mimetype. The <a href="http://docs.python.org/library/stat.html" rel...
1
2009-04-22T05:14:27Z
[ "python" ]
Filetype information
775,674
<p>I'm in the process of writing a python script, and I want to find out information about a file, such as for example a mime-type (or any useful depiction of what a file contains).</p> <p>I've heard about python-magic, but I'm really looking for <em>the</em> solution that will allow me to find this information, witho...
0
2009-04-22T04:28:18Z
775,792
<p>I am not sure if you want to infer something from file content but if you want to know mime type from file extension mimetypes module will be sufficient</p> <pre><code>&gt;&gt;&gt; import mimetypes &gt;&gt;&gt; mimetypes.init() &gt;&gt;&gt; mimetypes.knownfiles ['/etc/mime.types', '/etc/httpd/mime.types', ... ] &gt...
5
2009-04-22T05:18:46Z
[ "python" ]
access eggs in python?
775,880
<p>Is there any way to call an installed python egg from python code? I need to cal a sphinx documentation generator from within a python code, and currently i'm doing it like this:</p> <p><code>os.system( "sphinx-build.exe -b html c:\\src c:\\dst" )</code></p> <p>This works, but requires some additional configuratio...
0
2009-04-22T05:55:19Z
775,908
<p>Adding the egg to PYTHONPATH or to sys.path will allow you to access the modules and packages within.</p>
1
2009-04-22T06:16:02Z
[ "python", "egg" ]
access eggs in python?
775,880
<p>Is there any way to call an installed python egg from python code? I need to cal a sphinx documentation generator from within a python code, and currently i'm doing it like this:</p> <p><code>os.system( "sphinx-build.exe -b html c:\\src c:\\dst" )</code></p> <p>This works, but requires some additional configuratio...
0
2009-04-22T05:55:19Z
776,425
<p>So basically, you want to use Sphinx as a library?</p> <p>Here is what <code>sphinx-build</code> does:</p> <pre><code>from pkg_resources import load_entry_point load_entry_point('Sphinx==0.5.1', 'console_scripts', 'sphinx-build')() </code></pre> <p>Looking at <code>entry-points.txt</code> in the EGG-INFO directo...
2
2009-04-22T09:47:06Z
[ "python", "egg" ]
What is "generator object" in django?
776,060
<p>Am using Django voting package and when i use the method get_top() in the shell, it returns something like <strong>"generator object at 0x022f7AD0</strong>, i've never seen anything like this before, how do you access it and what is it?</p> <p>my code:</p> <pre><code>v=Vote.objects.get_top(myModel, limit=10, rever...
4
2009-04-22T07:41:35Z
776,089
<p>If you want a list, just call list() on your generator object.</p> <p>A generator object in python is something like a lazy list. The elements are only evaluated as soon as you iterate over them. (Thus calling list on it evaluates all of them.)</p> <p>For example you can do:</p> <pre><code>&gt;&gt;&gt; def f(x): ...
19
2009-04-22T07:55:01Z
[ "python", "generator" ]
What is "generator object" in django?
776,060
<p>Am using Django voting package and when i use the method get_top() in the shell, it returns something like <strong>"generator object at 0x022f7AD0</strong>, i've never seen anything like this before, how do you access it and what is it?</p> <p>my code:</p> <pre><code>v=Vote.objects.get_top(myModel, limit=10, rever...
4
2009-04-22T07:41:35Z
776,139
<p>Hmmmm </p> <p>I've read <a href="http://www.dalkescientific.com/writings/NBN/generators.html" rel="nofollow">this</a> and <a href="http://www.neotitans.com/resources/python/python-generators-tutorial.html" rel="nofollow">this</a> and things are quiet clear now;</p> <p>Actually i can convert generators to list by j...
1
2009-04-22T08:10:28Z
[ "python", "generator" ]
What is "generator object" in django?
776,060
<p>Am using Django voting package and when i use the method get_top() in the shell, it returns something like <strong>"generator object at 0x022f7AD0</strong>, i've never seen anything like this before, how do you access it and what is it?</p> <p>my code:</p> <pre><code>v=Vote.objects.get_top(myModel, limit=10, rever...
4
2009-04-22T07:41:35Z
776,143
<p>A generator is a kind of iterator. An iterator is a kind of iterable object, and like any other iterable,</p> <p>You can iterate over every item using a for loop:</p> <pre><code>for vote in Vote.objects.get_top(myModel, limit=10, reversed=False): print v.name, vote </code></pre> <p>If you need to access item...
7
2009-04-22T08:11:20Z
[ "python", "generator" ]
How to get the public channel URL from YouTubeVideoFeed object using the YouTube API?
776,110
<p>I'm using the Python version of the YouTube API to get a YouTubeVideoFeed object using the following URL:</p> <blockquote> <p><a href="http://gdata.youtube.com/feeds/api/users/USERNAME/uploads" rel="nofollow">http://gdata.youtube.com/feeds/api/users/USERNAME/uploads</a></p> </blockquote> <p><em>Note: I've replac...
1
2009-04-22T08:01:09Z
776,200
<p>you might be confusing usernames... when I use my username I get my public page <a href="http://gdata.youtube.com/feeds/api/users/drdredel/uploads" rel="nofollow">http://gdata.youtube.com/feeds/api/users/drdredel/uploads</a> They have some wacky distinction between your gmail username and your youtube username. Or a...
0
2009-04-22T08:29:51Z
[ "python", "youtube", "feeds", "youtube-api" ]
How to get the public channel URL from YouTubeVideoFeed object using the YouTube API?
776,110
<p>I'm using the Python version of the YouTube API to get a YouTubeVideoFeed object using the following URL:</p> <blockquote> <p><a href="http://gdata.youtube.com/feeds/api/users/USERNAME/uploads" rel="nofollow">http://gdata.youtube.com/feeds/api/users/USERNAME/uploads</a></p> </blockquote> <p><em>Note: I've replac...
1
2009-04-22T08:01:09Z
786,979
<p>Well, the youtube.com/user/USERNAME is a pretty safe bet if you want to construct the URL yourself, but I think what you want is the link rel='alternate'</p> <p>You have to get the link array from the feed and iterate to find alternate, then grab the href</p> <p>something like:</p> <pre><code>client = gdata.youtu...
1
2009-04-24T18:09:41Z
[ "python", "youtube", "feeds", "youtube-api" ]
Multiple simultaneous network connections - Telnet server, Python
776,120
<p>I'm currently writing a telnet server in Python. It's a content server. People would connect to the server via telnet, and be presented with text-only content.</p> <p>My problem is that the server would obviously need to support more than one simultaneous connection. The current implementation I have now supports o...
16
2009-04-22T08:03:44Z
776,128
<p>If you're up for a bit of a conceptual challenge, I'd look into using twisted. </p> <p>Your case should be trivial to implement as a part of twisted. <a href="http://twistedmatrix.com/projects/core/documentation/howto/servers.html" rel="nofollow">http://twistedmatrix.com/projects/core/documentation/howto/servers.ht...
2
2009-04-22T08:06:46Z
[ "python", "sockets", "telnet" ]
Multiple simultaneous network connections - Telnet server, Python
776,120
<p>I'm currently writing a telnet server in Python. It's a content server. People would connect to the server via telnet, and be presented with text-only content.</p> <p>My problem is that the server would obviously need to support more than one simultaneous connection. The current implementation I have now supports o...
16
2009-04-22T08:03:44Z
776,157
<p>You need some form of asynchronous socket IO. Have a look at <a href="http://squirl.nightmare.com/medusa/async%5Fsockets.html" rel="nofollow">this explanation</a>, which discusses the concept in low-level socket terms, and the related examples which are implemented in Python. That should point you in the right direc...
4
2009-04-22T08:16:13Z
[ "python", "sockets", "telnet" ]
Multiple simultaneous network connections - Telnet server, Python
776,120
<p>I'm currently writing a telnet server in Python. It's a content server. People would connect to the server via telnet, and be presented with text-only content.</p> <p>My problem is that the server would obviously need to support more than one simultaneous connection. The current implementation I have now supports o...
16
2009-04-22T08:03:44Z
776,314
<p>For a really easy win implement you solution using SocketServer &amp; the SocketServer.ThreadingMixIn</p> <p>have a look a this echo server example it looks quite similar to what you're doing anyway: <a href="http://www.oreillynet.com/onlamp/blog/2007/12/pymotw_socketserver.html" rel="nofollow">http://www.oreillyne...
2
2009-04-22T09:10:38Z
[ "python", "sockets", "telnet" ]
Multiple simultaneous network connections - Telnet server, Python
776,120
<p>I'm currently writing a telnet server in Python. It's a content server. People would connect to the server via telnet, and be presented with text-only content.</p> <p>My problem is that the server would obviously need to support more than one simultaneous connection. The current implementation I have now supports o...
16
2009-04-22T08:03:44Z
776,845
<p>Implemented in <a href="http://twistedmatrix.com/">twisted</a>:</p> <pre><code>from twisted.internet.protocol import Factory, Protocol from twisted.internet import reactor class SendContent(Protocol): def connectionMade(self): self.transport.write(self.factory.text) self.transport.loseConnectio...
16
2009-04-22T11:54:36Z
[ "python", "sockets", "telnet" ]
Multiple simultaneous network connections - Telnet server, Python
776,120
<p>I'm currently writing a telnet server in Python. It's a content server. People would connect to the server via telnet, and be presented with text-only content.</p> <p>My problem is that the server would obviously need to support more than one simultaneous connection. The current implementation I have now supports o...
16
2009-04-22T08:03:44Z
776,865
<p>If you want to do it in pure python (sans-twisted), you need to do some threading. If you havnt seen it before, check out: <a href="http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf" rel="nofollow">http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf</a></p> <p>around page 5/6 is an example that is...
0
2009-04-22T12:00:17Z
[ "python", "sockets", "telnet" ]
Multiple simultaneous network connections - Telnet server, Python
776,120
<p>I'm currently writing a telnet server in Python. It's a content server. People would connect to the server via telnet, and be presented with text-only content.</p> <p>My problem is that the server would obviously need to support more than one simultaneous connection. The current implementation I have now supports o...
16
2009-04-22T08:03:44Z
777,734
<p>First, buy Comer's books on <a href="http://www.cs.purdue.edu/homes/dec/netbooks.html" rel="nofollow">TCP/IP programming</a>. </p> <p>In those books, Comer will provide several alternative algorithms for servers. There are two standard approaches.</p> <ul> <li><p>Thread-per-request.</p></li> <li><p>Process-per-r...
0
2009-04-22T15:10:49Z
[ "python", "sockets", "telnet" ]
Multiple simultaneous network connections - Telnet server, Python
776,120
<p>I'm currently writing a telnet server in Python. It's a content server. People would connect to the server via telnet, and be presented with text-only content.</p> <p>My problem is that the server would obviously need to support more than one simultaneous connection. The current implementation I have now supports o...
16
2009-04-22T08:03:44Z
2,397,206
<p>Late for the reply, but with the only answers being Twisted or threads (ouch), I wanted to add an answer for MiniBoa. </p> <p><a href="http://code.google.com/p/miniboa/" rel="nofollow">http://code.google.com/p/miniboa/</a></p> <p>Twisted is great, but it's a rather large beast that may not be the best introduction...
3
2010-03-07T17:47:24Z
[ "python", "sockets", "telnet" ]
Multiple simultaneous network connections - Telnet server, Python
776,120
<p>I'm currently writing a telnet server in Python. It's a content server. People would connect to the server via telnet, and be presented with text-only content.</p> <p>My problem is that the server would obviously need to support more than one simultaneous connection. The current implementation I have now supports o...
16
2009-04-22T08:03:44Z
5,927,337
<p>Try MiniBoa server? It has exactly 0 dependencies, no twisted or other stuff needed. MiniBoa is a non-blocking async telnet server, single threaded, exactly what you need.</p> <p><a href="http://code.google.com/p/miniboa/" rel="nofollow">http://code.google.com/p/miniboa/</a></p>
1
2011-05-08T12:12:46Z
[ "python", "sockets", "telnet" ]
Multiple simultaneous network connections - Telnet server, Python
776,120
<p>I'm currently writing a telnet server in Python. It's a content server. People would connect to the server via telnet, and be presented with text-only content.</p> <p>My problem is that the server would obviously need to support more than one simultaneous connection. The current implementation I have now supports o...
16
2009-04-22T08:03:44Z
18,166,699
<p>Use threading and then add the handler into a function. The thread will call every time a request i made:</p> <p>Look at this</p> <pre><code> import socket # Import socket module import pygame import thread import threading,sys s = socket.socket() # Create a socket object host = socket.geth...
1
2013-08-10T21:53:34Z
[ "python", "sockets", "telnet" ]
Appengine - Possible to get an entity using only key string without model name?
776,324
<p>I want to be able to have a view that will act upon a number of different types of objects</p> <p>all the view will get is the key string eg:</p> <p>agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww</p> <p>without knowing the model type, is it possible to retrieve the entity from just that key string?</p> <p>thank...
3
2009-04-22T09:15:04Z
776,332
<p>If you design your models so they all use a common superclass it should be possible to retrieve your objects by using something like:</p> <pre><code>entity = CommonSuperclass.get('agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww') </code></pre>
1
2009-04-22T09:18:19Z
[ "python", "google-app-engine" ]