Re: checking if a list is empty

2011-05-06 Thread Chris Rebert
On Thu, May 5, 2011 at 11:36 PM, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? Option (2), IMO. > li = [] > > (1) if len(li) == 0: > ... FYI, also equivalent: if not len(li): ... > or > (2) if not li: Cheers, Chris -- http://mail.pytho

string formatting

2011-05-06 Thread Jabba Laci
Hi, Which is the preferred way of string formatting? (1) "the %s is %s" % ('sky', 'blue') (2) "the {0} is {1}".format('sky', 'blue') (3) "the {} is {}".format('sky', 'blue') As I know (1) is old style. (2) and (3) are new but (3) is only supported from Python 2.7+. Which one should be used?

Re: string formatting

2011-05-06 Thread Steven D'Aprano
On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: > Jabba Laci a écrit ce vendredi 6 mai 2011 09:18 dans > : > >> Hi, >> >> Which is the preferred way of string formatting? >> >> (1) "the %s is %s" % ('sky', 'blue') >> >> (2) "the {0} is {1}".format('sky', 'blue') >> >> (3) "the {} is {

Re: string formatting

2011-05-06 Thread Chris Rebert
On Fri, May 6, 2011 at 1:46 AM, Steven D'Aprano wrote: > On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: >> Jabba Laci a écrit ce vendredi 6 mai 2011 09:18 dans >> : >>> Hi, >>> >>> Which is the preferred way of string formatting? >>> >>> (1) "the %s is %s" % ('sky', 'blue') >>> >>> (2) "t

seems like a bug in isinstance()

2011-05-06 Thread dmitrey
hi all, suppose I've created a class Point in file .../openopt/kernel/Point.py Consider the code in file .../somewhere/file1.py from openopt.kernel.Point import Point p = Point() now let's pass p into a func from .../openopt/kernel/file2.py and check from Point import Point isinstance(p, Point)

Re: Development tools and practices for Pythonistas

2011-05-06 Thread Jonathan Hartley
On Apr 26, 3:39 pm, snorble wrote: > I appreciate any advice or guidance anyone has to offer. The 'Python Project HOWTO' gives good advice in terms of setting up a new project, what files and directories to create, what to put in version control, etc: http://infinitemonkeycorps.net/docs/pph/ Al

Re: seems like a bug in isinstance()

2011-05-06 Thread Chris Rebert
On Fri, May 6, 2011 at 2:24 AM, dmitrey wrote: > hi all, > > suppose I've created a class Point in file .../openopt/kernel/Point.py > > Consider the code in file .../somewhere/file1.py > from openopt.kernel.Point import Point > p = Point() > > now let's pass p into a func from .../openopt/kernel/f

Re: Development tools and practices for Pythonistas

2011-05-06 Thread Tim Golden
On 06/05/2011 10:51, Jonathan Hartley wrote: On Apr 26, 3:39 pm, snorble wrote: I appreciate any advice or guidance anyone has to offer. The 'Python Project HOWTO' gives good advice in terms of setting up a new project, what files and directories to create, what to put in version control, etc

Re: Embedding Python's library as zip file

2011-05-06 Thread Wojtek Mamrak
> Are you calling Py_SetProgramName? That may help to set sys.prefix > and sys.exec_prefix. However, looking at site.py, it appears that > it's only looking for proper directories. I don't think it will be > able to add a site-packages inside a zip archive at all; you will just > have to add tha

Re: PIL: The _imaging C module is not installed

2011-05-06 Thread Christian Heimes
Am 06.05.2011 01:48, schrieb Michel Claveau - MVP: > Re! > > And why the problem no exist with PIL 1.1.6? (only 1.1.7) > Is that the version 1.1.6 does not use these libraries? PIL 1.1.6 also uses its internal C library to speed things up. For Windows you should use the precompiled packages. ht

Re: seems like a bug in isinstance()

2011-05-06 Thread dmitrey
On May 6, 12:57 pm, Chris Rebert wrote: > On Fri, May 6, 2011 at 2:24 AM, dmitrey wrote: > > hi all, > > > suppose I've created a class Point in file .../openopt/kernel/Point.py > > > Consider the code in file .../somewhere/file1.py > > from openopt.kernel.Point import Point > > p = Point() > > >

