[Tutor] enhanced subtration in an exponent

2015-04-21 Thread Jim Mooney
Why does the compiler choke on this? It seems to me that the enhanced subtraction resolves to a legitimate integer in the exponent, but I get a syntax error: B = '11011101' sum = 0 start = len(B) for char in B: sum += int(char) * 2**(start -= 1) ## syntax error print(sum) -- Jim ___

[Tutor] calling a method directly

2015-04-21 Thread Jim Mooney
Is there any difference between these two since they give the same result, and when is the second preferred? >>> x = 'ABE' >>> x.lower() 'abe' >>> str.lower(x) 'abe' -- Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription o

[Tutor] what's wrong with this ?

2015-04-21 Thread lei yang
>>>start_time = "2014-7-1" >>> revlines = commands.getoutput("git log --pretty=format:'%ad:%an' --date=short --since='%s' --no-merges" %start_time).strip().split('\n') Traceback (most recent call last): File "", line 1, in ValueError: unsupported format character 'a' (0x61) at index 26 >>> if

Re: [Tutor] enhanced subtration in an exponent

2015-04-21 Thread Danny Yoo
On Apr 21, 2015 12:24 AM, "Jim Mooney" wrote: > > Why does the compiler choke on this? It seems to me that the enhanced > subtraction resolves to a legitimate integer in the exponent, but I get a > syntax error: > > B = '11011101' > sum = 0 > start = len(B) > for char in B: > sum += int(char)

Re: [Tutor] what's wrong with this ?

2015-04-21 Thread Danny Yoo
On Apr 21, 2015 12:27 AM, "lei yang" wrote: > > >>>start_time = "2014-7-1" > >>> revlines = commands.getoutput("git log --pretty=format:'%ad:%an' > --date=short --since='%s' --no-merges" %start_time).strip().split('\n') > Traceback (most recent call last): > File "", line 1, in > ValueError: un

Re: [Tutor] calling a method directly

2015-04-21 Thread Alan Gauld
On 21/04/15 05:19, Jim Mooney wrote: Is there any difference between these two since they give the same result, and when is the second preferred? x = 'ABE' x.lower() 'abe' str.lower(x) 'abe' They are essentially the same method being accessed in two different ways. The first via the insta

Re: [Tutor] what's wrong with this ?

2015-04-21 Thread Alan Gauld
On 21/04/15 06:22, lei yang wrote: start_time = "2014-7-1" revlines = commands.getoutput("git log --pretty=format:'%ad:%an' --date=short --since='%s' --no-merges" %start_time).strip().split('\n') Traceback (most recent call last): File "", line 1, in ValueError: unsupported format character

Re: [Tutor] enhanced subtration in an exponent

2015-04-21 Thread Alan Gauld
On 21/04/15 01:44, Jim Mooney wrote: Why does the compiler choke on this? It seems to me that the enhanced subtraction resolves to a legitimate integer That's your mistake. Assignment is a statement not an expression. It does not return anything. In fact its just illegal to try: >>> print x=

Re: [Tutor] calling a method directly

2015-04-21 Thread Peter Otten
Jim Mooney wrote: > Is there any difference between these two since they give the same result, > and when is the second preferred? > x = 'ABE' x.lower() > 'abe' str.lower(x) > 'abe' You may call str.lower() explicitly for subclasses of str. If the subclass overrides the lower() me

[Tutor] Pun panic, was Re: calling a method directly

2015-04-21 Thread Peter Otten
Peter Otten wrote: class Cow: > ... def lower(self): return "moo" If you can't make sense of that: at the time of writing I thought that "lowering" was a synonym for "mooing". After a look into the dictionary it turns out to be "lowing", not "lowering". Sorry!

Re: [Tutor] Pun panic, was Re: calling a method directly

2015-04-21 Thread Alan Gauld
On 21/04/15 09:45, Peter Otten wrote: Peter Otten wrote: class Cow: ... def lower(self): return "moo" If you can't make sense of that: at the time of writing I thought that "lowering" was a synonym for "mooing". After a look into the dictionary it turns out to be "lowing", not "lowering"

