Re: [BangPypers] Tuples vs Lists, perfromance difference

2009-12-24 Thread Sidharth Kuruvila
> even more optimizations can be made at runtime. Much of that is just not > possible in Python. No amount of compiler improvements and optimizations can > change this. Unless someone comes up with a really smart profiling jit. Like, I believe, they're doing with the javascript engines. :-). And g

Re: [BangPypers] Tuples vs Lists, perfromance difference

2009-12-22 Thread Sidharth Kuruvila
Hi, I don't think you should see and difference in performance. Lists might take a bit more space since they usually preallocate memory for future inserts. I'd go for lists where ever i need to use an array or a list, and tuples for storing records. Regards, Sidharth On Tue, Dec 22, 2009 a

Re: [BangPypers] Python moratorium

2009-11-13 Thread Sidharth Kuruvila
This is to allow the alternate implementations to catch up, and not really about the users of the python language. Adding breaking changes between versions of python 3 would just be bad language design, so users should be fine either way. I've found myself quite happy using many of the new feature

Re: [BangPypers] ElementTree nodes

2009-10-25 Thread Sidharth Kuruvila
Ah yes, silly me. Must remember to go to the docs before posting :">. On Mon, Oct 26, 2009 at 2:12 AM, bhaskar jain wrote: > On Mon, Oct 26, 2009 at 1:53 AM, Sidharth Kuruvila < > sidharth.kuruv...@gmail.com> wrote: >>>>It turns out any object that returns

Re: [BangPypers] ElementTree nodes

2009-10-25 Thread Sidharth Kuruvila
behaviour holds in python 3? Regards, Sidharth On Mon, Oct 26, 2009 at 1:43 AM, Sidharth Kuruvila wrote: > Hi, > >  I don't have elementree, so I just wanted to confirm what is > happening here. Is it that the Element type is a subclass of list. > Which would lead an empty Elem

Re: [BangPypers] ElementTree nodes

2009-10-25 Thread Sidharth Kuruvila
Hi, I don't have elementree, so I just wanted to confirm what is happening here. Is it that the Element type is a subclass of list. Which would lead an empty Element to have the same boolean property as an empty list. Or is there some way of specifying the truthfulness of an object. Regards, S

Re: [BangPypers] sort query

2009-10-24 Thread Sidharth Kuruvila
Hi, The sort method doesn't return anything. It modifies the list which you call it on. l = d.keys() l.sort() #There is no point assigning the return value to this because it will be None #Which is what you do when you write l = d.keys().sort() print l Now there is another subtle issue here wi

Re: [BangPypers] sort query

2009-10-24 Thread Sidharth Kuruvila
Hi Anand. > Looks like Python dictionary implementation is doing something clever. > d.keys() returns the cached object if its refcount == 1 and returns a > new object if refcount > 1. > I don't think that's what's happening >>> id(d.keys()) 535168 >>> id(d.keys()) 535168 >>> l = [1,2,3,4] >>> i

Re: [BangPypers] sort query

2009-10-24 Thread Sidharth Kuruvila
ought up this http://www.python.org/dev/peps/pep-0372/. Regards, Sidharth On Sat, Oct 24, 2009 at 3:23 PM, Sidharth Kuruvila wrote: > Hi, > >>>> d = {"a":1, "b":2} >>>> d.keys() > ['a', 'b'] >>>> a = d.keys() >&

Re: [BangPypers] sort query

2009-10-24 Thread Sidharth Kuruvila
Hi, >>> d = {"a":1, "b":2} >>> d.keys() ['a', 'b'] >>> a = d.keys() >>> b = d.keys() >>> id(a) 542120 >>> id(b) 542200 So d creates a new list with each call to keys. The behavior might be different in python 3 where I hear d.keys() will return a set Regards, Sidharth On Sat, Oct 24, 2009 at 2

Re: [BangPypers] An interesting beginner post at Stackoverflow

2009-10-21 Thread Sidharth Kuruvila
Hi, My bad, that was a bit of laziness on my part. The reason why my code was silly is not to do with interning though that does happen for strings. Literals, that is numbers and string literals and a few others are loaded as constants. So the cost of constructing them in your code has already be

Re: [BangPypers] An interesting beginner post at Stackoverflow

2009-10-20 Thread Sidharth Kuruvila
Hi, d = {"a":"Hello"} print d.setdefault("a", "blah") Even though the string blah is not being used an object has to be created to represent it. Even worse, you could put some complex expression in there expecting it to evaluate only if the key is missing. Regards, Sidharth On Wed, Oct 21,

Re: [BangPypers] help me to fix this error

2009-10-20 Thread Sidharth Kuruvila
s to, >>  print (str.translate(trantab)) >> >>  And you don't need semi-colons in Python. Semi-colons >>  are used only to separate 2 expressions in the same line. >>  Something like >> >>  x=2; print x >> >>  Here they are superfluous. >> >>  And I think &

Re: [BangPypers] help me to fix this error

2009-10-20 Thread Sidharth Kuruvila
trantab = intab.maketrans(outtab) > str = "this is string examplewow!!!"; > print str.translate(trantab); > > Thanks for the response. > I changed the code as above > this code too shows an error. > > On Tue, Oct 20, 2009 at 2:23 PM, Sid

Re: [BangPypers] help me to fix this error

2009-10-20 Thread Sidharth Kuruvila
Hi, This looks like it's because python's strings have change in python 3. The characters used to be 8bit bytes but now they are 16 bits wide. A quick google tells me that str now has a method called maketrans so s1.maketrans(s2) should work. I'm guessing you are using a tutorial written for one

Re: [BangPypers] Python interpreter in mobile phone (java)

