title stringlengths 12 150 | question_id int64 469 40.1M | question_score int64 2 5.52k | question_date stringdate 2008-08-02 15:11:16 2016-10-18 06:16:31 | answer_id int64 536 40.1M | answer_score int64 7 8.38k | answer_date stringdate 2008-08-02 18:49:07 2016-10-18 06:19:33 | tags listlengths 1 5 | question_body_md stringlengths 15 30.2k | answer_body_md stringlengths 11 27.8k |
|---|---|---|---|---|---|---|---|---|---|
add line based on slope and intercept in matplotlib? | 7,941,226 | 11 | 2011-10-29T19:39:13Z | 14,348,481 | 7 | 2013-01-15T22:56:19Z | [
"python",
"matplotlib"
] | In R, there is a function called `abline` in which a line can be drawn on a plot based on specification of intercept (first argument) slope (second argument). For instance,
```
plot(1:10,1:10)
abline(0,1)
```
where the line with intercept of 0 and slope of 1 spans the entire range of the plot. Is there such a functio... | I couldn't figure a way to do it without resorting to callbacks, but this seems to work fairly well.
```
import numpy as np
from matplotlib import pyplot as plt
class ABLine2D(plt.Line2D):
"""
Draw a line based on its slope and y-intercept. Additional arguments are
passed to the <matplotlib.lines.Line2D... |
add line based on slope and intercept in matplotlib? | 7,941,226 | 11 | 2011-10-29T19:39:13Z | 20,477,522 | 9 | 2013-12-09T18:06:06Z | [
"python",
"matplotlib"
] | In R, there is a function called `abline` in which a line can be drawn on a plot based on specification of intercept (first argument) slope (second argument). For instance,
```
plot(1:10,1:10)
abline(0,1)
```
where the line with intercept of 0 and slope of 1 spans the entire range of the plot. Is there such a functio... | I know this question is a couple years old, but since there is no accepted answer, I'll add what works for me.
You could just plot the values in your graph, and then generate another set of values for the coordinates of the best fit line and plot that over your original graph. For example, see the following code:
```... |
How to get the function definition from an object? | 7,941,773 | 4 | 2011-10-29T21:19:12Z | 7,941,808 | 8 | 2011-10-29T21:23:13Z | [
"python"
] | Suppose we have following code defined in tester.py
```
class Tester( object ):
def method( self ):
print 'I am a Tester'
```
and we have following defined in main.py
```
from tester import Tester
t = Tester()
#print definition of t
```
is there anyway we could get the definitions of a class/function fr... | You can use the `inspect` module:
```
import inspect
class Tester( object ):
def method( self ):
print 'I am a Tester'
print inspect.getsource(Tester)
```
Output:
```
class Tester( object ):
def method( self ):
print 'I am a Tester'
``` |
Python 3.2.2 Function Returns None on Non-Empty Variable | 7,942,107 | 2 | 2011-10-29T22:31:35Z | 7,942,113 | 9 | 2011-10-29T22:33:15Z | [
"python",
"python-3.x"
] | I am writing a simple script to download .mp4 TEDTalks given a list of TEDTalk website links:
```
# Run through a list of TEDTalk website links and download each
# TEDTalk in high quality MP4
import urllib.request
#List of website links
l = [
"http://www.ted.com/index.php/talks/view/id/28",
"http://w... | > I am certain that the function findFullURL works.
Being certain that a certain piece of code works is the best way to waste hours of debugging time looking in the wrong place.
In fact that function does not work. You are missing a return:
```
def findFullURL(d, e, s):
a = s[d]
if a != "/":
#Subtrac... |
How does python compare functions? | 7,942,346 | 23 | 2011-10-29T23:30:22Z | 7,942,392 | 9 | 2011-10-29T23:41:30Z | [
"python",
"sorting"
] | How come this doesn't rise Attribute error? function object doesn't have any of the comparison methods. Does it use id() somehow?
```
fun1 = lambda:x
fun2 = lambda:x
print fun1 == fun1 # True
print fun1 == fun2 # False
print fun1 > fun2 # True
print fun1 < fun2 # False
print fun1 > 1 # True
```
I understand that it c... | `__eq__`, `__lt__` et al. don't *implement* comparisons in Python, they just let you *override* it.
The [Python language reference](http://docs.python.org/reference/expressions.html#notin) states:
> Most other objects of built-in types compare unequal unless they are the same object; the choice whether one object is ... |
How does python compare functions? | 7,942,346 | 23 | 2011-10-29T23:30:22Z | 7,942,468 | 20 | 2011-10-29T23:58:41Z | [
"python",
"sorting"
] | How come this doesn't rise Attribute error? function object doesn't have any of the comparison methods. Does it use id() somehow?
```
fun1 = lambda:x
fun2 = lambda:x
print fun1 == fun1 # True
print fun1 == fun2 # False
print fun1 > fun2 # True
print fun1 < fun2 # False
print fun1 > 1 # True
```
I understand that it c... | [Function objects](http://hg.python.org/cpython/file/2.7/Objects/funcobject.c) do not define their own comparisons or rich comparisons. Instead, they inherit from [type objects](http://hg.python.org/cpython/file/2.7/Objects/typeobject.c) which implement [rich comparisons based on the object's address in memory](http://... |
Using OR in SQLAlchemy | 7,942,547 | 76 | 2011-10-30T00:17:28Z | 7,942,571 | 119 | 2011-10-30T00:22:29Z | [
"python",
"sqlalchemy"
] | I've looked [through the docs](http://www.sqlalchemy.org/docs/orm/query.html) and I cant seem to find out how to do an OR query in SQLAlchemy. I just want to do this query.
```
SELECT address FROM addressbook WHERE city='boston' AND (lastname='bulger' OR firstname='whitey')
```
Should be something like
```
addr = se... | From the [tutorial](http://www.sqlalchemy.org/docs/orm/tutorial.html#common-filter-operators):
```
from sqlalchemy import or_
filter(or_(User.name == 'ed', User.name == 'wendy'))
``` |
Using OR in SQLAlchemy | 7,942,547 | 76 | 2011-10-30T00:17:28Z | 14,185,275 | 149 | 2013-01-06T18:23:48Z | [
"python",
"sqlalchemy"
] | I've looked [through the docs](http://www.sqlalchemy.org/docs/orm/query.html) and I cant seem to find out how to do an OR query in SQLAlchemy. I just want to do this query.
```
SELECT address FROM addressbook WHERE city='boston' AND (lastname='bulger' OR firstname='whitey')
```
Should be something like
```
addr = se... | SQLAlchemy overloads the bitwise operators `&`, `|` and `~` so instead of the ugly and hard-to-read prefix syntax with `or_()` and `and_()` (like in [Bastien's answer](http://stackoverflow.com/a/7942571/298479)) you can use these operators:
```
.filter((AddressBook.lastname == 'bulger') | (AddressBook.firstname == 'wh... |
Using OR in SQLAlchemy | 7,942,547 | 76 | 2011-10-30T00:17:28Z | 30,465,087 | 11 | 2015-05-26T17:26:09Z | [
"python",
"sqlalchemy"
] | I've looked [through the docs](http://www.sqlalchemy.org/docs/orm/query.html) and I cant seem to find out how to do an OR query in SQLAlchemy. I just want to do this query.
```
SELECT address FROM addressbook WHERE city='boston' AND (lastname='bulger' OR firstname='whitey')
```
Should be something like
```
addr = se... | or\_ operator can be useful in case of unknown number of OR query components.
For example, let's assume that we are creating a REST service with few optional filters, that should return record if any of filters return true. On the other side, if parameter was not defined in a request, our query shouldn't change. Witho... |
Correct Style for Python Line breaks | 7,942,586 | 18 | 2011-10-30T00:26:37Z | 7,942,617 | 26 | 2011-10-30T00:42:11Z | [
"python",
"coding-style",
"line-breaks",
"pep8"
] | I have some code like this. Should the break occur before the periods or after?
```
# before
my_var = somethinglikethis.where(we=do_things).where(we=domore).where(we=everdomore)
# this way
my_var = somethinglikethis.where(we=do_things) \
.where(we=domore) \
.where(w... | Personally, I prefer using parenthesis so that you don't need `\`:
```
my_var = (somethinglikethis
.where(we=do_things)
.where(we=domore)
.where(we=everdomore))
```
(I changed the indentation because that's how my editor indents it automatically.)
I just looked through PEP 8, and it loo... |
Create a python object that can be accessed with square brackets | 7,942,669 | 26 | 2011-10-30T00:59:35Z | 7,942,685 | 37 | 2011-10-30T01:03:59Z | [
"python"
] | I would like to create a new class that acts as a special type of container for objects, and can be accessed using square brackets.
For example, suppose I have a class called `ListWrapper`. Suppose `obj` is a `ListWrapper`. When I say `obj[0]`, I expect the method `obj.access()` to be called with 0 as an argument. The... | You want to define the special [`__getitem__`*[docs]*](http://docs.python.org/reference/datamodel.html#object.__getitem__) method.
```
class Test(object):
def __getitem__(self, arg):
return str(arg)*3
test = Test()
print test[0]
print test['kitten']
```
**Result:**
```
000
kittenkittenkitten
``` |
What Python framework for a REST/JSON web service with no front end? | 7,943,385 | 24 | 2011-10-30T04:58:28Z | 7,943,557 | 20 | 2011-10-30T06:01:48Z | [
"python",
"web-services",
"rest",
"tastypie"
] | I need to create a Python REST/JSON web service for an iOS app to interact with. There will be no front end on the web.
What will be the fastest, most lightweight framework to use for this? Learning curve to implement also considered?
From the research I've done Django-Tastypie or Djanjo-Piston look like the best opt... | At Pycon Australia, Richard Jones compared the most popular lightweight web frameworks. [Bottle](http://bottlepy.org/docs/dev/) came out on top. Here is the [full presentation](http://www.youtube.com/watch?v=AYjPIMe0BhA). |
What Python framework for a REST/JSON web service with no front end? | 7,943,385 | 24 | 2011-10-30T04:58:28Z | 7,948,514 | 7 | 2011-10-30T22:57:46Z | [
"python",
"web-services",
"rest",
"tastypie"
] | I need to create a Python REST/JSON web service for an iOS app to interact with. There will be no front end on the web.
What will be the fastest, most lightweight framework to use for this? Learning curve to implement also considered?
From the research I've done Django-Tastypie or Djanjo-Piston look like the best opt... | In general, I think you'll find [web2py](http://www.web2py.com) to be one of the easiest frameworks to set up, learn, and use. web2py makes it very easy to [generate JSON](http://web2py.com/book/default/chapter/09#HTML,-XML,-and-JSON) (just add a .json extension), and it now includes new functionality to automatically ... |
What is the Python 3 equivalent of "python -m SimpleHTTPServer" | 7,943,751 | 346 | 2011-10-30T07:22:49Z | 7,943,764 | 67 | 2011-10-30T07:27:48Z | [
"python",
"python-3.x"
] | What is the Python 3 equivalent of `python -m SimpleHTTPServer`? | The equivalent is:
```
python3 -m http.server
``` |
What is the Python 3 equivalent of "python -m SimpleHTTPServer" | 7,943,751 | 346 | 2011-10-30T07:22:49Z | 7,943,768 | 500 | 2011-10-30T07:28:58Z | [
"python",
"python-3.x"
] | What is the Python 3 equivalent of `python -m SimpleHTTPServer`? | From [the docs](https://docs.python.org/2/library/simplehttpserver.html):
> The `SimpleHTTPServer` module has been merged into `http.server` in Python 3.0. The 2to3 tool will automatically adapt imports when converting your sources to 3.0.
So, your command is `python3 -m http.server`. |
What is the Python 3 equivalent of "python -m SimpleHTTPServer" | 7,943,751 | 346 | 2011-10-30T07:22:49Z | 17,351,445 | 39 | 2013-06-27T19:16:32Z | [
"python",
"python-3.x"
] | What is the Python 3 equivalent of `python -m SimpleHTTPServer`? | Using 2to3 utility.
```
$ cat try.py
import SimpleHTTPServer
$ 2to3 try.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
RefactoringTool: Refactored try.py
--- t... |
What is the Python 3 equivalent of "python -m SimpleHTTPServer" | 7,943,751 | 346 | 2011-10-30T07:22:49Z | 23,260,928 | 8 | 2014-04-24T05:59:02Z | [
"python",
"python-3.x"
] | What is the Python 3 equivalent of `python -m SimpleHTTPServer`? | Here's something you might like to try, if you want a file-based version (rather than a command-line commandâothers have already stated how to do that).
```
import http.server
def start_server(port=8000, bind="", cgi=False):
if cgi==True:
http.server.test(HandlerClass=http.server.CGIHTTPRequestHandler, ... |
How to get ready using python 3.X on Mac? | 7,944,533 | 7 | 2011-10-30T10:58:03Z | 7,944,575 | 7 | 2011-10-30T11:12:06Z | [
"python",
"osx",
"development-environment"
] | I download the python 3.2 on OS X, and I installed in my harddisk. But the problem is , when I go to terminal, I type `python`...
It still shows the old version like this:
> Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple
> Inc. build 5646)] on darwin Type "help", "copyright", "credits" or
> "licens... | in your terminal, type `python3`.
on unix like system, python 2.x is generally the default python version for use by the system. but the language syntax has drastically changed between python 2 and python 3, making the 2 incompatible. thus, you cannot replace python 2 by python 3 on your system or you may completely b... |
Opening multiple (an unspecified number) of files at once and ensuring they are correctly closed | 7,945,182 | 14 | 2011-10-30T13:28:55Z | 7,945,205 | 12 | 2011-10-30T13:35:15Z | [
"python",
"exception",
"python-3.x",
"with-statement"
] | I am aware that I can open multiple files with something like,
```
with open('a', 'rb') as a, open('b', 'rb') as b:
```
But I have a situation where I have a list of files to open and am wondering what the preferred method is of doing the same when the number of files is unknown in advance. Something like,
```
with ... | No, your code wouldn't initialise `fs` unless all `open()` calls completed successfully. This should work though:
```
fs = []
try:
for f in files:
fs.append(open(f, 'rb'))
....
finally:
for f in fs:
f.close()
```
Note also that f.close() could fail so you may want to catch and ignore (or... |
Submit a form without refreshing/redirecting of the current page (Python (Django) + jQuery + Ajax) | 7,945,848 | 7 | 2011-10-30T15:32:42Z | 7,965,746 | 8 | 2011-11-01T11:27:49Z | [
"jquery",
"python",
"ajax",
"django"
] | Any way to submit a form without refreshing the current page at all using Python with jQuery Ajax? I want the end results similar to how Facebook comment works.
I'm currently using jQuery Form to do the Ajax. However, it doesn't give me the user experience that I want because:
1. After submitting using jQuery Form, t... | You could handle this by instead of using jquery's form, use jquery's ajaxPost. This will allow you to `.serialize()` the form (to get the parameters) and be able to return to a JS function to do what you want after the 'form is submitted'. Check out [`jQuery.post()`](http://api.jquery.com/jQuery.post/)
[jsFiddle](htt... |
How to migrate my app.yaml to 2.7? | 7,945,889 | 10 | 2011-10-30T15:39:01Z | 7,945,952 | 7 | 2011-10-30T15:50:18Z | [
"python",
"google-app-engine",
"python-2.7",
"yaml"
] | I'm migrating my gae app to python 2.7. This is my new app.yaml:
```
application: webfaze
version: main
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /mapreduce(/.*)?
script: mapreduce/main.application
- url: /(.*\.(html|css|js|gif|jpg|png|ico|swf))
static_files: static/\1
upload: static/.... | Checking the [source code](http://www.google.com/codesearch#Qx8E-7HUBTk/trunk/python/google/appengine/api/appinfo.py&q=%22threadsafe%20cannot%20be%20enabled%20with%20CGI%20handler%22%20package%3ahttp://googleappengine%5C.googlecode%5C.com&l=893), it looks that you need to define your handlers' path without any slash:
... |
How to migrate my app.yaml to 2.7? | 7,945,889 | 10 | 2011-10-30T15:39:01Z | 9,304,590 | 7 | 2012-02-16T02:17:40Z | [
"python",
"google-app-engine",
"python-2.7",
"yaml"
] | I'm migrating my gae app to python 2.7. This is my new app.yaml:
```
application: webfaze
version: main
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /mapreduce(/.*)?
script: mapreduce/main.application
- url: /(.*\.(html|css|js|gif|jpg|png|ico|swf))
static_files: static/\1
upload: static/.... | **Change:**
```
- url: /mapreduce(/.*)?
script: mapreduce/main.application
```
**To:**
```
- url: /mapreduce(/.*)?
script: mapreduce.main.application
```
You may also need to add an **\_\_init\_\_.py** to the 'mapreduce' folder if one doesn't exist there already. That will make the python interpret the folder a... |
Interleaving two lists in Python | 7,946,798 | 21 | 2011-10-30T18:15:32Z | 7,946,825 | 40 | 2011-10-30T18:19:27Z | [
"python",
"list"
] | In Python, is there a good way to interleave two lists of the same length?
Say I'm given `[1,2,3]` and `[10,20,30]`. I'd like to transform those into `[1,10,2,20,3,30]`. | Having posted the question, I've realised that I can simply do the following:
```
[val for pair in zip(l1, l2) for val in pair]
```
where `l1` and `l2` are the two lists. |
Interleaving two lists in Python | 7,946,798 | 21 | 2011-10-30T18:15:32Z | 7,947,461 | 15 | 2011-10-30T20:02:51Z | [
"python",
"list"
] | In Python, is there a good way to interleave two lists of the same length?
Say I'm given `[1,2,3]` and `[10,20,30]`. I'd like to transform those into `[1,10,2,20,3,30]`. | For python>=2.3, there's [extended slice syntax](http://docs.python.org/2.3/whatsnew/section-slices.html):
```
>>> a = [0, 2, 4, 6, 8]
>>> b = [1, 3, 5, 7, 9]
>>> c = a + b
>>> c[::2] = a
>>> c[1::2] = b
>>> c
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
``` |
Getting all visible text from a webpage using Selenium | 7,947,579 | 8 | 2011-10-30T20:23:47Z | 7,947,811 | 7 | 2011-10-30T21:05:43Z | [
"python",
"xpath",
"webpage",
"selenium-webdriver"
] | I've been googling this all day with out finding the answer, so apologies in advance if this is already answered.
I'm trying to get all visible text from a large number of different websites. The reason is that I want to process the text to eventually categorize the websites.
After a couple of days of research, I dec... | Using [lxml](http://codespeak.net/lxml/), you might try something like this:
```
import contextlib
import selenium.webdriver as webdriver
import lxml.html as LH
import lxml.html.clean as clean
url="http://www.yahoo.com"
ignore_tags=('script','noscript','style')
with contextlib.closing(webdriver.Firefox()) as browser:... |
Classifiers confidence in opencv face detector | 7,948,055 | 15 | 2011-10-30T21:42:37Z | 7,951,862 | 7 | 2011-10-31T09:31:39Z | [
"python",
"opencv",
"machine-learning",
"computer-vision",
"face-detection"
] | I'm using opencv's har cascade face detector (cv.HaarDetectObjects) in python.
for example:
```
faces = cv.HaarDetectObjects(grayscale, cascade, storage, 1.2, 2,
cv.CV_HAAR_DO_CANNY_PRUNING, (50,50))
for f in faces:
print(f)
```
This will print a list of detections in this form:
```
((17... | 1) The detection code produces more than one detection for an object - e.g. in different scales, slightly shifted, etc. The detections are then grouped and the number of neighbours in such a group is the number returned. See also Viola Jones paper, paragraph 5.6 (<http://research.microsoft.com/en-us/um/people/viola/Pub... |
Finding the sum of matching components in two lists | 7,948,058 | 4 | 2011-10-30T21:43:09Z | 7,948,100 | 13 | 2011-10-30T21:48:38Z | [
"python",
"list",
"sum"
] | I have two lists:
```
A = [1, 2, 3, 4, 5]
B = [6, 7, 8, 9, 10]
```
And I need to be able to find the sum of the nth terms from both lists i.e. 1+6, 2+7, 3+8 etc
Could someone please tell me how to refer to items in both lists at the same time?
I read somewhere that I could do Sum = a[i] + b[i] but I'm not convinced... | Use a list comprehension and `zip`:
```
[a + b for (a,b) in zip(A,B)]
```
Are these questions homework? Or self-study? |
Finding the sum of matching components in two lists | 7,948,058 | 4 | 2011-10-30T21:43:09Z | 7,948,152 | 15 | 2011-10-30T21:55:38Z | [
"python",
"list",
"sum"
] | I have two lists:
```
A = [1, 2, 3, 4, 5]
B = [6, 7, 8, 9, 10]
```
And I need to be able to find the sum of the nth terms from both lists i.e. 1+6, 2+7, 3+8 etc
Could someone please tell me how to refer to items in both lists at the same time?
I read somewhere that I could do Sum = a[i] + b[i] but I'm not convinced... | ```
>>> import operator
>>> map(operator.add, A, B)
[7, 9, 11, 13, 15]
```
just to demonstrate Pythons elegance :-) |
What's the difference between a Python module and a Python package? | 7,948,494 | 214 | 2011-10-30T22:53:39Z | 7,948,504 | 173 | 2011-10-30T22:55:47Z | [
"python",
"module",
"package"
] | What's the difference between a Python module and a Python package?
See also: [What's the difference between "package" and "module"](http://stackoverflow.com/questions/3680883/whats-the-difference-between-package-and-module) (for other languages) | A module is a single file (or files) that are imported under one import and used.
e.g.
```
import my_module
```
A package is a collection of modules in directories that give a package hierarchy.
```
from my_package.timing.danger.internets import function_of_love
```
[Documentation for modules](http://docs.python.or... |
What's the difference between a Python module and a Python package? | 7,948,494 | 214 | 2011-10-30T22:53:39Z | 7,948,672 | 216 | 2011-10-30T23:29:34Z | [
"python",
"module",
"package"
] | What's the difference between a Python module and a Python package?
See also: [What's the difference between "package" and "module"](http://stackoverflow.com/questions/3680883/whats-the-difference-between-package-and-module) (for other languages) | Any Python file is a [module](http://docs.python.org/tutorial/modules.html), its name being the file's base name without the `.py` extension. A [package](http://docs.python.org/tutorial/modules.html#packages) is a collection of Python modules: while a module is a single Python file, a package is a directory of Python m... |
How do I define a Python property *outside* of a class definition? | 7,948,691 | 8 | 2011-10-30T23:34:52Z | 7,948,728 | 10 | 2011-10-30T23:44:48Z | [
"python",
"properties"
] | I would like to define a Python property *outside* of a class definition:
```
c = C()
c.user = property(lambda self: User.objects.get(self.user_id))
print c.user.email
```
But I get the following error:
```
AttributeError: 'property' object has no attribute 'email'
```
What is the correct syntax for defining a prop... | Object instances like `c` cannot have properties; only classes like `C` can have properties. So you need to set the property on the class, not the instance, because Python only looks for it on the class:
```
C.user = property(lambda self: User.objects.get(self.user_id))
``` |
Create nested JSON from flat csv | 7,948,709 | 2 | 2011-10-30T23:39:28Z | 7,948,824 | 8 | 2011-10-31T00:06:11Z | [
"python",
"json",
"csv",
"nested",
"flat"
] | Trying to create a 4 deep nested JSON from a csv based upon this example:
```
Region,Company,Department,Expense,Cost
Gondwanaland,Bobs Bits,Operations,nuts,332
Gondwanaland,Bobs Bits,Operations,bolts,254
Gondwanaland,Maureens Melons,Operations,nuts,123
```
At each level I would like to sum the costs and include it in... | Here are some hints.
Parse the input to a list of lists with *csv.reader*:
```
>>> rows = list(csv.reader(source.splitlines()))
```
Loop over the list to buildi up your dictionary and summarize the costs. Depending on the structure you're looking to create the build-up might look something like this:
```
>>> summar... |
Add two lists in Python | 7,948,941 | 4 | 2011-10-31T00:34:40Z | 7,948,963 | 9 | 2011-10-31T00:37:18Z | [
"python",
"string",
"list",
"int"
] | I am trying to add together two lists so the first item of one list is added to the first item of the other list, second to second and so on to form a new list.
Currently I have:
```
def zipper(a,b):
list = [a[i] + b[i] for i in range(len(a))]
print 'The combined list of a and b is'
print list
a = input(... | Zip first, then add (only not).
```
['%s+%s' % x for x in zip(a, b)]
``` |
How to unpack 6 bytes as single integer using struct in Python | 7,949,912 | 3 | 2011-10-31T04:04:35Z | 7,949,939 | 7 | 2011-10-31T04:09:38Z | [
"python",
"struct"
] | I have the following 8 bytes:
```
b'\x05\x00\x00\x00\x00\x00\x05\x00'
```
I'm trying to get two integers using struct.unpack: one for the first 2 bytes, and one for the last 6. Getting the first two is easy using:
```
struct.unpack("<H6B")
```
But, that returns
```
(5, 0, 0, 0, 0, 5, 0)
```
I want it to return th... | Struct does not support integers with non-power-of-two size. This is common. C doesn't support such integers on your platform either (well, bitfields, but you can't make an array of those).
```
def unpack48(x):
x1, x2, x3 = struct.unpack('<HHI', x)
return x1, x2 | (x3 << 16)
``` |
How to continue with next line in a Python's try block? | 7,952,869 | 3 | 2011-10-31T11:08:38Z | 7,952,892 | 8 | 2011-10-31T11:10:10Z | [
"python",
"exception"
] | e.g.
```
try:
foo()
bar()
except:
pass
```
When foo function raise an exception, how to skip to the next line (bar) and execute it? | Take `bar()` out of the `try` block:
```
try:
foo()
except:
pass
bar()
```
Btw., watch out with catch-all `except` clauses. Prefer to selectively catch the exceptions that you know you can handle/ignore. |
Addressing sys.excepthook error in bash script | 7,955,138 | 7 | 2011-10-31T14:32:55Z | 8,690,674 | 16 | 2011-12-31T21:33:14Z | [
"python",
"bash",
"shell",
"unix"
] | I've written a bash script that is doing exactly what I want it to do, but kicking out the following error:
`close failed in file object destructor: sys.excepthook is missing lost sys.stderr`
I'm completely stumped on how to address this. Here is the script:
```
#!/bin/bash
usage () { echo "${0##*/} inputfile outpu... | I was seeing this error when piping output from a Python 2.6.2 script into the `head` command in `bash` on Ubuntu 9.04. I added `try` blocks to close `stdout` and `stderr` before exiting the script:
```
try:
sys.stdout.close()
except:
pass
try:
sys.stderr.close()
except:
pass
```
I am no longer seeing... |
Python Subprocess Grep | 7,956,865 | 7 | 2011-10-31T16:52:50Z | 7,956,965 | 7 | 2011-10-31T16:59:06Z | [
"python",
"grep",
"popen"
] | I am trying to use the grep command in a python script using the subprocess module.
Here's what I have:
```
userid = 'foo12'
p = subprocess.Popen(['grep', "%s *.log"%userid], stdout=subprocess.PIPE)
```
And it returns nothing.
I am not entirely sure what I am doing wrong so can someone please explain. The current me... | Here are two tested pieces of code to model from:
```
>>> print subprocess.check_output(['grep', 'python', 'api_talk.txt'])
Discuss python API patterns
Limitations of python
Introspection in python
>>> print subprocess.check_output('grep python *.txt', shell=True)
```
Use the latter if you want the shell to do wildc... |
Python Subprocess Grep | 7,956,865 | 7 | 2011-10-31T16:52:50Z | 7,957,083 | 9 | 2011-10-31T17:11:03Z | [
"python",
"grep",
"popen"
] | I am trying to use the grep command in a python script using the subprocess module.
Here's what I have:
```
userid = 'foo12'
p = subprocess.Popen(['grep', "%s *.log"%userid], stdout=subprocess.PIPE)
```
And it returns nothing.
I am not entirely sure what I am doing wrong so can someone please explain. The current me... | I think you're running up against two problems:
1. This call:
```
p = subprocess.Popen(['grep', "%s *.log"%userid]...
```
will not work as expected without `shell=True` because the list of arguments are being passed directly to `os.execvp`, which requires each item to be a single string representing an a... |
Error exception must derive from BaseException even when it does (Python 2.7) | 7,957,436 | 6 | 2011-10-31T17:40:43Z | 7,957,496 | 7 | 2011-10-31T17:45:44Z | [
"python"
] | What's wrong with the following code (under Python 2.7.1):
```
class TestFailed(BaseException):
def __new__(self, m):
self.message = m
def __str__(self):
return self.message
try:
raise TestFailed('Oops')
except TestFailed as x:
print x
```
When I run it, I get:
```
Traceback (most re... | [\_\_new\_\_](http://docs.python.org/reference/datamodel.html?highlight=__new__#object.__new__) is a staticmethod that needs to return an instance.
Instead, use the [\_\_init\_\_](http://docs.python.org/reference/datamodel.html?highlight=__new__#object.__init__) method:
```
>>> class TestFailed(Exception):
def __... |
Error exception must derive from BaseException even when it does (Python 2.7) | 7,957,436 | 6 | 2011-10-31T17:40:43Z | 7,957,799 | 8 | 2011-10-31T18:09:19Z | [
"python"
] | What's wrong with the following code (under Python 2.7.1):
```
class TestFailed(BaseException):
def __new__(self, m):
self.message = m
def __str__(self):
return self.message
try:
raise TestFailed('Oops')
except TestFailed as x:
print x
```
When I run it, I get:
```
Traceback (most re... | Others have shown you how to fix your implementation, but I feel it important to point out that the behavior you are implementing is already the *standard behavior of exceptions in Python* so most of your code is completely unnecessary. Just derive from `Exception` (the appropriate base class for runtime exceptions) an... |
AES in GCM mode in Python | 7,958,088 | 11 | 2011-10-31T18:36:42Z | 23,716,143 | 7 | 2014-05-17T21:15:20Z | [
"python",
"encryption",
"cryptography"
] | Does anyone know of a python library or wrapper around a c library that will easily provide Authenticated AES via [GCM mode](http://en.wikipedia.org/wiki/Galois/Counter_Mode)?
PyCrypto does not support it and it does not appear that PyOpenSSL supports direct access to the symmetric cipher portions of OpenSSL | The PyCA cryptography library provides AES-GCM: <https://cryptography.io/en/latest/hazmat/primitives/symmetric-encryption/#cryptography.hazmat.primitives.ciphers.modes.GCM> |
Example of implementation of Baum-Welch | 7,958,738 | 8 | 2011-10-31T19:35:42Z | 7,962,692 | 11 | 2011-11-01T05:12:06Z | [
"java",
"python",
"algorithm",
"statistics",
"machine-learning"
] | I'm trying to learn about Baum-Welch algorithm(to be used with a hidden markov model). I understand the basic theory of forward-backward models, but it would be nice for someone to help explain it with some code(I find it easier to read code because I can play around to understand it). I checked github and bitbucket an... | Here's some code that I wrote several years ago for a class, based on the presentation in Jurafsky/Martin (2nd edition, chapter 6, if you have access to the book). It's really not very good code, doesn't use numpy which it absolutely should, and it does some crap to have the arrays be 1-indexed instead of just tweaking... |
How to add keyboard shortcuts / accelerator keys for a menu item created by a Gedit plugin | 7,959,697 | 3 | 2011-10-31T21:00:51Z | 7,959,702 | 8 | 2011-10-31T21:01:16Z | [
"python",
"gtk",
"keyboard-shortcuts",
"pygtk",
"gedit"
] | I created a Gedit 2 plugin which adds an item to a menu as described [here](https://live.gnome.org/Gedit/PythonPluginHowToOld#Adding_a_menu_item). How could I bind a keyboard shortcut / accel key / accelerator key to this menu item? | Following the given tutorial, your plugin have some lines like the ones below somewhere:
```
self._action_group = gtk.ActionGroup("ExamplePyPluginActions")
self._action_group.add_actions([("ExamplePy", None, _("Clear document"),
None, _("Clear the document"),
self.on_clear_document_activate)])
manage... |
How can I print all unicode characters? | 7,959,740 | 6 | 2011-10-31T21:04:28Z | 7,959,764 | 7 | 2011-10-31T21:06:53Z | [
"python"
] | I want to print some unicode characters but `u'\u1000'` up to `u'\u1099'`. This doesn't work:
```
for i in range(1000,1100):
s=unicode('u'+str(i))
print i,s
``` | Use [unichr](http://docs.python.org/library/functions.html#unichr):
```
s = unichr(i)
```
From the documentation:
> `unichr(i)`
>
> Return the Unicode string of one character whose Unicode code is the integer i. For example, unichr(97) returns the string u'a'. |
How can I print all unicode characters? | 7,959,740 | 6 | 2011-10-31T21:04:28Z | 7,959,828 | 8 | 2011-10-31T21:12:49Z | [
"python"
] | I want to print some unicode characters but `u'\u1000'` up to `u'\u1099'`. This doesn't work:
```
for i in range(1000,1100):
s=unicode('u'+str(i))
print i,s
``` | You'll want to use the [unichr()](http://docs.python.org/library/functions.html#unichr) builtin function:
```
for i in range(1000,1100):
print i, unichr(i)
```
Note that in Python 3, just [chr()](http://docs.python.org/dev/library/functions.html#chr) will suffice. |
numpy: can values not be assigned to a sub-array? | 7,960,735 | 3 | 2011-10-31T22:52:20Z | 7,960,811 | 8 | 2011-10-31T23:03:30Z | [
"python",
"arrays",
"numpy"
] | ```
import numpy as np
a = np.zeros((3,2))
ind_row = np.array([0,1])
a[ind_row, 1]=3
```
now, `a` is, as expected:
```
[[ 0. 3.]
[ 0. 3.]
[ 0. 0.]]
```
I want to assign a value to a sub-array of `a[ind_row, 1]`, and expect to be able to do this as follows:
```
a[ind_row, 1][1] = 5
```
However, this leav... | The problem here is that [advanced indexing](http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing) creates a copy of the array, and only the copy is modified. (This is in contrast to basic indexing, which results in a view into the original data.)
When directly assigning to an advanced slic... |
Removing duplicates in lists | 7,961,363 | 349 | 2011-11-01T00:45:24Z | 7,961,390 | 590 | 2011-11-01T00:49:04Z | [
"python",
"list",
"duplicates"
] | Pretty much I need to write a program to check if a list has any duplicates and if it does it removes them and returns a new list with the items that werent duplicated/removed. This is what I have but to be honest I do not know what to do.
```
def remove_duplicates():
t = ['a', 'b', 'c', 'd']
t2 = ['a', 'c', '... | The common approach to get a unique collection of items is to use a [`set`](http://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset). Sets are *unordered* collections of *distinct* objects. To create a set from any iterable, you can simply pass it to the built-in [`set()`](http://docs.python.org/3/librar... |
Removing duplicates in lists | 7,961,363 | 349 | 2011-11-01T00:45:24Z | 7,961,391 | 36 | 2011-11-01T00:49:08Z | [
"python",
"list",
"duplicates"
] | Pretty much I need to write a program to check if a list has any duplicates and if it does it removes them and returns a new list with the items that werent duplicated/removed. This is what I have but to be honest I do not know what to do.
```
def remove_duplicates():
t = ['a', 'b', 'c', 'd']
t2 = ['a', 'c', '... | If you don't care about the order, just do this:
```
def remove_duplicates(l):
return list(set(l))
```
A `set` is guaranteed to not have duplicates. |
Removing duplicates in lists | 7,961,363 | 349 | 2011-11-01T00:45:24Z | 7,961,393 | 99 | 2011-11-01T00:49:33Z | [
"python",
"list",
"duplicates"
] | Pretty much I need to write a program to check if a list has any duplicates and if it does it removes them and returns a new list with the items that werent duplicated/removed. This is what I have but to be honest I do not know what to do.
```
def remove_duplicates():
t = ['a', 'b', 'c', 'd']
t2 = ['a', 'c', '... | It's a one-liner: `list(set(source_list))` will do the trick.
A `set` is something that can't possibly have duplicates. |
Removing duplicates in lists | 7,961,363 | 349 | 2011-11-01T00:45:24Z | 7,961,425 | 168 | 2011-11-01T00:53:55Z | [
"python",
"list",
"duplicates"
] | Pretty much I need to write a program to check if a list has any duplicates and if it does it removes them and returns a new list with the items that werent duplicated/removed. This is what I have but to be honest I do not know what to do.
```
def remove_duplicates():
t = ['a', 'b', 'c', 'd']
t2 = ['a', 'c', '... | FWIW, the new (v2.7) Python way for removing duplicates from an iterable while keeping it in the original order is:
```
>>> from collections import OrderedDict
>>> list(OrderedDict.fromkeys('abracadabra'))
['a', 'b', 'r', 'c', 'd']
``` |
Removing duplicates in lists | 7,961,363 | 349 | 2011-11-01T00:45:24Z | 16,543,406 | 45 | 2013-05-14T12:39:55Z | [
"python",
"list",
"duplicates"
] | Pretty much I need to write a program to check if a list has any duplicates and if it does it removes them and returns a new list with the items that werent duplicated/removed. This is what I have but to be honest I do not know what to do.
```
def remove_duplicates():
t = ['a', 'b', 'c', 'd']
t2 = ['a', 'c', '... | ```
>>> t = [1, 2, 3, 1, 2, 5, 6, 7, 8]
>>> t
[1, 2, 3, 1, 2, 5, 6, 7, 8]
>>> s = []
>>> for i in t:
if i not in s:
s.append(i)
>>> s
[1, 2, 3, 5, 6, 7, 8]
``` |
Removing duplicates in lists | 7,961,363 | 349 | 2011-11-01T00:45:24Z | 20,870,217 | 12 | 2014-01-01T15:39:09Z | [
"python",
"list",
"duplicates"
] | Pretty much I need to write a program to check if a list has any duplicates and if it does it removes them and returns a new list with the items that werent duplicated/removed. This is what I have but to be honest I do not know what to do.
```
def remove_duplicates():
t = ['a', 'b', 'c', 'd']
t2 = ['a', 'c', '... | Another way of doing :
```
>>> seq = [1,2,3,'a', 'a', 1,2]
>> dict.fromkeys(seq).keys()
['a', 1, 2, 3]
>>>
``` |
Removing duplicates in lists | 7,961,363 | 349 | 2011-11-01T00:45:24Z | 24,085,464 | 10 | 2014-06-06T15:25:56Z | [
"python",
"list",
"duplicates"
] | Pretty much I need to write a program to check if a list has any duplicates and if it does it removes them and returns a new list with the items that werent duplicated/removed. This is what I have but to be honest I do not know what to do.
```
def remove_duplicates():
t = ['a', 'b', 'c', 'd']
t2 = ['a', 'c', '... | I had a dict in my list, so I could not use the above approach. I got the error:
```
TypeError: unhashable type:
```
So if you care about **order** and/or some items are **unhashable**. Then you might find this useful:
```
def make_unique(original_list):
unique_list = []
[unique_list.append(obj) for obj in o... |
Removing duplicates in lists | 7,961,363 | 349 | 2011-11-01T00:45:24Z | 24,582,741 | 18 | 2014-07-05T03:39:26Z | [
"python",
"list",
"duplicates"
] | Pretty much I need to write a program to check if a list has any duplicates and if it does it removes them and returns a new list with the items that werent duplicated/removed. This is what I have but to be honest I do not know what to do.
```
def remove_duplicates():
t = ['a', 'b', 'c', 'd']
t2 = ['a', 'c', '... | To make a new list retaining the order of first elements of duplicates in `L`
`newlist=[ii for n,ii in enumerate(L) if ii not in L[:n]]`
for example `if L=[1, 2, 2, 3, 4, 2, 4, 3, 5]` then `newlist` will be `[1,2,3,4,5]`
This checks each new element has not appeared previously in the list before adding it.
Also it d... |
Removing duplicates in lists | 7,961,363 | 349 | 2011-11-01T00:45:24Z | 25,887,387 | 9 | 2014-09-17T09:52:45Z | [
"python",
"list",
"duplicates"
] | Pretty much I need to write a program to check if a list has any duplicates and if it does it removes them and returns a new list with the items that werent duplicated/removed. This is what I have but to be honest I do not know what to do.
```
def remove_duplicates():
t = ['a', 'b', 'c', 'd']
t2 = ['a', 'c', '... | A colleague have sent the accepted answer as part of his code to me for a codereview today.
While I certainly admire the elegance of the answer in question, I am not happy with the performance.
I have tried this solution (I use *set* to reduce lookup time)
```
def ordered_set(in_list):
out_list = []
added = se... |
Best way to loop over a python string backwards | 7,961,499 | 16 | 2011-11-01T01:07:26Z | 7,961,513 | 37 | 2011-11-01T01:10:32Z | [
"python",
"string",
"optimization",
"iterator",
"reverse"
] | What is the best way to loop over a python string backwards?
The following seems a little awkward for all the need of -1 offset:
```
string = "trick or treat"
for i in range(len(string)-1, 0-1, -1):
print string[i]
```
The following seems more succinct, but is it actually generate a reversed string so that there... | Try the *[reversed](http://docs.python.org/library/functions.html#reversed)* builtin:
```
for c in reversed(string):
print c
```
The *reversed()* call will make an iterator rather than copying the entire string.
[PEP 322](http://www.python.org/dev/peps/pep-0322/) details the motivation for *reversed()* and its ... |
Need help installing lxml on os x 10.7 | 7,961,577 | 5 | 2011-11-01T01:22:38Z | 7,961,663 | 12 | 2011-11-01T01:39:53Z | [
"python",
"lxml",
"libxml2",
"pip",
"homebrew"
] | I have been struggling to be able to do `from lxml import etree` (`import lxml` works fine by the way) The error is:
```
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/lxml/etree.so, 2): Symbol not found: _htmlParseChunk
Referenced from: /Library/Framework... | `lxml` is a bit fussy about what 3rd-party libraries it uses and it often needs newer versions than what are supplied by Apple. Suggest you read and follow the instructions [here](http://lxml.de/build.html#building-lxml-on-macos-x) for building `lxml` from source on Mac OS X including building its own statically linked... |
Sorting a list by frequency of letter in python (decreasing order) | 7,961,629 | 5 | 2011-11-01T01:33:10Z | 7,961,651 | 9 | 2011-11-01T01:37:32Z | [
"python",
"frequency"
] | Like the title says I need to write a function that will sort a list by frequency of letters. Normally I would supply my code with what I have so far but I have no idea where to get started. I'm sure its something simple but I just don't know what to do. I need them sorted in decreasing order, any help is appreciated, ... | in python 2.7 or higher you can use a counter:
<http://docs.python.org/dev/library/collections.html#collections.Counter>
```
>>> mywords = ['red', 'blue', 'red', 'green', 'blue', 'blue']
>>> cnt = Counter(mywords)
>>> cnt
Counter({'blue': 3, 'red': 2, 'green': 1})
```
as per [Word frequency count using python](http:/... |
QSettings(): How to save to current working directory | 7,962,292 | 8 | 2011-11-01T03:53:14Z | 7,963,687 | 7 | 2011-11-01T07:42:05Z | [
"python",
"pyqt4",
"pyside"
] | For an app that can be run directly from a flash/pen/usb/jump/thumb drive, for portability in moving from one machine to another it can make sense for user settings to be stored on the memory stick in the same directory that the program is being run from (rather than Windows/Mac/Linux user or system dirs per machine).
... | You can use that overload `class QSettings(fileName, format[, parent=None])` like this:
```
self.settings = QSettings("__settings.ini", QSettings.IniFormat)
```
If the path is relative, the file will already be opened in the current working directory, but that may not be what you want.
You may try one of [these an... |
Using the key in collections.defaultdict | 7,963,755 | 12 | 2011-11-01T07:52:26Z | 7,966,208 | 23 | 2011-11-01T12:10:44Z | [
"python",
"collections",
"lambda",
"defaultdict"
] | [`collections.defaultdict`](http://docs.python.org/library/collections.html#collections.defaultdict) is great. Especially in conjunction with `lambda`:
```
>>> import collections
>>> a = collections.defaultdict(lambda : [None,None])
>>> a['foo']
[None, None]
```
Is there a way to use the key given (e.g. `'foo'`) in t... | You probably want `__missing__` which is called on `dict` whenever you try to access an item not present in the dict; the vanilla `__missing__` raises an exception, but you could do whatever you like in a subclass:
```
class A(dict):
def __missing__(self, key):
value = self[key] = [None] * key
retu... |
Qt Designer: how to add custom slot and code to a button | 7,964,869 | 9 | 2011-11-01T09:59:10Z | 7,965,081 | 22 | 2011-11-01T10:21:11Z | [
"python",
"qt4",
"qt-designer"
] | I use Qt4 Designer and I want that when I click on the "yes" button, some code will execute. And when I click on the "no", some other code will be execute. How can I do it? | 1. Click on the `Edit Signal/Slots` tool.
2. Create a connection for your button. For this, select your button in the designer by pressing on it with the left button of the mouse. Move the mouse to some place in the main window to create a connection with the main window (it is like a red line with a earth connection).... |
calling a function from class in python - different way | 7,965,114 | 7 | 2011-11-01T10:24:20Z | 7,965,197 | 7 | 2011-11-01T10:32:57Z | [
"python",
"oop",
"class",
"methods"
] | EDIT2: Thank you all for your help!
EDIT: on adding @staticmethod, it works. However I am still wondering why i am getting a type error here.
I have just started OOPS and am completely new to it. I have a very basic question regarding the different ways I can call a function from a class.
I have a testClass.py file wi... | you have to use self as the first parameters of a method
in the second case you should use
```
class MathOperations:
def testAddition (self,x, y):
return x + y
def testMultiplication (self,a, b):
return a * b
```
and in your code you could do the following
```
tmp = MathOperations
print tmp... |
calling a function from class in python - different way | 7,965,114 | 7 | 2011-11-01T10:24:20Z | 7,965,449 | 7 | 2011-11-01T10:57:55Z | [
"python",
"oop",
"class",
"methods"
] | EDIT2: Thank you all for your help!
EDIT: on adding @staticmethod, it works. However I am still wondering why i am getting a type error here.
I have just started OOPS and am completely new to it. I have a very basic question regarding the different ways I can call a function from a class.
I have a testClass.py file wi... | *disclaimer: this is not a just to the point answer, it's more like a piece of advice, even if the answer can be found on the references*
IMHO: object oriented programming in Python sucks quite a lot.
The method dispatching is not very straightforward, you need to know about bound/unbound instance/class (and static!)... |
How can I set the aspect ratio in matplotlib? | 7,965,743 | 57 | 2011-11-01T11:27:29Z | 7,968,690 | 38 | 2011-11-01T15:20:54Z | [
"python",
"matplotlib"
] | I'm trying to make a square plot (using imshow), i.e. aspect ratio of 1:1, but I can't. None of these work:
```
import matplotlib.pyplot as plt
ax = fig.add_subplot(111,aspect='equal')
ax = fig.add_subplot(111,aspect=1.0)
ax.set_aspect('equal')
plt.axes().set_aspect('equal')
```
Any ideas? Let me know if you need mo... | Third times the charm. My guess is that this is a bug and [Zhenya's answer](http://stackoverflow.com/questions/7965743/python-matplotlib-setting-aspect-ratio/7969475#7969475) suggests it's fixed in the latest version. I have version 0.99.1.1 and I've created the following solution:
```
import matplotlib.pyplot as plt
... |
How can I set the aspect ratio in matplotlib? | 7,965,743 | 57 | 2011-11-01T11:27:29Z | 7,969,475 | 10 | 2011-11-01T16:18:32Z | [
"python",
"matplotlib"
] | I'm trying to make a square plot (using imshow), i.e. aspect ratio of 1:1, but I can't. None of these work:
```
import matplotlib.pyplot as plt
ax = fig.add_subplot(111,aspect='equal')
ax = fig.add_subplot(111,aspect=1.0)
ax.set_aspect('equal')
plt.axes().set_aspect('equal')
```
Any ideas? Let me know if you need mo... | What is the `matplotlib` version you are running? I have recently had to upgrade to `1.1.0`, and with it, `add_subplot(111,aspect='equal')` works for me. |
Display fullscreen mode on Tkinter | 7,966,119 | 18 | 2011-11-01T12:04:36Z | 7,966,437 | 14 | 2011-11-01T12:28:19Z | [
"python",
"tkinter"
] | How can one get a frame in Tkinter to display in fullscreen mode?
? ? I saw this code, it's very usefull,
```
>>> import Tkinter
>>> root = Tkinter.Tk()
>>> root.overrideredirect(True)
>>> root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
```
but is that a possible, when I hit E... | This creates a fullscreen window. Pressing `Escape` resizes the window to '200x200+0+0' by default. If you move or resize the window, `Escape` toggles between the current geometry and the previous geometry.
```
import Tkinter as tk
class FullScreenApp(object):
def __init__(self, master, **kwargs):
self.ma... |
Display fullscreen mode on Tkinter | 7,966,119 | 18 | 2011-11-01T12:04:36Z | 23,840,010 | 27 | 2014-05-24T00:13:49Z | [
"python",
"tkinter"
] | How can one get a frame in Tkinter to display in fullscreen mode?
? ? I saw this code, it's very usefull,
```
>>> import Tkinter
>>> root = Tkinter.Tk()
>>> root.overrideredirect(True)
>>> root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
```
but is that a possible, when I hit E... | I think this is what you're looking for:
```
Tk.attributes("-fullscreen", True) # substitute `Tk` for whatever your `Tk()` object is called
```
You can use `wm_attributes` instead of `attributes`, too.
Then just bind the escape key and add this to the handler:
```
Tk.attributes("-fullscreen", False)
```
An answer... |
Is there an easy way to manipulate XML documents in Python? | 7,967,082 | 4 | 2011-11-01T13:21:11Z | 7,967,206 | 9 | 2011-11-01T13:30:27Z | [
"python",
"xml"
] | I have done a little research around the matter, but haven't really been able to come up with anything useful. What I need is to not just parse and read, but actually manipulate XML documents in python, similar to the way JavaScript is able to manipulate HTML documents.
Allow me to give an example. say I have the foll... | [`lxml`](http://lxml.de/) allows you to select elements using XPath, and also manipulate those elements.
```
import lxml.etree as et
xmltext = """
<root>
<fruit>apple</fruit>
<fruit>pear</fruit>
<fruit>mango</fruit>
<fruit>kiwi</fruit>
</root>
"""
tree = et.fromstring(xmltext)
for fruit in tree.xpat... |
Is there an easy way to manipulate XML documents in Python? | 7,967,082 | 4 | 2011-11-01T13:21:11Z | 7,967,830 | 11 | 2011-11-01T14:16:46Z | [
"python",
"xml"
] | I have done a little research around the matter, but haven't really been able to come up with anything useful. What I need is to not just parse and read, but actually manipulate XML documents in python, similar to the way JavaScript is able to manipulate HTML documents.
Allow me to give an example. say I have the foll... | If you want to avoid installing `lxml.etree`, you can use [`xml.etree`](http://docs.python.org/library/xml.etree.elementtree.html) from the standard library.
Here is [Acorn's answer](http://stackoverflow.com/questions/7967082/is-there-an-easy-way-to-manipulate-xml-documents-in-python/7967206#7967206) ported to `xml.et... |
HTML/Javascript/CSS GUI for the development of desktop applications with python? | 7,967,575 | 5 | 2011-11-01T13:59:21Z | 7,967,636 | 9 | 2011-11-01T14:03:14Z | [
"python",
"html",
"css",
"user-interface"
] | I wonder if there's a python GUI like pyqt etc. which works purely with html and javascript for layouting desktop applications...
Do you know if there are projects like this? Does this make sense at all ;-) Or it it just me finding that a nice tool... | If it were Python-based but had nothing to do with Python, would you really care if it wasn't Python based?
Anyways, yes, a project exists. A pretty big one too. It's called [XULRunner](https://developer.mozilla.org/en/XULRunner). The project is maintained by Mozilla and is used for the GUI of every Mozilla program.
... |
Namespace, argparse, and usage | 7,968,697 | 22 | 2011-11-01T15:21:29Z | 7,968,772 | 19 | 2011-11-01T15:27:04Z | [
"python",
"namespaces",
"argparse"
] | This is really a few questions:
1. Is there a reason argparse uses a namespace instead of a dictionary?
2. Assuming I have a class with `__init__(self, init_method, *args)`. The `init_method` parameter tells the init\_function which way I want to initialize the class, while `arg` parameter gives all the arguments necc... | 1. The designers of `arparse` apparently felt it would be more convenient to access arguments as
```
args.arg_name
```
rather than
```
args["arg_name"]
```
This might be a matter of taste, though. I would have happily gone with the dictionary, especially given the fact that there is no `Name... |
Namespace, argparse, and usage | 7,968,697 | 22 | 2011-11-01T15:21:29Z | 7,968,995 | 64 | 2011-11-01T15:44:50Z | [
"python",
"namespaces",
"argparse"
] | This is really a few questions:
1. Is there a reason argparse uses a namespace instead of a dictionary?
2. Assuming I have a class with `__init__(self, init_method, *args)`. The `init_method` parameter tells the init\_function which way I want to initialize the class, while `arg` parameter gives all the arguments necc... | It is easy to convert a *Namespace* into a dictionary using [vars()](http://docs.python.org/library/functions.html#vars):
```
>>> vars(args)
``` |
Apache + mod_wsgi interaction | 7,968,840 | 12 | 2011-11-01T15:31:56Z | 7,974,689 | 9 | 2011-11-02T00:59:44Z | [
"python",
"apache",
"mod-wsgi"
] | Before posting this, I have read quite a few resources online, including the [mod\_wsgi](http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading) wiki, but I am confused about how exactly Apache processes/threads interact with mod\_wsgi.
This is my current understanding: Apache can be configured to run such that o... | Answers to each of the points.
1 - WSGIDaemonProcess/WSGIProcessGroup indicate that mod\_wsgi should fork of a separate process for running the WSGI application in. This is a fork only and not a fork/exec, so mod\_wsgi is still in control of it. When it is detected that a URL maps to a WSGI application running in daem... |
PYTHONPATH not working for sudo on GNU/Linux (works for root) | 7,969,540 | 10 | 2011-11-01T16:23:54Z | 7,974,746 | 7 | 2011-11-02T01:08:11Z | [
"python",
"linux",
"osx",
"bash",
"pythonpath"
] | EDIT: Works for root, sudo is the problem. Read below.
I have a directory with my own libraries, e.g. my Python libraries are located at `/home/name/lib/py`.
I've added this directory to **Python's PATH** for all users (including root) by adding the following line to `/etc/bash.bashrc`:
```
export PYTHONPATH=$PYTHO... | The fix in my case was to remove `Defaults !env_reset` from sudoers.
But, I had to keep `Defaults env_keep += "PYTHONPATH"` in sudoers.
I've actually added `Defaults env_reset` (which resets environment variables), but it still works because of `env_keep`.
It seems that `env_keep` and `!env_reset` conflict with eac... |
Why does 4 < '3' return True in Python 2? | 7,969,552 | 23 | 2011-11-01T16:24:37Z | 7,969,617 | 31 | 2011-11-01T16:28:59Z | [
"python",
"comparison",
"operators",
"python-2.x"
] | Why does `4 < '3'` return `True` in Python 2?
Is it because when I place single quotes around a number Python sees it as a string and strings are bigger than numbers? | Yes, any number will be less than any string (including the empty string) in Python 2.
In Python 3, you can't make arbitrary comparisons. [You'll get a `TypeError`.](http://docs.python.org/release/3.0.1/whatsnew/3.0.html#ordering-comparisons)
---
From [the link in eryksun's comment](http://hg.python.org/cpython/file... |
Why does 4 < '3' return True in Python 2? | 7,969,552 | 23 | 2011-11-01T16:24:37Z | 7,969,655 | 7 | 2011-11-01T16:32:39Z | [
"python",
"comparison",
"operators",
"python-2.x"
] | Why does `4 < '3'` return `True` in Python 2?
Is it because when I place single quotes around a number Python sees it as a string and strings are bigger than numbers? | [From Python v2.7.2 documentation](http://docs.python.org/library/stdtypes.html#comparisons)
Objects of different types except numbers are ordered by their type names; objects of the same types that donât support proper comparison are ordered by their address.
When you order two strings or two numeric types the ord... |
s3- boto- list files within a bucket by upload time | 7,969,653 | 2 | 2011-11-01T16:32:20Z | 10,488,995 | 7 | 2012-05-07T20:55:18Z | [
"python",
"amazon-s3",
"boto",
"bucket"
] | I need to download every hour 100 newest files from s3 server.
```
bucketList = bucket.list(PREFIX)
```
The code above creates list of the files but it is not depend on the uploading time of the files, since it lists by file name?
I can do nothing with file name. It is given randomly.
Thanks. | How big is the list? You could sort the list on the 'last\_modified' attr of the Key
```
orderedList = sorted(bucketList, key=lambda k: k.last_modified)
keysYouWant = orderedList[0:100]
```
If your list is HUGE this may not be efficient. Check out the inline docs for the list() function in boto.s3.bucket.Bucket. |
Python's foreach backwards | 7,969,841 | 5 | 2011-11-01T16:47:42Z | 7,969,899 | 13 | 2011-11-01T16:52:22Z | [
"python",
"foreach",
"python-2.4"
] | Does python have a means of doing foreach backwards? I'm hoping to do a filter() (or list comprehension) and reverse a list at the same time, so that I can avoid doing it separately (which I suspect will be slower). I'm using python 2.4 (I have to unfortunately), but I'm also curious what the list comprehension solutio... | You are looking for the built-in [`reversed()`](http://docs.python.org/library/functions.html#reversed):
```
>>> for i in reversed(range(5)):
... print i
...
4
3
2
1
0
```
This iterates over the sequence in reverse, without creating an additional copy of your list. |
What's the difference between globals(), locals(), and vars()? | 7,969,949 | 56 | 2011-11-01T16:56:22Z | 7,969,953 | 75 | 2011-11-01T16:57:05Z | [
"python"
] | What is the difference between `globals()`, `locals()`, and `vars()`? What do they return? Are updates to the results useful? | Each of these return a dictionary:
* `globals()` *always* returns the dictionary of the *module* namespace
* `locals()` *always* returns *a* dictionary of the *current* namespace
* `vars()` returns *either a* dictionary of the current namespace (if called with no argument) or *the* dictionary of the argument.
`locals... |
In python, how can I ensure that one of my class's methods is always called even if a subclass overrides it? | 7,970,200 | 10 | 2011-11-01T17:16:42Z | 7,970,843 | 10 | 2011-11-01T18:12:17Z | [
"python",
"subclass"
] | For example, I have a
```
class BaseHandler(object):
def prepare(self):
self.prepped = 1
```
I do not want everyone that subclasses BaseHandler and also wants to implement prepare to have to remember to call
```
super(SubBaseHandler, self).prepare()
```
Is there a way to ensure the superclass method is ... | I have solved this problem using a metaclass.
Using a metaclass allows the implementer of the `BaseHandler` to be sure that all subclasses will call the superclasses `prepare()` with no adjustment to any existing code.
The metaclass looks for an implementation of `prepare` on both classes and then overwrites the subc... |
Python - Return first N key:value pairs from dict | 7,971,618 | 16 | 2011-11-01T19:15:35Z | 7,971,655 | 25 | 2011-11-01T19:18:16Z | [
"python",
"dictionary"
] | Consider the following dictionary, d:
```
d = {'a': 3, 'b': 2, 'c': 3, 'd': 4}
```
I want to return the first N key:value pairs from d (N <= 4 in this case). What is the most efficient method of doing this? | There's no such thing a the "first n" keys because a `dict` doesn't remember which keys were inserted first.
You can get *any* n key-value pairs though:
```
n_items = take(n, d.iteritems())
```
This uses the implementation of `take` from the [`itertools` recipes](http://docs.python.org/library/itertools.html#recipes... |
Python - Return first N key:value pairs from dict | 7,971,618 | 16 | 2011-11-01T19:15:35Z | 7,971,660 | 7 | 2011-11-01T19:18:38Z | [
"python",
"dictionary"
] | Consider the following dictionary, d:
```
d = {'a': 3, 'b': 2, 'c': 3, 'd': 4}
```
I want to return the first N key:value pairs from d (N <= 4 in this case). What is the most efficient method of doing this? | Python's `dict`s are not ordered, so it's meaningless to ask for the "first N" keys.
The [`collections.OrderedDict`](http://docs.python.org/dev/library/collections.html#collections.OrderedDict) class is available if that's what you need. You could efficiently get its first four elements as
```
import itertools
import... |
Python - Return first N key:value pairs from dict | 7,971,618 | 16 | 2011-11-01T19:15:35Z | 12,980,510 | 8 | 2012-10-19T18:43:52Z | [
"python",
"dictionary"
] | Consider the following dictionary, d:
```
d = {'a': 3, 'b': 2, 'c': 3, 'd': 4}
```
I want to return the first N key:value pairs from d (N <= 4 in this case). What is the most efficient method of doing this? | A very efficient way to retrieve anything is to combine list or dictionary comprehensions with slicing. If you don't need to order the items (you just want n random pairs), you can use a dictionary comprehension like this:
```
first2pairs = {k: mydict[k] for k in mydict.keys()[:2]}
```
Generally a comprehension like ... |
Generate slug field in existing table | 7,971,689 | 2 | 2011-11-01T19:21:32Z | 7,971,800 | 15 | 2011-11-01T19:31:39Z | [
"python",
"django"
] | I have table with data. Is it possible slug field automatically generated on existing table? Or is there any other alternative? Thanks
Here is my table
 | Using the [`slugify`](https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#slugify) template filter, you can write a script, or loop through the objects in the shell.
```
>>> from django.template.defaultfilters import slugify
>>> for obj in MyModel.objects.all():
... obj.slug = slugify(obj.ti... |
importing a module in Idle shell | 7,971,744 | 3 | 2011-11-01T19:27:24Z | 7,971,928 | 7 | 2011-11-01T19:42:22Z | [
"python",
"python-3.x",
"pyc"
] | I'm trying to learn python and I'm having trouble importing a module.
I have a .pyc file that I'm trying to import into idle shell called dfa.pyc
I have the file in a folder called xyz.
I navigate to this folder using:
```
os.chdir('/Users/xxx/Desktop/xyz')
```
So now, if I try to run the command:
```
from ... | I don't think python modules are loaded I based on what you do with chdir. Modules are loaded from the folder you started the python shell and folders in PYTHONPATH.
If you want dynamically load modules maybe you can check [imp.loadmodule](http://docs.python.org/library/imp.html) (sample in the bottom of the page). |
Turning a tuple of tuples into a dictionary | 7,971,914 | 3 | 2011-11-01T19:40:53Z | 7,971,923 | 11 | 2011-11-01T19:42:06Z | [
"python"
] | So I've got tuples inside of tuples, and I would like to turn them into a key: value pair.
```
((1L, 'I.T.'), (2L, 'Project Management'), (3L, 'Creative'), (4L, 'Programming'), (5L, 'Sales'), (6L, 'Administration'), (7L, 'AV'), (8L, 'Human Resources'), (9L, 'Conference Rooms'), (10L, 'Testing'), (11L, 'none'))
```
Ho... | Just pass it to the `dict` constructor/function! It can take any iterable of `(key, value)` tuples and create a dictionary from it.
```
>>> x = ((1L, 'I.T.'), (2L, 'Project Management'), (3L, 'Creative'), (4L, 'Programming'), (5L, 'Sales'), (6L, 'Administration'), (7L, 'AV'), (8L, 'Human Resources'), (9L, 'Conference ... |
Bypass "Do you want to continue (y/n, default n)" for "setup.py"? | 7,973,986 | 2 | 2011-11-01T23:02:25Z | 7,974,019 | 8 | 2011-11-01T23:06:46Z | [
"python",
"bash",
"shell",
"install"
] | I'd like to bypass the "Do you want to continue (y/n, default n)" prompt via a shell script.
I've tried:
```
python setup.py install --force
```
and
```
python setup.py install
wait
y
```
both don't work ... anyone have other ideas? | If this question is displayed multiple times, just do a:
```
yes | command
```
However this will also aknowledge all other questions. If you want something more sophisticated have a look at [`expect`](http://linux.die.net/man/1/expect). |
lambda in python | 7,974,442 | 15 | 2011-11-02T00:12:59Z | 7,974,482 | 8 | 2011-11-02T00:18:51Z | [
"python",
"lambda",
"functional-programming"
] | I'm revisiting some scheme excercises in python (if that makes sense) to find out what python can do in terms of FP. My problem concerns lambda in python :
Can i define a general function in python with an operator as one of the arguments?
Think this :
```
def f (op,x,y):
#return some lambda function that combine... | Operators aren't really function in python, more like methods -- `x + y` is short for `x.__add__(y)`, or `y.__radd__(x)`. You can use the functions in the [`operator` module](http://docs.python.org/library/operator.html) to emulate the behavior you want. |
lambda in python | 7,974,442 | 15 | 2011-11-02T00:12:59Z | 7,974,487 | 12 | 2011-11-02T00:19:48Z | [
"python",
"lambda",
"functional-programming"
] | I'm revisiting some scheme excercises in python (if that makes sense) to find out what python can do in terms of FP. My problem concerns lambda in python :
Can i define a general function in python with an operator as one of the arguments?
Think this :
```
def f (op,x,y):
#return some lambda function that combine... | I can see some points in your question, lets go through them in order:
## 1. Can I pass a function as a parameter to someone?
Yes:
```
def f(op, x, y):
return op(x, y)
def add(x, y):
return x + y
f(add, 10, 7) #gives 17
```
## 2. What about operators then?
Unlike scheme, Python operators are not function... |
Pycrypto - Using Crypto.Random to generate a secret key and an initialisation vector | 7,974,443 | 4 | 2011-11-02T00:13:17Z | 7,974,716 | 9 | 2011-11-02T01:03:13Z | [
"python",
"pycrypto"
] | Can Crypto.Random be used to safely generate a strong secret key and an initialisation vector? | According to the [PyCryto docs](https://www.dlitz.net/software/pycrypto/doc/#crypto-publickey-public-key-algorithms), the answer is yes:
```
from Crypto.PublicKey import RSA
from Crypto import Random
rng = Random.new().read
RSAkey = RSA.generate(1024, rng)
``` |
flask blueprint template folder | 7,974,771 | 30 | 2011-11-02T01:13:09Z | 8,198,325 | 38 | 2011-11-19T23:56:04Z | [
"python",
"flask"
] | My flask app layout is:
```
myapp/
run.py
admin/
__init__.py
views.py
pages/
index.html
main/
__init__.py
views.py
pages/
index.html
```
\_***init*\_**.py files are empty. **admin/views.py** content is:
```
from flask import Blueprin... | As of Flask 0.8, blueprints add the specified template\_folder to the app's searchpath, rather than treating each of the directories as separate entities. This means that if you have two templates with the same filename, the first one found in the searchpath is the one used. This is admittedly confusing, and is poorly ... |
flask blueprint template folder | 7,974,771 | 30 | 2011-11-02T01:13:09Z | 8,737,529 | 19 | 2012-01-05T04:09:06Z | [
"python",
"flask"
] | My flask app layout is:
```
myapp/
run.py
admin/
__init__.py
views.py
pages/
index.html
main/
__init__.py
views.py
pages/
index.html
```
\_***init*\_**.py files are empty. **admin/views.py** content is:
```
from flask import Blueprin... | In addition to linqq's good suggestions above, you can also override the default functionality if needed. There are a couple ways:
One can override `create_global_jinja_loader` in a subclassed Flask application (which returns a `DispatchingJinjaLoader` defined in flask/templating.py). This is not recommended, but woul... |
flask blueprint template folder | 7,974,771 | 30 | 2011-11-02T01:13:09Z | 11,145,483 | 7 | 2012-06-21T19:34:42Z | [
"python",
"flask"
] | My flask app layout is:
```
myapp/
run.py
admin/
__init__.py
views.py
pages/
index.html
main/
__init__.py
views.py
pages/
index.html
```
\_***init*\_**.py files are empty. **admin/views.py** content is:
```
from flask import Blueprin... | twooster's answer is interesting, but another problem is that Jinja by default caches a template based on its name. Because both templates are named "index.html", the loader won't run for subsequent blueprints.
Besides linqq's two suggestions, a third option is to ignore the blueprint's templates\_folder option all to... |
How can I make one python file run another? | 7,974,849 | 68 | 2011-11-02T01:29:19Z | 7,975,511 | 90 | 2011-11-02T03:27:55Z | [
"python"
] | How I can make one python file run the other?
For example I have to two .py files. I want one file to be run, and then have it run the other .py file. | There are more than a few ways. I'll list them in order of inverted preference (*i.e.*, best first, worst last):
1. **Treat it like a module:** `import file`. This is good because it's secure, fast, and maintainable. Code gets reused as it's supposed to be done. Most Python libraries run using multiple methods stretch... |
How can I make one python file run another? | 7,974,849 | 68 | 2011-11-02T01:29:19Z | 20,457,045 | 9 | 2013-12-08T18:14:29Z | [
"python"
] | How I can make one python file run the other?
For example I have to two .py files. I want one file to be run, and then have it run the other .py file. | ## Get one python file to run another:
1. Put this in main.py:
```
#!/usr/bin/python
import yoursubfile
```
2. Put this in yoursubfile.py
```
#!/usr/bin/python
print "hello";
```
3. Run it:
```
python main.py
```
4. It prints:
```
hello
```
Thus main.py called yoursubfile... |
Deploying existing Django app on Heroku | 7,974,902 | 12 | 2011-11-02T01:38:32Z | 7,974,981 | 19 | 2011-11-02T01:53:23Z | [
"python",
"django",
"git",
"heroku"
] | Following the Heroku tutorial but I have already created a rather complex Django app that I want to upload. I have copied it to a fresh folder and issued `git init` successfully, along with adding the files to a commit. I do `heroku create --stack cedar` so I get a site then issue the `git push heroku master`. I get th... | Chris,
Specifically for Django heroku expects you to check in the directory that your Django project lives in (this directory should live at the same level as your requirements.txt). An ls might look something like:
```
$ ls
requirements.txt appfolder
$ ls appfolder
__init__.py manage.py settings.py urls.py
``... |
How does the GUI testing tool PyUseCase compare to Dogtail? | 7,975,211 | 4 | 2011-11-02T02:35:26Z | 7,987,732 | 8 | 2011-11-02T21:48:28Z | [
"python",
"user-interface",
"testing",
"automation",
"compare"
] | How does the GUI testing tool [PyUseCase](http://pypi.python.org/pypi/PyUseCase) renamed to **[StoryText](http://pypi.python.org/pypi/StoryText)**. compare to [Dogtail](http://en.wikipedia.org/wiki/Dogtail)?
I want to hear from people who have hopefully experience in using both.
Interested in:
* Maintainabilty of th... | Firstly: I'm the author of PyUseCase and I haven't done more than play around with Dogtail...
The tools are different in a number of respects.
* Dogtail works via the accessibility interface under Gnome on Linux, while PyUseCase operates via GUI toolkits (PyGTK, Tkinter, SWT/Eclipse in the current release, plus Swing... |
How can I make this loop with Jinja2? | 7,975,365 | 4 | 2011-11-02T03:00:03Z | 7,975,385 | 9 | 2011-11-02T03:04:28Z | [
"python",
"jinja2"
] | With Jinja2, how can I make an iteration like the folllowing which works with django and not Jinja:
```
{% for key,value in location_map_india.items %}
{{value.name}}
{% endfor %}
```
The above is valid django but with Jinja2 it returns an error message
> TypeError: 'builtin\_function\_or\_method' object is not iter... | In Jinja2, functions and methods [must be explicitly called](http://jinja.pocoo.org/docs/switching/#method-calls).
```
{% for key,value in location_map_india.items() %}
{{value.name}}
{% endfor %}
``` |
Is it a sin to use infinite recursion for infinite loops in Python? | 7,975,515 | 8 | 2011-11-02T03:29:05Z | 7,975,535 | 16 | 2011-11-02T03:31:56Z | [
"python",
"c",
"recursion",
"infinite-loop"
] | This question is more about curiosity than utility. If I'm writing a function that's supposed to run for ever, for instance a daemon, how would Python handle it if I called the function again from the end of the function?
```
def daemonLoop():
# Declare locals
# Do stuff
daemonLoop()
```
I'm fairly sur... | In almost all Python interpreters that will cause a stack overflow, as it would in C. The higher-level feature that would permit this is called [Tail Call Optimization](http://en.wikipedia.org/wiki/Tail_call) or Tail Recursion Elimination, and [the benevolent dictator of Python opposes adding this to the language](http... |
How do I make python processes run with correct process name? | 7,976,926 | 4 | 2011-11-02T07:20:11Z | 7,977,112 | 9 | 2011-11-02T07:44:25Z | [
"python",
"linux"
] | I have a few long term processes and temporary processes in Python. While shell and C programs run under their own names, all Python processes run as 'python filename.py', which makes it tough to identify processes.
How can I make python processes show up as 'logserver.py' or such in Linux? I use Python 2.7 in Ubuntu ... | Add a shebang to the Python file in question, make the Python file executable (e.g. by `chmod a+x ./logserver.py`) and start it directly by `./logserver.py`.
A shebang is a line telling the kernel which interpreter to use. It's simply a line like `#!/usr/bin/env python` at the very beginning of the file. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.