python

Is Paramiko going to be ported over to Python 3.x?

Seems to be that PyCrypt is required to be ported, in order to make that happen. Is it hard to do yourself? ...

parsing parenthesized list in python's imaplib

I am looking for simple way to split parenthesized lists that come out of IMAP responses into Python lists or tuples. I want to go from '(BODYSTRUCTURE ("text" "plain" ("charset" "ISO-8859-1") NIL NIL "quoted-printable" 1207 50 NIL NIL NIL NIL))' to (BODYSTRUCTURE, ("text", "plain", ("charset", "ISO-8859-1"), None, None, "quoted-prin...

Loop through values or registry key.. _winreg Python

How would I loop through all the values of a Windows Registry Key using the Python module _winreg. I have code that will do what I want, but it is for the subkeys of the specified registry key. Here Is The Code: from _winreg import * t = OpenKey(HKEY_CURRENT_USER, r"PATH TO KEY", 0, KEY_ALL_ACCESS) try: i = 0 while True: ...

Could a bored AWK master kindly convert this Python program?

I love Python but do not really care for AWK. For purposes of comparison (and to see how a Python-to-AWK master would do this), could someone rewrite the following Python program in AWK? Considering how short it is, some would think that the rewrite would be simple and easy for anyone with a little time. import os ROOT = '/Users/Zero/D...

SHA-256 password generator

i saw a javascript implementation of sha-256. i waana ask if it is safe (pros/cons wathever) to use sha-256 (using javascript implementation or maybe python standard modules) alogrithm as a password generator: i remember one password, put it in followed(etc) by the website address and use the generated text as the password for that webs...

String splitting issue problem with multiword expressions

I have a series of strings like: 'i would like a blood orange' I also have a list of strings like: ["blood orange", "loan shark"] Operating on the string, I want the following list: ["i", "would", "like", "a", "blood orange"] What is the best way to get the above list? I've been using re throughout my code, but I'm stumped with ...

Python urllib2.urlopen bug: timeout error brings down my Internet connection?

I don't know if I'm doing something wrong, but I'm 100% sure it's the python script brings down my Internet connection. I wrote a python script to scrape thousands of files header info, mainly for Content-Length to get the exact size of each file, using HEAD request. Sample code: class HeadRequest(urllib2.Request): def get_method(...

Getting unique value when the same tag is in children's tree in XML with Python

I have getElementText as follows which works pretty well with [0] as the XML that I'm working on doesn't have the duplicate tag. from xml.dom import minidom def getElementText(element, tagName): return str(element.getElementsByTagName(tagName)[0].firstChild.data) doc = minidom.parse("/Users/smcho/Desktop/hello.xml") outputTree = ...

Widgets disappear after tkMessageBox in Tkinter.

Every time I use this code in my applications: tkMessageBox.showinfo("Test", "Info goes here!") a message box pops up (like it is supposed to), but after I click OK, the box disappears along with most of the other widgets on the window. How do I prevent the other widgets from disappearing? Here Is My Code: from Tkinter import * im...

Python: How to generate the code on the fly?

I've got a problem, I have to generate program on the fly and then execute it. How could we do this? ...

How do I pass/catch/respond to Python's KeyboardInterrupt in C++?

I have a simple library written in C++ which I'm creating a Python wrapper for using boost.python. Some functions take a long time to execute (over 30 seconds), and I would like to make it interruptible so that when I hit ctrl-d to trigger KeyboardInterrupt in the python interpreter, I'm somehow able to respond to that in C++. Is there ...

Parameter in Python

Let's say there is a parameter n. Can n be any numbers? For example, question like this: Given a non-negative number num, return True if num is within 2 of a multiple of 10. This is what I am thinking: def near_ten(num): n = int #So I assume n can be any integer if abs(num - n*10) <=2: return True Return False Howe...

How can I convert SQLite 2 to SQLite3 using Python on Windows?

I'm trying to convert a SQLite 2 file to SQLite3 using Python on Windows. On Linux, I'd just pipe a dump from sqlite to sqlite3: os.system("sqlite db.sqlite .dump | sqlite3 db3.sqlite") On Windows, I have no such convenient means of transferring the dump. Here's what I'm doing: sqlite_dump = os.popen('sqlite %s .dump' % sqlite_db)....

How to invoke ant task in python script ??

I know we can call like this: os.system("ant compile") But how to know whether the ant task is successful or not? And is there another way to invoke ant task? ...

How to select a MenuItem programatically

I am trying to add a global shortcut to a gtk.MenuItem which has a sub menu. Here is my code: import pygtk, gtk import keybinder dlg = gtk.Dialog('menu test') dlg.set_size_request(200, 40) menubar = gtk.MenuBar() menubar.show() menuitem = gtk.MenuItem('foo') menuitem.show() menubar.append(menuitem) mitem = gtk.MenuItem('bar') mitem....

How to prevent PyQt objects from garbage collecting from different thread?

...

Understanding dict.copy() - shallow or deep?

Hello. While reading up the documentation for dict.copy(), it says that it makes a shallow copy of the dictionary. Same goes for the book I am following (Beazley's Python Reference), which says: The m.copy() method makes a shallow copy of the items contained in a mapping object and places them in a new mapping object. Consi...

Why can't python infer types like scala ?

Possible Duplicate: How to deal with Python ~ static typing? I'm basically a Java programmer with little knowledge of python.I really like the syntax of python and the ease with which a programmer is able to express his idea's but also I'm aware that python is dynamically typed and thus is not as fast as Java.My question is wh...

Django model instance specific code

Hi, in one of my Django models I have to add specific code for each model instance. Now, I wonder what would be a good way to implement this. My current attempt results in a big, hard to read if statement. Consider the following model: class Foo(models.Model): name = models.CharField(max_length=255) def do_instance_specific_s...

How to convert .xlsx to .txt?

I want to know if there is a linux tool or a script available to convert xlsx file to .txt. Thanks. ...