[Tutor] Tutor Digest, Vol 103, Issue 124

Afzal Hossain afzal.pcc at gmail.com
Tue Sep 25 18:06:42 CEST 2012


hi i am trying to install python3.1.5 tgz in windows 7 but not getting
exe file for installing.can u help me for this

On 9/25/12, tutor-request at python.org <tutor-request at python.org> wrote:
> Send Tutor mailing list submissions to
> 	tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> 	tutor-request at python.org
>
> You can reach the person managing the list at
> 	tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>    1. Usefulness of BIFs all() and any()? (Richard D. Moores)
>    2. Re: Usefulness of BIFs all() and any()? (Hugo Arts)
>    3. Re: Usefulness of BIFs all() and any()? (Dave Angel)
>    4. Re: Usefulness of BIFs all() and any()? (Steven D'Aprano)
>    5. Re: Unzipping a Zip of folders that have zips within them
>       that I'd like to unzip all at once. (Gregory Lund)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 25 Sep 2012 04:55:47 -0700
> From: "Richard D. Moores" <rdmoores at gmail.com>
> To: Tutor List <tutor at python.org>
> Subject: [Tutor] Usefulness of BIFs all() and any()?
> Message-ID:
> 	<CALMxxxkhjHF0BEfLOox0zPbAiD=zs35S3NaVNhUjDba+88E_Cg at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> I was just perusing the Built-in Functions of Python 3.2 (<
> http://docs.python.org/py3k/library/functions.html>) and was wondering
> where would one ever use any() or all().
>
> all(iterable)
> Return True if all elements of the iterable are true (or if the iterable is
> empty). Equivalent to:
>
> def all(iterable):
>     for element in iterable:
>         if not element:
>             return False
>     return True
>
> any(iterable)
> Return True if any element of the iterable is true. If the iterable is
> empty, return False. Equivalent to:
>
> def any(iterable):
>     for element in iterable:
>         if element:
>             return True
>     return False
>
> Given a = [0, 1, 2, 3],
>
>>>> all(a)
> False
>>>> any(a)
> True
>
> But so what? Could I get some better examples?
>
> And why
>>>> all([])
> True
>>>> any([])
> False
>
> Thanks,
>
> Dick Moores
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> <http://mail.python.org/pipermail/tutor/attachments/20120925/2f126a49/attachment-0001.html>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 25 Sep 2012 14:24:20 +0200
> From: Hugo Arts <hugo.yoshi at gmail.com>
> To: "Richard D. Moores" <rdmoores at gmail.com>
> Cc: Tutor List <tutor at python.org>
> Subject: Re: [Tutor] Usefulness of BIFs all() and any()?
> Message-ID:
> 	<CAJmBOfmgBBw4mvYb7HPGEigm5yg-KaRjx86QL6zYLQMKRFivAA at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> On Tue, Sep 25, 2012 at 1:55 PM, Richard D. Moores
> <rdmoores at gmail.com>wrote:
>
>> I was just perusing the Built-in Functions of Python 3.2 (<
>> http://docs.python.org/py3k/library/functions.html>) and was wondering
>> where would one ever use any() or all().
>>
>> But so what? Could I get some better examples?
>>
>
> I frequently use any() or all() in combination with a generator expression
> to check for a certain condition over a list of elements. Let's say, for
> example, I want to make sure all files I used are closed at the end of a
> function (or perhaps a unit test?)
>
> assert all(f.closed for f in open_files)
>
> probably not the *most* useful example of that, but I'm sure you understand
> the principle. It's useful when you need to check if all() or any() of an
> iterator pass a certain condition.
>
>
>>
>> And why
>> >>> all([])
>> True
>> >>> any([])
>> False
>>
>
> People often wonder over this one. any([]) should logically be False,
> because it is like asking the question "is there any member in this
> iterable that is True?" Obviously, there is not, since the iterator is
> empty. all([]) is True by the principle of vacuous truth:
>
> http://en.wikipedia.org/wiki/Vacuous_truth
>
> The principle, though somewhat intuitive, has a strong mathematical basis.
>
> HTH,
> Hugo
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> <http://mail.python.org/pipermail/tutor/attachments/20120925/0d4590e1/attachment-0001.html>
>
> ------------------------------
>
> Message: 3
> Date: Tue, 25 Sep 2012 08:33:22 -0400
> From: Dave Angel <d at davea.name>
> To: "Richard D. Moores" <rdmoores at gmail.com>
> Cc: Tutor List <tutor at python.org>
> Subject: Re: [Tutor] Usefulness of BIFs all() and any()?
> Message-ID: <5061A492.2080100 at davea.name>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On 09/25/2012 07:55 AM, Richard D. Moores wrote:
>> <snip>
>>
>> And why
>>>>> all([])
>> True
>>>>> any([])
>> False
>>
>>
>
> Same problem as calling sum() with an empty list.  What value should it
> have?  Clearly, it should return its 'start' parameter, which defaults
> to zero.
>
> Well the all() has a start value of True, and ands that with each
> element of the iterable till one of them ends up with false.  Similarly,
> the any() has a start value of False.
>
>
>
> --
>
> DaveA
>
>
>
> ------------------------------
>
> Message: 4
> Date: Tue, 25 Sep 2012 23:41:53 +1000
> From: Steven D'Aprano <steve at pearwood.info>
> To: tutor at python.org
> Subject: Re: [Tutor] Usefulness of BIFs all() and any()?
> Message-ID: <5061B4A1.4040304 at pearwood.info>
> Content-Type: text/plain; charset=UTF-8; format=flowed
>
> On 25/09/12 21:55, Richard D. Moores wrote:
>> I was just perusing the Built-in Functions of Python 3.2 (<
>> http://docs.python.org/py3k/library/functions.html>) and was wondering
>> where would one ever use any() or all().
>
> Both are very useful. They are especially useful for validating data, or
> for interactive use. For instance, to check that a list of numbers are
> all positive:
>
> if all(x > 0 for x in numbers):  ...
>
> and then go on to process the numbers.
>
> There are over a dozen examples of any or all in the Python standard
> library. (There would be more, but a lot of the std lib pre-dates the two
> functions.) They tend to be used to check the state of some collection of
> values, and return a flag. For example:
>
>      return any(key in m for m in self.maps)
>
> checks whether a key appears in a collection of maps. Otherwise that one
> line would be written as:
>
>      for m in self.maps:
>          if key in m:
>              return True
>      return False
>
>
> Notice the pattern there is that if the collection of maps is empty, then
> you return False. And sure enough, any([]) returns False.
>
> In an example from my own code, I have a pool of threads doing work, and
> loop until all of the threads have finished:
>
>      while any(t.isAlive() for t in threads):  ...
>
>
> Another example, I check that a list of objects are all integers:
>
>      if not all(isinstance(i, int) for i in key):  ...
>
>
> Basically, the functions all and any should be used whenever you need to
> check that a condition holds for ALL the values, or for ANY value, in a
> collection of values. If they sound like trivial functions, well, yes,
> they are trivial like a hammer is trivial. It's just a lump of metal used
> for bashing in nails.
>
>
>> And why
>>>>> all([])
>> True
>>>>> any([])
>> False
>
> Because they match the most useful and common patterns for testing that
> some condition holds. Normally we want to test:
>
> * there is at least one value where this condition holds (use any)
>
> rather than:
>
> * there are no values at all, or there is at least one value...
>
> Imagine the set of living people with no heads. If any of them are called
> "Steve", you pay me a dollar. Do you owe me anything?
>
> The case for all([]) returning True is a bit less obvious. One of the first
> things I did in my own code was write an alternative version of all:
>
> def all2(iterable):
>      magic = object()
>      element = magic
>      for element in iterable:
>          if not element:
>              return False
>      return element is not magic
>
>
> but I've never used it.
>
> See also:
>
> http://en.wikipedia.org/wiki/Vacuous_truth
>
>
>
>
> --
> Steven
>
>
> ------------------------------
>
> Message: 5
> Date: Tue, 25 Sep 2012 07:52:04 -0700
> From: Gregory Lund <gnj091405 at gmail.com>
> To: Peter Otten <__peter__ at web.de>, Oscar Benjamin
> 	<oscar.j.benjamin at gmail.com>
> Cc: tutor at python.org
> Subject: Re: [Tutor] Unzipping a Zip of folders that have zips within
> 	them that I'd like to unzip all at once.
> Message-ID:
> 	<CAK=ob9x3x-epLkySzg+uaSZyKpYXWs9jKbJJsc2Q8ud8vc_2CA at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
>> Why did you change file mode to "a"?
> I was trying different things and forgot to change it back before I
> cut/pasted.
>>
>
>
>>
>> dest_path = os.path.dirname(fullpath)
>> x.extractall(dest_path)
>>
> Ding ding ding, winner winner chicken dinner!
> It's working!
> Final .py stand alone code is:
>
> import os, os.path, zipfile, arcpy
>
> in_Zip = r'D:\D_Drive_Documents\Student_Work_Sample_usecopy1\2012-09-18
> Lab_2.zip'
>
> outDir = r"D:\D_Drive_Documents\Student_Work_Sample_usecopy1"
>
> z = zipfile.ZipFile(in_Zip,'r')
>
> z.extractall(outDir)
>
> zipContents = z.namelist()
> z.close()
>
> for item in zipContents:
>     if item.endswith('.zip'):
>         # Combine the base folder name with the subpath to the zip file
>         fullpath = os.path.join(outDir, item)
>         x = zipfile.ZipFile(fullpath,'r')
>         dest_path = os.path.dirname(fullpath)
>         x.extractall(dest_path)
>         x.close()
>
> and... the final code that I'll use in my ArcGIS script/tool is:
> (I kept the old code with absolute paths to help anyone who wanted to
> use this on their zip of zips (with it commented out and my ArcGIS
> requirements immediately below.)
>
>
> import os, os.path, zipfile, arcpy
>
> #in_Zip = r'D:\D_Drive_Documents\Student_Work_Sample_usecopy1\2012-09-18
> Lab_2.zip'
> in_Zip = arcpy.GetParameterAsText(0)
>
> #outDir = r"D:\D_Drive_Documents\Student_Work_Sample_usecopy1"
> outDir = os.getcwd()
>
> z = zipfile.ZipFile(in_Zip,'r')
>
> z.extractall(outDir)
>
> zipContents = z.namelist()
> z.close()
>
> for item in zipContents:
>     if item.endswith('.zip'):
>         # Combine the base folder name with the subpath to the zip file
>         fullpath = os.path.join(outDir, item)
>         x = zipfile.ZipFile(fullpath,'r')
>         dest_path = os.path.dirname(fullpath)
>         x.extractall(dest_path)
>         x.close()
>
> --------------------------------
> Words/pixels can not express how grateful I am to everyone that
> pitched in and helped guide me through this seemingly simple task.
> The code works & the Esri ArcGIS tool works!
>
> It's not really 'my' code or tool:
> the credit goes to Peter, Oscar, Dave, Stephen and others for
> their/your comments, debugging, code suggestions, and patience.
>
> I also appreciate the fact that someone didn't just give me the full
> code, struggling through googling etc. helped me learn.
> I'm still a rookie/neophyte, but a very happy one this morning!
> Aug. 7 to now, thanks for all the help!
>
> Thanks again!
>
> Regards,
> Greg Lund
>
> PS, but aren't you all going to miss my daily stupid questions? (ok,
> maybe not!).
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> ------------------------------
>
> End of Tutor Digest, Vol 103, Issue 124
> ***************************************
>


-- 
afzal


More information about the Tutor mailing list