Re: [Tutor] introspection

2015-04-21 Thread Dave Angel
On 04/21/2015 01:21 AM, Danny Yoo wrote: What's supposed to happen in this situation? ## class Person(object): def __init__(self): pass j = Person() john = j jack = j ## What single name should we get back fr

Re: [Tutor] enhanced subtration in an exponent

2015-04-21 Thread Dave Angel
On 04/20/2015 08:44 PM, Jim Mooney wrote: Why does the compiler choke on this? It seems to me that the enhanced subtraction resolves to a legitimate integer in the exponent, but I get a syntax error: B = '11011101' sum = 0 start = len(B) for char in B: sum += int(char) * 2**(start -= 1) ##

Re: [Tutor] Is it possible to "backport" the datetime module of Python 3.3 to Python 3.2?

2015-04-21 Thread Mark Lawrence
On 20/04/2015 21:05, Albert-Jan Roskam wrote: Hi, My Raspberry Pi 2 comes with Python 3.2 (and 2.7). I run some code that uses the datetime module but I get an error: "AttributeError: 'datetime.datetime' object has no attribute 'timestamp'". On https://docs.python.org/3/whatsnew/3.3.html I se

Re: [Tutor] bin to dec conversion puzzlement

2015-04-21 Thread Mark Lawrence
On 20/04/2015 21:47, Ben Finney wrote: Jim Mooney writes: I can't seem to get my head around this 'simple' book example of binary-to-decimal conversion, which goes from left to right: B = '11011101' I = 0 while B: I = I * 2 + int(B[0]) B = B[1:] print(I) 221 That is, IMO, a need

Re: [Tutor] Is it possible to "backport" the datetime module of Python 3.3 to Python 3.2?

2015-04-21 Thread Albert-Jan Roskam
- Original Message - > From: Mark Lawrence > To: tutor@python.org > Cc: > Sent: Tuesday, April 21, 2015 1:31 PM > Subject: Re: [Tutor] Is it possible to "backport" the datetime module of > Python 3.3 to Python 3.2? > > On 20/04/2015 21:05, Albert-Jan Roskam wrote: > >> Hi, >> >>

Re: [Tutor] Is it possible to "backport" the datetime module of Python 3.3 to Python 3.2?

2015-04-21 Thread Steven D'Aprano
On Tue, Apr 21, 2015 at 12:31:53PM +0100, Mark Lawrence wrote: > Python is very strong in guaranteeing backward compatibility, so why not > copy the 3.3 pure Python code to your 3.2 setup and see what happens? Normally backwards compatibility refers to the other way: 3.3 will run 3.2 code. To h

Re: [Tutor] Pun panic, was Re: calling a method directly

2015-04-21 Thread Martin A. Brown
Good morning underscore underscore Peter underscore underscore, class Cow: ... def lower(self): return "moo" If you can't make sense of that: at the time of writing I thought that "lowering" was a synonym for "mooing". After a look into the dictionary it turns out to be "lowing", not

Re: [Tutor] Pun panic, was Re: calling a method directly

2015-04-21 Thread Marc Tompkins
On Tue, Apr 21, 2015 at 7:09 AM, Martin A. Brown wrote: > And, I dairy not chase this pun any further > No - keep milking it. It gets butter all the time. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https

Re: [Tutor] introspection

2015-04-21 Thread Alex Kleider
On 2015-04-20 22:21, Danny Yoo wrote: What's supposed to happen in this situation? ## class Person(object): def __init__(self): pass j = Person() john = j jack = j ## What single name should we get back from t

Re: [Tutor] introspection

2015-04-21 Thread Danny Yoo
> But I see what I think you and others have been trying to explain to me: > that the expression some_object.__name__, if it existed, would indeed be > schizophrenic since it would be an attribute of the object, not the name(s) > to which it is bound. The hypothetical feature might also, if desi

