python

It there an equivalent to PHP's extract in Python?

Looking for the python equivalent of this. http://ca3.php.net/manual/en/function.extract.php ...

Updating tkinter labels in python

I'm working on giving a python server a GUI with tkinter by passing the Server's root instance to the Tkinter window. The problem is in keeping information in the labels up to date. For instance, the server has a Users list, containing the users that are logged on. It's simple enough to do this for an initial list: string = "" for user...

Plot logarithmic axes with matplotlib in python

I want to plot a graph with one logarithmic axis using matplotlib. I've been reading the docs, but can't figure out the syntax. I know that it's probably something simple like 'scale=linear' in the plot arguments, but I can't seem to get it right Sample program: from pylab import * import matplotlib.pyplot as pyplot a = [ pow(10,i)...

Python +sockets

Hello, i have to create connecting server<=>client. I use this code: Server: import socket HOST = 'localhost' PORT = 50007 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr while 1: data = conn.recv(1024) if not data: break conn.se...

SFTP listing directory

I'm trying to make a connection to a secure sftp site, however I'm not able to list the directory,however, it's possible to connect using python "expect" or php"ssh2_connect" but it gives me the following mesg: Received disconnect from xx.xx.xx. If I use a GUI appliction like winscp I'm able to go to the sftp server and retrieve files. ...

Business rules for calculating prices

The business I work for is an on-line retailer, I'm currently working on a project that among other things involves calculating the customer prices for products. We will probably create a service that looks something like... public interface IPriceService { decimal CalculateCustomerPrice(ISupplierPriceProvider product); } public inte...

Python difflib: highlighting differences inline?

When comparing similar lines, I want to highlight the differences on the same line: a) lorem ipsum dolor sit amet b) lorem foo ipsum dolor amet lorem <ins>foo</ins> ipsum dolor <del>sit</del> amet While difflib.HtmlDiff appears to do this sort of inline highlighting, it produces very verbose markup. Unfortunately, I have not been ab...

Programming tutorials for people with zero experience

A friend of mine is interested in learning how to program computers, but she knows nothing about programming. I suggested that Python might be a good language to start with, but after some googling, I couldn't find any tutorials that covered both programming and Python in an adequate way. I don't want her to go through the tiresome "lea...

Python scripted mp3 database, with a php front end

So, here's the deal. I am attempting to write a quick python script that reads the basic id3 tags from an mp3 (artist, album, songname, genre, etc). The python script will use most likely the mutagen library (unless you know of a better one). I'm not sure how to recursively scan through a directory to get each mp3's tags, and then fil...

Is it possible to overload ++ operators in Python?

Is it possible to overload ++ operators in Python? ...

Explain Python entry points?

I've read the documentation on egg entry points in Pylons and on the Peak pages, and I still don't really understand. Could someone explain them to me, or point me at an article or book that does? ...

Multiple statements in list compherensions in Python?

Is it possible to have something like: list1 = ... currentValue = 0 list2 = [currentValue += i, i for i in list1] I tried that but didn't work? What's the proper syntax to write those? EDIT: the print statement was an example. Actually I am incrementing a value outside the loop. ...

Python Time Seconds to h:m:s

I have a function that returns information in seconds, but I need to store that information in hours:minutes:seconds. Is there an easy way to convert the seconds to this format in python? ...

Efficiently determining if a business is open or not based on store hours

Given a time (eg. currently 4:24pm on Tuesday), I'd like to be able to select all businesses that are currently open out of a set of businesses. I have the open and close times for every business for every day of the week Let's assume a business can open/close only on 00, 15, 30, 45 minute marks of each hour I'm assuming the same sche...

Directory Walker for Python

I am currently using the directory walker from Here import os class DirectoryWalker: # a forward iterator that traverses a directory tree def __init__(self, directory): self.stack = [directory] self.files = [] self.index = 0 def __getitem__(self, index): while 1: try: file = self.files[self.index] ...

Python mysql with variables

I am having a hard time using the MySQLdb module to insert information into my database. I need to insert 6 variables into the table. cursor.execute (""" INSERT INTO Songs (SongName, SongArtist, SongAlbum, SongGenre, SongLength, SongLocation) VALUES (var1, var2, var3, var4, var5, var6) ...

os.path.exists() for files in your Path?

I commonly use os.path.exists() to check if a file is there before doing anything with it. I've run across a situation where I'm calling a executable that's in the configured env path, so it can be called without specifying the abspath. Is there something that can be done to check if the file exists before calling it? (I may fall back ...

how can I decode the REG_BINARY value HKLM\Software\Microsoft\Ole\DefaultLaunchPermission to see which users have permission?

Hello, I am trying to find a way to decode the REG_BINARY value for "HKLM\Software\Microsoft\Ole\DefaultLaunchPermission" to see which users have permissions by default, and if possible, a method in which I can also append other users by their username. At work we make use of DCOM and for the most part we always give the same users pe...

How to catch POST using WSGIREF

I am trying to catch POST data from a simple form. This is the first time I am playing around with WSGIREF and I can't seem to find the correct way to do this. This is the form: <form action="test" method="POST"> <input type="text" name="name"> <input type="submit"></form> And the function that is obviously missing the right informat...

How do you transfer binary data with Python?

I'm working on a client-server program for the first time, and I'm feeling woefully inadequate on where to begin for what I'm doing. I'm going to use Google Protocol Buffers to transfer binary data between my client and my server. I'm going to be using the Python variant. The basic idea, as I understand, is that the client will serial...