python

Programmatic Form Submit

Hi, I want to scrape the contents of a webpage. The contents are produced after a form on that site has been filled in and submitted. I've read on how to scrape the end result content/webpage - but how to I programmatically submit the form? I'm using python and have read that I might need to get the original webpage with the form, ...

python and regular expression with unicode

I need to delete some unicode symbols from the string 'بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ' I know they exist here for sure. I try: re.sub('([\u064B-\u0652\u06D4\u0670\u0674\u06D5-\u06ED]+)', '', 'بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ') but it doesn't work. String stays the same. ant suggestion what i do wrong? ...

Scripting inside a Python application

I'd like to include Python scripting in one of my applications, that is written in Python itself. My application must be able to call external Python functions (written by the user) as callbacks. There must be some control on code execution; for example, if the user provided code with syntax errors, the application must signal that. ...

Which Python GUI framework?

I am a newbie at Python. I see a few GUIs listed in the Python wiki but I would like to know what you think is the easiest to use. I have 2 requirements Have buttons, tabs and a textbox Be able to load an image in memory/from the web (I am using pyCURL to download the temp image(s)) ...

python introspection not showing functions for Lock

When I try to use introspection to look at what methods are available on threading.Lock I don't see what I would expect. Specifically I don't see acquire, release or locked. Why is this? Here's what I do see: >>> dir (threading.Lock) ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__ini...

Finding when the ActiveApplication changes in OSX through Python...

Is there a way to find when the activeApplication changes in OSX through Python and AppKit? I know how to find out launchedApplication and activeApplication ( please refer to my other question here: http://stackoverflow.com/questions/373020/finding-the-current-active-window-in-mac-os-x-using-python ) ...

Python: Lock directory access under windows

Hi, I'd like to be able to lock directory access under windows. The following code work greatly with file or directory under POSIX system: def flock(fd, blocking=False, exclusive=False): if exclusive: flags = fcntl.LOCK_EX else: flags = fcntl.LOCK_SH if not blocking: flags |= fcntl.LOCK_NB fcntl....

Python POST data using mod_wsgi

This must be a very simple question, but I don't seem to be able to figure out. I'm using apache + mod_wsgi to host my python application, and I'd like to get the post content submitted in one of the forms -however, neither the environment values, nor sys.stdin contains any of this data. Mind giving me a quick hand? Edit: Tried already...

Is there a simple way in Python to create a file which can be written to in one thread and read in a different one?

In the python program I'm writing, I've got a thread which iterates over a large structure in memory and writes it incrementally into a file-like object. I've got another thread which takes a file-like object and writes it to disk. Is there an easy way to connect the two, such that any data input from the first thread will be buffered ...

SDL or PyGame international input.

So basically, how is non-western input handled in SDL or OpenGL games or applications? Googling for it reveals http://sdl-im.csie.net/ but that doesn't seem to be maintained or available anymore. Just to view the page I had to use the Google cache. To clarify, I'm not having any kind of issue in terms of the application displaying t...

Override a method at instance level

Hi! Is there a way in Python to override a class method at instance level? For example: class Dog: def bark(self): print "WOOF" boby = Dog() boby.bark() # WOOF # METHOD OVERRIDE boby.bark() # WoOoOoF!! Thanks ...

Python Ternary Operator

I was under the impression that Python had a ternary operator... But then I did some research, Not enough to find out for sure though Thought I'd ask the professionals ;) ...

Python threads stack_size and segfaults

A web crawler script that spawns at most 500 threads and each thread basically requests for certain data served from the remote server, which each server's reply is different in content and size from others. i'm setting stack_size as 756K's for threads threading.stack_size(756*1024) which enables me to have the sufficient number of t...

Download from EXPLOSM.net Comics Script [Python]

So I wrote this short script (correct word?) to download the comic images from explosm.net comics because I somewhat-recently found out about it and I want to...put it on my iPhone...3G. It works fine and all. urllib2 for getting webpage html and urllib for image.retrieve() Why I posted this on SO: how do I optimize this code? Would RE...

Can I use a ForeignKey in __unicode__ return?

I have the following classes: Ingredients, Recipe and RecipeContent... class Ingredient(models.Model): name = models.CharField(max_length=30, primary_key=True) qty_on_stock = models.IntegerField() def __unicode__(self): return self.name class Recipe(models.Model): name = models.CharField(max_length=30, primary_...

How to download a file over http with authorization in python 3.0, working around bugs?

I have a script that I'd like to continue using, but it looks like I either have to find some workaround for a bug in Python 3, or downgrade back to 2.6, and thus having to downgrade other scripts as well... Hopefully someone here have already managed to find a workaround. The problem is that due to the new changes in Python 3.0 regard...

How do I install MySQL and the python MySql package on OSX Leopard? Or how do I learn about being a web developer using OSX?

I'm new to the Mac OS and I'm just about ready to throw my brand new MacBook pro out the window. Every tutorial on setting up a Django development environment on Leopard is insidiously wrong. They are all skipping over one step, or assuming you have setup something one way, or are just assuming that I know one thing that I must not. I...

Threads in Python

General tutorial or good resource on how to use threads in Python? When to use threads, how they are effective, and some general background on threads [specific to Python]? ...

Python : How to check whether a variable is a class or not?

I was wondering how to check whether a variable is a class (not an instance!) or not. I've tried to use the function isinstance(object, class_or_type_or_tuple) to do this, but I don't know what type would a class will have. For example, in the following code class Foo: pass isinstance(Foo, **???**) # i want to make this return True....

How do I send an ARP packet through python on windows without needing winpcap?

Is there any way to send ARP packet on Windows without the use of another library such as winpcap? I have heard that Windows XP SP2 blocks raw ethernet sockets, but I have also heard that raw sockets are only blocked for administrators. Any clarification here? ...