python

Python example of Joe's Erlang websocket example

I've just been working through the erlang websockets example from Joe Armstrong's blog I'm still quite new to erlang so I decided to write a simple server in python that would help teach me about websockets (and hopefully some erlang by interpreting joe's code). I'm having two issues: 1) Data I receive from the page includes a 'ÿ' as th...

Python object conversion

Greetings, let assume that we have a an object k of type class A. We defined a second class B(A). What is the best practice to "convert" object k to class B and preserve all data in k? Thanks, Shakov ...

Python: Finding average of a nested list

I have a list a = [[1,2,3],[4,5,6],[7,8,9]] Now I want to find the average of these inner list so that a = [(1+4+7)/3,(2+5+8)/3,(3+6+9)/3] 'a' should not be a nested list in the end. Kindly provide an answer for the generic case ...

Loading a document on OpenOffice using an external Python program

I'm trying to create a python program (using pyUNO ) to make some changes on a OpenOffice calc sheet. I've launched previously OpenOffice on "accept" mode to be able to connect from an external program. Apparently, should be as easy as: import uno # get the uno component context from the PyUNO runtime localContext = uno.getComponentCon...

Python: Visualization tool for graphs

Guys I have asked this question before but did not receive a single comment or answer I want to simulate a search algorithm on a power law graph and want to visually see the algorithm move from one node to another on the graph. How do I do that? ...

Returning the first N characters of a unicode string

I have a string in unicode and I need to return the first N characters. I am doing this: result = unistring[:5] but of course the length of unicode strings != length of characters. Any ideas? The only solution is using re? Edit: More info unistring = "Μεταλλικα" #Metallica written in Greek letters result = unistring[:1] returns-> ...

Efficient reordering of coordinate pairs (2-tuples) in a list of pairs in Python

I am wanting to zip up a list of entities with a new entity to generate a list of coordinates (2-tuples), but I want to assure that for (i, j) that i < j is always true. However, I am not extremely pleased with my current solutions: from itertools import repeat mems = range(1, 10, 2) mem = 8 def ij(i, j): if i < j: return (i, ...

Log onto a Website and select options using Python

Hello, I am trying to log onto a website using Python. I have written the code to connect to the target but I need to login and select a button on the website and wait for a response. I have looked at the HTTP Protocol in Python and was thinking of using 'HTTPConnection.putrequest'. I am not sure how to do this, I have the code I have s...

Simple question: How to enter item into Google AppEngine Datastore?

I want to check if an email is in my database in Appengine, and if not: then enter it into the datastore. I am new to python. Why is this simple code not working? (Also If there is a better way/more efficient way to write this, please tell me) (I get the error: BadArgumentError: Unused positional arguments [1]) class EmailAdd(webapp....

Parsing a range of integers in a list

Hey guys! I've just began learning Python and I've ran into a small problem. I need to parse a text file, more specifically an HTML file (but it's syntax is so weird - divs after divs after divs, the result of a Google's 'View as HTML' for a certain PDF i can't seem to extract the text because it has a messy table done in m$ word). Any...

PyQt and Bespin (KDE style)

What tab widget decorate by Bespin Tabs? I tried QTabWidget, QTabBar, KTabWidget, KTabBar, bau no effect. What Im doing wrong? All KDE apps and SMPlayer decorate by Bespin, but acetoneiso and PyQt apps have regular tabs=( I mean this Bespin: http://kde-look.org/content/show.php/Bespin?content=63928 ...

Identify groups of continuous numbers in a list

I'd like to identify groups of continuous numbers in a list, so that: myfunc([2, 3, 4, 5, 12, 13, 14, 15, 16, 17, 20]) returns: [(2,5), (12,17), 20] And was wondering what the best way to do this was (particularly if there's something inbuilt into Python). Edit: Note I originally forgot to mention that individual numbers should be...

Screen Capture Under Win7 of JOGL Applet

Hi I'm trying to take a screen shot of an applet running inside a browser. The applet is using JOGL (OpenGL for Java) to display 3D models. (1) The screen shots always come out either black or white.The current solution uses the usual GDI calls. Screen shots of applets not running OpenGL are fine. A few examples of JOGL apps can be foun...

Python linked list O(1) insert/remove

Hey, I am looking for a linked list and related algorithms implementation for Python. Everyone I ask just recommends using built in Python lists, but performance measurements indicate that list insertion and removal is a bottleneck for our application. It's trivial to implement a simple linked list, but I wonder if there is a mature lib...

how to change process name of python script running on windows machine

Windows Task Manager (Processes Tab) lists all the running processes. the image name for python scripts is always python.exe (or pythonw.exe or the name of the python interpreter). it there a nice way to change the image name corresponding to a python script? (I mean other than changing the name of the python interpreter) ...

python dictionary question

All, This is the request from the template that i get u'subjects': [u'7', u'4', u'5', u'3', u'2', u'1'] In my views how to extract the values like 7 4 5 3 2 1 How do i extract the above sequence from new_subjects=request.POST.get('subjects') Thanks. ...

How to launch winpdb from a Python script?

When I have to deal with bugs in Python code, I often insert breakpoints so during execution I'm being dropped into the debuger when a breakpoint is reached. I've been mostly using pdb (command line) and pudb (ncurses interface). Is it possible to launch winpdb instead in such situation? What's the breakpoint code I shall include in my ...

Use getControl to control objects other than the name variable

Hello, I am using the Zope testbrowser which has been recommended in my last question. The problem that I am facing is that I can use the getControl function to control different objects like: password, username etc. I am trying to submit the page to get to the next page but the submit button has no 'name' variable, just an 'id' variab...

Basics of string based protocol security

I wasn't sure how to phrase this question, so apologies in advance if it's a duplicate of something else. I wanted to sanity check how I've secured my twisted based application and think I've done a good job at it, but it's been over a decade since I've written anything that uses raw or managed sockets. Authentication transaction: Cl...

Is AMQP production ready?

I'd like to use AMQP to join two services one written in C# and other written in python. I'm expecting quite large volume of messages per second. Is there any AMQP Broker that is production ready? Are the python & .net bindings good enough? ...