Re: [Tutor] Some shameless self promotion

2014-11-04 Thread memilanuk

On 11/03/2014 11:41 PM, Alan Gauld wrote:

On 04/11/14 00:55, memilanuk wrote:

On 11/02/2014 05:22 PM, Alan Gauld wrote:

For anyone who might be interested

http://www.amazon.com/Python-Projects-Laura-Cassell/dp/111890866X

A book aimed at those who have just finished their first python tutorial
and are wondering what to do next...



Do you know if there are any plans for an electronic version i.e. pdf or
kindle?


I assume so but I'm only the author and that's a decision
for the publishers! :-)




Well, maybe as one of the authors you can poke 'em a bit.  So far the 
only version listed on Amazon or Wrox's site is paperback.


--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com

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


Re: [Tutor] eval use (directly by interpreter vs with in a script)

2014-11-04 Thread Albert-Jan Roskam

- Original Message -
> From: Steven D'Aprano 
> To: tutor@python.org
> Cc: 
> Sent: Tuesday, November 4, 2014 4:08 AM
> Subject: Re: [Tutor] eval use (directly by interpreter vs with in a script)
> 
> On Mon, Nov 03, 2014 at 09:33:18AM -0800, Albert-Jan Roskam wrote:
> 
> 
>>  >Real question is what you're trying to do.  eval() and exec() are 
> to be 
>>  >avoided if possible, so the solutions are not necessarily the easiest.
>> 
>>  I sometimes do something like
>>  ifelse = "'teddybear' if bmi > 30 else 
> 'skinny'"
>>  weightcats = [eval(ifelse) for bmi in bmis]
>> 
>>  Would this also be a *bad* use of eval? It can be avoided, but this is so 
> concise.
> 
> Two lines, 92 characters. This is more concise:
> 
> weightcats = ['teddybear' if bmi > 30 else 'skinny' for bmi 
> in bmis]

Aaah *slap against forehead*! I did not know this is legal. MUCH nicer indeed


> One line, 68 characters. And it will be faster too. On average, you 
> should expect that:
> 
> eval(expression)
> 
> is about ten times slower than expression would be on its own.
> 
> In my opinion, a *minimum* requirement for eval() is that you don't know 
> what the code being evaluated will be when you're writing it. If you can 
> write a fixed string inside the eval, like your example above, or a 
> simpler case here:
> 
> results = [eval("x + 2") for x in values]
> 
> then eval is unneccessary and should be avoided, just write the 
> expression itself:
> 
> results = [x + 2 for x in values]
> 
> 
> You *may* have a good reason for using eval if you don't know what the 
> expression will be until runtime:
> 
> results = [eval("x %c 2" % random.choice("+-/*")) for x in 
> values]
> 
> 
> but even then there is often a better way to get the same result, e.g. 
> using getattr(myvariable, name) instead of eval("myvariable.%s" % 
> name). 
> In the case of the random operator, I'd write something like this:
> 
> OPERATORS = {'+': operator.add, '-': operator.sub,
>  '/': operator.truediv, '*': operator.mul}
> results = [OPERATORS[random.choice("+-/*")](x, 2) for x in values]
> 
> which in this case is a little longer but safer and probably faster. 
> It's also more easily extensible to a wider range of operators and even 
> functions.
 
Hmm, I get 1900 occurrences of eval() (and 700 of frozenset, just curious) in 
Python. That's MUCH, I must be something wrong, but I am rushing now!

import os
import sys
import collections
os.chdir(os.path.dirname(sys.executable))
cmds = ["eval(", "frozenset"]
counter = collections.Counter()
for root, dirs, files in os.walk(".", topdown=False):
for name in files:
if name.endswith(".py"):
contents = open(os.path.join(root, name))
for line in contents:
if not line.startswith("#"):
for cmd in cmds:
if cmd in line:
counter[cmd] += 1
print counter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Remove artca...@google.com from mailing list, PLEASE

2014-11-04 Thread Art Caton

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


Re: [Tutor] Remove artca...@google.com from mailing list, PLEASE

2014-11-04 Thread Danny Yoo
Hi Art,

You may imagine a very busy administrator sending messages to each user
individually, but that's now how computer-based mailing lists work these
days.

If you wish to unsubscribe, please visit the following url:

