python

Placing a Button in UltimateListCtrl using wxPython

I'm new to Pythong and I have been trying to get a button within UltimateListCtrl. I still can't figure out what I'm doing wrong. Here is my code: try: from agw import ultimatelistctrl as ULC except ImportError: # if it's not there locally, try the wxPython lib. from wx.lib.agw import ultimatelistctrl as ULC self.table = ULC....

Learning Python

Hi all, Was coding something in Python. Have a piece of code, wanted to know if it can be done more elegantly... # Statistics format is - done|remaining|200's|404's|size statf = open(STATS_FILE, 'r').read() starf = statf.strip().split('|') done = int(starf[0]) rema = int(starf[1]) succ = int(starf[2]) fails = int(starf[3]) size = in...

django middleware redirect infinite loop

I have a middleware that checks a session value and redirects depending that value. My problem is, it is creating an infinite redirect loop and I'm not sure why. So, what I want to do is check to see if the value of the session visible is yes and if not redirect the user to my test view. Here is my middleware: class CheckStatus(ob...

Is there a way to serve up a Python dictionary to a compatible type in Visual Basic 6 using win32com?

Is there a way to serve up a Python dictionary to a compatible type in Visual Basic 6 using win32com? ...

Loading numpy into IronPython

Hi, I've recently installed Ironpython + tools and having trouble loading external modules (numpy). this is my test code: import numpy numpy.test() when writing my simple test, intellisense can find numpy, however when it's run from vs2010, I get: ImportException was unhandled by user code: No module named numpy IronPython Consol...

What is in your Python Interactive Startup Script?

Are there any common timesavers that people put in Python Interactive Startup scripts? I made a dopey one to help me know where I am when I try to do relative file operations or imports, using a win32 module to change the name of the console window. import sys import os import win32api __title_prefix = 'Python %i.%i.%i %s %s' % (sys.ve...

TypeError: 'type' object is unsubscriptable using python on google app engine .

i use gaefy.db.properties 's JsonProperty # -*- coding: utf-8 -*- """ gaefy.db.properties ~~~~~~~~~~~~~~~~~~~ Extra properties for App Engine Models. :copyright: 2009 by tipfy.org. :license: BSD, see LICENSE.txt for more details. """ import csv, pickle, simplejson from cStringIO import StringIO from google.appengi...

writing large CSV files - dictionary based CSV writer seems to be the problem

Hi, I have a big bag of words array (words, and their counts) that I need to write to large flat csv file. In testing with around 1000 or so words, this works just fine - I use the dictwriter as follows: self.csv_out = csv.DictWriter(open(self.loc+'.csv','w'), quoting=csv.QUOTE_ALL, fieldnames=fields) where fields is list of words (...

Google Appengine: objects passed to a template changes their addresses in memory

I query an array of objects from DB, then compare addresses of the objects in Model and in View. They differs! Why? I want access the same objects as from template as from business logics code. I wouldn't ask for it but it really bother me because function calls are disallowed in Django-styled templates and I even can't assign custom pr...

Web.py URL Mapping not accepting '/'

So every web.py tutorial I've seen includes this line: urls = ( '/', 'index', ) And then, later on, the index class is defined with a GET function and so on. My problem is, this doesn't work. Using the code above, I get a 404 error. Using the following mapping works: urls = ( '/.*', 'index', ) But that's going to catch, at ...

How to specify a full click in Python Tkinter

The following python line will bind the method "click" to the event when the user presses the mouse button while the pointer is on the widget; no matter where the pointer is when she releases the button. self.bind('<Button-1>',self.click) If I use "ButtonRelease" instead of "Button" in the code, it seems that the method "click" will b...

What is the most useful Python Trick/Shortcut?

Possible Duplicate: Hidden features of Python What trick or shortcut is the most useful when you code in Python and why? Please post one item per post so that the readers can rate. ...

Wrappers around lambda expressions

I have functions in python that take two inputs, do some manipulations, and return two outputs. I would like to rearrange the output arguments, so I wrote a wrapper function around the original function that creates a new function with the new output order def rotate(f): h = lambda x,y: -f(x,y)[1], f(x,y)[0] return h f = lambda...

Why is my code stopping?

Hey I've encountered an issue where my program stops iterating through the file at the 57802 record for some reason I cannot figure out. I put a heartbeat section in so I would be able to see which line it is on and it helped but now I am stuck as to why it stops here. I thought it was a memory issue but I just ran it on my 6GB memory ...

How do you make a choices field in django with an editable "other" option?

( ('one', 'One'), ('two', 'Two'), ('other', EDITABLE_HUMAN_READABLE_CHOICE), ) So what I would like is a choices field with some common choices that are used frequently, but still be able to have the option of filling in a custom human readable value. Is this possible or is there some better way of doing this that I am co...

Would someone explain to me why type(foo)(bar) is so heavily discouraged?

I have a dict of configuration variables that looks something like this: self.config = { "foo": "abcdef", "bar": 42, "xyz": True } I want to be able to update these variables from user input (which, in this case, will always be in the form of a string). The problem I'm facing is obvious, and my first solution seemed good e...

How to strip "()," from Python, PyODBC, SQL Returns?

Hi, I grabbed a bunch of SQL IDs I need to update with Python and PyODBC: import pyodbc cnxn = pyodbc.connect('DSN=YesOne;PWD=xxx') cursor = cnxn.cursor() cursor.execute("SELECT ID FROM One.dbo.Two WHERE STATUS = 'OnGoing' AND ID = ''") I have a second bit of code that updates the IDs: cursor.execute("Update One.dbo.Two SET STATUS =...

change background color highlight for errors detected by pylint with ropevim and ropemode installed

It changes the background to red, I can't read the text to correct the error! How can I configure a different highlight? Does it have a setting? ...

AttributeError when unpickling an object

I'm trying to pickle an instance of a class in one module, and unpickle it in another. Here's where I pickle: import cPickle def pickleObject(): object = Foo() savefile = open('path/to/file', 'w') cPickle.dump(object, savefile, cPickle.HIGHEST_PROTOCOL) class Foo(object): (...) and here's where I try to unpickle: ...

How to check if key exists in datastore without returning the object

Hello, I want to be able to check if a key_name for my model exists in the datastore. My code goes: t=MyModel.get_by_key_name(c) if t==None: #key_name does not exist I don't need the object, so is there a way (which would be faster and cost less resource) to ccheck if the object exist without returning it? I only know the...