python

scramble function won't output

this function will not give me an output when tested in python's IDLE: import random def scramble(string): rlist = [] while len(rlist) < len(string): n = random.randint(0, len(string) - 1) if rlist.count(string[n]) < string.count(string[n]): rlist += string[n] rstring = str(rlist) return ...

Python statement uses excessive amounts of RAM

This simple statement: zip(xrange(0, 11614321), xrange(0, 11627964)) ...is eating most of my RAM. (>150 MiB!) Why? Edit: Ah, re-reading the docs, I see zip returns a list, not an iterable. Anything like zip that returns an iterable? The larger picture: I'm iterating over two large arrays of file data, and I'm doing things like ite...

tkinter python button run in background command

Hi I'm mucking about with Tkinter and Python. I have a basic gui with a couple of buttons on, one button goes away and does something that takes some amount of time, which is variable. The problem is when I hit this button the whole of my gui locks up/ doesnt show correctly - I guess because its trying to do these things that take some ...

Django Can't Find My Templates

I'm running Python 2.6.1 and Django 1.2.1 on Windows XP SP3. I'm using JetBrains PyCharm 1.0 to create and deploy my Django apps. I'm relatively inexperienced with Python, and I'm starting to learn Django by following along with "Writing Your First Django App" from the web site - the poll application. I'm stuck on part 3. Everything ...

uTidylib segmentation fault

uTidylib is crashing and giving me a segmentation fault every time I try to use it. Here's some info about the crash: Process: Python [432] Path: /System/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python Identifier: Python Version: ??? (???) Code Type: X86-...

Using gevent with python xmlrpclib

Hello! Is it possible to use python's standard libs xmlrpclib with gevent? Currently i'm tried to use monkey.patch_all(), but without success. from gevent import monkey monkey.patch_all() import gevent import time import xmlrpclib from SimpleXMLRPCServer import SimpleXMLRPCServer import urllib2 def fetch(url): g = gevent.sp...

Safe dereferencing in Python

Groovy has a nice operator for safe dereferencing, which helps to avoid NullPointerExceptions: variable?.method() The method will only be called, if variable is not null. Is there a way to do the same in Python? Or do I have to write if variable: variable.method()? ...

Python problem with circular reference:

I get: ImportError: cannot import name Image (from image_blob.py) please help me thanks :s my code: image.py: from google.appengine.ext import db from app.models.item import Item class Image(Item): # imports from app.models.image_blob import ImageBlob #from app.models.user import User #from list_user import ListUse...

Django Time issues

Hi everyone, My app in django requires to tell the user what time an action occurred. Aside from asking the user what timezone he/she is in, is it possible for me to generate the time on the client end? Off the top of my head, are there a particular representation of time that is timezone independent, (unix time?), and then I can simpl...

How to add a python binding to C# ?

When you want to call C from python, you write a module like this: http://docs.python.org/extending/extending.html Now, I have a question: I want to write a module for use in Python with C#. How can I get C# to interact with native Python ? (Note: I'm not interested in Python.NET or IronPython). ...

How to index a Blog as a search engine ?

I want to create a simple search engine for learning purpose. I want to know how to index a simple blog site. A blog site has many pages and in every page there is a blogpost. But in every page there are other stuff in common as well ( header, footer, category block and other stuff ). In your opinion, How can I index this blog ? The ...

Proxying with django and gunicorn

I have a django application that i serve using gunicorn. I do that by using the method prescribed on the gunicorn site - embedding gunicorn into my django application. I'm trying to set up a proxy into my application so that when you go to "http://mysite.com/proxy/" it does proxy you to "http://mysite.com:8100". I know i can do that wi...

Using the RESTful interface to Google's AJAX Search API for "Did you mean"?

Is it possible to get spelling/search suggestions (i.e. "Did you mean") via the RESTful interface to Google's AJAX search API? I'm trying to access this from Python, though the URL query syntax is all I really need. Thanks! ...

SQLite vague syntax error

Ok, so I'm putting a list of 25 tuples, with each tuple containing 5 items, into an sqlite database. Each time I try the main code to write, I get "apsw.SQLError: SQLError: near "?": syntax error" Here's the code I'm running. Be aware that this is part of a much, much larger server project for a game, so some of the functions will be unk...

How to programmatically merge text files with potential conflicts (ala git or svn, etc)?

As part of a larger project, I want the ability to take two bodies of text and hand them to a merge algorithm which returns either an auto-merged result (in cases where the changes are not conflicting) or throws an error and (potentially) produces a single text document with the conflicting changes highlighted. Basically, I just want a ...

twisted dns doesn't work

I'd like to know why the following doesn't work. from twisted internet import defer, reactor from twisted.python.failure import Failure import twisted.names.client def do_lookup(do_lookup): d = twisted.names.client.getHostByName(domain) d.addBoth(lookup_done) def lookup_done(result): print 'result:', result reactor.sto...

reading a file in python

I am new to python been using it for graphics but never done it for other problems. My question is how to read this file which is tab or space delimited and has headers in python, i know how to do comma delimted file but not done this on? ID YR MO DA YrM MoM DaM 100 2010 2 20 2010 8 2010 30 110 2010 4 30 2010 9 2010 1...

PyGtk - Activating a combo box

If I have a combo box in pyGTK and would like to set a list of strings and then on clicking on one activate a command how would I do it? At the moment I have: self.combo_key = gtk.Combo() self.combo_key.set_popdown_strings(self.keys) self.combo_key.entry.set_text(db.keys()[0]) self.combo_key.entry.connect("activate", se...

wx.GenericDirCtrl Event's handling

Hi, I'm using this control but I can't to handle control click (and others events). This is my code: class BoExplorerPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent, wx.ID_ANY) self.initComponents() # initialize Window components def initComponents(self): print "Inizializzo i controlli" ...

Python/Numpy: Convert list of bools to unsigned int

What is the fastest (or most "Pythonic") way to convert x = [False, False, True, True] into 12? (If there is such a way.) What if x were instead a numpy.array of bools? Is there a special command for that? I have a large m-by-n array of booleans, where each n-element row represents a single low-dimensional hash of a high-dimensiona...