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:
Nested memcache lookups in Python, o(n) good/bad?
Is something like this bad with memcache?
1. GET LIST OF KEYS
2. FOR EACH KEY IN LIST OF KEYS
- GET DATA
I'm expecting the list of keys to be around ~1000 long.
If this is bad, I'm wondering if there is a better way to do this? I figured memcache might be fast... | Nested memcache lookups in Python, o(n) good/bad? | Is something like this bad with memcache?
1. GET LIST OF KEYS
2. FOR EACH KEY IN LIST OF KEYS
- GET DATA
I'm expecting the list of keys to be around ~1000 long.
If this is bad, I'm wondering if there is a better way to do this? I figured memcache might be fast enough where such an O(n) query might not be so import... | [
"This will be slower than it needs to be, because each request will wait for the previous one to complete before being sent. If there's any latency at all to the memcache server, this will add up quickly: if there's just 100uS of latency (a typical Ethernet round-trip time), these 1000 lookups will take a tenth of... | [
2
] | [] | [] | [
"memcached",
"memcachedb",
"python"
] | stackoverflow_0004001052_memcached_memcachedb_python.txt |
Q:
What's the fastest way to remove duplicate lines in a txt file(and also some lines which contain specific strings) using python?
The txt is about 22,000 lines, and it's about 3.5MB. There are lots of duplicate lines in it. I simply want to remove the duplicate lines and also some lines which include specific strin... | What's the fastest way to remove duplicate lines in a txt file(and also some lines which contain specific strings) using python? | The txt is about 22,000 lines, and it's about 3.5MB. There are lots of duplicate lines in it. I simply want to remove the duplicate lines and also some lines which include specific strings not needed.
My way is to read the file into a big list using readlines() method, then read the file as a big string using read() m... | [
"list(set(line for line in file.readlines()\n if 'badstring' not in line\n and 'garbage' not in line))\n\nAlso, a regex might be faster than multiple not in tests. \n",
"I almost always do file processing using generators. This makes for code that's fast, easy to modify, and easy to test.\nFirst,... | [
3,
3,
0
] | [] | [] | [
"file",
"python"
] | stackoverflow_0003996535_file_python.txt |
Q:
Is there Python web application framework for creating desktop-like GUI end-to-end applications?
I mean that the user interface and the server logic are like one thing, and no html/js is used.
There is an excellent C++ web toolkit, which does exactly this:
http://www.webtoolkit.eu/wt
Is there python equivalent/alt... | Is there Python web application framework for creating desktop-like GUI end-to-end applications? | I mean that the user interface and the server logic are like one thing, and no html/js is used.
There is an excellent C++ web toolkit, which does exactly this:
http://www.webtoolkit.eu/wt
Is there python equivalent/alternative?
Note: pyjamas does not count - it's great, but client side only.
Thanks!
| [
"Nope, Wt is just about the only thing like that. The only thing remotely similar to Wt is ASP.NET, and that is a very long stretch. \n"
] | [
0
] | [] | [] | [
"python",
"user_interface"
] | stackoverflow_0004001324_python_user_interface.txt |
Q:
Can pygame use vector art?
http://cache.kotaku.com/assets/resources/2008/02/dbzburstcell.jpg
-edit- bassically just detailed vectorized 2d games.
When making a side scroller in pygame or any other comparable 2d framework with python, can you utilize graphics such as in the above link?
Thanks.
A:
You can always r... | Can pygame use vector art? | http://cache.kotaku.com/assets/resources/2008/02/dbzburstcell.jpg
-edit- bassically just detailed vectorized 2d games.
When making a side scroller in pygame or any other comparable 2d framework with python, can you utilize graphics such as in the above link?
Thanks.
| [
"You can always render your vectors to bitmaps with enough resolution and use the rendered version in the game, instead of rendering everything in runtime -- that seems to be what the game you linked above does.\nThat said, you could use cairo to render .svgs at runtime. There's even a tutorial available.\n"
] | [
4
] | [] | [] | [
"graphics",
"pygame",
"python"
] | stackoverflow_0004001340_graphics_pygame_python.txt |
Q:
How to initialize empty list?
Every time the input s comes from the form; the list is initialized again. How do I change the code to append each new s to the list?
Thank you.
class Test(webapp.RequestHandler):
def get(self):
s = self.request.get('sentence')
list = [] ... | How to initialize empty list? | Every time the input s comes from the form; the list is initialized again. How do I change the code to append each new s to the list?
Thank you.
class Test(webapp.RequestHandler):
def get(self):
s = self.request.get('sentence')
list = []
list.append(s) ... | [
"I'm not sure what the context of your code is, but this should work:\nclass Test(webapp.RequestHandler):\n def get(self):\n s = self.request.get('sentence')\n try:\n self.myList.append(s)\n except NameError:\n self.myList= [s]\n htmlcode1 = HTML.table(self.myLis... | [
6,
5
] | [] | [] | [
"python"
] | stackoverflow_0004001652_python.txt |
Q:
Python Regular Expression Matching ## ##
Possible Duplicate:
Python Regular Expression Matching: ## ##
I already asked this question, but let me restate it better... Im searching a file line by line for the occurrence of ##random_string##. It works except for the case of multiple #...
pattern='##(.*?)##'
prog=re... | Python Regular Expression Matching ## ## |
Possible Duplicate:
Python Regular Expression Matching: ## ##
I already asked this question, but let me restate it better... Im searching a file line by line for the occurrence of ##random_string##. It works except for the case of multiple #...
pattern='##(.*?)##'
prog=re.compile(pattern)
string='lala ###hey## ther... | [
"Your problem is with your inner match. You use ., which matches any character that isn't a line end, and that means it matches # as well. So when it gets ###hey##, it matches (.*?) to #hey.\nThe easy solution is to exclude the # character from the matchable set:\nprog = re.compile(r'##([^#]*)##')\n\nProtip: Use ... | [
1,
0,
0
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0004002131_python_regex.txt |
Q:
Python: Optimize this loop
a = [(1,2),(3,1),(4,4),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5)]
# Quite a lot tuples in the list, 6 digits~
# I want to split it into rows and columns.
rows = 5
cols = 5
Data structure is
rows and cols are the index for the bit list
[row... | Python: Optimize this loop | a = [(1,2),(3,1),(4,4),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5),(5,5)]
# Quite a lot tuples in the list, 6 digits~
# I want to split it into rows and columns.
rows = 5
cols = 5
Data structure is
rows and cols are the index for the bit list
[rows, cols, (data)]
I use loop to ... | [
"It's not at all clear to me what you want but here's a shot at the same loop in a more optimized manner:\nimport itertools as it\n\nindex = it.count(0) \nprocessed_data = [[h, w, a[next(index)]] \n for h in xrange(0, rows - 1)\n for w in xrange(0, cols - 1)]\n\nor, since you've alre... | [
2,
2,
0
] | [] | [] | [
"for_loop",
"python"
] | stackoverflow_0004002127_for_loop_python.txt |
Q:
Can I reliably figure out the correct mime type to serve untrusted content?
Say I let users upload files to my server, and I let users download them. I'd like to set the mime type to something other than just application/octet-stream, so that if the browser can just open them, it does (say, for images, pdf files,... | Can I reliably figure out the correct mime type to serve untrusted content? | Say I let users upload files to my server, and I let users download them. I'd like to set the mime type to something other than just application/octet-stream, so that if the browser can just open them, it does (say, for images, pdf files, plain text files, etc.) Of course, since the files are uploaded by users, I can... | [
"Try python-magic.\n",
"Beware of text files: there's no way of knowing what encoding they're in, and there's no reliable way of guessing, especially since most ones created in Windows are in 8-bit MBCS encodings which are indistinguishable without language heuristics. You need to know the encoding--not just the... | [
3,
1
] | [] | [] | [
"mime",
"mime_types",
"python",
"web_applications"
] | stackoverflow_0004002015_mime_mime_types_python_web_applications.txt |
Q:
How come when I use the tComment VIM plugin in a .ini file it adds/removes semi-colons instead of hashes as comment?
I am using gVIM and the tComment plug-in during editing the development.ini file in a Pylons/Python project. The default development.ini file has lines commented out using the hash # symbol which is... | How come when I use the tComment VIM plugin in a .ini file it adds/removes semi-colons instead of hashes as comment? | I am using gVIM and the tComment plug-in during editing the development.ini file in a Pylons/Python project. The default development.ini file has lines commented out using the hash # symbol which is the standard method of commenting out lines in Python. However, when I try to uncomment lines by using a tComment keyboar... | [
"In the tcomment.vim file in your autoload directory you should find a list like this:\ncall tcomment#DefineType('aap', '# %s' )\ncall tcomment#DefineType('ada', '-- %s' )\ncall tcomment#DefineType('apache', '# %s' )\n\nIn there you'll find this... | [
10
] | [] | [] | [
"comments",
"ini",
"pylons",
"python",
"vim"
] | stackoverflow_0004002018_comments_ini_pylons_python_vim.txt |
Q:
Measuring internet data transfers
Is there any way in python for S60 (using the python 2.5.4 codebase) to track the amount of data transferred over the mobile device's internet connection?
A:
Symbian C++ API has such a capability, so it is possible to write a python library for that, but if such already exists, ... | Measuring internet data transfers | Is there any way in python for S60 (using the python 2.5.4 codebase) to track the amount of data transferred over the mobile device's internet connection?
| [
"Symbian C++ API has such a capability, so it is possible to write a python library for that, but if such already exists, that I do not know...\nBR\nSTeN\n"
] | [
2
] | [] | [] | [
"pys60",
"python",
"symbian"
] | stackoverflow_0003928685_pys60_python_symbian.txt |
Q:
Django or Ruby on Rails - user extensions, plugins
Which framework has the most mature, flexible, intergrated, centralized and easy-to-use plugins/extension system.
My main requirements are:
a centralized system/repository where i could find a extension i need
no need to make changes in the source code, the plug... | Django or Ruby on Rails - user extensions, plugins | Which framework has the most mature, flexible, intergrated, centralized and easy-to-use plugins/extension system.
My main requirements are:
a centralized system/repository where i could find a extension i need
no need to make changes in the source code, the plugin should be easily enabled and disabled
large plugin/e... | [
"I can't speak for Django, but I can tell you about Rails' open source community. GitHub is the central location for all Rails open source code.\nMost ruby libraries/plugins these days are packaged as \"gems\", which are easy to install, update, and remove. RubyGems is the place to go for these pre-packaged gems,... | [
4,
1,
0
] | [] | [] | [
"django",
"python",
"ruby",
"ruby_on_rails"
] | stackoverflow_0003999234_django_python_ruby_ruby_on_rails.txt |
Q:
How to get the previous element when using a for loop?
Possible Duplicates:
Python - Previous and next values inside a loop
python for loop, how to find next value(object)?
I've got a list that contains a lot of elements, I iterate over the list using a for loop. For example:
li = [2, 31, 321, 41, 3423, 4, 234, ... | How to get the previous element when using a for loop? |
Possible Duplicates:
Python - Previous and next values inside a loop
python for loop, how to find next value(object)?
I've got a list that contains a lot of elements, I iterate over the list using a for loop. For example:
li = [2, 31, 321, 41, 3423, 4, 234, 24, 32, 42, 3, 24, 31, 123]
for i in li:
print(i)
But... | [
"You can use zip:\nfor previous, current in zip(li, li[1:]):\n print(previous, current)\n\nor, if you need to do something a little fancier, because creating a list or taking a slice of li would be inefficient, use the pairwise recipe from itertools\nimport itertools\n\ndef pairwise(iterable):\n \"s -> (s0,s1... | [
39,
24,
24,
9,
3,
2
] | [
"li = [2,31,321,41,3423,4,234,24,32,42,3,24,,31,123]\n\ncounter = 0\nfor l in li:\n print l\n print li[counter-1] #Will return last element in list during first iteration as martineau points out.\n counter+=1\n\n"
] | [
-3
] | [
"for_loop",
"list",
"python"
] | stackoverflow_0004002598_for_loop_list_python.txt |
Q:
Handling dates prior to 1970 in a repeatable way in MySQL and Python
In my MySQL database I have dates going back to the mid 1700s which I need to convert somehow to ints in a format similar to Unix time. The value of the int isn't important, so long as I can take a date from either my database or from user input ... | Handling dates prior to 1970 in a repeatable way in MySQL and Python | In my MySQL database I have dates going back to the mid 1700s which I need to convert somehow to ints in a format similar to Unix time. The value of the int isn't important, so long as I can take a date from either my database or from user input and generate the same int. I need to use MySQL to generate the int on the ... | [
"I don't have MySQL here installed, but when I look here: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_to-days - I see an example TO_DAYS('2008-10-07') returning 733687.\nThe following Python function returns datetime(2008,10,7).toordinal() = 733322, which is 365 less than the MySQL... | [
2,
2
] | [] | [] | [
"epoch",
"mysql",
"python",
"sphinx"
] | stackoverflow_0004002660_epoch_mysql_python_sphinx.txt |
Q:
Python Simulation: Total Website Traffic Qty Estimation using Personas Segments
I need to estimate future website traffic & conversion volume based on:
1) Baseline historical averages for 6 differing types of traffic segments
2) How each of those distinct visitor segments interacts with 5 unique content groups
A... | Python Simulation: Total Website Traffic Qty Estimation using Personas Segments | I need to estimate future website traffic & conversion volume based on:
1) Baseline historical averages for 6 differing types of traffic segments
2) How each of those distinct visitor segments interacts with 5 unique content groups
After searching the internet I've concluded modules exist that can easily be
adapted t... | [
"I'm not an expert in simulating of website traffic, but maybe you can use some Monte Carlo simulation to create a statistical representation of real traffic they have on the test site.\nExcuse the lack of particulars, and the first idea of what appeared to me, not tested. I'm not sure that I understood your proble... | [
0
] | [] | [] | [
"python",
"simulation",
"traffic"
] | stackoverflow_0004002427_python_simulation_traffic.txt |
Q:
Can a program call itself?
I have a Python program that runs a cell model continuously. when I press "A" or "B" certain functions are called - cell divide, etc. when the "esc" key is pressed the simulation exits. Is there a way for the program to exit and then restart itself when "esc" is pressed?
A:
Yes. Thi... | Can a program call itself? | I have a Python program that runs a cell model continuously. when I press "A" or "B" certain functions are called - cell divide, etc. when the "esc" key is pressed the simulation exits. Is there a way for the program to exit and then restart itself when "esc" is pressed?
| [
"Yes. This is probably what you want\nThe-Evil-MacBook:~ ivucica$ cat test.py\n#!/usr/bin/env python\nimport sys\nimport os\nprint sys.argv[0] + \" with argcount \" + str(len(sys.argv))\nif len(sys.argv) < 2 or sys.argv[1] != \"2\":\n print \"doing recursion\"\n os.system(sys.argv[0] + \" 2\");\nelse:\n pr... | [
2,
0
] | [] | [] | [
"command_line",
"linux",
"python"
] | stackoverflow_0004003104_command_line_linux_python.txt |
Q:
How can I change the cursor image in python soya?
Soya is a 3D game framework for python.
How can I change the cursor image to/from a different image?
A:
Not sure but,
dir() function is your friend. Use it see what methods and attributes are available for "Cursor" class.
From the look of it, it doesn't have one.... | How can I change the cursor image in python soya? | Soya is a 3D game framework for python.
How can I change the cursor image to/from a different image?
| [
"Not sure but,\ndir() function is your friend. Use it see what methods and attributes are available for \"Cursor\" class.\nFrom the look of it, it doesn't have one. How ever the parent class allows you to set a shape.\n\nhttp://home.gna.org/soya/soya.cursor.html \n\nThis class is derived from soya.Volume \n\nhttp:/... | [
0
] | [] | [] | [
"opengl",
"python",
"sdl"
] | stackoverflow_0004003122_opengl_python_sdl.txt |
Q:
Pyqt save dom to file
Why this code does not work ?
I want save dom after js execute at this page and i want use qt without gui.
Sorry for my English.
#coding:utf-8
from PyQt4 import QtCore, QtWebKit
class Sp():
def save(self):
print "call"
data = self.webView.page().currentFrame().documentEle... | Pyqt save dom to file | Why this code does not work ?
I want save dom after js execute at this page and i want use qt without gui.
Sorry for my English.
#coding:utf-8
from PyQt4 import QtCore, QtWebKit
class Sp():
def save(self):
print "call"
data = self.webView.page().currentFrame().documentElement().toInnerXml()
... | [
"You have to create a QApplication before executing other stuff.\nAdd this:\nimport sys\nfrom PyQt4 import QtGui\n\napp = QtGui.QApplication(sys.argv)\ns = Sp()\ns.main()\nsys.exit(app.exec_())\n\nUPDATED: Also, change the code, because QWebPage doesn't have a load method:\nimport sys\nfrom PyQt4 import QtGui, QtCo... | [
2
] | [] | [] | [
"pyqt4",
"python",
"qt",
"qwebpage"
] | stackoverflow_0004003416_pyqt4_python_qt_qwebpage.txt |
Q:
Translate `thread.start_new_thread(...)` to the new threading API
When I use the old Python thread API everything works fine:
thread.start_new_thread(main_func, args, kwargs)
But if I try to use the new threading API the process, which runs the thread hangs when it should exit itself with sys.exit(3):
threading.T... | Translate `thread.start_new_thread(...)` to the new threading API | When I use the old Python thread API everything works fine:
thread.start_new_thread(main_func, args, kwargs)
But if I try to use the new threading API the process, which runs the thread hangs when it should exit itself with sys.exit(3):
threading.Thread(target=main_func, args=args, kwargs=kwargs).start()
How can I tr... | [
"This behavior is due to the fact that thread.start_new_thread creates a thread in daemon mode while threading.Thread creates a thread in non-daemon mode.\nTo start threading.Thread in daemon mode, you need to use .setDaemon method:\nmy_thread = threading.Thread(target=main_func, args=args, kwargs=kwargs)\nmy_threa... | [
8,
2
] | [] | [] | [
"multithreading",
"python"
] | stackoverflow_0004003783_multithreading_python.txt |
Q:
Django Model Inheritance And Foreign Keys
Basically, I have a model where I've created a superclass that many other classes share, and then each of those classes has some unique features that differ from each other. Let's say class A is the superclass, and class B, C, and D are children of that class.
Both class B... | Django Model Inheritance And Foreign Keys | Basically, I have a model where I've created a superclass that many other classes share, and then each of those classes has some unique features that differ from each other. Let's say class A is the superclass, and class B, C, and D are children of that class.
Both class B and class C can have multiples of class D, how... | [
"One way to do this is to add an intermediate class as follows:\nclass A(Model):\n class Meta(Model.Meta):\n abstract = True\n # common definitions here\n\nclass Target(A):\n # this is the target for links from D - you then need to access the \n # subclass through \".b\" or \".c\"\n # (no fiel... | [
5,
4,
3,
2
] | [] | [] | [
"django",
"django_models",
"foreign_keys",
"inheritance",
"python"
] | stackoverflow_0001114767_django_django_models_foreign_keys_inheritance_python.txt |
Q:
How to change Selection Colour for selected items in wxpython's CustomTreeCtrl
I am using wxpython's CustumTreeCtrl. Since some of the items in my tree-hierarchy are supposed to have different textcolours it would useful if these items also keep their textcolours when selected. However, when an item is selected th... | How to change Selection Colour for selected items in wxpython's CustomTreeCtrl | I am using wxpython's CustumTreeCtrl. Since some of the items in my tree-hierarchy are supposed to have different textcolours it would useful if these items also keep their textcolours when selected. However, when an item is selected the background colour is automatically changed to blue (that can be controlled with Se... | [
"Are you on a Mac? I found this code in the (extremely long...) PaintItem method:\n if wx.Platform == \"__WXMAC__\" and item.IsSelected() and self._hasFocus:\n dc.SetTextForeground(wx.WHITE)\n dc.DrawLabel(item.GetText(), textrect)\n\nI couldn't be sure for other platforms, but it appears t... | [
0,
0
] | [] | [] | [
"python",
"wxpython"
] | stackoverflow_0003992868_python_wxpython.txt |
Q:
non-destructive version of pop() for a dictionary
Is there any idiom for getting an arbitrary key, value pair from a dictionary without removing them? (P3K)
EDIT:
Sorry for the confusing wording.
I used the word arbitrary in the sense that I don't care about what I'm getting.
It's different from random, where I do... | non-destructive version of pop() for a dictionary | Is there any idiom for getting an arbitrary key, value pair from a dictionary without removing them? (P3K)
EDIT:
Sorry for the confusing wording.
I used the word arbitrary in the sense that I don't care about what I'm getting.
It's different from random, where I do care about what I'm getting (i.e., I need probabilitie... | [
"k, v = next(iter(d.items())) # updated for Python 3\n\n"
] | [
5
] | [
"pop is supposed to remove a item. Isn't that the meaning of that method?\nIf you want to get random key , value pair use pseudo random module\n>>> import random\n>>> x = {1:3, 4:5, 6:7}\n>>> x = {1:3, 4:5, 6:7, 'a':9, 'z':'x'}\n>>> k = random.choice(x.keys())\n>>> x[k]\n7\n>>> \n\n",
"The items() method returns ... | [
-1,
-1,
-2,
-3
] | [
"dictionary",
"python",
"python_3.x"
] | stackoverflow_0004002874_dictionary_python_python_3.x.txt |
Q:
text with unicode escape sequences to unicode in python
suppose I have the string
test
'\\u0259'
Note the escaped backslash.
How do I convert it to the respective unicode string?
A:
>>> print('test \\u0259'.decode('unicode-escape'))
test ə
| text with unicode escape sequences to unicode in python | suppose I have the string
test
'\\u0259'
Note the escaped backslash.
How do I convert it to the respective unicode string?
| [
">>> print('test \\\\u0259'.decode('unicode-escape'))\ntest ə\n\n"
] | [
38
] | [] | [] | [
"python",
"unicode"
] | stackoverflow_0004004431_python_unicode.txt |
Q:
How to remove the last element in each list in a list
I've got a list like:
alist = [[a,b,(1,2)], [a,b,(1,2)], [a,b,(1,2)]]
I want to remove the last element from all the elements in a list. So the result will be:
alist = [[a,b], [a,b], [a,b]]
Is there a fast way to do this?
A:
You could use list comprehension... | How to remove the last element in each list in a list | I've got a list like:
alist = [[a,b,(1,2)], [a,b,(1,2)], [a,b,(1,2)]]
I want to remove the last element from all the elements in a list. So the result will be:
alist = [[a,b], [a,b], [a,b]]
Is there a fast way to do this?
| [
"You could use list comprehension to create a new list that removes the last element.\n>>> alist = [[1,2,(3,4)],[5,6,(7,8)],[9,10,(11,12)]]\n>>> [x[:-1] for x in alist] # <-------------\n[[1, 2], [5, 6], [9, 10]]\n\nHowever, if you want efficiency you could modify the list in-place:\n>>> alist = [[1,2,(3,4)],... | [
12
] | [
"This is basic Python stuff. You should be able to do it after reading the Python tutorial\n>>> alist = [[1,2,(3,4)],[5,6,(7,8)],[9,10,(11,12)]]\n>>> for li in alist:\n... print li[0:2]\n...\n[1, 2]\n[5, 6]\n[9, 10]\n>>>\n\nLater on, you can go to intermediate stuff like list comprehension etc\n"
] | [
-2
] | [
"list",
"python"
] | stackoverflow_0004004447_list_python.txt |
Q:
Replacing whitespaces within list elements
I have a list of tags:
>>> tags_list
['tag1', 'second tag', 'third longer tag']
How can I replace whitespaces within each element of the list with "+" ? I was trying to do this with regular expressions but each string remains unchanged:
for tag in tags_list:
re.sub("... | Replacing whitespaces within list elements | I have a list of tags:
>>> tags_list
['tag1', 'second tag', 'third longer tag']
How can I replace whitespaces within each element of the list with "+" ? I was trying to do this with regular expressions but each string remains unchanged:
for tag in tags_list:
re.sub("\s+" , " ", tag)
What is wrong with my approach... | [
"re.sub() returns a new string, it does not modify its parameter in-place.\nYou probably want:\ntags_list = [re.sub(r\"\\s+\", \"+\", tag) for tag in tags_list]\n\nAlso, don't forget the r before the regex or you'll have to double all the backslashes inside (i.e. the regex you posted won't work).\nEDIT: I assume re... | [
6,
2,
0
] | [] | [] | [
"python",
"regex",
"replace",
"string",
"whitespace"
] | stackoverflow_0004004349_python_regex_replace_string_whitespace.txt |
Q:
Converting string series to float list in python
I am quite new to programing so I hope this question is simple enough.
I need to know how to convert a string input of numbers separated by spaces on a single line:
5.2 5.6 5.3
and convert this to a float list
lsit = [5.2,5.6,5.3]
How can this be done?
A:
Try a ... | Converting string series to float list in python | I am quite new to programing so I hope this question is simple enough.
I need to know how to convert a string input of numbers separated by spaces on a single line:
5.2 5.6 5.3
and convert this to a float list
lsit = [5.2,5.6,5.3]
How can this be done?
| [
"Try a list comprehension:\ns = '5.2 5.6 5.3'\nfloats = [float(x) for x in s.split()]\n\nIn Python 2.x it can also be done with map:\nfloats = map(float, s.split())\n\nNote that in Python 3.x the second version returns a map object rather than a list. If you need a list you can convert it to a list with a call to l... | [
75
] | [] | [] | [
"python"
] | stackoverflow_0004004550_python.txt |
Q:
How can I distinguish lists from strings in django templates
I'm developing a project on Google AppEngine, using Django templates, so I have to use tags like {{ aitem.Author }} to print content within my HTML template.
Author, however, can either be a string or a list object, and I have no way to tell it in advanc... | How can I distinguish lists from strings in django templates | I'm developing a project on Google AppEngine, using Django templates, so I have to use tags like {{ aitem.Author }} to print content within my HTML template.
Author, however, can either be a string or a list object, and I have no way to tell it in advance. When the Author is a list and I try to print it on my template,... | [
"I think the cleanest solution would be to add a method to the model get_authors() which always returns a list either of one or more authors. Then you can use:\nAuthor: {{ aitem.get_authors|join:\", \" }}\n\nIf you for some reason have only access to the templates and can't change the model, then you can use a hack... | [
7,
1,
0
] | [] | [] | [
"django",
"django_templates",
"google_app_engine",
"python"
] | stackoverflow_0004001802_django_django_templates_google_app_engine_python.txt |
Q:
How to serialize XML document in python using xml.dom library
I'd like to know how I can serialize an XML document in python specifically using the xml.dom library.
A:
You mean something like:
xml.dom.ext.PrettyPrint(doc, open(name, "w"))
where doc is the XML document and name is the name of the file?
Or, if yo... | How to serialize XML document in python using xml.dom library | I'd like to know how I can serialize an XML document in python specifically using the xml.dom library.
| [
"You mean something like:\nxml.dom.ext.PrettyPrint(doc, open(name, \"w\"))\n\nwhere doc is the XML document and name is the name of the file?\nOr, if you have xml.dom.minidom, how about the xml.dom.minidom.writexml function?\n"
] | [
1
] | [] | [] | [
"dom",
"python",
"xml"
] | stackoverflow_0004004735_dom_python_xml.txt |
Q:
Python: how to know how many colors in a bounding box in PIL?
Hey, I've got so many PIL bounding box(x,y, x1,y1)
I just want to know how many colors are there in the bounding box, is there any fast way to do?
A:
>>> myimg = ...
>>> colors = myimg.crop((x0, y0, x1, y1)).getcolors()
According to PIL's docs getcol... | Python: how to know how many colors in a bounding box in PIL? | Hey, I've got so many PIL bounding box(x,y, x1,y1)
I just want to know how many colors are there in the bounding box, is there any fast way to do?
| [
">>> myimg = ...\n>>> colors = myimg.crop((x0, y0, x1, y1)).getcolors()\n\nAccording to PIL's docs getcolors \"Returns an unsorted list of (count, color) tuples, where the count is the number of times the corresponding color occurs in the image\".\n"
] | [
2
] | [] | [] | [
"bounding_box",
"python",
"python_imaging_library"
] | stackoverflow_0004004677_bounding_box_python_python_imaging_library.txt |
Q:
GUI-embeddable Python drawing widget with anti-aliasing
I am writing a small diagram drawing application (similar to Graphviz in spirit), and need a GUI library that would allow me to embed a canvas capable of drawing anti-aliased lines and text. I want to have a text editor in one half of the window to edit the d... | GUI-embeddable Python drawing widget with anti-aliasing | I am writing a small diagram drawing application (similar to Graphviz in spirit), and need a GUI library that would allow me to embed a canvas capable of drawing anti-aliased lines and text. I want to have a text editor in one half of the window to edit the diagram code and a (perhaps live) preview pane in the other.
R... | [
"If you don't mind the way GTK looks, pygtk has an option for antialising in their canvas widget (see this) and is considered by many to be as powerful as Tkinter, though it is not included in standard Python installs.\nAlso, it's Python 3.x compatible, which can't be said of most non-standard library modules and p... | [
2,
2,
2
] | [] | [] | [
"drawing",
"pygame",
"python",
"python_3.x",
"tkinter"
] | stackoverflow_0003999780_drawing_pygame_python_python_3.x_tkinter.txt |
Q:
GAE organizing data structure problem
Ok. I'm working with GAE. And i want create something like this:
I have types "group" "topic" "tag":
each "group" can have as many
"topics" as needed
each "topic" can have as many "tags"
as needed
each "group" can have as many "tags"
as needed
it's something like circle.
rig... | GAE organizing data structure problem | Ok. I'm working with GAE. And i want create something like this:
I have types "group" "topic" "tag":
each "group" can have as many
"topics" as needed
each "topic" can have as many "tags"
as needed
each "group" can have as many "tags"
as needed
it's something like circle.
right now i have something like this:
class To... | [
"Many-to-many joins can be implemented as join tables (or Relationship Models). In the solution below, there is a model that holds all of the tags that are applied to individual Groups (GroupTags) and a model that holds the tags that are applied to Topics (TopicTags).\nDecoupling the Tag itself from references to t... | [
5,
2
] | [] | [] | [
"database",
"google_app_engine",
"python"
] | stackoverflow_0004004770_database_google_app_engine_python.txt |
Q:
XML parser-writer that keeps Attributes order
I need to parse XML document and then write every node to separate files keeping exact order of attributes.
So if i have input file like :
<item a="a" b="b" c="c"/>
<item a="a1" b="b2" c="c3"/>
Output should be 2 files with every item.
Now if xml.dom.minidom is used... | XML parser-writer that keeps Attributes order | I need to parse XML document and then write every node to separate files keeping exact order of attributes.
So if i have input file like :
<item a="a" b="b" c="c"/>
<item a="a1" b="b2" c="c3"/>
Output should be 2 files with every item.
Now if xml.dom.minidom is used - attribute order is changed in output( i can get ... | [
"You might find this question useful. Bottom line summary-- standard xml tools and libraries most likely won't be able to do this.\n",
"You can use BeautifulSoup:\n>>> from BeautifulSoup import BeautifulSoup as soup\n\n>>> html = '''<item a=\"a\" b=\"b\" c=\"c\"/>\n<item a=\"a1\" b=\"b2\" c=\"c3\"/>'''\n>>> s = s... | [
1,
0
] | [] | [] | [
"python",
"xml"
] | stackoverflow_0004003643_python_xml.txt |
Q:
What is a good function to map an id to memcache in a pool of servers?
Something like:
host = getHost(id)
>>> 172.16.25.52
Ideally, the algorithm should minimize the number of cache misses when the pool of servers is expanded / contracted.
Are there any known algorithms out there that do this? Or libraries, po... | What is a good function to map an id to memcache in a pool of servers? | Something like:
host = getHost(id)
>>> 172.16.25.52
Ideally, the algorithm should minimize the number of cache misses when the pool of servers is expanded / contracted.
Are there any known algorithms out there that do this? Or libraries, potentially (I'm using Python).
Thank you.
| [
"The memcached library does this by default. So you can just read the code from the repository: http://bazaar.launchpad.net/~python-memcached-team/python-memcached/trunk/annotate/head%3A/memcache.py#L274\nAs for minimizing the cache misses with an expanding/contracting pool... a difficult thing to do. Either you're... | [
1
] | [] | [] | [
"memcached",
"python"
] | stackoverflow_0004004935_memcached_python.txt |
Q:
How to decode this YUV colorspace string and save it as an image
So I am using one third party library which is not very well documented. It has a method which takes a picture with camera and this is what it returns:
'E{\x7fM{\x7f;\x89\x89:\x89\x89=\x81\x87<\x81\x87O\x90\x7fJ\x90\x7fB\x87\x80I\x87\x80<{\x81={\x81A... | How to decode this YUV colorspace string and save it as an image | So I am using one third party library which is not very well documented. It has a method which takes a picture with camera and this is what it returns:
'E{\x7fM{\x7f;\x89\x89:\x89\x89=\x81\x87<\x81\x87O\x90\x7fJ\x90\x7fB\x87\x80I\x87\x80<{\x81={\x81A\x81\x82A\x81\x82E\x81\x81:\x81\x818\x80\x81?\x80\x81?\x8c\x85C\x8c\x8... | [
"The data looks to me like 4:4:4 YUV with the data samples interleaved rather than planar. Converting that to English, the bytes decode as \nY1 U1 V1 Y2 U2 V2 Y3 U3 V3 ...\nso the Y, U and V values of the first pixel, then of the second pixel, and so on.\nI'm guessing at that because of the good correllation betwee... | [
2
] | [] | [] | [
"python",
"yuv"
] | stackoverflow_0004004710_python_yuv.txt |
Q:
Restful communication between local applications is a good idea?
I wonder if it's a good idea letting local applications (in the same server) communicate with each other entirely through Restful API?
I know this is not an uncommon thing, cause we already have applications like CouchDB that is using HTTP REST for c... | Restful communication between local applications is a good idea? | I wonder if it's a good idea letting local applications (in the same server) communicate with each other entirely through Restful API?
I know this is not an uncommon thing, cause we already have applications like CouchDB that is using HTTP REST for communication, even with local applications.
But I want to take it to a... | [
"\nIs this a good idea? \n\nSure, perhaps.\n\nWill the data\ntransfer between them be slow? \n\nYup! But compared to what? Compared to native, internal calls, absolutely -- it'll be glacial. Compared to some other network API, eh, not necessarily slower.\n\nIf I\ndo this, then each application/module\nhave to be a ... | [
6,
5,
2,
0,
0
] | [] | [] | [
"javascript",
"node.js",
"python",
"rest",
"ruby"
] | stackoverflow_0004002545_javascript_node.js_python_rest_ruby.txt |
Q:
What does pynotify.init stand for?
I haven't find a documentation about pynotify, so I don't know what pynotify.init() function stands for.
A:
if you are talking about the python wrapper for libnotify
the notify.init() just wrap the C function notify_init() which initializes the notifications library.
For more ... | What does pynotify.init stand for? | I haven't find a documentation about pynotify, so I don't know what pynotify.init() function stands for.
| [
"if you are talking about the python wrapper for libnotify\nthe notify.init() just wrap the C function notify_init() which initializes the notifications library. \nFor more examples check this: http://roscidus.com/desktop/node/336\nthe code source is here : http://www.galago-project.org/downloads.php\nthe C API : h... | [
3
] | [] | [] | [
"pynotify",
"python"
] | stackoverflow_0004004971_pynotify_python.txt |
Q:
Django-Piston - I Can't POST on a model with a ForeignKey
I'm trying to set up piston on my Django project. I ran into a brick wall when I tried to POST (create) a new entry on a model that contains a ForeignKey: location.
Here is the exact error I receive:
Cannot assign "u'1'": "Fest.location" must be a "Locatio... | Django-Piston - I Can't POST on a model with a ForeignKey | I'm trying to set up piston on my Django project. I ran into a brick wall when I tried to POST (create) a new entry on a model that contains a ForeignKey: location.
Here is the exact error I receive:
Cannot assign "u'1'": "Fest.location" must be a "Location" instance.
In the above example, I tried to send over locati... | [
"You need to assign an actual object. Something like the following should work:\nloc = Location.objects.get(pk=1)\nobj.location = loc\nobj.save()\n\nwhere obj is the model you're trying to save which has location as a foreign key.\n"
] | [
2
] | [] | [] | [
"django",
"django_piston",
"python"
] | stackoverflow_0004005347_django_django_piston_python.txt |
Q:
Fast python tutorial for Django beginners?
Is there a FAST python tutorial for Django beginners?
A:
Google Python Class. It's a 2-day class providing written matrial, lecture videos and exercises.
A:
This is small tutorial and fasted paced
http://www.ibiblio.org/swaroopch/byteofpython/read/
I would suggest t... | Fast python tutorial for Django beginners? | Is there a FAST python tutorial for Django beginners?
| [
"Google Python Class. It's a 2-day class providing written matrial, lecture videos and exercises.\n",
"This is small tutorial and fasted paced\n\nhttp://www.ibiblio.org/swaroopch/byteofpython/read/\n\nI would suggest that you pick and choose the articles by Mertz from the \"Charming python\" columns\n\nhttp://gno... | [
4,
0
] | [] | [] | [
"django",
"python"
] | stackoverflow_0004005521_django_python.txt |
Q:
Ways to give a SQLite a variable name
I am tracking changes made to a levels in a game. The way I currently track changes is in a sqlite database. Each level is supposed to have its own database, as just one database for all the levels would provide complications when adding and deleting levels. So for each level,... | Ways to give a SQLite a variable name | I am tracking changes made to a levels in a game. The way I currently track changes is in a sqlite database. Each level is supposed to have its own database, as just one database for all the levels would provide complications when adding and deleting levels. So for each level, I want a database that has the same name a... | [
"You'll need to post some code for us to answer this completely.\nYou can use the ALTER TABLE command to rename the tables within your database, you can rename your sqlite db file on disk if you close it first, and you can use a variable in your python code to represent the name of the DB you're using. But you need... | [
0
] | [] | [] | [
"database",
"python",
"sqlite"
] | stackoverflow_0004005709_database_python_sqlite.txt |
Q:
web2py: Where should I store private, application-specific files?
I have just started working on web2py. Personally, I find it easier to learn than Django.
My query is that I have to load a file at application startup. Its a pickled hashtable. Where should I store this file so that the system is able to see it
My ... | web2py: Where should I store private, application-specific files? | I have just started working on web2py. Personally, I find it easier to learn than Django.
My query is that I have to load a file at application startup. Its a pickled hashtable. Where should I store this file so that the system is able to see it
My code is :
import cPickle as pickle
def index():
"""
Load the fi... | [
"I think the private folder would be a good place for this. You can get the absolute path with:\nimport os\nfp = os.path.join(request.folder,'private','tables.pkl') \n\nI would use cache instead of session if the file is not unique per user. \n"
] | [
4
] | [] | [] | [
"python",
"web2py"
] | stackoverflow_0004004794_python_web2py.txt |
Q:
Get CURRENT_FILE_ENCODING for a python file or environment
How can I tell the encoding of the source file from inside a running python process, if it is even possible?
A:
encoding = open(__file__).encoding
This might work in some circumstances, but take note of http://docs.python.org/library/stdtypes.html#file... | Get CURRENT_FILE_ENCODING for a python file or environment | How can I tell the encoding of the source file from inside a running python process, if it is even possible?
| [
"encoding = open(__file__).encoding\nThis might work in some circumstances, but take note of http://docs.python.org/library/stdtypes.html#file.encoding\n"
] | [
2
] | [
"If you examine __file__, it will give you the file name of the running code. If it ends in \".pyc\" or \".pyo\", clip off the last character. This is the source file of the running code. Read that file, looking for the encoding header.\nNote that this is a simplification, and it can get much harder to find the ... | [
-1
] | [
"encoding",
"python"
] | stackoverflow_0004005928_encoding_python.txt |
Q:
How to build a conceptual search engine?
I would like to build an internal search engine (I have a very large collection of thousands of XML files) that is able to map queries to concepts. For example, if I search for "big cats", I would want highly ranked results to return documents with "large cats" as well. B... | How to build a conceptual search engine? | I would like to build an internal search engine (I have a very large collection of thousands of XML files) that is able to map queries to concepts. For example, if I search for "big cats", I would want highly ranked results to return documents with "large cats" as well. But I may also be interested in having it retur... | [
"\nI'm not sure how to integrate that into a search engine. Could I use Lucene to do this? How?\n\nStep 1. Stop.\nStep 2. Get something to work.\nStep 3. By then, you'll understand more about Python and Lucene and other tools and ways you might integrate them.\nDon't start by trying to solve integration problems... | [
9,
1,
1,
0
] | [] | [] | [
"lsa",
"lucene",
"nlp",
"python",
"search"
] | stackoverflow_0004003840_lsa_lucene_nlp_python_search.txt |
Q:
Is possible to know the path of the file of a subclass in python?
I have a plugin system. The plugins subclass from a common ancestor... ad look like this:
-- SDK
--- basePlugin.py
-- PLUGINS
--- PluginA
---- Plugin.py
---- Config.ini
--- PluginB
---- Plugin.py
---- Config.ini
I need to read the info of Config.in... | Is possible to know the path of the file of a subclass in python? | I have a plugin system. The plugins subclass from a common ancestor... ad look like this:
-- SDK
--- basePlugin.py
-- PLUGINS
--- PluginA
---- Plugin.py
---- Config.ini
--- PluginB
---- Plugin.py
---- Config.ini
I need to read the info of Config.ini in basePlugin.py __init__. CUrrently in each plugin I do:
class Plugi... | [
"Assuming BaseSync is a new-style class, the parent class BaseSync could find the file that defines PluginA this way:\nimport sys\nclass BaseSync(object):\n def __init__(self):\n path=sys.modules[self.__module__].__file__\n\n(so you don't have to pass the path explicitly).\n"
] | [
26
] | [] | [] | [
"inheritance",
"plugins",
"python"
] | stackoverflow_0004006102_inheritance_plugins_python.txt |
Q:
How to choose 10 different integers from range (0, 99)
I want to choose 10 random integers from 0 to 99. I know I can use:
random.randint(a, b)
But how to tell the randint() that I only want different integers.
Do I have to just check after each random generation to see if the integer has already been generated a... | How to choose 10 different integers from range (0, 99) | I want to choose 10 random integers from 0 to 99. I know I can use:
random.randint(a, b)
But how to tell the randint() that I only want different integers.
Do I have to just check after each random generation to see if the integer has already been generated and call the method again? That does not seem like an optimal... | [
"from random import sample\n\nsample(range(0, 100), 10)\n\n",
"Here's general strategy that is language independent. Generate an array of 100 entries from 0 to 99. Choose a random number from 0 to 99 and swap the entry at that position with the element at position 0. Then successively choose a random number fro... | [
10,
8,
1,
0
] | [] | [] | [
"python"
] | stackoverflow_0004006054_python.txt |
Q:
python - 'str' object has no attribute 'execute'
First time python user here, be gentle.... ;-)
Python 2.6 on OSX
Got a class which just has some wrappers around sqlite... here it is
from pysqlite2 import dbapi2 as sqlite
class SqliteDB:
connection = ''
curser = ''
def connect(self):
try:
... | python - 'str' object has no attribute 'execute' | First time python user here, be gentle.... ;-)
Python 2.6 on OSX
Got a class which just has some wrappers around sqlite... here it is
from pysqlite2 import dbapi2 as sqlite
class SqliteDB:
connection = ''
curser = ''
def connect(self):
try:
self.connection = sqlite.connect("pagespeed.s... | [
"I don't know what's wrong, but at the very least:\ndb.connect \n\nshould be\ndb.connect()\n\ne.g. call the function.\nOK. S.Lott had the answer, I just found an other bug :)\n",
"Do Not Do This.\nclass SqliteDB:\n connection = ''\n curser = ''\n\nIt doesn't \"declare\" any variables. This isn't C++ or Ja... | [
7,
4,
1,
1
] | [] | [] | [
"python",
"sqlite"
] | stackoverflow_0004006257_python_sqlite.txt |
Q:
Is it possible to put strings in the copy buffer?
Preferentially using the standard libraries.
A:
Try googling "Python clipboard". There seem to be various solutions out there. Here's one called Pyperclip that claims to work across Windows/Mac/Linux
| Is it possible to put strings in the copy buffer? | Preferentially using the standard libraries.
| [
"Try googling \"Python clipboard\". There seem to be various solutions out there. Here's one called Pyperclip that claims to work across Windows/Mac/Linux\n"
] | [
2
] | [] | [] | [
"copy",
"copy_paste",
"python"
] | stackoverflow_0004006444_copy_copy_paste_python.txt |
Q:
Ignore last \n when using readlines with python
I have a file I read from that looks like:
1 value1
2 value2
3 value3
The file may or may not have a trailing \n in the last line.
The code I'm using works great, but if there is an trailing \n it fails.
Whats the best way to catch this?
My code for reference:... | Ignore last \n when using readlines with python | I have a file I read from that looks like:
1 value1
2 value2
3 value3
The file may or may not have a trailing \n in the last line.
The code I'm using works great, but if there is an trailing \n it fails.
Whats the best way to catch this?
My code for reference:
r=open(sys.argv[1], 'r');
for line in r.readlines():... | [
"You can ignore lines that contain only whitespace:\nfor line in r.readlines():\n line = line.rstrip() # Remove trailing whitespace.\n if line: # Only process non-empty lines.\n ref = line.split();\n print ref[0], ref[1]\n\n",
"I don't think that you have told us the whol... | [
8,
2
] | [] | [] | [
"python",
"readlines"
] | stackoverflow_0004006441_python_readlines.txt |
Q:
How to use the same variable in two classes
# I have this class:
class Test(webapp.RequestHandler):
myList = []
def get(self):
s = [self.request.get('sentence')]
self.myList.append(s)
htmlcode1 = HTML.table(self.myList)
myListLen = len(self.myList)
lastItem = self.m... | How to use the same variable in two classes | # I have this class:
class Test(webapp.RequestHandler):
myList = []
def get(self):
s = [self.request.get('sentence')]
self.myList.append(s)
htmlcode1 = HTML.table(self.myList)
myListLen = len(self.myList)
lastItem = self.myList[myListLen-2]
# I want to add the following... | [
"You would want to use\nTest.myList\n\nbecause myList is an attribute of the class, not a particular instance of that class.\n"
] | [
6
] | [] | [] | [
"python"
] | stackoverflow_0004006518_python.txt |
Q:
Best way to keep an activity log in memcached
I'd like to build a "feed" for recent activity related to a specific section of my site. I haven't used memcache before, but I'm thinking of something like this:
When a new piece of information is submitted to the site, assign a unique key to it and also add it to me... | Best way to keep an activity log in memcached | I'd like to build a "feed" for recent activity related to a specific section of my site. I haven't used memcache before, but I'm thinking of something like this:
When a new piece of information is submitted to the site, assign a unique key to it and also add it to memcache.
Add this key to the end of an existing list... | [
"If the list of keys is bounded in size then it should be ok. memcache by default has a 1MB item size limit.\nSounds like memcache is the only storage for the data, is it a good idea?\n"
] | [
0
] | [] | [] | [
"feed",
"memcached",
"python"
] | stackoverflow_0003999496_feed_memcached_python.txt |
Q:
How to get raw XML back from lxml?
I'm using the following code to locate a div:
parser = etree.HTMLParser()
tree = etree.parse(StringIO(page), parser)
div = tree.xpath("//div[@class='content']")[0]
My only problem is, that after doing this I do not want to rely on lxml to extract the contents of said div: I jus... | How to get raw XML back from lxml? | I'm using the following code to locate a div:
parser = etree.HTMLParser()
tree = etree.parse(StringIO(page), parser)
div = tree.xpath("//div[@class='content']")[0]
My only problem is, that after doing this I do not want to rely on lxml to extract the contents of said div: I just want to get back the raw XML the div c... | [
"I think you are looking for:\netree.tostring(div)\n\n",
"Did you try tostring?\nraw_xml = etree.tostring(div)\n\n"
] | [
14,
2
] | [] | [] | [
"html_parsing",
"lxml",
"python",
"xml"
] | stackoverflow_0004006668_html_parsing_lxml_python_xml.txt |
Q:
Find System Hard Disk Drive from Python?
I am working on a software installer for my current application. It needs to be installed to the System HDD. How owuld I detect the system drive and return the letter from Python?
Would the win32 extensions be useful? How about the os module pre packaged with Python?
A:
... | Find System Hard Disk Drive from Python? | I am working on a software installer for my current application. It needs to be installed to the System HDD. How owuld I detect the system drive and return the letter from Python?
Would the win32 extensions be useful? How about the os module pre packaged with Python?
| [
"This is how to return the letter of the System drive on a Win32 platform:\nimport os\nprint os.getenv(\"SystemDrive\")\n\nThe above snippet returns the system drive letter. In my case ( and most cases on windows) C:\n",
"If you install the win32 extensions, the following will get you the information you want:\nI... | [
16,
2
] | [] | [] | [
"disk",
"python",
"system",
"winapi"
] | stackoverflow_0004006730_disk_python_system_winapi.txt |
Q:
python re module - What regular expression to use to extract pieces of text
I have text which shows course numbers, names, grade and other information for courses taken by students. Specifically, the lines look like these:
0301 453 20071 LINEAR SYSTEMS I A 4 4 16.0
0301 481 20071 ELEC... | python re module - What regular expression to use to extract pieces of text | I have text which shows course numbers, names, grade and other information for courses taken by students. Specifically, the lines look like these:
0301 453 20071 LINEAR SYSTEMS I A 4 4 16.0
0301 481 20071 ELECTRONICS I WITH LAB A 4 4 16.0
0301 481 20084 ELECTRONICS I... | [
"If the layout is fixed as you show, then forget the regular expression, and just grab the columns you want:\ncourse_name = line[16:45].strip()\n\n",
"for line in open(\"file\"):\n s=filter(None,line.split(\" \",4))\n print s[3].replace(\" \",\"|\").split(\"|\",1)[0]\n\noutput\n$ python myscript.py\nLINEAR... | [
5,
2
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0004006798_python_regex.txt |
Q:
Python list manipulation
I've got a python list
alist = [ [0, 4, 5, 5], [2, 2, 4, 5], [6, 7, 8,13]], [ [3, 4, 5, 5], [2, 2, 4, 5], [6, 7, 8,999] ]
I need the result is
alist = [[0,4,8,13], [3, 4, 8, 999]]
It means first two and last two numbers in each alist element.
I need a fast way to do this as the list coul... | Python list manipulation | I've got a python list
alist = [ [0, 4, 5, 5], [2, 2, 4, 5], [6, 7, 8,13]], [ [3, 4, 5, 5], [2, 2, 4, 5], [6, 7, 8,999] ]
I need the result is
alist = [[0,4,8,13], [3, 4, 8, 999]]
It means first two and last two numbers in each alist element.
I need a fast way to do this as the list could be huge.
| [
"[x[0][:2] + x[-1][-2:] for x in alist]\n\n",
"The object is actually a tuple, rather than a list. This can trip you up if you're expecting it to be mutable and it's hard to read. Consider using the continuation character \\ for long lines:\nalist = [ [0, 4, 5, 5], [2, 2, 4, 5], [6, 7, 8,13]], [ [3, 4, 5, 5], [2,... | [
12,
1
] | [] | [] | [
"list",
"python"
] | stackoverflow_0004006794_list_python.txt |
Q:
how do I invoke jython from the python shell (ubuntu)
I like the python shell in ubuntu, it looks pretty, and I want to run jython from there. Can this be done somehow?
A:
Can't you just start a jython shell by typing jython?
Or are you trying to run ipython with jython? or do you want to run a jython program/sc... | how do I invoke jython from the python shell (ubuntu) | I like the python shell in ubuntu, it looks pretty, and I want to run jython from there. Can this be done somehow?
| [
"Can't you just start a jython shell by typing jython?\nOr are you trying to run ipython with jython? or do you want to run a jython program/script from an interactive python shell?\nP.S.\nPossibly\nimport subrocess \nf=subprocess.Popen(['jython', '/usr/share/jython/Lib/test/test_xml... | [
0
] | [] | [] | [
"jython",
"python",
"ubuntu"
] | stackoverflow_0004007009_jython_python_ubuntu.txt |
Q:
Using SoupStrainer to parse selectively
Im trying to parse a list of video game titles from a shopping site. however as the item list is all stored inside a tag .
This section of the documentation supposedly explains how to parse only part of the document but i cant work it out. my code:
from BeautifulSoup import ... | Using SoupStrainer to parse selectively | Im trying to parse a list of video game titles from a shopping site. however as the item list is all stored inside a tag .
This section of the documentation supposedly explains how to parse only part of the document but i cant work it out. my code:
from BeautifulSoup import BeautifulSoup
import urllib
import re
url = ... | [
"Oh boy am i silly, i was searching for tags with atribute id = products, but it should have been product_list\nheres the finaly code if anyone comes searching.\nfrom BeautifulSoup import BeautifulSoup, SoupStrainer\nimport urllib\nimport re\n\n\nstart = time.clock()\nurl = \"http://someplace.com\"\nhtml = urllib.u... | [
12,
0
] | [] | [] | [
"beautifulsoup",
"python",
"scrape"
] | stackoverflow_0004004979_beautifulsoup_python_scrape.txt |
Q:
How can I use a Perl module from Python?
There exists a Perl module that provides the perfect functionality for my Python app.
Is there any way for me to utilize it? (it is complicated, it would take me a month to port it)
I don't want to have to spawn a subprocess for every usage, as I need it several hundred th... | How can I use a Perl module from Python? | There exists a Perl module that provides the perfect functionality for my Python app.
Is there any way for me to utilize it? (it is complicated, it would take me a month to port it)
I don't want to have to spawn a subprocess for every usage, as I need it several hundred thousand times (it is a specific type of data pa... | [
"I am not sure if this is still active but PyPerl may be of interest to you\n\nhttp://wiki.python.org/moin/PyPerl\n\nStill there should be support for most data parsers in python. It would be good, if you can point to the parser that you are looking at.\nAlternatively, you could create a complete process with that ... | [
5,
4,
2
] | [
"\nI don't want to have to spawn a subprocess for every usage, as I need it several hundred thousand times (it is a specific type of data parser).\n\nBad policy. The basic Linux shells do this kind of process forking all the time. Avoiding process spawning is a bad limitation.\nHowever, you can trivially do this.... | [
-3
] | [
"perl",
"python"
] | stackoverflow_0004002344_perl_python.txt |
Q:
Any good audio podcasts for Python and Django?
I listen to Python411 but is there any other great podcasts out there for Python and Django?
A:
I'm a fan of Django Dose.
| Any good audio podcasts for Python and Django? | I listen to Python411 but is there any other great podcasts out there for Python and Django?
| [
"I'm a fan of Django Dose.\n"
] | [
1
] | [] | [] | [
"django",
"python"
] | stackoverflow_0004007005_django_python.txt |
Q:
Using python and the bittorrent protocol
I wanted to write a program with could send and receive data over a NAT router without having to set up port forwarding first. Do i need to use the bittorrent protocol or is there something better?
A:
BitTorrent is not a NAT traversal technology but a P2P file sharing pro... | Using python and the bittorrent protocol | I wanted to write a program with could send and receive data over a NAT router without having to set up port forwarding first. Do i need to use the bittorrent protocol or is there something better?
| [
"BitTorrent is not a NAT traversal technology but a P2P file sharing protocol. Unless you want to transfer files BitTorrent probably won't help much.\nSome routers will let you setup a port mapping using UPnP. (see this other question to find a Python UPnP client library)\nAn alternative would be to setup Teredo tu... | [
2
] | [] | [] | [
"bittorrent",
"python"
] | stackoverflow_0004002286_bittorrent_python.txt |
Q:
What is a best practice method to log visits per page / object
Take my profile for example, or any question number of views on this site, what is the process of logging the number of visits per page or object on a website, which I presumably think includes:
Counting registered users once (this must be reflected i... | What is a best practice method to log visits per page / object | Take my profile for example, or any question number of views on this site, what is the process of logging the number of visits per page or object on a website, which I presumably think includes:
Counting registered users once (this must be reflected in the db, which pages / objects the user has visited). this will als... | [
"The \"correct\" answer varies according to the situation; primarily the most desired statistic and the availability of resources to gather and process them:\neg:\nServer Side\nRaw web server logs\nAll webservers have some facility to log requests. The trouble with them is that it requires a lot of processing to g... | [
19,
5,
1,
1,
0,
0
] | [] | [] | [
"asp.net",
"php",
"python"
] | stackoverflow_0003673556_asp.net_php_python.txt |
Q:
Python 2.7/Windows: ttk combobox dropdown shows up underneath topmost root window
I'm experimenting with the new ttk Tile enhancements that ship with Python 2.7.
Windows 7: The code below demonstrates how the combobox dropdown shows up BEHIND our root window when the root window is configured as a topmost window ... | Python 2.7/Windows: ttk combobox dropdown shows up underneath topmost root window | I'm experimenting with the new ttk Tile enhancements that ship with Python 2.7.
Windows 7: The code below demonstrates how the combobox dropdown shows up BEHIND our root window when the root window is configured as a topmost window ("always on top"). If you comment out the line """ root.attributes( '-topmost', 1 )"... | [
"That's a known bug in the Tk toolkit. It was fixed in release 8.5.6. Maybe you just need to wait until that release makes its way into Python.\n"
] | [
1
] | [] | [] | [
"python",
"tkinter",
"ttk",
"windows"
] | stackoverflow_0004007325_python_tkinter_ttk_windows.txt |
Q:
better way to pass data to print in python
I was going through http://web2py.com/book/default/chapter/02 and found this:
>>> print 'number is ' + str(3)
number is 3
>>> print 'number is %s' % (3)
number is 3
>>> print 'number is %(number)s' % dict(number=3)
number is 3
It has been given that The last notation is ... | better way to pass data to print in python | I was going through http://web2py.com/book/default/chapter/02 and found this:
>>> print 'number is ' + str(3)
number is 3
>>> print 'number is %s' % (3)
number is 3
>>> print 'number is %(number)s' % dict(number=3)
number is 3
It has been given that The last notation is more explicit and less error prone, and is to be... | [
">>> print 'number is ' + str(3)\nnumber is 3\n\nThis is definitely the worst solution and might cause you problems if you do the beginner mistake \"Value of obj: \" + obj where obj is not a string or unicode object. For many concatenations, it's not readable at all - it's similar to something like echo \"<p>Hello ... | [
4,
2,
0,
0
] | [] | [] | [
"python"
] | stackoverflow_0004007358_python.txt |
Q:
GAE: what are the args of webapp.RequestHanderls get(*args)
I read the document
http://code.google.com/appengine/docs/python/tools/webapp/requesthandlerclass.html
but I cant find any information of the args parameters
A:
Depends on the regular expressions in your URL matching. For example:
def main():
appli... | GAE: what are the args of webapp.RequestHanderls get(*args) | I read the document
http://code.google.com/appengine/docs/python/tools/webapp/requesthandlerclass.html
but I cant find any information of the args parameters
| [
"Depends on the regular expressions in your URL matching. For example:\ndef main():\n application = webapp.WSGIApplication([\n ('/rechnungsdatencontainer/([a-z0-9_-]+)', RechnungsdatencontainerHandler),\n ('/empfaenger/([A-Za-z0-9_-]+)/rechnungen/([A-Za-z0-9_-]+)\\.?(json|pdf|xml|invoic|html)?', ... | [
6
] | [] | [] | [
"google_app_engine",
"python"
] | stackoverflow_0004007449_google_app_engine_python.txt |
Q:
How would I go about playing an alarm sound in python?
I have a clock I made and I'd like to make it an alarm clock.
A:
Assuming you're on Windows:
import winsound
winsound.PlaySound('alert.wav')
If you're on Linux (or Mac OS X I believe), you can either use pygame or call a Linux program (like mplayer) using... | How would I go about playing an alarm sound in python? | I have a clock I made and I'd like to make it an alarm clock.
| [
"Assuming you're on Windows: \nimport winsound\nwinsound.PlaySound('alert.wav')\n\nIf you're on Linux (or Mac OS X I believe), you can either use pygame or call a Linux program (like mplayer) using popen. pygame example:\nimport pygame\npygame.init()\n\npygame.mixer.music.load(\"alert.ogg\")\npygame.mixer.music.pla... | [
6,
3,
0
] | [] | [] | [
"python",
"tkinter"
] | stackoverflow_0004006709_python_tkinter.txt |
Q:
Appending at run-time to a dictionary
I have a function named OpenAccount() which takes in the details from the User and appends it to my database dictionary.
I have a database file(module) which is imported in my function file.
I have a function called AppendRecord(key,**dictvalues) which appends values to my dat... | Appending at run-time to a dictionary | I have a function named OpenAccount() which takes in the details from the User and appends it to my database dictionary.
I have a database file(module) which is imported in my function file.
I have a function called AppendRecord(key,**dictvalues) which appends values to my database file.
However I am not able to call t... | [
"Your problem is that the DB module is closing the shelf before you write to it. Get rid of the last line and it will work fine.\nYou will also need to provide a function to close it or do so manually.\n#!/usr/bin/python\n\nimport shelve #Module:Shelve is imported to achieve persistence\n\n\nAcco... | [
1
] | [] | [] | [
"append",
"dictionary",
"python",
"runtime"
] | stackoverflow_0004007522_append_dictionary_python_runtime.txt |
Q:
Multiple ModelManager filter methods
def by_this(self):
return super(MyModelManager, self).get_query_set().filter(this=True)
def by_that(self):
return super(MyModelManager, self).get_query_set().filter(that=True)
If i do MyModel.objects.by_this() or by_that() it works.
But i want to do: MyModel.... | Multiple ModelManager filter methods | def by_this(self):
return super(MyModelManager, self).get_query_set().filter(this=True)
def by_that(self):
return super(MyModelManager, self).get_query_set().filter(that=True)
If i do MyModel.objects.by_this() or by_that() it works.
But i want to do: MyModel.objects.by_this().by_that()
| [
"As others say, you need custom QuerySet. Here are some examples of how to do this: \nhttp://djangosnippets.org/snippets/562/\nhttp://adam.gomaa.us/blog/2009/feb/16/subclassing-django-querysets/index.html\n",
"MyModel.objects will return your ModelManager type, but by_this returns a queryset. So you can't call b... | [
1,
0,
0
] | [] | [] | [
"django",
"django_models",
"python"
] | stackoverflow_0004007240_django_django_models_python.txt |
Q:
Can't read appended data using pickle.load() method
I have written two scripts Write.py and Read.py.
Write.py opens friends.txt in append mode and takes input for name, email ,phone no and then dumps the dictionary into the file using pickle.dump() method and every thing works fine in this script.
Read.py opens fr... | Can't read appended data using pickle.load() method | I have written two scripts Write.py and Read.py.
Write.py opens friends.txt in append mode and takes input for name, email ,phone no and then dumps the dictionary into the file using pickle.dump() method and every thing works fine in this script.
Read.py opens friends.txt in read mode and then loads the contents into d... | [
"You have to call pickle.load once for each time you called pickle.dump. You write routine does not add an entry to the dictionary, it adds another dictionary. You will have to call pickle.load until the entire file is read, but this will give you several dictionaries you would have to merge. The easier way for thi... | [
1,
1
] | [] | [] | [
"dictionary",
"file_io",
"pickle",
"python"
] | stackoverflow_0004007753_dictionary_file_io_pickle_python.txt |
Q:
lxml memory problem
I'm trying to parse large XML files (>3GB) like this:
context = lxml.etree.iterparse(path)
for action,el in self.context:
# do sth. with el
With iterparse I thought the data is not completely loaded into RAM, but according to this article I'm wrong:
http://www.ibm.com/developerworks/xml/li... | lxml memory problem | I'm trying to parse large XML files (>3GB) like this:
context = lxml.etree.iterparse(path)
for action,el in self.context:
# do sth. with el
With iterparse I thought the data is not completely loaded into RAM, but according to this article I'm wrong:
http://www.ibm.com/developerworks/xml/library/x-hiperfparse/ (see... | [
"Don't forget to use clear(), optionally also clearing the root element, as explained here. But as I understand, you're already doing this, but apparently you are trying to access content that you have already cleared, or that is not yet parsed. It would be helpful if you could provide something more than \"do sth.... | [
2,
1
] | [] | [] | [
"lxml",
"python",
"xml"
] | stackoverflow_0004004672_lxml_python_xml.txt |
Q:
Python: how to get the edge values from this list
I've got a python list like
a = [
[[1,2,(3,4)],[1,2,(5)],[-3,3,(3)],[8,-2,(5)]],
[[1,2,(3,4,5)],[-1,222,(3,4,5)],[99,2,(3)],[8,-2,(4,5)]]
]
The tuple in each list element is total useless, please ignore that but delete them
I want to get the max min value ... | Python: how to get the edge values from this list | I've got a python list like
a = [
[[1,2,(3,4)],[1,2,(5)],[-3,3,(3)],[8,-2,(5)]],
[[1,2,(3,4,5)],[-1,222,(3,4,5)],[99,2,(3)],[8,-2,(4,5)]]
]
The tuple in each list element is total useless, please ignore that but delete them
I want to get the max min value from each list element in each position
The exepected o... | [
"If you have access to numpy, you can use numpy.amax. You can use the axis parameter to get the maximum of a certain column of the array.\n",
"You can use zip:\na = [ [[1,2,(3,4)],[1,2,(5)],[-3,3,(3)],[8,-2,(5)] ],\n[[1,2,(3,4,5)],[-1,222,(3,4,5)],[99,2,(3)],[8,-2,(4,5)] ] ]\n\n>>> i, h = zip(*a[0]), zip(*a[1])\n... | [
1,
1,
0
] | [] | [] | [
"list",
"python"
] | stackoverflow_0004007880_list_python.txt |
Q:
Python C extension not threadsafe?
I made a c extension out of a python script that was fairly labour intensive. The code itself is well tested and simple. The c extension is called with a few large lists, and it then performs some clever arithmetic and returns a few new lists. The c extension is 100% self suffici... | Python C extension not threadsafe? | I made a c extension out of a python script that was fairly labour intensive. The code itself is well tested and simple. The c extension is called with a few large lists, and it then performs some clever arithmetic and returns a few new lists. The c extension is 100% self sufficient, it doesn't use any other c function... | [
"I finally managed to get rid of the problem, but in a pretty long winded way. Here goes.\nI spent a very very long time trying to make sense of the documentation for c extensions and their thread-safeness. On one of the many google trajectories that night I stumbled on this page describing how to use numpy arrays ... | [
4,
1
] | [] | [] | [
"cpython",
"python",
"python_c_extension",
"thread_safety"
] | stackoverflow_0003999900_cpython_python_python_c_extension_thread_safety.txt |
Q:
WMI querying issues in Python
I've recently been working on a Squish test script, and trying to do something like what's described in the solution at:
Total memory used by Python process?
The relevant snippets from my code are as follows:
def measureMemory():
w = wmi.WMI('.')
result = w.query("SELECT Worki... | WMI querying issues in Python | I've recently been working on a Squish test script, and trying to do something like what's described in the solution at:
Total memory used by Python process?
The relevant snippets from my code are as follows:
def measureMemory():
w = wmi.WMI('.')
result = w.query("SELECT WorkingSet FROM Win32_PerfRawData_PerfPr... | [
"The WMI syntax seems to have changed from the examples. Try using subset.WorkingSet instead of subset['WorkingSet']\n"
] | [
2
] | [] | [] | [
"python",
"wmi",
"wmi_query"
] | stackoverflow_0002105668_python_wmi_wmi_query.txt |
Q:
Storing JSON in MySQL?
I have some things that do not need to be indexed or searched (game configurations) so I was thinking of storing JSON on a BLOB. Is this a good idea at all? Or are there alternatives?
A:
If you need to query based on the values within the JSON, it would be better to store the values separa... | Storing JSON in MySQL? | I have some things that do not need to be indexed or searched (game configurations) so I was thinking of storing JSON on a BLOB. Is this a good idea at all? Or are there alternatives?
| [
"If you need to query based on the values within the JSON, it would be better to store the values separately.\nIf you are just loading a set of configurations like you say you are doing, storing the JSON directly in the database works great and is a very easy solution.\n",
"No different than people storing XML sn... | [
5,
2,
2,
0
] | [] | [] | [
"json",
"mysql",
"python"
] | stackoverflow_0004001314_json_mysql_python.txt |
Q:
How do I programmatically check if a url needs unescaping in python?
Working on a small web spider in python, using the lxml module I have a segment of code which does an xpath query of the document and places all the links from 'a href' tags into a list. what I'd like to do is check each link as it is being added... | How do I programmatically check if a url needs unescaping in python? | Working on a small web spider in python, using the lxml module I have a segment of code which does an xpath query of the document and places all the links from 'a href' tags into a list. what I'd like to do is check each link as it is being added to the list, and if it is needed, unescape it. I understand using the url... | [
"unquote doesn't throw exceptions because of URLs that don't need escaping. You haven't shown us the exception, but I'll guess that the problem is that old isn't a string, it's probably None, because you have an <a> tag with no href attribute.\nCheck the value of old before you try to use it.\n",
"url.find('%') ... | [
1,
0,
0
] | [] | [] | [
"escaping",
"python"
] | stackoverflow_0004007141_escaping_python.txt |
Q:
Python: I am unable to comprehend the concept of a For Loop, apparently
I've got a list of 400 numbers, and i want to but them in a 20x20 grid using Python.
I've made a "2d array" (not really because Python doesn't support them, I've had to use a list of lists.)
When i try to loop through and assign each subsequn... | Python: I am unable to comprehend the concept of a For Loop, apparently | I've got a list of 400 numbers, and i want to but them in a 20x20 grid using Python.
I've made a "2d array" (not really because Python doesn't support them, I've had to use a list of lists.)
When i try to loop through and assign each subsequnt item to the next box in the grid, it fails. i end up assinging the last ite... | [
"This is the sort of thing that list comprehensions are good for.\nnums = iter(numbers.split())\ngrid = [[next(nums) for col in range(20)] for row in range(20)]\n\nAlternatively, as a for loop:\ngrid = [[0]*20 for row in range(20)]\nnums = iter(numbers.split())\nfor i in xrange(20):\n for j in xrange(20):\n ... | [
6,
5,
3
] | [] | [] | [
"loops",
"multidimensional_array",
"python"
] | stackoverflow_0004008055_loops_multidimensional_array_python.txt |
Q:
Python: Sorting this list
`li = [(1106257, (255, 255, 255)), (1, (16, 16, 118)), (1, (32, 32, 128)), (1, (48, 48, 122)), (9, (249, 249, 249)), (1, (64, 64, 126)), (406, (247, 247, 251))]`
I want to sort li depending on the first number in each element eg.1106257, 1, 1,1,9,1,406
How to do this fast? Thanks
A:
ha... | Python: Sorting this list | `li = [(1106257, (255, 255, 255)), (1, (16, 16, 118)), (1, (32, 32, 128)), (1, (48, 48, 122)), (9, (249, 249, 249)), (1, (64, 64, 126)), (406, (247, 247, 251))]`
I want to sort li depending on the first number in each element eg.1106257, 1, 1,1,9,1,406
How to do this fast? Thanks
| [
"have you tried li.sort() or sorted(li)?\n",
">>> li = [(1106257, (255, 255, 255)), (1, (16, 16, 118)), (1, (32, 32, 128)), (1, (48, 48, 122)), (9, (249, 249, 249)), (1, (64, 64, 126)), (406, (247, 247, 251))]\n>>> li.sort()\n>>> li\n[(1, (16, 16, 118)), (1, (32, 32, 128)), (1, (48, 48, 122)), (1, (64, 64, 126)),... | [
2,
2,
1
] | [] | [] | [
"list",
"python",
"sorting"
] | stackoverflow_0004006438_list_python_sorting.txt |
Q:
Modifying *.RC file with python (regexp involved)
What I need is to parce my projects' resource files and change its version number. I have a working JS script but I would like to implement it with python.
So, the problem stands in using re.sub:
version = "2,3,4,5"
modified_str = re.sub(r"(/FILEVERSION )\d+,\d+,\d... | Modifying *.RC file with python (regexp involved) | What I need is to parce my projects' resource files and change its version number. I have a working JS script but I would like to implement it with python.
So, the problem stands in using re.sub:
version = "2,3,4,5"
modified_str = re.sub(r"(/FILEVERSION )\d+,\d+,\d+,\d+(\s)/g", version, str_text)
I understand that bec... | [
"That's not the way to make multiline regexes in python. You have to compile the regex with the MULTILINE flag:\nregex = re.compile(r\"\\bFILEVERSION \\d+,\\d+,\\d+,\\d+\\b\", re.MULTILINE)\n\nAlso, since you're using re.sub(), the FILEVERSION part of your string will disappear if you don't specify it again in the ... | [
4,
4
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0004003725_python_regex.txt |
Q:
how to implement the options/arguments for the command line functions in python
my python version is 2.4.3.
Now I am developing a CLI with cmd module from python for a CD player. I have some classes like CDContainer (with method like addCD, removeCD, etc), CD (with method like play, stop, pause). Now, I want to ad... | how to implement the options/arguments for the command line functions in python | my python version is 2.4.3.
Now I am developing a CLI with cmd module from python for a CD player. I have some classes like CDContainer (with method like addCD, removeCD, etc), CD (with method like play, stop, pause). Now, I want to add some options for the commands and also if the options inputs are not correct, the C... | [
"\nmy question is in python, is there some module that is handy for my case to parse and analyse the options or arguments ?\n\nYes, the argparse module.\nIf you're already familiar with the getopt library from C, that's also available as a python module - though less easy to use, if you're not already used to it.\n... | [
3,
3,
1
] | [] | [] | [
"command_line",
"command_line_arguments",
"python"
] | stackoverflow_0004008048_command_line_command_line_arguments_python.txt |
Q:
Do all Mac OS X versions (above 10.4) have python preinstalled?
Do all Mac OS X versions (above 10.4) have python preinstalled?
A:
Yes, but the Python version may be different. OS X 10.5 shipped with Python 2.5, OS X 10.6 with Python 2.6.
A:
Yes, they do all have python preinstalled.
| Do all Mac OS X versions (above 10.4) have python preinstalled? | Do all Mac OS X versions (above 10.4) have python preinstalled?
| [
"Yes, but the Python version may be different. OS X 10.5 shipped with Python 2.5, OS X 10.6 with Python 2.6.\n",
"Yes, they do all have python preinstalled.\n"
] | [
5,
4
] | [
"Yes they do. Use it from Terminal.\n"
] | [
-1
] | [
"macos",
"python"
] | stackoverflow_0004007801_macos_python.txt |
Q:
Python Regular Expression Matching: ## ##
I'm searching a file line by line for the occurrence of ##random_string##. It works except for the case of multiple #...
pattern='##(.*?)##'
prog=re.compile(pattern)
string='lala ###hey## there'
result=prog.search(string)
print re.sub(result.group(1), 'FOUND', string)
D... | Python Regular Expression Matching: ## ## | I'm searching a file line by line for the occurrence of ##random_string##. It works except for the case of multiple #...
pattern='##(.*?)##'
prog=re.compile(pattern)
string='lala ###hey## there'
result=prog.search(string)
print re.sub(result.group(1), 'FOUND', string)
Desired Output:
"lala #FOUND there"
Instead I g... | [
"To match at least two hashes at either end:\npattern='##+(.*?)##+'\n\n",
"Your problem is with your inner match. You use ., which matches any character that isn't a line end, and that means it matches # as well. So when it gets ###hey##, it matches (.*?) to #hey.\nThe easy solution is to exclude the # characte... | [
3,
3,
1,
0,
0,
0,
0
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0004001980_python_regex.txt |
Q:
Passing user data with glade/gtkbuilder
I am a newbie of glade/pygtk.
I am doing with some radio menu items.
I created a signal handler on the signals tab,
handler: on_group_menu_change
user data: 7
what I expected is pass the int(or str) value 7 as user param to the handler. However, at startup, I found such wa... | Passing user data with glade/gtkbuilder | I am a newbie of glade/pygtk.
I am doing with some radio menu items.
I created a signal handler on the signals tab,
handler: on_group_menu_change
user data: 7
what I expected is pass the int(or str) value 7 as user param to the handler. However, at startup, I found such warning:
Could not lookup object 0 on signal
... | [
"It seems this is still on the Glade/GtkBuilder todo-list: http://live.gnome.org/Glade/Roadmap/RealUsableSignals\nCurrently you can only pass references to objects that you define in your xml.\nEdit: Since gtk+3, the devs have broken more than just the API... The archived link above is:\nhttps://web.archive.org/web... | [
1
] | [] | [] | [
"glade",
"gtk",
"pygtk",
"python"
] | stackoverflow_0004008309_glade_gtk_pygtk_python.txt |
Q:
Creating views in django (string indentation problems)
I am new to both Python (and django) - but not to programming.
I am having no end of problems with identation in my view. I am trying to generate my html dynamically, so that means a lot of string manipulation. Obviously - I cant have my entire HTML page in on... | Creating views in django (string indentation problems) | I am new to both Python (and django) - but not to programming.
I am having no end of problems with identation in my view. I am trying to generate my html dynamically, so that means a lot of string manipulation. Obviously - I cant have my entire HTML page in one line - so what is required in order to be able to dynamica... | [
"\nI am trying to generate my html dynamically, so that means a lot of string manipulation.\n\nDon't do this.\n\nUse Django's templates. They work really, really well. If you can't figure out how to apply them, do this. Ask a question showing what you want to do. Don't ask how to make dynamic HTML. Ask about h... | [
4,
1
] | [] | [] | [
"django",
"python"
] | stackoverflow_0004008748_django_python.txt |
Q:
Merging .xlsx file with Python
Two-headed question here guys,
First, I've been trying to do some searching for a way to read .xlsx files in python. Does xlrd read .xlsx files now? If not, what's the recommended way to read/write to such a file?
Second, I have two files with similar information. One primary field ... | Merging .xlsx file with Python | Two-headed question here guys,
First, I've been trying to do some searching for a way to read .xlsx files in python. Does xlrd read .xlsx files now? If not, what's the recommended way to read/write to such a file?
Second, I have two files with similar information. One primary field with scoping subfields (like coordin... | [
"I frequently access excel files through python and xlrd, python and the Excel COM object. For this job, xlrd won't work because it does not support the xlsx format. But no matter, both approaches are overkill for what you are looking for. Simple Excel formulas will deliver what you want, specifically VLOOKUP. \... | [
4,
2,
0,
0
] | [] | [] | [
"excel",
"python",
"vba"
] | stackoverflow_0003997745_excel_python_vba.txt |
Q:
extending an irc bot with modules
I've created an IRC bot in Python from scratch just for the fun of it. I've got a way to load modules into it, but you have to manually type out the code to load each module as below:
if data.find('PRIVMSG %s :add_mod foo\r\n' % channel)
enabled_mods.append(foo)
if data.find('... | extending an irc bot with modules | I've created an IRC bot in Python from scratch just for the fun of it. I've got a way to load modules into it, but you have to manually type out the code to load each module as below:
if data.find('PRIVMSG %s :add_mod foo\r\n' % channel)
enabled_mods.append(foo)
if data.find('PRIVMSG %s :rm_mod foo\r\n' % channel)
... | [
"Are you looking for the __import__ function?\n"
] | [
0
] | [] | [] | [
"irc",
"module",
"python"
] | stackoverflow_0004008935_irc_module_python.txt |
Q:
How to debug Python inside a WSC
We're programming classic ASP for a big (legacy) web application. This works quite well using WSC (Windows script components) to separate GUI from business logic; the WSCs contain the business logic, classic asp is used for displaying returned information. The WSC's return stringva... | How to debug Python inside a WSC | We're programming classic ASP for a big (legacy) web application. This works quite well using WSC (Windows script components) to separate GUI from business logic; the WSCs contain the business logic, classic asp is used for displaying returned information. The WSC's return stringvalues, ADO recordsets and in some cases... | [
"as for #2, you need to catch exceptions in the VBScript that calls the component. A WSC is just a com component. Ignore for a moment that there is python running when you invoke your WSC. It's just a COM component. \nErrors may occur when invoking that component. It's good practice when invoking a component tha... | [
0
] | [] | [] | [
"asp_classic",
"python",
"vbscript"
] | stackoverflow_0003879788_asp_classic_python_vbscript.txt |
Q:
pytz and Etc/GMT-5
I'm having trouble understanding the conversion between the "Etc/GMT-5" timezone and UTC in pytz.
>>> dt = datetime(2009, 9, 9, 10, 0) # September 9 2009, 10:00
>>> gmt_5 = pytz.timezone("Etc/GMT-5")
>>> gmt_5.localize(dt)
datetime.datetime(2009, 9, 9, 10, 0, tzinfo=<StaticTzInfo 'Etc/GMT-5'>)
... | pytz and Etc/GMT-5 | I'm having trouble understanding the conversion between the "Etc/GMT-5" timezone and UTC in pytz.
>>> dt = datetime(2009, 9, 9, 10, 0) # September 9 2009, 10:00
>>> gmt_5 = pytz.timezone("Etc/GMT-5")
>>> gmt_5.localize(dt)
datetime.datetime(2009, 9, 9, 10, 0, tzinfo=<StaticTzInfo 'Etc/GMT-5'>)
Everything is fine so fa... | [
"This is apparently a POSIX thing. From Wikipedia:\n\nIn order to conform with the POSIX style, those zones beginning with \"Etc/GMT\" have their sign reversed from what most people expect. In this style, zones west of GMT have a positive sign and those east have a negative sign.\n\n",
"This bug report explains t... | [
18,
1
] | [] | [] | [
"python",
"pytz",
"timezone",
"utc"
] | stackoverflow_0004008960_python_pytz_timezone_utc.txt |
Q:
Removing duplicates members from a list of tuples
this question might have similars in SO but my case is a bit different. and I tried to adapt those answers to my problem but couldn't.
so here is the thing:
I have this list :
[(['c', 'a', 'b'], 10), (['c', 'a', 'b'], 9),(['h','b'],2)] for example.
I want to remove... | Removing duplicates members from a list of tuples | this question might have similars in SO but my case is a bit different. and I tried to adapt those answers to my problem but couldn't.
so here is the thing:
I have this list :
[(['c', 'a', 'b'], 10), (['c', 'a', 'b'], 9),(['h','b'],2)] for example.
I want to remove the duplicates in this list by keeping tuple that has ... | [
">>> lst = [(['c', 'a', 'b'], 10), (['c', 'a', 'b'], 9),(['h','b'],2)]\n>>> from collections import defaultdict\n>>> d = defaultdict(int)\n>>> for i, j in lst:\n d[tuple(i)] = max(d[tuple(i)], j) # assuming positive numbers\n\n\n>>> d\ndefaultdict(<class 'int'>, {('h', 'b'): 2, ('c', 'a', 'b'): 10})\n\n... | [
3,
2
] | [] | [] | [
"duplicates",
"list",
"python",
"tuples"
] | stackoverflow_0004009304_duplicates_list_python_tuples.txt |
Q:
Use URLLIB without system default proxy Python
I have a small script that needs to communicate with me, it is part of my proxy. The script needs to run before the proxy starts, but the system is set to use the proxy, so it does not go through. How would I use urllib, but not the default proxy?
A:
urllib docs:
u... | Use URLLIB without system default proxy Python | I have a small script that needs to communicate with me, it is part of my proxy. The script needs to run before the proxy starts, but the system is set to use the proxy, so it does not go through. How would I use urllib, but not the default proxy?
| [
"urllib docs:\n\nurllib.urlopen(url[, data[, proxies]])\n\n[...]\n Alternatively, the optional proxies argument may be used to explicitly specify proxies. It must be a dictionary mapping scheme names to proxy URLs, where an empty dictionary causes no proxies to be used, and None (the default value) causes environm... | [
2
] | [] | [] | [
"overriding",
"proxy",
"python",
"urllib"
] | stackoverflow_0004009305_overriding_proxy_python_urllib.txt |
Q:
An algorithm to create HTML table from this row data?
I have come unstuck on a relatively (almost) trivial problem. I have a row of data that I want to display in tabular form (HTML). For some reason (possibly long day [again] behind the computer), I am not coming up with any elegant solutions (algorithms) to do t... | An algorithm to create HTML table from this row data? | I have come unstuck on a relatively (almost) trivial problem. I have a row of data that I want to display in tabular form (HTML). For some reason (possibly long day [again] behind the computer), I am not coming up with any elegant solutions (algorithms) to do this.
I have presented some sample data, and how such data w... | [
"I assumed you have Raw data stored similar to what I have below.\nAlso, the level is non-unique. \n<?\n $rowData = array( \n 0=> array('index'=>1, 'Score'=>\"level 1\", 'amount'=>12.24), \n 1=> array('index'=>3, 'Score'=>\"level 4\", 'amount'=>14.61),\n 2=> array('index'=>9, 'Score'=>\"leve... | [
1,
0,
0
] | [] | [] | [
"c#",
"c++",
"html",
"php",
"python"
] | stackoverflow_0004009250_c#_c++_html_php_python.txt |
Q:
Read dynamic xml using element tree
Environment: Windows,Python,wxpython and Element tree as xml parser.
I am developing a stand alone where it reads the xml and creates a tree.
My application reads the xml and creates tree but when xml changes next time(when DEPTH of xml increases- i mean when two child elements ... | Read dynamic xml using element tree | Environment: Windows,Python,wxpython and Element tree as xml parser.
I am developing a stand alone where it reads the xml and creates a tree.
My application reads the xml and creates tree but when xml changes next time(when DEPTH of xml increases- i mean when two child elements are added).Application fails to read(Logi... | [
"You should use recursive calls, something more like:\ndef recurse_tree(node):\n tree = {}\n for element in node:\n name = element.get('name')\n tree[name] = recurse_tree(element)\n if tree:\n return tree\n else:\n return 'No children.'\n\nNot all of your elements had 'name' ... | [
2
] | [] | [] | [
"elementtree",
"python",
"xml"
] | stackoverflow_0004009268_elementtree_python_xml.txt |
Q:
Appengine: How can I set another cookie when use google OAuth login logout
I want set another cookie when user login, I use google.appenine.api.users.create_loginurl() to create the login url, it's /_ah/login, how can I extend this handler and add another cookie. The same as logout.
A:
One option: You could cre... | Appengine: How can I set another cookie when use google OAuth login logout | I want set another cookie when user login, I use google.appenine.api.users.create_loginurl() to create the login url, it's /_ah/login, how can I extend this handler and add another cookie. The same as logout.
| [
"One option: You could create landing pages to set or unset your app cookies. create_login_url takes a destination url as an argument, redirect to your page that sets up your cookie. To logout, forward users to a page that unsets the cookie then redirects them on to the log out page.\nAnother choice would be to ... | [
1
] | [] | [] | [
"google_app_engine",
"python"
] | stackoverflow_0004008466_google_app_engine_python.txt |
Q:
Data persistence for python when a lot of lookups but few writes?
I am working on a project that basically monitors a set remote directories (FTP, networked paths, and another), if the file is considered new and meets criteria we download it and process it. However i am stuck on what the best way is to keep track ... | Data persistence for python when a lot of lookups but few writes? | I am working on a project that basically monitors a set remote directories (FTP, networked paths, and another), if the file is considered new and meets criteria we download it and process it. However i am stuck on what the best way is to keep track of the files we already downloaded. I don't want to download any duplic... | [
"I would create a set of tuples, then pickle it to a file. The tuples would be (server, directory, file_name), or even just (server, full_file_name_including_directory). There's no need for a multiple-level data structure. The tuples will hash into the set, and give you a O(1) lookup.\nYou mention \"stuff starts... | [
1
] | [] | [] | [
"persistence",
"python"
] | stackoverflow_0004009696_persistence_python.txt |
Q:
process closing while saving a file - Python - Windows XP
I'm working on a project for school where e-mails will be pulled from an inbox and downloaded to different locations depending on how things are parsed. The language I'm writing in is Python, and the environment it will be run on is Windows XP. The idea is ... | process closing while saving a file - Python - Windows XP | I'm working on a project for school where e-mails will be pulled from an inbox and downloaded to different locations depending on how things are parsed. The language I'm writing in is Python, and the environment it will be run on is Windows XP. The idea is that the program will run in the background with no interaction... | [
"You should really check this out: Link (How Windows Shuts Down)\n",
"use atexit module\n",
"easy crossplatform/crosslanguage way of handling partial file saving:\n\nsave to a temporary filename like \"file.ext.part\"\nafter you're done saving, rename to \"file.ext\"\n\n"
] | [
1,
1,
0
] | [] | [] | [
"python",
"windows"
] | stackoverflow_0004009130_python_windows.txt |
Q:
Python - default arguments in function
Looking at the python doc http://docs.python.org/library/urllib2.html
urllib2.urlopen(url[, data][, timeout])
So, I pass in a url, then optional data and timeout variables (from how I read it).
So if I want to pass a timeout, but not the data... whats the default variable for... | Python - default arguments in function | Looking at the python doc http://docs.python.org/library/urllib2.html
urllib2.urlopen(url[, data][, timeout])
So, I pass in a url, then optional data and timeout variables (from how I read it).
So if I want to pass a timeout, but not the data... whats the default variable for data? Do you just do,
urlopen('http://www.e... | [
"You use the parameter names:\nurlopen('http://www.exmaple.com/', timeout=5)\n\n",
"urlopen('http://www.example.com/',timeout=5)\n\n"
] | [
8,
1
] | [] | [] | [
"python",
"urllib2"
] | stackoverflow_0004009863_python_urllib2.txt |
Q:
python - undefined variable?
Does python have some undefined variable / debug mode which will output a notice/warning?
PHP allows you to modify the error_reporting to turn on notice warnings which mean doing
<?php
echo $foo;
will throw an "Undefined variable foo on line 2.......
does python have something similar... | python - undefined variable? | Does python have some undefined variable / debug mode which will output a notice/warning?
PHP allows you to modify the error_reporting to turn on notice warnings which mean doing
<?php
echo $foo;
will throw an "Undefined variable foo on line 2.......
does python have something similar?
I had a bug where I was doing
db... | [
"Python complains about undefined variables, without any adjustments to its warning system:\nh[1] >>> print x\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nNameError: name 'x' is not defined\n\nIn your case db.connect actually has a value, namely a function object. So your connection... | [
9,
3,
0,
0
] | [] | [] | [
"debugging",
"error_reporting",
"python",
"variables"
] | stackoverflow_0004009795_debugging_error_reporting_python_variables.txt |
Q:
Python Twitter library: which one?
I realize this is a bit of a lazyweb question, but I wanted to see which python library for Twitter people have had good experiences with.
I've used Python Twitter Tools and like its brevity and beauty of interface, but it doesn't seem to be one of the popular ones - it's not eve... | Python Twitter library: which one? | I realize this is a bit of a lazyweb question, but I wanted to see which python library for Twitter people have had good experiences with.
I've used Python Twitter Tools and like its brevity and beauty of interface, but it doesn't seem to be one of the popular ones - it's not even listed on the Twitter Libraries page. ... | [
"python-twitter should cover the first four requirements. I've used it before, and it's fairly easy to start developing with it. For leveraging Twitter's streaming API, I would recommend tweetstream. It's a fantastic Python module that grabs tweets in real-time as they are posted. Based on whether you have gardenho... | [
24,
21,
1
] | [] | [] | [
"python",
"twitter"
] | stackoverflow_0003577399_python_twitter.txt |
Q:
Responding to httpRequest after using threading.Timer to delay response
I'm trying to patch a testing framework built in python for javascript called mootools-test-runner (i'm a front end developer by day, so my python skills are pretty weak... really weak.)
The use case is we want to be able to make a json reques... | Responding to httpRequest after using threading.Timer to delay response | I'm trying to patch a testing framework built in python for javascript called mootools-test-runner (i'm a front end developer by day, so my python skills are pretty weak... really weak.)
The use case is we want to be able to make a json request to the server and have it delay x amount of time before it returns -- origi... | [
"Are you sure you want the return statement inside the for key, value loop? You're only allowing a single iteration, and returning.\nAlso, check the flow of the function. There are cases in which it will return None. Easiest way to do this is printing out your request object and examining it in the cases in which t... | [
0
] | [] | [] | [
"django",
"httpresponse",
"multithreading",
"python",
"timer"
] | stackoverflow_0004010071_django_httpresponse_multithreading_python_timer.txt |
Q:
Bash Script for MythTV which requires Python Dependencies
I wrote a bash script which renames MythTV files based upon data it receives. I wrote it in bash because bash has the strong points of textual data manipulation and ease of use.
You can see the script itself here: http://code.google.com/p/mythicallibrarian... | Bash Script for MythTV which requires Python Dependencies | I wrote a bash script which renames MythTV files based upon data it receives. I wrote it in bash because bash has the strong points of textual data manipulation and ease of use.
You can see the script itself here: http://code.google.com/p/mythicallibrarian/source/browse/trunk/mythicalLibrarian
I have several users whi... | [
"You can check the status code of:\npython -c \"import MythDB.MythTV\"\n\nIf it returns non-zero, there was an error, likely an ImportError.\n",
"Write a Python script:\ntry:\n from MythTV import MythDB\n print \"Yes\"\nexcept ImportError:\n print \"No\"\n\nthen run the Python script from your Bash scrip... | [
5,
0
] | [] | [] | [
"bash",
"dependencies",
"python"
] | stackoverflow_0004010200_bash_dependencies_python.txt |
Q:
comparing two lists, python
I should define a function overlapping() that takes two lists and returns True if they have at least one member in common, False otherwise. For the sake of the exercise, I should write it using two nested for-loops. What am I doing wrong?
def overlapping(a,b):
for char in a:
... | comparing two lists, python | I should define a function overlapping() that takes two lists and returns True if they have at least one member in common, False otherwise. For the sake of the exercise, I should write it using two nested for-loops. What am I doing wrong?
def overlapping(a,b):
for char in a:
for char2 in b:
retu... | [
"You should use == and not the in operator\ndef overlapping(list_a,list_b):\n for char_in_list_a in list_a:\n for char_in_list_b in list_b:\n if char_in_list_a == char_in_list_b:\n return True\n return False\n\nIf you want something using set:\ndef overlapping(a,b):\n ... | [
2,
2,
0
] | [] | [] | [
"for_loop",
"nested",
"python"
] | stackoverflow_0004010218_for_loop_nested_python.txt |
Q:
Simplify the changing of this binary variable
When I am writing my code, I find the following situation many times:
def Mwindow_stayontop(self, event):
if CFG["AlwOnTop"] == 1:
self.SetWindowStyle(wx.DEFAULT_FRAME_STYLE)
CFG["AlwOnTop"] = 0
else:
self.SetWindowStyle(wx.DEFAULT_FRAME... | Simplify the changing of this binary variable | When I am writing my code, I find the following situation many times:
def Mwindow_stayontop(self, event):
if CFG["AlwOnTop"] == 1:
self.SetWindowStyle(wx.DEFAULT_FRAME_STYLE)
CFG["AlwOnTop"] = 0
else:
self.SetWindowStyle(wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP)
CFG["AlwOnTop"] = ... | [
"CFG[\"AlwOnTop\"] = 1 - CFG[\"AlwOnTop\"]\n\nor\nCFG[\"AlwOnTop\"] = not CFG[\"AlwOnTop\"]\n\nThe complete function could be:\ndef Mwindow_stayontop(self, event):\n CFG[\"AlwOnTop\"] = 1 - CFG[\"AlwOnTop\"]\n self.SetWindowStyle(wx.DEFAULT_FRAME_STYLE | CFG[\"AlwOnTop\"]*wx.STAY_ON_TOP)\n\nthough some might ... | [
2,
1
] | [] | [] | [
"python"
] | stackoverflow_0004010301_python.txt |
Q:
List membership in Python without "in"
How to define a function is_member() that takes a value (i.e. a number, string, etc) x and a list of values a, and returns True if x is a member of a, False otherwise. (Note that this is exactly what the in operator does, but for the sake of the exercise I should pretend Pyth... | List membership in Python without "in" | How to define a function is_member() that takes a value (i.e. a number, string, etc) x and a list of values a, and returns True if x is a member of a, False otherwise. (Note that this is exactly what the in operator does, but for the sake of the exercise I should pretend Python did not have this operator.
This is what ... | [
"I can think of two (edit: three) ways to do this:\nFirst:\ndef is_member(array, value):\n try:\n array.index(value)\n except ValueError:\n return False\n else:\n return True\n\nSecond:\ndef is_member(array, value):\n for item in array:\n if item == value:\n return... | [
4,
3,
2,
1,
1,
0
] | [] | [] | [
"membership",
"python"
] | stackoverflow_0004008380_membership_python.txt |
Q:
Is Python bad at XML?
EDIT
The use of the phrase "bad at XML" in this question has been a point of contention, so I'd like to start out by providing a very clear definition of what I mean by this term in this context: if support for standard XML APIs is poor, and forces one to use a language-specific API, in which... | Is Python bad at XML? | EDIT
The use of the phrase "bad at XML" in this question has been a point of contention, so I'd like to start out by providing a very clear definition of what I mean by this term in this context: if support for standard XML APIs is poor, and forces one to use a language-specific API, in which namespaces seem to be an a... | [
"I would say python handles XML pretty well. The number of different libraries available speaks to that - you have lots of options. And if there are features missing from libraries that you would like to use, feel free to contribute some patches!\nI personally use the DOM and lxml.etree (etree is really fast). Howe... | [
4,
1,
1
] | [] | [] | [
"dom",
"python",
"xml"
] | stackoverflow_0004005641_dom_python_xml.txt |
Q:
Ackermann function versus n nested loops
I'm working my way thorugh a book on computation (Minksy 1967) and am having a hard time with relating a recursive function to a function defined in terms of loops. Specifically he asks to find the relationship between two functions:
The Ackermann function (all code in pyt... | Ackermann function versus n nested loops | I'm working my way thorugh a book on computation (Minksy 1967) and am having a hard time with relating a recursive function to a function defined in terms of loops. Specifically he asks to find the relationship between two functions:
The Ackermann function (all code in python):
def a(n,m):
if n==0:
return ... | [
"Uhm... I don't think this will help you much, I'm kinda baffled too, but here are my thoughts.\n\nAckerman(0, m) == p(0, m)\nAckerman(1, m + 1) == p(1, m)\n\nedit -- wait I think I miscopied the function. I'll give this more thought later, and if I think of something I'll update!\n"
] | [
1
] | [] | [] | [
"computability",
"computer_science",
"python"
] | stackoverflow_0004010367_computability_computer_science_python.txt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.