python

Python: Obtain a URL

Because I cant get this working: http://stackoverflow.com/questions/3250572/python-keyerror-with-form-getfirst I have an alternative option, I have a function in DTML which needs to obtain a URL: For example if the dtml webpage is located at www.blah.com/foo/foo2?variable=55 How would i obtain the URL of this page using a python...

How do I tell what type of data is inside python variable?

I have a list of variables.. inside the list are strings, numbers, and class objects. I need to perform logic based on each different type of data. I am having trouble detecting class objects and branching my logic at that point. if(type(lists[listname][0]).__name__ == 'str'): # <--- this works for strings elif(type(lists[listname][0])....

Automatically recognize patterns in images

Recently I downloaded some flags from the CIA world factbook. Now I want to "classify them. Get the colors Get some shapes (stars, moons etc.) While browsing I came across the Python Image Library which allows me to extract the colors (i.e. for Austria: #!/usr/bin/env python import Image bild = Image.open("au-lgflag.gif").convert("R...

Value Error: Too many values to unpack

When I execute it, it is giving me an eror i.e too many values to unpack? How do i make it to work properly. stack = util.Stack() closed = [] child = [] index = 0 currNode = problem.getStartState() node = currNode stack.push(node) while not stack.isEmpty(): node = stack.pop() if problem.isGoalState(node): ...

How to simulate re.findall for pexpect in python?

Is it possible to simulate re.findall in the pexpect module? I currently have a script that ssh's into a server using pexpect. I then have it send a command to the server which returns a bunch of lines in p.before (p being a pexpect spawn): JUNK JUNK JUNK IP ADDRESS 10.0.0.1 JUNK JUNK JUNK IP ADDRESS 10.0.0.3 JUNK JUNK JUNK JUNK JUNK J...

Python Hotmail login

I need a python script that prompts for a username and password and tries to login to Hotmail using those credentials, outputting whether they are valid or not. ...

Problem with python packages and tests

I have a directory struture like that: project | __init__.py | project.py | src/ | __init__.py | class_one.py | class_two.py | test/ | __init__.py | test_class_one.py Which project.py just instantiate ClassOne and run it. My problem is in the tests, I don't know how to import src classes. I've tried importing the...

How do you add Python Imaging Library (PIL) documentation (code completion, etc.) to Netbeans?

I am using Netbeans 6.8 as my Python IDE. I can use PIL (1.1.7) in my Python programs, but the code completion features are not working. I just downloaded the Source Kit edition of PIL, but I am unsure if it contains documentation/code completion entries that Netbeans can use. Does anyone know how to use the PIL documentation with Netb...

How to click a javascripted' radio button and fetch next page using Python (urllib2)? [WebScrape, selenium]

I am struggling with this. I have a fully tested python script. I have to make a small change wherein I have to first click on a radio button which in turn automatically executes a javascript function forwarding the page to a search form. My working platform : Linux Language : Python Radio button code : <input type="radio" language...

Optimize a list comprehension

Here is a code snippet that shows the code I would like to optimize: result = [(item, foo(item)) for item in item_list if cond1(item) and cond2(foo(item))] In the above snippet I call foo(item) twice. I can't think of a way to iterate over the list only once maintain both item and foo(item) for the conditional and ...

Regex help in python

I am trying to parse an output of about a hundred lines. The format of this output is as such: <random text> STATION "STATION_NAME_ONE": <random text> <random text> IP Address: 0.0.0.0 <random text> <SEVERAL LINES OF RANDOM TEXT> <random text> STATION "STATION_NAME_TWO": <random text> <random text> IP Address: 1.1.1.1 <random text> <SE...

Django-easytree doesn't register in admin.

I've decided to use django-easytree to create a forum hierarchy in django. I downloaded the source via Mercurial from bitbucket. And added the following to a new django app: http://bytebucket.org/fivethreeo/django-easytree/src/7ab11cd55b09/docs/install.rst I added a couple of fields to the model so now it looks like this: class Exampl...

wx.ProgressDialog disappears

The progress dialog disappers rather then the cancel button changing to a close button when it is to be destroyed (and the PD_AUTO_HIDE flag is not set). progressDlg = wx.ProgressDialog("Organizing music files", "This may take some time..", maximum=9999...

Changing the size of a wx.ProgressDialog

The size of the ProgresDialog is too narrow to hold the text that I need to display... I tryed to change the size of the dialog by calling the SetSize method on the dialog after it is created. This fixed the size of the dialog but on creation of the dialog the gauge size is initially smaller and then jumps in size to fit the dialog box...

Help me fix this bug in Suds

There is a bug in the Python SOAP module Suds which is preventing me from making progress on a project. It seems as though the internal definitions for complex data types don't include inherited properties. The data type is defined in the WSDL and extends the standard xsd:string data type. Take a look at the bug's open ticket. Update: ...

Python: obtain the url?

Whats the simpliest way to obtain the URL of the webpage you are currently on? For example if i have a python function and i call it from within a webpage, whats the best way to obtain the URL. What maybe an easier question how is how do you obtain the variables passed within the URL i.e. after the "?" I've tried calling: def return_q...

What's the best performing xml parsing for GAE (Python Version)?

I think we all know this page, but the benchmarks provided dated from more than two years ago. So, I would like to know if you could point out the best xml parser around. As I need just a xml parser, the more important thing to me is speed over everything else. My objective is to process some xml feeds (about 25k) that are 4kb in size (t...

algorithm for DFS

Can anybody tell me the algorithm for depth first search (DFS)? I need to write the code for DFS in python. ...

Numpy and line intersections

How would I use numpy to calculate the intersection between two line segments? In the code I have segment1 = ((x1,y1),(x2,y2)) and segment2 = ((x1,y1),(x2,y2)). Note segment 1 does not equal segment2. So in my code I've also been calculating the slope and y-intercept, it would be nice if that could be avoided but I don't know of a way...

help in executing the code

My code: nodes = [] stack = util.Stack() child = [] currNode = problem.getStartState() stack.push(currNode) while not stack.isEmpty(): nodes = stack.pop() if problem.isGoalState(nodes): return nodes else: child = problem.getSuccessors(nodes) ...