Re: sum up numbers in a list

2008-08-26 Thread c james
>>> L=['10','15','20'] >>> sum(int(x) for x in L) 45 or >>> sum(map(int,L)) 45 sharon kim wrote: hi all, i have a list, for example; >>> L=[] >>> L.append('10') >>> L.append('15') >>> L.append('20') >>> len(L) 3 >>> print L ['10', '15', '20'] is there a way to sum up all the numbers in

Re: Books for learning how to write "big" programs

2008-05-27 Thread c james
duli wrote: Hi: I would like recommendations for books (in any language, not necessarily C++, C, python) which have walkthroughs for developing a big software project ? So starting from inception, problem definition, design, coding and final delivery on a single theme or application. Most of the

Re: Problems with psycopg2

2008-05-05 Thread c james
David Anderson wrote: The thing is this query works fine on the console through psql, but not in my code? can anyone explain me why? On Thu, May 1, 2008 at 9:31 PM, David Anderson <[EMAIL PROTECTED] > wrote: Hi all I have this function: def checkName(sel

keyword 'in' not returning a bool?

2008-02-08 Thread c james
Try this >>> sample = {'t':True, 'f':False} >>> 't' in sample True >>> type('t' in sample) >>> 't' in sample == True False Why is this? Now try >>> bool('t' in sample) == True True Can someone explain what is going on? -- http://mail.python.org/mailman/listinfo/python-list

Re: Cheat sheet

2007-12-28 Thread c james
Riccardo T. wrote: > I wrote a little cheat sheet for this wonderful language, but because of > my still little experience with it, I would like to have a feedback > Could you have a look at it and tell me what do you think about, please? > > http://greyfox.imente.org/index.php?id=73 > > -- > Gre

Re: Overriding member methods in __init__

2007-12-03 Thread c james
Arnaud Delobelle wrote: > Why not simply do: > > class YesNo(object): > def __init__(self, which): > self.yesno = which and self.yes or self.no > def yes(self, val): > print 'Yes', val > def no(self, val): > print 'No', val > def __call__(self, val): >

Re: Overriding member methods in __init__

2007-12-03 Thread c james
Bruno Desthuilliers wrote: > c james a écrit : >> Given a condition at the time a class is instantiated, I want to change >> how __call__ is used. From the example below, self.no is using self.yes >> but self.__call__ is not. Can someone please explain why? > &g

Overriding member methods in __init__

2007-12-03 Thread c james
Given a condition at the time a class is instantiated, I want to change how __call__ is used. From the example below, self.no is using self.yes but self.__call__ is not. Can someone please explain why? EXAMPLE: class YesNo(object): def __init__(self, which): self.no = self.yes

Re: appending into a list

2007-10-30 Thread c james
Beema shafreen wrote: > 2721520 2721569A_16_P21360235199-49 > 2721768 2721821A_16_P03641971139-53 > 2721960 2722004A_16_P21360237312-44 > I need to append the column D and E into a list: > in such a way that the li

Re: Pure Python equivalent of unix "file" command?

2007-07-23 Thread c james
Take a look at http://www.demonseed.net/~jp/code/magic.py W3 wrote: > Hi all, > > Just a quick one... Is there such a thing? > > Thanks, > /Walter -- http://mail.python.org/mailman/listinfo/python-list

Re: multi threaded SimpleXMLRPCServer

2007-05-14 Thread c james
I use a variation of the following. Clean and straight forward. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/425043 Vyacheslav Maslov wrote: > Hi, all! > > I need multi threaded version of SimpleXMLRPCServer. Does python library > already have implementation of this one? Or i need

Re: "Plugin" architecture - how to do?

2007-04-10 Thread c james
Take a look at Trac. This might give you some ideas. http://trac.edgewall.org/wiki/TracDev/ComponentArchitecture -- http://mail.python.org/mailman/listinfo/python-list

Re: SimpleXMLRPCServer - client address

2007-04-02 Thread c james
Jan Danielsson wrote: > Hello all, > >I writing an application based on the SimpleXMLRPCServer class. I > would like to know the IP address of the client performing the RPC. Is > that possible, without having to abandon the SimpleXMLRPCServer class? > I did this a long time ago so it's not li

Re: Controlling kwrite by dcop

2005-05-08 Thread R. C. James Harlow
On Sunday 08 May 2005 13:41, [EMAIL PROTECTED] wrote: > As you can see you can interact with kwrite from dcop. > Unfortunately I don't have this module in my Python (2.3) nor I have > been able to find it. It's normally installed seperately from the main kde libraries - on gentoo it's a package c

Re: large dictionary creation takes a LOT of time.

2005-04-29 Thread R. C. James Harlow
On Friday 29 April 2005 11:53, Ville Vainio wrote: > > "Kent" == Kent Johnson <[EMAIL PROTECTED]> writes: > > Kent> if frequency.has_key(word): > Kent> frequency[word] += 1 > Kent> else: > Kent> frequency[word] = 1 > > This is a good place to use 'get' method of dict: > > freque

Re: Do I need a nested lambda to do this?

2005-04-25 Thread R. C. James Harlow
On Tuesday 26 April 2005 00:34, raoul wrote: > I can't figure this one out. Trying to be unnecessarily functional I > suspect. With list comprehensions: Python 2.3.4 (#1, Mar 26 2005, 20:54:10) [GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on linux2 Type "help", "copyright"

Re: Multiple tuples for one for statement

2005-04-25 Thread R. C. James Harlow
On Monday 25 April 2005 14:34, Ivan Van Laningham wrote: > Hi All-- > > "R. C. James Harlow" wrote: > > or just: > > > > for a,b,c in (tup1, tup2, tup3): > > print a > > print b > > print c > > And this works in Python v

Re: Multiple tuples for one for statement

2005-04-25 Thread R. C. James Harlow
On Monday 25 April 2005 04:20, James Stroud wrote: > for a,b,c in zip(tup1, tup2, tup3): >print a >print b >print c or just: for a,b,c in (tup1, tup2, tup3): print a print b print c pgpJ0RNTnCUA3.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/

Re: Parsing data from URL

2005-04-24 Thread R. C. James Harlow
On Monday 25 April 2005 01:24, Harlin Seritt wrote: > dat = urllib.urlopen(url, 'r').read() Drop the 'r' - urlopen is posting the 'r' to the server, instead of doing what you mean, opening the file read-only. pgpmZ2zcMs1bO.pgp Description: PGP signature -- http://mail.python.org/mailman/listi

Re: Variables

2005-04-24 Thread R. C. James Harlow
On Sunday 24 April 2005 03:20, Richard Blackwood wrote: > To All: > > Folks, I need your help. I have a friend who claims that if I write: > > foo = 5 > > then foo is NOT a variable, necessarily. This is a really amusingly recursive discussion. Your friend has a piece of knowledge, "what a

Re: goto statement

2005-04-21 Thread R. C. James Harlow
On Thursday 21 April 2005 17:42, Maxim Kasimov wrote: > > Have you tried the triple quote comment technique? > how do use this here: Simple. > sql = ''' > some long query > ''' Change this to: sql = """ some long query """ since you shouldn't be using multiple quoting styles in one module, an

Re: Piping data into script under Win32

2005-04-15 Thread R. C. James Harlow
On Saturday 16 April 2005 03:43, runes wrote: > type countlines.py | python countlines.py = Success > type countlines.py | countlines.py = Failure > > Why doesn't the latter work? Don't quote me on this, but I think it's because invoking countlines.py involves running some sort of wrapper that d

Re: Piping data into script under Win32

2005-04-15 Thread R. C. James Harlow
On Saturday 16 April 2005 03:11, runes wrote: > I trying to figure out a way to make a python script accept data output > from another process under Windows XP, but I fail miserably. I have a > vague memory having read this is not possible with Python under > Windows... > > C:\> type countlines.py

Re: Supercomputer and encryption and compression @ rate of 96%

2005-04-15 Thread R. C. James Harlow
On Thursday 14 April 2005 10:27, [EMAIL PROTECTED] wrote: > Supercomputer and encryption and compression @ rate of 96% Dear Sir or Madam, I have received notification that you posted a compression algorithm on the newsgroup comp.lang.python on or about 10:27:26 on the 04/14/2005. I am writ

Re: Supercomputer and encryption and compression @ rate of 96%

2005-04-14 Thread R. C. James Harlow
On Thursday 14 April 2005 22:21, R. C. James Harlow wrote: > You have to do that before Fredrick's script works... Damn - 'Fredrik's' - I accidentally decompressed his name. pgpbUXNRRyNvA.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Supercomputer and encryption and compression @ rate of 96%

2005-04-14 Thread R. C. James Harlow
On Thursday 14 April 2005 22:18, Tiziano Bettio wrote: > Actually your script doesn't work on my python distribution... Works fine here - did you decompress the first bit of the python executable? You have to do that before Fredrick's script works... pgpYFHzjRTUoB.pgp Description: PGP signatur

Re: Python license (2.3)

2005-04-12 Thread R. C. James Harlow
On Tuesday 12 April 2005 09:51, Antoon Pardon wrote: > It seems I have to include the following in > my code: > > "Copyright (c) 2001, 2002 Python Software Foundation; >All Rights Reserved" > > Do I understand correctly? You are of course allowed to *add* your own copyright statement: "Copy

Re: database in python ?

2005-04-11 Thread R. C. James Harlow
On Monday 11 April 2005 11:01, Pierre-Frédéric Caillaud wrote: > psycopg ... has a dictfetchall() method which is worth its weight in > donuts ! It's very simple to write one for MySQLdb: def dictfetchall(cursor): '''Takes a MySQLdb cursor and returns the rows as dictionaries.''' col_nam