content stringlengths 85 101k | title stringlengths 0 150 | question stringlengths 15 48k | answers list | answers_scores list | non_answers list | non_answers_scores list | tags list | name stringlengths 35 137 |
|---|---|---|---|---|---|---|---|---|
Q:
Strange python behaviour involving floats, ints and sqlite
I have a very strange bug that I can't explain. It occurs when I combine python and sqlite. I have a table that contains a REAL field called stop_lat. When I run the following code:
c = conn.cursor()
c.execute("select stop_lat from stops;")
for (stop_lat, ... | Strange python behaviour involving floats, ints and sqlite | I have a very strange bug that I can't explain. It occurs when I combine python and sqlite. I have a table that contains a REAL field called stop_lat. When I run the following code:
c = conn.cursor()
c.execute("select stop_lat from stops;")
for (stop_lat, ) in c:
print stop_lat
print type(stop_lat)
stop_lat... | [
"It looks to me like more is changing that the commented out line.\nThe first SQL statement appears to be running, select \"stop_lat\" from stops and the other running without quotes: select stop_lat from stops.\n"
] | [
2
] | [] | [] | [
"floating_point",
"python",
"sqlite"
] | stackoverflow_0008064761_floating_point_python_sqlite.txt |
Q:
how to send image with django-email-extras
I'm using http://code.google.com/p/django-email-extras/ to generate rich email content.
I have trouble in sending email with image included.
I put this line in my template
<img border="0" src="{{ image.url }}">
Sending email python script
# put everything to dictionary
d... | how to send image with django-email-extras | I'm using http://code.google.com/p/django-email-extras/ to generate rich email content.
I have trouble in sending email with image included.
I put this line in my template
<img border="0" src="{{ image.url }}">
Sending email python script
# put everything to dictionary
dict = {'image': image,}
# send email
send_mail_... | [
"{{ image.url }} will most likely return something like \n/site_media/media/mypicture.jpeg This is not sufficient. For emails you need to include the domain address also. \nWhat does the raw html look like in the email? The src url should be similar to \"http://www.mydomain.com/{{image.url}}/ \" in the documen... | [
0
] | [] | [] | [
"django",
"email",
"python"
] | stackoverflow_0008060128_django_email_python.txt |
Q:
Error when running tests of scipy and numpy on OS X Snow Leopard
I am new to stackoverflow as well as Python, and I hope to use stackoverflow to learn and improve my Python programming.
However, as soon as I set up Python, SciPy, NumPy on my Mac, I encountered a problem when I tried running a full test of SciPy an... | Error when running tests of scipy and numpy on OS X Snow Leopard | I am new to stackoverflow as well as Python, and I hope to use stackoverflow to learn and improve my Python programming.
However, as soon as I set up Python, SciPy, NumPy on my Mac, I encountered a problem when I tried running a full test of SciPy and NumPy to verify the install:
>>> import scipy
>>> scipy.test()
Runni... | [
"I tried replicating the error that you were encountering. I did not have nose, so I was getting the same error.\nI installed nose using pip\n\n\nsudo pip install nose\n\n\nAfter that the scipy.test() worked. I did nothing else. Did you install nose using pip? If not, try using pip.\nMy machine has : \nSciPy versio... | [
7,
0
] | [] | [] | [
"nose",
"numpy",
"osx_snow_leopard",
"python",
"scipy"
] | stackoverflow_0008057777_nose_numpy_osx_snow_leopard_python_scipy.txt |
Q:
returning subarrays with the same dimensions when looping over numpy array
Consider the following convenient looping idiom.
import numpy
print "shape of"
x = numpy.array([['a', 'b'], ['c', 'd']])
print x
print "is", x.shape
for row in x:
print "shape of", row, "is", row.shape
This gives
shape of
[['a' 'b']
... | returning subarrays with the same dimensions when looping over numpy array | Consider the following convenient looping idiom.
import numpy
print "shape of"
x = numpy.array([['a', 'b'], ['c', 'd']])
print x
print "is", x.shape
for row in x:
print "shape of", row, "is", row.shape
This gives
shape of
[['a' 'b']
['c' 'd']]
is (2, 2)
shape of ['a' 'b'] is (2,)
shape of ['c' 'd'] is (2,)
My q... | [
"You can use numpy.expand_dim to increase the rank of any numpy array:\nIn [7]: x=np.array([1,2,3,4])\n\nIn [8]: x.shape\nOut[8]: (4,)\n\nIn [9]: np.expand_dims(x,axis=-1).shape\nOut[9]: (4, 1)\n\n",
"I don't see why you would want that but you could give this a try:\nfor row in x:\n print \"shape of\", row, \... | [
2,
1
] | [] | [] | [
"arrays",
"numpy",
"python"
] | stackoverflow_0008062826_arrays_numpy_python.txt |
Q:
Bind different ip addresses to scrapy spiders
How can I bind different public ip addresses to scrapy spider? And furthermore, is it possible to set rate limit for each source ip (like CONCURRENT_REQUESTS_PER_SOURCE_IP).
From scrapy documentation, CONCURRENT_REQUESTS_PER_DOMAIN and CONCURRENT_REQUESTS_PER_IP both s... | Bind different ip addresses to scrapy spiders | How can I bind different public ip addresses to scrapy spider? And furthermore, is it possible to set rate limit for each source ip (like CONCURRENT_REQUESTS_PER_SOURCE_IP).
From scrapy documentation, CONCURRENT_REQUESTS_PER_DOMAIN and CONCURRENT_REQUESTS_PER_IP both seem to work with target domain and target ip.
| [
"It is possible, but requires you to alter the Scrapy core a tiny bit.\nSomeone else made a change proposal some time ago, but it never made it by the looks of the current source.\nWith the information in this change proposal you should be able to patch it in yourself in a couple of minutes.\nAlthough the change pr... | [
0
] | [] | [] | [
"ip",
"python",
"scrapy"
] | stackoverflow_0008052662_ip_python_scrapy.txt |
Q:
python gather together ascii and utf-8 stuff
I have a text file "words.txt" that contains english words. Let's assume it contains just three words: "one", "two" and "three".
I also have three files: one.dat, two.dat and three.dat. Each of these files contains binary data representing transcription of corresponding... | python gather together ascii and utf-8 stuff | I have a text file "words.txt" that contains english words. Let's assume it contains just three words: "one", "two" and "three".
I also have three files: one.dat, two.dat and three.dat. Each of these files contains binary data representing transcription of corresponding word. Format is UTF-8.
What do I want: I want to ... | [
"In Python 2.x, reading a UTF-8 file can be accomplished using\nopen('one.dat').read().decode('utf-8')\n\nor\ncodecs.open('one.dat', encoding='utf-8').read()\n\nboth of which return a Python unicode object. If you want to turn a str (ASCII/binary string) s into a unicode, use s.decode('utf-8').\nIn Python 3.x, do j... | [
4
] | [] | [] | [
"codec",
"encoding",
"python"
] | stackoverflow_0008065914_codec_encoding_python.txt |
Q:
How to package a python3K application to an executable?
I would like to deliver the application to my client, who don't have any computer knowledge, therefore, I don't wanna to let him/her to use terminal to execute my script. How can I make a single package, and let the user double click and execute?? Is there an... | How to package a python3K application to an executable? | I would like to deliver the application to my client, who don't have any computer knowledge, therefore, I don't wanna to let him/her to use terminal to execute my script. How can I make a single package, and let the user double click and execute?? Is there any way to do so??
Moreover, is this possible to package the py... | [
"Py2Exe for Windows:\nhttp://www.py2exe.org/index.cgi/FAQ\nAnd a brief Google leads me to Py2App for OS X:\nhttp://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html\n"
] | [
2
] | [] | [] | [
"package",
"python",
"python_3.x"
] | stackoverflow_0008065542_package_python_python_3.x.txt |
Q:
Getting the final destination of a javascript redirect on a website
I parse a website with python. They use a lot of redirects and they do them by calling javascript functions.
So when I just use urllib to parse the site, it doesn't help me, because I can't find the destination url in the returned html code.
Is th... | Getting the final destination of a javascript redirect on a website | I parse a website with python. They use a lot of redirects and they do them by calling javascript functions.
So when I just use urllib to parse the site, it doesn't help me, because I can't find the destination url in the returned html code.
Is there a way to access the DOM and call the correct javascript function from... | [
"I looked into Selenium. And if you are not running a pure script (meaning you don't have a display and can't start a \"normal\" browser) the solution is actually quite simple:\nfrom selenium import webdriver\n\ndriver = webdriver.Firefox()\nlink = \"http://yourlink.com\"\ndriver.get(link)\n\n#this waits for the ne... | [
10
] | [
"It doesnt sound like fun to me, but every javascript function is a is also an object, so you can just read the function rather than call it and perhaps the URL is in it. Otherwise, that function may call another which you would then have to recurse into... Again, doesnt sound like fun, but might be doable.\n"
] | [
-1
] | [
"python",
"urllib2"
] | stackoverflow_0008053295_python_urllib2.txt |
Q:
positioning images in a CSS-grid coming from Python
I have images read out of a database by Python in the form
for i in images:
print >> htmlpage, "<img src='../folder/%s'>" % i
giving me an output on a static html-page like
<img src='../folder/image01.jpg'>
<img src='../folder/image02.jpg'>
<img src='../fold... | positioning images in a CSS-grid coming from Python | I have images read out of a database by Python in the form
for i in images:
print >> htmlpage, "<img src='../folder/%s'>" % i
giving me an output on a static html-page like
<img src='../folder/image01.jpg'>
<img src='../folder/image02.jpg'>
<img src='../folder/image03.jpg'>
<img src='../folder/image04.jpg'>
I wou... | [
"If all images have the same width you could wrap all the images in a container, give the container a width equal to the images width*5 and float the images. Check this fiddle: http://jsfiddle.net/YDUsz/\nI don't know python, so this might be stupid, but hopefully you'll get what I mean:\n<div clas=\"image-wrapper\... | [
1,
0,
0
] | [] | [] | [
"css",
"grid",
"html",
"python"
] | stackoverflow_0008065971_css_grid_html_python.txt |
Q:
is Flask an MVC or MTV?
and sorry for that question
but it seems that i dont get what is really Flask, it comes with a Template engine like the one used in django, so is it an MTV?
and each time i see something related to MVC and Python, there is Turbogears and Django, so how about Flask?
A:
As the homepage put... | is Flask an MVC or MTV? | and sorry for that question
but it seems that i dont get what is really Flask, it comes with a Template engine like the one used in django, so is it an MTV?
and each time i see something related to MVC and Python, there is Turbogears and Django, so how about Flask?
| [
"As the homepage puts it, it's a microframework. It's not an MVC (for one, there's no model in flask -- however, you can combine it with something like SQLAlchemy), and I'm not sure what you mean by MTV. It's basically a wrapper around werkzeug which is a wrapper around pure WSGI. A wrapper with templating abilitie... | [
32
] | [] | [] | [
"flask",
"model_view_controller",
"python"
] | stackoverflow_0008066199_flask_model_view_controller_python.txt |
Q:
How to send a javascript array to cherrypy
I have a jQuery post something like
var arr = ['some', 'string', 'array'];
jQuery.post('saveTheValues', { 'values': arr },
function(data)
{
//do stuff with the returned data
}, 'json'
);
And it goes to a che... | How to send a javascript array to cherrypy | I have a jQuery post something like
var arr = ['some', 'string', 'array'];
jQuery.post('saveTheValues', { 'values': arr },
function(data)
{
//do stuff with the returned data
}, 'json'
);
And it goes to a cheerypy function:
@cherrypy.expose
def saveTheValu... | [
"The problem is that newer jQuery versions send the braces as part of the name which CherryPy doesn't like. One solution is to catch this on the CherryPy side:\n@cherrypy.expose\ndef saveTheValues(self, **kw):\n values = kw.pop('values[]', [])\n #code to save the values\n\nAnother solution is to let jQuery us... | [
7
] | [] | [] | [
"cherrypy",
"jquery",
"python"
] | stackoverflow_0008065913_cherrypy_jquery_python.txt |
Q:
Cherrypy server winding up on too many requests
I was using a cherrypy based server on AWS to handle some REST API calls. But on deploying the server and with some serious traffic (around 200,000 requests within 8hours) the server wound up. The error log shows only one type of error.
ENGINE Error in HTTPServer.ti... | Cherrypy server winding up on too many requests | I was using a cherrypy based server on AWS to handle some REST API calls. But on deploying the server and with some serious traffic (around 200,000 requests within 8hours) the server wound up. The error log shows only one type of error.
ENGINE Error in HTTPServer.tick
Traceback (most recent call last):
File "/usr/lo... | [
"Sounds like you backlogged more connections than the operating system was configured to allow. Try checking ulimit -n and increasing it if you can.\n"
] | [
3
] | [] | [] | [
"amazon_ec2",
"amazon_web_services",
"cherrypy",
"python",
"rest"
] | stackoverflow_0008061527_amazon_ec2_amazon_web_services_cherrypy_python_rest.txt |
Q:
Blank page after installing dpaste in a django site. What is the issue?
This is my base.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<div style="width:50%; m... | Blank page after installing dpaste in a django site. What is the issue? | This is my base.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<div style="width:50%; marginleft:25%;">
{% block main %}{% endblock %}
</div>
I installed d... | [
"Have you moved the templates from the dpaste/templates folder into your own project's template folder (i.e. TEMPLATE_DIRS in your settings)? \n",
"Given your base.html, if {% block main %}{% endblock %} is not replaced with anything, you would get a blank page. My guess would that that is the case. What should b... | [
1,
1,
1
] | [] | [] | [
"django",
"python"
] | stackoverflow_0008066735_django_python.txt |
Q:
Enabling Template Inheritance in Django
Python 2.7.1 / Django 1.3
I am new to Django Templates and trying to do very simple template inheritance.
testbase.html
hello
{% block tester %}
fail
{% endblock %}
testblock.html
{% extends "testbase.html" %}
{% block tester %}
pass
{% endblock %}
result
hello fail
The... | Enabling Template Inheritance in Django | Python 2.7.1 / Django 1.3
I am new to Django Templates and trying to do very simple template inheritance.
testbase.html
hello
{% block tester %}
fail
{% endblock %}
testblock.html
{% extends "testbase.html" %}
{% block tester %}
pass
{% endblock %}
result
hello fail
The two templates are in the same directory whic... | [
"In your view, you need to make sure the template you are pointing to is testblock.html and not testbase.html.\nAssuming you're using render_to_response, it would look something like:\nreturn render_to_response('testblock.html')\n\nIf your view function is referencing testbase.html, then you'll get the unextended t... | [
2
] | [] | [] | [
"django",
"django_templates",
"inheritance",
"python",
"templates"
] | stackoverflow_0008059712_django_django_templates_inheritance_python_templates.txt |
Q:
Why does this List insert a nested List?
Simple question here; I've got a list of stop words in a CSV text file called stop_words.txt.
I'm using this code to add these to a list:
>>> import csv
>>> stops = []
>>> with open('/stop_words.txt', 'rU') as f:
reader = csv.reader(f)
for row in reader:
sto... | Why does this List insert a nested List? | Simple question here; I've got a list of stop words in a CSV text file called stop_words.txt.
I'm using this code to add these to a list:
>>> import csv
>>> stops = []
>>> with open('/stop_words.txt', 'rU') as f:
reader = csv.reader(f)
for row in reader:
stops.append(row)
The problem is that when I run... | [
"csv.reader returns a list for each row. Since you add row to stops, you add a list to a list. To prevent that, you could use:\nstops.extend(row)\n\nOr even better, use a list-comprehension:\nstops = [item for row in reader for item in row]\n\n",
"This looks like your stop_words.txt file is one long line. You can... | [
9,
2,
1,
1
] | [] | [] | [
"list",
"python"
] | stackoverflow_0008067096_list_python.txt |
Q:
Insert gives me an empty list? What is going on here?
>>> numlist = ['0', '1', '2', '3', '4', '5', '6']
>>> numlist = numlist.insert(0, '-1')
>>> numlist
>>> print numlist
None
>>>
I don't get it - I am trying to append to the first position of the list, and it is giving me a NoneType?
A:
list.insert modifies t... | Insert gives me an empty list? What is going on here? | >>> numlist = ['0', '1', '2', '3', '4', '5', '6']
>>> numlist = numlist.insert(0, '-1')
>>> numlist
>>> print numlist
None
>>>
I don't get it - I am trying to append to the first position of the list, and it is giving me a NoneType?
| [
"list.insert modifies the list in-place and returns None. Use it like this instead:\n>>> numlist = ['0', '1', '2', '3', '4', '5', '6']\n>>> numlist.insert(0, '-1')\n>>> numlist\n['-1', '1', '2', '3', '4', '5', '6']\n\nAlso, is there any particular reason you are using quoted numbers?\n",
"list.insert returns None... | [
9,
6,
2,
2
] | [] | [] | [
"list",
"python"
] | stackoverflow_0008067344_list_python.txt |
Q:
python: read and split files in to list of dictionaries
I'm having troubles with converting file content into list of dictionaries, could you advise?
File content:
host1.example.com#192.168.0.1#web server
host2.example.com#192.168.0.5#dns server
host3.example.com#192.168.0.7#web server
host4.example.com#192.168.... | python: read and split files in to list of dictionaries | I'm having troubles with converting file content into list of dictionaries, could you advise?
File content:
host1.example.com#192.168.0.1#web server
host2.example.com#192.168.0.5#dns server
host3.example.com#192.168.0.7#web server
host4.example.com#192.168.0.9#application server
host5.example.com#192.168.0.10#databa... | [
"First, you want to split each line on #. Then, you can use zip to zip them together with the labels, then convert it to a dictionary.\nout = []\nlabels = ['dns', 'ip', 'description']\nfor line in data:\n out.append(dict(zip(labels, line.split('#'))))\n\nThat one append line is a bit complex, so to break it down... | [
9,
2,
2,
2
] | [] | [] | [
"dictionary",
"file",
"list",
"python",
"split"
] | stackoverflow_0008067389_dictionary_file_list_python_split.txt |
Q:
Python, logging lines that cause an exception
I wrote a program in Python yesterday that checks hundreds of URLs for validity (that they won't 404 mainly) but currently when my program runs into a URL that is not valid it throws many exceptions and then crashes. I am using urllib.urlopen to visit the links. Is the... | Python, logging lines that cause an exception | I wrote a program in Python yesterday that checks hundreds of URLs for validity (that they won't 404 mainly) but currently when my program runs into a URL that is not valid it throws many exceptions and then crashes. I am using urllib.urlopen to visit the links. Is there anyway for my program to ignore these exceptions... | [
"You can use the Logger.exception() method. For example :\nLOGGER = logging.getLogger(\"my_logger_name\")\nfor my_url in urls_to_test:\n try:\n #test your url\n except Exception: # or BaseException if you really want to catch all python exceptions\n LOGGER.exception(\"something weird happened\") \n... | [
3,
0
] | [] | [] | [
"exception",
"lines",
"python",
"url"
] | stackoverflow_0008067064_exception_lines_python_url.txt |
Q:
OpenCV+Python: Firewire Cams not supported on Windows XP?
I'm trying to capture frames from a Firewire Cam (Firefyl MV) using OpenCV 2.3.1 and Python 2.7 on Windows XP.
My example finds the Camera when i use
capture = cv.CaptureFromCAM(-1)
but i cant capture the frames with
frame = cv.QueryFrame(capture)
Here ht... | OpenCV+Python: Firewire Cams not supported on Windows XP? | I'm trying to capture frames from a Firewire Cam (Firefyl MV) using OpenCV 2.3.1 and Python 2.7 on Windows XP.
My example finds the Camera when i use
capture = cv.CaptureFromCAM(-1)
but i cant capture the frames with
frame = cv.QueryFrame(capture)
Here http://opencv.willowgarage.com/documentation/python/highgui_readi... | [
"Only if the firewire camera maker included a VFW driver.\nIt's also possible to grab data from a DirectShow filter which the camera maker might provide instead \n"
] | [
1
] | [] | [] | [
"firewire",
"opencv",
"python",
"windows_xp"
] | stackoverflow_0008066559_firewire_opencv_python_windows_xp.txt |
Q:
Slicing a 20×20 area around known indices (x, y) in a numpy array
I have a large 2D numpy array for which I know a pair of indices which represent one element of the array. I want to set this element and the surrounding 20×20 area equal to zero; I have attempted using a slicing technique:
s = array[x:10, y:10]
s =... | Slicing a 20×20 area around known indices (x, y) in a numpy array | I have a large 2D numpy array for which I know a pair of indices which represent one element of the array. I want to set this element and the surrounding 20×20 area equal to zero; I have attempted using a slicing technique:
s = array[x:10, y:10]
s == 0
However, although x and y are previously defined, this is an 'inva... | [
"my_array[x - 10:x + 10, y - 10:y + 10] = 0\n\nor\ns = my_array[x - 10:x + 10, y - 10:y + 10]\ns[:] = 0\n\n",
"I believe you mean array[x:x+10,y:y+10]\n",
"You select multiple elements of an array A with A[start:stop] where start and stop are zero-based indices.\nFor a 2D Array this applies as well: A[start1:st... | [
3,
0,
0,
0
] | [] | [] | [
"arrays",
"numpy",
"python",
"slice"
] | stackoverflow_0008066410_arrays_numpy_python_slice.txt |
Q:
python-matplotlib -- how to combine multiple graphs in one - proper use of survival function
pos=10000
c=0.1
trap1=trapping(pos,c) # instance of a class
mylabel=('c=0.1','c=0.01','c=0.001')
colors=('bo','ro','mo')
for i in range(3):
plot1d=trap1.steps1d(pos,c)
cn=stats.norm.sf(plot1d) #create the sur... | python-matplotlib -- how to combine multiple graphs in one - proper use of survival function | pos=10000
c=0.1
trap1=trapping(pos,c) # instance of a class
mylabel=('c=0.1','c=0.01','c=0.001')
colors=('bo','ro','mo')
for i in range(3):
plot1d=trap1.steps1d(pos,c)
cn=stats.norm.sf(plot1d) #create the survival function
for label,color in zip(mylabel,colors):
plt.loglog(plot1d,cn,color,labe... | [
"In [44]: import scipy.stats as stats\nIn [45]: sf=stats.norm.sf\nIn [48]: np.log(sf(24))\nOut[48]: -292.09872100320786\n\nTherefore, if plot1d contains a value around 24, then the loglog plot of the survival function will have a y-axis tick mark around 10e-292. \nIf you want the y-range to vary from 0 to 1, then i... | [
1
] | [] | [] | [
"matplotlib",
"python"
] | stackoverflow_0008066844_matplotlib_python.txt |
Q:
Parsing a hierarchical config file structure with Python
I'm using ConfigParser for a project with a configuration file that is getting to large. I plan to split it but maintain a central config file that points to the others.
I haven't seen this in the documentation, but can ConfigParser handle a hierarchical con... | Parsing a hierarchical config file structure with Python | I'm using ConfigParser for a project with a configuration file that is getting to large. I plan to split it but maintain a central config file that points to the others.
I haven't seen this in the documentation, but can ConfigParser handle a hierarchical configuration file structure? Can I somehow point it from one con... | [
"You can use a Python module as configuration file, say config.py so you just have to import it : \nimport config\n\n",
"XML has XInclude support. If you use lxml when parsing an XML file, it will go off and find the configuration files that you've included through <xinclude> statements\n"
] | [
2,
1
] | [] | [] | [
"configparser",
"configuration",
"hierarchical",
"python"
] | stackoverflow_0008067403_configparser_configuration_hierarchical_python.txt |
Q:
ConfigParser vs. import config
ConfigParser is the much debated vanilla configuration parser for Python.
However you can simply import config where config.py has python code which sets configuration parameters.
What are the pros\cons of these two approaches of configuration?
When should I choose each?
A:
The big... | ConfigParser vs. import config | ConfigParser is the much debated vanilla configuration parser for Python.
However you can simply import config where config.py has python code which sets configuration parameters.
What are the pros\cons of these two approaches of configuration?
When should I choose each?
| [
"The biggest issue I see with import config is that you don't know what will happen when you import it. Yes, you will get a set of symbols that are naturally referenced using a . style interface. But the code in the configuration file can also do who-knows-what. Now, if you completely trust your users, then allo... | [
31,
8,
6,
4
] | [] | [] | [
"configparser",
"configuration",
"import_module",
"python"
] | stackoverflow_0008067651_configparser_configuration_import_module_python.txt |
Q:
Make Advanced Searches in SQLite Data Base
I got and address book with names of people.
I use the following code to perform a search in the name column:
register = []
text = "{0}%" .format(self.lineEdit_6.text())
c.execute("select id, name from contacts where nome like '{0}'" .format(text))
for row in c:
regis... | Make Advanced Searches in SQLite Data Base | I got and address book with names of people.
I use the following code to perform a search in the name column:
register = []
text = "{0}%" .format(self.lineEdit_6.text())
c.execute("select id, name from contacts where nome like '{0}'" .format(text))
for row in c:
register.append(row)
self.listWidget_4.addItem(st... | [
"Do this:\n text = \"%{0}%\" .format(self.lineEdit_6.text())\n c.execute(\"select id, name from contacts where nome like '{0}'\" .format(text))\n\n(include the wildcard before the match string as well as after).\nAlso, please consider using (note: corrected this syntax):\n c.execute(\"select id, name from ... | [
1
] | [] | [] | [
"database",
"python",
"search",
"select",
"sqlite"
] | stackoverflow_0008067971_database_python_search_select_sqlite.txt |
Q:
CleverCSS complaining when using gradient functions, is there a way to avoid this?
I'm trying to use -webkit-linear-gradient inside of CleverCSS. However, when I try to "compile" it, I get an error of TypeError: not enough arguments for format string
Here is the CleverCSS
button:
background-image: -webkit-lin... | CleverCSS complaining when using gradient functions, is there a way to avoid this? | I'm trying to use -webkit-linear-gradient inside of CleverCSS. However, when I try to "compile" it, I get an error of TypeError: not enough arguments for format string
Here is the CleverCSS
button:
background-image: -webkit-linear-gradient(top, #fff, #e6e6e6)
If I throw that into clevercss.convert(), that's the e... | [
"Use the backtick operator for verbatim CSS:\nbackground-image: `-webkit-linear-gradient(top, #fff, #e6e6e6)`\n\nThe “official” PyPI version of CleverCSS isn't maintained and may not have that feature; get an updated version from Github.\n"
] | [
3
] | [] | [] | [
"clevercss",
"css",
"python"
] | stackoverflow_0008067845_clevercss_css_python.txt |
Q:
pygooglechart define data encoding
when using chart.add_date([1,2,3,4,5]) it creates the URL with "chd=e:LNYAczgATN5m", it is encoded the data but i want to be of type text as "chd=t:1,2,3,4,5"
What is the function that can do this ?
Thanks in Advance
A:
pygooglechart attempts to detect the source data range, an... | pygooglechart define data encoding | when using chart.add_date([1,2,3,4,5]) it creates the URL with "chd=e:LNYAczgATN5m", it is encoded the data but i want to be of type text as "chd=t:1,2,3,4,5"
What is the function that can do this ?
Thanks in Advance
| [
"pygooglechart attempts to detect the source data range, and automatically decide what data encoding type to use. See the def data_class_detection() method in the source:\nhttps://github.com/gak/pygooglechart/blob/master/pygooglechart.py#L518\nTo force a certain type of encoding, you can call get_url(self, data_cla... | [
1,
0
] | [] | [] | [
"google_visualization",
"pygooglechart",
"python"
] | stackoverflow_0005716103_google_visualization_pygooglechart_python.txt |
Q:
how to make sys.executable be inherited by a subprocess in python
I have a main process which creates some child processes using subprocess.Popen. Those child processes in turn may or many not create a new processes. I want to be able to use the sys.executable from the root process.
Is there any way this can be do... | how to make sys.executable be inherited by a subprocess in python | I have a main process which creates some child processes using subprocess.Popen. Those child processes in turn may or many not create a new processes. I want to be able to use the sys.executable from the root process.
Is there any way this can be done without using environment variables which can be passed from process... | [
"As Thomas K said, sys.executable is just a variable that contains the running interpreter. To call it as a process pass it as the first argument to subprocess.Popen\nsubprocess.Popen([sys.executable, \"path/to/script.py\"])\n\n"
] | [
1
] | [] | [] | [
"python",
"subprocess"
] | stackoverflow_0008057127_python_subprocess.txt |
Q:
Python: why are * and ** faster than / and sqrt()?
While optimising my code I realised the following:
>>> from timeit import Timer as T
>>> T(lambda : 1234567890 / 4.0).repeat()
[0.22256922721862793, 0.20560789108276367, 0.20530295372009277]
>>> from __future__ import division
>>> T(lambda : 1234567890 / 4).repeat... | Python: why are * and ** faster than / and sqrt()? | While optimising my code I realised the following:
>>> from timeit import Timer as T
>>> T(lambda : 1234567890 / 4.0).repeat()
[0.22256922721862793, 0.20560789108276367, 0.20530295372009277]
>>> from __future__ import division
>>> T(lambda : 1234567890 / 4).repeat()
[0.14969301223754883, 0.14155197143554688, 0.14141488... | [
"The (somewhat unexpected) reason for your results is that Python seems to fold constant expressions involving floating-point multiplication and exponentiation, but not division. math.sqrt() is a different beast altogether since there's no bytecode for it and it involves a function call.\nOn Python 2.6.5, the follo... | [
115
] | [] | [] | [
"c",
"performance",
"python",
"python_2.7",
"python_internals"
] | stackoverflow_0008068019_c_performance_python_python_2.7_python_internals.txt |
Q:
Why is python list comprehension sometimes frowned upon?
Many developers I have met suggest it's best practice to go with simple loops and if conditions instead of one line list comprehension statements.
I have always found them very powerful as I can fit a lot of code in a single line and it saves a lot of variab... | Why is python list comprehension sometimes frowned upon? | Many developers I have met suggest it's best practice to go with simple loops and if conditions instead of one line list comprehension statements.
I have always found them very powerful as I can fit a lot of code in a single line and it saves a lot of variables from being created. Why is it still considered a bad pract... | [
"List comprehensions are used for creating lists, for example:\nsquares = [item ** 2 for item in some_list]\n\nFor loops are better for doing something with the elements of a list (or other objects):\nfor item in some_list:\n print(item)\n\nUsing a comprehension for its side effects, or a for-loop for creating a... | [
27,
6,
5
] | [] | [] | [
"list_comprehension",
"python"
] | stackoverflow_0008068251_list_comprehension_python.txt |
Q:
how to convert characters like these,"a³ a¡ a´a§" in unicode, using python?
i'm making a crawler to get text html inside, i'm using beautifulsoup.
when I open the url using urllib2, this library converts automatically the html that was using portuguese accents like " ã ó é õ " in another characters like these "a³ ... | how to convert characters like these,"a³ a¡ a´a§" in unicode, using python? | i'm making a crawler to get text html inside, i'm using beautifulsoup.
when I open the url using urllib2, this library converts automatically the html that was using portuguese accents like " ã ó é õ " in another characters like these "a³ a¡ a´a§"
what I want is just get the words without accents
contrã¡rio -> contrari... | [
"Firstly, you have to ensure that your crawler returns HTML that is unicode text (Eg. Scrapy has a method response.body_as_unicode() that does exactly this)\nOnce you have unicode text that you cant make sense of, the step of going from unicode text to equivalent ascii text lies here - http://pypi.python.org/pypi/U... | [
1
] | [
"You have byte data. You need Unicode data. Isn’t the library supposed to decode it for you? It has to, because you don’t have the HTTP headers and so lack the encoding.\nEDIT\nBizarre though this sounds, it appears that Python does not support content decoding in its web library. If you run this program:\n#!/u... | [
-2
] | [
"python",
"string",
"unicode",
"urllib",
"utf_8"
] | stackoverflow_0007237241_python_string_unicode_urllib_utf_8.txt |
Q:
Process .txt file into dictionary (Python v2.7)
I am currently looking to process and parse out information from this .txt file. The file appears to be tab delimited. I am looking to parse out the base 16 value (ie. 000000) as the dictionary key and the company name (ie. Xerox Corporation) as the dictionary value.... | Process .txt file into dictionary (Python v2.7) | I am currently looking to process and parse out information from this .txt file. The file appears to be tab delimited. I am looking to parse out the base 16 value (ie. 000000) as the dictionary key and the company name (ie. Xerox Corporation) as the dictionary value. So, if for example I look up in my dictionary the ke... | [
"result = dict()\nfor lig in open('oui.txt'):\n if 'base 16' in lig:\n num, sep, txt = lig.strip().partition('(base 16)')\n result.[num.strip()] = txt.strip()\n\n",
"Well entries are seperated with two newlines. The second line always is the base16 one. The data before the first tab is the base16... | [
1,
1,
1,
1
] | [] | [] | [
"dictionary",
"parsing",
"python"
] | stackoverflow_0008068138_dictionary_parsing_python.txt |
Q:
Coding a shell in Python
I am coding a data entry system in Python, in which the user should also be able to submit 'commands', exactly like the Python shell works, or for example SAS or R interfaces. I would like to know how to code a shell. For examnple, it should provide a prompt (which cannot be deleted by the... | Coding a shell in Python | I am coding a data entry system in Python, in which the user should also be able to submit 'commands', exactly like the Python shell works, or for example SAS or R interfaces. I would like to know how to code a shell. For examnple, it should provide a prompt (which cannot be deleted by the user, e.g. the >>> prompt in ... | [
"The cmd.Cmd class is something that would help you build a shell-like application. \nLikewise, cmd2 is a nice upgrade from the above module. With these you can build a shell application that has command history, help menus, and smart command parsing. Don't build a REPL from scratch because these modules will proba... | [
5,
0,
0
] | [] | [] | [
"python"
] | stackoverflow_0008068396_python.txt |
Q:
Python - Dynamic class import
I have the following folder structure:
- MyProject
- App1
- some_module1.py
- some_module2.py
- App2
- some_other_module1.py
- some_other_module2.py
Inside each of the modules (some_module1.py for example) there is a class that extends from a b... | Python - Dynamic class import | I have the following folder structure:
- MyProject
- App1
- some_module1.py
- some_module2.py
- App2
- some_other_module1.py
- some_other_module2.py
Inside each of the modules (some_module1.py for example) there is a class that extends from a base class, in my case, Producer.
Wh... | [
"You may want to have a look at:\n\n__import__() to import modules knowing their name as string;\ndir() to get the names of all the objects of a module (attributes, functions, etc);\ninspect.isclass(getattr(<module ref>, <object name>)) to identify classes among the objects of a module;\nissubclass() to identify su... | [
5
] | [] | [] | [
"python",
"python_import"
] | stackoverflow_0008068458_python_python_import.txt |
Q:
Add "default" headers to all boto requests?
Is it possible to set default headers for boto requests? Basically I want to include a couple of headers in every API call I make to S3.
A:
Right now, extra headers have to be specified on each request. The various methods of the bucket and key class all take an opti... | Add "default" headers to all boto requests? | Is it possible to set default headers for boto requests? Basically I want to include a couple of headers in every API call I make to S3.
| [
"Right now, extra headers have to be specified on each request. The various methods of the bucket and key class all take an optional headers parameter and the contents of that dict gets merged into the request headers.\nBeing able to specify extra headers at the bucket level and then have those merged into all req... | [
1
] | [] | [] | [
"amazon_s3",
"amazon_web_services",
"boto",
"python"
] | stackoverflow_0008068422_amazon_s3_amazon_web_services_boto_python.txt |
Q:
Plotting large numbers of points and edges in matplotlib
I have some points (about 3000) and edges (about 6000) in this type of format:
points = numpy.array([1,2],[4,5],[2,7],[3,9],[9,2])
edges = numpy.array([0,1],[3,4],[3,2],[2,4])
where the edges are indices into points, so that the start and end coordinates of... | Plotting large numbers of points and edges in matplotlib | I have some points (about 3000) and edges (about 6000) in this type of format:
points = numpy.array([1,2],[4,5],[2,7],[3,9],[9,2])
edges = numpy.array([0,1],[3,4],[3,2],[2,4])
where the edges are indices into points, so that the start and end coordinates of each edges is given by:
points[edges]
I am looking for a fas... | [
"Well, I found the following which is much faster:\nfrom matplotlib import pyplot as plt\nfrom matplotlib.collections import LineCollection\nlc = LineCollection(points[edges])\nfig = plt.figure()\nplt.gca().add_collection(lc)\nplt.xlim(points[:,0].min(), points[:,0].max())\nplt.ylim(points[:,1].min(), points[:,1].m... | [
5,
3
] | [] | [] | [
"matplotlib",
"numpy",
"python"
] | stackoverflow_0008068183_matplotlib_numpy_python.txt |
Q:
python list copy: is there a difference between old[:] and list(old)?
old = [1, 2, 3]
What is the difference between the following two lines (if there is any)?
new = old[:]
new = list(old)
Update I had already accepted ubershmekel's answer but later I've learned an interesting fact: [:] is faster for small list ... | python list copy: is there a difference between old[:] and list(old)? | old = [1, 2, 3]
What is the difference between the following two lines (if there is any)?
new = old[:]
new = list(old)
Update I had already accepted ubershmekel's answer but later I've learned an interesting fact: [:] is faster for small list (10 elements) but list() is faster for larger list (100000 elements).
~$ p... | [
"If old is not a list, old[:] will be all the elements of old in the same kind of container as old (maybe a tuple or a string), while list(old) will be a list with the same elements.\nI.e. if old is the string 'foo', old[:] will be the string 'foo', while list(old) wille be the list ['f', 'o', 'o'].\n",
"Yes ther... | [
6,
4,
1,
0,
0,
0
] | [] | [] | [
"python"
] | stackoverflow_0008067765_python.txt |
Q:
formatting string output with linebreaks and tabs in Python?
Im trying to extract some data from a large batch of files and convert them to a specific (JSON) format for importing into a database using Django Fixtures
I've been able to get this far:
'{ {\n "pk":2,\n "model": trials.conditions,\n ... | formatting string output with linebreaks and tabs in Python? | Im trying to extract some data from a large batch of files and convert them to a specific (JSON) format for importing into a database using Django Fixtures
I've been able to get this far:
'{ {\n "pk":2,\n "model": trials.conditions,\n "fields": {\n "trial_id": NCT00109798,\n ... | [
"Alternative to json.dumps indent parameter:\nPython has a pretty printer at http://docs.python.org/library/pprint.html. It is extremely simple to use but only pretty prints python objects (You can't give it a json string and expect formatted output)\nEg.\npydict = {\"name\":\"Chateau des Tours Brouilly\",\"code\":... | [
3,
1
] | [] | [] | [
"django",
"fixture",
"formatting",
"python",
"string"
] | stackoverflow_0008024769_django_fixture_formatting_python_string.txt |
Q:
Python remove JSON substring
If I have a string where there is a valid JSON substring like this one:
mystr = '100{"1":2, "3":4}312'
What is the best way to do extract just the JSON string? The numbers outside can be anything (except a { or }), including newlines and things like that.
Just to be clear, this is t... | Python remove JSON substring | If I have a string where there is a valid JSON substring like this one:
mystr = '100{"1":2, "3":4}312'
What is the best way to do extract just the JSON string? The numbers outside can be anything (except a { or }), including newlines and things like that.
Just to be clear, this is the result I want
newStr = '{"1":... | [
"Note that the following code very much assumes that there is nothing other than non-bracket material on either side of the JSON string.\nimport re\nmatcher = re.compile(r\"\"\"\n^[^\\{]* # Starting from the beginning of the string, match anything that isn't an opening bracket\n ( # Open a gr... | [
6
] | [] | [] | [
"json",
"python",
"string"
] | stackoverflow_0008068821_json_python_string.txt |
Q:
Simultaneously log and take commandline input using Twisted
I am building an app using Twisted in which a server contains some timers and several times a second it writes the timer values to a client over UDP. The client needs to be able to send various commands (such as "pause timer 1" or "reset timer 2") to the ... | Simultaneously log and take commandline input using Twisted | I am building an app using Twisted in which a server contains some timers and several times a second it writes the timer values to a client over UDP. The client needs to be able to send various commands (such as "pause timer 1" or "reset timer 2") to the server to change the timers being sent to the client. The problem... | [
"You can use twisted.internet.stdio for non-blocking standard I/O. This provides an alternate streaming, ordered, connection-oriented transport that can be used with any protocol that normally runs on such a transport (other similar transports include TCP and SSL).\nSee stdin.py and stdiodemo.py linked from http:... | [
1
] | [] | [] | [
"asynchronous",
"python",
"twisted"
] | stackoverflow_0008068085_asynchronous_python_twisted.txt |
Q:
How do I solve an import error on 'self' not being globally defined in Python?
So I keep getting this error that when I Google for it, the most common fix for it is to be sure that all the methods of a class have 'self' as the first argument. Here is the error:
File "C:\Users\me\Documents\Project\code\model\Train... | How do I solve an import error on 'self' not being globally defined in Python? | So I keep getting this error that when I Google for it, the most common fix for it is to be sure that all the methods of a class have 'self' as the first argument. Here is the error:
File "C:\Users\me\Documents\Project\code\model\TrainEvent.py", line 9, in
NameError: global name 'self' is not definedPress any key to ... | [
"The problem is in your __tagGrab function: \ndef __tagGrab(self, tagName, parent=self._element):\n\nYou cannot have self in the header -- rather have None and then correct in the body:\ndef __tagGrab(self, tagName, parent=None):\n if parent is None:\n parent = self._element\n ...\n\nThe reason is that... | [
11
] | [] | [] | [
"ironpython",
"python",
"self",
"syntax"
] | stackoverflow_0008069017_ironpython_python_self_syntax.txt |
Q:
Python Tk - Dynamically change button, defined in function, on click
I am new to making GUIs with Python and what I am trying to do should be pretty simple. Essentially, I have a dialog class that I use to instantiate a dialog in my program. One of the things on this dialog is a button that I want to use to chang... | Python Tk - Dynamically change button, defined in function, on click | I am new to making GUIs with Python and what I am trying to do should be pretty simple. Essentially, I have a dialog class that I use to instantiate a dialog in my program. One of the things on this dialog is a button that I want to use to change color. I want the user to be able to click the button, be taken to a col... | [
"Make b a member variable:\nself.b = Button(.....)\n\nThen self.chooseColor can \"see\" self.b and make changes to it:\ndef chooseColor(self):\n color = askColor()\n self.b[\"bg\"] = color # or however you change a color in python/tkinter\n\n"
] | [
2
] | [] | [] | [
"button",
"click",
"python",
"tk_toolkit",
"tkinter"
] | stackoverflow_0008069079_button_click_python_tk_toolkit_tkinter.txt |
Q:
scipy - construction of lattice which traps molecules in 2d dimension
this is a continuation of a previous stackoverflow question here
I want to do it in 2 dimensions.
I tried the following:
for i in range(pos):
steps=0 #the steps that the particle does until it falls in a trap
in_pos = sc.random.randin... | scipy - construction of lattice which traps molecules in 2d dimension | this is a continuation of a previous stackoverflow question here
I want to do it in 2 dimensions.
I tried the following:
for i in range(pos):
steps=0 #the steps that the particle does until it falls in a trap
in_pos = sc.random.randint(0, len(grid), 2)
initial_trap=False
while initial_trap==False:
... | [
"After the comments, I think I understand where you are going.\nI guess you are using periodic boundaries, but the check you are doing as below is wrong:\n# Check position for edges and fix if requireD\n\nif in_pos + step > sc.size(grid) - 1:\n in_pos = 0\nelif in_pos + step < 0:\n in_pos = sc.size(grid) - 1\... | [
3
] | [] | [] | [
"python",
"scipy"
] | stackoverflow_0008067800_python_scipy.txt |
Q:
ctypes vs C extension
I have a few functions written in C for a game project. These functions get called quite a lot (about 2000-4000 times per second). The functions are written in C for raw speed.
Now, the easiest way for me to include these functions into Python is to use ctypes. The alternative is to write a C... | ctypes vs C extension | I have a few functions written in C for a game project. These functions get called quite a lot (about 2000-4000 times per second). The functions are written in C for raw speed.
Now, the easiest way for me to include these functions into Python is to use ctypes. The alternative is to write a C extension to Python around... | [
"I've compared the performance of a C extension vs. a ctypes wrapper. In my particular test, the difference was about 250x. There were multiple calls into the C library so the ctypes wrapper was also executing Python code. The running time for the C library was very short which made the extra overhead for Python co... | [
18,
9
] | [] | [] | [
"c",
"ctypes",
"overhead",
"python"
] | stackoverflow_0008067171_c_ctypes_overhead_python.txt |
Q:
Python regex positive look ahead
I have the following regex that is supposed to find sequence of words that are ended with a punctuation. The look ahead function assures that after the match there is a space and a capital letter or digit.
pat1 = re.compile(r"\w.+?[?.!](?=\s[A-Z\d])"
What is the function of the fo... | Python regex positive look ahead | I have the following regex that is supposed to find sequence of words that are ended with a punctuation. The look ahead function assures that after the match there is a space and a capital letter or digit.
pat1 = re.compile(r"\w.+?[?.!](?=\s[A-Z\d])"
What is the function of the following lookahead?
pat2 = re.compile(... | [
"The difference is that the first lookahead expects exactly one whitespace character before the digit or capital letter while the second one expects at least one whitespace character but as many as possible.\nThe + is called a quantifier. It means 1 to n as many as possible. \nTo recap\n\\s (Exactly one whitespace ... | [
2,
2
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0008069349_python_regex.txt |
Q:
Headless Browser for Python (Javascript support REQUIRED!)
I need a headless browser which is fairly easy to use (I am still fairly new to Python and programming in general) which will allow me to navigate to a page, log into a form that requires Javascript, and then scrape the resulting web page by searching for ... | Headless Browser for Python (Javascript support REQUIRED!) | I need a headless browser which is fairly easy to use (I am still fairly new to Python and programming in general) which will allow me to navigate to a page, log into a form that requires Javascript, and then scrape the resulting web page by searching for results matching certain criteria, clicking check boxes, and cli... | [
"I use webkit as a headless browser in Python via pyqt / pyside:\nhttp://www.riverbankcomputing.co.uk/software/pyqt/download\nhttp://developer.qt.nokia.com/wiki/Category:LanguageBindings::PySide::Downloads\nI particularly like webkit because it is simple to setup. For Ubuntu you just use: sudo apt-get install pytho... | [
30,
11,
9,
5,
3,
1
] | [] | [] | [
"headless_browser",
"javascript",
"python",
"screen_scraping"
] | stackoverflow_0006025082_headless_browser_javascript_python_screen_scraping.txt |
Q:
How to find out if object has attributes?
if groupName.group == "None":
error:
AttributeError: 'NoneType' object has no attribute 'group'
How to check if object has an attribute?
A:
You want getattr(), which you can pass a default value, or hasattr().
A:
The error message is telling you that groupName itsel... | How to find out if object has attributes? | if groupName.group == "None":
error:
AttributeError: 'NoneType' object has no attribute 'group'
How to check if object has an attribute?
| [
"You want getattr(), which you can pass a default value, or hasattr().\n",
"The error message is telling you that groupName itself is None.\nIn which case, there's little point in testing whether it has a particular attribute.\nSo you probably want something more like:\nIf groupName is not None:\n print groupN... | [
9,
5,
3,
2,
1
] | [] | [] | [
"python"
] | stackoverflow_0008068478_python.txt |
Q:
Django - How use generic views from a Django external App in my own App?
I'm new to Django...
I have installed a Django external App called Haystack, this external App have a "views.py" file inside "python2.6/site-packages/haystack". I think this "views.py" is called a "generic view" in Django terms.
This generic ... | Django - How use generic views from a Django external App in my own App? | I'm new to Django...
I have installed a Django external App called Haystack, this external App have a "views.py" file inside "python2.6/site-packages/haystack". I think this "views.py" is called a "generic view" in Django terms.
This generic view is called using "urls.py" like this:
urlpatterns = patterns('haystack.vie... | [
"Try to put (r'^search/', include('haystack.urls')),. You also might want to read \"Getting started with Haystack\"\nTry: \n#your root urls.py\nfrom django.conf.urls.defaults import *\nfrom haystack.forms import FacetedSearchForm\nfrom haystack.query import SearchQuerySet\nfrom haystack.views import FacetedSearchVi... | [
1,
1
] | [] | [] | [
"django",
"django_views",
"python"
] | stackoverflow_0008069728_django_django_views_python.txt |
Q:
Django: URL doesn't match view function
I have my URL defined as follows:
(r'^article/edit/(.*)/$', 'mysite.views.edit_article')
And the function defined as:
def edit_article(request, article_id):
However, it seems that any request to this page results in the wrong value being passed in for article_id. If I rede... | Django: URL doesn't match view function | I have my URL defined as follows:
(r'^article/edit/(.*)/$', 'mysite.views.edit_article')
And the function defined as:
def edit_article(request, article_id):
However, it seems that any request to this page results in the wrong value being passed in for article_id. If I redefine my URL as
(r'^article/(.*)/$', 'mysite.v... | [
"Try this:\nurl (r'^article/edit/(?P<article_id>\\d+)$', 'mysite.views.edit_article'),\n\nTake a look at the Named Groups in the Django documentation\n"
] | [
3
] | [] | [] | [
"django",
"python"
] | stackoverflow_0008069859_django_python.txt |
Q:
Can Rails & Django (now) query more than one database at a time?
EDIT: Since you are asking for specifics, consider a photo-sharing site (like Flickr or picasa - - I know that one uses PHP, while the other uses Python) for instance. If it proves to be successful, it needs to scale enormously. I hope this is specif... | Can Rails & Django (now) query more than one database at a time? | EDIT: Since you are asking for specifics, consider a photo-sharing site (like Flickr or picasa - - I know that one uses PHP, while the other uses Python) for instance. If it proves to be successful, it needs to scale enormously. I hope this is specific enough.
It's been sometime since I heard any discussion on this, an... | [
"Multi-database support exists in Django. In our Django project we have models pulling data from Postgres, MySQL, Oracle, and MS SQL Server (there are various issues depending on the database, but it all generally works). From what I've read, RoR supports multiple databases as well. Each framework comes with its... | [
0,
0
] | [] | [] | [
"database",
"django",
"python",
"ruby",
"ruby_on_rails"
] | stackoverflow_0008069705_database_django_python_ruby_ruby_on_rails.txt |
Q:
Split string on commas but ignore commas within double-quotes?
I have some input that looks like the following:
A,B,C,"D12121",E,F,G,H,"I9,I8",J,K
The comma-separated values can be in any order. I'd like to split the string on commas; however, in the case where something is inside double quotation marks, I need i... | Split string on commas but ignore commas within double-quotes? | I have some input that looks like the following:
A,B,C,"D12121",E,F,G,H,"I9,I8",J,K
The comma-separated values can be in any order. I'd like to split the string on commas; however, in the case where something is inside double quotation marks, I need it to both ignore commas and strip out the quotation marks (if possib... | [
"Lasse is right; it's a comma separated value file, so you should use the csv module. A brief example:\nfrom csv import reader\n\n# test\ninfile = ['A,B,C,\"D12121\",E,F,G,H,\"I9,I8\",J,K']\n# real is probably like\n# infile = open('filename', 'r')\n# or use 'with open(...) as infile:' and indent the rest\n\nfor li... | [
75
] | [] | [] | [
"csv",
"double_quotes",
"python",
"regex",
"split"
] | stackoverflow_0008069975_csv_double_quotes_python_regex_split.txt |
Q:
python socket.connect does not seem to work on a virtual IP
I have set up some virtual IPs via:
~# ip link add link eth0 name eth0.1 address 11:22:33:44:55:66 type macvlan
~# ifconfig eth0.1 10.10.0.0/24
I am using the following code to connect from it:
sTCP = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sTC... | python socket.connect does not seem to work on a virtual IP | I have set up some virtual IPs via:
~# ip link add link eth0 name eth0.1 address 11:22:33:44:55:66 type macvlan
~# ifconfig eth0.1 10.10.0.0/24
I am using the following code to connect from it:
sTCP = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sTCP.setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, IFACE)
print ... | [
"I just tried this on my Fedora 13 system and it worked. I did have to make some modifications to make it work on my system, hopefully this will give you clues. Code used:\n### in shell\n# Used 00 for first MAC octet to avoid issues with multicast addressing\nip link add link eth0 name eth0.1 address 00:22:33:44:55... | [
1
] | [] | [] | [
"linux",
"networking",
"python"
] | stackoverflow_0007376024_linux_networking_python.txt |
Q:
load text file then load different words into different lists
I have searched on strings, lists, append etc. but can't seem to handle this.
I have created some files from android based on selections done in an app.
The output looks like this and is in a text file:
House 1,bwfront3,colorfront2,bwtilt3,colortilt3
... | load text file then load different words into different lists | I have searched on strings, lists, append etc. but can't seem to handle this.
I have created some files from android based on selections done in an app.
The output looks like this and is in a text file:
House 1,bwfront3,colorfront2,bwtilt3,colortilt3
House 2,bwfront6,colorfront6,bwtilt6,colortilt6
House 3,bwfront5,co... | [
"Possible way to parse such a file to count different bwfronts:\n\nimport csv\nfrom collections import Counter\n\ndef count_bwfronts():\n \"\"\"Counts occurrences of different bwfronts in \n yourfile.txt. Returns a Counter object which\n maps different bwfront values to a number of their\n occurances in... | [
1,
0,
0
] | [] | [] | [
"python"
] | stackoverflow_0008069752_python.txt |
Q:
py2exe don't install "Python version 2.5 required, which was not found in the registry"
I have python 2.7 installed on my 32-bit Windows 7 machine, I'm trying to install py2exe-0.6.9 but I receive the following error
"Python version 2.5 required, which was not found in the registry", any clue how to solve this or ... | py2exe don't install "Python version 2.5 required, which was not found in the registry" | I have python 2.7 installed on my 32-bit Windows 7 machine, I'm trying to install py2exe-0.6.9 but I receive the following error
"Python version 2.5 required, which was not found in the registry", any clue how to solve this or any good alternative to convert my python solution to exe
Thanks in Advance
| [
"Try using the Python 2.7 version of py2exe located here: http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/\nNote that if you are upgrading from previous versions of Python, you will likely need to modify your setup.py files to distribute some extra Microsoft DLLs as well.\nhttp://www.py2exe.org/index.cgi/... | [
1
] | [] | [] | [
"py2exe",
"python"
] | stackoverflow_0008066171_py2exe_python.txt |
Q:
How to get duration of video flash file?
On Linux, YouTube places temporary flash files in /tmp. Nautilus can display the duration (Minutes:Seconds) of them, but I haven't found a way to extract the duration using python.'
The fewer dependencies your method requires the better.
Thanks in advance.
A:
One way it c... | How to get duration of video flash file? | On Linux, YouTube places temporary flash files in /tmp. Nautilus can display the duration (Minutes:Seconds) of them, but I haven't found a way to extract the duration using python.'
The fewer dependencies your method requires the better.
Thanks in advance.
| [
"One way it can be done using ffmpeg. ffmpeg needs to be installed with h.264 and h.263 codec support. Then following is the command to retrieve the video duration, which can be called via python system(command).\nffmpeg -i flv_file 2>&1 | grep \"Duration\" | cut -d ' ' -f 4 | sed s/,//\n",
"While this example ma... | [
3,
1
] | [] | [] | [
"flash",
"python"
] | stackoverflow_0001615690_flash_python.txt |
Q:
How to use Python closing context manager
The standard library open function works both as a function:
f = open('file.txt')
print(type(f))
<type 'file'>
or as a context manager:
with open('file.txt') as f:
print(type(f))
<type 'file'>
I am trying to mimic this behaviour using contextlib.closing, where File i... | How to use Python closing context manager | The standard library open function works both as a function:
f = open('file.txt')
print(type(f))
<type 'file'>
or as a context manager:
with open('file.txt') as f:
print(type(f))
<type 'file'>
I am trying to mimic this behaviour using contextlib.closing, where File is my custom file I/O class:
def myopen(filename... | [
"The easiest thing is probably to implement the __enter__ and __exit__ methods yourself. Something like this should do it:\nclass File(object):\n # ... all the methods you already have ...\n\n # context management\n def __enter__(self):\n return self\n def __exit__(self, *exc_info):\n self.clos... | [
13
] | [] | [] | [
"file_io",
"python",
"with_statement"
] | stackoverflow_0008070259_file_io_python_with_statement.txt |
Q:
How to parse a string into two different strings based on first instance of an integer? (Python)
I'm trying to take a string like "PR405j" and separate it into two strings. In this instance, the two strings would be "PR" and "405j." There are a variety of strings I have to do this to. Exmaples:
"ACR498" would be "... | How to parse a string into two different strings based on first instance of an integer? (Python) | I'm trying to take a string like "PR405j" and separate it into two strings. In this instance, the two strings would be "PR" and "405j." There are a variety of strings I have to do this to. Exmaples:
"ACR498" would be "ACR" and "498", "FR707e" would be "FR" and "707e", "TY699l" would be "TY" and "699l" and so on and so ... | [
"You can use regular expressions to do simple string matching such as this. The expression '(\\D+)(.+)' is saying 'Extract one or more non-digits as the first group, then extract one or more other characters as the second.'\nimport re\n\ninputs = ['PR405j']\n\nfor input in inputs:\n match = re.match('(\\D+)(.+)... | [
5,
0,
0
] | [] | [] | [
"python",
"string"
] | stackoverflow_0008070557_python_string.txt |
Q:
Counting while compressing in LZW?
Note: This is not the right use for LZW compression. I am just playing around with it.
Question
In a single pass, is it possible to also update the frequency counts of the elements inside the dictionary?
My implementation
import sys
from collections import defaultdict
import re
... | Counting while compressing in LZW? | Note: This is not the right use for LZW compression. I am just playing around with it.
Question
In a single pass, is it possible to also update the frequency counts of the elements inside the dictionary?
My implementation
import sys
from collections import defaultdict
import re
# The silliest string!
inputString = "th... | [
"Not sure to understand your question.\nIf you just need the Frequency Table, then this should be straightforward : each time you find a pattern, you just add +1 to its frequency count.\nSo the real problem should be to find the pattern.\nIf you want to keep the patterns in sorted order, this should be pretty easy ... | [
1
] | [] | [] | [
"algorithm",
"lzw",
"python",
"string",
"text"
] | stackoverflow_0008042332_algorithm_lzw_python_string_text.txt |
Q:
Python+matplotlib: custom linestyles
I'm not satisfied with default set of linestyles, namely the size of line segments and the gap between them. I'd also want to have something like '-..', '-...', etc line patterns. Does anybody know how to customize it?
Best witches.
A:
Use set_dashes.
| Python+matplotlib: custom linestyles | I'm not satisfied with default set of linestyles, namely the size of line segments and the gap between them. I'd also want to have something like '-..', '-...', etc line patterns. Does anybody know how to customize it?
Best witches.
| [
"Use set_dashes.\n"
] | [
7
] | [] | [] | [
"matplotlib",
"python"
] | stackoverflow_0008070492_matplotlib_python.txt |
Q:
Can't pass a string to char * arg of function call in dll in python
I am trying to use a dll in Python source using the ctypes. I began reading it from Python documentation as I am new to this. After successfully loading the dll in Python, when I try to pass a string to a function which expects a char *, it gives ... | Can't pass a string to char * arg of function call in dll in python | I am trying to use a dll in Python source using the ctypes. I began reading it from Python documentation as I am new to this. After successfully loading the dll in Python, when I try to pass a string to a function which expects a char *, it gives me
"ValueError: Procedure probably called with too many arguments (4
b... | [
"Most likely the cause of the error is a mismatch of calling conventions. I'm guessing your C++ DLL exports functions with cdecl convention but your use of WinDLL implies stdcall.\nCreate your library like this to use cdecl:\nlpDLL=CDLL(\"C:\\some_path\\myDll.dll\")\n\n"
] | [
2
] | [] | [] | [
"dll",
"python"
] | stackoverflow_0008071269_dll_python.txt |
Q:
Expose API in Python for a PHP web app?
I want to create a stock picking game just to challenge my friend to see who does best with say, a million dollars. I am planning on using a Python module to fetch the stock data from Yahoo finance API. I then want my friend to login and buy/sell stock with the virtual dolla... | Expose API in Python for a PHP web app? | I want to create a stock picking game just to challenge my friend to see who does best with say, a million dollars. I am planning on using a Python module to fetch the stock data from Yahoo finance API. I then want my friend to login and buy/sell stock with the virtual dollars he has from the web app (PHP).
So, how do... | [
"Tonnes of ways:\n\nHTTP (look into Tornado Web or similar)\nSockets\nA database (such as MySQL)\nHell, even a textfile\n\nThat's assuming of course that you actually want the Python running continuously. A cron job might work fine too: http://en.wikipedia.org/wiki/Cron\n"
] | [
0
] | [] | [] | [
"api",
"php",
"python",
"web_applications"
] | stackoverflow_0008071546_api_php_python_web_applications.txt |
Q:
django form dynamic select box
I don't understand what's happening, I have in my form
mylist = forms.MultipleChoiceField(required=False, widget=forms.SelectMultiple, label='MyList',help_text = "help")
I then have some jquery on the page that adds dynamic values to this, but when I submit the form I get form.is_val... | django form dynamic select box | I don't understand what's happening, I have in my form
mylist = forms.MultipleChoiceField(required=False, widget=forms.SelectMultiple, label='MyList',help_text = "help")
I then have some jquery on the page that adds dynamic values to this, but when I submit the form I get form.is_valid to false "object has no attribute... | [
"When you submit the form MultipleChoiseField validates that all selected items belong to choises parameter of the MultipleChoiseField. If you dynamically later add fields they are naturally not in the choises set. Read more here.\nAs solution you could think of using CharField with SelectMultiple widget and overri... | [
1
] | [] | [] | [
"django",
"python"
] | stackoverflow_0008071586_django_python.txt |
Q:
Delete image in wxpython?
I know this sounds easy but how can i delete a image with wxpython?
I am using wx.StaticBitmap and wx.Image to create the image, but is there a way to delete an image?
Maybe theres something like this:
bmp1 = wx.Image(filename, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.bitmap1 = wx.Stati... | Delete image in wxpython? | I know this sounds easy but how can i delete a image with wxpython?
I am using wx.StaticBitmap and wx.Image to create the image, but is there a way to delete an image?
Maybe theres something like this:
bmp1 = wx.Image(filename, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.bitmap1 = wx.StaticBitmap(self.sizer, -1, bmp1, (... | [
"self.bitmap1.Hide() or self.bitmap1.Destroy(). The first will just hide it whereas the second will actually destroy the widget. You'll probably want to call self.Layout() to make your window redraw and update the layout of your widgets.\n"
] | [
5
] | [] | [] | [
"python",
"wxpython"
] | stackoverflow_0008071613_python_wxpython.txt |
Q:
Set stretched background image for sizer wxpython?
i am wondering how to put a stretched background image in a sizer with wxpython.
I am looking at this tutorial:
http://www.blog.pythonlibrary.org/2010/03/18/wxpython-putting-a-background-image-on-a-panel/
but the image does not resize.
import wx
#################... | Set stretched background image for sizer wxpython? | i am wondering how to put a stretched background image in a sizer with wxpython.
I am looking at this tutorial:
http://www.blog.pythonlibrary.org/2010/03/18/wxpython-putting-a-background-image-on-a-panel/
but the image does not resize.
import wx
########################################################################
... | [
"That article isn't meant to show how to stretch or resize the image. To do that, you will probably require the Python Imaging Library (PIL). Then when you resize, you can grab the new size of the frame and use that to calculate how to scale the image. See the following link to download PIL: http://www.pythonware.c... | [
1
] | [] | [] | [
"python",
"wxpython"
] | stackoverflow_0008070897_python_wxpython.txt |
Q:
Force language code in django
I have a website with two languages. Turkish and English.
I already setup django internalization with gettext.
If browser request Turkish it translates to Turkish.
If browser request English it translates to English.
But i only want Turkish language to show users.
How can i set langu... | Force language code in django | I have a website with two languages. Turkish and English.
I already setup django internalization with gettext.
If browser request Turkish it translates to Turkish.
If browser request English it translates to English.
But i only want Turkish language to show users.
How can i set language to Turkish permanently?(I am us... | [
"\nIf all you want to do is run Django with your native language, and a language file is available for it, all you need to do is set LANGUAGE_CODE.\n\nhttps://docs.djangoproject.com/en/dev/ref/settings/#language-code\n"
] | [
3
] | [] | [] | [
"django",
"locale",
"python"
] | stackoverflow_0008071739_django_locale_python.txt |
Q:
adding items to treeview in PyGObject
I have a GUI created in Glade, and I would like to populate the treeview widget. Here is the relevant part of my code
def __init__(self):
.....
self.fill_store()
self.add_column(self.widget('treeview_preview'))
self.widget('treeview_preview').set_pixbuf... | adding items to treeview in PyGObject | I have a GUI created in Glade, and I would like to populate the treeview widget. Here is the relevant part of my code
def __init__(self):
.....
self.fill_store()
self.add_column(self.widget('treeview_preview'))
self.widget('treeview_preview').set_pixbuf_column(0)
def fill_store(self):
self.... | [
"Are you sure you don't have an typo like this?\n>>> something = 1\n>>> somthing # typo, left out 'e'\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nNameError: name 'somthing' is not defined\n\n"
] | [
1
] | [] | [] | [
"glade",
"gtk",
"gtktreeview",
"pygobject",
"python"
] | stackoverflow_0008071832_glade_gtk_gtktreeview_pygobject_python.txt |
Q:
Get a List of conffiles in a deb package in python
I want to get the list of conffiles associated with a deb package using python. I am working on a project for which I need to know if any conffile installed by a package is modified so I need to have a list of conffiles installed by a package so that I can use it ... | Get a List of conffiles in a deb package in python | I want to get the list of conffiles associated with a deb package using python. I am working on a project for which I need to know if any conffile installed by a package is modified so I need to have a list of conffiles installed by a package so that I can use it to see which of the conffile has been modified.
I tried ... | [
"this is tested on python-apt on squeeze:\nthe package I used is:\nhttp://ftp.debian.org/debian/pool/main/o/openssh/openssh-server_5.5p1-6+squeeze1_amd64.deb\nfrom apt.debfile import DebPackage\nssh = DebPackage('openssh-server_5.5p1-6+squeeze1_amd64.deb')\nprint ssh.control_content('conffiles').split('\\n')\n\n[u'... | [
2,
0
] | [] | [] | [
"apt",
"package",
"python"
] | stackoverflow_0008022578_apt_package_python.txt |
Q:
IOError: [Errno url error] invalid proxy for http: 'xxx.xxx.xxx.xxx'
I'm having some trouble with my script.
It's supposed to open a website trough a proxy but I get, always, this error, with several proxies that I'm trying to...
What could it be?
Traceback (most recent call last):
File "C:\Users\Shady\Desktop\p... | IOError: [Errno url error] invalid proxy for http: 'xxx.xxx.xxx.xxx' | I'm having some trouble with my script.
It's supposed to open a website trough a proxy but I get, always, this error, with several proxies that I'm trying to...
What could it be?
Traceback (most recent call last):
File "C:\Users\Shady\Desktop\ptzplace.3.0 - Copy.py", line 43, in <module>
h = urllib.urlopen(websit... | [
"Try urllib2.urlopen instead of urllib.urlopen. I've had situations where urllib.urlopen chokes on my proxy server but urllib2.urlopen opens it fine.\n",
"I believe you need the http schema identifier before each proxy:\nproxylist = ['http://79.174.195.84:80',... 'http://79.174.33.95:3128'] \n\n",
"I try the ne... | [
9,
5,
3
] | [] | [] | [
"proxy",
"python",
"windows"
] | stackoverflow_0003191254_proxy_python_windows.txt |
Q:
what is python's road map to evolve
Where can I find the mid-term or long-term road map for python. By which, I can understand what the decision makers care the most and what the future of this language in their eyes?
I have been playing around with Python and Ruby by making small to middle sized tools I need in m... | what is python's road map to evolve | Where can I find the mid-term or long-term road map for python. By which, I can understand what the decision makers care the most and what the future of this language in their eyes?
I have been playing around with Python and Ruby by making small to middle sized tools I need in my development for a while, for fun and fo... | [
"PEP 0 lists accepted, open, and deferred proposals. See PEP 398 for the 3.3 release schedule. Also, see Nick Coghlan's blog post \"Of Python and Road Maps (or the lack thereof)\".\n"
] | [
7
] | [] | [] | [
"python",
"ruby"
] | stackoverflow_0008062336_python_ruby.txt |
Q:
How to retrieve a single item from nested dictionary in python
I am reading from a file with data like this:
{"day" :"Monday", "alarm":"on", "kids":"School" , "work":"days"}
{"day" :"Tuesday", "alarm":"on", "kids":"School" , "work":"days"}
{"day" :"Wednesday", "alarm":"on", "kids":"School" , "work":"days"}
{"day" ... | How to retrieve a single item from nested dictionary in python | I am reading from a file with data like this:
{"day" :"Monday", "alarm":"on", "kids":"School" , "work":"days"}
{"day" :"Tuesday", "alarm":"on", "kids":"School" , "work":"days"}
{"day" :"Wednesday", "alarm":"on", "kids":"School" , "work":"days"}
{"day" :"Thursday", "alarm":"on", "kids":"School" , "work":"nights"}
{"day"... | [
"You can simplify your code by using a dictionary to map weekday names to numbers. To extract the \"kids\" item of the record for day 4, you can use result[4][\"kids\"]:\ndays = {\"Monday\": 1, \"Tuesday\": 2, \"Wednesday\": 3, \"Thursday\": 4,\n \"Friday\": 5, \"Saturday\": 6, \"Sunday\": 7}\nresult = {}\n... | [
2
] | [] | [] | [
"dictionary",
"python"
] | stackoverflow_0008072025_dictionary_python.txt |
Q:
Automatically merging arbitrary Django models
I have two Django-ORM managed databases that I'd like to merge. Both have a very similar schema, and both have the standard auth_users table, along with a few other shared tables that reference each other as well as auth_users, which I'd like to merge into a single dat... | Automatically merging arbitrary Django models | I have two Django-ORM managed databases that I'd like to merge. Both have a very similar schema, and both have the standard auth_users table, along with a few other shared tables that reference each other as well as auth_users, which I'd like to merge into a single database automatically.
Understandably, this could be ... | [
"Wow. This is going to be a complex job regardless. That said:\nIf I understand the needs of your project correctly, this can be something that can be done using a data migration in South. Even so, I'd be lying if I said it was going to be a joke.\nMy recommendation is -- and this is mostly a parrot of an assumptio... | [
1
] | [] | [] | [
"database_design",
"django",
"django_models",
"django_orm",
"python"
] | stackoverflow_0008071523_database_design_django_django_models_django_orm_python.txt |
Q:
Python REPL tab completion on MacOS
Before upgrading to lion, I had tab complete working in a python shell via terminal. Following these instructions, it was possible to have tab complete working.
Since upgrading to Lion, I am now unable to get tab complete working in a terminal session of Python. I've followed th... | Python REPL tab completion on MacOS | Before upgrading to lion, I had tab complete working in a python shell via terminal. Following these instructions, it was possible to have tab complete working.
Since upgrading to Lion, I am now unable to get tab complete working in a terminal session of Python. I've followed the above instructions to the letter, and i... | [
"Apple does not ship GNU readline with OS X. It does ship BSD libedit which includes a readline compatibility interface. The system Pythons shipped by Apple and the 64-bit/32-bit Pythons from python.org installers are built with libedit. The problem is that the commands supported by libedit are completely differ... | [
114,
15
] | [] | [] | [
"macos",
"python",
"readline"
] | stackoverflow_0007116038_macos_python_readline.txt |
Q:
xpath - libxml2dom insert element to the dom?
A specific question regarding xpath, python, libxml2dom
Assume the following test html
How can one create python/xpath logic to insert an element in the dom before the tr associated with the xpath="//tr/td[@class='foo']"
I know there are associated methods for libxml2d... | xpath - libxml2dom insert element to the dom? | A specific question regarding xpath, python, libxml2dom
Assume the following test html
How can one create python/xpath logic to insert an element in the dom before the tr associated with the xpath="//tr/td[@class='foo']"
I know there are associated methods for libxml2dom to accomplish this.. but I can't find docs/examp... | [
"Yes, documentation for libxml2's Python bindings is pretty sparse. Anyway, this is how I would do it...\nimport libxml2\nhtml = '<html><body><tr><td class=\"foo\"></td></tr><tr><td></td></tr><tr><td class=\"foo\"></td></tr></body></html>'\ndoc = libxml2.parseDoc(html)\nfor elem in [xeval.parent for xeval in doc.xp... | [
0
] | [] | [] | [
"libxml2",
"python",
"xpath"
] | stackoverflow_0007421209_libxml2_python_xpath.txt |
Q:
How do I replace/update the version of the expat library used by Apache?
(Disclaimer: I just started using Linux and don't have much experience with configuring Apache and Python.)
I have a rather common issue that is explained in more depth here http://code.google.com/p/modwsgi/wiki/IssuesWithExpatLibrary. Basica... | How do I replace/update the version of the expat library used by Apache? | (Disclaimer: I just started using Linux and don't have much experience with configuring Apache and Python.)
I have a rather common issue that is explained in more depth here http://code.google.com/p/modwsgi/wiki/IssuesWithExpatLibrary. Basically, I'm 99% sure that my main issue is that my Apache is using version 1.95.7... | [
"Looking for this? It's pretty well known - I've followed this a couple of times myself.\n"
] | [
1
] | [] | [] | [
"apache",
"expat_parser",
"mod_wsgi",
"python",
"segmentation_fault"
] | stackoverflow_0008072209_apache_expat_parser_mod_wsgi_python_segmentation_fault.txt |
Q:
Is it possible to access an object via memory address?
In CPython, the builtin-function id(x) returns the memory address of x.
Is it possible to reverse this ?
Something like object_by_memoryadress(id(x)) == x.
Update: The reason I need this is, because I'm using a program with embedded Python. And in this program... | Is it possible to access an object via memory address? | In CPython, the builtin-function id(x) returns the memory address of x.
Is it possible to reverse this ?
Something like object_by_memoryadress(id(x)) == x.
Update: The reason I need this is, because I'm using a program with embedded Python. And in this program I can create so called "Nodes" that can communicate with ea... | [
"If your goal is to send info between different Python processes running concurrently, check out multiprocessing or celery.\nIf you're just looking to be able to save / restore / pass around arbitrary Python objects, check out pickle and marshal.\nDon't do this, it's wrong and bad!\n>>> x = 'asdd3r3'\n>>> b = id(x)... | [
2,
1,
0
] | [] | [] | [
"cpython",
"python"
] | stackoverflow_0007119196_cpython_python.txt |
Q:
How to get method call detail from the python hotshot profiling module?
I'm using the python hotshot profiler, and it tells me one of my methods foo() is being called N times, where N is a larger number than I was expecting.
Is there a way to get more detail about where foo() is being called from? Ideally, a list... | How to get method call detail from the python hotshot profiling module? | I'm using the python hotshot profiler, and it tells me one of my methods foo() is being called N times, where N is a larger number than I was expecting.
Is there a way to get more detail about where foo() is being called from? Ideally, a listing of module names and line numbers?
(I can't just use grep. My codebase co... | [
"One option is to add some logging to the top of foo() to indicate where it was called from, you just need to add these lines:\ndef foo():\n import traceback\n print 'foo called from', traceback.extract_stack(limit=2)[0][2]\n # previous foo() code\n\nInstead of logging you may find it more useful to mainta... | [
1
] | [] | [] | [
"callstack",
"profiler",
"python"
] | stackoverflow_0008072455_callstack_profiler_python.txt |
Q:
How to compile .py into an executable for Debian
I'm having a hard time finding a conclusive answer for how to compile a Python 2.7 .py file into a executable program for Debian. Most tutorials say "we assume you've already written the manifest, etc.", but I cannot find how to do those first steps.
So, I need a st... | How to compile .py into an executable for Debian | I'm having a hard time finding a conclusive answer for how to compile a Python 2.7 .py file into a executable program for Debian. Most tutorials say "we assume you've already written the manifest, etc.", but I cannot find how to do those first steps.
So, I need a step-by-step. How do I take JUST a .py file (using Pytho... | [
"A .deb file is not an \"executable program\", it is a package. Building a Debian package does not involve compiling, but rather, well, \"packaging\".\nA good introduction to building Debian packages is the Debian New Maintainers' Guide.\n",
"deb files are packages: an archive that extracts files into certain pre... | [
4,
3,
0
] | [] | [] | [
"compilation",
"debian",
"python"
] | stackoverflow_0008072461_compilation_debian_python.txt |
Q:
Best way to filter out emails and domains in python
I have a list of emails and domains which I am trying to filter out as a blacklist
For email it is easy, since I can simply compare the emails directly but for domains, emails with subdomains etc need to be matched as well.
so for the foo.com domain, I would need... | Best way to filter out emails and domains in python | I have a list of emails and domains which I am trying to filter out as a blacklist
For email it is easy, since I can simply compare the emails directly but for domains, emails with subdomains etc need to be matched as well.
so for the foo.com domain, I would need to filter out
x@foo.com
x@subdomain.foo.com
How is this... | [
"I'm thinking the easiest way to go about this is to use the string method ends_with. This method works as follows:\n>>> blacklisted = 'foo.com'\n>>> email = 'x@foo.com'\n>>> email.endswith('foo.com')\nTrue\n>>> email = 'x@subdomain.foo.com'\n>>> email.endswith('foo.com')\nTrue\n\nSo, this will return true if the ... | [
6,
1,
0
] | [] | [] | [
"email",
"email_validation",
"filtering",
"python",
"regex"
] | stackoverflow_0008072394_email_email_validation_filtering_python_regex.txt |
Q:
Efficient Matching of Sublists In Python
Given a two-dimensional list, I would like to find everything that contains a sublist. I realize I can do something like:
#Psuedo-Python (not kosher)
def MatchAll(theList,toMatch):
result=list(theList)
for nMatch in toMatch:
for nResult in result:
... | Efficient Matching of Sublists In Python | Given a two-dimensional list, I would like to find everything that contains a sublist. I realize I can do something like:
#Psuedo-Python (not kosher)
def MatchAll(theList,toMatch):
result=list(theList)
for nMatch in toMatch:
for nResult in result:
if not nMatch in nResult:
re... | [
"What I'd do is only keep sub-lists that match all the items in the \"match\" list.\ndef match_all(the_list, to_match):\n return [sublist for sublist in the_list \n if all(item in sublist for item in to_match)]\n\nYou can speed this up by using a set:\ndef match_all(the_list, to_match):\n match... | [
3
] | [] | [] | [
"list",
"matching",
"python",
"sublist"
] | stackoverflow_0008072811_list_matching_python_sublist.txt |
Q:
Foursquare venues from a specific area
I want to retrieve all 4sq venues from a specific area. Now I can get some venues like this:https://api.foursquare.com/v2/venues/search?ll=40.7,-74 where ll is my geopoint. I can pass a radius argument, but my area can have any shape.
For my backend I use Django
A:
/venue... | Foursquare venues from a specific area | I want to retrieve all 4sq venues from a specific area. Now I can get some venues like this:https://api.foursquare.com/v2/venues/search?ll=40.7,-74 where ll is my geopoint. I can pass a radius argument, but my area can have any shape.
For my backend I use Django
| [
"/venues/search now supports querying with rectangles (in addition to circles). Specify \"sw\" and \"ne\" params instead of \"ll\" in your request.\nYou can also now specify \"intent=browse\" to get back the best results in an area, not weighted by proximity to your region's center.\nhttps://developer.foursquare.co... | [
1
] | [] | [] | [
"django",
"foursquare",
"python"
] | stackoverflow_0007455177_django_foursquare_python.txt |
Q:
Python image processing for 16-bit grayscale png image
I'm writing a script to check if an image is normalized or not. I'm using Python PNG module to analyze the image. To test it I created a 16-bit image consisting of a 2 pixels line with a black and white pixel in Photoshop.
My script correctly identifies the bl... | Python image processing for 16-bit grayscale png image | I'm writing a script to check if an image is normalized or not. I'm using Python PNG module to analyze the image. To test it I created a 16-bit image consisting of a 2 pixels line with a black and white pixel in Photoshop.
My script correctly identifies the black pixel (0), but it gives a different value (65533) than I... | [
"It seems the PNG file really has the 65533 value stored for the white pixel instead of 65535. I assume this has something to do with the fact that Photoshop in reality works with 15 bits in the \"16 bit mode\", so there is a small inaccuracy when saving 16 bit greyscale images.\n"
] | [
2
] | [] | [] | [
"16_bit",
"image_processing",
"png",
"pypng",
"python"
] | stackoverflow_0008064384_16_bit_image_processing_png_pypng_python.txt |
Q:
Variables declared in exec'ed code don't become local in Python 3 – documentation?
The code
x = 3
def f():
exec("x = 2")
print(x)
f()
runs on both Python 2 and Python 3, but prints different results. Is this change documented anywhere? (A pointer to a mailing list discussion would also be fine -- I ask ... | Variables declared in exec'ed code don't become local in Python 3 – documentation? | The code
x = 3
def f():
exec("x = 2")
print(x)
f()
runs on both Python 2 and Python 3, but prints different results. Is this change documented anywhere? (A pointer to a mailing list discussion would also be fine -- I ask this purely out of curiosity.)
| [
"That's because some hackery were removed from Python 3.\nThe new documentation about the exec() function has some Notes about that but don't fully explain the situtation.\nPython 2, after seeing a exec statement, change every access to vars and functions to LOAD_NAME instead of LOAD_FAST or LOAD_GLOBAL.\nCheck my ... | [
5,
1
] | [] | [] | [
"python",
"python_3.x"
] | stackoverflow_0007668724_python_python_3.x.txt |
Q:
How do I setup and alternate directory structure for django?
I'm starting on my first large django project and have realized that the default directory structure isn't going to work well.
I saw this question and answer and decided to implement something similar.
Large Django application layout
What do I need to do... | How do I setup and alternate directory structure for django? | I'm starting on my first large django project and have realized that the default directory structure isn't going to work well.
I saw this question and answer and decided to implement something similar.
Large Django application layout
What do I need to do to make something like this work? How can I change where django l... | [
"I have two methods to handle this; one for production and one for development. \nIn development:\nAppend the path to your apps in your settings.py. In my case, I have my main project in ~/hg/django/project/ and my apps are in ~/hg/django/apps/. So I use:\nif DEVEL:\n sys.path.insert(0, os.path.join(os.path.d... | [
1,
1,
1
] | [] | [] | [
"django",
"python"
] | stackoverflow_0008072358_django_python.txt |
Q:
wx.TaskBarIcon on Ubuntu 11.04
There is no tray in Unity under Ubuntu 11.04.
How can I make icon appear somewhere in Unity? wx.TaskBarIcon is not appear anywhere.
Thanks
A:
With Ubuntu Unity desktop environment (i.e. Ubuntu 11.04 or 11.10), you need to "whitelist" your application.
There are different ways to do... | wx.TaskBarIcon on Ubuntu 11.04 | There is no tray in Unity under Ubuntu 11.04.
How can I make icon appear somewhere in Unity? wx.TaskBarIcon is not appear anywhere.
Thanks
| [
"With Ubuntu Unity desktop environment (i.e. Ubuntu 11.04 or 11.10), you need to \"whitelist\" your application.\nThere are different ways to do this using the 'gsettings' application from the command line.\nI had to do this to get programs like Skype showing in the system tray again, not just for my own custom app... | [
6,
4,
0
] | [] | [] | [
"python",
"ubuntu",
"ubuntu_unity",
"wxpython",
"wxwidgets"
] | stackoverflow_0007144756_python_ubuntu_ubuntu_unity_wxpython_wxwidgets.txt |
Q:
Simple python communication class error?
Hi i am having some trouble passing variables/doing functions from other classes,
Right now I have something like this,
class 1(3):
def hi():
print 'class 1'
class 2(3):
def hi2():
print 'class 2'
class 3:
def hi3():
print 'class 3'
Lets ... | Simple python communication class error? | Hi i am having some trouble passing variables/doing functions from other classes,
Right now I have something like this,
class 1(3):
def hi():
print 'class 1'
class 2(3):
def hi2():
print 'class 2'
class 3:
def hi3():
print 'class 3'
Lets say, from class 1 I would like to execute a fu... | [
"1 doesn't have access to 2's methods; 2 is on a different inheritance chain.\nYou can call the raw function from the method with an instance of 1, but don't do that. Fix your inheritance chain instead.\n",
"if class 3 needs functions from both class 1 and class 2 you could do a double inheritance:\nclass one:\n ... | [
2,
2
] | [
"Class 3 is the base class and Class 2 is the child class. You are trying to call a child class function from a base class. This doesn't seem right. This is not trivially possible.\nWhy are you trying to do this?\n"
] | [
-1
] | [
"inheritance",
"python"
] | stackoverflow_0008072963_inheritance_python.txt |
Q:
Passing a Fabric env.host string as a variable
I want to be able to programmatically create a new cloud server, and then pass the new root@1.2.3.4 into additional Fabric commands to run other setup scripts.
I am able to create the server, grab the relevant variables, and initiate a local('ssh root@1.2.3.4') comman... | Passing a Fabric env.host string as a variable | I want to be able to programmatically create a new cloud server, and then pass the new root@1.2.3.4 into additional Fabric commands to run other setup scripts.
I am able to create the server, grab the relevant variables, and initiate a local('ssh root@1.2.3.4') command to add the new IP to my known hosts file. However... | [
"The \"No hosts found\" error is a bit deceptive. It throws if what you've put in env.hosts isn't well formed. env.hosts should look something like one of these:\nenv.hosts = ['1.2.3.4']\nenv.hosts = ['1.2.3.4', 'hostname', '4.5.6.7']\n\nIt should not include the user (root@1.2.3.4) that gets passed to env.user\nTr... | [
0
] | [] | [] | [
"cloud_hosting",
"fabric",
"python"
] | stackoverflow_0007758379_cloud_hosting_fabric_python.txt |
Q:
How to check if a folder exists by its complete path in Plone?
I use xmlrpclib, wsapi4plone to connect to plone:
client = xmlrpclib.ServerProxy('http://user:password@blah.com/plone')
is there a method to check if a folder on plone exists by its url? something like: client.exists('/sites/ng/path/to/folder')
What I... | How to check if a folder exists by its complete path in Plone? | I use xmlrpclib, wsapi4plone to connect to plone:
client = xmlrpclib.ServerProxy('http://user:password@blah.com/plone')
is there a method to check if a folder on plone exists by its url? something like: client.exists('/sites/ng/path/to/folder')
What I did is a bit of cheating:
try:
client.get_types('/sites/n... | [
"A fast solution is to query the catalog, like this:\nclient = xmlrpclib.ServerProxy('http://user:password@blah.com/plone')\ncompletePath = '/'.join(client.getPhysicalPath()) + '/sites/ng/path/to/folder'\nif len(client.portal_catalog.searchResults(path=completePath)):\n return True\n\nAnother solution could be t... | [
2
] | [] | [] | [
"plone",
"python",
"xmlrpclib"
] | stackoverflow_0008070981_plone_python_xmlrpclib.txt |
Q:
Python raw http request retrieval issues via urllib2
I am using Python 2.6.5 and I am trying to capture the raw http request sent via HTTP, this works fine except when I add a proxy handler into the mix so the situation is as follows:
HTTP and HTTPS requests work fine without the proxy handler: raw HTTP request c... | Python raw http request retrieval issues via urllib2 | I am using Python 2.6.5 and I am trying to capture the raw http request sent via HTTP, this works fine except when I add a proxy handler into the mix so the situation is as follows:
HTTP and HTTPS requests work fine without the proxy handler: raw HTTP request captured
HTTP requests work fine with proxy handler: proxy ... | [
"Answering my own question: It seems a bug in the underlying libraries, making RawRequest a list solves the problem: The HTTP Raw request is the first item. The custom HTTPS class is called several times, the last of which is blank. The fact that the custom HTTP class is only called once suggests this is a bug in p... | [
1
] | [] | [] | [
"http",
"python",
"request"
] | stackoverflow_0008062337_http_python_request.txt |
Q:
How to keep submodule names out of the name space of a Python package?
I want the interface of some module to contain a certain number of functions and classes (and nothing else). I could implement all of those in a single file, and would easily get the interface I want. But since there is a lot of code, I'd pre... | How to keep submodule names out of the name space of a Python package? | I want the interface of some module to contain a certain number of functions and classes (and nothing else). I could implement all of those in a single file, and would easily get the interface I want. But since there is a lot of code, I'd prefer to split the whole thing up into several files, say
mypackage/
__ini... | [
"If some of the files in a package are indeed implementation details, go ahead and stick an underscore in front of them -- that's what we use them for.\nFor example, if you look in ctypes you'll see\n__init__.py\n==================================================\n\"\"\"create and manipulate C data types in Python\... | [
12,
6,
0,
0
] | [] | [] | [
"module",
"package",
"python"
] | stackoverflow_0005265497_module_package_python.txt |
Q:
How to make an executable to use in a shell - Python
I have a Python script and I was wondering how I can make it executable; in other words how can I run it by using a shell like bash.
I know the first thing is to stick on the first line #! /usr/bin/env python but then do I need for example the functions to be in... | How to make an executable to use in a shell - Python | I have a Python script and I was wondering how I can make it executable; in other words how can I run it by using a shell like bash.
I know the first thing is to stick on the first line #! /usr/bin/env python but then do I need for example the functions to be in a specific order (i.e., the main one at the top or the bo... | [
"This is how I make an executable script. It doesn't take eggs or anything like that into account. It's just a simple script that I want to be able to execute. I'm assuming you are using linux.\n#! /usr/bin/env python\nimport sys\n\n\ndef main():\n #\n # Do something ... Whatever processing you need to do,... | [
4,
1,
0,
0,
0,
0,
0
] | [] | [] | [
"executable",
"python",
"shell"
] | stackoverflow_0008073561_executable_python_shell.txt |
Q:
Python webdriver: driver.get(URL) does not open in unittest - works through console
Just as the title says I have a copy of Selenium
- installed from svn repo
When I import and run things through the console everything works
when I try to run a unittest even one exported directly from Selenium IDE
it will open th... | Python webdriver: driver.get(URL) does not open in unittest - works through console | Just as the title says I have a copy of Selenium
- installed from svn repo
When I import and run things through the console everything works
when I try to run a unittest even one exported directly from Selenium IDE
it will open the browser and hang without trying to open a URL
Additional Details
OS: Ubuntu 11.04
Pyth... | [
"Found my solution by chatting with AutomatedTester in IRC\ncurrently the python webdriver implementation ignores the self.base_url value\nso when you .get() a URL you need to use the full URL\na bug report has been filed and will likely be updated in the near future\nWebdriver version 2.11.1\n"
] | [
2
] | [] | [] | [
"python",
"selenium",
"webdriver"
] | stackoverflow_0008044728_python_selenium_webdriver.txt |
Q:
Is there a way to not return a response from a Django view?
Say I want to do a ajax get request that goes to a Django view. Instead of returning a response to the client, could I store the request in a dictionary or list and forget about it for a while leaving the ajax/client waiting for a response? Then say aft... | Is there a way to not return a response from a Django view? | Say I want to do a ajax get request that goes to a Django view. Instead of returning a response to the client, could I store the request in a dictionary or list and forget about it for a while leaving the ajax/client waiting for a response? Then say after something happens on the server I use another view or function... | [
"Django uses WSGI which is designed for synchronous processing, so doing what you want is not easy. That said there is one guy who seems to have done implementation for asynchronous responses. That's probably not the most efficient or reliable, but at least it's possible.\n"
] | [
2
] | [] | [] | [
"ajax",
"django",
"python"
] | stackoverflow_0008073672_ajax_django_python.txt |
Q:
GAE/Python request forwarding?
I was wondering if there's a pythonic equivalent of the RequestDispatcher.forward(request, response) that I'm used to from Java servlet programming? It's a common enough technique in Java, and enables you to do, say, a little preprocessing of a particular type of request, and then ha... | GAE/Python request forwarding? | I was wondering if there's a pythonic equivalent of the RequestDispatcher.forward(request, response) that I'm used to from Java servlet programming? It's a common enough technique in Java, and enables you to do, say, a little preprocessing of a particular type of request, and then hand over to another url handler. This... | [
"I don't know about GAE, but in django you can do something like this:\ndef view2(request):\n do_some_stuff()\n\ndef view1(request):\n do_some_stuff()\n view2(request) # <-- note this line\n\nIn GAE maybe you can do this:\nreturn View.action.__func__(self, ...)\n\n(though this, depending on the function, mi... | [
0,
0
] | [] | [] | [
"forwarding",
"google_app_engine",
"python",
"request"
] | stackoverflow_0008059858_forwarding_google_app_engine_python_request.txt |
Q:
Python: Inheritance and default values in __init__
I am trying to make a class with generic __init__ values, but have defaults for its subclasses, as so:
class Enemy:
def __init__(self, difficulty, power, MaxHP, magic, MaxMP, speed, name):
self.power = power + 2*difficulty
self.HP = self.MaxHP = MaxHP + ... | Python: Inheritance and default values in __init__ | I am trying to make a class with generic __init__ values, but have defaults for its subclasses, as so:
class Enemy:
def __init__(self, difficulty, power, MaxHP, magic, MaxMP, speed, name):
self.power = power + 2*difficulty
self.HP = self.MaxHP = MaxHP + 5*difficulty
self.magic = magic + 2* difficulty
... | [
"Because you called super(Goblin, self).__init__(self, power, MaxHP, magic, MaxMP, speed, name) without difficulty. You probably also want to inherit like class Enemy(object) to make sure Enemy is a new-style class if you're on 2.x (which I guess you must be, considering the old way that you've used super).\nHere'... | [
5,
1
] | [] | [] | [
"default",
"inheritance",
"init",
"python"
] | stackoverflow_0008073726_default_inheritance_init_python.txt |
Q:
sending an email using python SMTP library credentials security
When I send credentials using the login method of the python SMTP library, do they go off the wire encrypted or as plaintext?
A:
They will only be encrypted if you use SMTP with TLS or SSL.
| sending an email using python SMTP library credentials security | When I send credentials using the login method of the python SMTP library, do they go off the wire encrypted or as plaintext?
| [
"They will only be encrypted if you use SMTP with TLS or SSL.\n"
] | [
3
] | [] | [] | [
"credentials",
"python",
"security",
"smtp"
] | stackoverflow_0008074227_credentials_python_security_smtp.txt |
Q:
Longest common prefix using buffer?
If I have an input string and an array:
s = "to_be_or_not_to_be"
pos = [15, 2, 8]
I am trying to find the longest common prefix between the consecutive elements of the array pos referencing the original s. I am trying to get the following output:
longest = [3,1]
The way I obt... | Longest common prefix using buffer? | If I have an input string and an array:
s = "to_be_or_not_to_be"
pos = [15, 2, 8]
I am trying to find the longest common prefix between the consecutive elements of the array pos referencing the original s. I am trying to get the following output:
longest = [3,1]
The way I obtained this is by computing the longest co... | [
">>> import os\n>>> os.path.commonprefix([s[i:] for i in pos])\n'_'\n\nLet Python to manage memory for you. Don't optimize prematurely.\nTo get the exact output you could do (as @agf suggested):\nprint [len(commonprefix([buffer(s, i) for i in adj_indexes]))\n for adj_indexes in zip(pos, pos[1:])]\n# -> [3, 1]... | [
2,
2,
1,
0
] | [] | [] | [
"buffer",
"python",
"string",
"text"
] | stackoverflow_0008073808_buffer_python_string_text.txt |
Q:
print arbitrary amount of digits of float
How can I print more than about 10 digits of a float in python? Right now, when do
print sqr_newton(10, 3, 0.001) (where sqr_newton is newton's algorithm for square roots; returns a float)
it only gives so many digits after the decimal place... how can I get more?
A:
Tha... | print arbitrary amount of digits of float | How can I print more than about 10 digits of a float in python? Right now, when do
print sqr_newton(10, 3, 0.001) (where sqr_newton is newton's algorithm for square roots; returns a float)
it only gives so many digits after the decimal place... how can I get more?
| [
"That is the standard precision for floats in python.\nFor arbitrary precision, you can use the bigfloat package.\n",
"I'm not sure what operating system you are using but bigfloat requires that the MPFR and GMP libraries already exist on your computer. It may not be easy to use on Windows.\nThere are two other m... | [
5,
3
] | [] | [] | [
"algorithm",
"floating_point",
"newtons_method",
"python",
"square_root"
] | stackoverflow_0008074067_algorithm_floating_point_newtons_method_python_square_root.txt |
Q:
Python zeromq "Hello World" blocks on recv()
I've been trying to get zeromq working with Python on Fedora 11. As it needed Python 2.7, I installed ActivePython. I installed pyzmq using easy_install and it installed fine. When I run the hello world example from here:
http://zguide.zeromq.org/py:hwclient
It blocks o... | Python zeromq "Hello World" blocks on recv() | I've been trying to get zeromq working with Python on Fedora 11. As it needed Python 2.7, I installed ActivePython. I installed pyzmq using easy_install and it installed fine. When I run the hello world example from here:
http://zguide.zeromq.org/py:hwclient
It blocks on:
socket.recv()
I have read that there are issue... | [
"To be honest, I skipped over the hello-world bit and went straight to the Lazy Pirate pattern client-server. That one did have some bugs in the Python version in the client retry loops, but at least it did something. I added a few print statements and got a proper client-server communication going.\nAfter that I w... | [
2
] | [] | [] | [
"python",
"zeromq"
] | stackoverflow_0008074112_python_zeromq.txt |
Q:
Do AWS Canonical UserIDs exist for AWS Federated Users (temporary security credentials)?
Does a canonical user id exist for a federated user created using STS? When using boto I need a canonical user id to grant permissions to a bucket.
Here's a quick tour through my code:
I've successfully created temporary c... | Do AWS Canonical UserIDs exist for AWS Federated Users (temporary security credentials)? | Does a canonical user id exist for a federated user created using STS? When using boto I need a canonical user id to grant permissions to a bucket.
Here's a quick tour through my code:
I've successfully created temporary credentials using boto's STS module (using a "master" account), and this gives me back:
federa... | [
"Contacted the author of boto and learned of:\nget_canonical_user_id() for the S3Connection class.\nThis will give you the canonical user ID for the credentials associated with the connection. The connection will have to have been used for some operation (e.g.: listing buckets).\nVery awkward, but possible.\n"
] | [
1
] | [] | [] | [
"amazon_iam",
"amazon_s3",
"amazon_web_services",
"boto",
"python"
] | stackoverflow_0008032576_amazon_iam_amazon_s3_amazon_web_services_boto_python.txt |
Q:
on Windows, virtualenv is not being used with i run a python program
I have virtualenv installed on windows.
In cmd, i run python and look at sys.path and see the virtualenv path included.
but when i run manage.py (for django), I don't see the virtualenv path,
so virtualenv is not working with django server.
Why?... | on Windows, virtualenv is not being used with i run a python program | I have virtualenv installed on windows.
In cmd, i run python and look at sys.path and see the virtualenv path included.
but when i run manage.py (for django), I don't see the virtualenv path,
so virtualenv is not working with django server.
Why?
| [
"the solution is to explicitly invoke python by using: python file.py\nas described in http://www.velocityreviews.com/forums/t727997-problems-running-virtualenv-under-windows.html\nfor some reason, the python registered with .py in windows does not invoke virtualenv.\n",
"Virtualenv modifies the PATH to include a... | [
3,
1,
0
] | [] | [] | [
"django",
"python",
"virtualenv",
"windows"
] | stackoverflow_0008069029_django_python_virtualenv_windows.txt |
Q:
Pythonic/djangonic way to handle user timeouts on the scale of seconds (or minutes if need be)
The closest example to my case is a Django ajax chat application. The rooms need to keep a list of active users. Aside from displaying that list of users within the chat, a given room might have a maximum number of activ... | Pythonic/djangonic way to handle user timeouts on the scale of seconds (or minutes if need be) | The closest example to my case is a Django ajax chat application. The rooms need to keep a list of active users. Aside from displaying that list of users within the chat, a given room might have a maximum number of active users; new users need to be blocked from entering if there's no room.
Currently I have the chat cl... | [
"I'd use sessions and store last ping datetime as a session parameter. Don't worry about database hits, if at the certain point you would feel that you're getting too many of them, just switch your session storage to cache. \nMake your application robust to cache-flushing.\nOne of my friends used to host a relativ... | [
3
] | [] | [] | [
"ajax",
"django",
"django_middleware",
"python",
"session"
] | stackoverflow_0008074588_ajax_django_django_middleware_python_session.txt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.