Re: [Tutor] 'slice', etc

2013-12-14 Thread eryksun
On Fri, Dec 13, 2013 at 6:24 PM, Mark Lawrence  wrote:
> On 07/12/2013 10:41, spir wrote:
>> On 12/07/2013 02:45 AM, Mark Lawrence wrote:
>>>
>>> The good news is there is a memoryview in Python, see
>>> http://docs.python.org/3/library/functions.html#func-memoryview.
>>> The bad news is it doesn't work on strings.
>>> See here for the slice object
>>> http://docs.python.org/3/library/functions.html#slice.
>>
>> Thank you, Mark, I'll have a look at memoryview, seems interesting anyway.
>
> I've just remembered that one distinct disadvantage of memoryviews is that
> you can't use them anywhere if you want to do any sorting, as you can't
> compare them :(

memorview requires the buffer interface, so that excludes 3.x str,
int, and many others. But it works for bytes, bytearray, mmap, ctypes,
and numpy to name just a few. Prior to 3.3, memoryview tests equality
using C memcmp, but not relative order. Sorting the raw buffers would
be arbitrary in general.

CPython 3.3's memoryview incorporates fast unpacking for primitive
types, and otherwise uses the struct module (but see issue 3132 about
updating struct for PEP 3118; this affects various ctypes data types).
Checking if memoryview objects are equal in 3.3 uses unpacked values,
which generally allows for a more meaningful comparison:

from ctypes import c_int, c_float

i, f = c_int(1), c_float(1)
mi, mf = map(memoryview, (i, f))

>>> mi == mf
True

A memcmp of the primitive int and float buffers, as used prior to 3.3,
is clearly unequal:

>>> list(map(int, bytes(i)))
[1, 0, 0, 0]
>>> list(map(int, bytes(f)))
[0, 0, 128, 63]

It's not all roses, however. If memoryview in 3.3 fails to get a
struct unpacker, it doesn't default to using memcmp. It just assumes
inequality. This affects the view of a ctypes Array:

>>> a = (c_int * 2)(1, 2)
>>> b = (c_int * 2)(1, 2)
>>> memoryview(a) == memoryview(b)
False

The struct module doesn't know about the Array's PEP 3118 format string:

>>> memoryview(a).format
'(2)>> unpack = struct.Struct('(2)", line 1, in 
struct.error: bad char in struct format

struct understands '>> unpack = struct.Struct('>> unpack(a)
(1, 2)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Thanks a bunch (was Re: Tutor Digest, Vol 118, Issue 64)

2013-12-14 Thread eryksun
On Sat, Dec 14, 2013 at 10:16 AM, Walter Prins  wrote:
>
> Gmail matches the format of the sender.  If I reply to a text format
> email, the reply is text format.  If the original is HTML mail, it
> replies in HTML format.  In that sense it talks back and respects the
> sender on their terms.  Also, there is a drop down (right bottom) with
> which it's trivial to change from one format to the other.

This is contrary to my experience. If I send a test message to myself
in rich text mode, Gmail's webmail composer remembers that setting the
next time I reply (i.e., the reply uses styled block quoting,
practically destined to be mangled as messages are quoted multiple
times through incompatible clients). This setting is apparently stored
in one's account and remembered across sessions. I can log out, remove
all Google cookies, and the choice of rich text persists in a new
session. But outside of a test message, I never use rich text. When I
reply it's always in plain text mode; the format of the original
message doesn't matter. Maybe it's more complicated than this, but I
can only speak from experience.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quantum computing

2013-12-14 Thread William Ray Wing
On Dec 14, 2013, at 1:22 PM, Mark Lawrence  wrote:

> On 14/12/2013 17:14, Alan Gauld wrote:
>> On 14/12/13 15:37, Mark Lawrence wrote:
>>> 
>>> I believe that quantum computing is way OT for the Python tutor mailing
>>> list.
>> 
>> Yeah, you are probably right. Although there are precedents where we
>> have discussed general topics about the future of computing and
>> where/whether Python fits in.
>> 
>> But QC is probably a but more esoteric than any of those were!
>> 
> 
> True.  As it happens I'm happy to see things go OT on Python threads. It 
> makes for more interesting reading, plus people might well pick up on 
> something that otherwise they'd not have learned.  However I draw a line 
> firmly in the sand at quantum computing here.  Let's stick with the wonders 
> of list comprehensions, recursive functions and why can't Python do floating 
> point arithmetic correctly?
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask what you 
> can do for our language.
> 
> Mark Lawrence

Well, as it turns out, there actually *IS* a commercially available quantum 
computer on the market today.  It is built by a Canadian company "D-Wave 
Systems" and early prototypes have been bought by companies like Google and 
Lockeed Martin and some Government labs.  Unfortunately, it isn't clear whether 
or not it is living up to expectations…

You can read a summary and sort of intro here:  
http://spectrum.ieee.org/computing/hardware/dwaves-year-of-computing-dangerously

-Bill

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trying to parse an xml file

2013-12-14 Thread Dave Angel
On Sun, 15 Dec 2013 09:22:09 +1100, Steven D'Aprano 
 wrote:
I cannot reproduce that error. Perhaps you have inadvertently 

corrupted

Another approach to narrow the problem might be to compare md5 hashes 
for your files. If you and the op have different hashes then he's 
probably got a corrupt file.


--
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Coding for a Secret Message in a Game

2013-12-14 Thread Sky blaze
Thank you for the answers! Unfortunately, I haven't had the time to test
them out, but these answers make a lot of sense, and I'm sure they'd work.
Again, thanks!

*See ya!*
  -Skyblaze101


On Fri, Dec 13, 2013 at 2:20 PM, Danny Yoo  wrote:

> Whoops, made a small typo in the program I sent.  Let me rewrite again:
>
> ###
> def GetFailureMessage(failure_count):
> """Returns a message given how many times we've seen failure."""
> if failure_count <= 1:
> return "Try again"
> else:
> return "Please try again"
>
> ## Let's try it out:
> print(GetFailureMessage(0))
> print(GetFailureMessage(1))
> print(GetFailureMessage(2))
> ###
>
> (The mistake was in my "documentation string" at the beginning of the
> function.  I put too few quotes at the end.  Sorry about that!)
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trying to parse an xml file

2013-12-14 Thread Steven D'Aprano
On Sat, Dec 14, 2013 at 09:29:00AM -0500, bruce wrote:
> Hi.
> 
> Looking at a file -->>
> http://www.marquette.edu/mucentral/registrar/snapshot/fall13/xml/BIOL_bysubject.xml
> 
> The file is generated via online/web url, and appears to be XML.
> 
> However, when I use elementtree:
>   document = ElementTree.parse( '/apps/parseapp2/testxml.xml' )
> 
> I get an invalid error : not well-formed (invalid token):

I cannot reproduce that error. Perhaps you have inadvertently corrupted 
the file when downloading it? What did you use to download the file?

I used the wget command under Linux:

wget 
http://www.marquette.edu/mucentral/registrar/snapshot/fall13/xml/BIOL_bysubject.xml

And then I tried parsing it using ElementTree two different ways, both 
ways successfully with no errors:

py> import xml.etree.cElementTree as ET
py> tree = ET.ElementTree(file='BIOL_bysubject.xml')
py> root = tree.getroot()
py> for node in root:
... print node.tag, node.attrib
...
STAMP {}
RECORD {}
RECORD {}
RECORD {}
[... snip lots more output for brevity ...]
py> tree = ET.parse('BIOL_bysubject.xml')
py> for node in tree.iter():
... print node.tag, node.attrib
... 
[... snip even more output ...]


Both worked fine and gave no errors. I'm using Python 2.7. If you need 
additional help, I'm afraid that you're going to have to give more 
detail on what you actually did. Please show how you downloaded the 
file, what code you used to parse it, and the full error you receive. 
Copy and paste the entire traceback.



-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trying to parse an xml file

2013-12-14 Thread Steven D'Aprano
On Sat, Dec 14, 2013 at 04:03:09PM +0100, spir wrote:
> On 12/14/2013 03:29 PM, bruce wrote:
[...]
> >Anyone have any python suggestions as to how to proceed to parse out the 
> >data!
> 
> You do not tell us what you actually want to do. Since the input is invalid 
> (as XML), obviously you cannot parse it (as XML). So what?

Denis, Bruce asks for suggestions on how to parse the data from what he 
thinks is invalid XML.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quantum computing

2013-12-14 Thread Mark Lawrence

On 14/12/2013 17:14, Alan Gauld wrote:

On 14/12/13 15:37, Mark Lawrence wrote:


I believe that quantum computing is way OT for the Python tutor mailing
list.


Yeah, you are probably right. Although there are precedents where we
have discussed general topics about the future of computing and
where/whether Python fits in.

But QC is probably a but more esoteric than any of those were!



True.  As it happens I'm happy to see things go OT on Python threads. 
It makes for more interesting reading, plus people might well pick up on 
something that otherwise they'd not have learned.  However I draw a line 
firmly in the sand at quantum computing here.  Let's stick with the 
wonders of list comprehensions, recursive functions and why can't Python 
do floating point arithmetic correctly?


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trying to parse an xml file

2013-12-14 Thread Felix Dietrich
bruce  writes:

> Looking at a file -->>
> http://www.marquette.edu/mucentral/registrar/snapshot/fall13/xml/BIOL_bysubject.xml>
>
> However, when I use elementtree:
>
>   document = ElementTree.parse( '/apps/parseapp2/testxml.xml' )
>
> I get an invalid error : not well-formed (invalid token):
>
> Anyone have any python suggestions as to how to proceed to parse out
> the data!

I skimmed the xml.etree.ElementTree documentation and tried the
following:



from urllib.request import urlopen
import xml.etree.ElementTree as ET

URL = 
'http://www.marquette.edu/mucentral/registrar/snapshot/fall13/xml/BIOL_bysubject.xml'

with urlopen(URL) as page:
root = ET.fromstring(page.read())

print(next(root.iter('datetime')).text)



Output: 12/14/2013 at 3:30 am

It worked as expected.  Maybe something is wrong with your local copy of
the xml-file.

--
Felix Dietrich
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quantum computing

2013-12-14 Thread Alan Gauld

On 14/12/13 15:37, Mark Lawrence wrote:


I believe that quantum computing is way OT for the Python tutor mailing
list.


Yeah, you are probably right. Although there are precedents where we 
have discussed general topics about the future of computing and 
where/whether Python fits in.


But QC is probably a but more esoteric than any of those were!

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quantum computing

2013-12-14 Thread Mark Lawrence

On 14/12/2013 04:36, David Hutto wrote:


Recently, after having some personal problems, I've returned to looking
at the future of not only prototyping languages like python, but also
the more advanced/older(refinement of your computers resources) languages.

My main question/topic, is what is to become of languages like python
with the emergence of quantum computing?

How will python evolve to meet the needs of these newr technologies
intertwining into the marketplace?

We know the richest get it first, but how do we begin to even simulate,
and evolve to meet the needs of tomorrows world of advanced computing,
and will the instruction sets of these newer technologies effect us
considerably?

Just to kick off a topic.
--
Best Regards,
David Hutto
/*CEO:*/ _http://www.hitwebdevelopment.com_



I believe that quantum computing is way OT for the Python tutor mailing 
list.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pass argument from python to powershell

2013-12-14 Thread Alan Gauld

On 14/12/13 12:57, phanidhar wrote:


Have a code which is powershell script and i want to execute this script
using python .

example of powershell script content is :

get-aduser $args[0]

Python script :

import subprocess
import os

a =
subprocess.Popen([r'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe',
'./aduser.ps1'])
result = a.wait()

so when i run the python script it displays all the output of AD users
but not the argument alone i give.


You don't appear to be giving any arguments to the Powershell Script?
You are just calling

powershell.exe ./aduser.ps1

Where is the argument defined? Are you by any chance passing it
to the python script when you call it? If so you will need to,
like the powershell version, extract it from sys.srgv[] and then
pass it into the Popen call.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Thanks a bunch (was Re: Tutor Digest, Vol 118, Issue 64)

2013-12-14 Thread Walter Prins
Hi,

On 14 December 2013 03:31, Steven D'Aprano  wrote:
> On Fri, Dec 13, 2013 at 02:24:15PM -0500, eryksun wrote:
>> On Fri, Dec 13, 2013 at 12:47 PM, Mark Lawrence  
>> wrote:
>> > Did you really have to send an entire digest, without changing the title,
>> > just to send this one line?
>>
>> Gmail's composer top posts unless the text to quote is selected
>> beforehand.
> [...]
>
> This explains the faux pas, it doesn't excuse it. Gmail is, in my
> opinion, a *terrible* mail client. It makes what should be easy hard,
> what should be hard impossible, and encourages the dumbing down of
> communication.
>
> It is bad enough that non-technical people cannot control their email
> beyond clicking "Forward" and "Reply". But when people who have

You have the option to Forward, Reply or Reply-all, not just Forward or Reply.

> expectations of being programmers cannot even control what they send out
> as an email, well, that's just shameful. And Google has to take a large
> part of the blame for that.

Gmail matches the format of the sender.  If I reply to a text format
email, the reply is text format.  If the original is HTML mail, it
replies in HTML format.  In that sense it talks back and respects the
sender on their terms.  Also, there is a drop down (right bottom) with
which it's trivial to change from one format to the other.

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] pass argument from python to powershell

