python

how to close all windows that Selenium opens?

Hey guys, I am using Selenium RC to do some test now. And the driver I use is python. But now, I faced a problem, that is: every time Selenium RC runs, and open a url, it opens 2 windows, one is for logging and the other one is for showing HTML content. But I can't close them all in script. here's my script: #!/usr/bin/env python #-*-c...

Forms not getting submitted with MECHANIZE in PYTHON!

from mechanize import * import cookielib from BeautifulSoup import BeautifulSoup br = Browser() br.open('http://casesearch.courts.state.md.us/inquiry/inquiry-index.jsp') br.select_form(name="main") br.find_control(name="disclaimer").selected = True reponse = br.submit() print reponse.read() The Above is my code. Now I expect it to sh...

Postgres raises a "ACTIVE SQL TRANSACTION" (Errcode: 25001)

I use psycopg2 for accessing my postgres database in python. My function should create a new database, the code looks like this: def createDB(host, username, dbname): adminuser = settings.DB_ADMIN_USER adminpass = settings.DB_ADMIN_PASS try: conn=psycopg2.connect(user=adminuser, password=adminpass, host=host) cur = conn.c...

What's Python equivalent to or equals expression, to get return foo or foo = 'bar' working?

I'd like to do something like: def get_foo(): return self._foo or self._foo = Bar() I am looking for the cleanest way to do it. Is it possible with or equals? My attempts failed: >>> foo = None >>> foo or 'bar' 'bar' >>> foo >>> foo or foo = 'bar' File "<stdin>", line 1 SyntaxError: can't assign to operator >>> foo or (foo =...

Escaping [ in Python Regular Expressions

Hi This reg exp search correctly checks to see if a string contains the text harry: re.search(r'\bharry\b','[harry] blah',re.IGNORECASE) However, I need to ensure that the string contains [harry]. I have tried escaping with various numbers of back-slashes: re.search(r'\b\[harry\]\b','[harry] blah',re.IGNORECASE) re.search(r'\b\\[h...

How to create an empty R vector to add new items

Hi, I want to use R in Python, as provided by the module Rpy2. I notice that R has very convenient [] operations by which you can extract the specific columns or lines, how could I achieve such a function by python scripts? My idea is to create a R vector and add those wanted elements into this vecotr so that the final vector is the same...

Qt vs java on kindle - darren??

I use my kindle to store large numbers of articles for research purposes. I would really like to have a operating system that can navigate to documents in different directories instead of “collections”. I can create directories on the Kindle, but in the main view these are all invisible, so I have to assign my documents to the collectio...

Do Python and wxPython run on Windows 98?

I'm trying to write an application that should work both on Windows 98 and XP. I decided to go with Python, but I'm having trouble even installing it on Win'98 (Python 2.7 installer says something about missing features of Windows Installer, but AFAIK 2.0 is the latest Windows Installer version compatible with '98). Does anyone have a...

Pythonpath Store

Where is my pythonpath stored? When I write import sys sys.path Where does python get that data? ...

testing assertion error in python

I'm doing a test suite in python based on the code provided by selenium and i get strange assertion errors when checking for the actual page like this: sel.click("link=Overview") sel.wait_for_page_to_load("30000") self.assertEqual("Naaya testing - Subtitlu testare", sel.get_title()) sel.click("link=Portal properties") sel.wait_for_page...

py2exe access 'other_resources'

So with py2exe you can add additional data inside the library zip file, now I was wondering, how do you access this data, do you need to read it out from the zipfile or can you just access it like any other file ? or perhaps there's another way to access it. ...

Plural of words using Open Office API for Python (UNO)

I would like to retrieve the plural words in different languages in Python. I know that openoffice has an API called uno (import uno) and it should give me this ability using openoffice's language dictionaries, but I could not find any reference to it. As a concrete example, I would something like this: >>> print getPluralOf('table') ...

Problem uploading image file to Amazon S3 in Django using BOTO Library

Hi there, I am a total beginner to programming and Django so I'd appreciate help that beginner can get his head round! I was following a tutorial to show how to upload images to an Amazon S3 account with the Boto library but I think it is for an older version of Django (I'm on 1.1.2 and Python 2.65) and something has changed. I get an ...

Python submodule internal references -- are they just crazy?

Apologies in advange for the newbie question. I can't get my head around this, and the docs don't help! Consider the following directory structure: spam.py foo / __init__.py ham.py eggs.py with the following code: # __init__.py # blank # ham.py print( "got ham!" ) # eggs.py print( "got eggs, importing ham!"...

PEXPECT with HOWIE (pyaiml chat bot) to make OBJECTIVE C gui to replace terminal

So I want to make a nice objective c GUI for HOWIE. Can someone show me how to use PEXPECT to communicate with howie? I don't want to use terminal, I want to use my gui as the interface. ...

Pythonic way to iterate over sequence, 4 items at a time

Possible Duplicate: What is the most pythonic way to iterate over a list in chunks? I am reading in some PNG data, which has 4 channels per pixel. I would like to iterate over the data 1 pixel at a time (meaning every 4 elements = 1 pixel, rgba). red_channel = 0 while red_channel < len(raw_png_data): green_channel, blue_...

Best way to overwrite some bits in a particular range

Given a series of bits, what's the best way to overwrite a particular range of them. For example, given: 0100 1010 Say I want to overwrite the middle 2 bits with 10 to make the result: 0101 0010 What would be the best way of doing this? At first, I thought I would just shift the overwriting bits I want to the correct position (1000...

How to test if a dictionary contains certain keys

Is there a nice approach to test if a dictionary contains multiple keys? A short version of: d = {} if 'a' in d and 'b' in d and 'c' in d: pass #do something Thanks. Edit: I can only use python2.4 -.- ...

How to alternate colors in stacked bar graph in matplotlib?

Dear All I want to alternate colors in a stacked bar graph in matplotlib..so as I can get different colors for the graphs depending on their type. I have two types except that they do not alternate regularly. so I need to check their type before I choose the colors. The problem is that it is conditional. I provide the type in an array,...

Asymmetric behavior for __getattr__, newstyle vs oldstyle classes

Hi, this is the first time I write here, sorry if the message is unfocuessed or too long. I was interested in understanding more about how objects'attributes are fetched when needed. So I read the Python 2.7 documentation titled "Data Model" here, I met __getattr__ and, in order to check whether I understood or not its behavior, I wro...