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 |
|---|---|---|---|---|---|---|---|---|---|
Command Line Arguments In Python | 1,009,860 | <p>I am originally a C programmer. I have seen numerous tricks and "hacks" to read many different arguments. </p>
<p>What are some of the ways Python programmers can do this?</p>
<h3>Related</h3>
<ul>
<li><a href="http://stackoverflow.com/questions/20063/whats-the-best-way-to-grab-parse-command-line-arguments-passed... | 269 | 2009-06-17T22:38:30Z | 7,161,355 | <p>As you can see <a href="http://docs.python.org/library/optparse.html#module-optparse">optparse</a> "The optparse module is deprecated with and will not be developed further; development will continue with the <a href="http://docs.python.org/library/argparse.html#module-argparse">argparse</a> module." </p>
| 5 | 2011-08-23T12:57:14Z | [
"python",
"command-line",
"command-line-arguments"
] |
Command Line Arguments In Python | 1,009,860 | <p>I am originally a C programmer. I have seen numerous tricks and "hacks" to read many different arguments. </p>
<p>What are some of the ways Python programmers can do this?</p>
<h3>Related</h3>
<ul>
<li><a href="http://stackoverflow.com/questions/20063/whats-the-best-way-to-grab-parse-command-line-arguments-passed... | 269 | 2009-06-17T22:38:30Z | 7,875,868 | <p>My solution is <a href="https://github.com/ponty/entrypoint2" rel="nofollow">entrypoint2</a>. Example:</p>
<pre><code>from entrypoint2 import entrypoint
@entrypoint
def add(file, quiet=True):
''' This function writes report.
:param file: write report to FILE
:param quiet: don't print status messages t... | 0 | 2011-10-24T12:48:37Z | [
"python",
"command-line",
"command-line-arguments"
] |
Command Line Arguments In Python | 1,009,860 | <p>I am originally a C programmer. I have seen numerous tricks and "hacks" to read many different arguments. </p>
<p>What are some of the ways Python programmers can do this?</p>
<h3>Related</h3>
<ul>
<li><a href="http://stackoverflow.com/questions/20063/whats-the-best-way-to-grab-parse-command-line-arguments-passed... | 269 | 2009-06-17T22:38:30Z | 10,545,218 | <pre><code>#set default args as -h , if no args:
if len(sys.argv) == 1: sys.argv[1:] = ["-h"]
</code></pre>
| 18 | 2012-05-11T03:53:30Z | [
"python",
"command-line",
"command-line-arguments"
] |
Command Line Arguments In Python | 1,009,860 | <p>I am originally a C programmer. I have seen numerous tricks and "hacks" to read many different arguments. </p>
<p>What are some of the ways Python programmers can do this?</p>
<h3>Related</h3>
<ul>
<li><a href="http://stackoverflow.com/questions/20063/whats-the-best-way-to-grab-parse-command-line-arguments-passed... | 269 | 2009-06-17T22:38:30Z | 14,790,373 | <p>The <a href="https://github.com/docopt/docopt">docopt</a> library is really slick. It builds an argument dict from the usage string for your app.</p>
<p>Eg from the docopt readme:</p>
<pre><code>"""Naval Fate.
Usage:
naval_fate.py ship new <name>...
naval_fate.py ship <name> move <x> <y&... | 24 | 2013-02-09T16:52:31Z | [
"python",
"command-line",
"command-line-arguments"
] |
Command Line Arguments In Python | 1,009,860 | <p>I am originally a C programmer. I have seen numerous tricks and "hacks" to read many different arguments. </p>
<p>What are some of the ways Python programmers can do this?</p>
<h3>Related</h3>
<ul>
<li><a href="http://stackoverflow.com/questions/20063/whats-the-best-way-to-grab-parse-command-line-arguments-passed... | 269 | 2009-06-17T22:38:30Z | 18,296,313 | <p>I recommend looking at <a href="http://docopt.org/" rel="nofollow">docopt</a> as a simple alternative to these others.</p>
<p>docopt is a new project that works by parsing your --help usage message rather than requiring you to implement everything yourself. You just have to put your usage message in the POSIX forma... | 4 | 2013-08-18T06:21:51Z | [
"python",
"command-line",
"command-line-arguments"
] |
Command Line Arguments In Python | 1,009,860 | <p>I am originally a C programmer. I have seen numerous tricks and "hacks" to read many different arguments. </p>
<p>What are some of the ways Python programmers can do this?</p>
<h3>Related</h3>
<ul>
<li><a href="http://stackoverflow.com/questions/20063/whats-the-best-way-to-grab-parse-command-line-arguments-passed... | 269 | 2009-06-17T22:38:30Z | 25,272,710 | <p>Pocoo's <a href="http://click.pocoo.org/" rel="nofollow">click</a> is more intuitive, requires less boilerplate, and is at least as powerful as argparse.</p>
<p>The only weakness I've encountered so far is that you can't do much customization to help pages, but that usually isn't a requirement and <a href="http://d... | 3 | 2014-08-12T19:38:40Z | [
"python",
"command-line",
"command-line-arguments"
] |
Command Line Arguments In Python | 1,009,860 | <p>I am originally a C programmer. I have seen numerous tricks and "hacks" to read many different arguments. </p>
<p>What are some of the ways Python programmers can do this?</p>
<h3>Related</h3>
<ul>
<li><a href="http://stackoverflow.com/questions/20063/whats-the-best-way-to-grab-parse-command-line-arguments-passed... | 269 | 2009-06-17T22:38:30Z | 33,329,251 | <p>If you need something fast and not very flexible</p>
<p><strong>main.py:</strong></p>
<pre><code>import sys
first_name = sys.argv[1]
last_name = sys.argv[2]
print("Hello " + first_name+ " " + last_name )
</code></pre>
<p>Then run <code>python main.py James Smith</code></p>
<p>to produce the following output:</p... | 6 | 2015-10-25T11:40:25Z | [
"python",
"command-line",
"command-line-arguments"
] |
Command Line Arguments In Python | 1,009,860 | <p>I am originally a C programmer. I have seen numerous tricks and "hacks" to read many different arguments. </p>
<p>What are some of the ways Python programmers can do this?</p>
<h3>Related</h3>
<ul>
<li><a href="http://stackoverflow.com/questions/20063/whats-the-best-way-to-grab-parse-command-line-arguments-passed... | 269 | 2009-06-17T22:38:30Z | 33,660,810 | <p>Yet another option is <a href="https://pypi.python.org/pypi/argh" rel="nofollow">argh</a>. It builds on argparse, and lets you write things like:</p>
<pre><code>import argh
# declaring:
def echo(text):
"Returns given word as is."
return text
def greet(name, greeting='Hello'):
"Greets the user with gi... | 1 | 2015-11-11T22:10:35Z | [
"python",
"command-line",
"command-line-arguments"
] |
Python - Get original function arguments in decorator | 1,010,080 | <p>I am trying to write a "login_required" decorator for the views in a WSGI+Werkzeug application.</p>
<p>In order to do this, I need to get at the user's session, which is accessible via the Request object that is passed into the view methods.</p>
<p>I can't figure out how to get at that instance of Request in the d... | 9 | 2009-06-17T23:55:25Z | 1,010,109 | <p>The decorator <code>login_required</code> is passed the function (<code>hello</code> in this case).</p>
<p>So what you want to do is:</p>
<pre><code>def login_required(f):
# This function is what we "replace" hello with
def wrapper(*args, **kw):
args[0].client_session['test'] = True
logged_in = 0
... | 17 | 2009-06-18T00:02:17Z | [
"python",
"decorator"
] |
How to construct a webob.Request or a WSGI 'environ' dict from raw HTTP request byte stream? | 1,010,103 | <p>Suppose I have a byte stream with the following in it:</p>
<pre>
POST /mum/ble?q=huh
Content-Length: 18
Content-Type: application/json; charset="utf-8"
Host: localhost:80
["do", "re", "mi"]
</pre>
<p>Is there a way to produce an WSGI-style 'environ' dict from it?</p>
<p>Hopefully, I've overlooked an easy answer,... | 3 | 2009-06-18T00:00:43Z | 1,010,639 | <p>Reusing Python's standard library code for the purpose is a bit tricky (it was not designed to be reused that way!-), but should be doable, e.g:</p>
<pre><code>import cStringIO
from wsgiref import simple_server, util
input_string = """POST /mum/ble?q=huh HTTP/1.0
Content-Length: 18
Content-Type: application/json; ... | 5 | 2009-06-18T03:27:59Z | [
"python",
"wsgi",
"webob"
] |
How to distribute proportionally dates on a scale with Python | 1,010,139 | <p>I have a very simple charting component which takes integer on the x/y axis. My problem is that I need to represent date/float on this chart. So I though I could distribute proportionally dates on a scale. In other words, let's say I have the following date : 01/01/2008, 02/01/2008 and 31/12/2008. The algorithm woul... | 0 | 2009-06-18T00:13:16Z | 1,010,169 | <p>I don't know if I fully understand what you are trying to do, but you can just deal with times as number of seconds since the UNIX epoch and then just use plain old subtraction to get a range that you can scale to the size of your plot.</p>
<p>In processing, the map function will handle this case for you. <a href=... | 0 | 2009-06-18T00:26:47Z | [
"python",
"algorithm",
"datetime",
"timedelta"
] |
How to distribute proportionally dates on a scale with Python | 1,010,139 | <p>I have a very simple charting component which takes integer on the x/y axis. My problem is that I need to represent date/float on this chart. So I though I could distribute proportionally dates on a scale. In other words, let's say I have the following date : 01/01/2008, 02/01/2008 and 31/12/2008. The algorithm woul... | 0 | 2009-06-18T00:13:16Z | 1,010,200 | <p>It's fairly easy to convert a timedelta into a numeric value.</p>
<p>Select an epoch time. Calculate deltas for every value relative to the epoch. Convert the delta's into a numeric value. Then map the numeric values as you normally would.</p>
<p>Conversion is straight forward. Something like:</p>
<pre><code>def ... | 1 | 2009-06-18T00:37:20Z | [
"python",
"algorithm",
"datetime",
"timedelta"
] |
How to distribute proportionally dates on a scale with Python | 1,010,139 | <p>I have a very simple charting component which takes integer on the x/y axis. My problem is that I need to represent date/float on this chart. So I though I could distribute proportionally dates on a scale. In other words, let's say I have the following date : 01/01/2008, 02/01/2008 and 31/12/2008. The algorithm woul... | 0 | 2009-06-18T00:13:16Z | 1,010,248 | <p>If you're dealing with dates, then you can use the method <a href="http://docs.python.org/library/datetime.html#datetime.date.toordinal" rel="nofollow">toordinal</a>.</p>
<pre><code>import datetime
jan1=datetime.datetime(2008,1,1)
dec31=datetime.datetime(2008,12,31)
feb1=datetime.datetime(2008,02,01)
dates=[jan1,... | 3 | 2009-06-18T00:51:12Z | [
"python",
"algorithm",
"datetime",
"timedelta"
] |
Would extracting page metadata be a good use of multiple inheritance? | 1,010,349 | <p>I was wondering if I have a couple of models which both include fields like "meta_keywords" or "slug" which have to do with the web page the model instance will be displayed on, whether it would be advisable to break those page metadata elements out into their own class, say PageMeta, and have my other models subcla... | 1 | 2009-06-18T01:26:58Z | 1,010,420 | <p>General advice for a lightly-specified question:</p>
<p>Nontrivial multiple inheritance in Python requires Advanced Techniques to deal with the metaclass/metatype conflict. Look over <a href="http://code.activestate.com/recipes/204197/" rel="nofollow">this recipe</a> from the ActiveState archives and see if it loo... | 0 | 2009-06-18T02:01:10Z | [
"python",
"django",
"architecture",
"multiple-inheritance",
"mixins"
] |
Python factorization | 1,010,381 | <p>I'd just like to know the best way of listing all integer factors of a number, given a dictionary of its prime factors and their exponents.<br/>
For example if we have {2:3, 3:2, 5:1} (2^3 * 3^2 * 5 = 360)<br/>
Then I could write:<br/></p>
<pre><code>for i in range(4):
for j in range(3):
for k in range(1):
... | 11 | 2009-06-18T01:39:13Z | 1,010,445 | <p>Basically, what you have here is a set, consisting of each factor of the target number. In your example, the set would be <code>{2 2 2 3 3 5}</code>. Each strict subset of that set is the factorization of one of the divisors of your number, so if you can generate all the subsets of that set, you can multiply the e... | 1 | 2009-06-18T02:11:16Z | [
"python",
"algorithm"
] |
Python factorization | 1,010,381 | <p>I'd just like to know the best way of listing all integer factors of a number, given a dictionary of its prime factors and their exponents.<br/>
For example if we have {2:3, 3:2, 5:1} (2^3 * 3^2 * 5 = 360)<br/>
Then I could write:<br/></p>
<pre><code>for i in range(4):
for j in range(3):
for k in range(1):
... | 11 | 2009-06-18T01:39:13Z | 1,010,460 | <p>Using <a href="http://docs.python.org/library/itertools.html#itertools.product"><code>itertools.product</code></a> from Python 2.6:</p>
<pre><code>#!/usr/bin/env python
import itertools, operator
def all_factors(prime_dict):
series = [[p**e for e in range(maxe+1)] for p, maxe in prime_dict.items()]
for mul... | 10 | 2009-06-18T02:17:59Z | [
"python",
"algorithm"
] |
Python factorization | 1,010,381 | <p>I'd just like to know the best way of listing all integer factors of a number, given a dictionary of its prime factors and their exponents.<br/>
For example if we have {2:3, 3:2, 5:1} (2^3 * 3^2 * 5 = 360)<br/>
Then I could write:<br/></p>
<pre><code>for i in range(4):
for j in range(3):
for k in range(1):
... | 11 | 2009-06-18T01:39:13Z | 1,010,461 | <p>Yes. When you've got an algorithm that needs n nested for loops, you can usually turn it into a recursive function:</p>
<pre><code>def print_factors(d, product=1):
if len(d) == 0: # Base case: we've dealt with all prime factors, so
print product # Just print the product
return
d2 = ... | 3 | 2009-06-18T02:18:11Z | [
"python",
"algorithm"
] |
Python factorization | 1,010,381 | <p>I'd just like to know the best way of listing all integer factors of a number, given a dictionary of its prime factors and their exponents.<br/>
For example if we have {2:3, 3:2, 5:1} (2^3 * 3^2 * 5 = 360)<br/>
Then I could write:<br/></p>
<pre><code>for i in range(4):
for j in range(3):
for k in range(1):
... | 11 | 2009-06-18T01:39:13Z | 1,010,463 | <p>Well, not only you have 3 loops, but this approach won't work if you have more than 3 factors :)</p>
<p>One possible way:</p>
<pre><code>def genfactors(fdict):
factors = set([1])
for factor, count in fdict.iteritems():
for ignore in range(count):
factors.update([n*factor for n in f... | 9 | 2009-06-18T02:18:50Z | [
"python",
"algorithm"
] |
Python factorization | 1,010,381 | <p>I'd just like to know the best way of listing all integer factors of a number, given a dictionary of its prime factors and their exponents.<br/>
For example if we have {2:3, 3:2, 5:1} (2^3 * 3^2 * 5 = 360)<br/>
Then I could write:<br/></p>
<pre><code>for i in range(4):
for j in range(3):
for k in range(1):
... | 11 | 2009-06-18T01:39:13Z | 1,011,573 | <p>I have <a href="http://numericalrecipes.wordpress.com/tag/divisors/">blogged about this</a>, and the fastest pure python (without itertools) comes from a post by Tim Peters to the python list, and uses nested recursive generators:</p>
<pre><code>def divisors(factors) :
"""
Generates all divisors, unordered,... | 14 | 2009-06-18T08:53:59Z | [
"python",
"algorithm"
] |
plot line at particular angle and offset | 1,010,423 | <p>I'm attempting to plot a particular line over an original image (an array) that i have. Basically, I have an angle and offset (measured from the center of the image) that I want to plot the line over. The problem is, I'm not exactly sure how to do this. I can write a really complicated piece of code to do this, but ... | 0 | 2009-06-18T02:02:47Z | 1,010,604 | <p>Assuming that your offset is actually a x, y coordinate of the center of the line, and that the line should be a fixed length, then it's a simple matter of trigonometry with matplotlib:</p>
<pre><code>x = [offsetx-linelength*cos(angle), offsetx+linelength*cos(angle)]
y = [offsety-linelength*sin(angle), offsety+line... | 0 | 2009-06-18T03:15:13Z | [
"python",
"image",
"plot",
"offset",
"angle"
] |
plot line at particular angle and offset | 1,010,423 | <p>I'm attempting to plot a particular line over an original image (an array) that i have. Basically, I have an angle and offset (measured from the center of the image) that I want to plot the line over. The problem is, I'm not exactly sure how to do this. I can write a really complicated piece of code to do this, but ... | 0 | 2009-06-18T02:02:47Z | 1,010,644 | <p>You may want to look at <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a> If you do a lot of image manipulation.</p>
| 0 | 2009-06-18T03:30:44Z | [
"python",
"image",
"plot",
"offset",
"angle"
] |
plot line at particular angle and offset | 1,010,423 | <p>I'm attempting to plot a particular line over an original image (an array) that i have. Basically, I have an angle and offset (measured from the center of the image) that I want to plot the line over. The problem is, I'm not exactly sure how to do this. I can write a really complicated piece of code to do this, but ... | 0 | 2009-06-18T02:02:47Z | 1,010,659 | <p>Use PIL and draw line, cricle, or another image over the original image</p>
<pre><code>import Image, ImageDraw
im = Image.open("my.png")
draw = ImageDraw.Draw(im)
draw.line((0, 0, 100, 100), fill=128)
del draw
# write to stdout
im.save(sys.stdout, "PNG")
</code></pre>
| 1 | 2009-06-18T03:37:30Z | [
"python",
"image",
"plot",
"offset",
"angle"
] |
Mapping URL Pattern to a Single RequestHandler in a WSGIApplication | 1,010,427 | <p>Is it possible to map a URL pattern (regular expression or some other mapping) to a single RequestHandler? If so how can I accomplish this?</p>
<p>Ideally I'd like to do something like this:</p>
<pre><code>application=WSGIApplication([('/*',MyRequestHandler),])
</code></pre>
<p>So that MyRequestHandler handles a... | 3 | 2009-06-18T02:05:22Z | 1,010,452 | <pre><code>application=WSGIApplication([(r'.*',MyRequestHandler),])
</code></pre>
<p>for more see <a href="http://code.google.com/appengine/docs/python/tools/webapp/running.html" rel="nofollow">the AppEngine docs</a></p>
| 1 | 2009-06-18T02:16:30Z | [
"python",
"google-app-engine"
] |
Mapping URL Pattern to a Single RequestHandler in a WSGIApplication | 1,010,427 | <p>Is it possible to map a URL pattern (regular expression or some other mapping) to a single RequestHandler? If so how can I accomplish this?</p>
<p>Ideally I'd like to do something like this:</p>
<pre><code>application=WSGIApplication([('/*',MyRequestHandler),])
</code></pre>
<p>So that MyRequestHandler handles a... | 3 | 2009-06-18T02:05:22Z | 1,012,365 | <p>The pattern you describe will work fine. Also, any groups in the regular expression you specify will be passed as arguments to the handler methods (get, post, etc). For example:</p>
<pre><code>class MyRequestHandler(webapp.RequestHandler):
def get(self, date, id):
# Do stuff. Note that date and id are both st... | 8 | 2009-06-18T12:27:29Z | [
"python",
"google-app-engine"
] |
Mathematical equation manipulation in Python | 1,010,583 | <p>I want to develop a GUI application which displays a given mathematical equation. When you click upon a particular variable in the equation to signify that it is the unknown variable ie., to be calculated, the equation transforms itself to evaluate the required unknown variable.</p>
<p>For example:</p>
<hr>
<pre>... | 10 | 2009-06-18T03:07:52Z | 1,010,613 | <p>Sage has support for symbolic math. You could just use some of the equation manipulating functions built-in:</p>
<p><a href="http://sagemath.org/" rel="nofollow">http://sagemath.org/</a></p>
| 3 | 2009-06-18T03:16:47Z | [
"python",
"math",
"equation"
] |
Mathematical equation manipulation in Python | 1,010,583 | <p>I want to develop a GUI application which displays a given mathematical equation. When you click upon a particular variable in the equation to signify that it is the unknown variable ie., to be calculated, the equation transforms itself to evaluate the required unknown variable.</p>
<p>For example:</p>
<hr>
<pre>... | 10 | 2009-06-18T03:07:52Z | 1,010,637 | <p>What you want to do isn't easy. Some equations are quite straight forward to rearrange (like make <code>b</code> the subject of <code>a = b*c+d</code>, which is <code>b = (a-d)/c</code>), while others are not so obvious (like make <code>x</code> the subject of <code>y = x*x + 4*x + 4</code>), while others are not po... | 4 | 2009-06-18T03:26:53Z | [
"python",
"math",
"equation"
] |
Mathematical equation manipulation in Python | 1,010,583 | <p>I want to develop a GUI application which displays a given mathematical equation. When you click upon a particular variable in the equation to signify that it is the unknown variable ie., to be calculated, the equation transforms itself to evaluate the required unknown variable.</p>
<p>For example:</p>
<hr>
<pre>... | 10 | 2009-06-18T03:07:52Z | 1,010,666 | <p>Using <a href="http://sympy.org/" rel="nofollow">SymPy</a>, your example would go something like this:</p>
<pre><code>>>> import sympy
>>> a,b,c,d,e = sympy.symbols('abcde')
>>> r = (b+c*d)/e
>>> l = a
>>> r = sympy.solve(l-r,d)
>>> l = d
>>> r
[(-b + a... | 20 | 2009-06-18T03:40:25Z | [
"python",
"math",
"equation"
] |
Mathematical equation manipulation in Python | 1,010,583 | <p>I want to develop a GUI application which displays a given mathematical equation. When you click upon a particular variable in the equation to signify that it is the unknown variable ie., to be calculated, the equation transforms itself to evaluate the required unknown variable.</p>
<p>For example:</p>
<hr>
<pre>... | 10 | 2009-06-18T03:07:52Z | 1,010,712 | <p>If you want to do this out of the box, without relying on librairies, I think that the problems you will find are not Python related. If you want to find such equations, you have to describe the heuristics necessary to solve these equations.</p>
<p>First, you have to represent your equation. What about separating:<... | 6 | 2009-06-18T03:58:12Z | [
"python",
"math",
"equation"
] |
Mathematical equation manipulation in Python | 1,010,583 | <p>I want to develop a GUI application which displays a given mathematical equation. When you click upon a particular variable in the equation to signify that it is the unknown variable ie., to be calculated, the equation transforms itself to evaluate the required unknown variable.</p>
<p>For example:</p>
<hr>
<pre>... | 10 | 2009-06-18T03:07:52Z | 18,307,095 | <p>Things have sure changed since 2009. I don't know how your GUI application is going, but this is now possible directly in IPython qtconsole (which one could embed inside a custom PyQt/PySide application, and keep track of all the defined symbols, to allow GUI interaction in a separate listbox, etc.)</p>
<p><img sr... | 4 | 2013-08-19T05:47:47Z | [
"python",
"math",
"equation"
] |
Customizing Django auto admin terminology | 1,010,794 | <p>I'm playing around with Django's admin module, but I've seemed to run into a bit of a bump that's more of an annoyance than an error. I have my modules setup using names like UserData and Status, so Django's admin panel likes to try to call each row in UserData a user datas and each status a statuss. Is there any wa... | 2 | 2009-06-18T04:36:20Z | 1,010,798 | <p>You can define <code>verbose_name</code> and <code>verbose_name_plural</code> in your model's inner <code>Meta</code> class to override the values used there. See <a href="http://docs.djangoproject.com/en/dev/ref/models/options/#verbose-name-plural" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/models/opti... | 6 | 2009-06-18T04:40:25Z | [
"python",
"django"
] |
Traversing multi-dimensional dictionary in django | 1,010,848 | <p>I'm a PHP guy on my first day in Python-land, trying to convert a php site to python (learning experience), and I'm hurting for advice. I never thought it would be so hard to use multi-dimensional arrays or dictionaries as you pythoners call them.</p>
<p>So I can create multi-dimensional arrays using <a href="http:... | -1 | 2009-06-18T05:01:43Z | 1,010,862 | <p>I'm also a Django beginner...</p>
<p>You should be able to nest the for loops to get something like this:</p>
<pre><code>{% for key,val in dictionary.items %}
{% for key,val in val.items %}
</code></pre>
<p>and so on.</p>
| 0 | 2009-06-18T05:08:08Z | [
"python",
"django",
"django-models",
"dictionary",
"django-templates"
] |
Traversing multi-dimensional dictionary in django | 1,010,848 | <p>I'm a PHP guy on my first day in Python-land, trying to convert a php site to python (learning experience), and I'm hurting for advice. I never thought it would be so hard to use multi-dimensional arrays or dictionaries as you pythoners call them.</p>
<p>So I can create multi-dimensional arrays using <a href="http:... | -1 | 2009-06-18T05:01:43Z | 1,010,870 | <p>If you built your complicated dictionary in the following way:</p>
<pre><code>vid[ video[ 7 ], 'cat_short_name' ] = video[ 2 ]
vid[ video[ 7 ], 'cat_name' ] = video[ 1 ]
vid[ video[ 7 ], 'cat_id' ] = video[ 7 ]
vid[ video[ 7 ], 'companies', video[ 14 ], 'comp_short_name' ] = video[ 5 ]
</code></pre>
<p>etc, would... | 0 | 2009-06-18T05:10:13Z | [
"python",
"django",
"django-models",
"dictionary",
"django-templates"
] |
Traversing multi-dimensional dictionary in django | 1,010,848 | <p>I'm a PHP guy on my first day in Python-land, trying to convert a php site to python (learning experience), and I'm hurting for advice. I never thought it would be so hard to use multi-dimensional arrays or dictionaries as you pythoners call them.</p>
<p>So I can create multi-dimensional arrays using <a href="http:... | -1 | 2009-06-18T05:01:43Z | 1,011,027 | <p><code></p>
<pre><code>{% for key, val in vid.items %}
<h1>{{ val.cat_name }}</h1>
{% for k2, v2 in val.companies.items %}
<h2>{{ v2.comp_name }}</h2>
<ul>
{% for k3, v3 in v2.videos.items %}
<li>{{ v3.vid_name }}</li>
{% e... | 0 | 2009-06-18T06:04:25Z | [
"python",
"django",
"django-models",
"dictionary",
"django-templates"
] |
Traversing multi-dimensional dictionary in django | 1,010,848 | <p>I'm a PHP guy on my first day in Python-land, trying to convert a php site to python (learning experience), and I'm hurting for advice. I never thought it would be so hard to use multi-dimensional arrays or dictionaries as you pythoners call them.</p>
<p>So I can create multi-dimensional arrays using <a href="http:... | -1 | 2009-06-18T05:01:43Z | 1,011,082 | <p>When moving from one language or framework to another, you need to realise that it's not usually a good idea to write your code in exactly the same way, even if you can.</p>
<p>For example:</p>
<blockquote>
<p>I'm creating my dictionary from a sql query</p>
</blockquote>
<p>Why are you doing this? The way to re... | 2 | 2009-06-18T06:22:54Z | [
"python",
"django",
"django-models",
"dictionary",
"django-templates"
] |
Traversing multi-dimensional dictionary in django | 1,010,848 | <p>I'm a PHP guy on my first day in Python-land, trying to convert a php site to python (learning experience), and I'm hurting for advice. I never thought it would be so hard to use multi-dimensional arrays or dictionaries as you pythoners call them.</p>
<p>So I can create multi-dimensional arrays using <a href="http:... | -1 | 2009-06-18T05:01:43Z | 1,011,145 | <p>You should be using the built in <a href="http://docs.djangoproject.com/en/dev/topics/db/" rel="nofollow">ORM</a> instead of using your own queries (at least for something simple like this), makes things much easier (assuming you've also built your models in your models.py file)</p>
<p>In your view:</p>
<pre><code... | 3 | 2009-06-18T06:54:50Z | [
"python",
"django",
"django-models",
"dictionary",
"django-templates"
] |
how many places are optimized in Python's bytecode(version 2.5) | 1,010,914 | <p>Can anyone tell me how many places there are optimized in Python's bytecode?
I was trying to de-compile Python's bytecode these days,but I found that in Python's version 2.5 there are a lot of optimization.For example: to this code</p>
<pre><code>a,b,c=([],[],[])#build list
</code></pre>
<p>the non-optimized bytec... | 1 | 2009-06-18T05:33:29Z | 1,010,947 | <p>I don't think there's any documentation per se, but there's the C code for the Python interpreter. You can find several different versions of it <a href="http://python.org/download/releases/" rel="nofollow">here</a>.</p>
| 0 | 2009-06-18T05:41:59Z | [
"python",
"bytecode"
] |
how many places are optimized in Python's bytecode(version 2.5) | 1,010,914 | <p>Can anyone tell me how many places there are optimized in Python's bytecode?
I was trying to de-compile Python's bytecode these days,but I found that in Python's version 2.5 there are a lot of optimization.For example: to this code</p>
<pre><code>a,b,c=([],[],[])#build list
</code></pre>
<p>the non-optimized bytec... | 1 | 2009-06-18T05:33:29Z | 1,010,963 | <p>The <a href="http://svn.python.org/projects/python/trunk/Python/peephole.c" rel="nofollow">Python/peephole.c</a> source file is where basically all such optimizations are performed -- the link I gave is to the current version (2.6 or better), because I'm having trouble getting to the dynamic source browser <a href="... | 2 | 2009-06-18T05:46:05Z | [
"python",
"bytecode"
] |
String Slicing Python | 1,010,961 | <p>I have a string, example:</p>
<pre><code>s = "this is a string, a"
</code></pre>
<p>where ','(comma) will always be the 3rd last character, aka s[-3].</p>
<p>I am thinking of ways to remove the ',' but can only think of converting the string into a list, deleting it, and converting it back to a string. This howev... | 5 | 2009-06-18T05:45:47Z | 1,010,973 | <p>Normally, you would just do:</p>
<pre><code>s = s[:-3] + s[-2:]
</code></pre>
<p>The <code>s[:-3]</code> gives you a string up to, but not including, the comma you want removed (<code>"this is a string"</code>) and the <code>s[-2:]</code> gives you another string starting one character beyond that comma (<code>" a... | 23 | 2009-06-18T05:48:55Z | [
"python"
] |
String Slicing Python | 1,010,961 | <p>I have a string, example:</p>
<pre><code>s = "this is a string, a"
</code></pre>
<p>where ','(comma) will always be the 3rd last character, aka s[-3].</p>
<p>I am thinking of ways to remove the ',' but can only think of converting the string into a list, deleting it, and converting it back to a string. This howev... | 5 | 2009-06-18T05:45:47Z | 1,010,991 | <p>Python strings are immutable. This means that you <strong>must</strong> create at least 1 new string in order to remove the comma, as opposed to editing the string in place in a language like C.</p>
| 2 | 2009-06-18T05:52:41Z | [
"python"
] |
String Slicing Python | 1,010,961 | <p>I have a string, example:</p>
<pre><code>s = "this is a string, a"
</code></pre>
<p>where ','(comma) will always be the 3rd last character, aka s[-3].</p>
<p>I am thinking of ways to remove the ',' but can only think of converting the string into a list, deleting it, and converting it back to a string. This howev... | 5 | 2009-06-18T05:45:47Z | 1,011,397 | <p>For deleting every ',' character in the text, you can try</p>
<pre><code>s = s.split(',')
>> ["this is a string", " a"]
s = "".join(s)
>> "this is a string a"
</code></pre>
<p>Or in one line:</p>
<pre><code>s0 = "".join(s.split(','))
</code></pre>
| 1 | 2009-06-18T08:08:53Z | [
"python"
] |
String Slicing Python | 1,010,961 | <p>I have a string, example:</p>
<pre><code>s = "this is a string, a"
</code></pre>
<p>where ','(comma) will always be the 3rd last character, aka s[-3].</p>
<p>I am thinking of ways to remove the ',' but can only think of converting the string into a list, deleting it, and converting it back to a string. This howev... | 5 | 2009-06-18T05:45:47Z | 1,011,645 | <p>A couple of variants, using the "delete the last comma" rather than "delete third last character" are:</p>
<pre><code>s[::-1].replace(",","",1)[::-1]
</code></pre>
<p>or</p>
<pre><code>''.join(s.rsplit(",", 1))
</code></pre>
<p>But these are pretty ugly. Slightly better is:</p>
<pre><code>a, _, b = s.rpartitio... | 5 | 2009-06-18T09:13:15Z | [
"python"
] |
What to learn for RIA | 1,011,168 | <p>I am planning to build a RIA about a year from now (when my current contract ends). What technology would you recommend investing time in? </p>
<p>I will need good cross browser/platform support for video, music, and canvas.
And ideally I would like to leverage my Python skills.</p>
<p>Silverlight looks interestin... | 1 | 2009-06-18T06:59:45Z | 1,011,195 | <p>Silverlight/Flash are interesting but closed platform</p>
<p><a href="http://www.openlaszlo.org/" rel="nofollow">openlaszlo</a> is another RIA platform which you should consider, you write in XML/javascript and output to multiple platforms e.g. Flash/DHTML and may be more in future</p>
<p>another candidate is <a ... | 1 | 2009-06-18T07:09:50Z | [
"python",
"silverlight",
"html5",
"ria"
] |
What to learn for RIA | 1,011,168 | <p>I am planning to build a RIA about a year from now (when my current contract ends). What technology would you recommend investing time in? </p>
<p>I will need good cross browser/platform support for video, music, and canvas.
And ideally I would like to leverage my Python skills.</p>
<p>Silverlight looks interestin... | 1 | 2009-06-18T06:59:45Z | 1,011,196 | <p>If you have a year to prepare I recommend that you research all the technologies you can. Build the hello worlds for the different platforms. Then build the SAME simple RIA on each candidate framework to get a good feel for the differences. Obviously you will not uncover every little gotcha, but the gross archite... | 2 | 2009-06-18T07:10:04Z | [
"python",
"silverlight",
"html5",
"ria"
] |
What to learn for RIA | 1,011,168 | <p>I am planning to build a RIA about a year from now (when my current contract ends). What technology would you recommend investing time in? </p>
<p>I will need good cross browser/platform support for video, music, and canvas.
And ideally I would like to leverage my Python skills.</p>
<p>Silverlight looks interestin... | 1 | 2009-06-18T06:59:45Z | 1,011,396 | <p>You should focus on âHTML5â where âHTML5â is the new âAjaxâ buzzword aka. the âOpen Web Platformâânot just the HTML 5 spec itself.</p>
<p>Flash, Silverlight and JavaFX are all single-vendor plug-in offerings but âHTML5â is a multi-vendor browser-native thing.</p>
<p>If you want to an IDE work... | 2 | 2009-06-18T08:08:47Z | [
"python",
"silverlight",
"html5",
"ria"
] |
What to learn for RIA | 1,011,168 | <p>I am planning to build a RIA about a year from now (when my current contract ends). What technology would you recommend investing time in? </p>
<p>I will need good cross browser/platform support for video, music, and canvas.
And ideally I would like to leverage my Python skills.</p>
<p>Silverlight looks interestin... | 1 | 2009-06-18T06:59:45Z | 1,020,743 | <p>I would recommend Flash/Flex/AIR. It would definitely gives you the most freedom to build what you want.</p>
<p>Flex is great for making RIAs, and now with AIR, you can now deploy to the desktop.</p>
<p>Here are a few links:</p>
<ul>
<li><a href="http://www.adobe.com/resources/business/rich%5Finternet%5Fapps/#ope... | 1 | 2009-06-20T02:03:14Z | [
"python",
"silverlight",
"html5",
"ria"
] |
What to learn for RIA | 1,011,168 | <p>I am planning to build a RIA about a year from now (when my current contract ends). What technology would you recommend investing time in? </p>
<p>I will need good cross browser/platform support for video, music, and canvas.
And ideally I would like to leverage my Python skills.</p>
<p>Silverlight looks interestin... | 1 | 2009-06-18T06:59:45Z | 1,020,763 | <p>Check out <a href="http://www.appcelerator.com/" rel="nofollow">Titanium</a> while you're looking around. It's similar to AIR, and you can use your Python chops.</p>
<p>Otherwise, I would say go as HTML/CSS/JavaScript as you can, and use Flash for any multimedia that you can't get to work otherwise. Keep in mind th... | 1 | 2009-06-20T02:15:22Z | [
"python",
"silverlight",
"html5",
"ria"
] |
What to learn for RIA | 1,011,168 | <p>I am planning to build a RIA about a year from now (when my current contract ends). What technology would you recommend investing time in? </p>
<p>I will need good cross browser/platform support for video, music, and canvas.
And ideally I would like to leverage my Python skills.</p>
<p>Silverlight looks interestin... | 1 | 2009-06-18T06:59:45Z | 12,746,438 | <p><a href="http://pyjs.org/" rel="nofollow">http://pyjs.org/</a>
pyjs is a Rich Internet Application (RIA) Development Platform for both Web and Desktop. With pyjs you can write your JavaScript-powered web applications entirely in Python.</p>
| 0 | 2012-10-05T12:37:45Z | [
"python",
"silverlight",
"html5",
"ria"
] |
Relative file paths in Python packages | 1,011,337 | <p>How do I reference a file relatively to a package's directory?</p>
<p>My directory structure is:</p>
<pre>
/foo
package1/
resources/
__init__.py
package2/
resources/
__init__.py
script.py
</pre>
<p><code>script.py</code> imports packages <code>package1</code> and <code>p... | 8 | 2009-06-18T07:51:23Z | 1,011,366 | <p>If you want to reference files from the <code>foo/package1/resources</code> folder you would want to use the <code>__file__</code> variable of the module. Inside <code>foo/package1/__init__.py</code>:</p>
<pre><code>from os import path
resources_dir = path.join(path.dirname(__file__), 'resources')
</code></pre>
| 10 | 2009-06-18T08:00:44Z | [
"python",
"reference",
"packages",
"relative-path"
] |
Relative file paths in Python packages | 1,011,337 | <p>How do I reference a file relatively to a package's directory?</p>
<p>My directory structure is:</p>
<pre>
/foo
package1/
resources/
__init__.py
package2/
resources/
__init__.py
script.py
</pre>
<p><code>script.py</code> imports packages <code>package1</code> and <code>p... | 8 | 2009-06-18T07:51:23Z | 1,011,435 | <p>This is a bad idea, because, if your package was installed as zipped egg, then resources can be unavailable.</p>
<p>If you use setuptool, don't forget to add zip_safe=False to the setup.py config.</p>
| 0 | 2009-06-18T08:20:28Z | [
"python",
"reference",
"packages",
"relative-path"
] |
Relative file paths in Python packages | 1,011,337 | <p>How do I reference a file relatively to a package's directory?</p>
<p>My directory structure is:</p>
<pre>
/foo
package1/
resources/
__init__.py
package2/
resources/
__init__.py
script.py
</pre>
<p><code>script.py</code> imports packages <code>package1</code> and <code>p... | 8 | 2009-06-18T07:51:23Z | 1,011,491 | <p>You can be zip-safe and at the same time use a nice convenient API if you use <a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.python.modules.html" rel="nofollow">twisted.python.modules</a>.</p>
<p>For example, if I have a <code>data.txt</code> with some text in it and and this <code>sample.py</code> i... | 3 | 2009-06-18T08:33:57Z | [
"python",
"reference",
"packages",
"relative-path"
] |
Relative file paths in Python packages | 1,011,337 | <p>How do I reference a file relatively to a package's directory?</p>
<p>My directory structure is:</p>
<pre>
/foo
package1/
resources/
__init__.py
package2/
resources/
__init__.py
script.py
</pre>
<p><code>script.py</code> imports packages <code>package1</code> and <code>p... | 8 | 2009-06-18T07:51:23Z | 39,864,336 | <p>A simple/safe way to do this is using the <code>resource_filename</code> method from <a href="http://setuptools.readthedocs.io/en/latest/pkg_resources.html" rel="nofollow">pkg_resources</a> (which is distributed with <a href="https://pypi.python.org/pypi/setuptools" rel="nofollow">setuptools</a>) like so:</p>
<pre>... | 0 | 2016-10-05T02:01:22Z | [
"python",
"reference",
"packages",
"relative-path"
] |
Configuring Django to use SQLAlchemy | 1,011,476 | <p>how we configure django with SQLAlchemy??</p>
| 17 | 2009-06-18T08:31:04Z | 1,011,495 | <p>Check this:</p>
<p><a href="http://lethain.com/entry/2008/jul/23/replacing-django-s-orm-with-sqlalchemy/">Replacing django orm</a></p>
| 8 | 2009-06-18T08:34:42Z | [
"python",
"django",
"sqlalchemy",
"configure"
] |
Configuring Django to use SQLAlchemy | 1,011,476 | <p>how we configure django with SQLAlchemy??</p>
| 17 | 2009-06-18T08:31:04Z | 1,011,507 | <p>alchemy? :)</p>
<p>Google links:</p>
<ul>
<li><a href="http://lethain.com/entry/2008/jul/23/replacing-django-s-orm-with-sqlalchemy/" rel="nofollow">replacing-django-s-orm-with-sqlalchemy</a></li>
<li><a href="http://code.google.com/p/django-sqlalchemy/" rel="nofollow">django-sqlalchemy</a></li>
<li><a href="http:/... | 3 | 2009-06-18T08:38:50Z | [
"python",
"django",
"sqlalchemy",
"configure"
] |
Configuring Django to use SQLAlchemy | 1,011,476 | <p>how we configure django with SQLAlchemy??</p>
| 17 | 2009-06-18T08:31:04Z | 8,539,407 | <p>You can use SQLAlchemy within a Django project with Aldjemy:</p>
<p><a href="https://github.com/Deepwalker/aldjemy" rel="nofollow">https://github.com/Deepwalker/aldjemy</a></p>
| 8 | 2011-12-16T19:53:12Z | [
"python",
"django",
"sqlalchemy",
"configure"
] |
Configuring Django to use SQLAlchemy | 1,011,476 | <p>how we configure django with SQLAlchemy??</p>
| 17 | 2009-06-18T08:31:04Z | 27,579,486 | <p>Please find this little tutorial on <a href="http://rodic.fr/blog/sqlalchemy-django/" rel="nofollow">how to use SQLAlchemy with Django</a></p>
| 3 | 2014-12-20T10:54:37Z | [
"python",
"django",
"sqlalchemy",
"configure"
] |
How can you add a camera to a robot in the Breve Simulator? | 1,011,602 | <p>I've created a two wheeled robot based on the braitenberg vehicle. Our robots have two wheels and a PolygonDisk body(Much like kepera and e-puck robots). I would like to add a camera to the front of the robot. The problem then becomes how to control the camera and how to keep pointing it in the right direction(same ... | 1 | 2009-06-18T09:01:23Z | 1,027,059 | <p>After much trying and failing I finally made it work.
So here is how I did it:</p>
<p>The general idea is to have an link or object linked to the vehicle and then measuring
its rotation and location in order to find out in which direction the camera should be aimed.</p>
<p>1) Add an object that is linked to the r... | 1 | 2009-06-22T12:54:10Z | [
"python",
"simulation",
"robotics"
] |
How can I accurately program an automated "click" on Windows? | 1,011,799 | <p>I wrote a program to click on an application automatically at scheduled time using Win32, using <code>MOUSE_DOWN</code> and <code>MOUSE_UP</code>. It usually works well, except I found that I need to put in a </p>
<pre><code>sleep 0.1
</code></pre>
<p>between the <code>MOUSE_DOWN</code> and <code>MOUSE_UP</code>.... | 0 | 2009-06-18T09:44:12Z | 1,011,846 | <p>If you're not bound to a specific language you could have a look at <a href="http://www.autoitscript.com/autoit3/" rel="nofollow">AutoIt</a> which is made especially for things like this.
I had good experiences with it for automating things like mouseclicks or keystrokes.</p>
| 3 | 2009-06-18T09:52:49Z | [
"python",
"ruby",
"perl",
"winapi",
"windows"
] |
How can I accurately program an automated "click" on Windows? | 1,011,799 | <p>I wrote a program to click on an application automatically at scheduled time using Win32, using <code>MOUSE_DOWN</code> and <code>MOUSE_UP</code>. It usually works well, except I found that I need to put in a </p>
<pre><code>sleep 0.1
</code></pre>
<p>between the <code>MOUSE_DOWN</code> and <code>MOUSE_UP</code>.... | 0 | 2009-06-18T09:44:12Z | 1,011,855 | <p>What function(s) are you using to accomplish this?</p>
<p>I'd expect <a href="http://msdn.microsoft.com/en-us/library/ms646310.aspx" rel="nofollow">SendInput</a> with a chain of 2 passed in MOUSEINPUT structures (one button down, the other button up) would pull this off for you. You can even play games with the ti... | 1 | 2009-06-18T09:55:35Z | [
"python",
"ruby",
"perl",
"winapi",
"windows"
] |
How can I accurately program an automated "click" on Windows? | 1,011,799 | <p>I wrote a program to click on an application automatically at scheduled time using Win32, using <code>MOUSE_DOWN</code> and <code>MOUSE_UP</code>. It usually works well, except I found that I need to put in a </p>
<pre><code>sleep 0.1
</code></pre>
<p>between the <code>MOUSE_DOWN</code> and <code>MOUSE_UP</code>.... | 0 | 2009-06-18T09:44:12Z | 1,011,872 | <p>I guess 2 things:</p>
<ol>
<li>I bet ruby doesn't and can't guarantee that sleep 0.1 really sleeps only 0.1 seconds. As this is probably out of rubys control and OS controlled</li>
<li>The call to the Win32 API via Win32 itself may take an arbitrary time and cause the delay</li>
</ol>
| 1 | 2009-06-18T10:00:09Z | [
"python",
"ruby",
"perl",
"winapi",
"windows"
] |
How can I accurately program an automated "click" on Windows? | 1,011,799 | <p>I wrote a program to click on an application automatically at scheduled time using Win32, using <code>MOUSE_DOWN</code> and <code>MOUSE_UP</code>. It usually works well, except I found that I need to put in a </p>
<pre><code>sleep 0.1
</code></pre>
<p>between the <code>MOUSE_DOWN</code> and <code>MOUSE_UP</code>.... | 0 | 2009-06-18T09:44:12Z | 1,011,902 | <p>Since the Windows API supports sleeping down to 1 millisecond, why not just sleep a shorter time? 0.01 seconds should be enough?</p>
| 1 | 2009-06-18T10:10:21Z | [
"python",
"ruby",
"perl",
"winapi",
"windows"
] |
How can I accurately program an automated "click" on Windows? | 1,011,799 | <p>I wrote a program to click on an application automatically at scheduled time using Win32, using <code>MOUSE_DOWN</code> and <code>MOUSE_UP</code>. It usually works well, except I found that I need to put in a </p>
<pre><code>sleep 0.1
</code></pre>
<p>between the <code>MOUSE_DOWN</code> and <code>MOUSE_UP</code>.... | 0 | 2009-06-18T09:44:12Z | 1,012,559 | <p>You do not decide what delay setting between mouse down and mouse up results in a valid single click, the operating system does.</p>
<p>No <code>sleep</code> function can guarantee the timing between the mouse down and mouse up events you want. Perl's <a href="http://search.cpan.org/~karasik/Win32-GuiTest-1.56/" re... | 3 | 2009-06-18T13:11:58Z | [
"python",
"ruby",
"perl",
"winapi",
"windows"
] |
How can I accurately program an automated "click" on Windows? | 1,011,799 | <p>I wrote a program to click on an application automatically at scheduled time using Win32, using <code>MOUSE_DOWN</code> and <code>MOUSE_UP</code>. It usually works well, except I found that I need to put in a </p>
<pre><code>sleep 0.1
</code></pre>
<p>between the <code>MOUSE_DOWN</code> and <code>MOUSE_UP</code>.... | 0 | 2009-06-18T09:44:12Z | 1,015,717 | <p>I'd use AutoHotKey. It's open source and free, been around a long time and actively maintained, to the point that others have built an IDE for it. I use it for generating unique random test data for form testing but it does mouse stuff too. </p>
<p><a href="http://www.autohotkey.com/" rel="nofollow">http://www.auto... | 1 | 2009-06-18T23:30:54Z | [
"python",
"ruby",
"perl",
"winapi",
"windows"
] |
Python - Previous and next values inside a loop | 1,011,938 | <p>How can I do thing like this in python?</p>
<pre><code>foo = somevalue
previous = next = 0
for (i=1; i<objects.length(); i++) {
if (objects[i]==foo){
previous = objects[i-1]
next = objects[i+1]
}
}
</code></pre>
| 33 | 2009-06-18T10:23:38Z | 1,011,962 | <p>This should do the trick.</p>
<pre><code>foo = somevalue
previous = next_ = None
l = len(objects)
for index, obj in enumerate(objects):
if obj == foo:
if index > 0:
previous = objects[index - 1]
if index < (l - 1):
next_ = objects[index + 1]
</code></pre>
<p>Here's... | 45 | 2009-06-18T10:28:51Z | [
"python",
"loops"
] |
Python - Previous and next values inside a loop | 1,011,938 | <p>How can I do thing like this in python?</p>
<pre><code>foo = somevalue
previous = next = 0
for (i=1; i<objects.length(); i++) {
if (objects[i]==foo){
previous = objects[i-1]
next = objects[i+1]
}
}
</code></pre>
| 33 | 2009-06-18T10:23:38Z | 1,012,017 | <p>You could just use <code>index</code> on the list to find where <code>somevalue</code> is and then get the previous and next as needed:</p>
<pre>
<code>
def find_prev_next(elem, elements):
previous, next = None, None
index = elements.index(elem)
if index > 0:
previous = elements[index -1]
... | 0 | 2009-06-18T10:49:16Z | [
"python",
"loops"
] |
Python - Previous and next values inside a loop | 1,011,938 | <p>How can I do thing like this in python?</p>
<pre><code>foo = somevalue
previous = next = 0
for (i=1; i<objects.length(); i++) {
if (objects[i]==foo){
previous = objects[i-1]
next = objects[i+1]
}
}
</code></pre>
| 33 | 2009-06-18T10:23:38Z | 1,012,063 | <p>using conditional expressions for conciseness for python >= 2.5</p>
<pre><code>def prenext(l,v) :
i=l.index(v)
return l[i-1] if i>0 else None,l[i+1] if i<len(l)-1 else None
# example
x=range(10)
prenext(x,3)
>>> (2,4)
prenext(x,0)
>>> (None,2)
prenext(x,9)
>>> (8,None)
</co... | 1 | 2009-06-18T11:02:48Z | [
"python",
"loops"
] |
Python - Previous and next values inside a loop | 1,011,938 | <p>How can I do thing like this in python?</p>
<pre><code>foo = somevalue
previous = next = 0
for (i=1; i<objects.length(); i++) {
if (objects[i]==foo){
previous = objects[i-1]
next = objects[i+1]
}
}
</code></pre>
| 33 | 2009-06-18T10:23:38Z | 1,012,089 | <p>Solutions until now only deal with lists, and most are copying the list. In my experience a lot of times that isn't possible.</p>
<p>Also, they don't deal with the fact that you can have repeated elements in the list.</p>
<p>The title of your question says "<em>Previous and next values inside a loop</em>", but if ... | 71 | 2009-06-18T11:12:58Z | [
"python",
"loops"
] |
Python - Previous and next values inside a loop | 1,011,938 | <p>How can I do thing like this in python?</p>
<pre><code>foo = somevalue
previous = next = 0
for (i=1; i<objects.length(); i++) {
if (objects[i]==foo){
previous = objects[i-1]
next = objects[i+1]
}
}
</code></pre>
| 33 | 2009-06-18T10:23:38Z | 1,012,169 | <p>Here's a version using generators with no boundary errors:</p>
<pre><code>def trios(input):
input = iter(input) # make sure input is an iterator
try:
prev, current = input.next(), input.next()
except StopIteration:
return
for next in input:
yield prev, current, next
p... | 2 | 2009-06-18T11:29:11Z | [
"python",
"loops"
] |
Python - Previous and next values inside a loop | 1,011,938 | <p>How can I do thing like this in python?</p>
<pre><code>foo = somevalue
previous = next = 0
for (i=1; i<objects.length(); i++) {
if (objects[i]==foo){
previous = objects[i-1]
next = objects[i+1]
}
}
</code></pre>
| 33 | 2009-06-18T10:23:38Z | 22,608,381 | <p>AFAIK this should be pretty fast, but I didn't test it:</p>
<pre><code>def iterate_prv_nxt(my_list):
prv, cur, nxt = None, iter(my_list), iter(my_list)
next(nxt, None)
while True:
try:
if prv:
yield next(prv), next(cur), next(nxt, None)
else:
... | 0 | 2014-03-24T11:40:31Z | [
"python",
"loops"
] |
Python - Previous and next values inside a loop | 1,011,938 | <p>How can I do thing like this in python?</p>
<pre><code>foo = somevalue
previous = next = 0
for (i=1; i<objects.length(); i++) {
if (objects[i]==foo){
previous = objects[i-1]
next = objects[i+1]
}
}
</code></pre>
| 33 | 2009-06-18T10:23:38Z | 32,714,764 | <p>Using a list comprehension, return a 3-tuple with current, previous and next elements:</p>
<pre><code>three_tuple = [(current, my_list[idx - 1] if idx >= 1 else None,
my_list[idx + 1] if idx < len(my_list) - 1 else None) for idx, current in
enumerate(my_list)]
</code><... | 0 | 2015-09-22T10:40:53Z | [
"python",
"loops"
] |
Python - Previous and next values inside a loop | 1,011,938 | <p>How can I do thing like this in python?</p>
<pre><code>foo = somevalue
previous = next = 0
for (i=1; i<objects.length(); i++) {
if (objects[i]==foo){
previous = objects[i-1]
next = objects[i+1]
}
}
</code></pre>
| 33 | 2009-06-18T10:23:38Z | 33,036,692 | <p>Pythonic and elegant way:</p>
<pre><code>objects = [1, 2, 3, 4, 5]
value = 3
if value in objects:
index = objects.index(value)
previous_value = objects[index-1]
next_value = objects[index+1] if index + 1 < len(objects) else None
</code></pre>
| 0 | 2015-10-09T11:06:07Z | [
"python",
"loops"
] |
How to get links on a webpage using mechanize and open those links | 1,011,975 | <p>I want to use mechanize with python to get all the links of the page, and then open the links.How can I do it?</p>
| 1 | 2009-06-18T10:32:44Z | 1,012,022 | <p>The <code>Browser</code> object in <code>mechanize</code> has a <code>links</code> method that will retrieve all the links on the page.</p>
| 0 | 2009-06-18T10:51:03Z | [
"python",
"mechanize"
] |
How to get links on a webpage using mechanize and open those links | 1,011,975 | <p>I want to use mechanize with python to get all the links of the page, and then open the links.How can I do it?</p>
| 1 | 2009-06-18T10:32:44Z | 1,012,030 | <p>Here is an example from the project's <a href="http://wwwsearch.sourceforge.net/mechanize/">page</a>:</p>
<pre><code>
import re
from mechanize import Browser
br = Browser()
br.open("http://www.example.com/")
# ...
# .links() optionally accepts the keyword args of .follow_/.find_link()
for link in br.links(url_re... | 5 | 2009-06-18T10:53:11Z | [
"python",
"mechanize"
] |
how to generate a many-to-many-relationship FORM in web2py? | 1,012,179 | <p>Do I need a custom validator? Do I need a custom widget?</p>
<p>If this helps to clear the problem, the relationship is between <code>member</code> and <code>language</code> where a member can have multiple languages and a language is spoken by multiple members.</p>
<p>I would like to add a multi-select box in the... | 2 | 2009-06-18T11:32:10Z | 1,075,983 | <p>It depends and I suggest you take this on the web2py mailin list. One way to do it is</p>
<pre><code>db.table.field.requires=IS_IN_DB(db,'othertable.id','%(otherfield)',multiple=True)
</code></pre>
| 1 | 2009-07-02T18:34:00Z | [
"python",
"web2py"
] |
how to generate a many-to-many-relationship FORM in web2py? | 1,012,179 | <p>Do I need a custom validator? Do I need a custom widget?</p>
<p>If this helps to clear the problem, the relationship is between <code>member</code> and <code>language</code> where a member can have multiple languages and a language is spoken by multiple members.</p>
<p>I would like to add a multi-select box in the... | 2 | 2009-06-18T11:32:10Z | 1,401,702 | <p>Another way to do this:</p>
<pre><code>db.define_table( 'make', Field( 'name' ) )
db.define_table( 'model',
Field( 'name' ),
Field( 'make', db.make, requires = IS_IN_DB( db, 'make.id', '%(name)' ) ) )
</code></pre>
| 0 | 2009-09-09T19:46:49Z | [
"python",
"web2py"
] |
In Python, how do I index a list with another list? | 1,012,185 | <p>I would like to index a list with another list like this</p>
<pre><code>L = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
Idx = [0, 3, 7]
T = L[ Idx ]
</code></pre>
<p>and T should end up being a list containing ['a', 'd', 'h'].</p>
<p>Is there a better way than</p>
<pre><code>T = []
for i in Idx:
T.append(L[i])
... | 36 | 2009-06-18T11:36:06Z | 1,012,197 | <pre><code>T = [L[i] for i in Idx]
</code></pre>
| 85 | 2009-06-18T11:38:46Z | [
"python",
"list",
"indexing"
] |
In Python, how do I index a list with another list? | 1,012,185 | <p>I would like to index a list with another list like this</p>
<pre><code>L = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
Idx = [0, 3, 7]
T = L[ Idx ]
</code></pre>
<p>and T should end up being a list containing ['a', 'd', 'h'].</p>
<p>Is there a better way than</p>
<pre><code>T = []
for i in Idx:
T.append(L[i])
... | 36 | 2009-06-18T11:36:06Z | 1,012,204 | <pre><code>T = map(lambda i: L[i], Idx)
</code></pre>
| 4 | 2009-06-18T11:39:58Z | [
"python",
"list",
"indexing"
] |
In Python, how do I index a list with another list? | 1,012,185 | <p>I would like to index a list with another list like this</p>
<pre><code>L = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
Idx = [0, 3, 7]
T = L[ Idx ]
</code></pre>
<p>and T should end up being a list containing ['a', 'd', 'h'].</p>
<p>Is there a better way than</p>
<pre><code>T = []
for i in Idx:
T.append(L[i])
... | 36 | 2009-06-18T11:36:06Z | 1,012,484 | <p>If you are using numpy, you can perform extended slicing like that:</p>
<pre><code>>>> import numpy
>>> a=numpy.array(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])
>>> Idx = [0, 3, 7]
>>> a[Idx]
array(['a', 'd', 'h'],
dtype='|S1')
</code></pre>
<p>...and is probably much fast... | 16 | 2009-06-18T12:54:26Z | [
"python",
"list",
"indexing"
] |
In Python, how do I index a list with another list? | 1,012,185 | <p>I would like to index a list with another list like this</p>
<pre><code>L = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
Idx = [0, 3, 7]
T = L[ Idx ]
</code></pre>
<p>and T should end up being a list containing ['a', 'd', 'h'].</p>
<p>Is there a better way than</p>
<pre><code>T = []
for i in Idx:
T.append(L[i])
... | 36 | 2009-06-18T11:36:06Z | 29,447,861 | <p>I wasn't happy with any of these approaches, so I came up with a <code>Flexlist</code> class that allows for flexible indexing, either by integer, slice or index-list:</p>
<pre><code>class Flexlist(list):
def __getitem__(self, keys):
if isinstance(keys, (int, slice)): return list.__getitem__(self, keys)... | 2 | 2015-04-04T14:59:55Z | [
"python",
"list",
"indexing"
] |
In Python, how do I index a list with another list? | 1,012,185 | <p>I would like to index a list with another list like this</p>
<pre><code>L = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
Idx = [0, 3, 7]
T = L[ Idx ]
</code></pre>
<p>and T should end up being a list containing ['a', 'd', 'h'].</p>
<p>Is there a better way than</p>
<pre><code>T = []
for i in Idx:
T.append(L[i])
... | 36 | 2009-06-18T11:36:06Z | 29,448,401 | <pre><code> L= {'a':'a','d':'d', 'h':'h}
index= ['a','d','h']
for keys in index:
print(L[keys])
</code></pre>
<p>I would use a <code>Dict add</code> desired <code>keys</code> to <code>index</code> </p>
| 0 | 2015-04-04T15:55:18Z | [
"python",
"list",
"indexing"
] |
In Python, how do I index a list with another list? | 1,012,185 | <p>I would like to index a list with another list like this</p>
<pre><code>L = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
Idx = [0, 3, 7]
T = L[ Idx ]
</code></pre>
<p>and T should end up being a list containing ['a', 'd', 'h'].</p>
<p>Is there a better way than</p>
<pre><code>T = []
for i in Idx:
T.append(L[i])
... | 36 | 2009-06-18T11:36:06Z | 31,257,239 | <p>A functional approach:</p>
<pre><code>a = [1,"A", 34, -123, "Hello", 12]
b = [0, 2, 5]
from operator import itemgetter
print(list(itemgetter(*b)(a)))
[1, 34, 12]
</code></pre>
| 1 | 2015-07-06T23:12:25Z | [
"python",
"list",
"indexing"
] |
How to concatenate strings with binary values in python? | 1,012,457 | <p>What's the easiest way in python to concatenate string with binary values ?</p>
<pre><code>sep = 0x1
data = ["abc","def","ghi","jkl"]
</code></pre>
<p>Looking for result data <code>"abc0x1def0x1ghi0x1jkl"</code> with the 0x1 being binary value not string "0x1".</p>
| 3 | 2009-06-18T12:48:28Z | 1,012,472 | <p>I think</p>
<pre><code>joined = '\x01'.join(data)
</code></pre>
<p>should do it. <code>\x01</code> is the escape sequence for a byte with value 0x01.</p>
| 9 | 2009-06-18T12:51:12Z | [
"python",
"string",
"binary",
"concatenation"
] |
How to concatenate strings with binary values in python? | 1,012,457 | <p>What's the easiest way in python to concatenate string with binary values ?</p>
<pre><code>sep = 0x1
data = ["abc","def","ghi","jkl"]
</code></pre>
<p>Looking for result data <code>"abc0x1def0x1ghi0x1jkl"</code> with the 0x1 being binary value not string "0x1".</p>
| 3 | 2009-06-18T12:48:28Z | 1,012,526 | <p>The chr() function will have the effect of translating a variable into a string with the binary value you are looking for.</p>
<pre><code>>>> sep = 0x1
>>> sepc = chr(sep)
>>> sepc
'\x01'
</code></pre>
<p>The join() function can then be used to concat a series of strings with your binary... | 3 | 2009-06-18T13:03:35Z | [
"python",
"string",
"binary",
"concatenation"
] |
Bash or Python to go backwards? | 1,012,490 | <p>I have a text file which a lot of random occurrences of the string @STRING_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like</p>
<pre><code>@STRING_A
</code></pre>
<p>then checks i... | 6 | 2009-06-18T12:56:09Z | 1,012,512 | <p>In bash you can use <code>sort -r filename</code> and <code>tail -n filename</code> to read the file backwards.</p>
<pre><code>$LINES=`tail -n filename | sort -r`
# now iterate through the lines and do your checking
</code></pre>
| -1 | 2009-06-18T13:01:17Z | [
"python",
"bash"
] |
Bash or Python to go backwards? | 1,012,490 | <p>I have a text file which a lot of random occurrences of the string @STRING_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like</p>
<pre><code>@STRING_A
</code></pre>
<p>then checks i... | 6 | 2009-06-18T12:56:09Z | 1,012,520 | <p>Why shouldn't it possible in bash? You don't need to keep the whole file in memory, just the last three lines (if I understood correctly), and write what's appropriate to standard-out. Redirect that into a temporary file, check that everything worked as expected, and overwrite the source file with the temporary one.... | 1 | 2009-06-18T13:03:05Z | [
"python",
"bash"
] |
Bash or Python to go backwards? | 1,012,490 | <p>I have a text file which a lot of random occurrences of the string @STRING_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like</p>
<pre><code>@STRING_A
</code></pre>
<p>then checks i... | 6 | 2009-06-18T12:56:09Z | 1,012,543 | <p>Of course Python will work as well. Simply store the last three lines in an array and check if the first element in the array is the same as the value you are currently reading. Then delete the value and print out the current array. You would then move over your elements to make room for the new value and repeat. Of... | 2 | 2009-06-18T13:07:59Z | [
"python",
"bash"
] |
Bash or Python to go backwards? | 1,012,490 | <p>I have a text file which a lot of random occurrences of the string @STRING_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like</p>
<pre><code>@STRING_A
</code></pre>
<p>then checks i... | 6 | 2009-06-18T12:56:09Z | 1,012,637 | <p>This code will scan through the file, and remove lines starting with the marker. It only keeps only three lines in memory by default:</p>
<pre><code>from collections import deque
def delete(fp, marker, gap=3):
"""Delete lines from *fp* if they with *marker* and are followed
by another line starting with *m... | 1 | 2009-06-18T13:33:09Z | [
"python",
"bash"
] |
Bash or Python to go backwards? | 1,012,490 | <p>I have a text file which a lot of random occurrences of the string @STRING_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like</p>
<pre><code>@STRING_A
</code></pre>
<p>then checks i... | 6 | 2009-06-18T12:56:09Z | 1,012,953 | <p>I would consider using sed. gnu sed supports definition of line ranges. if sed would fail, then there is another beast - awk and I'm sure you can do it with awk.</p>
<p>O.K. I feel I should put my awk POC. I could not figure out to use sed addresses. I have not tried combination of awk+sed, but it seems to me it's ... | -2 | 2009-06-18T14:27:17Z | [
"python",
"bash"
] |
Bash or Python to go backwards? | 1,012,490 | <p>I have a text file which a lot of random occurrences of the string @STRING_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like</p>
<pre><code>@STRING_A
</code></pre>
<p>then checks i... | 6 | 2009-06-18T12:56:09Z | 1,013,162 | <p>As AlbertoPL said, store lines in a fifo for later use--don't "go backwards". For this I would definitely use python over bash+sed/awk/whatever. </p>
<p>I took a few moments to code this snippet up:</p>
<pre><code>from collections import deque
line_fifo = deque()
for line in open("test"):
line_fifo.append(li... | 1 | 2009-06-18T14:57:11Z | [
"python",
"bash"
] |
Bash or Python to go backwards? | 1,012,490 | <p>I have a text file which a lot of random occurrences of the string @STRING_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like</p>
<pre><code>@STRING_A
</code></pre>
<p>then checks i... | 6 | 2009-06-18T12:56:09Z | 1,015,515 | <p>My awk-fu has never been that good... but the following may provide you what you're looking for in a bash-shell/shell-utility form:</p>
<pre><code>sed `awk 'BEGIN{ORS=";"}
/@STRING_A/ {
if(LAST!="" && LAST+3 >= NR) print LAST "d"
LAST = NR
}' test_file` test_file
</code></pre>
<p>Basically... awk is... | 0 | 2009-06-18T22:23:33Z | [
"python",
"bash"
] |
Bash or Python to go backwards? | 1,012,490 | <p>I have a text file which a lot of random occurrences of the string @STRING_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like</p>
<pre><code>@STRING_A
</code></pre>
<p>then checks i... | 6 | 2009-06-18T12:56:09Z | 1,015,598 | <p>Here is a more fun solution, using two iterators with a three element offset :)</p>
<pre><code>from itertools import izip, chain, tee
f1, f2 = tee(open("foo.txt"))
for third, line in izip(chain(" ", f1), f2):
if not (third.startswith("@STRING_A") and line.startswith("@STRING_A")):
print line,
</code><... | 2 | 2009-06-18T22:53:20Z | [
"python",
"bash"
] |
Bash or Python to go backwards? | 1,012,490 | <p>I have a text file which a lot of random occurrences of the string @STRING_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like</p>
<pre><code>@STRING_A
</code></pre>
<p>then checks i... | 6 | 2009-06-18T12:56:09Z | 1,015,960 | <p>Funny that after all these hours nobody's yet given a solution to the problem as actually phrased (as @John Machin points out in a comment) -- remove just the leading marker (if followed by another such marker 3 lines down), not the whole line containing it. It's not hard, of course -- here's a tiny mod as needed of... | 4 | 2009-06-19T01:10:30Z | [
"python",
"bash"
] |
Bash or Python to go backwards? | 1,012,490 | <p>I have a text file which a lot of random occurrences of the string @STRING_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like</p>
<pre><code>@STRING_A
</code></pre>
<p>then checks i... | 6 | 2009-06-18T12:56:09Z | 1,016,123 | <p>This may be what you're looking for?</p>
<pre><code>lines = open('sample.txt').readlines()
needle = "@string "
for i,line in enumerate(lines):
if line.startswith(needle) and lines[i-3].startswith(needle):
lines[i-3] = lines[i-3].replace(needle, "")
print ''.join(lines)
</code></pre>
<p>this outputs:</p>... | -1 | 2009-06-19T02:37:20Z | [
"python",
"bash"
] |
Bash or Python to go backwards? | 1,012,490 | <p>I have a text file which a lot of random occurrences of the string @STRING_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like</p>
<pre><code>@STRING_A
</code></pre>
<p>then checks i... | 6 | 2009-06-18T12:56:09Z | 1,017,298 | <p>This "answer" is for lyrae ... I'll amend my previous comment: if the needle is in the first 3 lines of the file, your script will either cause an IndexError or access a line that it shouldn't be accessing, sometimes with interesting side-effects.</p>
<p>Example of your script causing IndexError:</p>
<pre><code>&g... | 0 | 2009-06-19T10:23:05Z | [
"python",
"bash"
] |
Why does this python code hang on import/compile but work in the shell? | 1,013,064 | <p>I'm trying to use python to sftp a file, and the code works great in the interactive shell -- even pasting it in all at once.</p>
<p>When I try to import the file (just to compile it), the code hangs with no exceptions or obvious errors. </p>
<p>How do I get the code to compile, or does someone have working code... | 1 | 2009-06-18T14:45:19Z | 1,013,135 | <p>This may not be a direct reason why, but <strong>rarely do you ever</strong> want to have "functionality" executed upon import. Normally you should define a <em>class</em> or <em>function</em> that you then call like this:</p>
<pre><code>import mymodule
mymodule.run()
</code></pre>
<p>The "global" code that you r... | 1 | 2009-06-18T14:54:21Z | [
"python",
"shell",
"compilation",
"sftp"
] |
Why does this python code hang on import/compile but work in the shell? | 1,013,064 | <p>I'm trying to use python to sftp a file, and the code works great in the interactive shell -- even pasting it in all at once.</p>
<p>When I try to import the file (just to compile it), the code hangs with no exceptions or obvious errors. </p>
<p>How do I get the code to compile, or does someone have working code... | 1 | 2009-06-18T14:45:19Z | 1,013,232 | <p>That's indeed a bad idea to execute this kind of code at import time, although I am not sure why it hangs - it may be that import mechanism does something strange which interacts badly with paramiko (thread related issues maybe ?). Anyway, the usual solution is to implement the functionality into a function:</p>
<p... | 3 | 2009-06-18T15:09:50Z | [
"python",
"shell",
"compilation",
"sftp"
] |
Why does this python code hang on import/compile but work in the shell? | 1,013,064 | <p>I'm trying to use python to sftp a file, and the code works great in the interactive shell -- even pasting it in all at once.</p>
<p>When I try to import the file (just to compile it), the code hangs with no exceptions or obvious errors. </p>
<p>How do I get the code to compile, or does someone have working code... | 1 | 2009-06-18T14:45:19Z | 1,013,366 | <p>Weirdness aside, I was just using import to compile the code. Turning the script into a function seems like an unnecessary complication for this kind of application.</p>
<p>Searched for alternate means to compile and found:</p>
<pre>
import py_compile
py_compile.compile("ProblemDemo.py")
</pre>
<p>This generate... | 0 | 2009-06-18T15:29:12Z | [
"python",
"shell",
"compilation",
"sftp"
] |
Call Python From Bat File And Get Return Code | 1,013,246 | <p>I'm looking for a way to call a python script from a batch file and getting a return code from the python script. Confusing I know, but it's based on a system that's currently in use. I'd re-write it, but this way would be much, much quicker.</p>
<p>So:</p>
<pre><code>Bat ---------------------> Python
* ... | 10 | 2009-06-18T15:11:43Z | 1,013,293 | <p>The windows shell saves the return code in the <code>ERRORLEVEL</code> variable:</p>
<pre><code>python somescript.py
echo %ERRORLEVEL%
</code></pre>
<p>In the python script you can exit the script and set the return value by calling <code>exit()</code>:</p>
<pre><code>exit(15)
</code></pre>
<p>In older versions ... | 14 | 2009-06-18T15:17:46Z | [
"python",
"batch-file"
] |
Call Python From Bat File And Get Return Code | 1,013,246 | <p>I'm looking for a way to call a python script from a batch file and getting a return code from the python script. Confusing I know, but it's based on a system that's currently in use. I'd re-write it, but this way would be much, much quicker.</p>
<p>So:</p>
<pre><code>Bat ---------------------> Python
* ... | 10 | 2009-06-18T15:11:43Z | 1,013,296 | <p>Try:</p>
<pre><code>import os
os._exit(ret_value)
</code></pre>
<p>You should also check:</p>
<ul>
<li><a href="http://bytes.com/groups/python/585533-sys-exit-versus-raise-systemexit" rel="nofollow">sys.exit()</a></li>
</ul>
| 3 | 2009-06-18T15:18:16Z | [
"python",
"batch-file"
] |
What is the purpose of the two colons in this Python string-slicing statement? | 1,013,272 | <p>For example,</p>
<pre><code>str = "hello"
str[1::3]
</code></pre>
<p>And where can I find this in Python documentation?</p>
| 13 | 2009-06-18T15:14:57Z | 1,013,295 | <p>in <a href="http://docs.python.org/library/stdtypes.html#index-510">sequences' description</a>:</p>
<pre><code>s[i:j:k] slice of s from i to j with step k
</code></pre>
<blockquote>
<p>The slice of <code>s</code> from <code>i</code> to <code>j</code> with step <code>k</code> is defined as the sequence of item... | 19 | 2009-06-18T15:18:13Z | [
"python",
"slice"
] |
python ORM allowing for table creation and bulk inserting? | 1,013,282 | <p>I'm looking for an ORM that allows me to do bulk inserts, as well as create code based on python classes. I tried sqlobject, it worked fine for creating the tables but inserting was unacceptibly slow for the amount of data I wanted to insert. If such an ORM doesn't exist any pointers on classes that can help with th... | 1 | 2009-06-18T15:16:00Z | 1,013,307 | <p>You might want to try <a href="http://www.sqlalchemy.org/">SQLAlchemy</a>.</p>
| 5 | 2009-06-18T15:19:38Z | [
"python",
"database",
"orm"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.