2013-12-14 Thread phanidhar
Hi All ,

I am very new to python and really like to learn it .

Have a code which is powershell script and i want to execute this script
using python .

example of powershell script content is :

get-aduser $args[0]

Python script :

import subprocess
import os

a =
subprocess.Popen([r'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe',
'./aduser.ps1'])
result = a.wait()

so when i run the python script it displays all the output of AD users but
not the argument alone i give.

If I change my powershell script to "get-aduser kunnu" and run the python
code it display the output of my account alone which doesnt happen when i
give it as an argument .

so how do we pass an argument in python while executing where the value
gets enterred in powershell script and displays the output i required...

Thanks,
Kunnu
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quantum computing (Alan Gauld)

2013-12-14 Thread Bo Morris
 attempted numerous times to
> code
> > this, but all of them have failed. Could you help me with the coding? It
> > should look something like this in the end:
> >
>
>
> > while start != True: #Infinite loop that doesn't end until "start" is
> typed
> > if start_prompt == "start":
> > start = True #Continues from the title screen
> > else:
> > #This is where I'm stuck. I can loop it so it always returns the
> > command message when
> > #"start" isn't typed, but changing the message upon having that
> > occur at least 10 times is
> > #what's giving me trouble
> >
>
> Probably smarter people than I will have better ideas, but if you make your
> else an elif and use an expression something like
> *** counter = 0 # somewhere before the while
> elif counter < 10:
> counter += 1
> print("type start")
> else
> print("just do it")
> that should (roughly) do it, unless I'm misunderstanding. Good luck!
> -- next part --
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20131213/18d76856/attachment-0001.html
> >
>
> --
>
> Message: 4
> Date: Sat, 14 Dec 2013 04:12:20 -0500
> From: Bo Morris 
> To: Amit Saha 
> Cc: "tutor@python.org" 
> Subject: Re: [Tutor] list comprehension equivalent to map(function,
> list item)
> Message-ID:
> <
> cakkcnfd9+atpkip-vfn8cwxshdfcnzhkx-b_am7jzufsk_x...@mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Thank you for your assistance. Based on your direction, I figured it out.
>
> *This... *
>
> def add(number):
>  print 1 + int(number)
>
> x = ['2', '4', '6', '8', '10', '12']
>
> [add(item) for item in x]
>
>  *Is the same as... *
>
>
> def add(number):
>  print 1 + int(number)
>
> x = ['2', '4', '6', '8', '10', '12']
>
> map(add, x)
>
> They both yield the same results. Is there a benefit to using one way over
> the other? In larger computations, does one way calculate faster or is it
> merely a preference? Again, thank you.
>
> AngryNinja
>
>
> On Fri, Dec 13, 2013 at 9:24 PM, Amit Saha  wrote:
>
> > On Sat, Dec 14, 2013 at 11:03 AM, Bo Morris  wrote:
> > > i have the following simple function that iterates over the list. It
> > passes
> > > the list item into the function and adds the numbers. What would be the
> > > equivalent way of writing the "map" portion with list comprehension? My
> > code
> > > is as follows:
> > >
> > > def add(number):
> > > print 1 + int(number)
> > >
> > >
> > >
> > > x = ['2', '4', '6', '8', '10', '12']
> > >
> > > map(add, x)
> >
> > Think of a list comprehension as:
> >
> > [ dosomething(item) for item in alist]
> >
> > And, comparing it with your map implementation, here is what you get:
> >
> > >>> [1+int(item) for item in x]
> > [3, 5, 7, 9, 11, 13]
> >
> >
> > Here, dosomething(item) corresponds to 1+int(item).
> >
> > Hope that helps.
> >
> > -Amit.
> >
> >
> > --
> > http://echorand.me
> >
> -- next part --
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20131214/1c4329cf/attachment-0001.html
> >
>
> --
>
> Message: 5
> Date: Sat, 14 Dec 2013 09:27:17 +
> From: Alan Gauld 
> To: tutor@python.org
> Subject: Re: [Tutor] weird lambda expression -- can someone help me
> understand how this works
> Message-ID: 
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 14/12/13 04:19, Steven D'Aprano wrote:
>
> > Lambda is just syntactic sugar for a function. It is exactly the same as
> > a def function, except with two limitations:
> >
> > - there is no name, or to be precise, the name of all lambda functions
> > is the same, "";
>
> Sorry, I don't think that is precise. lambda is not the name of the
> function. You can't use lambda to access the function(s) or treat it
> like any other kind of name in Python. In fact if you try to use it as a
> name you'll likely get a s

