Re: Problem reading csv files

2008-01-04 Thread Ramashish Baranwal
> > XLS != CSV > XLS is M$'s format for spreadsheets whereas CSV is essentially a text > document with comma-delimited fields. If you open it up in OpenOffice > and go File -> Save As then in the 'Save as type:' drop-down list > select 'Text CSV (.csv)' and ofc change your code to point to the new

Problem reading csv files

2008-01-03 Thread Ramashish Baranwal
Hi, I am trying to read a csv file using csv.reader. The file is created using Open Office and saved in Excel format. import csv reader = csv.reader(open('test.xls')) for row in reader: print row It however throws the exception _csv.Error: : line contains NULL byte Any idea whats going wro

Understanding closures

2007-08-18 Thread Ramashish Baranwal
Hi, I want to use variables passed to a function in an inner defined function. Something like- def fun1(method=None): def fun2(): if not method: method = 'GET' print '%s: this is fun2' % method return fun2() fun1() However I get this error- UnboundLocalError: loc

Re: SMTPAuthenticationError

2007-05-30 Thread Ramashish Baranwal
> To help debug this, you may want to try the following. > > 1) Copy smptlib.py into your local directory. On my > box, you can find it here, or import sys; print > sys.path to help find it on your box: > >/usr/local/lib/python2.3 > > 2) Go the login() method, add some print statements > there

Re: SMTPAuthenticationError

2007-05-29 Thread Ramashish Baranwal
> > > I am trying to send a mail using smtplib. My server requires me to > > authenticate, for this I'm using SMTP.login function. However it > > fails- > > server = smtplib.SMTP(host='mail.domain', port=25) > server.login('username', 'password') > > Traceback (most recent call last): > >

Re: How to set a class inheritance at instance creation?

2007-05-29 Thread Ramashish Baranwal
On May 29, 8:52 pm, glomde <[EMAIL PROTECTED]> wrote: > Hi I wonder if you can set what subclass a class should > have at instance creation. > > The problem is that I have something like: > > class CoreLang(): > def AssignVar(self, var, value): > pass > > class Lang1(CoreLang): >

Re: How to set a class inheritance at instance creation?

2007-05-29 Thread Ramashish Baranwal
On May 29, 8:52 pm, glomde <[EMAIL PROTECTED]> wrote: > Hi I wonder if you can set what subclass a class should > have at instance creation. > > The problem is that I have something like: > > class CoreLang(): > def AssignVar(self, var, value): > pass > > class Lang1(CoreLang): >

SMTPAuthenticationError

2007-05-29 Thread Ramashish Baranwal
Hi, I am trying to send a mail using smtplib. My server requires me to authenticate, for this I'm using SMTP.login function. However it fails- >>> server = smtplib.SMTP(host='mail.domain', port=25) >>> server.login('username', 'password') Traceback (most recent call last): File "", line 1, in ?

Re: Periodic tasks.

2007-05-29 Thread Ramashish Baranwal
> > I am trying to execute some tasks periodically, those familiar with > > unix can think of it as equivalent to cron jobs. > > Can you not use cron? If not, why not? Is there an equivalent service > you can use? I can, but the work I want to do is written in Python. This is not an issue but I wo

Periodic tasks.

2007-05-28 Thread Ramashish Baranwal
Hi, I am trying to execute some tasks periodically, those familiar with unix can think of it as equivalent to cron jobs. I have tried looking around, but couldn't find a way. Would appreciate any pointers or clues.. Thanks, -Ram -- http://mail.python.org/mailman/listinfo/python-list

Re: Module listing in order.

2007-05-25 Thread Ramashish Baranwal
> > I want a way to get the contents in the order of their declaration, > > i.e. [B, A, D]. Does anyone know a way to get it? > > My suggestion would be to actually parse the text of the module. "Brute > force" is what it's called ;). But doing so with, say, pyparsing > shouldn't be *very* difficul

Module listing in order.

2007-05-23 Thread Ramashish Baranwal
Hi, I want to get a module's contents (classes, functions and variables) in the order in which they are declared. Using dir(module) therefore doesn't work for me as it returns a list in alphabetical order. As an example- # mymodule.py class B: pass class A: pass class D: pass # test.py import my

Re: setDaemon problem.

2007-04-20 Thread Ramashish Baranwal
> > Hi, > > > I am facing an issue in daemonizing a thread using setDaemon method. > > Here is my code- > > > import time > > from threading import Thread > > > class MThread(Thread): > > def run(self): > > f = open('/tmp/t.log', 'w') > > for i in range(10): > > f.wr

Re: How to upgrade python from 2.3 to 2.4

2007-04-20 Thread Ramashish Baranwal
On Apr 20, 2:03 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi, > > Red hat 4 comes with python 2.3, and I am trying to upgrade to python > 2.4. So I download and compile the source of python2.4. > > But as I run it I get the following error, can you please tell me how > to fix it? > > # /

setDaemon problem.

2007-04-20 Thread Ramashish Baranwal
Hi, I am facing an issue in daemonizing a thread using setDaemon method. Here is my code- import time from threading import Thread class MThread(Thread): def run(self): f = open('/tmp/t.log', 'w') for i in range(10): f.write('Iteration %d\n' % i) time.

Re: Accessing class variables in staticmethods.

2007-01-21 Thread Ramashish Baranwal
Sam wrote: > On 21 Jan 2007 12:49:17 -0800, Ramashish Baranwal > <[EMAIL PROTECTED]> wrote: > > class Base: > > staticvar = 'Base' > > > > @staticmethod > > def printname(): > > # this doesn't work > >

Accessing class variables in staticmethods.

2007-01-21 Thread Ramashish Baranwal
Hi, I want to access a static variable in a staticmethod. The variable can be redefined by derived classes and that should be reflected in base's staticmethod. Consider this trivial example- class Base: staticvar = 'Base' @staticmethod def printname(): # this doesn't work

Re: Passing variable number of named arguments

2006-12-27 Thread Ramashish Baranwal
Carsten Haese wrote: > On Wed, 2006-12-27 at 10:37 -0800, Ramashish Baranwal wrote: > >[...] > > def fun2(**kwargs): > > # get id param > > id = kwargs.pop('id', '') > > # pass on remaining to fun1 > > fun1(kwargs

Passing variable number of named arguments

2006-12-27 Thread Ramashish Baranwal
Hi, I need to process few out of a variable number of named arguments in a function and pass the remaining to another function that also takes variable number of named arguments. Consider this simple example, def fun1(**kwargs): print kwargs.keys() def fun2(**kwargs): # get id param