python

index error:list out of range

from string import Template from string import Formatter import pickle f=open("C:/begpython/text2.txt",'r') p='C:/begpython/text2.txt' f1=open("C:/begpython/text3.txt",'w') m=[] i=0 k='a' while k is not '': k=f.readline() mi=k.split(' ') m=m+[mi] i=i+1 print m[1] f1.write(str(m[3])) f1.write(str(m[4])) x=[] j=0 while ...

Emailing smtp with Python error

I can't figure out why this isn't working. I'm trying to send an email from my school email address with this code I got online. The same code works for sending from my GMail address. Does anyone know what this error means? The error occurs after waiting for about one and a half minutes. import smtplib FROMADDR = "FROM_EMAIL" LOGIN...

XML - python prints extra lines

`from xml import xpath from xml.dom import minidom xmldata = minidom.parse('model.xml').documentElement for maks in xpath.Evaluate('/cacti/results/maks/text()', xmldata): print maks.nodeValue ` and I get result: 85603399.14 398673062.66 95785523.81 But I needed to be: 85603399.14 NO SPACE 398673062.66 NO SPACE 95785523.81...

writing string to a file on a new line everytime?

i want to write a string to a file and every time i use file.write( )it should write on a new line in my file please tell how can i do this ...

Making GUI applications on Linux/Windows. What languages/tools to use?

My student group and I are trying to continue working on a project we worked on this semester over the summer to become a professional, deployable app. We originally did it in Adobe AIR but it seems now that the computers this program will be running on will be very slow, maybe 600mhz and 128-256mb ram so flash just isn't going to cut it...

Use a foreign key mapping to get data from the other table using Python and SQLAlchemy.

Hmm, the title was harder to formulate than I thought. Basically, I've got these simple classes mapped to tables, using SQLAlchemy. I know they're missing a few items but those aren't essential for highlighting the problem. class Customer(object): def __init__(self, uid, name, email): self.uid = uid self.name = name...

Is there autoexpect for pexpect?

I would like to generate Python Expect (pexpect) code automatically, does something like autoexpect exist for pexpect? ...

problem with f.readline()?

I am reading one line at a time from a file, but at the end of each line it adds a '\n'. Example: The file has: 094 234 hii but my input is: 094 234 hii\n I want to read line by line but I don't need to keep the newlines... My goal is to read a list from every line: I need ['094','234','hii'], not ['094','234','hii\n']. Any advice...

how to change headers data

hello i have the following class class AssetTableModel(QtCore.QAbstractTableModel): def __init__(self,filename=''): super(AssetTableModel,self).__init__() self.fileName=filename self.dirty = False self.assets = [] self.setHeaderData(0,QtCore.Qt.Horizontal,QtCore.QVariant('moayyad'),QtCore.Qt...

Parsing complicated query parameters

My Python server receives jobs that contain a list of the items to act against, rather like a search query term; an example input: (Customer:24 OR Customer:25 OR (Group:NW NOT Customer:26)) So when a job is submitted, I have to parse this recipient pattern and resolve all those customers that match, and create the job with that input....

Prevent Python from caching the imported modules

While developing a largeish project (split in several files and folders) in Python with IPython, I run into the trouble of cached imported modules. The problem is that instructions import module only reads the module once, even if that module has changed! So each time I change something in my package, I have to quit and restart IPython....

What host do I have to bind a listening socket to?

I used python's socket module and tried to open a listening socket using import socket import sys def getServerSocket(host, port): for r in socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE): af, socktype, proto, canonname, sa = r try: ...

Python: Copying files with special characters in path

Hi is there any possibility in Python 2.5 to copy files having special chars (Japanese chars, cyrillic letters) in their path? shutil.copy cannot handle this. here is some example code: import copy, os,shutil,sys fname=os.getenv("USERPROFILE")+"\\Desktop\\testfile.txt" print fname print "type of fname: "+str(type(fname)) fname0 = unico...

Load image from string

Given a string containing jpeg image data, is it possible to load this directly in pygame? I've tried using StringIO but failed and I don't completely understand the 'file-like' object concept. Currently, as a workaround, I'm saving to disk and then loading an image the standard way: # imagestring contains a jpeg f=open('test.jpg','w...

Get client ip with python

Hi, I'm a newbie in python. I want to write a simple web that prints the client ip on screen my http.conf Handler: AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On The cgi.escape(os.environ["REMOTE_ADDR"]) return this error: KeyError: 'REMOTE_ADDR' and I just get lost with the BaseHTTPRequestHandl...

Writing a post search algorithm.

I'm trying to write a free text search algorithm for finding specific posts on a wall (similar kind of wall as Facebook uses). A user is suppose to be able to write some words in a search field and get hits on posts that contain the words; with the best match on top and then other posts in decreasing order according to match score. I'm ...

GWT on Python App Engine

Hi, I have a python app engine code (matured backend) - and we are now planning to have a front end for that code. I was wondering whether it is possible to implement GWT as the front end. Even though Alex Martelli in this post [1] mentions it is not possible, a comment to that post suggests that it is indeed possible using rpc over...

How do I type a floating point infinity literal in python

How do I type a floating point infinity literal in python? I have heard inf = float('inf') is non portable. Thus, I have had the following recommended: inf = 1e400 Is either of these standard, or portable? What is best practice? ...

problem with lists??

j=0 x=[] for j in range(9): x=x+ [j] this will output [1,2,3,4,5,6,7,8,9] i wanted it as ['1','2','3'... how can I get it? ...

Python - Calling a non python program from python?

Hi, I am currently struggling to call a non python program from a python script. I have a ~1000 files that when passed through this C++ program will generate ~1000 outputs. Each output file must have a distinct name. The command I wish to run is of the form: program_name -input -output -o1 -o2 -o3 To date I have tried: import os ...