Re: checking if a list is empty

2011-05-06 Thread Richard Thomas
On May 6, 7:36 am, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? > > li = [] > > (1) if len(li) == 0: > ... > or > (2) if not li: > ... > > Thanks, > > Laszlo I prefer (1), it feels more explicit about what I'm testing. The fact that empty sequ

if statement multiple or

2011-05-06 Thread Lutfi Oduncuoglu
Hi, I am trying to write a script and I realised that I need to use something like if ('a' or 'b' or 'c') not in line: print line But it does not work for. What may be the problem Thanks, Lutfi -- http://mail.python.org/mailman/listinfo/python-list

Re: if statement multiple or

2011-05-06 Thread Christian Heimes
Am 06.05.2011 12:47, schrieb Lutfi Oduncuoglu: > Hi, > > I am trying to write a script and I realised that I need to use something > like > > if ('a' or 'b' or 'c') not in line: >print line > > But it does not work for. What may be the problem if any(s not in line for s in ('a', 'b', 'c'))

Re: if statement multiple or

2011-05-06 Thread Albert Hopkins
On Fri, 2011-05-06 at 13:47 +0300, Lutfi Oduncuoglu wrote: > Hi, > > I am trying to write a script and I realised that I need to use > something like > > if ('a' or 'b' or 'c') not in line: >print line > The expression: ('a' or 'b' or 'c') evaluates to True True not in line Is

Re: if statement multiple or

2011-05-06 Thread Albert Hopkins
Correction: ('a' or 'b' or 'c') evaluates to 'a' -- http://mail.python.org/mailman/listinfo/python-list

Re: if statement multiple or

2011-05-06 Thread Chris Rebert
On Fri, May 6, 2011 at 4:02 AM, Albert Hopkins wrote: > On Fri, 2011-05-06 at 13:47 +0300, Lutfi Oduncuoglu wrote: >> Hi, >> >> I am trying to write a script and I realised that I need to use >> something like >> >> if ('a' or 'b' or 'c')  not in line: >>    print line >> > > The expression: >    

Re: checking if a list is empty

2011-05-06 Thread James Mills
On Fri, May 6, 2011 at 4:36 PM, Jabba Laci wrote: > If I want to check if a list is empty, which is the more pythonic way? [...] > (2) if not li: This is fine. cheers James -- -- James Mills -- -- "Problems are solved by method" -- http://mail.python.org/mailman/listinfo/python-list

Re: if statement multiple or

2011-05-06 Thread James Mills
On Fri, May 6, 2011 at 8:47 PM, Lutfi Oduncuoglu wrote: > I am trying to write a script and I realised that I need to use something > like > > if ('a' or 'b' or 'c')  not in line: >    print line > > But it does not work for. What may be the problem You will need to (naively) do this: if "a" not

Python packaging (was Development tools and practices for Pythonistas)

2011-05-06 Thread rusi
On May 6, 2:59 pm, Tim Golden wrote: > On 06/05/2011 10:51, Jonathan Hartley wrote: > > > On Apr 26, 3:39 pm, snorble  wrote: > >> I appreciate any advice or guidance anyone has to offer. > > > The 'Python Project HOWTO' gives good advice in terms of setting up a > > new project, what files and di

Re: if statement multiple or

2011-05-06 Thread scattered
On May 6, 7:00 am, Christian Heimes wrote: > Am 06.05.2011 12:47, schrieb Lutfi Oduncuoglu: > > > Hi, > > > I am trying to write a script and I realised that I need to use something > > like > > > if ('a' or 'b' or 'c')  not in line: > >    print line > > > But it does not work for. What may be th

Re: if statement multiple or

2011-05-06 Thread Christian Heimes
Am 06.05.2011 14:09, schrieb scattered: > sets could also work > > if set('abc') & set(line) == set(): > print line Right! Sets work in this special case, because the OP just wants to search for a single char. It won't work for longer strings, though. Also I would write the test as: if set

Re: BeautifulSoup import error

