I'm trying to do a Depth-First search in Python but it's not working.
Basically we have a peg-solitaire board:
[1,1,1,1,1,0,1,1,1,1]
1's represent a peg, and 0 is an open spot. You must move a peg one at a time TWO SLOTS backwards or forward ONLY to an empty spot. If you jump over another peg in the process it becomes an empty slot....
I am trying to store raw, unescaped HTML inside one of my Django models for display on my home page. However, when I store it in a TextField it gets escaped, and ends up just being displayed as raw text. How can I store raw HTML in a Django model?
** EDIT **
It seems as if its not getting escaped in the model layer, but in the Template...
Any idea if there is a way to make the following code to work
class Test(object):
def __init__(self, var):
self.var = var
def changeme(self):
self = Test(3)
t = Test(1)
assert t.var == 1
t.changeme()
assert t.var == 3
is something like the following safe to use for more complex objects (like django models, t...
The trivial
import Image
im = Image.OPEN('C:\abc.bmp')
results in the following exception
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
im = Image.OPEN('C:\Documents and Settings\umair.ahmed\My Documents\My Pictures\avanza.bmp')
TypeError: 'dict' object is not callable
not sure if i am missing so...
Hi,
I had this question posted earlier, but it wasn't very clear, and I had trouble with the answers. Since I edited it to make MUCH more sense it seems that people haven't been looking at it, perhaps because they see it already has 6 answers. So I'm re=-posting it here:
I'm still new to Python and Programming in general, so I need s...
Do not code like this. Please, read the hints by the accepted answer. I tried to remove the junk but I coundn't.
Code
import sys
a = []
i=0
for line in sys.stdin:
try:
n = float(line)
a.append(n)
i+=1
except ValueError:
print 'Number please!';
...
Hi,
I am currently using the win32com module of CPython to use a DLL.
I know some people using IronPython to automagically get the list of functions provided by this DLL. They don't need to register the DLL.
I'd like to do the same as them but with CPython.
1) Is it possible to use CPython and win32com to connect to a dll reg-free. Ho...
I have a problem in Python.
I'm using Tkinter and have four bind events, that listen to key presses on my form.
My problem is, that these don't run asynchronously. So, for example I can press one button, and the events are recognized. But when I press and hold two keys at the same time, just one event gets fired.
Is there an alternativ...
Hi there,
When I include "Python.h" from Python 2.5 in a C++ project, it knows through some magical process that it has to link with "python25.lib" and load "python25.dll" at runtime, though I didn't specified anything neither in "Linker -> Additional Dependencies" nor in "Linker -> Additional Library Directories".
Now I would like to ...
Hi, currently I'm interfacing the Twitter API using the OAuth protocol and writing the code in Python. As most of the users out there, I think the toughest part of the specs is dealing with signatures.
After wandering around the web in search for a solution, I decided to go for my custom code, so as to have a better understanding of wha...
I've well developed Python Server having workflows, views, object - ORM/OSV, etc...
Server/Client communication based on socket protocol, can be done by any of service
1. XMLRPC Service
2. Socket Service
now I want to develop a Fully Ajax based GUI web Client..
I've web/socket services to communicate with server.
what I need is to s...
What's the best way of getting the last item from an iterator in Python 2.6? For example, say
my_iter = iter(range(5))
What is the shortest-code / cleanest way of getting 4 from my_iter?
I could do this, but it doesn't seem very efficient:
[x for x in my_iter][-1]
...
I am trying to make a simple localization module that takes a key name and returns the localized string based on the language given. The language is one of the constants and maps to a python file that contains the string table. I want to do this dynamically at runtime. Below is my approach, but GAE does not support the imp module. Is the...
Is there any way to make this scenario work?
There is a Python script. It is built into a DLL by running this script with IronPython:
import clr
clr.CompileModules("CompiledScript.dll", "script.py")
The goal is to call this DLL's methods from C# code. .NET Reflector shows there is one class in the DLL - DLRCashedCode and the methods ...
i want to install openlibrary in my ubuntu system and i followed the instruction from the below link http://openlibrary.org/dev/docs/setup
$ ./scripts/openlibrary-server openlibrary.yml
while i am using the above command it shows infogami module not found error message
...
Is there a quick way in python to split a 32-bit variable, say, a1a2a3a4 into a1, a2, a3, a4 quickly? I've done it by changing the value into hex and then splitting it, but it seems like a waste of time doing int->string->int.
...
I wrote a small WSGI App:
def foo(environ, start_response):
bar = 'Your request is %s' % environ['PATH_INFO']
status = '200 OK'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(bar)))]
start_response(status, response_headers)
return [bar]
...
A trivial CSV line could be spitted using string split function. But some lines could have ", e.g.
"good,morning", 100, 300, "1998,5,3"
thus directly using string split would not solve the problem.
My solution is to first split out the line using , and then combining the strings with " at then begin or end of the string.
What's th...
Hi,
I have a set of 10000 files c1.dat ... c10000.dat. Each of these files contains a line which starts with @ and contains a string with spaces specific for this file, lije c37 7.379 6.23.
I have another set of 10000 files kind of determined_cXXX_send.dat (where XXX goes from 1 to 10000). Each of these files has only one line. Each l...
I am trying to ping two different networks with thread. I am able to get the response I want but I want to convert it into a test. I have the code that I have tried below but the test runner says that no tests were run. The code is below:
#!/home/workspace/downloads/Python-2.6.4/python
from threading import Thread
import subprocess, un...