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, datetime "time gap" percentage | 2,489,513 | <p>Assume I have these datatime variables:</p>
<pre><code>start_time, end_time, current_time
</code></pre>
<p>I would like to know how much time left as percentage by checking <code>current_time</code> and the time delta between <code>start_time</code> and the <code>end_time</code></p>
<p>IE: Assume the interval is ... | 3 | 2010-03-22T01:17:59Z | 2,489,591 | <p>Possibly simplest:</p>
<pre><code>import time
def t(dt):
return time.mktime(dt.timetuple())
def percent(start_time, end_time, current_time):
total = t(end_time) - t(start_time)
current = t(current_time) - t(start_time)
return (100.0 * current) / total
</code></pre>
| 1 | 2010-03-22T01:46:33Z | [
"python",
"datetime",
"timedelta"
] |
Python, datetime "time gap" percentage | 2,489,513 | <p>Assume I have these datatime variables:</p>
<pre><code>start_time, end_time, current_time
</code></pre>
<p>I would like to know how much time left as percentage by checking <code>current_time</code> and the time delta between <code>start_time</code> and the <code>end_time</code></p>
<p>IE: Assume the interval is ... | 3 | 2010-03-22T01:17:59Z | 12,922,732 | <p>In Python 2.7.x, time delta has a method total_seconds to achieve this:</p>
<pre><code>import datetime
startTime = datetime.datetime.now() - datetime.timedelta(hours=2)
endTime = datetime.datetime.now() + datetime.timedelta(hours=4)
rest = endTime - datetime.datetime.now()
total = endTime - startTime
print "left:... | 2 | 2012-10-16T20:18:06Z | [
"python",
"datetime",
"timedelta"
] |
importing same module more than once | 2,489,601 | <p>So after a few hours, I discovered the cause of a bug in my application. My app's source is structured like:</p>
<pre><code>main/
__init__.py
folderA/
__init__.py
fileA.py
fileB.py
</code></pre>
<p>Really, there are about 50 more files. But that's not the point. In <code>main/__init... | 3 | 2010-03-22T01:51:07Z | 2,489,607 | <p>Don't modify sys.path this way, as it provides two ways (names) to access your modules, leading to your problem.</p>
<p>Use absolute or <a href="http://www.python.org/dev/peps/pep-0328/" rel="nofollow">unambiguous-relative imports</a> instead. (The ambiguous-relative imports can be used as a last resort with older... | 4 | 2010-03-22T01:57:48Z | [
"python",
"import",
"import-hooks"
] |
importing same module more than once | 2,489,601 | <p>So after a few hours, I discovered the cause of a bug in my application. My app's source is structured like:</p>
<pre><code>main/
__init__.py
folderA/
__init__.py
fileA.py
fileB.py
</code></pre>
<p>Really, there are about 50 more files. But that's not the point. In <code>main/__init... | 3 | 2010-03-22T01:51:07Z | 2,489,609 | <ul>
<li><p>Modifying <code>sys.path</code> isn't something you do in a real program. It hurts modularity and portability with no gain over setting PYTHONPATH permanently or putting your module in a place Python can find it.</p></li>
<li><p>Never ever ever ever use <code>import *</code>. It pollutes your namespace and ... | 5 | 2010-03-22T01:58:06Z | [
"python",
"import",
"import-hooks"
] |
Tricky model inheritance - Django | 2,489,620 | <p>I think this is a bit tricky, at least for me. :)</p>
<p>So I have 4 models <strong>Person</strong>, <strong>Singer</strong>, <strong>Bassist</strong> and <strong>Ninja</strong>.</p>
<p>Singer, Bassist and Ninja inherit from Person.</p>
<hr>
<p>The problem is that each Person can be any of its subclasses. </p>
... | 14 | 2010-03-22T02:01:42Z | 2,489,645 | <p>Multiple inheritance doesn't work well with databases (and your Django models do need to map down to a database in the end), and inheritance is often a bad way to model "roles" (because people's roles do change). I would have Singer, Bassist and Ninja as "roles", <strong>not</strong> as subclasses of Person, and co... | 15 | 2010-03-22T02:09:11Z | [
"python",
"django",
"inheritance",
"django-models",
"django-orm"
] |
Tricky model inheritance - Django | 2,489,620 | <p>I think this is a bit tricky, at least for me. :)</p>
<p>So I have 4 models <strong>Person</strong>, <strong>Singer</strong>, <strong>Bassist</strong> and <strong>Ninja</strong>.</p>
<p>Singer, Bassist and Ninja inherit from Person.</p>
<hr>
<p>The problem is that each Person can be any of its subclasses. </p>
... | 14 | 2010-03-22T02:01:42Z | 2,489,866 | <p>I agree about the roles solution, as depicted by Alex. What you have is not different subclasses of persons. You have different roles a person can have.</p>
<p>But I hear you say: "hey, the ninja can have a property "numberOfStars", while a singer can have a property "highestNote". Same as for the interface: a ninj... | 2 | 2010-03-22T03:20:34Z | [
"python",
"django",
"inheritance",
"django-models",
"django-orm"
] |
Tricky model inheritance - Django | 2,489,620 | <p>I think this is a bit tricky, at least for me. :)</p>
<p>So I have 4 models <strong>Person</strong>, <strong>Singer</strong>, <strong>Bassist</strong> and <strong>Ninja</strong>.</p>
<p>Singer, Bassist and Ninja inherit from Person.</p>
<hr>
<p>The problem is that each Person can be any of its subclasses. </p>
... | 14 | 2010-03-22T02:01:42Z | 2,492,290 | <p>In principle you can do something like the following:</p>
<pre><code>class Role(models.Model):
......
class Ninja(Role):
.......
class Person(models.Model):
roles = models.ManyToManyField(Role)
</code></pre>
<p>But then you run in to the problem that Person.roles.objects.all() can only giv... | 3 | 2010-03-22T12:53:39Z | [
"python",
"django",
"inheritance",
"django-models",
"django-orm"
] |
Tricky model inheritance - Django | 2,489,620 | <p>I think this is a bit tricky, at least for me. :)</p>
<p>So I have 4 models <strong>Person</strong>, <strong>Singer</strong>, <strong>Bassist</strong> and <strong>Ninja</strong>.</p>
<p>Singer, Bassist and Ninja inherit from Person.</p>
<hr>
<p>The problem is that each Person can be any of its subclasses. </p>
... | 14 | 2010-03-22T02:01:42Z | 16,554,051 | <p>You could make all your professions (Ninja, Bassist....) inherit from <strong>Person</strong> in the models, and then use the function <strong>isinstance</strong> in the backend code to distinguish between the professions of a <strong>Person</strong>.</p>
| 1 | 2013-05-14T22:44:49Z | [
"python",
"django",
"inheritance",
"django-models",
"django-orm"
] |
Using QTDesigner with PyQT and Python 2.6 | 2,489,643 | <p>I'm new to Python and am starting to teach myself GUI programming (hopefully) using PyQT4.7 and Python 2.6</p>
<p>I just downloaded the whole PyQT/QT4 package (including QTDesigner) from the PyQT website, however it seems QTDesigner, which looks amazing to use as a newbie (since you can see all the attributes/prope... | 20 | 2010-03-22T02:08:09Z | 2,494,652 | <p>You can run <code>pyuic</code> (or rather <code>pyuic4</code>) from hand, in your console. You can make your GUI using designer with Python, just as you would do it with C++.</p>
<p>By the way: I have written all GUI stuff for my app (10k of code) by hand. I don't really like GUI designers and working with generate... | 1 | 2010-03-22T18:11:49Z | [
"python",
"qt4",
"pyqt4",
"qt-designer"
] |
Using QTDesigner with PyQT and Python 2.6 | 2,489,643 | <p>I'm new to Python and am starting to teach myself GUI programming (hopefully) using PyQT4.7 and Python 2.6</p>
<p>I just downloaded the whole PyQT/QT4 package (including QTDesigner) from the PyQT website, however it seems QTDesigner, which looks amazing to use as a newbie (since you can see all the attributes/prope... | 20 | 2010-03-22T02:08:09Z | 2,506,843 | <p>I started to write my first PyQT application (PyQT is used only to handle GUI), and it seems, that good toolchain is: QtDesigner to generate .ui s and handle resources and some IDE, that can set QtDesigner to edit those. I use Eclipse, cause it is highly customisable.
You can compile your .qrc and .ui by demand by d... | 19 | 2010-03-24T10:27:06Z | [
"python",
"qt4",
"pyqt4",
"qt-designer"
] |
Using QTDesigner with PyQT and Python 2.6 | 2,489,643 | <p>I'm new to Python and am starting to teach myself GUI programming (hopefully) using PyQT4.7 and Python 2.6</p>
<p>I just downloaded the whole PyQT/QT4 package (including QTDesigner) from the PyQT website, however it seems QTDesigner, which looks amazing to use as a newbie (since you can see all the attributes/prope... | 20 | 2010-03-22T02:08:09Z | 3,595,979 | <p>QtDesigner uses <code>uic.exe</code> to generate on the fly C++ code. <code>uic.exe</code> is a command-line tool, it gets file names as input parameters. For integration with python, you can write a python program that uses <code>pyuic.py</code>, match it inputs with <code>uic.exe</code>'s input (order, switchs etc... | 0 | 2010-08-29T18:15:06Z | [
"python",
"qt4",
"pyqt4",
"qt-designer"
] |
Using QTDesigner with PyQT and Python 2.6 | 2,489,643 | <p>I'm new to Python and am starting to teach myself GUI programming (hopefully) using PyQT4.7 and Python 2.6</p>
<p>I just downloaded the whole PyQT/QT4 package (including QTDesigner) from the PyQT website, however it seems QTDesigner, which looks amazing to use as a newbie (since you can see all the attributes/prope... | 20 | 2010-03-22T02:08:09Z | 13,461,481 | <p>What I did was I made my own uic executable that's a wrapper for the pyuic.py script.</p>
<p>You'll need... </p>
<ol>
<li><p>To get and install <a href="http://www.py2exe.org/" rel="nofollow">py2exe</a></p></li>
<li><p>Replace PYTHON_PATH in the uic.py code below</p></li>
<li><p>Edit the qt.conf file in the site-p... | 2 | 2012-11-19T20:16:49Z | [
"python",
"qt4",
"pyqt4",
"qt-designer"
] |
Function parameter types in Python | 2,489,669 | <p>Unless I'm mistaken, creating a function in Python works like this:</p>
<pre><code>def my_func(param1, param2):
# stuff
</code></pre>
<p>However, you don't actually give the types of those parameters. Also, if I remember, Python is a strongly typed language, as such, it seems like Python shouldn't let you pass... | 76 | 2010-03-22T02:17:20Z | 2,489,678 | <p>Python is not strongly typed in the sense of static or compile-time type checking.</p>
<p>Most Python code falls under so-called <a href="http://en.wikipedia.org/wiki/Duck_typing">"Duck Typing"</a> -- for example, you look for a method <code>read</code> on an object -- you don't care if the object is a file on disk... | 7 | 2010-03-22T02:20:17Z | [
"python",
"function",
"parameters"
] |
Function parameter types in Python | 2,489,669 | <p>Unless I'm mistaken, creating a function in Python works like this:</p>
<pre><code>def my_func(param1, param2):
# stuff
</code></pre>
<p>However, you don't actually give the types of those parameters. Also, if I remember, Python is a strongly typed language, as such, it seems like Python shouldn't let you pass... | 76 | 2010-03-22T02:17:20Z | 2,489,690 | <p>You never specify the type; Python has the concept of <a href="http://en.wikipedia.org/wiki/Duck_typing" rel="nofollow">duck typing</a>; basically the code that processes the parameters will make certain assumptions about them - perhaps by calling certain methods that a parameter is expected to implement. If the par... | 2 | 2010-03-22T02:22:42Z | [
"python",
"function",
"parameters"
] |
Function parameter types in Python | 2,489,669 | <p>Unless I'm mistaken, creating a function in Python works like this:</p>
<pre><code>def my_func(param1, param2):
# stuff
</code></pre>
<p>However, you don't actually give the types of those parameters. Also, if I remember, Python is a strongly typed language, as such, it seems like Python shouldn't let you pass... | 76 | 2010-03-22T02:17:20Z | 2,489,691 | <p>You don't specify a type. The method will only fail (at runtime) if it tries to access attributes that are not defined on the parameters that are passed in.</p>
<p>So this simple function:</p>
<pre><code>def no_op(param1, param2):
pass
</code></pre>
<p>... will not fail no matter what two args are passed in.... | 12 | 2010-03-22T02:22:42Z | [
"python",
"function",
"parameters"
] |
Function parameter types in Python | 2,489,669 | <p>Unless I'm mistaken, creating a function in Python works like this:</p>
<pre><code>def my_func(param1, param2):
# stuff
</code></pre>
<p>However, you don't actually give the types of those parameters. Also, if I remember, Python is a strongly typed language, as such, it seems like Python shouldn't let you pass... | 76 | 2010-03-22T02:17:20Z | 2,489,692 | <p>Python doesn't care what you pass in to its functions. When you call my_func(a,b), the param1 and param2 variables will then hold the values of a and b. Python doesn't know that you are calling the function with the proper types, and excepts the programmer to take care of that. If your function will be called with d... | 3 | 2010-03-22T02:23:21Z | [
"python",
"function",
"parameters"
] |
Function parameter types in Python | 2,489,669 | <p>Unless I'm mistaken, creating a function in Python works like this:</p>
<pre><code>def my_func(param1, param2):
# stuff
</code></pre>
<p>However, you don't actually give the types of those parameters. Also, if I remember, Python is a strongly typed language, as such, it seems like Python shouldn't let you pass... | 76 | 2010-03-22T02:17:20Z | 2,489,693 | <p>As <a href="http://stackoverflow.com/questions/1549801/differences-between-isinstance-and-type-in-python/1549854#1549854">Alex Martelli explains</a>,</p>
<blockquote>
<p>The normal, Pythonic, preferred solution is almost invariably "duck typing": try using the argument as if it was of a certain desired type, do i... | 3 | 2010-03-22T02:23:41Z | [
"python",
"function",
"parameters"
] |
Function parameter types in Python | 2,489,669 | <p>Unless I'm mistaken, creating a function in Python works like this:</p>
<pre><code>def my_func(param1, param2):
# stuff
</code></pre>
<p>However, you don't actually give the types of those parameters. Also, if I remember, Python is a strongly typed language, as such, it seems like Python shouldn't let you pass... | 76 | 2010-03-22T02:17:20Z | 2,489,718 | <p>Python is strongly typed because every object <em>has</em> a type, every object <em>knows</em> its type, it's impossible to accidentally or deliberately use an object of a type "as if" it was an object of a <em>different</em> type, and all elementary operations on the object are delegated to its type.</p>
<p>This h... | 73 | 2010-03-22T02:33:15Z | [
"python",
"function",
"parameters"
] |
Function parameter types in Python | 2,489,669 | <p>Unless I'm mistaken, creating a function in Python works like this:</p>
<pre><code>def my_func(param1, param2):
# stuff
</code></pre>
<p>However, you don't actually give the types of those parameters. Also, if I remember, Python is a strongly typed language, as such, it seems like Python shouldn't let you pass... | 76 | 2010-03-22T02:17:20Z | 2,490,474 | <p>In python everything has a type. Python function will do anything it is asked to do if the type of arguments support it.</p>
<p>Example: <code>foo</code> will add everything that can be <code>__add__</code>ed ;) without worrying much about its type. So that means ,to avoid failure ,you should provide only those thi... | 1 | 2010-03-22T07:04:09Z | [
"python",
"function",
"parameters"
] |
Function parameter types in Python | 2,489,669 | <p>Unless I'm mistaken, creating a function in Python works like this:</p>
<pre><code>def my_func(param1, param2):
# stuff
</code></pre>
<p>However, you don't actually give the types of those parameters. Also, if I remember, Python is a strongly typed language, as such, it seems like Python shouldn't let you pass... | 76 | 2010-03-22T02:17:20Z | 2,569,441 | <p>Many languages have variables, which are of a specific type and have a value. Python does not have variables; it has objects, and you use names to refer to these objects.</p>
<p>In other languages, when you say:</p>
<pre><code>a = 1
</code></pre>
<p>then a (typically integer) variable changes its contents to the ... | 4 | 2010-04-02T22:03:01Z | [
"python",
"function",
"parameters"
] |
Function parameter types in Python | 2,489,669 | <p>Unless I'm mistaken, creating a function in Python works like this:</p>
<pre><code>def my_func(param1, param2):
# stuff
</code></pre>
<p>However, you don't actually give the types of those parameters. Also, if I remember, Python is a strongly typed language, as such, it seems like Python shouldn't let you pass... | 76 | 2010-03-22T02:17:20Z | 21,384,492 | <p>The other answers have done a good job at explaining duck typing and the simple answer by tzot:</p>
<blockquote>
<p>Python does not have variables, like other languages where variables have a type and a value; it has names pointing to objects, which know their type.</p>
</blockquote>
<p><strong>However</strong>,... | 112 | 2014-01-27T15:16:18Z | [
"python",
"function",
"parameters"
] |
Function parameter types in Python | 2,489,669 | <p>Unless I'm mistaken, creating a function in Python works like this:</p>
<pre><code>def my_func(param1, param2):
# stuff
</code></pre>
<p>However, you don't actually give the types of those parameters. Also, if I remember, Python is a strongly typed language, as such, it seems like Python shouldn't let you pass... | 76 | 2010-03-22T02:17:20Z | 31,745,110 | <p>There's one notorious exception from the duck-typing worth mentioning on this page.</p>
<p>When <code>str</code> function calls <code>__str__</code> class method it subtly Ñhecks its type:</p>
<pre><code>>>> class A(object):
... def __str__(self):
... return 'a','b'
...
>>> a = A()
&... | 1 | 2015-07-31T11:30:15Z | [
"python",
"function",
"parameters"
] |
how to do asynchronous http requests with epoll and python 3.1 | 2,489,780 | <p><strong>UPDATE: after much laboring with Py3, including writing my own asynchronous webserver (following a presentation given by Dave Beazley), i finally dumped Python (and a huge stack of my code )-: in favor of <a href="http://coffeescript.org/" rel="nofollow">CoffeeScript</a> running on <a href="http://nodejs.org... | 3 | 2010-03-22T02:54:53Z | 2,489,818 | <p>In <a href="http://www.mail-archive.com/python-bugs-list@python.org/msg61273.html" rel="nofollow">this poll</a>, months ago, Giampaolo Rodolá said</p>
<blockquote>
<p>I have a patch for adding epoll()
support which is almost ready
(asyncore supports poll(), not
epoll()), it's just a matter of
writing tes... | 0 | 2010-03-22T03:07:02Z | [
"python",
"http",
"asynchronous",
"python-3.x",
"nonblocking"
] |
how to do asynchronous http requests with epoll and python 3.1 | 2,489,780 | <p><strong>UPDATE: after much laboring with Py3, including writing my own asynchronous webserver (following a presentation given by Dave Beazley), i finally dumped Python (and a huge stack of my code )-: in favor of <a href="http://coffeescript.org/" rel="nofollow">CoffeeScript</a> running on <a href="http://nodejs.org... | 3 | 2010-03-22T02:54:53Z | 2,511,360 | <p>Python 3 lacks libraries. You seem interested in libraries to help you do stuff, so why exactly are you using python 3 to solve your problem?</p>
| -2 | 2010-03-24T20:59:07Z | [
"python",
"http",
"asynchronous",
"python-3.x",
"nonblocking"
] |
how to do asynchronous http requests with epoll and python 3.1 | 2,489,780 | <p><strong>UPDATE: after much laboring with Py3, including writing my own asynchronous webserver (following a presentation given by Dave Beazley), i finally dumped Python (and a huge stack of my code )-: in favor of <a href="http://coffeescript.org/" rel="nofollow">CoffeeScript</a> running on <a href="http://nodejs.org... | 3 | 2010-03-22T02:54:53Z | 2,635,124 | <p>FWIW, I have a library at:
<a href="http://github.com/mnot/nbhttp/" rel="nofollow">http://github.com/mnot/nbhttp/</a></p>
<p>The client side is in production as part of redbot.org.</p>
<p>I haven't tried it in Python 3, but it may help as a basis for your work.</p>
<p>Cheers,</p>
| 0 | 2010-04-14T05:42:33Z | [
"python",
"http",
"asynchronous",
"python-3.x",
"nonblocking"
] |
how to do asynchronous http requests with epoll and python 3.1 | 2,489,780 | <p><strong>UPDATE: after much laboring with Py3, including writing my own asynchronous webserver (following a presentation given by Dave Beazley), i finally dumped Python (and a huge stack of my code )-: in favor of <a href="http://coffeescript.org/" rel="nofollow">CoffeeScript</a> running on <a href="http://nodejs.org... | 3 | 2010-03-22T02:54:53Z | 15,191,853 | <p>circuits has support for epoll and includes an async )#50 client.</p>
<p><a href="http://circuitsframework.com/" rel="nofollow">http://circuitsframework.com/</a></p>
| 0 | 2013-03-03T22:46:55Z | [
"python",
"http",
"asynchronous",
"python-3.x",
"nonblocking"
] |
Best/Fastest Way to Test Python CGI locally? | 2,490,150 | <p>Just wondering whats the best way to test Python CGI while developing a site?
(I'm used to PHP for web dev so bear with me :P)</p>
| 0 | 2010-03-22T05:27:45Z | 2,490,241 | <p>There are a number of Python web frameworks which make this easier for you. Django, for example, has a built-in web server designed for testing out your application.</p>
<p>However, if you're already using CGI, the easiest way to test it would be to run Apache. Configuring CGI for Apache is straightforward and th... | 0 | 2010-03-22T05:54:25Z | [
"python",
"cgi"
] |
Best/Fastest Way to Test Python CGI locally? | 2,490,150 | <p>Just wondering whats the best way to test Python CGI while developing a site?
(I'm used to PHP for web dev so bear with me :P)</p>
| 0 | 2010-03-22T05:27:45Z | 2,490,305 | <p>The Python standard library's <a href="http://docs.python.org/library/cgihttpserver.html">CGIHTTPServer</a> module is a simple, quick-and-dirty way to locally test CGI scripts!</p>
| 6 | 2010-03-22T06:13:33Z | [
"python",
"cgi"
] |
Parse http GET and POST parameters from BaseHTTPHandler? | 2,490,162 | <p>BaseHTTPHandler from the BaseHTTPServer module doesn't seem to provide any convenient way to access http request parameters. What is the best way to parse the GET parameters from the path, and the POST parameters from the request body?</p>
<p>Right now, I'm using this for GET:</p>
<pre><code>def do_GET(self):
... | 20 | 2010-03-22T05:32:24Z | 2,490,175 | <p>You could try the <a href="http://werkzeug.pocoo.org/documentation/dev/utils.html#werkzeug.url_decode" rel="nofollow">Werkzeug</a> modules, the base Werkzeug library isn't too large and if needed you can simply extract this bit of code and you're done.</p>
<p>The <code>url_decode</code> method returns a MultiDict a... | 5 | 2010-03-22T05:37:29Z | [
"python",
"http",
"basehttpserver"
] |
Parse http GET and POST parameters from BaseHTTPHandler? | 2,490,162 | <p>BaseHTTPHandler from the BaseHTTPServer module doesn't seem to provide any convenient way to access http request parameters. What is the best way to parse the GET parameters from the path, and the POST parameters from the request body?</p>
<p>Right now, I'm using this for GET:</p>
<pre><code>def do_GET(self):
... | 20 | 2010-03-22T05:32:24Z | 2,490,207 | <p>Have you investigated using libraries like <a href="http://www.cherrypy.org/" rel="nofollow">CherryPy</a>? They provide a much quicker path to handling these things than BaseHTTPServer.</p>
| 2 | 2010-03-22T05:46:13Z | [
"python",
"http",
"basehttpserver"
] |
Parse http GET and POST parameters from BaseHTTPHandler? | 2,490,162 | <p>BaseHTTPHandler from the BaseHTTPServer module doesn't seem to provide any convenient way to access http request parameters. What is the best way to parse the GET parameters from the path, and the POST parameters from the request body?</p>
<p>Right now, I'm using this for GET:</p>
<pre><code>def do_GET(self):
... | 20 | 2010-03-22T05:32:24Z | 2,490,321 | <p>Basic HTTP request parameters support is provided in the <a href="http://docs.python.org/library/cgi.html#module-cgi" rel="nofollow"><code>CGI</code> module</a>.
The recommended mechanism to handle form data is the <code>cgi.FieldStorage</code> class.</p>
<blockquote>
<p>To get at submitted form data, itâs best... | 2 | 2010-03-22T06:19:22Z | [
"python",
"http",
"basehttpserver"
] |
Parse http GET and POST parameters from BaseHTTPHandler? | 2,490,162 | <p>BaseHTTPHandler from the BaseHTTPServer module doesn't seem to provide any convenient way to access http request parameters. What is the best way to parse the GET parameters from the path, and the POST parameters from the request body?</p>
<p>Right now, I'm using this for GET:</p>
<pre><code>def do_GET(self):
... | 20 | 2010-03-22T05:32:24Z | 7,168,126 | <p>You may want to use <a href="https://docs.python.org/2/library/urlparse.html?highlight=urlparse#urlparse.parse_qs" rel="nofollow" title="urlparse.parse_qs">urlparse.parse_qs</a>:</p>
<pre><code>>>> from urlparse import urlparse, parse_qs
>>> url = 'http://example.com/?foo=bar&one=1'
>>&g... | 64 | 2011-08-23T22:04:28Z | [
"python",
"http",
"basehttpserver"
] |
Parse http GET and POST parameters from BaseHTTPHandler? | 2,490,162 | <p>BaseHTTPHandler from the BaseHTTPServer module doesn't seem to provide any convenient way to access http request parameters. What is the best way to parse the GET parameters from the path, and the POST parameters from the request body?</p>
<p>Right now, I'm using this for GET:</p>
<pre><code>def do_GET(self):
... | 20 | 2010-03-22T05:32:24Z | 31,363,982 | <p>Better solution to an old question:</p>
<pre><code>def do_POST(self):
length = int(self.headers.getheader('content-length'))
field_data = self.rfile.read(length)
fields = urlparse.parse_qs(field_data)
</code></pre>
<p>This will pull urlencoded POST data from the document content and parse it a dict wit... | 4 | 2015-07-12T03:03:43Z | [
"python",
"http",
"basehttpserver"
] |
Detect user logout / shutdown in Python / GTK under Linux - SIGTERM/HUP not received | 2,490,166 | <p>OK this is presumably a hard one, I've got an pyGTK application that has random crashes due to X Window errors that I can't catch/control.</p>
<p>So I created a wrapper that restarts the app as soon as it detects a crash, now comes the problem, when the user logs out or shuts down the system, the app exits with sta... | 4 | 2010-03-22T05:32:59Z | 2,491,901 | <p>You forgot to close gtk's event loop.</p>
<p>This code exits with code <code>0</code> when you close the window:</p>
<pre><code>import gtk
class Test(gtk.Window):
def destroy_event(self, widget, data=None):
gtk.main_quit()
def __init__(self):
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)... | 0 | 2010-03-22T11:50:29Z | [
"python",
"linux",
"gtk",
"pygtk",
"sigterm"
] |
Detect user logout / shutdown in Python / GTK under Linux - SIGTERM/HUP not received | 2,490,166 | <p>OK this is presumably a hard one, I've got an pyGTK application that has random crashes due to X Window errors that I can't catch/control.</p>
<p>So I created a wrapper that restarts the app as soon as it detects a crash, now comes the problem, when the user logs out or shuts down the system, the app exits with sta... | 4 | 2010-03-22T05:32:59Z | 2,519,829 | <p>OK, I finally found the solution :)</p>
<p>You simply can't rely on signals in this case. You have to connect to the Desktop Session in order to get notified that a logout is going to happen.</p>
<pre><code>import gnome.ui
gnome.program_init('Program', self.version) # This is going to trigger a warning that progr... | 1 | 2010-03-25T22:18:50Z | [
"python",
"linux",
"gtk",
"pygtk",
"sigterm"
] |
Performance Wise, Python VS JAVA For File Based Processing | 2,490,291 | <p>I need to create daemon that will monitor certain directory and will process every file that's written to that particular path.
My choice is either java or python.
Did you guys have any experience using both technology? what is the best one?</p>
<p>EDIT 1: files that will be processed is simple text file (one line... | 1 | 2010-03-22T06:07:45Z | 2,490,299 | <p>Performance-wise, for an I/O - syscall bound task such as you're mentioning, it's going to be a wash, most likely, depending a bit on the platform. Java tends to have better CPU usage (partly because a JVM can effectively use multiple cores on a multicore CPU on different threads, with CPython having problems with ... | 0 | 2010-03-22T06:11:33Z | [
"java",
"python",
"file-io"
] |
Simple way to encode a string according to a password? | 2,490,334 | <p>Does Python have a built-in, simple way of encoding/decoding strings using a password?</p>
<p>Something like this:</p>
<pre><code>>>> encode('John Doe', password = 'mypass')
'sjkl28cn2sx0'
>>> decode('sjkl28cn2sx0', password = 'mypass')
'John Doe'
</code></pre>
<p>So the string "John Doe" gets e... | 35 | 2010-03-22T06:23:04Z | 2,490,348 | <p>Simple way is using the library, and <a href="http://www.dlitz.net/software/pycrypto/" rel="nofollow">PyCrypto</a> is the good one.</p>
| 2 | 2010-03-22T06:27:09Z | [
"python",
"encryption",
"passwords"
] |
Simple way to encode a string according to a password? | 2,490,334 | <p>Does Python have a built-in, simple way of encoding/decoding strings using a password?</p>
<p>Something like this:</p>
<pre><code>>>> encode('John Doe', password = 'mypass')
'sjkl28cn2sx0'
>>> decode('sjkl28cn2sx0', password = 'mypass')
'John Doe'
</code></pre>
<p>So the string "John Doe" gets e... | 35 | 2010-03-22T06:23:04Z | 2,490,354 | <p><strike>If you are using passwords, it's best to do it right (especially if you are dealing with user passwords).</p>
<p>What you want to do is "encrypt" the password, not encode.</p>
<p>You have two choices on how you can do this, depending on who is doign the encrypting.</p>
<p>If its a trusted thirdparty, use ... | 0 | 2010-03-22T06:29:26Z | [
"python",
"encryption",
"passwords"
] |
Simple way to encode a string according to a password? | 2,490,334 | <p>Does Python have a built-in, simple way of encoding/decoding strings using a password?</p>
<p>Something like this:</p>
<pre><code>>>> encode('John Doe', password = 'mypass')
'sjkl28cn2sx0'
>>> decode('sjkl28cn2sx0', password = 'mypass')
'John Doe'
</code></pre>
<p>So the string "John Doe" gets e... | 35 | 2010-03-22T06:23:04Z | 2,490,376 | <p>As you explicitly state that you want obscurity not security, we'll avoid reprimanding you for the weakness of what you suggest :)</p>
<p>So, using PyCrypto:</p>
<pre><code>from Crypto.Cipher import AES
import base64
msg_text = 'test some plain text here'.rjust(32)
secret_key = '1234567890123456' # create new &am... | 26 | 2010-03-22T06:34:51Z | [
"python",
"encryption",
"passwords"
] |
Simple way to encode a string according to a password? | 2,490,334 | <p>Does Python have a built-in, simple way of encoding/decoding strings using a password?</p>
<p>Something like this:</p>
<pre><code>>>> encode('John Doe', password = 'mypass')
'sjkl28cn2sx0'
>>> decode('sjkl28cn2sx0', password = 'mypass')
'John Doe'
</code></pre>
<p>So the string "John Doe" gets e... | 35 | 2010-03-22T06:23:04Z | 2,490,413 | <p>External libraries provide secret-key encryption algorithms.</p>
<p>For example, the <a href="http://www.dlitz.net/software/pycrypto/apidoc/Crypto.Cipher-module.html" rel="nofollow"><code>Cypher</code> module in PyCrypto</a> offers a selection of many encryption algorithms:</p>
<ul>
<li><code>Crypto.Cipher.AES</co... | 0 | 2010-03-22T06:47:53Z | [
"python",
"encryption",
"passwords"
] |
Simple way to encode a string according to a password? | 2,490,334 | <p>Does Python have a built-in, simple way of encoding/decoding strings using a password?</p>
<p>Something like this:</p>
<pre><code>>>> encode('John Doe', password = 'mypass')
'sjkl28cn2sx0'
>>> decode('sjkl28cn2sx0', password = 'mypass')
'John Doe'
</code></pre>
<p>So the string "John Doe" gets e... | 35 | 2010-03-22T06:23:04Z | 2,490,561 | <p>This works but password length should be exactly <code>8</code>. This is simple and requires <a href="http://twhiteman.netfirms.com/des.html" rel="nofollow">pyDes</a>.</p>
<pre><code>from pyDes import *
def encode(data,password):
k = des(password, CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
d = k... | 2 | 2010-03-22T07:28:55Z | [
"python",
"encryption",
"passwords"
] |
Simple way to encode a string according to a password? | 2,490,334 | <p>Does Python have a built-in, simple way of encoding/decoding strings using a password?</p>
<p>Something like this:</p>
<pre><code>>>> encode('John Doe', password = 'mypass')
'sjkl28cn2sx0'
>>> decode('sjkl28cn2sx0', password = 'mypass')
'John Doe'
</code></pre>
<p>So the string "John Doe" gets e... | 35 | 2010-03-22T06:23:04Z | 2,490,718 | <p>Assuming you are <em>only</em> looking for simple obfuscation that will obscure things from the <em>very</em> casual observer, and you aren't looking to use third party libraries. I'd recommend something like the Vigenere cipher. It is one of the strongest of the simple ancient ciphers.</p>
<p><a href="https://en.w... | 18 | 2010-03-22T08:11:36Z | [
"python",
"encryption",
"passwords"
] |
Simple way to encode a string according to a password? | 2,490,334 | <p>Does Python have a built-in, simple way of encoding/decoding strings using a password?</p>
<p>Something like this:</p>
<pre><code>>>> encode('John Doe', password = 'mypass')
'sjkl28cn2sx0'
>>> decode('sjkl28cn2sx0', password = 'mypass')
'John Doe'
</code></pre>
<p>So the string "John Doe" gets e... | 35 | 2010-03-22T06:23:04Z | 14,139,906 | <p>if you want secure encryption:</p>
<p>for python 2, you should use keyczar <a href="http://www.keyczar.org/" rel="nofollow">http://www.keyczar.org/</a></p>
<p>for python 3, until keyczar is available, i have written simple-crypt <a href="http://pypi.python.org/pypi/simple-crypt" rel="nofollow">http://pypi.python.o... | 1 | 2013-01-03T13:30:32Z | [
"python",
"encryption",
"passwords"
] |
Simple way to encode a string according to a password? | 2,490,334 | <p>Does Python have a built-in, simple way of encoding/decoding strings using a password?</p>
<p>Something like this:</p>
<pre><code>>>> encode('John Doe', password = 'mypass')
'sjkl28cn2sx0'
>>> decode('sjkl28cn2sx0', password = 'mypass')
'John Doe'
</code></pre>
<p>So the string "John Doe" gets e... | 35 | 2010-03-22T06:23:04Z | 16,321,853 | <p>The "encoded_c" mentioned in the @smehmood's Vigenere cipher answer should be "key_c".</p>
<p>Here are working encode/decode functions.</p>
<pre><code>import base64
def encode(key, clear):
enc = []
for i in range(len(clear)):
key_c = key[i % len(key)]
enc_c = chr((ord(clear[i]) + ord(key_c)... | 20 | 2013-05-01T16:07:29Z | [
"python",
"encryption",
"passwords"
] |
Simple way to encode a string according to a password? | 2,490,334 | <p>Does Python have a built-in, simple way of encoding/decoding strings using a password?</p>
<p>Something like this:</p>
<pre><code>>>> encode('John Doe', password = 'mypass')
'sjkl28cn2sx0'
>>> decode('sjkl28cn2sx0', password = 'mypass')
'John Doe'
</code></pre>
<p>So the string "John Doe" gets e... | 35 | 2010-03-22T06:23:04Z | 21,754,610 | <p>As has been mentioned the PyCrypto library contains a suite of ciphers. The XOR cipher can be used to do the dirty work if you don't want to do it yourself:</p>
<pre><code>from Crypto.Cipher import XOR
import base64
def encrypt(key, plaintext):
cipher = XOR.new(key)
return base64.b64encode(cipher.encrypt(plain... | 9 | 2014-02-13T12:43:54Z | [
"python",
"encryption",
"passwords"
] |
Simple way to encode a string according to a password? | 2,490,334 | <p>Does Python have a built-in, simple way of encoding/decoding strings using a password?</p>
<p>Something like this:</p>
<pre><code>>>> encode('John Doe', password = 'mypass')
'sjkl28cn2sx0'
>>> decode('sjkl28cn2sx0', password = 'mypass')
'John Doe'
</code></pre>
<p>So the string "John Doe" gets e... | 35 | 2010-03-22T06:23:04Z | 35,626,761 | <p>Working encode/decode functions in python3 (adapted very little from qneill's answer):</p>
<pre><code>def encode(key, clear):
enc = []
for i in range(len(clear)):
key_c = key[i % len(key)]
enc_c = (ord(clear[i]) + ord(key_c)) % 256
enc.append(enc_c)
return base64.urlsafe_b64encod... | 2 | 2016-02-25T12:03:25Z | [
"python",
"encryption",
"passwords"
] |
Simple way to encode a string according to a password? | 2,490,334 | <p>Does Python have a built-in, simple way of encoding/decoding strings using a password?</p>
<p>Something like this:</p>
<pre><code>>>> encode('John Doe', password = 'mypass')
'sjkl28cn2sx0'
>>> decode('sjkl28cn2sx0', password = 'mypass')
'John Doe'
</code></pre>
<p>So the string "John Doe" gets e... | 35 | 2010-03-22T06:23:04Z | 38,078,130 | <p>An other implementation of @qneill code which include CRC checksum of the original message, it throw an exception if the check fail:</p>
<pre><code>import hashlib
import struct
import zlib
def vigenere_encode(text, key):
text = '{}{}'.format(text, struct.pack('i', zlib.crc32(text)))
enc = []
for i in ... | 0 | 2016-06-28T13:51:30Z | [
"python",
"encryption",
"passwords"
] |
Simple way to encode a string according to a password? | 2,490,334 | <p>Does Python have a built-in, simple way of encoding/decoding strings using a password?</p>
<p>Something like this:</p>
<pre><code>>>> encode('John Doe', password = 'mypass')
'sjkl28cn2sx0'
>>> decode('sjkl28cn2sx0', password = 'mypass')
'John Doe'
</code></pre>
<p>So the string "John Doe" gets e... | 35 | 2010-03-22T06:23:04Z | 38,223,403 | <p>Here's a Python 3 version of @qniell 's functions:</p>
<pre><code>import base64
def encode(key, clear):
enc = []
for i in range(len(clear)):
key_c = key[i % len(key)]
enc_c = chr((ord(clear[i]) + ord(key_c)) % 256)
enc.append(enc_c)
return base64.urlsafe_b64encode("".join(enc).en... | 5 | 2016-07-06T11:55:32Z | [
"python",
"encryption",
"passwords"
] |
Is it good to use Django 1.1 on App Engine? | 2,490,335 | <p>We are planning a web application to build on Google's <a href="http://en.wikipedia.org/wiki/Google_App_Engine" rel="nofollow">App Engine</a> platform.
Is it good to use the Django 1.1 framework to develop Google App Engine applications?</p>
<p>If not, could you please suggest me the best option available, which ha... | 3 | 2010-03-22T06:23:14Z | 2,490,398 | <p>Yes, Django 1.1 is well-supported on Google App Engine. You'll need to do your own installation thereof locally, to enable it in the GAE SDK -- but it's already there for you on the App Engine production servers, see <a href="http://code.google.com/appengine/docs/python/tools/libraries.html#Django" rel="nofollow">t... | 4 | 2010-03-22T06:42:09Z | [
"python",
"django",
"google-app-engine",
"gae-datastore"
] |
Is it good to use Django 1.1 on App Engine? | 2,490,335 | <p>We are planning a web application to build on Google's <a href="http://en.wikipedia.org/wiki/Google_App_Engine" rel="nofollow">App Engine</a> platform.
Is it good to use the Django 1.1 framework to develop Google App Engine applications?</p>
<p>If not, could you please suggest me the best option available, which ha... | 3 | 2010-03-22T06:23:14Z | 2,490,782 | <p>You should check out appenginepatch (http://code.google.com/p/app-engine-patch/) and django-nonrel (http://www.allbuttonspressed.com/projects/django-nonrel)</p>
<p>I'm using appenginepatch for my website (beta.fiddme.com) and its awesome (there's a full post on the technology stack we're using at <a href="http://w... | 0 | 2010-03-22T08:28:02Z | [
"python",
"django",
"google-app-engine",
"gae-datastore"
] |
Is it good to use Django 1.1 on App Engine? | 2,490,335 | <p>We are planning a web application to build on Google's <a href="http://en.wikipedia.org/wiki/Google_App_Engine" rel="nofollow">App Engine</a> platform.
Is it good to use the Django 1.1 framework to develop Google App Engine applications?</p>
<p>If not, could you please suggest me the best option available, which ha... | 3 | 2010-03-22T06:23:14Z | 2,493,089 | <p>You might also want to take a look at <a href="http://code.google.com/p/kay-framework/" rel="nofollow">Kay Framework</a>. It's based on Django with middleware and such. It is exclusively geared towards App Engine and uses <a href="http://werkzeug.pocoo.org/" rel="nofollow">Werkzeug</a> and <a href="http://jinja.poco... | 0 | 2010-03-22T14:46:20Z | [
"python",
"django",
"google-app-engine",
"gae-datastore"
] |
Is it good to use Django 1.1 on App Engine? | 2,490,335 | <p>We are planning a web application to build on Google's <a href="http://en.wikipedia.org/wiki/Google_App_Engine" rel="nofollow">App Engine</a> platform.
Is it good to use the Django 1.1 framework to develop Google App Engine applications?</p>
<p>If not, could you please suggest me the best option available, which ha... | 3 | 2010-03-22T06:23:14Z | 2,503,773 | <p>Google has developed a 'helper' project to aid with Django integration:
<a href="http://code.google.com/p/google-app-engine-django/" rel="nofollow">http://code.google.com/p/google-app-engine-django/</a></p>
<p>Also, you might check out this video where Guido walks through it:
<a href="http://sites.google.com/site/i... | 1 | 2010-03-23T21:29:16Z | [
"python",
"django",
"google-app-engine",
"gae-datastore"
] |
Use URL Fetch of Google App Engine just to call a php script | 2,490,592 | <p>I wanto call a PHP script using Google App Engine. I just want to execute the script. The script updates a couple of databases on my webhost. But I guess Google App waits for the response. Is there a way by which I can start the script.</p>
<p>The script takes some time and Google App might die during that time.</p... | 0 | 2010-03-22T07:36:58Z | 2,491,392 | <p>Can you not modify the PHP script to simply execute a background task, and return a 200 confirmation? In any case, if simply issuing a GET to that script will start a task, you can do that with AppEngine with an asynchronous URLFetch (http://code.google.com/appengine/docs/python/urlfetch/asynchronousrequests.html) a... | 2 | 2010-03-22T10:28:53Z | [
"python",
"google-app-engine"
] |
Use URL Fetch of Google App Engine just to call a php script | 2,490,592 | <p>I wanto call a PHP script using Google App Engine. I just want to execute the script. The script updates a couple of databases on my webhost. But I guess Google App waits for the response. Is there a way by which I can start the script.</p>
<p>The script takes some time and Google App might die during that time.</p... | 0 | 2010-03-22T07:36:58Z | 2,491,775 | <p>Why not rewrite what your php script does in python?
Php is a awful scripting language, and considering your thinking about calling it from inside a very powerful language, why not do it all in python</p>
| 0 | 2010-03-22T11:26:43Z | [
"python",
"google-app-engine"
] |
Use URL Fetch of Google App Engine just to call a php script | 2,490,592 | <p>I wanto call a PHP script using Google App Engine. I just want to execute the script. The script updates a couple of databases on my webhost. But I guess Google App waits for the response. Is there a way by which I can start the script.</p>
<p>The script takes some time and Google App might die during that time.</p... | 0 | 2010-03-22T07:36:58Z | 2,492,527 | <p>Just do a URLFetch request. If the PHP page takes longer than 10 seconds to return, that doesn't matter (presuming you don't care about the response) - it'll complete execution anyway.</p>
<p>If you wish, you can do an <a href="http://code.google.com/appengine/docs/python/urlfetch/asynchronousrequests.html" rel="no... | 1 | 2010-03-22T13:29:48Z | [
"python",
"google-app-engine"
] |
Enforce "spaces" or "tabs" only in python files? | 2,490,686 | <p>In Python, is there a mean to enforce the use of spaces or tabs indentation with a per file basis ? </p>
<p>Well, perhaps "enforce" is too strong, more like a "recommendation".</p>
<p>I keep receiving patch files with mixed indentation and this is annoying... (to say the least) Python itself can tell when there is... | 3 | 2010-03-22T08:04:26Z | 2,490,722 | <p>Look at the <a href="http://docs.python.org/library/tabnanny.html#module-tabnanny"><code>tabnanny</code></a> module: â Detection of ambiguous indentation.</p>
| 5 | 2010-03-22T08:12:38Z | [
"python",
"tabs",
"indentation",
"spaces"
] |
Enforce "spaces" or "tabs" only in python files? | 2,490,686 | <p>In Python, is there a mean to enforce the use of spaces or tabs indentation with a per file basis ? </p>
<p>Well, perhaps "enforce" is too strong, more like a "recommendation".</p>
<p>I keep receiving patch files with mixed indentation and this is annoying... (to say the least) Python itself can tell when there is... | 3 | 2010-03-22T08:04:26Z | 2,490,727 | <p>This is something your editor should do for you. Most editors (try Notepad++ for example, it's free) will let you set whether hitting tab enters a tab character or a number of spaces. I'd recommend using two spaces instead of tab in all files (I find 4 is too much). Using spaces instead of tabs is better as it means... | 2 | 2010-03-22T08:13:25Z | [
"python",
"tabs",
"indentation",
"spaces"
] |
Enforce "spaces" or "tabs" only in python files? | 2,490,686 | <p>In Python, is there a mean to enforce the use of spaces or tabs indentation with a per file basis ? </p>
<p>Well, perhaps "enforce" is too strong, more like a "recommendation".</p>
<p>I keep receiving patch files with mixed indentation and this is annoying... (to say the least) Python itself can tell when there is... | 3 | 2010-03-22T08:04:26Z | 2,490,905 | <p>As explicited in <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a>, never mix tabs and space. However, a file with both may just run...
As it says there:</p>
<blockquote>
<pre><code>The most popular way of indenting Python is with spaces only. The
second-most popular way is with tabs only... | 2 | 2010-03-22T09:00:22Z | [
"python",
"tabs",
"indentation",
"spaces"
] |
Enforce "spaces" or "tabs" only in python files? | 2,490,686 | <p>In Python, is there a mean to enforce the use of spaces or tabs indentation with a per file basis ? </p>
<p>Well, perhaps "enforce" is too strong, more like a "recommendation".</p>
<p>I keep receiving patch files with mixed indentation and this is annoying... (to say the least) Python itself can tell when there is... | 3 | 2010-03-22T08:04:26Z | 2,491,548 | <p>Tim Peters has written a nifty script called <a href="http://svn.python.org/projects/python/trunk/Tools/scripts/reindent.py" rel="nofollow">reindent.py</a> which converts .py files to use 4-space indents and no tabs. It is available <a href="http://svn.python.org/projects/python/trunk/Tools/scripts/reindent.py" rel=... | 10 | 2010-03-22T10:50:34Z | [
"python",
"tabs",
"indentation",
"spaces"
] |
Python/Django application with dynamic model name (application reuse) | 2,490,759 | <p>excuse me in advance if this is not the right title for the problem but here it is:
You have application that works with pre defined model. What happens if you want to
use this application one more time in your project but pointing to different model (same structure but differen name). </p>
<p>For example - you ha... | 1 | 2010-03-22T08:21:58Z | 2,491,022 | <p>This is what <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#abstract-base-classes" rel="nofollow">abstract models</a> are for. Define once, and all children will acquire the fields in the abstract model, plus be able to define additional fields.</p>
| 2 | 2010-03-22T09:22:35Z | [
"python",
"django",
"models",
"code-reuse"
] |
mysqldb python escaping ? or %s? | 2,490,852 | <p>Dear Everyone,
I am currently using mysqldb.</p>
<p>What is the correct way to escape strings in mysqldb arguments?</p>
<p>Note that <code>E = lambda x: x.encode('utf-8')</code>
1) so my connection is set with charset='utf8'.</p>
<p>These are the errors I am getting for these arguments: <code>w1, w2 = u'ä½ å¥½', ... | 4 | 2010-03-22T08:47:44Z | 2,490,873 | <p>You could use triple quotes and raw string format </p>
<pre><code>self.cur.execute(r"""SELECT dist FROM distance ... """,...)
</code></pre>
| 0 | 2010-03-22T08:54:16Z | [
"python",
"mysql"
] |
mysqldb python escaping ? or %s? | 2,490,852 | <p>Dear Everyone,
I am currently using mysqldb.</p>
<p>What is the correct way to escape strings in mysqldb arguments?</p>
<p>Note that <code>E = lambda x: x.encode('utf-8')</code>
1) so my connection is set with charset='utf8'.</p>
<p>These are the errors I am getting for these arguments: <code>w1, w2 = u'ä½ å¥½', ... | 4 | 2010-03-22T08:47:44Z | 2,491,046 | <p>When I remember it right, then you don't need to manually encode your unicode strings. The mysqldb module will do this for you.</p>
<p>And the mysqldb module uses <code>%s</code> as parameters instead of <code>?</code>. This is the reason for the error in your first example.</p>
| 1 | 2010-03-22T09:28:54Z | [
"python",
"mysql"
] |
mysqldb python escaping ? or %s? | 2,490,852 | <p>Dear Everyone,
I am currently using mysqldb.</p>
<p>What is the correct way to escape strings in mysqldb arguments?</p>
<p>Note that <code>E = lambda x: x.encode('utf-8')</code>
1) so my connection is set with charset='utf8'.</p>
<p>These are the errors I am getting for these arguments: <code>w1, w2 = u'ä½ å¥½', ... | 4 | 2010-03-22T08:47:44Z | 2,741,646 | <p>To be more specific ... the <code>cursor.execute()</code> method takes an optional argument which contains values to be quoted and interpolated into the SQL template/statement. This is NOT done with a simple <code>%</code> operator! <code>cursor.execute(some_sql, some_params)</code> is <em>NOT</em> the same as <co... | 4 | 2010-04-30T00:39:01Z | [
"python",
"mysql"
] |
How to read and write a file using python? | 2,491,141 | <p>I want to write the text (which I get from AJAX) to a file, and then read it.</p>
| 3 | 2010-03-22T09:47:56Z | 2,491,155 | <p>The tutorial <a href="http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files">covers this</a>.</p>
| 11 | 2010-03-22T09:51:35Z | [
"python",
"django"
] |
How to read and write a file using python? | 2,491,141 | <p>I want to write the text (which I get from AJAX) to a file, and then read it.</p>
| 3 | 2010-03-22T09:47:56Z | 2,491,160 | <pre><code>f = open( 'filename.txt', 'w+' )
f.write( 'text' )
f.close()
f = open( 'filename.txt', 'r' )
for line in f:
print( line )
f.close()
</code></pre>
| 3 | 2010-03-22T09:52:07Z | [
"python",
"django"
] |
How to read and write a file using python? | 2,491,141 | <p>I want to write the text (which I get from AJAX) to a file, and then read it.</p>
| 3 | 2010-03-22T09:47:56Z | 2,491,172 | <p>The following code for read the content from a file </p>
<pre><code>handle=open('file','r+')
var=handle.read()
print var
</code></pre>
<blockquote>
<p>If you want to read a single line use
the readline(). If you want to read
the whole lines in the file use
the readlines() also</p>
</blockquote>
<p>Th... | 3 | 2010-03-22T09:53:17Z | [
"python",
"django"
] |
How to read and write a file using python? | 2,491,141 | <p>I want to write the text (which I get from AJAX) to a file, and then read it.</p>
| 3 | 2010-03-22T09:47:56Z | 2,491,221 | <p>If you can use this in Django view... try somethink like this:</p>
<pre><code>def some_view(request):
text = request.POST.get("text", None)
if text is not None:
f = open( 'some_file.txt', 'w+')
f.write(text)
f.close()
return HttpResponse()
</code></pre>
| 6 | 2010-03-22T09:59:16Z | [
"python",
"django"
] |
Use string as input to re.compile | 2,491,196 | <p>I want to use a variable in a regex, like this:</p>
<pre><code>variables = ['variableA','variableB']
for i in range(len(variables)):
regex = r"'('+variables[i]+')[:|=|\(](-?\d+(?:\.\d+)?)(?:\))?'"
pattern_variable = re.compile(regex)
match = re.search(pattern_variable, line)
</code></pre>
<p>The probl... | 0 | 2010-03-22T09:55:03Z | 2,491,206 | <p>There is no problem there. What you're seeing is the output of the <code>repr()</code> of the string. Since the repr is supposed to be more-or-less reversible back into the original object, it doubles up all backslashes, as well as escaping the type of quote used at the ends of the repr.</p>
| 1 | 2010-03-22T09:56:56Z | [
"python",
"regex"
] |
Use string as input to re.compile | 2,491,196 | <p>I want to use a variable in a regex, like this:</p>
<pre><code>variables = ['variableA','variableB']
for i in range(len(variables)):
regex = r"'('+variables[i]+')[:|=|\(](-?\d+(?:\.\d+)?)(?:\))?'"
pattern_variable = re.compile(regex)
match = re.search(pattern_variable, line)
</code></pre>
<p>The probl... | 0 | 2010-03-22T09:55:03Z | 2,491,208 | <p>No, it only displays extra backslashes so that the string could be read in again and have the correct number of backslashes. Try</p>
<pre><code>print regex
</code></pre>
<p>and you will see the difference.</p>
| 2 | 2010-03-22T09:57:15Z | [
"python",
"regex"
] |
How to rename a file using Python | 2,491,222 | <p>I want to change <code>a.txt</code> to <code>b.kml</code>.</p>
| 36 | 2010-03-22T09:59:23Z | 2,491,231 | <pre><code>import shutil
shutil.move('a.txt', 'b.kml')
</code></pre>
<p>This will work to rename or move a file.</p>
| 18 | 2010-03-22T10:00:41Z | [
"python",
"file-rename"
] |
How to rename a file using Python | 2,491,222 | <p>I want to change <code>a.txt</code> to <code>b.kml</code>.</p>
| 36 | 2010-03-22T09:59:23Z | 2,491,232 | <p>Use <a href="http://docs.python.org/library/os.html#os.rename"><code>os.rename</code></a><code>('a.txt','b.kml')</code></p>
| 75 | 2010-03-22T10:00:52Z | [
"python",
"file-rename"
] |
How to rename a file using Python | 2,491,222 | <p>I want to change <code>a.txt</code> to <code>b.kml</code>.</p>
| 36 | 2010-03-22T09:59:23Z | 2,491,233 | <p><code>os.rename(old, new)</code></p>
<p>From <a href="http://docs.python.org/library/os.html">http://docs.python.org/library/os.html</a>. This really isn't hard to find...</p>
| 8 | 2010-03-22T10:00:55Z | [
"python",
"file-rename"
] |
How to rename a file using Python | 2,491,222 | <p>I want to change <code>a.txt</code> to <code>b.kml</code>.</p>
| 36 | 2010-03-22T09:59:23Z | 33,144,435 | <p>File may be inside the directory in that case specify the path <br/>
import os <br/>
old_file = "your derecoty path " +'/' + "a.txt" <br/>
new_file = "your derecoty path " +'/' + "b.kml" <br/>
os.rename(old_file,new_file)</p>
| 6 | 2015-10-15T09:15:07Z | [
"python",
"file-rename"
] |
How to rename a file using Python | 2,491,222 | <p>I want to change <code>a.txt</code> to <code>b.kml</code>.</p>
| 36 | 2010-03-22T09:59:23Z | 34,714,469 | <p>You can use os.system to invoke terminal to accomplish the task:</p>
<pre><code>os.system('mv oldfile newfile')
</code></pre>
| 1 | 2016-01-11T05:02:24Z | [
"python",
"file-rename"
] |
GAE, Python 2.5, Python 2.6 Side-by-side on windows | 2,491,280 | <p>On my development system, I have Python 2.6, Django 1.1 and GAE.</p>
<ul>
<li>I have three projects running on Python 2.6 and Django 1.1. </li>
<li>I have 1 project using GAE, Python 2.6 and Django 1.1. </li>
</ul>
<p>I have heard that my set-up for running GAE using Python 2.6 may create some head-scratching prob... | 2 | 2010-03-22T10:08:48Z | 2,491,293 | <p>Use <a href="http://virtualenv.openplans.org/" rel="nofollow">virtualenv</a> to isolate your development environments, so you can have one running 2.5 and the others running 2.6.</p>
<p>Edited to add: once 2.5 is installed, you can initialize your virtualenv to use it with the -p option:</p>
<pre><code>virtualenv ... | 1 | 2010-03-22T10:10:44Z | [
"python",
"django",
"google-app-engine"
] |
GAE, Python 2.5, Python 2.6 Side-by-side on windows | 2,491,280 | <p>On my development system, I have Python 2.6, Django 1.1 and GAE.</p>
<ul>
<li>I have three projects running on Python 2.6 and Django 1.1. </li>
<li>I have 1 project using GAE, Python 2.6 and Django 1.1. </li>
</ul>
<p>I have heard that my set-up for running GAE using Python 2.6 may create some head-scratching prob... | 2 | 2010-03-22T10:08:48Z | 2,491,639 | <p>Unless you are using python 2.6 specific syntax/code your application is safe to run on GAE.</p>
| 0 | 2010-03-22T11:06:37Z | [
"python",
"django",
"google-app-engine"
] |
GAE, Python 2.5, Python 2.6 Side-by-side on windows | 2,491,280 | <p>On my development system, I have Python 2.6, Django 1.1 and GAE.</p>
<ul>
<li>I have three projects running on Python 2.6 and Django 1.1. </li>
<li>I have 1 project using GAE, Python 2.6 and Django 1.1. </li>
</ul>
<p>I have heard that my set-up for running GAE using Python 2.6 may create some head-scratching prob... | 2 | 2010-03-22T10:08:48Z | 2,492,830 | <p>Re virtualenv question above: virtualenv have a parameter
<code>--python=PYTHON_EXE</code> that you can point to the interpreter you'd like
it to use. Running <code>virtualenv</code> without parameters or with an <code>--help</code>
option whill show you which options you may pass it.</p>
| 0 | 2010-03-22T14:12:16Z | [
"python",
"django",
"google-app-engine"
] |
why my code print this when i read and write | 2,491,511 | <pre><code>def sss(request):
handle=open('b.txt','r+')
handle.write("I AM NEW FILE")
var=handle.read();
return HttpResponse(var)
urlpatterns = patterns('',
('^$',sss),
)
</code></pre>
<p>1.my b.txt has nothing</p>
<p>2.when i run my code ,it print this :</p>
<pre><code>I AM NEW FILE7 ... | -2 | 2010-03-22T10:44:32Z | 2,491,590 | <p>The only way I can repro this is to open an existing non-empty file using <code>'r+'</code> (Are you absolutely sure it's empty?). In any event, opening the file in the <code>'w+'</code> mode truncates it.</p>
| 3 | 2010-03-22T10:57:49Z | [
"python",
"django"
] |
why my code print this when i read and write | 2,491,511 | <pre><code>def sss(request):
handle=open('b.txt','r+')
handle.write("I AM NEW FILE")
var=handle.read();
return HttpResponse(var)
urlpatterns = patterns('',
('^$',sss),
)
</code></pre>
<p>1.my b.txt has nothing</p>
<p>2.when i run my code ,it print this :</p>
<pre><code>I AM NEW FILE7 ... | -2 | 2010-03-22T10:44:32Z | 2,491,685 | <p>What middle-ware are you using? I guess that you have a lot of middle-ware installed, which explains some of the garbage.</p>
<p>For debugging, use a logging module to log what var was. Otherwise you can't isolate the problem, right?</p>
<p>Also, should you convert the string to unicode before sending it off to Ht... | 0 | 2010-03-22T11:13:20Z | [
"python",
"django"
] |
Find multiple regex in each line and skip result if one of the regex doesn't match | 2,491,778 | <p>I have a list of variables:</p>
<pre><code>variables = ['VariableA', 'VariableB','VariableC']
</code></pre>
<p>which I'm going to search for, line by line</p>
<pre><code>ifile = open("temp.txt",'r')
d = {}
match = zeros(len(variables))
for line in ifile:
emptyCells=0
for i in range(len(variables)):
... | 0 | 2010-03-22T11:27:30Z | 2,491,834 | <p>Can you edit your question to give an example of the source file, so we could test our solutions against it?</p>
<p>Anyway here's a quick hack:</p>
<pre><code>from collections import defaultdict
import re
variables = ['VariableA', 'VariableB', 'VariableC']
regexes = [re.compile(r'(%s)[:|=|\(](-?\d+(?:\.\d+)?)(?:\... | 1 | 2010-03-22T11:38:40Z | [
"python",
"regex"
] |
How to return a value from __init__ in Python? | 2,491,819 | <p>I have a class with an <code>__init__</code> function. </p>
<p>How can I return an integer value from this function when an object is created?</p>
<p>I wrote a program, where <code>__init__</code> does command line parsing and I need to have some value set. Is it OK set it in global variable and use it in other me... | 38 | 2010-03-22T11:35:10Z | 2,491,831 | <p><code>__init__</code> returns the newly created object. You cannot (or at least shouldn't) return something else.</p>
<p>Try making whatever you want to return an instance variable (or function).</p>
<pre><code>>>> class Foo:
... def __init__(self):
... return 42
...
>>> foo = Foo()
... | 43 | 2010-03-22T11:37:52Z | [
"python",
"class",
"init"
] |
How to return a value from __init__ in Python? | 2,491,819 | <p>I have a class with an <code>__init__</code> function. </p>
<p>How can I return an integer value from this function when an object is created?</p>
<p>I wrote a program, where <code>__init__</code> does command line parsing and I need to have some value set. Is it OK set it in global variable and use it in other me... | 38 | 2010-03-22T11:35:10Z | 2,491,843 | <p><code>__init__</code> doesn't return anything and should always return <code>None</code>.</p>
| 8 | 2010-03-22T11:39:51Z | [
"python",
"class",
"init"
] |
How to return a value from __init__ in Python? | 2,491,819 | <p>I have a class with an <code>__init__</code> function. </p>
<p>How can I return an integer value from this function when an object is created?</p>
<p>I wrote a program, where <code>__init__</code> does command line parsing and I need to have some value set. Is it OK set it in global variable and use it in other me... | 38 | 2010-03-22T11:35:10Z | 2,491,855 | <p>From the <a href="http://docs.python.org/reference/datamodel.html#object.__init__">documentation of <code>__init__</code></a>:</p>
<blockquote>
<p><em>As a special constraint on constructors, no value may be returned; doing so will cause a TypeError to be raised at runtime.</em></p>
</blockquote>
<p>As a proof, ... | 27 | 2010-03-22T11:41:16Z | [
"python",
"class",
"init"
] |
How to return a value from __init__ in Python? | 2,491,819 | <p>I have a class with an <code>__init__</code> function. </p>
<p>How can I return an integer value from this function when an object is created?</p>
<p>I wrote a program, where <code>__init__</code> does command line parsing and I need to have some value set. Is it OK set it in global variable and use it in other me... | 38 | 2010-03-22T11:35:10Z | 2,491,881 | <p>Why would you want to do that?</p>
<p>If you want to return some other object when a class is called, then use the <code>__new__()</code> method:</p>
<pre><code>class MyClass(object):
def __init__(self):
print "never called in this case"
def __new__(cls):
return 42
obj = MyClass()
print ob... | 61 | 2010-03-22T11:46:09Z | [
"python",
"class",
"init"
] |
How to return a value from __init__ in Python? | 2,491,819 | <p>I have a class with an <code>__init__</code> function. </p>
<p>How can I return an integer value from this function when an object is created?</p>
<p>I wrote a program, where <code>__init__</code> does command line parsing and I need to have some value set. Is it OK set it in global variable and use it in other me... | 38 | 2010-03-22T11:35:10Z | 2,491,913 | <p>The <code>__init__</code> method, like other methods and functions returns None by default in the absence of a return statement, so you can write it like either of these:</p>
<pre><code>class Foo:
def __init__(self):
self.value=42
class Bar:
def __init__(self):
self.value=42
return ... | 8 | 2010-03-22T11:52:08Z | [
"python",
"class",
"init"
] |
How to return a value from __init__ in Python? | 2,491,819 | <p>I have a class with an <code>__init__</code> function. </p>
<p>How can I return an integer value from this function when an object is created?</p>
<p>I wrote a program, where <code>__init__</code> does command line parsing and I need to have some value set. Is it OK set it in global variable and use it in other me... | 38 | 2010-03-22T11:35:10Z | 17,512,201 | <p>Sample Usage of the matter in question can be like:</p>
<pre><code>class SampleObject(object)
def __new__(cls,Item)
if self.IsValid(Item):
return super(SampleObject, cls).__new__(cls)
else:
return None
def __init__(self,Item)
self.InitData(Item) #large amoun... | 12 | 2013-07-07T12:37:09Z | [
"python",
"class",
"init"
] |
How to return a value from __init__ in Python? | 2,491,819 | <p>I have a class with an <code>__init__</code> function. </p>
<p>How can I return an integer value from this function when an object is created?</p>
<p>I wrote a program, where <code>__init__</code> does command line parsing and I need to have some value set. Is it OK set it in global variable and use it in other me... | 38 | 2010-03-22T11:35:10Z | 37,587,024 | <p>Just wanted to add, you can return classes in <code>__init__</code></p>
<pre><code>@property
def failureException(self):
class MyCustomException(AssertionError):
def __init__(self_, *args, **kwargs):
*** Your code here ***
return super().__init__(*args, **kwargs)
MyCustomExc... | 1 | 2016-06-02T08:52:42Z | [
"python",
"class",
"init"
] |
How to get the nth element of a python list or a default if not available | 2,492,087 | <p>I'm looking for an equivalent in python of dictionary.get(key, default) for lists. Is there any one liner idiom to get the nth element of a list or a default value if not available?</p>
<p>For example, given a list myList I would like to get myList[0], or 5 if myList is an empty list.</p>
| 55 | 2010-03-22T12:17:00Z | 2,492,093 | <pre><code>x[index] if len(x) > index else default
</code></pre>
<p>to support negative indices we can use:</p>
<pre><code>x[index] if -len(l) <= index < len(l) else default
</code></pre>
| 60 | 2010-03-22T12:18:48Z | [
"python",
"list"
] |
How to get the nth element of a python list or a default if not available | 2,492,087 | <p>I'm looking for an equivalent in python of dictionary.get(key, default) for lists. Is there any one liner idiom to get the nth element of a list or a default value if not available?</p>
<p>For example, given a list myList I would like to get myList[0], or 5 if myList is an empty list.</p>
| 55 | 2010-03-22T12:17:00Z | 2,492,094 | <pre><code>try:
a = b[n]
except IndexError:
a = default
</code></pre>
<p>Edit: I removed the check for TypeError - probably better to let the caller handle this.</p>
| 27 | 2010-03-22T12:18:55Z | [
"python",
"list"
] |
How to get the nth element of a python list or a default if not available | 2,492,087 | <p>I'm looking for an equivalent in python of dictionary.get(key, default) for lists. Is there any one liner idiom to get the nth element of a list or a default value if not available?</p>
<p>For example, given a list myList I would like to get myList[0], or 5 if myList is an empty list.</p>
| 55 | 2010-03-22T12:17:00Z | 2,492,102 | <pre><code>(L[n:n+1] or [somedefault])[0]
</code></pre>
| 10 | 2010-03-22T12:19:45Z | [
"python",
"list"
] |
How to get the nth element of a python list or a default if not available | 2,492,087 | <p>I'm looking for an equivalent in python of dictionary.get(key, default) for lists. Is there any one liner idiom to get the nth element of a list or a default value if not available?</p>
<p>For example, given a list myList I would like to get myList[0], or 5 if myList is an empty list.</p>
| 55 | 2010-03-22T12:17:00Z | 2,492,141 | <pre><code>(a[n:]+[default])[0]
</code></pre>
<p>This is probably better as <code>a</code> gets larger </p>
<pre><code>(a[n:n+1]+[default])[0]
</code></pre>
<p>This works because if <code>a[n:]</code> is an empty list if <code>n => len(a)</code></p>
<p>Here is an example of how this works with <code>range(5)</co... | 13 | 2010-03-22T12:25:46Z | [
"python",
"list"
] |
How to get the nth element of a python list or a default if not available | 2,492,087 | <p>I'm looking for an equivalent in python of dictionary.get(key, default) for lists. Is there any one liner idiom to get the nth element of a list or a default value if not available?</p>
<p>For example, given a list myList I would like to get myList[0], or 5 if myList is an empty list.</p>
| 55 | 2010-03-22T12:17:00Z | 22,865,211 | <p>Just dicovered that : </p>
<pre><code>next(iter(myList), 5)
</code></pre>
<p><code>iter(l)</code> returns an iterator on <code>myList</code>, <code>next()</code> consumes the first element of the iterator, and raises a <code>StopIteration</code> error except if called with a default value, which is the case here, ... | 10 | 2014-04-04T14:12:40Z | [
"python",
"list"
] |
meaning of the returned list of python json | 2,492,099 | <p>I'm new to python so I really don't know the language very well.</p>
<p>the following example was taken from here <a href="http://docs.python.org/library/json.html" rel="nofollow">http://docs.python.org/library/json.html</a></p>
<pre><code>>>> import json
>>> json.loads('["foo", {"bar":["baz", nu... | 0 | 2010-03-22T12:19:29Z | 2,492,115 | <p>It's a <a href="http://farmdev.com/talks/unicode/" rel="nofollow">unicode</a>. Iterating over the dict yields its keys:</p>
<pre><code>for k in D:
print k, D[k]
</code></pre>
| 4 | 2010-03-22T12:21:27Z | [
"python",
"json"
] |
meaning of the returned list of python json | 2,492,099 | <p>I'm new to python so I really don't know the language very well.</p>
<p>the following example was taken from here <a href="http://docs.python.org/library/json.html" rel="nofollow">http://docs.python.org/library/json.html</a></p>
<pre><code>>>> import json
>>> json.loads('["foo", {"bar":["baz", nu... | 0 | 2010-03-22T12:19:29Z | 2,492,180 | <p>Ignacio's answer a bit more verbose (no upvotes to me)</p>
<p>u'something' means that 'something' is a unicode string, and not for instance an ascii string. Generally text is encoded as 8-bit characters, and you need an encoding to properly interpret/display it. Unicode is 16-bit and doesn't need seperate encodings... | 3 | 2010-03-22T12:34:00Z | [
"python",
"json"
] |
meaning of the returned list of python json | 2,492,099 | <p>I'm new to python so I really don't know the language very well.</p>
<p>the following example was taken from here <a href="http://docs.python.org/library/json.html" rel="nofollow">http://docs.python.org/library/json.html</a></p>
<pre><code>>>> import json
>>> json.loads('["foo", {"bar":["baz", nu... | 0 | 2010-03-22T12:19:29Z | 2,492,635 | <p>The python <a href="http://docs.python.org/library/functions.html#type" rel="nofollow">type</a> function can be useful here.</p>
<pre><code>>>> import json
>>> data = json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
>>> data
[u'foo', {u'bar': [u'baz', None, 1.0, 2]}]
>>> type... | 1 | 2010-03-22T13:43:51Z | [
"python",
"json"
] |
Access Delicious API via Yahoo ID without redirect to Yahoo authorizing page | 2,492,326 | <p>To be more specific:</p>
<ol>
<li><p>My delicious account is a Yahoo ID so access via OAuth is required.</p></li>
<li><p>It's for my use only to add/remove bookmarks. I have the password.</p></li>
<li><p>It's a command line python program, not web-based.</p></li>
</ol>
<p>My question is:</p>
<p>Is it possible to ... | 1 | 2010-03-22T12:59:41Z | 2,616,894 | <p>Yes, but only if you go through the authorisation process once, to link your account to your application.</p>
<p>After that, you can re-authorise your existing information by using the session ID supplied from the original request.</p>
<p>I think <a href="http://developer.yahoo.com/oauth/guide/oauth-refreshaccesst... | 0 | 2010-04-11T11:53:30Z | [
"python",
"api",
"oauth",
"yahoo",
"delicious-api"
] |
Access Delicious API via Yahoo ID without redirect to Yahoo authorizing page | 2,492,326 | <p>To be more specific:</p>
<ol>
<li><p>My delicious account is a Yahoo ID so access via OAuth is required.</p></li>
<li><p>It's for my use only to add/remove bookmarks. I have the password.</p></li>
<li><p>It's a command line python program, not web-based.</p></li>
</ol>
<p>My question is:</p>
<p>Is it possible to ... | 1 | 2010-03-22T12:59:41Z | 3,994,783 | <p>What you probably actually want to do is set <code>oauth_callback=oob</code> (out of bounds). Instead of redirecting you, it will give you a verification code for you to paste into your command line. This feature is meant for non-web based situations like yours.</p>
<p>Also, since you're in Python you can use thi... | 0 | 2010-10-22T07:39:21Z | [
"python",
"api",
"oauth",
"yahoo",
"delicious-api"
] |
Access Delicious API via Yahoo ID without redirect to Yahoo authorizing page | 2,492,326 | <p>To be more specific:</p>
<ol>
<li><p>My delicious account is a Yahoo ID so access via OAuth is required.</p></li>
<li><p>It's for my use only to add/remove bookmarks. I have the password.</p></li>
<li><p>It's a command line python program, not web-based.</p></li>
</ol>
<p>My question is:</p>
<p>Is it possible to ... | 1 | 2010-03-22T12:59:41Z | 8,780,602 | <p>This is an older question, but since Yahoo has since sold off Delicious. The "new" Delicious is still compatible with the original API, but they have dropped the OAuth support. (It was tied directly to Yahoo's authentication system which the new company of course does not have access to.)</p>
<p>Otherwise the new A... | 0 | 2012-01-08T19:39:55Z | [
"python",
"api",
"oauth",
"yahoo",
"delicious-api"
] |
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>>>> 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,429 | <p>Just this should work:</p>
<pre><code>a.split()
</code></pre>
<p>Example:</p>
<pre><code>>>> 'a b'.split(' ')
['a', '', '', '', '', '', 'b']
>>> 'a b'.split()
['a', 'b']
</code></pre>
<p>From the <a href="http://docs.python.org/library/stdtypes.html#str.split">documentation</a>:</p>
... | 12 | 2010-03-22T13:14:56Z | [
"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>>>> 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,430 | <pre><code>>>> import re
>>> a="test result"
>>> re.split(" +",a)
['test', 'result']
>>> a.split()
['test', 'result']
</code></pre>
| 15 | 2010-03-22T13:15:01Z | [
"python",
"string",
"split",
"delimiter"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.