Re: [Tutor] trying to parse an xml file

2013-12-14 Thread spir

On 12/14/2013 03:29 PM, bruce wrote:

Hi.

Looking at a file -->>
http://www.marquette.edu/mucentral/registrar/snapshot/fall13/xml/BIOL_bysubject.xml

The file is generated via online/web url, and appears to be XML.

However, when I use elementtree:
   document = ElementTree.parse( '/apps/parseapp2/testxml.xml' )

I get an invalid error : not well-formed (invalid token):

I started to go through the file, to "remove" offending chars, but
decided there has to be a better approach. I also looked at the
underlying url/page to see what it's doing with the javascript to
parse the XML.


Anyone have any python suggestions as to how to proceed to parse out the data!


You do not tell us what you actually want to do. Since the input is invalid (as 
XML), obviously you cannot parse it (as XML). So what?
Also you do not reproduce the error message. How are we to guess what and why 
and how it is invalid? If this is relevant to help you, see question above. If 
not, then why do you mention this error at all?


Denis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trying to parse an xml file

2013-12-14 Thread Stefan Behnel
bruce, 14.12.2013 15:29:
> Looking at a file -->>
> http://www.marquette.edu/mucentral/registrar/snapshot/fall13/xml/BIOL_bysubject.xml

That file looks ok to me.