2009-10-18 Thread Sidharth Kuruvila
Hi, There's jython http://www.jython.org/. I don't know if it will run on j2me. Regards, Sidharth On Sun, Oct 18, 2009 at 6:38 PM, Aneesh A wrote: > I and my friend like to do a mobile application in python. > > It should be working on most of mobiles. > > Is there any python interpreter that

[BangPypers] Introducing the Y Combinator(Not the company)

2009-10-15 Thread Sidharth Kuruvila
AKA The Y Combinator in python. This is in response to Roshan Mathews' post that he got stuck with the Y Combinator. Aha a challenge, I shall undertake this as a test of my communication skillz. :-) The question is how do we implement a recursive function in a language in which names can only be

Re: [BangPypers] Pickle multiple objects

2009-10-07 Thread Sidharth Kuruvila
Oops formatting got mucked up. Should be def pickledobjects(f): try: while True: yield pickle.load(f) except EOFError: pass objs = list(pickledobjects(file("fi"))) ___ BangPypers mailing list BangPypers@python.org htt

Re: [BangPypers] Pickle multiple objects

2009-10-07 Thread Sidharth Kuruvila
Hi, I'm guessing you want to do something like this >>> fo = file("test.pkl", "w") >>> pickle.dump([1,2,3,4], fo) >>> pickle.dump([5,6,7,8], fo) >>> fo.close() >>> fi = file("test.pkl") >>> pickle.load(fi) [1, 2, 3, 4] >>> pickle.load(fi) [5, 6, 7, 8] >>> pickle.load(fi) Traceback (most recent c

Re: [BangPypers] SciPy India 2009 - SciPy.in

2009-10-04 Thread Sidharth Kuruvila
A thousand apologies, the "possibly just for Pradeep, goto", was a meant as a light joke not to be taken personally. Goto was the original issue with Basic. You hit the nail squarely on the head when you say "The *users* of PHP tend to get wired in weird ways after using it". So do the user

Re: [BangPypers] SciPy India 2009 - SciPy.in

2009-10-04 Thread Sidharth Kuruvila
Hey Hey, no need to dis Php, or Drupal for that matter, it's actually a mighty fine language for what it does. And they have been making it a lot better(namespaces, closures and, possibly just for Pradeep, goto). Nice to see conferences happening around python. On Sun, 04 Oct 2009 11:47:27 +

Re: [BangPypers] Implementing a fast factorial function in python

2009-09-14 Thread Sidharth Kuruvila
This should work, find f(6)**(10 raised to 7) On Mon, 14 Sep 2009 18:36:57 +0530, Shashwat Anand wrote: How do we calculate last 5-digits of 10**12 ignoring trailing zeros. The code i wrote works good until 10**8 and after that take ages. The source of problem is Project Euler : http://p

Re: [BangPypers] Low level Python

2009-09-12 Thread Sidharth Kuruvila
What's on your mind? On Sat, 12 Sep 2009 01:51:57 +0530, Noufal Ibrahim wrote: Hello everyone, Are there any people here who are interested and who've worked on the actual CPython (or any other) interpreter directly? The whole idea of unladen swallow is appealing to me and if there are

Re: [BangPypers] How to create Debug and Release code in Python

2009-06-07 Thread Sidharth Kuruvila
Hi, You could try the C preprocessor. Personally, I'd just go for python's inbult logging framework, and worry about the performance issue later. Regards On Mon, Jun 8, 2009 at 1:07 AM, Vishal wrote: > Hello, > We would like to have debug and release versions of our scripts. However > since

Re: [BangPypers] help using mysqldb

2008-12-17 Thread Sidharth Kuruvila
Do this instead cur.execute('select * from Employee where id in (%s)', ids.join(', ')); On Wed, Dec 17, 2008 at 5:13 PM, Vijay Ramachandran wrote: > Hello. > > I'm unable to figure out how to use mysqldb (actually, dbabi) to write an > "in" query. > > For instance, suppose my table looks like th

Re: [BangPypers] help needed with dictionary

2008-08-29 Thread Sidharth Kuruvila
Hi Sonny, Not if you run kev={} in front of your code. It will keep getting reinitialized to an empty dict. On Fri, Aug 29, 2008 at 3:42 PM, sunny_plone <[EMAIL PROTECTED]> wrote: > > hi , > actually my main problem is the the key name or Name should store multiple > values, but now the old va

Re: [BangPypers] strange behavior

2008-07-10 Thread Sidharth Kuruvila
Any number with a decimal point is treated as an object of type float and the numbers without a decimal point of are treated as ints. You can use the type function to find the type of an object. >>> type(1) >>> type(1.0) >>> 1+1.0 2.0 Arithmetic operations over two types give the result in the

Re: [BangPypers] [Job] Looking for developer

2008-07-05 Thread Sidharth Kuruvila
I'm sure there a lot of guys in bangpypers who could fit that bill. I don't think you have to have all of the qualification in point one. What I'd like to know is how successful people who post job requirements on bangpypers have been with recruitment. Vijay? On Sat, Jul 5, 2008 at 3:40 PM, Anan

Re: [BangPypers] Expressing meta-data about classes, methods, variables, parameters in python

2008-04-03 Thread Sidharth Kuruvila
Hi, You can simulate annotation using decorators. I might be missing something about annotation but you can do this. def annotate(returns, **params): def decorate(func): params['returns'] = returns func.__annotations__ = params return func return decorate @

Re: [BangPypers] Expressing meta-data about classes, methods, variables, parameters in python

2008-04-03 Thread Sidharth Kuruvila
H Heshan, Can you explain why you'd want to do this? You can write def f(): print f.a f.a = 4 f() But I can't see you would want to do something like that. Maybe if you give a use case. Someone can come up with a solution. Regards, Sidharth On Apr 3, 2008, at 2:03 PM, Heshan Suriya