python

Add a member variable / method to a Python generator?

Can I add a member variable / method to a Python generator? I want something along the following lines, so that I can "peek" at member variable j: def foo(): for i in range(10): self.j = 10 - i yield i gen = foo() for k in gen: print gen.j print k Yes, I know that I can return i AND j every time. But I do...

DOM to use with SpiderMonkey?

I'm trying to use the GoogleMaps javascript library from inside of SpiderMonkey using the pythong wrapper, but I can't because of the lack of a DOM. Is there some way I can integrate a DOM into this so that I can get this to work? ...

How properly bundle&install python to windows users

I need to redistribute Python 2.6 for my users. Currently, I execute the silent instalation for the msi installer from http://www.python.org/download/, but I have some problems, like if other version of python is installed this not get the default. In the other hand, despite this could be rare, if a user have already python and I insta...

mod_wsgi on Snow Leopard python version mismatch

Hello, I'm trying to run mod_wsgi 3.1 under Apache 2.2.14 using a non-default python installation on Mac OS X 10.6. After downloading the mod_wsgi source I run: sudo apachectl -k stop then ./configure --with-python=/usr/local/Cellar/python/2.6.4/bin/python make sudo make install I then start up apache again sudo apachectl -k sta...

Simple code but can't find the error (PyS60 but not specific)

Merry Christmas... I'm a python beginner and now it's freakin me out.... L = [] file = urllib.urlopen("http://someurl.com/someText.txt") line = file.readline() while line != "" : L.append(line) line = file.readline() appuifw.selection_list(choices=L) and I get this error: line = file.readline() ^ SyntaxError: invalid syntax ...

PyCURL: TLS Handshake Error

I'm using PyCURL to test a redirection service we're offering- a user hits http://xyz.com/asdf/ and gets redirected to https://a.com, https://b.com and https://c.com. I'm trying to use PyCURL to request http://xyz.com, and print out (but not HTTP request) the string "https://{a|b|c}.com", but whenever the destination URL is HTTPS and no...

A little misunderstanding timers in python

Hi guys, can somebody tell me how to use this class timers from python in my code more than one time. import MOD class timer: def __init__(self, seconds): self.start(seconds) def start(self, seconds): self.startTime = MOD.secCounter() self.expirationTime = self.startTime + seconds if seconds...

symbian v3 python center button caption

I am using python for s60 to make a symbian application. The body is set as appuifw.text. I have bound the center button (select) with a function. It is possible to add a caption over the center button like in other applications? ...

Open 3rd party Application with Python

Hi I am on Windows XP and have a 3rd party application that I want to be able to open using a Python script. How do I go about doing it? from win32com.client import Dispatch mySuite = Dispatch("TestSuite.Application") throws an error File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 312, in RunScri...

Python regular expression inconsistency

I am getting different results based on whether I precompile a regular expression: >>> re.compile('mr', re.IGNORECASE).sub('', 'Mr Bean') ' Bean' >>> re.sub('mr', '', 'Mr Bean', re.IGNORECASE) 'Mr Bean' The Python documentation says Some of the functions are simplified versions of the full featured methods for compiled regular express...

How to redirect to a newly created object in Django without a Generic View's post_save_redirect argument

I'm trying to redirect a user to a newly created object's object.get_absolute_url() after saving a form. I'm not using a generic view, so I can't use the post_save_redirect argument. The relevant portion of the view is like so: if form.is_valid(): form.save() return HttpResponseRedirect(reverse('story_detail', args=(story.user, ...

python fetching multiple pages using post and cookies

Hi. Got a test site that I'm fetching. The site uses the POST method, as well as cookies. (Not sure that the cookies are critical, but i'm inclined to think they are..) The app presents a page, with a "next button" to generate the subsequent pages. I've used LiveHttpHeaders/Firefof to determine what the post data should be in the query...

Grab Focus for Frame after Shortcut Pressed in wxPython on GNOME

I'm building an app that uses global shortcut keys (using python-keybinder), but there's a problem. The frame pops up and raises properly but doesn't have focus. I have to click on frame. After I press my keyboard shortcut my frame appears, but it is not focused. I can see that the frame I was focused on previously (e.g. my Firefox fra...

redirecting standard output to the calling process

hello everyone Im no bash expert so bear with me I have a python script thats starting other processes, which then emit log messages on stdout. what bash command would I use to redirect stdout of those child processes back to the stdout of the parent process (the python script thats starting the processes)? thank you in advance ...

How to call main() of a python script with arguments from mod_python.publisher ?

Hi, I use a mod_python publisher function which calls the main() function of another python script with a custom built argv list. When I execute the publisher script from shell command line it works. But when I tried it through apache2 with mod_python, I get the error (shown below) that main takes no arguments. File "/var/www/wabaSe...

Python logging before you run logging.basicConfig?

It appears that if you invoke logging.info() BEFORE you run logging.basicConfig, the logging.basicConfig call doesn't have any effect. In fact, no logging occurs. Where is this behavior documented? I don't really understand. ...

How to get value on a certain index, in a python list?

I have a list which looks something like this List = [q1,a1,q2,a2,q3,a3] I need the final code to be something like this dictionary = {q1:a1,q2:a2,q3:a3} if only I can get values at a certain index e.g List[0] I can accomplish this, is there any way I can get it? ...

What's the difference between _b and b in this place,thanks

class a: def __init__(self): self._b()#why here use _b,not b,What's the difference self._c='cccc'#why here use _c,not c,What's the difference def _b(): print 'bbbb' a.py class a: def __init__(self): self._b()#why here use _b,not b,What's the difference self._c='cccc'#why here use _c,...

Extending numpy with cython

I am trying to wrap a header file which has lots of functions like this test.h void test(int N, int* data_in, int* data_out); so that I can use those from numpy. Right now I have the following cython code: test.pyx import numpy as np cimport numpy as np ctypedef np.int_t itype_t cdef extern from 'VolumeForm.h': void _test '...

Why isn't count() working the way I expect in my code?

class FriendshipManager(models.Manager): def are_friends(self, user1, user2): if self.filter(from_user=user1, to_user=user2).count() > 0: return True if self.filter(from_user=user2, to_user=user1).count() > 0: return True return False and i found count() so ...