[Tutor] handling exception raising in atexit registered function

2015-04-21 Thread Opher Lubzens
Hi, I am developing an automated testing script in python which will, among other things, send an email when it is done. For this I would like to send an email when an exception is raised as well - since it already has a cleanup function registered with atexit, this is the logical place to do it. H

[Tutor] ?!

2015-04-21 Thread Ryan Scholes
Hi, Didn't really understand the instructions on the website but is this the right email address for help? Thanks, cory :) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription op

Re: [Tutor] ?!

2015-04-21 Thread memilanuk
On 04/21/2015 04:17 AM, Ryan Scholes wrote: Hi, Didn't really understand the instructions on the website but is this the right email address for help? It can be... Some very smart, experienced and helpful folks here - some are even all three! ;) Generally speaking... they aren't going

Re: [Tutor] ?!

2015-04-21 Thread Alan Gauld
On 21/04/15 12:17, Ryan Scholes wrote: Didn't really understand the instructions on the website but is this the right email address for help? If its help about: a) learning to program b) learning the Python programming language c) learning the Python standard library Then yes, this is the ri

Re: [Tutor] Pun panic

2015-04-21 Thread Ben Finney
"Martin A. Brown" writes: > Good morning underscore underscore Peter underscore underscore, The Pythonic way to pronounce that would be “dunder Pete dunder” https://wiki.python.org/moin/DunderAlias>. -- \ “Geeks like to think that they can ignore politics. You can | `\leave

Re: [Tutor] introspection

2015-04-21 Thread Ben Finney
Alex Kleider writes: > I was hoping that it would be possible to create a function > that would do the following: > > def my_name(some_object): > return some_object.__name__ That hope is understandable. It is also easy to be confused about why such a feature doesn't exist; after all, it works

Re: [Tutor] introspection

2015-04-21 Thread Cameron Simpson
On 21Apr2015 09:59, Alex Kleider wrote: On 2015-04-20 22:21, Danny Yoo wrote: What's supposed to happen in this situation? ## class Person(object): def __init__(self): pass j = Person() john = j jack = j ## Wha

Re: [Tutor] calling a method directly

2015-04-21 Thread Cameron Simpson
On 21Apr2015 09:03, alan.ga...@btinternet.com wrote: On 21/04/15 05:19, Jim Mooney wrote: Is there any difference between these two since they give the same result, and when is the second preferred? x = 'ABE' x.lower() 'abe' str.lower(x) 'abe' They are essentially the same method being a

Re: [Tutor] Is it possible to "backport" the datetime module of Python 3.3 to Python 3.2?

2015-04-21 Thread Cameron Simpson
On 21Apr2015 22:50, Steven D'Aprano wrote: On Tue, Apr 21, 2015 at 12:31:53PM +0100, Mark Lawrence wrote: Python is very strong in guaranteeing backward compatibility, so why not copy the 3.3 pure Python code to your 3.2 setup and see what happens? Normally backwards compatibility refers to

Re: [Tutor] introspection

2015-04-21 Thread Alex Kleider
On 2015-04-21 16:48, Cameron Simpson wrote: But it would not be schizophrenic to write a function that returned a name arbitrarily, by inspecting locals(). It depends whether you only need a name, or if you need "the" name. In my use case there'd probably be only one name for the given object

Re: [Tutor] introspection

2015-04-21 Thread Alex Kleider
On 2015-04-21 16:38, Ben Finney wrote: That hope is understandable. Your "understanding" is appreciated. It is also easy to be confused So true, but with the help of "Python Tutors" things are being rectified! about why such a feature doesn't exist; So why not arbitrary objects?

Re: [Tutor] Pun panic

2015-04-21 Thread Peter Otten
Ben Finney wrote: > "Martin A. Brown" writes: > >> Good morning underscore underscore Peter underscore underscore, > > The Pythonic way to pronounce that would be “dunder Pete dunder” > https://wiki.python.org/moin/DunderAlias>. > Hm, should I campaign for a peter() builtin?