https://mail.python.org/mailman/listinfo

There's a form there that you can use to unsubscribe yourself.

Think of it as "self-serve".  Almost every community-based mailing list
will have a URL that you can use to unsubscribe yourself.  Please learn to
use this.  Technical mailing lists, on the whole, all work like this.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Remove artca...@google.com from mailing list, PLEASE

2014-11-04 Thread Danny Yoo
s/that's now how/that's not how

On Tue Nov 04 2014 at 10:27:57 AM Danny Yoo  wrote:

> Hi Art,
>
> You may imagine a very busy administrator sending messages to each user
> individually, but that's now how computer-based mailing lists work these
> days.
>
> If you wish to unsubscribe, please visit the following url:
>
> https://mail.python.org/mailman/listinfo
>
> There's a form there that you can use to unsubscribe yourself.
>
> Think of it as "self-serve".  Almost every community-based mailing list
> will have a URL that you can use to unsubscribe yourself.  Please learn to
> use this.  Technical mailing lists, on the whole, all work like this.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Remove artca...@google.com from mailing list, PLEASE

2014-11-04 Thread Chris Warrick
Do it yourself at https://mail.python.org/mailman/listinfo/tutor .

Besides, your email is @gmail.com, not @google.com.
-- 
Chris Warrick 
PGP: 5EAAEA16
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Remove artca...@google.com from mailing list, PLEASE

2014-11-04 Thread Huy T
When you unsubscribe be sure to put the email address you sub'd with.

@google.com and @gmail.com both work and resolve to the same mailbox, just
fyi. Something wasn't terribly efficient of notifying people of.

So if you have a @gmail.com, you also have @google.com

On Tue, Nov 4, 2014 at 1:37 PM, Chris Warrick  wrote:

> Do it yourself at https://mail.python.org/mailman/listinfo/tutor .
>
> Besides, your email is @gmail.com, not @google.com.
> --
> Chris Warrick 
> PGP: 5EAAEA16
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] eval use (directly by interpreter vs with in a script)

2014-11-04 Thread Alan Gauld

On 04/11/14 16:11, Albert-Jan Roskam wrote:


Hmm, I get 1900 occurrences of eval()


Try printing the filenames too. A lot of those will be
in Tkinter/Tix which uses tcl.eval() to execute the
underlying Tcl/Tk widget code. Also I suspect a lot of the 
'introspection' type modules that are not intended for

normal project use will use eval etc.


--
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] eval use (directly by interpreter vs with in a script)

2014-11-04 Thread Steven D'Aprano
On Tue, Nov 04, 2014 at 04:11:13PM +, Albert-Jan Roskam wrote:

> Hmm, I get 1900 occurrences of eval() (and 700 of frozenset, just 
> curious) in Python. That's MUCH, I must be something wrong, but I am 
> rushing now!

For what it's worth, in Python 2.7, and *only* looking at the top level 
of the standard library, I get 23 occurances of "eval(". 11 of those are 
false positives, that is, comments, docstrings, or functions named 
"something_eval(".