> The file is generated via online/web url, and appears to be XML.
> 
> However, when I use elementtree:
>   document = ElementTree.parse( '/apps/parseapp2/testxml.xml' )
> 
> I get an invalid error : not well-formed (invalid token):

That's only a part of the error message. Could you provide the complete output?

That being said, maybe you did something wrong when you downloaded the
file? Try to get it again.

Stefan


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weird lambda expression -- can someone help me understand how this works

2013-12-14 Thread spir

On 12/14/2013 12:37 PM, Alan Gauld wrote:

I must admit I'd never even thought of checking the __name__ attribute
of a lambda, I'd kind of just assumed it would be empty (or maybe 'anonymous')!


You are right, Alan, in my view.
any_lambda_func.__name__ == ""
would be a better choice. (And in that case, shortcut imprecise human language 
--which is just natural and to be expected-- could not end up saying things that 
a lambda's name is lambda [or things that can be interpreted that way when not 
fully attentive, which is also natural and to be expected].)


Denis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weird lambda expression -- can someone help me understand how this works

2013-12-14 Thread spir

On 12/14/2013 03:28 PM, spir wrote:

This 'cols' is not even defined in the piece of code you posted (which is not
all reproduced above).


Oops! did not see it as param of the enclosing func. Sorry for the error,
Denis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] trying to parse an xml file

2013-12-14 Thread bruce
Hi.

Looking at a file -->>
http://www.marquette.edu/mucentral/registrar/snapshot/fall13/xml/BIOL_bysubject.xml

The file is generated via online/web url, and appears to be XML.

However, when I use elementtree:
  document = ElementTree.parse( '/apps/parseapp2/testxml.xml' )

I get an invalid error : not well-formed (invalid token):

I started to go through the file, to "remove" offending chars, but
decided there has to be a better approach. I also looked at the
underlying url/page to see what it's doing with the javascript to
parse the XML.


Anyone have any python suggestions as to how to proceed to parse out the data!

thanks


the javascript chunk ::

var dsSnapshot = new Spry.Data.XMLDataSet("xml/BIOL_bysubject.xml",
"RECORDS/RECORD");
dsSnapshot.setColumnType("nt", "html");
dsSnapshot.setColumnType("ti", "html");
dsSnapshot.setColumnType("new", "html");
dsSnapshot.setColumnType("se", "html");
dsSnapshot.setColumnType("mt", "html");
dsSnapshot.setColumnType("ex", "html");
dsSnapshot.setColumnType("in", "html");
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weird lambda expression -- can someone help me understand how this works

2013-12-14 Thread spir

On 12/14/2013 03:14 AM, Michael Crawford wrote:

I found this piece of code on github
 mkdict = lambda row: dict((col, row[col]) for col in cols)  
#<<


Apart form the "lambda" part, explained by others, one point I would note that 
makes the whole expression weird and hard to decode is that it uses a mysterious 
'cols' coming from nowhere (technically, an unbound variable, also called 
"upvalue" in programming). This 'cols' is not even defined in the piece of code 
you posted (which is not all reproduced above).


Better would be, in my view, making it an explicit (bound) variable:
mkdict = lambda (cols, row): dict((col, row[col]) for col in cols

Which is just a funny and obscure [*] way to say:
def col_rows (cols, row):
return dict((col, row[col]) for col in cols)


I don't understand how that lambda expression works.
For starters where did row come from?


I'd rather ask: where did 'cols' come from? 'row' is the (only) input var of the 
function.



How did it know it was working on data?


The data it actually works on is 'cols' (reason why it should be explicitely 
written as input var). 'row' is just an index in cols.


Denis

[*] Obscure, partly because (1) such "wild" 'lambda' function defs do not belong 
to Python mainstream coding style and (2) its (of Python) support for such style 
of coding is itself rather unpracticle & unreadable (which probably contributes 
to (1))

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-14 Thread spir

On 12/14/2013 10:12 AM, Bo Morris wrote:

Thank you for your assistance. Based on your direction, I figured it out.

*This... *

def add(number):
  print 1 + int(number)

x = ['2', '4', '6', '8', '10', '12']

[add(item) for item in x]

  *Is the same as... *


def add(number):
  print 1 + int(number)

x = ['2', '4', '6', '8', '10', '12']

map(add, x)

They both yield the same results.


Have you tried your own code? If I add one print() for each result and run the 
code, here is the output by me:


3
5
7
9
11
13
[None, None, None, None, None, None]


Certainly these are not "the same results". And probably neither of them is the 
result you expected. I guess you go on using very imprecise, in fact wrong, 
terminology, and this drives you into thinking wrongly.


There also are worng terms in your code itself, already signaled bu other (but 
you did not correct or even take into account, apparently), and consequent 
errors of thinking:

* the "add" function does not "add"
* in fact it does not _produce_ anything (instead it is an action that performs 
an effect, namely writing something onto the terminal) ...
* ...so that using it as loop function in map simply makes no sense: map collect 
the results (products) of a function -- if that function produces results
* this is why we get [None, None...]: a function (the term is wrong, it's 
actually say an "action") that does not produce but performs an effect return 
None by convention in Python.
* "number" is not a number, but hopefully) the written expression of a number, 
whay is technically called a numeral (see wikipedia)



 Is there a benefit to using one way over
the other? In larger computations, does one way calculate faster or is it
merely a preference? Again, thank you.

AngryNinja


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Thanks a bunch (was Re: Tutor Digest, Vol 118, Issue 64)

2013-12-14 Thread spir

On 12/14/2013 04:31 AM, Steven D'Aprano wrote:

To err is human, to forgive is humane.


Nicely said.


To the Original Poster, whoever you are... I hope you'll hang around
here and [...]


If it were me, he would probably not; too bad.

Denis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 'slice', etc

2013-12-14 Thread spir

On 12/14/2013 12:24 AM, Mark Lawrence wrote:

I've just remembered that one distinct disadvantage of memoryviews is that you
can't use them anywhere if you want to do any sorting, as you can't compare 
them :(


Not a blocker in my case (matching/parsing), thankfully.

Denis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weird lambda expression -- can someone help me understand how this works

2013-12-14 Thread Alan Gauld

On 14/12/13 10:12, Steven D'Aprano wrote:

On Sat, Dec 14, 2013 at 09:27:17AM +, Alan Gauld wrote:

Sorry, I don't think that is precise. lambda is not the name of the
function.


No. But  *including the angle brackets* is the name of the
function:

py> (lambda x: x).__name__
''


Ah, OK. I'll buy that.
Although I'd probably have called it the __name__ rather than just name.

I must admit I'd never even thought of checking the __name__ attribute
of a lambda, I'd kind of just assumed it would be empty (or maybe 
'anonymous')!



--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quantum computing

2013-12-14 Thread Steven D'Aprano
On Fri, Dec 13, 2013 at 11:36:37PM -0500, David Hutto wrote:

> My main question/topic, is what is to become of languages like python with
> the emergence of quantum computing?

Almost certainly no change. I expect that quantum computing is still 
decades away from becoming common in high-end supercomputing, and 
decades more before it becomes mainstream -- if it ever does. But when 
(if) it does, it will probably require a completely different computing 
paradigm to take advantage of it. I don't expect it will be something 
that existing languages will be able to take advantage of except perhaps 
in extremely narrow areas.

It will probably be possible to simulate a Von Neumann or Harvard 
machine architecture on a Quantum Computer, in which case there may be 
Python interpreters for them (assuming anyone is still using Python when 
quantum computers become mainstream).


> How will python evolve to meet the needs of these newr technologies
> intertwining into the marketplace?

It probably won't, in the same way that Python hasn't evolved to suit 
parallel processing computers. At most, you have a few techniques for 
adding a sprinkling of parallelism into an otherwise mostly sequential 
program: threads, and multi-processing. There are a few libraries 
designed to add parallelism to Python, such as Copperhead and Parallel 
Python, but the language remains primarily sequential.

I see no reason to expect quantum computing will be any different.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weird lambda expression -- can someone help me understand how this works

2013-12-14 Thread eryksun
On Fri, Dec 13, 2013 at 11:21 PM, Steven D'Aprano  wrote:
>
>> >>> l = lambda x: x**2
>> >>> apply(l, (3,))
>> 9
>
> The built-in function apply is deprecated in Python 2 and removed in
> Python 3.

Possibly using apply() was meant to be similar to pandas
DataFrame.apply, but the latter applies a function repeatedly to the
rows or columns along an axis. It's closer to map().

http://pandas.pydata.org/pandas-docs/dev/api.html#id6

df = pandas.DataFrame(
   [[2, 3],
[4, 6]],
   columns=('c0','c1'),
   index=('r0','r1'))

>>> df
c0  c1
r0   2   3
r1   4   6

>>> r = df.apply(print)
r02
r14
Name: c0, dtype: int64
r03
r16
Name: c1, dtype: int64

>>> r = df.apply(print, axis=1)
c02
c13
Name: r0, dtype: int64
c04
c16
Name: r1, dtype: int64
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weird lambda expression -- can someone help me understand how this works

2013-12-14 Thread eryksun
On Sat, Dec 14, 2013 at 4:27 AM, Alan Gauld  wrote:
> Sorry, I don't think that is precise. lambda is not the name of the
> function. You can't use lambda to access the function(s) or treat it
> like any other kind of name in Python. In fact if you try to use it as a
> name you'll likely get a syntax error.
>
> lambda is the key word that defines the function. But its no more
> the name of the function than def is.

As Peter stated, Steven is referring to the function's __name__. In
CPython, the name is also set in the code object:

>>> f.__code__.co_name
''

In 3.3, __qualname__ gives the context for a closure:

def f():
return lambda: None

>>> g = f()
>>> g.__qualname__
'f..'

Of course you can set (but not delete) both attributes:

>>> g.__name__= 'g'
>>> g.__qualname__= 'f..g'
>>> g.__name__
'g'
>>> g.__qualname__
'f..g'
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weird lambda expression -- can someone help me understand how this works

2013-12-14 Thread Steven D'Aprano
On Sat, Dec 14, 2013 at 09:27:17AM +, Alan Gauld wrote:
> On 14/12/13 04:19, Steven D'Aprano wrote:
> 
> >Lambda is just syntactic sugar for a function. It is exactly the same as
> >a def function, except with two limitations:
> >
> >- there is no name, or to be precise, the name of all lambda functions
> >is the same, "";
> 
> Sorry, I don't think that is precise. lambda is not the name of the 
> function. 

No. But  *including the angle brackets* is the name of the 
function:

py> (lambda x: x).__name__
''




> You can't use lambda to access the function(s) or treat it
> like any other kind of name in Python. In fact if you try to use it as a 
> name you'll likely get a syntax error.

Remember that there are two meanings to "name" in Python:

1) names as in name bindings or variables:

   x = 42

   binds the value 42 to the name "x"


2) certain objects, such as classes, functions and modules, have 
   their very own name, which is not necessarily the same as the
   name the object is bound to:

py> import math as flibbert
py> flibbert.__name__
'math'


A function's personal name and the name it is bound to will initially be 
the same when using def, but not with lambda. We normally say that 
lambda functions are "anonymous", but they actually do have a name, it 
just happens to be the same name as every other function generated with 
lambda.



-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weird lambda expression -- can someone help me understand how this works

2013-12-14 Thread Peter Otten
Alan Gauld wrote:

> On 14/12/13 04:19, Steven D'Aprano wrote:
> 
>> Lambda is just syntactic sugar for a function. It is exactly the same as
>> a def function, except with two limitations:
>>
>> - there is no name, or to be precise, the name of all lambda functions
>> is the same, "";
> 
> Sorry, I don't think that is precise. lambda is not the name of the
> function. You can't use lambda to access the function(s) or treat it
> like any other kind of name in Python. In fact if you try to use it as a
> name you'll likely get a syntax error.
> 
> lambda is the key word that defines the function. But its no more
> the name of the function than def is.

There is the (variable) name the function object is bound to and the 
function's __name__ attribute. In the example below "" is the 
__name__ while the function object is bound to the name "f":

>>> f = lambda x: math.sqrt(x) + f(x-1)
>>> f.__name__
''
>>> f(5)
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1, in 
  File "", line 1, in 
  File "", line 1, in 
  File "", line 1, in 
  File "", line 1, in 
  File "", line 1, in 
  File "", line 1, in 
ValueError: math domain error


When the normal way to define a function object is used both __name__ 
attribute and variable name are identical (at least initially):

>>> def f(x): return math.sqrt(x) + f(x-1)
... 
>>> f.__name__
'f'
>>> f(2)
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1, in f
  File "", line 1, in f
  File "", line 1, in f
  File "", line 1, in f
ValueError: math domain error


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-14 Thread Peter Otten
Bo Morris wrote:

> Thank you for your assistance. Based on your direction, I figured it out.
> 
> *This... *
> 
> def add(number):
>  print 1 + int(number)
> 
> x = ['2', '4', '6', '8', '10', '12']
> 
> [add(item) for item in x]
> 
>  *Is the same as... *
> 
> 
> def add(number):
>  print 1 + int(number)
> 
> x = ['2', '4', '6', '8', '10', '12']
> 
> map(add, x)
> 
> They both yield the same results. Is there a benefit to using one way over
> the other? In larger computations, does one way calculate faster or is it
> merely a preference? Again, thank you.

For built-in functions map(f, items) is a bit faster. List-comps are more 
flexible; you can inline the function

>>> [int(s) + 1 for s in x]
[3, 5, 7, 9, 11, 13]

or add a filter:

>>> [int(s) + 1 for s in x if set("12") & set(s)]
[3, 11, 13]


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quantum computing

2013-12-14 Thread Alan Gauld

On 14/12/13 04:36, David Hutto wrote:


My main question/topic, is what is to become of languages like python
with the emergence of quantum computing?


Nothing, I suspect, since by the time quantum computing hits the 
mainstream we will all have progressed to other languages anyhow.


These kinds of breakthrough take decades to reach maturity. QC has
been around conceptually for 30 years and there is still no
commercial QC hardware available (so far as I know). When/if
it does appear it will be in the mainframe/supercomputing arena
first and then it may percolate down to mid size and personal
computers.

But I'm sceptical. QC may have a role in the medium term but it
will be in niche areas I suspect.

I remember being shown a computer in a petri dish while at Uni' and 
being told that biological computing was the future. It has never 
happened. Similarly the transputer (real commerial hardware) was 
heralded as the dawn of massive parallel computing in the late '80s.

Instead we got multi-core CPUs and blades and Google...


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] weird lambda expression -- can someone help me understand how this works

2013-12-14 Thread Alan Gauld

On 14/12/13 04:19, Steven D'Aprano wrote:


Lambda is just syntactic sugar for a function. It is exactly the same as
a def function, except with two limitations:

- there is no name, or to be precise, the name of all lambda functions
is the same, "";


Sorry, I don't think that is precise. lambda is not the name of the 
function. You can't use lambda to access the function(s) or treat it
like any other kind of name in Python. In fact if you try to use it as a 
name you'll likely get a syntax error.


lambda is the key word that defines the function. But its no more
the name of the function than def is.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-14 Thread Bo Morris
Thank you for your assistance. Based on your direction, I figured it out.

*This... *

def add(number):
 print 1 + int(number)

x = ['2', '4', '6', '8', '10', '12']

[add(item) for item in x]

 *Is the same as... *


def add(number):
 print 1 + int(number)

x = ['2', '4', '6', '8', '10', '12']

map(add, x)

They both yield the same results. Is there a benefit to using one way over
the other? In larger computations, does one way calculate faster or is it
merely a preference? Again, thank you.

AngryNinja


On Fri, Dec 13, 2013 at 9:24 PM, Amit Saha  wrote:

> On Sat, Dec 14, 2013 at 11:03 AM, Bo Morris  wrote:
> > i have the following simple function that iterates over the list. It
> passes
> > the list item into the function and adds the numbers. What would be the
> > equivalent way of writing the "map" portion with list comprehension? My
> code
> > is as follows:
> >
> > def add(number):
> > print 1 + int(number)
> >
> >
> >
> > x = ['2', '4', '6', '8', '10', '12']
> >
> > map(add, x)
>
> Think of a list comprehension as:
>
> [ dosomething(item) for item in alist]
>
> And, comparing it with your map implementation, here is what you get:
>
> >>> [1+int(item) for item in x]
> [3, 5, 7, 9, 11, 13]
>
>
> Here, dosomething(item) corresponds to 1+int(item).
>
> Hope that helps.
>
> -Amit.
>
>
> --
> http://echorand.me
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 118, Issue 62

2013-12-14 Thread Keith Winston
>
> Message: 6
> Date: Thu, 12 Dec 2013 23:10:31 -0500
> From: Sky blaze 
> To: tutor@python.org
> Subject: [Tutor] Coding for a Secret Message in a Game
>


> it'd be amusing to have the message change after the player types something
> other than "start" at least 10 times. I've attempted numerous times to code
> this, but all of them have failed. Could you help me with the coding? It
> should look something like this in the end:
>


> while start != True: #Infinite loop that doesn't end until "start" is typed
> if start_prompt == "start":
> start = True #Continues from the title screen
> else:
> #This is where I'm stuck. I can loop it so it always returns the
> command message when
> #"start" isn't typed, but changing the message upon having that
> occur at least 10 times is
> #what's giving me trouble
>

Probably smarter people than I will have better ideas, but if you make your
else an elif and use an expression something like
*** counter = 0 # somewhere before the while
elif counter < 10:
counter += 1
print("type start")
else
print("just do it")
that should (roughly) do it, unless I'm misunderstanding. Good luck!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Quantum computing

2013-12-14 Thread David Hutto
Recently, after having some personal problems, I've returned to looking at
the future of not only prototyping languages like python, but also the more
advanced/older(refinement of your computers resources) languages.


My main question/topic, is what is to become of languages like python with
the emergence of quantum computing?

How will python evolve to meet the needs of these newr technologies
intertwining into the marketplace?

We know the richest get it first, but how do we begin to even simulate, and
evolve to meet the needs of tomorrows world of advanced computing, and will
the instruction sets of these newer technologies effect us considerably?

Just to kick off a topic.
-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com *
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor