python

Using PIP in a virtual environment, how do I install MySQL-python

When I'm in my virtual environment, I attempt to run: pip install MySQL-python This didn't work, so I tried downloading the package and installing it by running: python setup.py install This returns the following error: % python setup.py install ...

Read to right of specific symbol in file from Python

I'm going to separate over 1000 virus signatures and the virus names. I have them all in a text file, and would like to do this with python. Here is the format: virus=signature I need to be able to take 'virus' and write it to one file, then take 'signature' and write it to another. This is what I've tied so far: h = open("FILEW...

missing messages when reading with non-blocking udp

I have problem with missing messages when using nonblocking read in udp between two hosts. The sender is on linux and the reader is on winxp. This example in python shows the problem. Here are three scripts used to show the problem. send.py: import socket, sys s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) host = sys.argv[1] s.send...

Does Python have a module to convert CSS styles to inline styles for emails?

I know this exists in other languages, but I want it for Python to I can send emails that'll show up in GMail, etc. ...

Python: How to get current System time of a machine on the network

I understand that I can query system time of my machine like this: from datetime import datetime datetime.now() Is there a way to query the system time of another machine on the windows network? eg of \mynetworkpc ...

Python timeit problem

Hi, I'm trying to use the timeit module but I don't know how. I have a main: from Foo import Foo if __name__ == '__main__': ... foo = Foo(arg1, arg2) t = Timer("foo.runAlgorithm()") print t.timeit(2) and my Class Foo has a method named as runAlgorithm() the error is this: NameError: global name 'foo' is not defined W...

What does this Python code mean?

__author__="Sergio.Tapia" __date__ ="$18-10-2010 12:03:29 PM$" if __name__ == "__main__": print("Hello") print(__author__) Where does it get __main__ and __name__? Thanks for the help ...

Passing an Array/List into Python

Hello, I've just started using Python for my Comp Sci degree and I've been looking at passing arrays (or lists, as Python tends to call them) into a function. I've done reading online on this and read something about using *args, such as: def someFunc(*args) for x in args print x But not sure if this is right/wrong. Noth...

easy_install does not work in Windows 7

I have Python 2.6.4 installed in C:\Python26. I have PyQt4 installed from here: http://www.riverbankcomputing.co.uk/static/Downloads/PyQt4/PyQt-Py2.6-gpl-4.7.7-1.exe I have added this path to %PATH%: C:\Python26;C:\Python26\Scripts When I type this command in cmd.exe however: easy_install cheetah I get this error: C:\Users\Richa...

Manipulate File Descriptors for select.select in Python

Hello everyone, I have an itching problem I know could be solved using many different ways, but I would still like to know if the following approach is possible in Python. Suppose I have some socket I am constantly waiting for input on, and there is some condition that eventually terminates the whole program. I want to do it in a BLOCK...

Python function prints None

I have the following exercise: The parameter weekday is True if it is a weekday, and the parameter vacation is True if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return True if we sleep in. Here's what I've done, but the second print function only prints 'None'. def sleep_in(weekday, vac...

Convert shell to Python

#!/bin/sh if [ ! -d $1 ] then echo $1 nu este director exit1 fi ls -R $1 >temp permission= ls -al $1 | cut -d" " -f1 for i in `cat temp` do perm= ls -l $i | cut -d" " -f1 if [ $permission -ne $perm ] then n=`expr $n + 1` fi echo $n done how can i transform this shell code into python? please help ...

I'm new to python and having trouble with this looping code

Hey gurus, I'm trying to copy sections in a file within a set of XML tags > <tag>I want to copy the data here</tag>` Please note I found out the data around the tags is not valid XML so I can't import a normal library and have to find it via string comparison :( * There are multiple sections of text I want to extract in the file...

Python assignment need help

I am new to programing and am having difficulties writing a program dealing with files. The program is to read a file, calculate an employees pay and an updated YTD pay total. After calculations the program will write to a new file. I can not get the program to do the calculations or make, write, or save the updated file. This is what ...

Get Line Number of certain phrase in file Python

I need to get the line number of a phrase in a text file. The phrase could be: the dog barked I need to open the file, search it for that phrase and print the line number. I'm using Python 2.6 on Windows XP This Is What I Have: o = open("C:/file.txt") j = o.read() if "the dog barked" in j: print "Found It" else: print "...

GTK and PYGTK difference

many programmers import both gtk and pygtk in this way: import gtk import pygtk I have created a simple program using only gtk and it works: import gtk window = gtk.Window() window.set_size_request(800, 700) window.set_position(gtk.WIN_POS_CENTER) window.connect("destroy", gtk.main_quit) button = gtk.Button("Vai") button.set_size_r...

Need help understanding ReferenceProperty

Say I have two classes: class A(db.Model): class B(db.Model): a_reference = ReferenceProperty(A) I can now do the following: a = A() a.put() b = B(); b.a_reference = a.key() b.put() The documentation states the following two things: The ReferenceProperty value can be used as if it were a model instance, and the datastore...

call remote programs by URL with python

Hi, guys, I am developing a GUI in python with wxPython framework to launch several subprocess programs. Now I could do it for the local files, e.g. if we have a compiled .out file under the path "/AAA/BBB/xxx.out", I could do with command like this: subprocess.Popen("/AAA/BBB/xxx.out", stdout=subprocess.PIPE) Now, I am thinking to ...

In Python, how to display current time in readable format

How can I display the current time as: 12:18PM EST on Oct 18, 2010 in Python. Thanks. ...

Python IDLE won't open

Hi, I'm have problems opening IDLE - I can only get it to open when I right click > edit with IDLE on a PY file. I'm running Python 2.6.4. I tried using 'python.exe Lib\idlelib\idle.py', and I get a few errors: C:\Python26>python.exe Lib\idlelib\idle.py ---------------------------------------- Unhandled server exception! Thread: SockTh...