[steve@ando ~]$ python2.7 -c "import timeit; print(timeit.__file__)"
/usr/local/lib/python2.7/timeit.pyc
[steve@ando ~]$ grep "eval(" /usr/local/lib/python2.7/*.py | wc -l
23
[steve@ando ~]$ grep "eval(" /usr/local/lib/python2.7/*.py
/usr/local/lib/python2.7/ast.py:def literal_eval(node_or_string):
/usr/local/lib/python2.7/bdb.py:def runeval(self, expr, globals=None, 
locals=None):
/usr/local/lib/python2.7/bdb.py:return eval(expr, globals, locals)
/usr/local/lib/python2.7/bdb.py:val = eval(b.cond, 
frame.f_globals,
/usr/local/lib/python2.7/decimal.py:# Invariant:  eval(repr(d)) == d
/usr/local/lib/python2.7/dumbdbm.py:key, pos_and_siz_pair = 
eval(line)
/usr/local/lib/python2.7/gettext.py:return eval('lambda n: int(%s)' % 
plural)
/usr/local/lib/python2.7/mhlib.py:def do(s): print s; print eval(s)
/usr/local/lib/python2.7/pdb.py:func = eval(arg,
/usr/local/lib/python2.7/pdb.py:return eval(arg, 
self.curframe.f_globals,
/usr/local/lib/python2.7/pdb.py:x = eval(arg, {}, {})
/usr/local/lib/python2.7/pdb.py:value = eval(arg, 
self.curframe.f_globals,
/usr/local/lib/python2.7/pdb.py:def runeval(expression, globals=None, 
locals=None):
/usr/local/lib/python2.7/pdb.py:return Pdb().runeval(expression, globals, 
locals)
/usr/local/lib/python2.7/pprint.py:"""Determine if saferepr(object) is 
readable by eval()."""
/usr/local/lib/python2.7/rexec.py:The class RExec exports methods r_exec(), 
r_eval(), r_execfile(), and
/usr/local/lib/python2.7/rexec.py:exec, eval(), execfile() and import, but 
executing the code in an
/usr/local/lib/python2.7/rexec.py:def r_eval(self, code):
/usr/local/lib/python2.7/rexec.py:return eval(code, m.__dict__)
/usr/local/lib/python2.7/rexec.py:def s_eval(self, *args):
/usr/local/lib/python2.7/rexec.py:Similar to the r_eval() method, but 
the code will be granted access
/usr/local/lib/python2.7/rlcompleter.py:thisobject = eval(expr, 
self.namespace)
/usr/local/lib/python2.7/warnings.py:cat = eval(category)


You'll note that most of the actual calls to eval are in the Python 
debugger, pdb, which makes sense.

Looking one directory down, I get a further 260 such instances, 224 of 
which are in the "test" subdirectory:

[steve@ando ~]$ grep "eval(" /usr/local/lib/python2.7/*/*.py | wc -l
260
[steve@ando ~]$ grep "eval(" /usr/local/lib/python2.7/test/*.py | wc -l
224

Digging deeper still, I find that IDLE also includes many calls to 
eval(), as does the turtle graphics module (which is old and hasn't had 
much love for a long time). There is also a large test suite with many 
calls to eval() in 2to3, as well as many hundreds of false positives, 
e.g. sympy defines dozens of classes with an eval method.

Since these results depend on what third-party libraries have been 
installed, your results may vary.



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


Re: [Tutor] Remove artca...@google.com from mailing list, PLEASE

2014-11-04 Thread Huy T
Yeah this is correct.

When I went to test google autocorrected google to googlemail.com

Typing fast and gmail built in autosuggest = :(

On Tue, Nov 4, 2014 at 2:29 PM, Danny Yoo  wrote:

>
>> @google.com and @gmail.com both work and resolve to the same mailbox,
>> just fyi. Something wasn't terribly efficient of notifying people of.
>>
>> So if you have a @gmail.com, you also have @google.com
>>
>>
> [Apologies for the off-toplic nature of my post.  I'll stop after this.]
>
> As a correction: no, this assertion is technically wrong.  Addresses that
> end with "@google.com" are _not_ interchangable with addresses that end
> with "@gmail.com".
>
> Please do not mix up the two.  You'll make employees at a certain company
> much happier if you don't accidently send messages to them.
>
> You may be confusing with the interchangability of "gmail.com" and "
> googlemail.com", but:
>
> ###
> >>> "google.com" == "googlemail.com"
> False
> ###
>
> See:  https://support.google.com/mail/answer/10313?hl=en
>
>
> I'd better get back to work.  :p
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Remove artca...@google.com from mailing list, PLEASE

2014-11-04 Thread Danny Yoo
>
>
> @google.com and @gmail.com both work and resolve to the same mailbox,
> just fyi. Something wasn't terribly efficient of notifying people of.
>
> So if you have a @gmail.com, you also have @google.com
>
>
[Apologies for the off-toplic nature of my post.  I'll stop after this.]

As a correction: no, this assertion is technically wrong.  Addresses that
end with "@google.com" are _not_ interchangable with addresses that end
with "@gmail.com".

Please do not mix up the two.  You'll make employees at a certain company
much happier if you don't accidently send messages to them.

You may be confusing with the interchangability of "gmail.com" and "
googlemail.com", but:

###
>>> "google.com" == "googlemail.com"
False
###

See:  https://support.google.com/mail/answer/10313?hl=en


I'd better get back to work.  :p
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor