python

Rotate dictionary keys in python

I have a dictionary with several values that I want to keep constant, but I need to rotate them throughout the different keys. Is there a built in function or external library that would be able to do this or would I be better off just writing the entire thing myself? Example of what I am trying to do: >>> firstdict = {'a':'a','b':'b',...

Python style: for-in syntax, checking for empty lists and dictionaries.

I'm new to python and haven't yet read a lot of code to verify which styles are considered 'pythonic'. As I've started to code, I've been using this pattern alot. listThatMightBeEmpty = [] for items in listThatMightBeEmpty: print "this may or may not print but the loop won't cause any errors" I assume that it would be redundant t...

Python: why does this division is not performed correctly ?

I've a strange issue in python, the division is not performed correctly: print pointB[1] print pointA[1] print pointB[0] print pointA[0] print (pointB[1]-pointA[1]) / (pointB[0]-pointA[0]) These are the results: 100 50 100 40 0 thanks ...

Tips, Tricks, Shortcuts for using EnigmaCurry's Emacs configuration

I just stated using emacs and wanted to find a good configuration for python programming. I choose the EnigmaCurry emacs configuration which is very extensive. There are a lot of ".el" files. The problem with this configuration is the lack of documentation on how to use the various tools. Without knowledge of emacs-lisp I feel a little ...

Refactoring long statement in Python

I have a very long conditional statement for deciding what action to take for a pair of variables a and b. action = 0 if (a==0) else 1 if (a>1 and b==1) else 2 if (a==1 and b>1) else 3 if (a>1 and b>1) else -1 While it is nice with the compactness (in lines;) ) of this statement, it must exist a more elegant way to do this? ...

gae-sessions and django variable passing.

I am using gae-sessions for the back end session management, the problem that occurs is although I am able to get the data of the session in a self.response.out.write() command when I am trying something simple like session = get_current_session() profile = session['me'] templates.render(self, 'tmp.html', profile=profile) {{profile}...

Urllib raising invalid argument URLError in Python 3, urllib.request.urlopen

Hi. New to Python, but I'm trying to...retrieve data from a site: import urllib.request response = urllib.request.urlopen("http://www.python.org") This is the same code I've seen from the Python 3.1 docs. And a lot of sites. However, I get: Message File Name Line Position Traceback <module> G:\My...

Web page scraping: press javascript button

Hello I am trying to scrape a web page and to recieve the data i need to press a button. This is the source code for the button: "a class="press-me_btn" href="javascript:void( NewPage['DemoPage'].startDemo() );" id="js_press-me_btn">PRESS ME Is it possible to "press" the button somehow without using a browser? either by using wget wi...

How is python more poweful programming language than Matlab for engineering projects?

I have started learning python now and shortly we'll be employing it by writing codes and scripts to better the already existing geo-statiscal modeling software package called SGeMS. As to what I know right now regarding the project, it'll involve using the sophisticated programming and visualization capabilities built into Python. I hav...

Easiest way to send emails via Python

Possible Duplicate: Receive and send emails in python I've been looking into sending mail with python and found a few different options (setting up my own mailserver, using gmail's smtp, etc) but was wondering if there was some simple way to do it. I am running the python script via wsgi on apache2 on an ubuntu box. Thanks for...

Justadistraction: tokenizing English without whitespaces. Murakami SheepMan

I wondered how you would go about tokenizing strings in English (or other western languages) if whitespaces were removed? The inspiration for the question is the Sheep Man character in the Murakami novel 'Dance Dance Dance' In the novel, the Sheep Man is translated as saying things like: "likewesaid, we'lldowhatwecan. Trytoreconnec...

Howto do reference to ints by name in Python

I want to have a a reference that reads as "whatever variable of name 'x' is pointing to" with ints so that it behaves as: >>> a = 1 >>> b = 2 >>> c = (a, b) >>> c (1, 2) >>> a = 3 >>> c (3, 2) I know I could do something similar with lists by doing: >>> a = [1] >>> b = [2] >>> c = (a, b) >>> c ([1], [2]) >>> a[0] = 3 >>> c ([3], [2]...

Compare folders recursively using python

Hello Guys, I'm going to implement recursive folder comparison on python. What do you think would best algorithm for this? Get two lists of the files for the folders Sort both lists Compare using filecmp module for a file Repeat for every folder recursively In result I need to get only the list of the files that are different (conte...

Reactor stopping earlier than I would have expected?

I am trying to teach myself some rudimentary Twisted programming thanks to this tutorial and many others. I have come to this current example which I Can't figure out why it's doing what it is doing. Short summary: I have instantiated three reactors that count down from 5 to 1 with different delays in their counting. Only thing is, it ...

Python: Rare problem generating .gif with ffmpeg

Hi, I have a problem when I generate an animated gif from a movie.avi using ffmpeg from python in Win7. If I open a cmd window and execute this line: "C:\ffmpeg\ffmpeg.exe" -i "C:\ffmpeg\video.avi" -pix_fmt rgb24 -r 10.0 -loop_output 0 -ss 5 -t 10 -s 352x288 -f gif "C:\ffmpeg\video.gif" ffmpeg.exe generates a gif perfectly from the vi...

python re problem

i test re on some pythonwebshelll, all of them are encounter issue if i use a=re.findall(r"""<ul>[\s\S]*?<li><a href="(?P<link>[\s\S]*?)"[\s\S]*?<img src="(?P<img>[\s\S]*?)"[\s\S]*?<br/>[\s\S]*?</li>[\s\S]*?</li>[\s\S]*?</li>[\s\S]*?</ul>""",html) print a it's ok but if i use a=re.findall(r"""<ul>[\s\S]*?<li><a href="(?P<link>[\s\...

How to draw polygons with Point2D in wxPython?

I have input values of x, y, z coordinates in the following format: [-11.235865 5.866001 -4.604924] [-11.262565 5.414276 -4.842384] [-11.291885 5.418229 -4.849229] [-11.235865 5.866001 -4.604924] I want to draw polygons and succeeded with making a list of wx.point objects. But I need to plot floating point coordinates so I had to ch...

Python Asymmetric Encryption: Using pre-generated prv/pub keys

Ok first off yes I have searched google and stackoverflow and done some reading (over 4 hours JUST in this sitting) have not found what I need for these reasons: Many of them suggest just launching an exe like gpg.exe (http://stackoverflow.com/questions/1020320) Some suggested using PyCrypto or other libraries and looking at them, eith...

Sending email from gmail using Python

Hi all, I'm trying to teaching myself how to program by building programs/scrips that will be useful to me. I'm trying to retool a script I found online to send an email through gmail using a python script (Source). This example has a portion of code to attach files, which I don't want/need. I have tweaked the code so that I don't have ...

Creating and rendering structure with years and months in django

In my blogging app I need a structure (created as a variable in context processor) that will store months number and corresponding year of 5 consecutive months till current one. So if current month is december, we will have year: 2010 and months: 12,11,10,9,8. If month will be january we will have years 2010: months: 1 and years: 2009 mo...