python

Getting Forms on Page in Python

I'm working on a project (web vulnerability scanner). I have compleate 30% of the program it can scan only GET Methods. but having a problem now. I have no idea how I shall make the program pentest the POST Method (the forms) . I'm having a idea to make it Extract the form data/names from all the pages on the website. but having no ide...

What's a good embedded browser for a pygtk application?

I'm planning on using an embedded browser in my pygtk application and I'm debating between gtkmozembed and pywebkitgtk. Is there any compelling difference between the two? Are there any third options that I don't know about? It should be noted that I won't be using this to access content on the web. I'm mainly using it for UI purpose...

How to keep track of thread progress in Python without freezing the PyQt GUI?

Questions: What is the best practice for keeping track of a tread's progress without locking the GUI ("Not Responding")? Generally, what are the best practices for threading as it applies to GUI development? Question Background: I have a PyQt GUI for Windows. It is used to process sets of HTML documents. It takes anywhere from t...

Lazy choices in Django form

I have a Django my_forms.py like this: class CarSearchForm(forms.Form): # lots of fields like this bodystyle = forms.ChoiceField(choices=bodystyle_choices()) Each choice is e.g. ("Saloon", "Saloon (15 cars)"). So the choices are computed by this function. def bodystyle_choices(): return [(bodystyle.bodystyle_name, '%s...

How to tell for which object attribute pickle fails?

When you pickle an object that has some attributes which cannot be pickled it will fail with a generic error message like: PicklingError: Can't pickle <type 'instancemethod'>: attribute lookup __builtin__.instancemethod failed Is there any way to tell which attribute caused the exception? I am using Python 2.5.2. Even if I understand...

Good book for Python beginners

I'm going to mentor a group of biologists that will be learning Python as their first programming language. I would like to provide them with a book that is written from this perspective, i.e. no expectation of previous programming experience. Any suggestions? Duplicate: http://stackoverflow.com/questions/34570/what-is-the-best-qu...

Statistics with numpy

I am working at some plots and statistics for work and I am not sure how I can do some statistics using numpy: I have a list of prices and another one of basePrices. And I want to know how many prices are with X percent above basePrice, how many are with Y percent above basePrice. Is there a simple way to do that using numpy? ...

admin template for manytomany

I have a manytomany relationship between publication and pathology. Each publication can have many pathologies. When a publication appears in the admin template, I need to be able to see the many pathologies associated with that publication. Here is the model statement: class Pathology(models.Model): pathology = models.CharField(...

With Twisted, how can 'connectionMade' fire a specific Deferred?

This is part of a larger program; I'll explain only the relevant parts. Basically, my code wants to create a new connection to a remote host. This should return a Deferred, which fires once the connection is established, so I can send something on it. I'm creating the connection with twisted.internet.interfaces.IReactorSSL.connectSSL....

How can I get the newest file from an FTP server?

I am using Python to connect to an FTP server that contains a new list of data once every hour. I am only connecting once a day, and I only want to download the newest file in the directory. Is there a way to do this? ...

How do I add plain text info to forms in a formset in Django?

I want to show a title and description from a db query in each form, but I don't want it to be in a charfield, I want it to be html-formatted text. sample template code: {% for form, data in zipped_data %} <div class="row"> <div class="first_col"> <span class="title">{{ data.0 }}</span> <div class="desc"> ...

Detect when a Python module unloads

I have a module that uses ctypes to wrap some functionality from a static library into a class. When the module loads, it calls an initialize function in the static library. When the module is unloaded (presumably when the interpreter exits), there's an unload function in the library that I'd like to be called. How can I create this hook...

Python c-api and unicode strings

I need to convert between python objects and c strings of various encodings. Going from a c string to a unicode object was fairly simple using PyUnicode_Decode, however Im not sure how to go the other way //char* can be a wchar_t or any other element size, just make sure it is correctly terminated for its encoding Unicode(const char *st...

How to program a schedule...

Hello! I have to build a program that schedules based on certain rules. I'm not sure how to explain it, so let me give you an example.. You have Five People A,B,C,D,E. And you Have another set of people S1 S2 S3 S4 S5 S6 S7. If A B C D and E are available every hour from 9 to 5, and S1 S2 S3 S4 S5 S6 and S7 have a list of 3 people they...

Django "SuspiciousOperation" Error While Deleting Uploaded File

I'm developing in Django on Windows XP using the manage.py runserver command to serve files. Apache isn't involved. When I login to the administration and try to delete a file I get a "SuspiciousOperation" error. Here's the traceback: http://dpaste.com/123112/ Here's my full model: http://dpaste.com/hold/123110/ How can I get rid of ...

In Python, how might one log in, answer a web form via HTTP POST (not url-encoded), and fetch a returned XML file?

I am basically trying to export a configuration file, once a week. While the product in question allows you to manually log in via a web client, enter some information, and get an XML file back when you submit, there's no facility for automating this. I can get away with using Python 2.5 (have used for a while) or 2.6 (unfamiliar) to d...

Split tags in python

I have a file that contains this: <html> <head> <title> Hello! - {{ today }}</title> </head> <body> {{ runner_up }} avasd {{ blabla }} sdvas {{ oooo }} </body> </html> what is the best more pythonic way to extract the {{today}}, {{runner_up}} etc? I know it can be done with splits/r...

Project Euler #12 in python

Hi, I'm trying to solve Euler problem #12 which is 'What is the value of the first triangle number to have over five hundred divisors?' (A triangle number is a number in the sequence of the sum of numbers i.e. 1+2+3+4+5...)I'm pretty sure that this is working code but I don't know because my computer is taking too long to calculate it. D...

Are there any declaration keywords in Python?

Are there any declaration keywords in python, like local, global, private, public etc. I know it's type free but how do you know if this statement: x = 5; Creates a new variable. or Sets an existing one. ...

What's the reason of providing some of the default methods in the global scope in Python?

What's the reason of providing some of the default methods in the global scope, like the len function, instead of providing them on an instance level, like: list.len() instead of: len (list) I find methods like len to be harder to discover than instance methods. Is there any reason behind this? ...