python

Python Implementation of PageRank

I am attempting to understand the concepts behind Google PageRank, and am attempting to implement a similar (though rudimentary) version in Python. I have spent the last few hours familiarizing myself with the algorithm, however it's still not all that clear. I've located a particularly interesting website that outlines the implementat...

How to find out the current widget size in tkinter?

I'm using Python and Tkinter, and I need to know the current dimensions (width, height) of a widget. I've tried somewidget["width"], but it returns only a fixed value, and is not updated whenever the widget size changes (e.g. when the window is resized). ...

Minimax: how can I implement it in Python?

As long as I've been a programmer I still have a very elementary level education in algorithms (because I'm self-taught). Perhaps there is a good beginner book on them that you could suggest in your answer. ...

Python: Fetching and parsing text from html files

I'm trying to work on a project about page ranking. I want to make an index (dictionary) which looks like this: file1.html -> [[cat, ate, food, drank, milk], [file2.html, file3.html]] file2.html -> [[dog, barked, ran, away], [file1.html, file4.html]] Fetching links is easy - look for anchor tags. My question is - how do I fetch text...

How to scroll a tkinter canvas to an absolute position?

I'm using Python and tkinter. I have a Canvas widget that will display just one image. Most times the image will be larger than the canvas dimensions, but sometimes it will be smaller. Let's just focus on the first case (image larger than canvas). I want to scroll the canvas to an absolute position that I have already calculated (in pix...

Safe way to uninstall old version of python

I want to update my Python framework on Mac and delete the old versions but I am not sure if is safe to rm -fr /Library/Frameworks/Python.framework/Versions/2.4 - 2.5 - 2.6 -3.0 etc. Any suggestion? ...

rotating tire rims of car opengl transformations

Here is the draw function which draws the parts of the car, in this function car rims is checked and flag is checked, and i need to rotate the tire rim as i move the car. Something is not working since the rims are rotated but taken out from the car model, when i press up arrow key, but the car does move. I also initialized self.fFlag =...

Preparing a web site for international usage

I am preparing to develop a web application that will (hopefully) be used by an audience with many different native languages. What should I do to prepare my software project to have the user interface be almost entirely internationalized? Are there any software stacks that make this easier? ...

Networkx: how to draw coloured edges?

Hi, I've built a graph using the following code: G = networkx.Graph() G.add_edges_from([list(e) for e in P + Q + R]) colors = "bgrcmyk" color_map = [colors[i] for i in range(n/2)] # add colors for i in range(len(P)): edge = list(P[i]) G[edge[0]][edge[1]]['edge_color'] = color_map[i] for i in range(len(P)): edge = lis...

Python IDLE will not open

After fumbling with some keys on my keyboard while trying to get a script to run by clicking on Run in python IDLE I must of did something, because now python will not open. It opens from the command prompt fine, but the normal way it will not open whatsoever. I tried repairing and reinstalling. Still no luck. I am on Windows 7 machines ...

How to change email account details in appcfg.py google appengine SDK

I have hosted GAE apps with two different email ids! When i first time used appcfg.py to update my app then it prompted me for email id and password but later it doesnot. How to i change the saved email id and password? I tried to use --email= flag with appcfg.py, but it dint worked. ...

fetching and parsing text not enclosed within tags

I'm trying to work on a project about page ranking. I want to make an index (dictionary) which looks like this: file1.html -> [[cat, ate, food, drank, milk], [file2.html, file3.html]] file2.html -> [[dog, barked, ran, away], [file1.html, file4.html]] Fetching links is easy - look for anchor tags. My question is - how do I fetch text? ...

How can I extend an embedded python interpreter with C++ functions?

How can I extend an embedded interpreter with C++ code? I have embedded the interpreter and I can use boost.python to make a loadable module (as in a shared library) but I don't want the library floating around because I want to directly interface with my C++ application. Sorry if my writing is a bit incoherent. ...

How to revert compiled Python 2.6.4 to system default on Snow Leopard?

So earlier this year I manually built 2.6.4 for Snow Leopard because I wanted a slightly more updated version of Python than what Apple released. This has caused all kinds of problems when installing some eggs like PIL and running other 3rd party python apps. Now I just want to revert everything back to what Snow Leopard ships with becau...

Learning Python Exercise

I have taken it upon myself to learn python. As it is my second language is has not been that hard to get the hang of. I am looking for some simple python projects to undertake so I can better learn the syntax of the language in general. I would specifically like to learn the syntax of arrays, lists, and dictionaries. Edit: I cant say...

How to replace the first occurrence of a regular expression in Python?

I want to replace just the first occurrence of a regular expression in a string. Is there a convenient way to do this? Thanks, ...

Using Python to write to HTML file with MySQL data as source ?

Hi all, I am trying to generate some simple html pages that contain data stored in a MySQL database. I have searched and searched for an answer to this and while I can successfully generate html pages from txt or user input I can't get it working with SQL. I am not worried about formatting the data in html or anything, that I can work o...

Is there a more Pythonic approach to this?

This is my first python script, be ye warned. I pieced this together from Dive Into Python, and it works great. However since it is my first Python script I would appreciate any tips on how it can be made better or approaches that may better embrace the Python way of programming. import os import shutil def getSourceDirectory(): ...

Python - How to invoke an function on an object dynamically by name?

In python, say I have a string that contains the name of a class function that I know a particular object will have, how can I invoke it? That is: obj = MyClass() # this class has a method doStuff() func = "doStuff" # how to call obj.doStuff() using the func variable? ...

WPF Binding Alternatives / Enhancements

I love WPF bindings, but I often find myself wish I could do a little more. PyBindings seem like a good start, but the Python syntax seems very clunky and out of place in a XAML file. Are there any alternatives out there? Something with a simpler syntax, that allows for quick comparisons & conversions so that I don't have to write (an...