python

Website stress test in Python - Django

Hi folks, I'm trying to build a small stress test script to test how quickly a set of requests gets done. Need to measure speed for 100 requests. Problem is that I wouldn't know how to implement it, as it would require parallel url requests to be called. Any ideas? ...

Django: reverse lookup URL of feeds?

I am having trouble doing a reverse URL lookup for Django-generated feeds. I have the following setup in urls.py: feeds = { 'latest': LatestEntries, } urlpatterns = patterns('', # ... # enable feeds (RSS) url(r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}, name='feeds_vie...

ImportError: No Module named simplejson

I'm trying to run a command to install bespinclient on my Windows laptop but every time I execute the command python bootstrap.py --no-site-packages, I get an error saying: ImportError: No module named simplejson I'm using Mozilla build tools to run these Linux commands. ...

Enable PyGTK Eventbox motion-notify-event while is a Layout child

I noticed when a Eventbox is added into a Layout some events are missed, this does not happend for example adding it to a Fixed (very similar widget), I tried to restore the event mask in this way with no sucess: import pygtk import gtk def foo(widget, event): print event pygtk.require('2.0') window = gtk.Window(gtk.WINDOW_TOPL...

Accessing a dictionary value by custom object value in Python?

So I have a square that's made up of a series of points. At every point there is a corresponding value. What I want to do is build a dictionary like this: class Point: def __init__(self, x, y): self._x = x self._y = y square = {} for x in range(0, 5): for y in range(0, 5): point = Point(x,y...

Scraping a page from a secure URL which is possibly using a session ID

How to scrape a page like this. https://www.procom.ca/JobList.aspx?keywords=&amp;Cities=&amp;reference=&amp;JobType=0 It is secure, and requires a referrer? I can't get anything using wget or httplib2. If you go through this page, you get a list and it works on a browser but not the command line. https://www.procom.ca/jobsearch.aspx ...

Issue with making python program executable

I'm trying to make a program so that I can run it through the command line with the following format: ./myProgram I made it executable and put #!/usr/bin/env python in the header, but it's giving me the following error. env: python\r: No such file or directory However, when I run "python myProgram", it runs fine. Can someone tell ...

Google appengine datastore tree structure

I need to be able to make a tree like structure in the appengine database. I have try to make an object reference itself but have not gotten it to work. class Item(db.Model): children = db.ListProperty(db.ReferenceProperty(Item)) ...

How do I do this loop in Django template?

{% for d in mydata %} {{ d.title }} {% endfor %} However, I would like the first one to be bolded. How can I use the loop to say...if the d is the first one, then bold it? ...

Silence loggers and printing to screen - Python

Hi folks, I'm having a problem with my python script. It's printing massive amounts of data on the screen, and I would like to prevent all sorts of printing to screen. Edit: The library I'm using is mechanize, and it's printing a LOT of data on screen. I have set these to false with no luck! br.set_debug_redirects(False) br.set_d...

Downloading a Directory Tree with FTPLIB

This will not download the contents of sub-directories; how can I do so? import ftplib import configparser import os directories = [] def add_directory(line): if line.startswith('d'): bits = line.split() dirname = bits[8] directories.append(dirname) def makeDir(archiveTo): for dir in directories: newDir = os.path.join(archi...

'NoneType' object has no attribute 'get' error using SQLAlchemy

I've been trying to map an object to a database using SQLAlchemy but have run into a snag. Edit: Basically changed a whole bunch of stuff. Version info if handy: [OS: Mac OSX 10.5.8 | Python: 2.6.4 | SQLAlchemy: 0.5.8] The class I'm going to map: class Student(object): def __init__(self, id, name): self.id = id ...

Run Python CGI Script on Windows XP

I have a Windows XP machine that has Apache installed via a VisualSVNServer installation. I am . trying to get a simple python cgi script to run in my browser e.g. http://build.procepts.com.au:8080/hg/cgi-bin/test.cgi. However despite trying all the recommended approaches the browser only ever displays the plain text from the cgi scrip...

How do you use scripting language (PHP, Python, etc) to improve your productivity?

Hi, I'm a Delphi developer on the Windows platform, recently read the PHP tutorial at W3CSchools, it looks interesting. We all know scripting languages are very good at web site development, but I also want to utilize it to improve my productivity or get some tedious tasks done quickly, maybe some quick-and-dirty string/file processin...

Where do I put common code for if and elif?

For the example below: if a == 100: # Five lines of code elif a == 200: # Five lines of code Five lines of code is common and repeating how can I avoid it? I know about putting it a function or if a == 100 or a == 200: # Five lines of code if a == 100: # Do something elif a == 200: # Do somet...

Django : presenting a form very different from the model and with multiple field values in a Django-ish way ?

Hi ! I'm currently doing a firewall management application for Django, here's the (simplified) model : class Port(models.Model): number = models.PositiveIntegerField(primary_key=True) application = models.CharField(max_length=16, blank=True) class Rule(models.Model): port = models.ForeignKey(Port) ip_source = models.IPA...

[python]: path between two nodes

I'm using networkx to work with graphs. I have pretty large graph (it's near 200 nodes in it) and I try to find all possible paths between two nodes. But, as I understand, networkx can find only shortest path. How can I get not just shortest path, but all possible paths? UPD: path can contain each node only once. UPD2: I need something...

How to use the validation rules on both client-side and server-side?

I'm using jQuery validation system for client-side validation. The backend works with django. jQuery use an interesting set of rules in JSON format. Does exists something to use the same rules on django side or I need to code it myself? ...

assigning a list in python

pt=[2] pt[0]=raw_input() when i do this , and give an input suppose 1011 , it says list indexing error- " list assignment index out of range" . may i know why? i think i am not able to assign a list properly . how to assign an array of 2 elements in python then? ...

Problem's running unittest test suite OO

Hello, I have a test suite to perform smoke tests. I have all my script stored in various classes but when I try and run the test suite I can't seem to get it working if it is in a class. The code is below: (a class to call the tests) from alltests import SmokeTests class CallTests(SmokeTests): def integration(self): sel...