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:
Which is the most useful Mercurial hook for programming in a loosely connected team?
I recently discovered the notify extension in Mercurial which allows me quickly send out emails whenever I push changes, but I'm pretty sure I'm still missing out on a lot of functionality which could make my life a lot easier.
... | Which is the most useful Mercurial hook for programming in a loosely connected team? | I recently discovered the notify extension in Mercurial which allows me quickly send out emails whenever I push changes, but I'm pretty sure I'm still missing out on a lot of functionality which could make my life a lot easier.
notify-extension: https://www.mercurial-scm.org/wiki/NotifyExtension
Which Mercurial hook... | [
"I really enjoy what I did with my custom hook. I have it post a message to my campfire account (campfire is a group based app). It worked out really well. Because I had my clients in there and it could show him my progress.\n",
"Take a look at the hgweb stuff. You can set up RSS feeds and see all the revisions... | [
2,
1,
1
] | [] | [] | [
"hook",
"mercurial",
"python"
] | stackoverflow_0000063488_hook_mercurial_python.txt |
Q:
jython date conversion
Given a string as below, I need to convert:
1 Dec 2008 06:43:00 +0100
to
MM/DD/YYYY HH:MM:SSAM
using jython what is the best way to do this?
A:
I don't have jython handy, but I'd expect something like this to work:
import java
sdf = java.text.SimpleDateFormat
fmt_in = sdf('d MMM yyyy HH:m... | jython date conversion | Given a string as below, I need to convert:
1 Dec 2008 06:43:00 +0100
to
MM/DD/YYYY HH:MM:SSAM
using jython what is the best way to do this?
| [
"I don't have jython handy, but I'd expect something like this to work:\nimport java\nsdf = java.text.SimpleDateFormat\n\nfmt_in = sdf('d MMM yyyy HH:mm:ss Z')\nfmt_out = sdf('MM/dd/yyyy HH:mm:ssaa')\n\nfmt_out.format(fmt_in.parse(time_str))\n\n",
"Jython 2.5b0 (beta) has an implementation of the time module that... | [
2,
1
] | [] | [] | [
"date_conversion",
"jython",
"python"
] | stackoverflow_0000330383_date_conversion_jython_python.txt |
Q:
CherryPy for a webhosting control panel application
For quite a long time I've wanted to start a pet project that will aim in
time to become a web hosting control panel, but mainly focused on Python hosting --
meaning I would like to make a way for users to generate/start Django/
other frameworks projects right fr... | CherryPy for a webhosting control panel application | For quite a long time I've wanted to start a pet project that will aim in
time to become a web hosting control panel, but mainly focused on Python hosting --
meaning I would like to make a way for users to generate/start Django/
other frameworks projects right from the panel. I seemed to have
found the perfect tool to ... | [
"\"Threaded\" and \"Fork based\" servers are equivalent. A \"threaded\" server has multiple threads of execution, and if one blocks then the others will continue. A \"Fork based\" server has multiple processes executing, and if one blocks then the others will continue. The only difference is that threaded server... | [
1
] | [] | [] | [
"cherrypy",
"fork",
"multithreading",
"python"
] | stackoverflow_0000330573_cherrypy_fork_multithreading_python.txt |
Q:
Pure Python rational numbers module for 2.5
Has anybody seen such a thing? Small self-sufficient modules are preferred.
A:
The fractions module from 2.6 can be ripped out if necessary. Grab fractions.py, numbers.py, and abc.py; all pure python modules.
You can get the single files from here (2.6 branch, 2.7 d... | Pure Python rational numbers module for 2.5 | Has anybody seen such a thing? Small self-sufficient modules are preferred.
| [
"The fractions module from 2.6 can be ripped out if necessary. Grab fractions.py, numbers.py, and abc.py; all pure python modules. \nYou can get the single files from here (2.6 branch, 2.7 does not work): \nhttp://hg.python.org/cpython/branches\n",
"SymPy is a symbolic maths library written entirely in Python a... | [
10,
9,
3
] | [] | [] | [
"python",
"rational_numbers"
] | stackoverflow_0000329333_python_rational_numbers.txt |
Q:
How to quickly parse a list of strings
If I want to split a list of words separated by a delimiter character, I can use
>>> 'abc,foo,bar'.split(',')
['abc', 'foo', 'bar']
But how to easily and quickly do the same thing if I also want to handle quoted-strings which can contain the delimiter character ?
In: 'abc,"a... | How to quickly parse a list of strings | If I want to split a list of words separated by a delimiter character, I can use
>>> 'abc,foo,bar'.split(',')
['abc', 'foo', 'bar']
But how to easily and quickly do the same thing if I also want to handle quoted-strings which can contain the delimiter character ?
In: 'abc,"a string, with a comma","another, one"'
Out: ... | [
"import csv\n\ninput = ['abc,\"a string, with a comma\",\"another, one\"']\nparser = csv.reader(input)\n\nfor fields in parser:\n for i,f in enumerate(fields):\n print i,f # in Python 3 and up, print is a function; use: print(i,f)\n\nResult:\n\n0 abc\n1 a string, with a comma\n2 another, one\n\n",
"The CSV... | [
42,
8
] | [] | [] | [
"python"
] | stackoverflow_0000330900_python.txt |
Q:
Parsing a string for nested patterns
What would be the best way to do this.
The input string is
<133_3><135_3><116_2>The other system worked for about 1 month</116_2> got some good images <137_3>on it then it started doing the same thing as the first one</137_3> so then I quit using either camera now they are jus... | Parsing a string for nested patterns | What would be the best way to do this.
The input string is
<133_3><135_3><116_2>The other system worked for about 1 month</116_2> got some good images <137_3>on it then it started doing the same thing as the first one</137_3> so then I quit using either camera now they are just sitting and collecting dust.</135_3></13... | [
"Take an XML parser, make it generate a DOM (Document Object Model) and then build a recursive algorithm that traverses all the nodes, calls \"text()\" in each node (that should give you the text in the current node and all children) and puts that as a key in the dictionary.\n",
"Use expat or another XML parser; ... | [
4,
4,
2,
1,
1,
0
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0000330334_python_regex.txt |
Q:
Memory Efficient Alternatives to Python Dictionaries
In one of my current side projects, I am scanning through some text looking at the frequency of word triplets. In my first go at it, I used the default dictionary three levels deep. In other words, topDict[word1][word2][word3] returns the number of times these... | Memory Efficient Alternatives to Python Dictionaries | In one of my current side projects, I am scanning through some text looking at the frequency of word triplets. In my first go at it, I used the default dictionary three levels deep. In other words, topDict[word1][word2][word3] returns the number of times these words appear in the text, topDict[word1][word2] returns a... | [
"Some measurements. I took 10MB of free e-book text and computed trigram frequencies, producing a 24MB file. Storing it in different simple Python data structures took this much space in kB, measured as RSS from running ps, where d is a dict, keys and freqs are lists, and a,b,c,freq are the fields of a trigram reco... | [
33,
9,
4,
3,
2,
1,
1,
1,
0,
0,
0
] | [
"You could put all words in a dictionary.\nkey would be word, and value is number (index).\nThen you use it like this:\nWord1=indexDict[word1]\nWord2=indexDict[word2]\nWord3=indexDict[word3]\n\ntopDictionary[Word1][Word2][Word3]\n\nInsert in indexDict with:\nif word not in indexDict:\n indexDict[word]=len(indexD... | [
-1
] | [
"data_structures",
"memory",
"python"
] | stackoverflow_0000327223_data_structures_memory_python.txt |
Q:
Python UPnP/IGD Client Implementation?
I am searching for an open-source implementation of an UPnP client in Python, and more specifically of its Internet Gateway Device (IGD) part.
For now, I have only been able to find UPnP Media Server implementations, in projects such as PyMediaServer, PyMedS, BRisa or Coheren... | Python UPnP/IGD Client Implementation? | I am searching for an open-source implementation of an UPnP client in Python, and more specifically of its Internet Gateway Device (IGD) part.
For now, I have only been able to find UPnP Media Server implementations, in projects such as PyMediaServer, PyMedS, BRisa or Coherence.
I am sure I could use those code bases a... | [
"MiniUPnP source code contains a Python sample code using the C library as an extension module (see testupnpigd.py), which I consider as a proper solution to my problem.\nRationale: this is not the pure Python solution I was looking for, but:\n\nsignificant effort has already been invested in this library,\nit is l... | [
7,
2
] | [] | [] | [
"nat",
"networking",
"python",
"upnp"
] | stackoverflow_0000294504_nat_networking_python_upnp.txt |
Q:
How to pack python libs I'm using so I can distribute them with my app and have as few dependencies as possible
How to pack python libs I'm using so I can distribute them with my app and have as few dependencies as possible and also not to conflict with different lib/version that is already on my system.
L.E.: Sor... | How to pack python libs I'm using so I can distribute them with my app and have as few dependencies as possible | How to pack python libs I'm using so I can distribute them with my app and have as few dependencies as possible and also not to conflict with different lib/version that is already on my system.
L.E.: Sorry i forgot to specify. I will be doing this on linux. And I'm not referring in making my app a installable file like... | [
"You could try freeze.py, see http://wiki.python.org/moin/Freeze for more details.\n",
"Try py2exe.\n",
"But if you make a deb with the correct dependencies listed the installer will download them for the user. That's the best way, as it's non redundant. \nMaybe you could make a tar or zip with your deb and all... | [
4,
3,
2,
2
] | [] | [] | [
"deployment",
"linux",
"python"
] | stackoverflow_0000331377_deployment_linux_python.txt |
Q:
How to determine if a page is being redirected
I need to check whether a page is being redirected or not without actually downloading the content. I just need the final URL. What's the best way of doing this is Python?
Thanks!
A:
If you specifically want to avoid downloading the content, you'll need to use the H... | How to determine if a page is being redirected | I need to check whether a page is being redirected or not without actually downloading the content. I just need the final URL. What's the best way of doing this is Python?
Thanks!
| [
"If you specifically want to avoid downloading the content, you'll need to use the HEAD request method. I believe the urllib and urllib2 libraries do not support HEAD requests, so you'll have to use the lower-level httplib library:\nimport httplib\n\nh = httplib.HTTPConnection('www.example.com')\nh.request('HEAD',... | [
9,
1
] | [] | [] | [
"http",
"http_headers",
"python"
] | stackoverflow_0000331855_http_http_headers_python.txt |
Q:
What is a good Python format style
I've created a small python script to toggle between two files I'm using for testing.
My question is, what is a good Python format style for the following code:
import filecmp
import shutil
local = "local.txt"
remote = "remote.txt"
config_file = "C:\some\path\file.txt"
shutil.c... | What is a good Python format style | I've created a small python script to toggle between two files I'm using for testing.
My question is, what is a good Python format style for the following code:
import filecmp
import shutil
local = "local.txt"
remote = "remote.txt"
config_file = "C:\some\path\file.txt"
shutil.copyfile( remote if( filecmp.cmp(local, c... | [
"For the conditional statement, I would probably go with:\nif filecmp.cmp(local, config_file):\n shutil.copyfile(remote, config_file)\nelse:\n shutil.copyfile(local, config_file)\n\nThere's little need to use the inline y if x else z in this case, since the surrounding code is simple enough.\n",
"The most c... | [
16,
5,
5,
5,
0
] | [] | [] | [
"coding_style",
"python"
] | stackoverflow_0000331767_coding_style_python.txt |
Q:
Storing and updating lists in Python dictionaries: why does this happen?
I have a list of data that looks like the following:
// timestep,x_position,y_position
0,4,7
0,2,7
0,9,5
0,6,7
1,2,5
1,4,7
1,9,0
1,6,8
... and I want to make this look like:
0, (4,7), (2,7), (9,5), (6,7)
1, (2,5), (4,7), (9,0), (6.8)
My pla... | Storing and updating lists in Python dictionaries: why does this happen? | I have a list of data that looks like the following:
// timestep,x_position,y_position
0,4,7
0,2,7
0,9,5
0,6,7
1,2,5
1,4,7
1,9,0
1,6,8
... and I want to make this look like:
0, (4,7), (2,7), (9,5), (6,7)
1, (2,5), (4,7), (9,0), (6.8)
My plan was to use a dictionary, where the value of t is the key for the dictionary,... | [
"Let's look at\nd[t].append(c)\n\nWhat is the value of d[t]? Try it.\nd = {}\nt = 0\nd[t]\n\nWhat do you get? Oh. There's nothing in d that has a key of t.\nNow try this.\nd[t] = []\nd[t]\n\nAhh. Now there's something in d with a key of t.\nThere are several things you can do. \n\nUse example 2.\nUse setdefaul... | [
73,
12,
1,
1
] | [] | [] | [
"dictionary",
"list",
"python"
] | stackoverflow_0000327534_dictionary_list_python.txt |
Q:
Integer (representing a sequence of bits) reinterpretation as Character Array in Python
I've written some C code that I would like to port to python, as I feel python is a better 'concept' language.
In my C code, I use memory reinterpretation to achieve my goals, for example:
sizeof(int) is 4 byte
sizeof(char) is... | Integer (representing a sequence of bits) reinterpretation as Character Array in Python | I've written some C code that I would like to port to python, as I feel python is a better 'concept' language.
In my C code, I use memory reinterpretation to achieve my goals, for example:
sizeof(int) is 4 byte
sizeof(char) is 1 byte
char c[4]={0x01,0x30,0x00,0x80};
int* i=(int*)c;
*i has the value 0x80003001
simil... | [
"You can use the struct module:\nimport struct\n\n# Pack a Python long as if it was a C unsigned integer, little endian\nbytes = struct.pack(\"<I\", 0x78FF00AA)\nprint [hex(ord(byte)) for byte in bytes]\n\n['0xaa', '0x0', '0xff', '0x78']\n\nRead the documentation page to find about datatypes, and pay attention to e... | [
9
] | [] | [] | [
"python"
] | stackoverflow_0000333097_python.txt |
Q:
Deploying a python application with shared package
I'm thinking how to arrange a deployed python application which will have a
Executable script located in /usr/bin/ which will provide a CLI to functionality implemented in
A library installed to wherever the current site-packages directory is.
Now, currently, I... | Deploying a python application with shared package | I'm thinking how to arrange a deployed python application which will have a
Executable script located in /usr/bin/ which will provide a CLI to functionality implemented in
A library installed to wherever the current site-packages directory is.
Now, currently, I have the following directory structure in my sources:
f... | [
"This article is pretty good, and shows you a good way to do it. The second item from the Do list answers your question.\nshameless copy paste:\n\nFilesystem structure of a Python project\nby Jp Calderone\nDo:\n\nname the directory something related to your project. For example, if your\n project is named \"Twiste... | [
5,
2,
0,
0
] | [] | [] | [
"conventions",
"deploying",
"naming",
"package",
"python"
] | stackoverflow_0000328568_conventions_deploying_naming_package_python.txt |
Q:
string.split(text) or text.split() : what's the difference?
There is one thing that I do not understand...
Imagine you have a text = "hello world" and you want to split it.
In some places I see people that want to split the text doing:
string.split(text)
In other places I see people just doing:
text.split()
Wh... | string.split(text) or text.split() : what's the difference? | There is one thing that I do not understand...
Imagine you have a text = "hello world" and you want to split it.
In some places I see people that want to split the text doing:
string.split(text)
In other places I see people just doing:
text.split()
What’s the difference? Why you do in one way or in the other way? C... | [
"Interestingly, the docstrings for the two are not completely the same in Python 2.5.1:\n>>> import string\n>>> help(string.split)\nHelp on function split in module string:\n\nsplit(s, sep=None, maxsplit=-1)\n split(s [,sep [,maxsplit]]) -> list of strings\n\n Return a list of the words in the string s, using... | [
21,
13,
5,
5,
1
] | [] | [] | [
"python",
"split",
"string"
] | stackoverflow_0000333706_python_split_string.txt |
Q:
getting redirect loop for admin_only decorator
I've made this decorator, which results in an infinite redirect loop.
The problem is this:
args[0].redirect(users.create_login_url(args[0].request.path))
It appears to be a perfectly valid URL. So why wouldn't it properly redirect?
def admin_only(handler, *args):
... | getting redirect loop for admin_only decorator | I've made this decorator, which results in an infinite redirect loop.
The problem is this:
args[0].redirect(users.create_login_url(args[0].request.path))
It appears to be a perfectly valid URL. So why wouldn't it properly redirect?
def admin_only(handler, *args):
def redirect_to_login(*args, **kwargs):
r... | [
"It seems that you aren't defining your decorator properly.\nA decorator is called only once every time you wrap a function with it; from then on the function that the decorator returned will be called. It seems that you (mistakenly) believe that the decorator function itself will be called every time.\nTry somethi... | [
2,
0,
0,
0
] | [] | [] | [
"decorator",
"google_app_engine",
"python",
"redirect"
] | stackoverflow_0000333487_decorator_google_app_engine_python_redirect.txt |
Q:
Now that Python 2.6 is out, what modules currently in the language should every programmer know about?
A lot of useful features in Python are somewhat "hidden" inside modules. Named tuples (new in Python 2.6), for instance, are found in the collections module.
The Library Documentation page will give you all the ... | Now that Python 2.6 is out, what modules currently in the language should every programmer know about? | A lot of useful features in Python are somewhat "hidden" inside modules. Named tuples (new in Python 2.6), for instance, are found in the collections module.
The Library Documentation page will give you all the modules in the language, but newcomers to Python are likely to find themselves saying "Oh, I didn't know I c... | [
"The most impressive new module is probably the multiprocessing module. First because it lets you execute functions in new processes just as easily and with roughly the same API as you would with the threading module. But more importantly because it introduces a lot of great classes for communicating between proc... | [
12,
6,
5,
3
] | [] | [] | [
"language_features",
"module",
"python"
] | stackoverflow_0000168727_language_features_module_python.txt |
Q:
How do I create trivial customized field types in Django models?
I'm trying to make some types in Django that map to standard Django types. The custom model field documentation goes into complicated cases; I just want to store a basic Django type from a class with a bunch of handy methods.
For example, if I were ... | How do I create trivial customized field types in Django models? | I'm trying to make some types in Django that map to standard Django types. The custom model field documentation goes into complicated cases; I just want to store a basic Django type from a class with a bunch of handy methods.
For example, if I were storing playing cards, I want something like:
class Card(object):
... | [
"I'd do this with a subclass of Django's PositiveIntegerField:\nfrom django.db import models\n\nclass Card(object):\n \"\"\"The ``Card`` class you described.\"\"\"\n ...\n\nclass CardField(models.PositiveIntegerField):\n __metaclass__ = models.SubfieldBase\n\n def get_db_prep_value(self, value):\n ... | [
4,
1,
0
] | [] | [] | [
"django",
"django_models",
"python"
] | stackoverflow_0000334992_django_django_models_python.txt |
Q:
How to generate a filmstrip image in python from a folder of images?
I would like to do the equivalent off this (ruby code) in python for a Django project I am working on. I want to make a filmstrip image of X number of images in a folder.
A:
Do you mnean something like this? Use PIL to make a "contact sheet" ... | How to generate a filmstrip image in python from a folder of images? | I would like to do the equivalent off this (ruby code) in python for a Django project I am working on. I want to make a filmstrip image of X number of images in a folder.
| [
"Do you mnean something like this? Use PIL to make a \"contact sheet\" of images?\nPerhaps there are others here that are closer to what you want: http://code.activestate.com/recipes/tags/graphics/\n",
"Here is a function that wraps the contact sheet function S.Lott mentioned.\n#!/usr/bin/env python\n\nimport os... | [
4,
1
] | [] | [] | [
"django",
"image",
"python",
"python_imaging_library"
] | stackoverflow_0000334827_django_image_python_python_imaging_library.txt |
Q:
How to complete this python function to save in the same folder?
I am trying to write my first real python function that does something real. What i want to accomplish is searching a given folder, and then open all images and merging them together so they make a filmstrip image. Imagine 5 images stacked on top of ... | How to complete this python function to save in the same folder? | I am trying to write my first real python function that does something real. What i want to accomplish is searching a given folder, and then open all images and merging them together so they make a filmstrip image. Imagine 5 images stacked on top of eachother in one image.
I have this code now, which should be pretty m... | [
"It is not an answer to your question, but It might be helpful:\n#!/usr/bin/env python\nfrom PIL import Image\n\ndef makefilmstrip(images, mode='RGB', color='white'):\n \"\"\"Return a combined (filmstripped, each on top of the other) image of the images.\n\n \"\"\"\n width = max(img.size[0] for img in ima... | [
2,
1,
1,
1
] | [] | [] | [
"image_processing",
"python",
"python_imaging_library"
] | stackoverflow_0000335896_image_processing_python_python_imaging_library.txt |
Q:
Shell Script doesn't run automatically though it is registered in Mac OS X Login Items
I have the following shell script registered in my "Login Items" preferences but it does not seem to have any effect. It is meant to launch the moinmoin wiki but only works when it is run by hand from a terminal window, after wh... | Shell Script doesn't run automatically though it is registered in Mac OS X Login Items | I have the following shell script registered in my "Login Items" preferences but it does not seem to have any effect. It is meant to launch the moinmoin wiki but only works when it is run by hand from a terminal window, after which it runs until the machine is next shut down.
#!/bin/bash
cd /Users/stuartcw/Documents/Wi... | [
"Try using launchd. More info at http://www.macgeekery.com/tips/all_about_launchd_items_and_how_to_make_one_yourself\n",
"launchd is one of the best parts of MacOS X, and it causes me great pain to not be able to find it on other systems.\nEdit and place this in /Library/LaunchDaemons as com.you.wiki.plist\n<?xm... | [
4,
4,
3,
1
] | [] | [] | [
"bash",
"launchd",
"macos",
"moinmoin",
"python"
] | stackoverflow_0000335891_bash_launchd_macos_moinmoin_python.txt |
Q:
How would you design a very "Pythonic" UI framework?
I have been playing with the Ruby library "shoes". Basically you can write a GUI application in the following way:
Shoes.app do
t = para "Not clicked!"
button "The Label" do
alert "You clicked the button!" # when clicked, make an alert
t.replace "Cli... | How would you design a very "Pythonic" UI framework? | I have been playing with the Ruby library "shoes". Basically you can write a GUI application in the following way:
Shoes.app do
t = para "Not clicked!"
button "The Label" do
alert "You clicked the button!" # when clicked, make an alert
t.replace "Clicked!" # ..and replace the label's text
end
end
This ma... | [
"You could actually pull this off, but it would require using metaclasses, which are deep magic (there be dragons). If you want an intro to metaclasses, there's a series of articles from IBM which manage to introduce the ideas without melting your brain.\nThe source code from an ORM like SQLObject might help, too, ... | [
7,
4,
4,
4,
3,
3,
3,
3,
2,
2,
1,
1,
1,
1,
0
] | [] | [] | [
"frameworks",
"python",
"user_interface"
] | stackoverflow_0000058711_frameworks_python_user_interface.txt |
Q:
Python: smtpd (or alternative) for production mail receiving?
I'm looking to do various processing of email - eg. inspect the headers, and if they meet some criteria (look like spam), drop the connection, or inspect the recipient list and perform special filtering.
Looks like Python's smtpd library provides a nice... | Python: smtpd (or alternative) for production mail receiving? | I'm looking to do various processing of email - eg. inspect the headers, and if they meet some criteria (look like spam), drop the connection, or inspect the recipient list and perform special filtering.
Looks like Python's smtpd library provides a nice and simple interface for processing the received email.
To deal w... | [
"You may want to look at the twisted implementation as that will give you access to the full range of interaction with the client. I believe (though I have never used it in production) that twisted can be trusted in a production environment.\n",
"Another approach: use Postfix for receiving email and write a poli... | [
5,
1
] | [] | [] | [
"python",
"smtp",
"smtpd"
] | stackoverflow_0000335582_python_smtp_smtpd.txt |
Q:
Python: Invalid Token
Some of you may recognize this as Project Euler's problem number 11. The one with the grid.
I'm trying to replicate the grid in a large multidimensional array, But it's giving me a syntax error and i'm not sure why
grid = [
[ 08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50... | Python: Invalid Token | Some of you may recognize this as Project Euler's problem number 11. The one with the grid.
I'm trying to replicate the grid in a large multidimensional array, But it's giving me a syntax error and i'm not sure why
grid = [
[ 08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08 ],
[ 49, 49, 9... | [
"I think when you start a literal number with a 0, it interprets it as an octal number and you can't have an '8' in an octal number.\n",
"Note that the \"^\" symbol in the error points exactly to the erroneous column. Together with the line number it points exactly on the digit 8. This can help lead you to what J... | [
40,
3,
1
] | [] | [] | [
"octal",
"python"
] | stackoverflow_0000336181_octal_python.txt |
Q:
Dynamic Keyword Arguments in Python?
Does python have the ability to create dynamic keywords?
For example:
qset.filter(min_price__usd__range=(min_price, max_price))
I want to be able to change the usd part based on a selected currency.
A:
Yes, It does. Use **kwargs in a function definition.
Example:
def f(**kwa... | Dynamic Keyword Arguments in Python? | Does python have the ability to create dynamic keywords?
For example:
qset.filter(min_price__usd__range=(min_price, max_price))
I want to be able to change the usd part based on a selected currency.
| [
"Yes, It does. Use **kwargs in a function definition.\nExample:\ndef f(**kwargs):\n print kwargs.keys()\n\n\nf(a=2, b=\"b\") # -> ['a', 'b']\nf(**{'d'+'e': 1}) # -> ['de']\n\nBut why do you need that?\n",
"If I understand what you're asking correctly,\nqset.filter(**{\n 'min_price_' + selected_currency ... | [
64,
37,
14,
0
] | [] | [] | [
"python"
] | stackoverflow_0000337688_python.txt |
Q:
Django FormWizard and Admin application
I have a series of forms that I need a user to complete in sequence, which is perfect for the formwizard app. However, I've some need of the admin application also and would like to set the whole thing up to trigger several forms within the admin app.
Is it possible/easy to... | Django FormWizard and Admin application | I have a series of forms that I need a user to complete in sequence, which is perfect for the formwizard app. However, I've some need of the admin application also and would like to set the whole thing up to trigger several forms within the admin app.
Is it possible/easy to integrate a 'formwizard' into the admin appl... | [
"There's a lot that you can do, but you'd need to be more specific about what you mean by \"integrate a formwizard into the admin app\" and \"trigger several forms within the admin app.\"\nThe admin app at its core is basically just a wrapper around a bunch of stock ModelForms, so if you just build a formwizard usi... | [
1
] | [
"You do have the source, and it is Python, so... you can read the admin application source to see what options it has.\nLook at \nhttp://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates.\nIt appears that you can override templates easily. They even provide step-by-step instructions for a... | [
-3
] | [
"django",
"forms",
"python"
] | stackoverflow_0000336753_django_forms_python.txt |
Q:
Python: item for item until stopterm in item?
Disclaimer: I'm fairly new to python!
If I want all the lines of a file until (edit: and including) the line containing some string stopterm, is there a way of using the list syntax for it? I was hoping there would be something like:
usefullines = [line for line in fil... | Python: item for item until stopterm in item? | Disclaimer: I'm fairly new to python!
If I want all the lines of a file until (edit: and including) the line containing some string stopterm, is there a way of using the list syntax for it? I was hoping there would be something like:
usefullines = [line for line in file until stopterm in line]
For now, I've got
useful... | [
"from itertools import takewhile\nusefullines = takewhile(lambda x: not re.search(stopterm, x), lines)\n\nfrom itertools import takewhile\nusefullines = takewhile(lambda x: stopterm not in x, lines)\n\nHere's a way that keeps the stopterm line:\ndef useful_lines(lines, stopterm):\n for line in lines:\n if... | [
10,
5,
2,
1,
1,
0
] | [] | [] | [
"python"
] | stackoverflow_0000337223_python.txt |
Q:
Setting the width of a wxPython TextCtrl in number of characters
I have a TextCtrl in my wxPython program and I'd like to set its width to exactly 3 characters. However, the only way to set its size manually accepts only numbers of pixels. Is there any way to specify characters instead of pixels?
A:
There does... | Setting the width of a wxPython TextCtrl in number of characters | I have a TextCtrl in my wxPython program and I'd like to set its width to exactly 3 characters. However, the only way to set its size manually accepts only numbers of pixels. Is there any way to specify characters instead of pixels?
| [
"There doesn't seem to be a way. You can, however, use wxWindow::GetTextExtent. This is C++ code, but can be easily adapted to wxPython:\nint x, y;\ntextCtrl->GetTextExtent(wxT(\"T\"), &x, &y);\ntextCtrl->SetMinSize(wxSize(x * N + 10, -1));\ntextCtrl->SetMaxSize(wxSize(x * N + 10, -1));\n\n/* re-layout the children... | [
3,
2
] | [] | [] | [
"python",
"wxpython"
] | stackoverflow_0000338217_python_wxpython.txt |
Q:
How do I modify the last line of a file?
The last line of my file is:
29-dez,40,
How can I modify that line so that it reads:
29-Dez,40,90,100,50
Note: I don't want to write a new line. I want to take the same line and put new values after 29-Dez,40,
I'm new at python. I'm having a lot of trouble manipulating ... | How do I modify the last line of a file? | The last line of my file is:
29-dez,40,
How can I modify that line so that it reads:
29-Dez,40,90,100,50
Note: I don't want to write a new line. I want to take the same line and put new values after 29-Dez,40,
I'm new at python. I'm having a lot of trouble manipulating files and for me every example I look at seems... | [
"Unless the file is huge, you'll probably find it easier to read the entire file into a data structure (which might just be a list of lines), and then modify the data structure in memory, and finally write it back to the file.\nOn the other hand maybe your file is really huge - multiple GBs at least. In which case:... | [
6,
6,
0,
0
] | [] | [] | [
"file",
"python"
] | stackoverflow_0000327985_file_python.txt |
Q:
How do I strptime from a pattern like this?
I need to use a datetime.strptime on the text which looks like follows.
"Some Random text of undetermined length Jan 28, 1986"
how do i do this?
A:
You may find this question useful. I'll give the answer I gave there, which is to use the dateutil module. This accepts... | How do I strptime from a pattern like this? | I need to use a datetime.strptime on the text which looks like follows.
"Some Random text of undetermined length Jan 28, 1986"
how do i do this?
| [
"You may find this question useful. I'll give the answer I gave there, which is to use the dateutil module. This accepts a fuzzy parameter which will ignore any text that doesn't look like a date. ie:\n>>> from dateutil.parser import parse\n>>> parse(\"Some Random text of undetermined length Jan 28, 1986\", fuzzy... | [
4,
3,
2
] | [] | [] | [
"datetime",
"python",
"regex"
] | stackoverflow_0000339856_datetime_python_regex.txt |
Q:
Proxy objects in IronPython
I'm trying to make a proxy object in IronPython, which should dynamically present underlying structure. The proxy itself shouldn't have any functions and properties, I'm trying to catch all the calls in the runtime. Catching the function calls is easy, I just need to define getattr() fu... | Proxy objects in IronPython | I'm trying to make a proxy object in IronPython, which should dynamically present underlying structure. The proxy itself shouldn't have any functions and properties, I'm trying to catch all the calls in the runtime. Catching the function calls is easy, I just need to define getattr() function for my object, and check d... | [
"The usual implementation of what you want in python would be this:\nclass CallProxy(object):\n 'this class wraps a callable in an object'\n def __init__(self, fun):\n self.fun = fun\n\n def __call__(self, *args, **kwargs):\n return self.fun(*args, **kwargs)\n\nclass ObjProxy(object):\n ''... | [
2,
2
] | [] | [] | [
".net",
"ironpython",
"python"
] | stackoverflow_0000340093_.net_ironpython_python.txt |
Q:
Suppressing Output of Paramiko SSHClient Class
When I call the connect function of the Paramiko SSHClient class, it outputs some log data about establishing the connection, which I would like to suppress.
Is there a way to do this either through Paramiko itself, or Python in general?
A:
Paramiko doesn't output a... | Suppressing Output of Paramiko SSHClient Class | When I call the connect function of the Paramiko SSHClient class, it outputs some log data about establishing the connection, which I would like to suppress.
Is there a way to do this either through Paramiko itself, or Python in general?
| [
"Paramiko doesn't output anything by default. You probably have a call to the logging module, setting a loglevel that's inherited when paramiko sets up it's own logging.\nIf you want to get at the paramiko logger to override the settings:\nlogger = paramiko.util.logging.getLogger()\n\nThere's also a convenience fun... | [
7,
0
] | [] | [] | [
"paramiko",
"python"
] | stackoverflow_0000340341_paramiko_python.txt |
Q:
How can I reboot a Windows XP64 Machine in a Python Script?
How can I reboot a Windows XP64 Machine in a Python Script? This machine does not have the "shutdown" or "restart" executables available.
A:
found it
win32api.InitiateSystemShutdown("localhost", "Maintenance Reboot", 60, 1, 1)
A:
You can use win32ap... | How can I reboot a Windows XP64 Machine in a Python Script? | How can I reboot a Windows XP64 Machine in a Python Script? This machine does not have the "shutdown" or "restart" executables available.
| [
"found it \nwin32api.InitiateSystemShutdown(\"localhost\", \"Maintenance Reboot\", 60, 1, 1)\n",
"You can use win32api module and call WinApi functions.\nRecipe at code.activestate.com\n"
] | [
4,
2
] | [] | [] | [
"python",
"windows"
] | stackoverflow_0000341138_python_windows.txt |
Q:
Decorators run before function it is decorating is called?
As an example:
def get_booking(f=None):
print "Calling get_booking Decorator"
def wrapper(request, **kwargs):
booking = _get_booking_from_session(request)
if booking == None:
# we don't have a booking in our session.
... | Decorators run before function it is decorating is called? | As an example:
def get_booking(f=None):
print "Calling get_booking Decorator"
def wrapper(request, **kwargs):
booking = _get_booking_from_session(request)
if booking == None:
# we don't have a booking in our session.
return HttpRedirect('/')
else:
retu... | [
"I believe python decorators are just syntactic sugar.\n@foo\ndef bar ():\n pass\n\nis the same thing as\ndef bar ():\n pass\nbar = foo(bar)\n\nAs you can see, foo is being called even though bar has not been called. This is why you see the output from your decorator function. Your output should contain a sin... | [
37,
1,
0,
0
] | [] | [] | [
"decorator",
"django",
"python"
] | stackoverflow_0000341379_decorator_django_python.txt |
Q:
Is rewriting a PHP app into Python a productive step?
I have some old apps written in PHP that I'm thinking of converting to Python - both are websites that started as simple static html, then progressed to PHP and now include blogs with admin areas, rss etc. I'm thinking of rewriting them in Python to improve mai... | Is rewriting a PHP app into Python a productive step? | I have some old apps written in PHP that I'm thinking of converting to Python - both are websites that started as simple static html, then progressed to PHP and now include blogs with admin areas, rss etc. I'm thinking of rewriting them in Python to improve maintainability as well as to take advantage of my increase in... | [
"You need to take some parts into mind here,\n\nWhat will you gain from re-writing\nIs it an economically wise decision\nWill the code be easier to handle for new programmers\nPerformance-wise, will this be a good option?\n\nThese four points is something that is important, will the work be more efficient after you... | [
14,
4,
2,
2,
2,
1,
1,
1,
1,
0,
0
] | [] | [] | [
"php",
"python"
] | stackoverflow_0000340318_php_python.txt |
Q:
Best way to import version-specific python modules
Which method makes the most sense for importing a module in python that is version specific? My use case is that I'm writing code that will be deployed into a python 2.3 environment and in a few months be upgraded to python 2.5. This:
if sys.version_info[:2] >= (2... | Best way to import version-specific python modules | Which method makes the most sense for importing a module in python that is version specific? My use case is that I'm writing code that will be deployed into a python 2.3 environment and in a few months be upgraded to python 2.5. This:
if sys.version_info[:2] >= (2, 5):
from string import Template
else:
from our... | [
"Always the second way - you never know what different Python installations will have installed. Template is a specific case where it matters less, but when you test for the capability instead of the versioning you're always more robust.\nThat's how I make Testoob support Python 2.2 - 2.6: I try to import a module ... | [
28,
2
] | [] | [] | [
"code_migration",
"migration",
"module",
"python"
] | stackoverflow_0000342437_code_migration_migration_module_python.txt |
Q:
Problem regarding 3.0's "hashlib" module
I've been working on getting a 2.5 module ported to 3.0, mostly for my own education, when I've gotten stuck. The class "Builder" has as its init:
def __init__(self, **options):
self._verifyOptions(options)
self._options = options
self._initDigest()
self._in... | Problem regarding 3.0's "hashlib" module | I've been working on getting a 2.5 module ported to 3.0, mostly for my own education, when I've gotten stuck. The class "Builder" has as its init:
def __init__(self, **options):
self._verifyOptions(options)
self._options = options
self._initDigest()
self._initBuildNames()
self._methods = []
But th... | [
"I'm guessing that this line:\ndigester.update(self._options.get('code'))\n\nshould become:\ndigester.update(self._options.get('code').encode(\"utf-8\"))\n\nThe actual desired encoding could be different in your case, but UTF-8 will work in all cases.\n",
"I havent tried 3.0 yet. But there is now a bigger distinc... | [
4,
0
] | [] | [] | [
"python",
"python_2to3",
"python_3.x"
] | stackoverflow_0000343204_python_python_2to3_python_3.x.txt |
Q:
Best way of sharing/managing our internal python library between applications
Our company (xyz) is moving a lot of our Flash code to Python.
In Flash, we have a shared library between our Flash apps - package xyz. We can make changes to the package without fear of breaking other apps when they are deployed because... | Best way of sharing/managing our internal python library between applications | Our company (xyz) is moving a lot of our Flash code to Python.
In Flash, we have a shared library between our Flash apps - package xyz. We can make changes to the package without fear of breaking other apps when they are deployed because Flash compiles their code and includes the contents of the library. We deploy the ... | [
"\"explicitly tested against App1,2,3 every time there was a new library\" actually isn't that onerous.\nTwo things.\n\nYou need a formal set of API unit tests that the library must pass. This is just the API, not every nuance of functionality. If this passes, then your changes are good to go. If this fails, you... | [
4,
1,
1
] | [] | [] | [
"deployment",
"projects_and_solutions",
"python",
"shared_libraries"
] | stackoverflow_0000342425_deployment_projects_and_solutions_python_shared_libraries.txt |
Q:
How do I work with multiple git branches of a python module?
I want to use git to allow me to work on several features in a module I'm writing concurrently. I'm currently using SVN, with only one workspace, so I just have the workspace on my PYTHONPATH. I'm realizing this is less than ideal, so I was wondering if ... | How do I work with multiple git branches of a python module? | I want to use git to allow me to work on several features in a module I'm writing concurrently. I'm currently using SVN, with only one workspace, so I just have the workspace on my PYTHONPATH. I'm realizing this is less than ideal, so I was wondering if anyone could suggest a more 'proper' way of doing this.
Let me ela... | [
"Relative imports (PEP 328) might help:\neggs/\n __init__.py\n foo.py\n bar.py\n\n# foo.py\nfrom __future__ import absolute_import\nfrom . import bar\n\nSee How do you organize Python modules? for other options.\nEDIT:\nYet another option is to use S.Lott's and Jim's suggestions i.e, restructure your package to ... | [
3,
1,
1
] | [] | [] | [
"git",
"module",
"python"
] | stackoverflow_0000343517_git_module_python.txt |
Q:
What can Pygame do in terms of graphics that wxPython can't?
I want to develop a very simple 2D game in Python. Pygame is the most popular library for game development in Python, but I'm already quite familiar with wxPython and feel comfortable using it. I've even written a Tetris clone in it, and it was pretty sm... | What can Pygame do in terms of graphics that wxPython can't? | I want to develop a very simple 2D game in Python. Pygame is the most popular library for game development in Python, but I'm already quite familiar with wxPython and feel comfortable using it. I've even written a Tetris clone in it, and it was pretty smooth.
I wonder, what does Pygame offer in terms of graphics (leavi... | [
"Well, in theory there is nothing you can do with Pygame that you can't with wxPython. The point is not what but how. In my opinion, it's easier to write a game with PyGame becasue:\n\nIt's faster. Pygame is based on SDL which is a C library specifically designed for games, it has been developed with speed in mind.... | [
19,
13
] | [] | [] | [
"graphics",
"pygame",
"python",
"wxpython"
] | stackoverflow_0000343505_graphics_pygame_python_wxpython.txt |
Q:
Having problem importing the PIL image library
i am trying to do something with the PIL Image library in django, but i experience some problems.
I do like this:
import Image
And then I do like this
images = map(Image.open, glob.glob(os.path.join(dirpath, '*.thumb.jpg')))
But when i try to run this i get an err... | Having problem importing the PIL image library | i am trying to do something with the PIL Image library in django, but i experience some problems.
I do like this:
import Image
And then I do like this
images = map(Image.open, glob.glob(os.path.join(dirpath, '*.thumb.jpg')))
But when i try to run this i get an error and it leeds me to think that its not imported co... | [
"The error above happens because your file is called Image.py and you're trying to import yourself. As Manual pointed out, you should import Image from the PIL module, but you'd also need to rename your file so it's not called Image.py.\n",
"Your example works fine in my machine. I don't know why you're getting t... | [
1,
0
] | [] | [] | [
"django",
"image",
"python",
"python_imaging_library"
] | stackoverflow_0000344753_django_image_python_python_imaging_library.txt |
Q:
Open file, read it, process, and write back - shortest method in Python
I want to do some basic filtering on a file. Read it, do processing, write it back.
I'm not looking for "golfing", but want the simplest and most elegant method to achieve this. I came up with:
from __future__ import with_statement
filename ... | Open file, read it, process, and write back - shortest method in Python | I want to do some basic filtering on a file. Read it, do processing, write it back.
I'm not looking for "golfing", but want the simplest and most elegant method to achieve this. I came up with:
from __future__ import with_statement
filename = "..." # or sys.argv...
with open(filename) as f:
new_txt = # ...some t... | [
"Actually an easier way using fileinput is to use the inplace parameter:\nimport fileinput\nfor line in fileinput.input (filenameToProcess, inplace=1):\n process (line)\n\nIf you use the inplace parameter it will redirect stdout to your file, so that if you do a print it will write back to your file.\nThis examp... | [
26,
4,
3,
2,
1,
0
] | [] | [] | [
"coding_style",
"python"
] | stackoverflow_0000227461_coding_style_python.txt |
Q:
How do I submit a form given only the HTML source?
I would like to be able to submit a form in an HTML source (string). In other words I need at least the ability to generate POST parameters from a string containing HTML source of the form. This is needed in unit tests for a Django project. I would like a solution... | How do I submit a form given only the HTML source? | I would like to be able to submit a form in an HTML source (string). In other words I need at least the ability to generate POST parameters from a string containing HTML source of the form. This is needed in unit tests for a Django project. I would like a solution that possibly;
Uses only standard Python library and D... | [
"You should re-read the documentation about Django's testing framework, specifically the part about testing views (and forms) with the test client.\nThe test client acts as a simple web browser, and lets you make GET and POST requests to your Django views. You can read the response HTML or get the same Context obje... | [
4,
2,
2,
0
] | [] | [] | [
"django",
"form_submit",
"parsing",
"python",
"testing"
] | stackoverflow_0000343622_django_form_submit_parsing_python_testing.txt |
Q:
Why doesn't Python 2.6 have set literals and comprehensions or dict comprehensions?
Python 2.6 was basically a stepping stone to make converting to Python 3 easier. A lot of the features destined for Python 3 were implemented in 2.6 if they didn't break backward compatibility with syntax and the class libs.
Why w... | Why doesn't Python 2.6 have set literals and comprehensions or dict comprehensions? | Python 2.6 was basically a stepping stone to make converting to Python 3 easier. A lot of the features destined for Python 3 were implemented in 2.6 if they didn't break backward compatibility with syntax and the class libs.
Why weren't set literals ({1, 2, 3}), set comprehensions ({v for v in l}), or dict comprehensi... | [
"It wasn't done because nobody took the time to do it. There are bugs opened for months, and no one commented on them:\n\nhttp://bugs.python.org/issue2333\nhttp://bugs.python.org/issue2334\nhttp://bugs.python.org/issue2335\n\nSo it wasn't important enough for anybody to care, probably.\n",
"All these are syntax/g... | [
19,
10
] | [] | [] | [
"python",
"python_3.x"
] | stackoverflow_0000345356_python_python_3.x.txt |
Q:
Is this idiom pythonic? (someBool and "True Result" or "False Result")
I just came across this idiom in some open-source Python, and I choked on my drink.
Rather than:
if isUp:
return "Up"
else:
return "Down"
or even:
return "Up" if isUp else "Down"
the code read:
return isUp and "Up" or "Down"
I can se... | Is this idiom pythonic? (someBool and "True Result" or "False Result") | I just came across this idiom in some open-source Python, and I choked on my drink.
Rather than:
if isUp:
return "Up"
else:
return "Down"
or even:
return "Up" if isUp else "Down"
the code read:
return isUp and "Up" or "Down"
I can see this is the same result, but is this a typical idiom in Python? If so, is ... | [
"The \"a and b or c\" idiom was the canonical way to express the ternary arithmetic if in Python, before PEP 308 was written and implemented. This idiom fails the \"b\" answer is false itself; to support the general case, you could write\n return (a and [b] or [c])[0]\n\nAn alternative way of spelling it was\n retu... | [
17,
9,
0
] | [
"No, it is not.\nI had a somehow similar question the other day. \nif the construct \nval if cond else alt\n\nWas not very welcome ( at least by the SO community ) and the preferred one was:\nif cond:\n val\nelse:\n alt\n\nYou can get your own conclusion. :) \n",
"Yikes. Not readable at all. For me pytho... | [
-1,
-1
] | [
"coding_style",
"python"
] | stackoverflow_0000345745_coding_style_python.txt |
Q:
Read file object as string in python
I'm using urllib2 to read in a page. I need to do a quick regex on the source and pull out a few variables but urllib2 presents as a file object rather than a string.
I'm new to python so I'm struggling to see how I use a file object to do this. Is there a quick way to convert ... | Read file object as string in python | I'm using urllib2 to read in a page. I need to do a quick regex on the source and pull out a few variables but urllib2 presents as a file object rather than a string.
I'm new to python so I'm struggling to see how I use a file object to do this. Is there a quick way to convert this into a string?
| [
"You can use Python in interactive mode to search for solutions.\nif f is your object, you can enter dir(f) to see all methods and attributes. There's one called read. Enter help(f.read) and it tells you that f.read() is the way to retrieve a string from an file object.\n",
"From the doc file.read() (my emphasis)... | [
77,
14,
5
] | [] | [] | [
"file",
"python",
"urllib2"
] | stackoverflow_0000346230_file_python_urllib2.txt |
Q:
Python Version for a Newbie
I am extremely new to python, having started to learn it less than a month ago, but experienced with some other programming languages (primarily C# and SQL). But now that Python 3.0 has been released and is not backwards compatible, what would be the advantages and disadvantages of dec... | Python Version for a Newbie | I am extremely new to python, having started to learn it less than a month ago, but experienced with some other programming languages (primarily C# and SQL). But now that Python 3.0 has been released and is not backwards compatible, what would be the advantages and disadvantages of deciding to focus on Python 3.0 or P... | [
"Go with 2.6 since that's what most libraries(pygame, wxpython, django, etc) target. \nThe differences in 3.0 aren't that huge, so transitioning to it later shouldn't be much of a problem.\n",
"Since they have incompatibilities, I suggest you start going for Python 3.0 which is more useful in the future anyway. ... | [
14,
6,
5,
3,
2,
1,
1
] | [] | [] | [
"python",
"python_3.x"
] | stackoverflow_0000345255_python_python_3.x.txt |
Q:
Installation problems with django-tagging
I am having problems using django-tagging. I try to follow the documentation but it fails at the second step
Once you've installed Django Tagging and want to use it in your Django applications, do the following:
Put 'tagging' in your INSTALLED_APPS setting.
Run the comma... | Installation problems with django-tagging | I am having problems using django-tagging. I try to follow the documentation but it fails at the second step
Once you've installed Django Tagging and want to use it in your Django applications, do the following:
Put 'tagging' in your INSTALLED_APPS setting.
Run the command manage.py syncdb.
The syncdb command create... | [
"http://code.djangoproject.com/ticket/7680\nparse_lookup has been removed. Not sure how this will affect tagging. Might want to do some searching. \nUpdate: apparently it's been fixed in the trunk version of tagging. Download the latest SVN build of tagging.\n",
"I had the same bug me recently. I checked out the... | [
4,
0
] | [] | [] | [
"django",
"django_tagging",
"python"
] | stackoverflow_0000346426_django_django_tagging_python.txt |
Q:
Django.contrib.flatpages without models
I have some flatpages with empty content field and their content inside the template (given with template_name field).
Why I am using django.contrib.flatpages
It allows me to serve (mostly) static pages with minimal URL configuration.
I don't have to write views for each of... | Django.contrib.flatpages without models | I have some flatpages with empty content field and their content inside the template (given with template_name field).
Why I am using django.contrib.flatpages
It allows me to serve (mostly) static pages with minimal URL configuration.
I don't have to write views for each of them.
Why I don't need the model FlatPage
... | [
"Using the direct_to_template generic view would be a lot simpler. You could use the passed in parameters on one view to specify the actual template in urls.py, if you don't want to add an entry for each page:\nr'^foo/(?P<template_name>.+)/$','direct_to_template', {'template': 'foo_index.html'}),\n\nThen import th... | [
9
] | [] | [] | [
"django",
"django_flatpages",
"python",
"templates"
] | stackoverflow_0000346840_django_django_flatpages_python_templates.txt |
Q:
Is it more efficient to use "import " or "from import "?
Say I only needed to use findall() from the re module, is it more efficient to do:
from re import findall
or
import re
Is there actually any difference in speed/memory usage etc?
A:
There is no difference on the import, however there is a small differe... | Is it more efficient to use "import " or "from import "? | Say I only needed to use findall() from the re module, is it more efficient to do:
from re import findall
or
import re
Is there actually any difference in speed/memory usage etc?
| [
"There is no difference on the import, however there is a small difference on access.\nWhen you access the function as\nre.findall() \n\npython will need to first find the module in the global scope and then find findall in modules dict. May make a difference if you are calling it inside a loop thousands of times.... | [
15,
12,
3
] | [] | [] | [
"import",
"python"
] | stackoverflow_0000346723_import_python.txt |
Q:
Refactoring python module configuration to avoid relative imports
This is related to a previous question of mine.
I understand how to store and read configuration files. There are choices such as ConfigParser and ConfigObj.
Consider this structure for a hypothetical 'eggs' module:
eggs/
common/
__init__.py
... | Refactoring python module configuration to avoid relative imports | This is related to a previous question of mine.
I understand how to store and read configuration files. There are choices such as ConfigParser and ConfigObj.
Consider this structure for a hypothetical 'eggs' module:
eggs/
common/
__init__.py
config.py
foo/
__init__.py
a.py
'eggs.foo.a' needs some ... | [
"\"imports ... require your module to be on your PYTHONPATH\"\nRight. \nSo, what's wrong with setting PYTHONPATH?\n",
"require statement from pkg_resources maybe what you need. \n",
"As I understand it from this and previous questions you only need one path to be in sys.path. If we are talking about git as VCS... | [
2,
0,
0,
0,
0
] | [] | [] | [
"configuration",
"module",
"python"
] | stackoverflow_0000345746_configuration_module_python.txt |
Q:
Python crypt module -- what's the correct use of salts?
First, context: I'm trying to create a command-line-based tool (Linux) that
requires login. Accounts on this tool have nothing to do with
system-level accounts -- none of this looks at /etc/passwd.
I am planning to store user accounts in a text file using the... | Python crypt module -- what's the correct use of salts? | First, context: I'm trying to create a command-line-based tool (Linux) that
requires login. Accounts on this tool have nothing to do with
system-level accounts -- none of this looks at /etc/passwd.
I am planning to store user accounts in a text file using the same format (roughly) as /etc/passwd.
Despite not using the ... | [
"Python's crypt() is a wrapper for the system's crypt() function. From the Linux crypt() man page:\n\nchar *crypt(const char *key, const char *salt);\n\nkey is a user’s typed password.\nsalt is a two-character string chosen from the set [a–zA–Z0–9./]. \nThis string is used to perturb the algorithm in one of 4096 \n... | [
7,
4,
3,
3,
2,
1,
1
] | [
"Take a look at the article TrueCrypt explained by Björn Edström. It contains easy to understand explanation of how truecrypt works and a simple Python implementation of some of truecrypt's functionality including password management.\n\nHe's talking about the Python crypt() module, not about TrueCrypt in Python\n\... | [
-2
] | [
"crypt",
"cryptography",
"linux",
"python"
] | stackoverflow_0000329956_crypt_cryptography_linux_python.txt |
Q:
Where do I go from here -- regarding programming?
I seem to be in a never ending tail spin of Linux, or not, Windows or not. Web programming or system programming. Python or PHP.
I'am self teaching myself programming. But it seems I keep being torn about which way to go. Unfortunately it is always seemingly good r... | Where do I go from here -- regarding programming? | I seem to be in a never ending tail spin of Linux, or not, Windows or not. Web programming or system programming. Python or PHP.
I'am self teaching myself programming. But it seems I keep being torn about which way to go. Unfortunately it is always seemingly good reasons to get side tracked. You know the whole open sou... | [
"You will only have a first language for a little while. Pick any direction that interests you, and follow it. There is no way around the introduction \"Drink from the Firehose\" experience.\nKeep early project simple, and tangible. Build useful things and the motivation will be there.\nWeb / desktop / mobile / etc... | [
7,
2,
2,
0,
0,
0,
0,
0,
0
] | [] | [] | [
"asp.net",
"linux",
"php",
"python"
] | stackoverflow_0000347054_asp.net_linux_php_python.txt |
Q:
Rounding float to the nearest factor?
I have a small math problem I am trying to solve
Given a number x and resolution y, I need to find the next x' with the required resolution.
e.g.
x = 1.002 y = 0.1 x'= 1.1
x = 0.348 y = 0.1 x'= 0.4
x = 0.50 y = 1 x'= 1
x = 0.32 y = 0.05 x'= 0.3... | Rounding float to the nearest factor? | I have a small math problem I am trying to solve
Given a number x and resolution y, I need to find the next x' with the required resolution.
e.g.
x = 1.002 y = 0.1 x'= 1.1
x = 0.348 y = 0.1 x'= 0.4
x = 0.50 y = 1 x'= 1
x = 0.32 y = 0.05 x'= 0.35
Is there any smart way of doing this in ... | [
"import math\n\ndef next_multiple(x, y):\n return math.ceil(x/y)*y\n\ndef try_it(x, y):\n print x, y, next_multiple(x, y)\n\nfor x, y in [\n (1.002, 0.1),\n (0.348, 0.1),\n (0.50, 1),\n (0.32, 0.05)\n ]:\n try_it(x, y)\n\nproduces:\n1.002 0.1 1.1\n0.348 0.1 0.4\n0.5 1 1.0\n0.32 0.05 0.35\n\n... | [
12
] | [] | [] | [
"algorithm",
"math",
"python"
] | stackoverflow_0000347538_algorithm_math_python.txt |
Q:
Emitting headers from a tiny Python web-framework
I am writing a web-framework for Python, of which the goal is to be as "small" as possible (currently under 100 lines of code).. You can see the current code on github
Basically it's written to be as simple to use as possible. An example "Hello World" like site:
fr... | Emitting headers from a tiny Python web-framework | I am writing a web-framework for Python, of which the goal is to be as "small" as possible (currently under 100 lines of code).. You can see the current code on github
Basically it's written to be as simple to use as possible. An example "Hello World" like site:
from pyerweb import GET, runner
@GET("/")
def index():
... | [
"Look at PEP 333 for an excellent design pattern for a very lightweight web server. If your server has this exact API, you can reuse it in a lot of context with a lot of other products.\nPEP 333 (WSGI) suggests that you don't directly return the page, but you provide the HTML page to a \"start_response\" callable ... | [
5,
3,
1
] | [] | [] | [
"frameworks",
"python"
] | stackoverflow_0000347497_frameworks_python.txt |
Q:
mod_python.publisher always gives content type 'text/plain'
I've just set up mod python with apache and I'm trying to get a simple script to work, but what happens is it publishes all my html as plain text when I load the page. I figured this is a problem with mod_python.publisher, The handler I set it too. I sea... | mod_python.publisher always gives content type 'text/plain' | I've just set up mod python with apache and I'm trying to get a simple script to work, but what happens is it publishes all my html as plain text when I load the page. I figured this is a problem with mod_python.publisher, The handler I set it too. I searched through the source of it and found the line where it differ... | [
"Your configuration looks okay: I've got a working mod_python.publisher script with essentially the same settings.\nA few other thoughts:\n\nWhen you tried editing the publisher source code, did you restart your web server? It only loads Python libraries once, when the server is first started.\nPublisher's autodete... | [
3
] | [] | [] | [
"content_type",
"mod_python",
"python"
] | stackoverflow_0000347632_content_type_mod_python_python.txt |
Q:
Gauss-Legendre Algorithm in python
I need some help calculating Pi. I am trying to write a python program that will calculate Pi to X digits. I have tried several from the python mailing list, and it is to slow for my use.
I have read about the Gauss-Legendre Algorithm, and I have tried porting it to Python with ... | Gauss-Legendre Algorithm in python | I need some help calculating Pi. I am trying to write a python program that will calculate Pi to X digits. I have tried several from the python mailing list, and it is to slow for my use.
I have read about the Gauss-Legendre Algorithm, and I have tried porting it to Python with no success.
I am reading from Here, and ... | [
"\nYou forgot parentheses around 4*t:\npi = (a+b)**2 / (4*t)\n\nYou can use decimal to perform calculation with higher precision.\n#!/usr/bin/env python\nfrom __future__ import with_statement\nimport decimal\n\ndef pi_gauss_legendre():\n D = decimal.Decimal\n with decimal.localcontext() as ctx:\n ctx.p... | [
29,
3,
3
] | [] | [] | [
"algorithm",
"pi",
"python"
] | stackoverflow_0000347734_algorithm_pi_python.txt |
Q:
Ticking function grapher
I am trying to figure out the following problem.
I am building Yet another math function grapher, The function is drawn on its predefined x,y range, that's all good.
Now I am working on the background and the ticking of X, Y axes (if any axes are shown).
I worked out the following.
I have ... | Ticking function grapher | I am trying to figure out the following problem.
I am building Yet another math function grapher, The function is drawn on its predefined x,y range, that's all good.
Now I am working on the background and the ticking of X, Y axes (if any axes are shown).
I worked out the following.
I have a fixed width of 250 p
The ti... | [
"One way to do this would be to \"normalise\" the difference between the minimum and maximum and do a case distinction on that value. In python:\ndelta = maximum - minimum\nfactor = 10**math.ceil(math.log(delta,10)) # smallest power of 10 greater than delta\nnormalised_delta = delta / factor # 0.1 <= nor... | [
4,
0,
0,
0,
0
] | [] | [] | [
"algorithm",
"math",
"python"
] | stackoverflow_0000346823_algorithm_math_python.txt |
Q:
Questions for python->scheme conversion
I currently am trying to write a Python program using scheme semantics so I can later translate it into Scheme without relying on a lot of Pythonic stuff.
I'm trying solve the sliding puzzle problem (where you have 9 slots and 8 tiles arranged in a square) using a*, depth fi... | Questions for python->scheme conversion | I currently am trying to write a Python program using scheme semantics so I can later translate it into Scheme without relying on a lot of Pythonic stuff.
I'm trying solve the sliding puzzle problem (where you have 9 slots and 8 tiles arranged in a square) using a*, depth first, and breadth first search algorithm. I d... | [
"You identified that your initial problem was trying to write C semantics in Lisp. Is it not repeating the mistake to try to write scheme semantics in python? I always try to learn language X as a paradigm as much as a language and write in the most x-ish way.\nIt might be justifiable if this was a business app you... | [
4,
2,
1,
0
] | [] | [] | [
"arrays",
"python",
"scheme"
] | stackoverflow_0000347010_arrays_python_scheme.txt |
Q:
Can I use Python to intercept global keystrokes in KDE?
I want to make a simple app, ideally in Python, that would run in the background on KDE, listening to all keystrokes being done by the user, so that the app goes to the foreground if a specific combination of keys is pressed. Is that doable? Can anyone point ... | Can I use Python to intercept global keystrokes in KDE? | I want to make a simple app, ideally in Python, that would run in the background on KDE, listening to all keystrokes being done by the user, so that the app goes to the foreground if a specific combination of keys is pressed. Is that doable? Can anyone point me to such resource?
| [
"A quick google found this:\nhttp://sourceforge.net/projects/pykeylogger/\nYou might be able to use some of the source code.\n"
] | [
1
] | [] | [] | [
"kde_plasma",
"python"
] | stackoverflow_0000347475_kde_plasma_python.txt |
Q:
What features of Python 3.0 will change your everyday coding?
Py3k just came out and has gobs of neat new stuff! I'm curious, what are SO pythonistas most excited about? What features are going to affect the way you write code on a daily basis, or have you been looking forward to?
A:
There are a few things I'm... | What features of Python 3.0 will change your everyday coding? | Py3k just came out and has gobs of neat new stuff! I'm curious, what are SO pythonistas most excited about? What features are going to affect the way you write code on a daily basis, or have you been looking forward to?
| [
"There are a few things I'm quite interested in:\n\nText and data instead of unicode and 8 bit\nExtended Iterable Unpacking\nFunction annotations\nBinary literals\nNew exception catching syntax\nA number of Python 2.6 features, eg: the with statement\n\n",
"I hope that exception chaining catches on. Losing except... | [
17,
7,
6,
4,
3,
3,
2,
2,
2,
1,
1
] | [] | [] | [
"python",
"python_3.x"
] | stackoverflow_0000340972_python_python_3.x.txt |
Q:
What is the most efficient way of extracting information from a large number of xml files in python?
I have a directory full (~103, 104) of XML files from which I need to extract the contents of several fields.
I've tested different xml parsers, and since I don't need to validate the contents (expensive) I was th... | What is the most efficient way of extracting information from a large number of xml files in python? | I have a directory full (~103, 104) of XML files from which I need to extract the contents of several fields.
I've tested different xml parsers, and since I don't need to validate the contents (expensive) I was thinking of simply using xml.parsers.expat (the fastest one) to go through the files, one by one to extract ... | [
"Usually, I would suggest using ElementTree's iterparse, or for extra-speed, its counterpart from lxml. Also try to use Processing (comes built-in with 2.6) to parallelize.\nThe important thing about iterparse is that you get the element (sub-)structures as they are parsed.\nimport xml.etree.cElementTree as ET\nxml... | [
4,
3,
1,
1
] | [] | [] | [
"expat_parser",
"large_files",
"performance",
"python",
"xml"
] | stackoverflow_0000344559_expat_parser_large_files_performance_python_xml.txt |
Q:
Python distutils and replacing strings in code
I often find a need to put paths in my code in order to find data or in some cases tool-specific modules. I've so far always used autotools because of this--it's just so easy to call sed to replace a few strings at build time. However, I'd like to find a more Python... | Python distutils and replacing strings in code | I often find a need to put paths in my code in order to find data or in some cases tool-specific modules. I've so far always used autotools because of this--it's just so easy to call sed to replace a few strings at build time. However, I'd like to find a more Pythonic way of doing this, i.e. use distutils or some oth... | [
"For modules paths, a common practice is putting them in .pth files, as documented here. The site module provides a space for Site-specific configuration hooks, you can use it to tailor your environment.\n",
"Well, with distutils (in the standard library) you have \"package data\". This is data that lives inside ... | [
1,
1,
1,
0
] | [
"\"I often find a need to put paths in my code\" -- this isn't very Pythonic to begin with.\nIdeally, your code lives in some place like site-packages and that's the end of that.\nOften, we have an installed \"application\" that uses a fairly fixed set of directories for working files. In linux, we get this infor... | [
-1
] | [
"python"
] | stackoverflow_0000267977_python.txt |
Q:
Notification Library for Windows
I'm developing a small tray-icon application for Windows and I need to display non-intrusive visual notifications similar to those that appear when you receive a new message in MSN Messenger or any other IM application.
I have looked at Snarl, but it seems to be a separate applicat... | Notification Library for Windows | I'm developing a small tray-icon application for Windows and I need to display non-intrusive visual notifications similar to those that appear when you receive a new message in MSN Messenger or any other IM application.
I have looked at Snarl, but it seems to be a separate application that I need to install. I want som... | [
"You can do it by depending on a GUI library.\nFor example, with PyQt,it is possible :\n\nPyQt QSystemTrayIcon Documentation\nQSystemTrayIcon Class Reference\nExample of QSystemTrayIcon (in C++, easy to adapt to python)\n\n",
"I wrote one for .NET for the Genghis project (link here) a while back. Looks like it i... | [
3,
2,
2,
1
] | [] | [] | [
"notifications",
"python",
"windows"
] | stackoverflow_0000344442_notifications_python_windows.txt |
Q:
Run a shortcut under windows
The following doesn't work, because it doesn't wait until the process is finished:
import subprocess
p = subprocess.Popen('start /WAIT /B MOZILL~1.LNK', shell=True)
p.wait()
Any idea how to run a shortcut and wait that the subprocess returns ?
Edit: originally I was trying this withou... | Run a shortcut under windows | The following doesn't work, because it doesn't wait until the process is finished:
import subprocess
p = subprocess.Popen('start /WAIT /B MOZILL~1.LNK', shell=True)
p.wait()
Any idea how to run a shortcut and wait that the subprocess returns ?
Edit: originally I was trying this without the shell option in my post, whi... | [
"You will need to invoke a shell to get the subprocess option to work:\np = subprocess.Popen('start /B MOZILL~1.LNK', shell=True)\np.wait()\n\nThis however will still exit immediately (see @R. Bemrose).\nIf p.pid contains the correct pid (I'm not sure on windows), then you could use os.waitpid() to wait for the pro... | [
4,
3,
0
] | [] | [] | [
"python",
"windows"
] | stackoverflow_0000349653_python_windows.txt |
Q:
Python for C++ Developers
I'm a long time C++/Java developer trying to get into Python and am looking for the stereotypical "Python for C++ Developers" article, but coming up blank. I've seen these sort of things for C#, Java, etc, and they're incredibly useful for getting up to speed on language features and not... | Python for C++ Developers | I'm a long time C++/Java developer trying to get into Python and am looking for the stereotypical "Python for C++ Developers" article, but coming up blank. I've seen these sort of things for C#, Java, etc, and they're incredibly useful for getting up to speed on language features and noteworthy differences. Anyone ha... | [
"I never really understood the \"Language X for Language Y developers\" approach. When I go looking to learn Language X I want to learn how to program in it the way that Language X programmers do, not the way Language Y programmers do. I want to learn the features, idioms, etc. that are unique to the language tha... | [
24,
13,
5,
4,
2,
1,
1,
0
] | [] | [] | [
"c++",
"python"
] | stackoverflow_0000328577_c++_python.txt |
Q:
Why is my Python C Extension leaking memory?
The function below takes a python file handle, reads in packed binary data from the file, creates a Python dictionary and returns it. If I loop it endlessly, it'll continually consume RAM. What's wrong with my RefCounting?
static PyObject* __binParse_getDBHeader(PyObj... | Why is my Python C Extension leaking memory? | The function below takes a python file handle, reads in packed binary data from the file, creates a Python dictionary and returns it. If I loop it endlessly, it'll continually consume RAM. What's wrong with my RefCounting?
static PyObject* __binParse_getDBHeader(PyObject *self, PyObject *args){
PyObject *o; //generi... | [
"PyDict_New() returns a new reference, check the docs for PyDict. So if you increase the refcount immediately after creating it, you have two references to it. One is transferred to the caller when you return it as a result value, but the other one never goes aways.\nYou also don't need to incref pyTimeList. It's y... | [
17,
5,
3
] | [] | [] | [
"c",
"python",
"refcounting"
] | stackoverflow_0000350647_c_python_refcounting.txt |
Q:
What does the function set use to check if two objects are different?
Simple code:
>>> set([2,2,1,2,2,2,3,3,5,1])
set([1, 2, 3, 5])
Ok, in the resulting sets there are no duplicates.
What if the object in the list are not int but are some defined by me?
What method does it check to understand if they are differen... | What does the function set use to check if two objects are different? | Simple code:
>>> set([2,2,1,2,2,2,3,3,5,1])
set([1, 2, 3, 5])
Ok, in the resulting sets there are no duplicates.
What if the object in the list are not int but are some defined by me?
What method does it check to understand if they are different? I implemented __eq__ and __cmp__ with some objects but set doesn't seems... | [
"According to the set documentation, the elements must be hashable. \nAn object is hashable if it has a hash value which never changes during its lifetime (it needs a __hash__() method), and can be compared to other objects (it needs an __eq__() or __cmp__() method). Hashable objects which compare equal must have ... | [
13
] | [] | [] | [
"methods",
"python",
"set"
] | stackoverflow_0000351271_methods_python_set.txt |
Q:
Determine record in multi record html form
In a html form, I'm displaying multiple records from a table, ready for update.
Right now I use: name=<column-name>_<pk-id> value=<value> for the fields.
Then in my python-script I go for:
for key in form.keys():
if key.startswith('<name-A>_'):
update <table> ... | Determine record in multi record html form | In a html form, I'm displaying multiple records from a table, ready for update.
Right now I use: name=<column-name>_<pk-id> value=<value> for the fields.
Then in my python-script I go for:
for key in form.keys():
if key.startswith('<name-A>_'):
update <table> set <name-A> = <value> where pk=<pk-id>
if k... | [
"In java apps, it's common to JSONify the name.\n<input name=\"records[pk].fieldName\"/>\n\npk being the primary key of the row and fieldName the field. Of course most frameworks handle this transparently. Each record ends up as a instance of a class with a property for each field, all of which are put into a list ... | [
1
] | [] | [] | [
"cgi",
"html",
"python"
] | stackoverflow_0000351440_cgi_html_python.txt |
Q:
How do I get data from stdin using os.system()
The only reliable method that I a have found for using a script to download text from wikipedia is with cURL. So far the only way I have for doing that is to call os.system(). Even though the output appears properly in the python shell I can't seem to the function it ... | How do I get data from stdin using os.system() | The only reliable method that I a have found for using a script to download text from wikipedia is with cURL. So far the only way I have for doing that is to call os.system(). Even though the output appears properly in the python shell I can't seem to the function it to return anything other than the exit code(0). Alte... | [
"From Dive into Python: \nimport urllib\nsock = urllib.urlopen(\"http://en.wikipedia.org/wiki/Python_(programming_language)\")\nhtmlsource = sock.read()\nsock.close()\nprint htmlsource\n\nThat will print out the source code for the Python Wikipedia article. I suggest you take a look at Dive into Python for more de... | [
7,
2,
0
] | [] | [] | [
"curl",
"os.system",
"python",
"shell",
"urllib"
] | stackoverflow_0000351456_curl_os.system_python_shell_urllib.txt |
Q:
Formatting a data structure into a comma-separated list of arguments
I need to convert a list (or a dict) into a comma-separated list for passing to another language.
Is there a nicer way of doing this than:
result = ''
args = ['a', 'b', 'c', 'd']
i = 0
for arg in args:
if i != 0: result += arg
e... | Formatting a data structure into a comma-separated list of arguments | I need to convert a list (or a dict) into a comma-separated list for passing to another language.
Is there a nicer way of doing this than:
result = ''
args = ['a', 'b', 'c', 'd']
i = 0
for arg in args:
if i != 0: result += arg
else: result += arg + ', '
i += 1
result = 'function (' + re... | [
"', '.join(args) will do the trick.\n",
"'function(%s)' % ', '.join(args)\n\nproduces\n'function(a, b, c, d)'\n\n",
"result = 'function (%s)' % ', '.join(map(str,args))\n\nI recommend the map(str, args) instead of just args because some of your arguments could potentially not be strings and would cause a TypeEr... | [
12,
11,
1,
0
] | [] | [] | [
"list",
"python",
"refactoring"
] | stackoverflow_0000349175_list_python_refactoring.txt |
Q:
destroying a Toplevel tk window in python
I was trying to write code that would auto-close a Toplevel Tk window in Python.
I ended up getting it to work, but ran into a little problem along the way that I wasn't able to figure out.
The second two buttons work, but the first one doesn't and I don't understand why..... | destroying a Toplevel tk window in python | I was trying to write code that would auto-close a Toplevel Tk window in Python.
I ended up getting it to work, but ran into a little problem along the way that I wasn't able to figure out.
The second two buttons work, but the first one doesn't and I don't understand why...
Any ideas?
from Tkinter import *
root = Tk()... | [
"Because it returns a function and not its result.\nYou should put:\ncommand=TL.destroy\n\nor if you used lambda:\ncommand=lambda: TL.destroy()\n\n"
] | [
8
] | [] | [] | [
"python",
"tkinter"
] | stackoverflow_0000351821_python_tkinter.txt |
Q:
Return file from python module
Edit: How to return/serve a file from a python controller (back end) over a web server, with the file_name? as suggested by @JV
A:
You can either pass back a reference to the file itself i.e. the full path to the file. Then you can open the file or otherwise manipulate it.
Or, the ... | Return file from python module | Edit: How to return/serve a file from a python controller (back end) over a web server, with the file_name? as suggested by @JV
| [
"You can either pass back a reference to the file itself i.e. the full path to the file. Then you can open the file or otherwise manipulate it.\nOr, the more normal case is to pass back the file handle, and, use the standard read/write operations on the file handle.\nIt is not recommended to pass the actual data as... | [
2,
1,
0
] | [] | [] | [
"download",
"file",
"mime_types",
"python"
] | stackoverflow_0000352340_download_file_mime_types_python.txt |
Q:
Making Python default to another version installed on a shared host
I am on a shared host and can not change the symbolic link to Python2.4, it defaults to 2.3. I tried creating a sym link in the director I would be working on to 2.4, but it seems the the 'global' python interpreter under /usr/bin/python take pres... | Making Python default to another version installed on a shared host | I am on a shared host and can not change the symbolic link to Python2.4, it defaults to 2.3. I tried creating a sym link in the director I would be working on to 2.4, but it seems the the 'global' python interpreter under /usr/bin/python take presedence unless I run it as ./python. What alternative ways are there to ov... | [
"If you're working from the shell, you can create a symbolic link as suggested and update your path in the .profile. This is described in a previous post.\nIn case these are CGI/whatever scripts that you only run on your shared host, you can alter the shebang line at the top of your scripts that tell the system wha... | [
3,
2
] | [] | [] | [
"linux",
"python"
] | stackoverflow_0000353148_linux_python.txt |
Q:
Python method arguments with spaces
I would like to create a simple file format/DSL which would allow my users to input data. My system is in python and using python's parser is appealing.
Syntax like this for defining a data element seems quite convenient.
Allocation(Param1 = Val1, Param2 = Val2 )
However, it ... | Python method arguments with spaces | I would like to create a simple file format/DSL which would allow my users to input data. My system is in python and using python's parser is appealing.
Syntax like this for defining a data element seems quite convenient.
Allocation(Param1 = Val1, Param2 = Val2 )
However, it does not support param names with spaces.... | [
"I'd imagine that there would be some way to do it. But I feel compelled to ask, is there really a big enough difference in readability from this\nAllocation(Param1 = Val1, Param2 = Val2 )\n\nTo this:\nAllocation(Param 1 = Val1, Param 2 = Val2 )\n\nto make that big a difference? I'm sure there's a way to do what ... | [
3,
1,
1,
1
] | [] | [] | [
"dsl",
"python"
] | stackoverflow_0000351760_dsl_python.txt |
Q:
Beginner: Trying to understand how apps interact in Django
I just got done working through the Django tutorials for the second time, and am understanding things much more clearly now. However, I'm still unclear how apps inside a site interact with one another.
For example, lets say I'm writing a blog application (... | Beginner: Trying to understand how apps interact in Django | I just got done working through the Django tutorials for the second time, and am understanding things much more clearly now. However, I'm still unclear how apps inside a site interact with one another.
For example, lets say I'm writing a blog application (a rather popular activity, apparently). Blog posts and comments ... | [
"Take a look at django's built-in contenttypes framework:\ndjango.contrib.contenttypes\nIt allows you develop your applications as stand-alone units. This is what the django developers used to allow django's built-in comment framework to attach a comment to any model in your project.\nFor instance, if you have som... | [
22,
4,
3,
2
] | [] | [] | [
"django",
"django_apps",
"django_models",
"python"
] | stackoverflow_0000353571_django_django_apps_django_models_python.txt |
Q:
Cleaner way to query on a dynamic number of columns in Django?
In my case, I have a number of column names coming from a form. I want to filter to make sure they're all true. Here's how I currently do it:
for op in self.cleaned_data['options']:
cars = cars.filter((op, True))
Now it works but there are are a p... | Cleaner way to query on a dynamic number of columns in Django? | In my case, I have a number of column names coming from a form. I want to filter to make sure they're all true. Here's how I currently do it:
for op in self.cleaned_data['options']:
cars = cars.filter((op, True))
Now it works but there are are a possible ~40 columns to be tested and it therefore doesn't appear ver... | [
"Build the query as a dictionary and use the ** operator to unpack the options as keyword arguments to the filter method.\nop_kwargs = {}\nfor op in self.cleaned_data['options']:\n op_kwargs[op] = True\ncars = CarModel.objects.filter(**op_kwargs)\n\nThis is covered in the django documentation and has been covere... | [
9,
3
] | [] | [] | [
"django",
"python"
] | stackoverflow_0000353489_django_python.txt |
Q:
How to blend drawn circles with pygame
I am trying to create an application like the one here:
http://www.eigenfaces.com/
Basically lots of overlapping circles drawn with pygame. I cannot figure out how the blend the circles to make them translucent. That is to have overlapping colors show through. My code so far ... | How to blend drawn circles with pygame | I am trying to create an application like the one here:
http://www.eigenfaces.com/
Basically lots of overlapping circles drawn with pygame. I cannot figure out how the blend the circles to make them translucent. That is to have overlapping colors show through. My code so far is this:
import sys, random, time
import pyg... | [
"I got it to work by drawing to a surface that is not the display and combining the set colorkey and set alpha functions.\nimport pygame\nfrom pygame.locals import *\n\nTRANSPARENT = (255,0,255)\npygame.init()\nscreen = pygame.display.set_mode((500,500))\n\nsurf1 = pygame.Surface((200,200))\nsurf1.fill(TRANSPARENT)... | [
6,
3
] | [] | [] | [
"pygame",
"python"
] | stackoverflow_0000353297_pygame_python.txt |
Q:
How is ** implemented in Python?
I'm wondering where I find the source to show how the operator ** is implemented in Python. Can someone point me in the right direction?
A:
The python grammar definition (from which the parser is generated using pgen), look for 'power': Gramar/Gramar
The python ast, look for '... | How is ** implemented in Python? | I'm wondering where I find the source to show how the operator ** is implemented in Python. Can someone point me in the right direction?
| [
"The python grammar definition (from which the parser is generated using pgen), look for 'power': Gramar/Gramar\nThe python ast, look for 'ast_for_power': Python/ast.c\nThe python eval loop, look for 'BINARY_POWER': Python/ceval.c\nWhich calls PyNumber_Power (implemented in Objects/abstract.c):\nPyObject *\nPyNumbe... | [
26,
2,
1,
0
] | [] | [] | [
"python"
] | stackoverflow_0000354421_python.txt |
Q:
How can I get the number of records that reference a particular foreign key in Django?
I'm working on a blog application in Django. Naturally, I have models set up such that there are Posts and Comments, and a particular Post may have many Comments; thus, Post is a ForeignKey in the Comments model.
Given a Post ob... | How can I get the number of records that reference a particular foreign key in Django? | I'm working on a blog application in Django. Naturally, I have models set up such that there are Posts and Comments, and a particular Post may have many Comments; thus, Post is a ForeignKey in the Comments model.
Given a Post object, is there an easy way (ideally, through a method call) to find out how many Comments be... | [
"Comments.objects.filter(post=post).count()\n\nor:\npost.comment_set.count()\n\n",
"You can add field CommentCount to you Post model, and update it in pre_save, pre_delete signals.\nIt's a hard for the db to calculate comments count at every view call and number of queries will be grow.\n"
] | [
6,
0
] | [] | [] | [
"django",
"django_models",
"python"
] | stackoverflow_0000354755_django_django_models_python.txt |
Q:
Save a deque in a text file
I am writing a crawler in Python, in order to make Ctrl+C not to cause my crawler to start over in next run, I need to save the processing deque in a text file (one item per line) and update it every iteration, the update operation needs to be super fast. In order not to reinvent the wh... | Save a deque in a text file | I am writing a crawler in Python, in order to make Ctrl+C not to cause my crawler to start over in next run, I need to save the processing deque in a text file (one item per line) and update it every iteration, the update operation needs to be super fast. In order not to reinvent the wheel, I am asking if there is an e... | [
"As an alternative, you could set up an exit function, and pickle the deque on exit.\nExit function\nPickle\n",
"You should be able to use pickle to serialize your lists.\n",
"I am not sure if I understood the question right, I am just curious, so here are few questions and suggestions:\nAre you planning to cat... | [
4,
2,
1,
0
] | [] | [] | [
"python",
"web_crawler"
] | stackoverflow_0000355739_python_web_crawler.txt |
Q:
A get() like method for checking for Python attributes
If I had a dictionary dict and I wanted to check for dict['key'] I could either do so in a try block (bleh!) or use the get() method, with False as a default value.
I'd like to do the same thing for object.attribute. That is, I already have object to return Fa... | A get() like method for checking for Python attributes | If I had a dictionary dict and I wanted to check for dict['key'] I could either do so in a try block (bleh!) or use the get() method, with False as a default value.
I'd like to do the same thing for object.attribute. That is, I already have object to return False if it hasn't been set, but then that gives me errors lik... | [
"A more direct analogue to dict.get(key, default) than hasattr is getattr.\nval = getattr(obj, 'attr_to_check', default_value)\n\n(Where default_value is optional, raising an exception on no attribute if not found.)\nFor your example, you would pass False.\n",
"Do you mean hasattr() perhaps?\nhasattr(object, \"at... | [
140,
21,
7
] | [] | [] | [
"attributes",
"python"
] | stackoverflow_0000355539_attributes_python.txt |
Q:
Python regex findall numbers and dots
I'm using re.findall() to extract some version numbers from an HTML file:
>>> import re
>>> text = "<table><td><a href=\"url\">Test0.2.1.zip</a></td><td>Test0.2.1</td></table> Test0.2.1"
>>> re.findall("Test([\.0-9]*)", text)
['0.2.1.', '0.2.1', '0.2.1']
but I would like to o... | Python regex findall numbers and dots | I'm using re.findall() to extract some version numbers from an HTML file:
>>> import re
>>> text = "<table><td><a href=\"url\">Test0.2.1.zip</a></td><td>Test0.2.1</td></table> Test0.2.1"
>>> re.findall("Test([\.0-9]*)", text)
['0.2.1.', '0.2.1', '0.2.1']
but I would like to only get the ones that do not end in a dot.
... | [
"re.findall(r\"Test([0-9.]*[0-9]+)\", text)\n\nor, a bit shorter:\nre.findall(r\"Test([\\d.]*\\d+)\", text)\n\nBy the way - you do not need to escape the dot in a character class. Inside [] the . has no special meaning, it just matches a literal dot. Escaping it has no effect.\n"
] | [
23
] | [] | [] | [
"findall",
"python",
"regex"
] | stackoverflow_0000356483_findall_python_regex.txt |
Q:
How would you parse indentation (python style)?
How would you define your parser and lexer rules to parse a language that uses indentation for defining scope.
I have already googled and found a clever approach for parsing it by generating INDENT and DEDENT tokens in the lexer.
I will go deeper on this problem and ... | How would you parse indentation (python style)? | How would you define your parser and lexer rules to parse a language that uses indentation for defining scope.
I have already googled and found a clever approach for parsing it by generating INDENT and DEDENT tokens in the lexer.
I will go deeper on this problem and post an answer if I come to something interesting, bu... | [
"This is kind of hypothetical, as it would depend on what technology you have for your lexer and parser, but the easiest way would seem to be to have BEGINBLOCK and ENDBLOCK tokens analogous to braces in C. Using the \"offsides rule\" your lexer needs to keep track of a stack of indendtation levels. When the inde... | [
12,
1
] | [] | [] | [
"indentation",
"lexer",
"parsing",
"python"
] | stackoverflow_0000356638_indentation_lexer_parsing_python.txt |
Q:
Problem with Python implementation of Conway's Game of Life
I am working on Conway's Game of Life currently and have gotten stuck. My code doesn't work.
When I run my code in GUI, it says:
[[0 0 0 0]
[0 1 1 0]
[0 1 0 0]
[0 0 0 0]]
Traceback (most recent call last):
File "C:\Users\Documents\Physics\Python\M... | Problem with Python implementation of Conway's Game of Life | I am working on Conway's Game of Life currently and have gotten stuck. My code doesn't work.
When I run my code in GUI, it says:
[[0 0 0 0]
[0 1 1 0]
[0 1 0 0]
[0 0 0 0]]
Traceback (most recent call last):
File "C:\Users\Documents\Physics\Python\MainProject\conway.py", line 53, in
b= apply_rules(a)
File ... | [
"Well, I guess that you are also quite new to programming per se, otherwise you should not have any problems in interpreting that simple error message.\nI'll help you dissect it:\n\nFirst, all \"current\" line numbers of your project's files are displayed, in calling order.\nThen, it shows you the function in which... | [
13,
3,
2,
0
] | [] | [] | [
"python"
] | stackoverflow_0000357968_python.txt |
Q:
A small question about python's variable scope
I am a beginner of python and have a question, very confusing for me.
If I define a function first but within the function I have to use a variable which is defined in another function below, can I do it like this? Or how can I import the return things of another func... | A small question about python's variable scope | I am a beginner of python and have a question, very confusing for me.
If I define a function first but within the function I have to use a variable which is defined in another function below, can I do it like this? Or how can I import the return things of another function into a function?
for example:
def hello(x,y):
... | [
"The scope of functions hello and hi are entirely different. They do not have any variables in common.\nNote that the result of calling hi(x,y) is some object. You save that object with the name good in the function hello.\nThe variable named good in hello is a different variable, unrelated to the variable named ... | [
5,
3,
2,
2,
1
] | [] | [] | [
"python",
"scope",
"variables"
] | stackoverflow_0000357810_python_scope_variables.txt |
Q:
log4j with timestamp per log entry
this is my log output
INFO main digestemails - process inbox
INFO main digestemails - checking for emails in c:\development\DCMail\email\KN-Source
INFO main digestemails - digesting 003d01c95a7b_3446880_0202fea9@xxxx.com.eml
INFO main digestemails - extracting attachments
INFO ma... | log4j with timestamp per log entry | this is my log output
INFO main digestemails - process inbox
INFO main digestemails - checking for emails in c:\development\DCMail\email\KN-Source
INFO main digestemails - digesting 003d01c95a7b_3446880_0202fea9@xxxx.com.eml
INFO main digestemails - extracting attachments
INFO main digestemails - no attachments or no a... | [
"Use %d in your PatternLayout.\nAlso %d can take a format pattern as in %d{dd MMM yyyy HH:mm:ss,SSS} you can pick and choose the elements that you want. When the format pattern is omitted the date will be in ISO8601 format.\n",
"A extract from my properties file\nlog4j.rootLogger=INFO, stdout, logfile\n\nlog4j.a... | [
104,
18,
6
] | [] | [] | [
"java",
"jython",
"log4j",
"python"
] | stackoverflow_0000358225_java_jython_log4j_python.txt |
Q:
Django Template System: How do I solve this looping / grouping / counting?
I have a list of articles, and each article belongs to a section.
class Section(models.Model):
name = models.CharField(max_length=200)
def __unicode__(self):
return self.name
class Article(models.Model):
section = models.Foreign... | Django Template System: How do I solve this looping / grouping / counting? | I have a list of articles, and each article belongs to a section.
class Section(models.Model):
name = models.CharField(max_length=200)
def __unicode__(self):
return self.name
class Article(models.Model):
section = models.ForeignKey(Section)
headline = models.CharField(max_length=200)
# ...
I want to di... | [
"Following Jeb's suggeston in a comment, I created a custom template tag.\nI replaced {{ forloop.counter }} with {% counter %}, a tag that simply prints how many times it's been called.\nHere's the code for my counter tag. \nclass CounterNode(template.Node):\n\n def __init__(self):\n self.count = 0\n\n def ren... | [
4,
1
] | [
"I think you can use forloop.parentloop.counter inside of the inner loop to achieve the numbering you're after.\n",
"You could just use an ordered list instead of unordered:\n{% regroup articles by section as articles_by_section %}\n\n<ol>\n{% for article in articles_by_section %} \n <h4>{{ article.grou... | [
-1,
-1
] | [
"django",
"django_templates",
"python"
] | stackoverflow_0000290397_django_django_templates_python.txt |
Q:
python, set terminal type in pexpect
I have a script which uses pexpect to start a CLI program. It works a bit like a shell where you get a prompt where you can enter some commands.
The problem I have, I think, is that this program uses a coloured prompt.
This is what I do
import pprint
import pexpect
1 a = pexp... | python, set terminal type in pexpect | I have a script which uses pexpect to start a CLI program. It works a bit like a shell where you get a prompt where you can enter some commands.
The problem I have, I think, is that this program uses a coloured prompt.
This is what I do
import pprint
import pexpect
1 a = pexpect.spawn('program')
2 a.expect("prompt>")... | [
"Ok, I found the answer. csl's answer set me on the right path.\npexpect has a \"env\" option which I thought I could use. like this:\na = pexpect.spawn('program', env = {\"TERM\": \"dumb\"})\n\nBut this spawns a new shell which does not work for me, our development environment \ndepends on a lot of environmental v... | [
8,
2
] | [] | [] | [
"pexpect",
"python"
] | stackoverflow_0000358783_pexpect_python.txt |
Q:
Comparing List of Arguments to it self?
Kind of a weird question, but. I need to have a list of strings i need to make sure that every string in that list is the same.
E.g:
a = ['foo', 'foo', 'boo'] #not valid
b = ['foo', 'foo', 'foo'] #valid
Whats the best way to go about doing that?
FYI, i don't know how many s... | Comparing List of Arguments to it self? | Kind of a weird question, but. I need to have a list of strings i need to make sure that every string in that list is the same.
E.g:
a = ['foo', 'foo', 'boo'] #not valid
b = ['foo', 'foo', 'foo'] #valid
Whats the best way to go about doing that?
FYI, i don't know how many strings are going to be in the list. Also this... | [
"Use list.count to get the number of items in a list that match a value. If that number doesn't match the number of items, you know they aren't all the same.\nif a.count( \"foo\" ) != len(a)\n\nWhich would look like...\nif a.count( a[0] ) != len(a)\n\n...in production code.\n",
"Perhaps\nall(a[0] == x for x in a... | [
5,
5,
3,
2,
1,
0,
0
] | [] | [] | [
"python"
] | stackoverflow_0000359903_python.txt |
Q:
Keeping a variable around from post to get?
I have a class called myClass which defines post() and get() methods.
From index.html, I have a form with an action that calls myClass.post() which grabs some data from the data base, sets a couple variables and sends the user to new.html.
now, new.html has a form whic... | Keeping a variable around from post to get? | I have a class called myClass which defines post() and get() methods.
From index.html, I have a form with an action that calls myClass.post() which grabs some data from the data base, sets a couple variables and sends the user to new.html.
now, new.html has a form which calls myClass.get().
I want the get() method t... | [
"What you're talking about is establishing a \"session\". That is, a way to remember the user and the state of their transaction.\nThere are several ways of tackling this, all of which rely on techniques for remembering that you're in a session in the first place.\nHTTP provides you no help. You have to find some... | [
3,
1,
1,
0,
0,
0
] | [] | [] | [
"get",
"google_app_engine",
"post",
"python"
] | stackoverflow_0000358398_get_google_app_engine_post_python.txt |
Q:
Split HTML after N words in python
Is there any way to split a long string of HTML after N words? Obviously I could use:
' '.join(foo.split(' ')[:n])
to get the first n words of a plain text string, but that might split in the middle of an html tag, and won't produce valid html because it won't close the tags tha... | Split HTML after N words in python | Is there any way to split a long string of HTML after N words? Obviously I could use:
' '.join(foo.split(' ')[:n])
to get the first n words of a plain text string, but that might split in the middle of an html tag, and won't produce valid html because it won't close the tags that have been opened.
I need to do this in... | [
"Take a look at the truncate_html_words function in django.utils.text. Even if you aren't using Django, the code there does exactly what you want.\n",
"I've heard that Beautiful Soup is very good at parsing html. It will probably be able to help you get correct html out.\n",
"I was going to mention the base H... | [
6,
3,
0,
0
] | [] | [] | [
"html",
"plone",
"python",
"zope"
] | stackoverflow_0000360036_html_plone_python_zope.txt |
Q:
Regular Expressions in unicode strings
I have some unicode text that I want to clean up using regular expressions. For example I have cases where u'(2'. This exists because for formatting reasons the closing paren ends up in an adjacent html cell. My initial solution to this problem was to look ahead at the con... | Regular Expressions in unicode strings | I have some unicode text that I want to clean up using regular expressions. For example I have cases where u'(2'. This exists because for formatting reasons the closing paren ends up in an adjacent html cell. My initial solution to this problem was to look ahead at the contents of the next cell and using a string fu... | [
"Okay sorry for using this a a stream of consciousness thinking stimulator but it appears that writing out my original question got me on the path. It seems to me that this is a solution for what I am trying to do:\n missingParen=re.compile(r\"^\\(\\d$\")\n\n"
] | [
1
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0000360600_python_regex.txt |
Q:
Access CVS through Apache service using SSPI
I'm running an Apache server (v2.2.10) with mod_python, Python 2.5 and Django. I have a small web app that will show the current projects we have in CVS and allow users to make a build of the different projects (the build checks out the project, and copies certain file... | Access CVS through Apache service using SSPI | I'm running an Apache server (v2.2.10) with mod_python, Python 2.5 and Django. I have a small web app that will show the current projects we have in CVS and allow users to make a build of the different projects (the build checks out the project, and copies certain files over with the source stripped out).
On the Djang... | [
"Usage of SSPI make me think you are using CVSNT, thus a Windows system; what is the user you are running Apache into? Default user for services is SYSTEM, which does not share the same registry as your current user.\n"
] | [
0
] | [] | [] | [
"apache",
"cvs",
"python",
"sspi"
] | stackoverflow_0000360911_apache_cvs_python_sspi.txt |
Q:
What GUI toolkit looks best for a native LAF for Python in Windows and Linux?
I need to decide on a GUI/Widget toolkit to use with Python for a new project. The target platforms will be Linux with KDE and Windows XP (and probably Vista). What Python GUI toolkit looks best and consistent with the native look and fe... | What GUI toolkit looks best for a native LAF for Python in Windows and Linux? | I need to decide on a GUI/Widget toolkit to use with Python for a new project. The target platforms will be Linux with KDE and Windows XP (and probably Vista). What Python GUI toolkit looks best and consistent with the native look and feel of the run time platform?
If possible, cite strengths and weaknesses of the sugg... | [
"Python binding of Wx is very strong since at least one of the core developer is a python guy itself. WxWdgets is robust, time proven stable, mature, but also bit more than just GUI. Even is a lot is left out in WxPython - because Python itself offers that already - you might find that extra convenient for your pro... | [
8,
2,
0
] | [] | [] | [
"gui_toolkit",
"linux",
"native",
"python",
"windows"
] | stackoverflow_0000360602_gui_toolkit_linux_native_python_windows.txt |
Q:
Techniques for data comparison between different schemas
Are there techniques for comparing the same data stored in different schemas? The situation is something like this. If I have a db with schema A and it stores data for a feature in say, 5 tables. Schema A -> Schema B is done during an upgrade process. During... | Techniques for data comparison between different schemas | Are there techniques for comparing the same data stored in different schemas? The situation is something like this. If I have a db with schema A and it stores data for a feature in say, 5 tables. Schema A -> Schema B is done during an upgrade process. During the upgrade process some transformation logic is applied and ... | [
"Make \"views\" on both the schemas that translate to the same buisness representation of data. Export these views to flat files and then you can use any plain vanilla file diff utility to compare and point out differences. \n",
"Basically, you should create object representations for both schema versions, and th... | [
2,
1,
0
] | [] | [] | [
"database",
"python",
"sql"
] | stackoverflow_0000361945_database_python_sql.txt |
Q:
Python: Finding partial string matches in a large corpus of strings
I'm interested in implementing autocomplete in Python. For example, as the user types in a string, I'd like to show the subset of files on disk whose names start with that string.
What's an efficient algorithm for finding strings that match some ... | Python: Finding partial string matches in a large corpus of strings | I'm interested in implementing autocomplete in Python. For example, as the user types in a string, I'd like to show the subset of files on disk whose names start with that string.
What's an efficient algorithm for finding strings that match some condition in a large corpus (say a few hundred thousand strings)? Somethi... | [
"For exact matching, generally the way to implement something like this is to store your corpus in a trie. The idea is that you store each letter as a node in the tree, linking to the next letter in a word. Finding the matches is simply walking the tree, and showing all children of your current location. eg. \"c... | [
7,
3,
1,
0,
0
] | [] | [] | [
"python",
"search"
] | stackoverflow_0000362231_python_search.txt |
Q:
mssql handles line returns rather awkwardly
Here is the problem:
for your reference:
database entries 1,2 and 3 are made using jython 2.2.1 using jdbc1.2.
database entry 4 is made using vb the old to be replace program using odbc.
We have found that if I copy and paste both jython and vb MailBody entries to word... | mssql handles line returns rather awkwardly | Here is the problem:
for your reference:
database entries 1,2 and 3 are made using jython 2.2.1 using jdbc1.2.
database entry 4 is made using vb the old to be replace program using odbc.
We have found that if I copy and paste both jython and vb MailBody entries to wordpad directly from that SQL Server Enterprise Mana... | [
"I suggest to add a debug output to your program, dumping character codes before insertion in DB. There are chances that Jython replace CrLf pair with single character and doesn't restore it when written to DB.\n",
"You should look at the quopri module (and others regarding email) so you don't have to use dirty t... | [
1,
1
] | [] | [] | [
"formatting",
"java",
"jython",
"python",
"sql_server"
] | stackoverflow_0000355135_formatting_java_jython_python_sql_server.txt |
Q:
Python Canvas library for geometric shapes
I'm looking for a Python library for creating canvases for manipulating geometric shapes. Specifically I need the ability to create arbitrary polygons and place them on the canvas, the polygons need to have the ability to be transparent/have an alpha channel, I need to be... | Python Canvas library for geometric shapes | I'm looking for a Python library for creating canvases for manipulating geometric shapes. Specifically I need the ability to create arbitrary polygons and place them on the canvas, the polygons need to have the ability to be transparent/have an alpha channel, I need to be able to edit polygons that are currently on the... | [
"I think cairo will do a lot of what you want. They have python bindings, too.\nThe one requirement that that won't help you with is modifying previously-drawn polygons, but I don't know of any canvas that will do that for you. \n",
"Sounds like a job for OpenGL.\nMy advice is that, whichever library you choose, ... | [
5,
2,
2,
1,
1,
1,
0,
0
] | [] | [] | [
"algorithm",
"canvas",
"drawing",
"python"
] | stackoverflow_0000361889_algorithm_canvas_drawing_python.txt |
Q:
How to script an OLE component using Python
I would like to use Python to script an application that advertises itself as providing an OLE component. How should I get started?
I don't yet know what methods I need to call on the COMponents I will be accessing. Should I use win32com to load those components, and the... | How to script an OLE component using Python | I would like to use Python to script an application that advertises itself as providing an OLE component. How should I get started?
I don't yet know what methods I need to call on the COMponents I will be accessing. Should I use win32com to load those components, and then start pressing 'tab' in IPython?
| [
"\"Python and COM\" contains an example. OLE is related to COM and ActiveX so you should look for those terms. \n\"Python Programming on Win32\" is a useful book. There is also a \"Python Win32\" mailing list.\n",
"You need the win32com package. Some examples:\nfrom win32com.client.dynamic import Dispatch\n\n# Ex... | [
3,
2,
2,
0,
0
] | [] | [] | [
"activex",
"ole",
"python",
"scripting",
"windows"
] | stackoverflow_0000279094_activex_ole_python_scripting_windows.txt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.