2011-05-06 Thread nirinA raseliarison
[1011_wxy] I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 the error i see is a SyntaxError. Is there any differences between Python 3.2 and other version? yes. and there is a tool, 2to3, which converts Python 2.x scripts to work with 3.x. And the error message w

Re: PIL: The _imaging C module is not installed

2011-05-06 Thread Wojtek Mamrak
@Michel use PIL downloaded from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/ regards 2011/5/6 Christian Heimes : > Am 06.05.2011 01:48, schrieb Michel Claveau - MVP: >> Re! >> >> And why the problem no exist with PIL 1.1.6?  (only 1.1.7) >> Is that the version 1.1.6 does not use these librari

Re: string formatting

2011-05-06 Thread nn
On May 6, 8:10 am, Web Dreamer wrote: > Chris Rebert a écrit ce vendredi 6 mai 2011 11:23 dans > : > > > > > I'm not them, but: > > "Note: The formatting operations described here [involving %] are > > obsolete and may go away in future versions of Python. Use the new > > String Formatting [i.e.

Re: access to some text string in PDFs

2011-05-06 Thread Robert Pazur
Hi Chris, thanks for fast reply and all recommendations in helps me much! as you recommended me i used Pdfminer module to extract the text from pdf files and then with file.xreadlines() I allocated the lines where my keyword ("factors in this case") appears. Till now i extract just the lines but

Re: What other languages use the same data model as Python?

2011-05-06 Thread Neil Cerutti
On 2011-05-05, Chris Angelico wrote: > On Fri, May 6, 2011 at 1:29 AM, Roy Smith wrote: >> "Hey, let's override operator,() and have some fun" > > Destroying sanity, for fun and profit. I was thinking more along the lines of stuff like combining the envelope pattern (an interface class containin

Re: if statement multiple or

2011-05-06 Thread scattered
On May 6, 8:25 am, Christian Heimes wrote: > Am 06.05.2011 14:09, schrieb scattered: > > > sets could also work > > > if set('abc') & set(line) == set(): > >      print line > > Right! > Sets work in this special case, because the OP just wants to search for > a single char. It won't work for long

Re: Embedding Python's library as zip file

2011-05-06 Thread Wojtek Mamrak
> I used py2exe in the past for that, see > http://www.py2exe.org/index.cgi/ShippingEmbedded Thanks for the advice, py2exe seems to be a great tool. Unfortunately the application stops executing at the same place. It might be the case of PIL library, I found some entries about it on py2exe site.

Re: if statement multiple or

2011-05-06 Thread Tim Golden
On 06/05/2011 14:17, scattered wrote: On May 6, 8:25 am, Christian Heimes wrote: Am 06.05.2011 14:09, schrieb scattered: sets could also work if set('abc')& set(line) == set(): print line Right! Sets work in this special case, because the OP just wants to search for a single char.

Re: PIL: The _imaging C module is not installed

2011-05-06 Thread Nico Grubert
> PIL will compile and install if you don't have some development > libraries and then simply not work or not work up to full steam when > used. > > To avoid this, you need to install the appropriate libraries, among > which are: > > libjpeg-devel > freetype-devel > libpng-devel Dear Albert Tha

Re: string formatting

2011-05-06 Thread Steven D'Aprano
On Fri, 06 May 2011 02:23:19 -0700, Chris Rebert wrote: > On Fri, May 6, 2011 at 1:46 AM, Steven D'Aprano > wrote: >> On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: >>> Jabba Laci a écrit ce vendredi 6 mai 2011 09:18 dans >>> : Hi, Which is the preferred way of string form

Re: string formatting

2011-05-06 Thread Steven D'Aprano
On Fri, 06 May 2011 14:10:17 +0200, Web Dreamer wrote: > What I would like to know is the difference between "deprecated" and > "obsolete"... Writing x*x instead of x**2 is obsolete, but it will never go away. Writing apply(func, args) instead of func(*args) is deprecated. It has gone away. O

Wing IDE 4.0.2 Released

2011-05-06 Thread Wingware
Hi, Wingware has released version 4.0.2 of Wing IDE, an integrated development environment designed specifically for the Python programming language. Wing IDE is a cross-platform Python IDE that provides a professional code editor with vi, emacs, and other key bindings, auto-completion, call tip

Re: Python IDE/text-editor

2011-05-06 Thread Alec Taylor
No thanks, it's shareware, doesn't included embedded python interpreter out-of-the-box, and isn't portable. On Fri, May 6, 2011 at 2:39 PM, JussiJ wrote: > On Apr 16, 1:20 pm, Alec Taylor wrote: > >> I'm looking for an IDE which offers syntax-highlighting, >> code-completion, tabs, > > The Zeus

Re: string formatting

2011-05-06 Thread MRAB
On 06/05/2011 08:18, Jabba Laci wrote: Hi, Which is the preferred way of string formatting? (1) "the %s is %s" % ('sky', 'blue') (2) "the {0} is {1}".format('sky', 'blue') (3) "the {} is {}".format('sky', 'blue') As I know (1) is old style. (2) and (3) are new but (3) is only supported from

Re: string formatting

2011-05-06 Thread Adam Tauno Williams
On Fri, 2011-05-06 at 15:58 +0100, MRAB wrote: > On 06/05/2011 08:18, Jabba Laci wrote: > > Which is the preferred way of string formatting? > > (1) "the %s is %s" % ('sky', 'blue') > > (2) "the {0} is {1}".format('sky', 'blue') > > (3) "the {} is {}".format('sky', 'blue') > > As I know (1) is old

Re: string formatting

2011-05-06 Thread MRAB
On 06/05/2011 16:06, Adam Tauno Williams wrote: On Fri, 2011-05-06 at 15:58 +0100, MRAB wrote: On 06/05/2011 08:18, Jabba Laci wrote: Which is the preferred way of string formatting? (1) "the %s is %s" % ('sky', 'blue') (2) "the {0} is {1}".format('sky', 'blue') (3) "the {} is {}".format('sky',

Re: Coolest Python recipe of all time

2011-05-06 Thread Steven D'Aprano
On Mon, 02 May 2011 10:33:31 -0700, Raymond Hettinger wrote: > I think it is time to give some visibility to some of the instructive > and very cool recipes in ActiveState's python cookbook. [...] > What are your favorites? I'm not sure if favourite is the right word, but I'm amazed by this one:

Re: seems like a bug in isinstance()

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 4:20 AM, dmitrey wrote: > Thanks Cris, however, I had understood reason of the bug and mere > informed Python developers of the bug to fix it. No you haven't. Few if any Python developers make a habit of reading this newsgroup. To actually report the issue so that it migh

Re: Coolest Python recipe of all time

2011-05-06 Thread geremy condra
On Fri, May 6, 2011 at 9:59 AM, Steven D'Aprano wrote: > On Mon, 02 May 2011 10:33:31 -0700, Raymond Hettinger wrote: > >> I think it is time to give some visibility to some of the instructive >> and very cool recipes in ActiveState's python cookbook. > [...] >> What are your favorites? > > > I'm

setuptools for 64-bit 2.7.1 on 64-bit Windows 7?

2011-05-06 Thread Dick Bridges
Hi all, Can someone provide some search terms I can use to find guidelines for installing modules for my 'stock' 64-bit r 271:86832, Nov 27, 2010 [MSC v.1500 64 bit (AMD)] on Win32. Host is 64-bit Windows 7. My goal is to install suds. Period. That's all. So far I've spent the better part o

Re: PIL: The _imaging C module is not installed

2011-05-06 Thread Irmen de Jong
On 06-05-11 15:56, Nico Grubert wrote: However, running the selftest still fails: $ python selftest.py *** The _imaging C module is not installed I had this happening to me as well someday. I recall that first installing it (python setup.py install), and then rerunning selftest, solved that

Re: Hello Friends

2011-05-06 Thread Alister Ware
On Thu, 05 May 2011 21:55:22 -0700, Ashraf Ali wrote: > Do you need legal help.If so Please visit > www.chicagopersonalinjurylawyerz.blogspot.com sorry I would only use a reputable firm (spaming a news group makes you disreputable by default) -- My NOSE is NUMB! -- http://mail.python.org/mai

Re: What other languages use the same data model as Python?

2011-05-06 Thread Chris Torek
>>> John Nagle wrote: A reasonable compromise would be that "is" is treated as "==" on immutable objects. (Note: I have no dog in this fight, I would be happy with a changed "is" or with the current one -- leaky abstractions are fine with me, provided I am told *when* they may -- or some

Re: What other languages use the same data model as Python?

2011-05-06 Thread Chris Torek
In article harrismh777 wrote: >There may be some language somewhere that does pass-by-reference which >is not implemented under the hood as pointers, but I can't think of >any... 'cause like I've been saying, way down under the hood, we only >have direct and indirect memory addressing in to

Re: Coolest Python recipe of all time

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 10:59 AM, Steven D'Aprano wrote: > As written, amb is just a brute-force solver using more magic than is > good for any code, but it's fun to play with. This isn't really amb; as you said it's just a brute-force solver with some weird syntax. The whole point of amb is to e

Re: Hello Friends

2011-05-06 Thread John Bokma
Alister Ware writes: > On Thu, 05 May 2011 21:55:22 -0700, Ashraf Ali wrote: > >> Do you need legal help.If so Please visit >> > > sorry I would only use a reputable firm > (spaming a news group makes you disreputable by default) Does it make you disreputable? Since you just repeated the spamve

Re: What other languages use the same data model as Python?

2011-05-06 Thread Chris Torek
In article I wrote, in part: >Like it or not, Python has similar "defined as undefined" grey >areas: one is not promised, for instance, whether the "is" operator >is always True for small integers that are equal (although it is >in CPython), nor when __del__ is called (if ever), and so on. As >wi

Re: string formatting

2011-05-06 Thread harrismh777
Steven D'Aprano wrote: It's perfectly safe to continue using % formatting, if you choose. I would hope so, since its the way in most of the books, much of the doc and a majority of the code... I don't really like the old style, not because there is anything wrong with it, because its

Re: What other languages use the same data model as Python?

2011-05-06 Thread harrismh777
Chris Torek wrote: with the Python-named-Monty, we have "rigidly defined areas of >doubt and uncertainty". These exist for good reasons: to allow >different implementations. Oops, attribution error: this comes from Douglas Adams rather than Monty Python. Well, its certainly Monte-esq I li

Re: checking if a list is empty

2011-05-06 Thread Terry Reedy
On 5/6/2011 7:34 AM, James Mills wrote: On Fri, May 6, 2011 at 4:36 PM, Jabba Laci wrote: If I want to check if a list is empty, which is the more pythonic way? [...] (2) if not li: This is fine. This is the intended way. Anything in addition is extra noise and wasted calculation. In o

Re: Coolest Python recipe of all time

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 12:36 PM, Ian Kelly wrote: > This is typically implemented using continuations, and I'm not sure > whether a true amb could actually be achieved in Python without adding > continuations or flow-control macros to the language. I stand corrected. After poking around a bit mo

Re: string formatting

2011-05-06 Thread harrismh777
harrismh777 wrote:OP wrote: (1) "the %s is %s" % ('sky', 'blue') (2) "the {0} is {1}".format('sky', 'blue') (3) "the {} is {}".format('sky', 'blue') On the other hand, consider this 3.x code snip: print("the %s is %d" % ('sky', 'blue')) That formatting will throw an exception

Python 3 dict question

2011-05-06 Thread dmitrey
hi all, suppose I have Python dict myDict and I know it's not empty. I have to get any (key, value) pair from the dict (no matter which one) and perform some operation. In Python 2 I used mere key, val = myDict.items()[0] but in Python 3 myDict.items() return iterator. Of course, I could use for ke

Re: checking if a list is empty

2011-05-06 Thread harrismh777
Terry Reedy wrote: (2) if not li: This is fine. This is the intended way. Anything in addition is extra noise and wasted calculation. In other words, let Python do the boilerplate work for you. I agree, but I don't like it. ... if not li says nothing about what li is supposed to 'be' a

Re: Python 3 dict question

2011-05-06 Thread Chris Rebert
On Fri, May 6, 2011 at 12:40 PM, dmitrey wrote: > hi all, > suppose I have Python dict myDict and I know it's not empty. > I have to get any (key, value) pair from the dict (no matter which > one) and perform some operation. > In Python 2 I used mere > key, val = myDict.items()[0] > but in Python

Re: string formatting

2011-05-06 Thread Neil Cerutti
On 2011-05-06, harrismh777 wrote: > Steven D'Aprano wrote: >> It's perfectly safe to continue using % formatting, if you >> choose. > > I would hope so, since its the way in most of the books, much > of the doc and a majority of the code... > > I don't really like the old style, not because there

Re: string formatting

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 1:39 PM, harrismh777 wrote: > harrismh777 wrote:    OP wrote: > >> (1) "the %s is %s" % ('sky', 'blue') >> >> (2) "the {0} is {1}".format('sky', 'blue') >> >> (3) "the {} is {}".format('sky', 'blue') > >   On the other hand, consider this 3.x code snip: > >   print("the %s i

Re: Python 3 dict question

2011-05-06 Thread dmitrey
On May 6, 10:51 pm, Chris Rebert wrote: > On Fri, May 6, 2011 at 12:40 PM, dmitrey wrote: > > hi all, > > suppose I have Python dict myDict and I know it's not empty. > > I have to get any (key, value) pair from the dict (no matter which > > one) and perform some operation. > > In Python 2 I used

Re: Coolest Python recipe of all time

2011-05-06 Thread Raymond Hettinger
[Steven D'Aprano]: > As written, amb is just a brute-force solver using more magic than is > good for any code, but it's fun to play with. With a small change in API, much of the magic isn't needed. from itertools import product def amb(func, *argument_ranges): for args in product(*argument_

Re: checking if a list is empty

2011-05-06 Thread Eric Snow
On Fri, May 6, 2011 at 1:31 PM, Terry Reedy wrote: > On 5/6/2011 7:34 AM, James Mills wrote: > >> On Fri, May 6, 2011 at 4:36 PM, Jabba Laci wrote: >> >>> If I want to check if a list is empty, which is the more pythonic way? >>> >> >> [...] >> >> (2) if not li: >>> >> >> This is fine. >> > > T

Re: Python 3 dict question

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 1:51 PM, Chris Rebert wrote: > On Fri, May 6, 2011 at 12:40 PM, dmitrey wrote: >> hi all, >> suppose I have Python dict myDict and I know it's not empty. >> I have to get any (key, value) pair from the dict (no matter which >> one) and perform some operation. >> In Python 2

Re: checking if a list is empty

2011-05-06 Thread Adam Tauno Williams
On Fri, 2011-05-06 at 14:49 -0500, harrismh777 wrote: > Terry Reedy wrote: > >>> (2) if not li: > >> This is fine. > > This is the intended way. Anything in addition is extra noise and wasted > > calculation. In other words, let Python do the boilerplate work for you. > I agree, but I don't lik

Re: checking if a list is empty

2011-05-06 Thread Chris Rebert
On Fri, May 6, 2011 at 1:05 PM, Adam Tauno Williams wrote: > - and ignore the Pythonistas [they're nuts;  that x.count() doesn't work > is amazingly stupid]. Eh? It works fine. [5, 2, 2, 1, 2].count(2) == 3. If you mean you want len(x) to be spelled x.count(), that's equally stupid; `count` woul

Re: Python 3 dict question

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 1:57 PM, dmitrey wrote: > Unfortunately, it doesn't work, it turn out to be dict_items: next({1:2}.items()) > Traceback (most recent call last): >  File "", line 1, in > TypeError: dict_items object is not an iterator So call iter() on it first: next(iter(myDict.item

How can I print one sqlite table with UTF-8 collumn

2011-05-06 Thread Jayme Proni Filho
I have one sqlite database called aripuanaonline.db. In this database I have one table with two collumns first with autoincrement not null and other with varchar(100) not null. I got this error: Traceback (most recent call last): File "C:\Documents and Settings\Marco\Desktop\aripuanaonline\arip

Re: Python 3 dict question

2011-05-06 Thread Rob Wolfe
dmitrey writes: > hi all, > suppose I have Python dict myDict and I know it's not empty. > I have to get any (key, value) pair from the dict (no matter which > one) and perform some operation. > In Python 2 I used mere > key, val = myDict.items()[0] > but in Python 3 myDict.items() return iterato

Re: string formatting

2011-05-06 Thread Terry Reedy
On 5/6/2011 3:22 PM, harrismh777 wrote: I don't really like the old style, not because there is anything wrong with it, There is in that it special cases tuples. For instance, a message function like def emsg(x): print("The following object caused a proplem: %s" % x) raises "TypeError: n

Re: Python 3 dict question

2011-05-06 Thread nirinA raseliarison
[dmitrey] > hi all, > suppose I have Python dict myDict and I know it's not empty. > I have to get any (key, value) pair from the dict (no matter which > one) and perform some operation. > In Python 2 I used mere > key, val = myDict.items()[0] > but in Python 3 myDict.items() return iterator. > Of

Re: checking if a list is empty

2011-05-06 Thread scattered
On May 6, 2:36 am, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? > > li = [] > > (1) if len(li) == 0: > ... > or > (2) if not li: > ... > > Thanks, > > Laszlo is there any problem with (3) if li == []: ? Seems to work when I test it and seem

Re: setuptools for 64-bit 2.7.1 on 64-bit Windows 7?

2011-05-06 Thread David Robinow
On Fri, May 6, 2011 at 1:43 PM, Dick Bridges wrote: > Simple question: Is it true that no setuptools (or any other module > installer) exists for 64-bit python 2.7.1? If there is an installer that > works, what terms might I use to Google for information on how to acquire > and install it? Doesn't

Dictionary Views -- good examples? [was Re: Python 3 dict question]

2011-05-06 Thread Ethan Furman
Ian Kelly wrote: On Fri, May 6, 2011 at 1:57 PM, dmitrey wrote: Unfortunately, it doesn't work, it turn out to be dict_items: next({1:2}.items()) Traceback (most recent call last): File "", line 1, in TypeError: dict_items object is not an iterator So call iter() on it first: next(iter(m

Re: checking if a list is empty

2011-05-06 Thread Raymond Hettinger
On May 5, 11:36 pm, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? > > li = [] > > (1) if len(li) == 0: > ... > or > (2) if not li: The Python core developers use the second form. See http://www.python.org/dev/peps/pep-0008/ for the official rec

Re: checking if a list is empty

2011-05-06 Thread Philip Semanchuk
On May 6, 2011, at 5:57 PM, scattered wrote: > On May 6, 2:36 am, Jabba Laci wrote: >> Hi, >> >> If I want to check if a list is empty, which is the more pythonic way? >> >> li = [] >> >> (1) if len(li) == 0: >> ... >> or >> (2) if not li: >> ... >> >> Thanks, >> >> Laszlo > > is there any

Re: What other languages use the same data model as Python?

2011-05-06 Thread Chris Angelico
On Sat, May 7, 2011 at 5:25 AM, harrismh777 wrote: > Chris Torek wrote: >>> >>> with the Python-named-Monty, we have "rigidly defined areas of >>> >doubt and uncertainty".  These exist for good reasons: to allow >>> >different implementations. >> >> Oops, attribution error: this comes from Douglas

Re: checking if a list is empty

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 4:21 PM, Philip Semanchuk wrote: > What if it's not a list but a tuple or a numpy array? Often I just want to > iterate through an element's items and I don't care if it's a list, set, etc. > For instance, given this function definition -- > > def print_items(an_iterable):

Re: string formatting

2011-05-06 Thread Chris Angelico
On Sat, May 7, 2011 at 6:54 AM, Terry Reedy wrote: > def emsg(x): >  if isinstance(x,tuple): >    x = (x,) >  print(The following object caused a proplem: %s" % x) > Couldn't you just do that unconditionally? print(The following object caused a proplem: %s" % (x,)) Chris Angelico -- http://mail

Re: Dictionary Views -- good examples? [was Re: Python 3 dict question]

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 4:49 PM, Ethan Furman wrote: > Ian Kelly wrote: >> >> On Fri, May 6, 2011 at 1:57 PM, dmitrey wrote: >>> >>> Unfortunately, it doesn't work, it turn out to be dict_items: >> >> next({1:2}.items()) >>> >>> Traceback (most recent call last): >>>  File "", line 1, in

Re: checking if a list is empty

2011-05-06 Thread Jon Clements
On May 7, 12:51 am, Ian Kelly wrote: > On Fri, May 6, 2011 at 4:21 PM, Philip Semanchuk wrote: > > What if it's not a list but a tuple or a numpy array? Often I just want to > > iterate through an element's items and I don't care if it's a list, set, > > etc. For instance, given this function d

Re: checking if a list is empty

2011-05-06 Thread Chris Angelico
On Sat, May 7, 2011 at 6:05 AM, Adam Tauno Williams wrote: > On Fri, 2011-05-06 at 14:49 -0500, harrismh777 wrote: >> Terry Reedy wrote: >> >>> (2) if not li: >> >> This is fine. >> > This is the intended way. Anything in addition is extra noise and wasted >> > calculation. In other words, let Pyt

PyGTK, Glade/libglade. What am I doing wrong?

2011-05-06 Thread Даниил Рыжков
Sorry for my English (I could not find help in the Russian community) I'm trying to learn PyGTK and Glade. I made test window in Glade and saved it as "test.glade" (attached). Then I wrote script "test.py"(attached, http://pastebin.com/waKytam3). I tried to run it. While the script was executed, co

Re: string formatting

2011-05-06 Thread Steven D'Aprano
On Fri, 06 May 2011 14:39:15 -0500, harrismh777 wrote: > On the other hand, consider this 3.x code snip: > > print("the %s is %d" % ('sky', 'blue')) > > > That formatting will throw an exception, because the format > construct is restricting the format entry to be a number, which 'b

Re: PyGTK, Glade/libglade. What am I doing wrong?

2011-05-06 Thread Benjamin Kaplan
On May 6, 2011 7:05 PM, "Даниил Рыжков" wrote: > > Sorry for my English (I could not find help in the Russian community) > I'm trying to learn PyGTK and Glade. I made test window in Glade and > saved it as "test.glade" (attached). Then I wrote script > "test.py"(attached, http://pastebin.com/waKyt

Re: checking if a list is empty

2011-05-06 Thread Steven D'Aprano
On Fri, 06 May 2011 16:05:09 -0400, Adam Tauno Williams wrote: > I'd never accept code like "if not x" as an empty test. So much the worse for you then. The point of the "if x" idiom is that it is a polymorphic test which is independent of the type. It works with any non-broken object[1], no m

Re: checking if a list is empty

2011-05-06 Thread Steven D'Aprano
On Fri, 06 May 2011 14:57:21 -0700, scattered wrote: > is there any problem with > > (3) if li == []: > > ? > > Seems to work when I test it and seems to clearly test what you are > trying to test. The only problem might be if in some contexts == has the > semantics of checking for object ident

Re: PyGTK, Glade/libglade. What am I doing wrong?

2011-05-06 Thread Даниил Рыжков
> I haven't used gtk before, but is there a show method or something similar > you need, to actually make the window appear? I don't know. I think "self.wTree = gtk.glade.XML(self.gladefile)" should do this. For example, author of this tutorial (http://www.learningpython.com/2006/05/07/creating-a-g

Re: PyGTK, Glade/libglade. What am I doing wrong?

2011-05-06 Thread craf
On May 6, 2011 7:05 PM, "Даниил Рыжков" wrote: > > Sorry for my English (I could not find help in the Russian community) > I'm trying to learn PyGTK and Glade. I made test window in Glade and > saved it as "test.glade" (attached). Then I wrote script > "test.py"(attached, http://pastebin.com/waKyt

Re: PyGTK, Glade/libglade. What am I doing wrong?

2011-05-06 Thread Даниил Рыжков
Thanks, Cristian! It works. > List of Pygtk: http://www.daa.com.au/mailman/listinfo/pygtk Thanks again. Subscribed :) 2011/5/7 craf : > Hi. > > Try this: > > #!/usr/bin/env python > > import gtk.glade > > class TestPyGtk: >    """This is an Hello World GTK application""" > >    def __init__(self):

Testing tools classification

2011-05-06 Thread rusi
There is this nice page of testing tools taxonomy: http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy But it does not list staf: http://staf.sourceforge.net/index.php. -- http://mail.python.org/mailman/listinfo/python-list