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

2013-12-20 Thread Keith Winston
On Thu, Dec 19, 2013 at 5:58 PM, tutor-requ...@python.org wrote:

  So... is there any way to go back up to the previous line and correct the
  syntax?  As it is now we are starting the entire file over.  It's really
  cumbersome.  Is it supposed to be this way?


I notice Python for Kids uses Python 3.2, and (p. 9) IDLE, the Integrated
Development Environment that comes with Python. But it doesn't sound like
YOU'RE using Idle: Look for an icon/button that says Idle, instead of
Python. Try to make sure that it says something about Python 3.x, since 2.x
is different in a few respects (in case you installed the wrong one).

If you use Idle, you'll need to open a new window (from within IDLE) in
which to create/edit files, and it will prompt you to save them before you
can run them (which will automatically happen in the other window): all of
this can be done from the menu bar of the new window. It will be sort of
obvious once you start.

It appears to be an interesting book, one of the reviewers is 15 y.o... but
it's not light, I will be surprised if a 5 y.o. gets through it. They
suggest 10 yo and up. But kids can often rise to challenges, good luck!


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


[Tutor] menu-libre broken?

2013-12-20 Thread Keith Winston
I did this sequence of commands:

sudo add-apt-repository ppa:menulibre-dev/devel
sudo apt-get update
sudo apt-get install menulibre

But at the end of the update I got:

W: Failed to fetch
http://ppa.launchpad.net/menulibre-dev/devel/ubuntu/dists/saucy/main/source/Sources
404  Not Found

W: Failed to fetch
http://ppa.launchpad.net/menulibre-dev/devel/ubuntu/dists/saucy/main/binary-amd64/Packages
404  Not Found

W: Failed to fetch
http://ppa.launchpad.net/menulibre-dev/devel/ubuntu/dists/saucy/main/binary-i386/Packages
404  Not Found

which led understandably, following the third command, to:

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package menulibre

Sooo: I think I understand that something went wrong (the package was
successfully added to my repository, I think, but then not successfully
updated, and therefore couldn't be installed, or something like that). But
I'm pretty clueless about what to do about it.

Which is to say, help!

Meanwhile however, I did find that some programs I'd installed (Python,
Idle) were added to my menu when I rebooted my machine, after I'd noted
they were not automatically added when I installed them with the software
manager. I unreasonably blamed it all on Whisker Menu...
-- 
Keith
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] class variables

2013-12-20 Thread Keith Winston
I am a little confused about class variables: I feel like I've repeatedly
seen statements like this:

There is only one copy of the class variable and when any one object makes a
change to a class variable, that change will be seen by all the other
instances.
Object variables are owned by each individual object/instance of the class.
In
this case, each object has its own copy

But when I test, I see some interesting things: first (and this is
consistent with above) the class variables are created when the class is
defined, and can be used even without any instances of the class being
created.

Second, initially confusing but maybe I understand... there are pointers to
the class variables associated with every instance of the object, but if I
assign THOSE variables new values, it crerates new, local/instance
variables.

So:
Class.pi == 3.14  # defined/set in the class def
instance.pi == 3.14  # initially
instance.pi = 4  # oops, changed it
Class.pi == 3.14  # still
Class.pi = rhubarb  # oops, there I go again
instance.pi == 4  # still

Sorry if I'm beating this to a pulp, I think I've got it... I'm just
confused because the way they are described feels a little confusing, but
maybe that's because I'm not taking into account how easy it is to create
local variables...
-- 
Keith
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class variables

2013-12-20 Thread Dominik George
Hi,

 I am a little confused about class variables: I feel like I've repeatedly
 seen statements like this:

please take a look at the archives - this topic has been discussed on
this list recently.

-nik

-- 
* mirabilos is handling my post-1990 smartphone *
mirabilos Aaah, it vibrates! Wherefore art thou, demonic device??

PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296


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


Re: [Tutor] class variables

2013-12-20 Thread Alan Gauld

On 20/12/13 07:04, Keith Winston wrote:


Class.pi == 3.14  # defined/set in the class def
instance.pi == 3.14  # initially
instance.pi = 4  # oops, changed it
Class.pi == 3.14  # still
Class.pi = rhubarb  # oops, there I go again
instance.pi == 4  # still

Sorry if I'm beating this to a pulp, I think I've got it...


You do have it.

Think of it like an extension to any other form of name look up.
The built in functions are available to you anywhere but you can 
override them in your code. Python  looks first to see if you have 
defined your own version, if you don't it looks in the built in

names.

Similarly if you have a name defined within the instance it will use 
that if not it will look in the class.


My personal rule for this is if you want the class variable always 
access it via the class rather than the instance.


But that falls down when processing a polymorphic collection where some 
instances may have instance variables and others only class variables.

So a loop like this

for obj in myMixedObjectList:
obj.someName = 42

Those instances that didn't have an instance var called someName
before, have one now. That may not be a good thing, especially
if the objects methods use self.someName to access the class
variable.

But these cases are relatively rare in my experience. Lists of
objects are usually more closely related than in the example above.

--
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] menu-libre broken?

2013-12-20 Thread Alan Gauld

On 20/12/13 03:46, Keith Winston wrote:

I did this sequence of commands:

sudo add-apt-repository ppa:menulibre-dev/devel
sudo apt-get update
sudo apt-get install menulibre



This looks more like an Ubuntu issue than a Python one?
Did you mean to send it to the tutor list?

--
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] menu-libre broken? :p:

2013-12-20 Thread Paradox


On 12/19/2013 10:46 PM, Keith Winston wrote:

I did this sequence of commands:

sudo add-apt-repository ppa:menulibre-dev/devel
sudo apt-get update
sudo apt-get install menulibre

But at the end of the update I got:

W: Failed to fetch
http://ppa.launchpad.net/menulibre-dev/devel/ubuntu/dists/saucy/main/source/Sources
404  Not Found

W: Failed to fetch
http://ppa.launchpad.net/menulibre-dev/devel/ubuntu/dists/saucy/main/binary-amd64/Packages
404  Not Found

W: Failed to fetch
http://ppa.launchpad.net/menulibre-dev/devel/ubuntu/dists/saucy/main/binary-i386/Packages
404  Not Found

Alan is correct, this is an Ubuntu problem rather than a Python problem. 
 You may well have better luck getting this answered on the Ubuntu forums.


I have run into this with a few PPAs before, seems like sometimes the 
PPAs are not accessible for whatever reason.  Obviously if the PPA is 
not accessible, you can't install the package.  You may want to try to 
contact the developers of the package (there should be a contact method 
on the PPA's website).


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


Re: [Tutor] class variables

2013-12-20 Thread eryksun
On Fri, Dec 20, 2013 at 5:20 AM, Alan Gauld alan.ga...@btinternet.com wrote:

 Similarly if you have a name defined within the instance it will use that if
 not it will look in the class.

An instance can generally shadow class attributes, except properties
and other data descriptors defined by the class are given precedence
when looking up attributes:

 instance = Class()
 Class.pi = property(lambda s: 3.14)

 instance.pi
3.14
 instance.pi = 4
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: can't set attribute

The property is used even if you manually assign pi in the instance dict:

 vars(instance)['pi'] = 4
 vars(instance)
{'pi': 4}
 instance.pi
3.14
___
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 95

2013-12-20 Thread Mark Lawrence

On 20/12/2013 01:21, Keith Winston wrote:

On Thu, Dec 19, 2013 at 5:58 PM, tutor-requ...@python.org
mailto:tutor-requ...@python.org wrote:

  So... is there any way to go back up to the previous line and
correct the
  syntax?  As it is now we are starting the entire file over.  It's
really
  cumbersome.  Is it supposed to be this way?


I notice Python for Kids uses Python 3.2, and (p. 9) IDLE, the
Integrated Development Environment that comes with Python. But it
doesn't sound like YOU'RE using Idle: Look for an icon/button that
says Idle, instead of Python. Try to make sure that it says something
about Python 3.x, since 2.x is different in a few respects (in case you
installed the wrong one).

If you use Idle, you'll need to open a new window (from within IDLE) in
which to create/edit files, and it will prompt you to save them before
you can run them (which will automatically happen in the other window):
all of this can be done from the menu bar of the new window. It will
be sort of obvious once you start.

It appears to be an interesting book, one of the reviewers is 15 y.o...
but it's not light, I will be surprised if a 5 y.o. gets through it.
They suggest 10 yo and up. But kids can often rise to challenges, good luck!


--
Keith



Please change the subject if you're replying to a digest.

TIA.

--
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


[Tutor] Linux vs. Python

2013-12-20 Thread Keith Winston
On Fri, Dec 20, 2013 at 6:00 AM, tutor-requ...@python.org wrote:

 This looks more like an Ubuntu issue than a Python one?
 Did you mean to send it to the tutor list?


Oops. Sorry


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


[Tutor] Stuck on error

2013-12-20 Thread NZHacker1 .
I'm trying to make a lottery in python and i keep getting this error. Cant
assign to operator.(Mega Millions, line 47)


Here's the code.

import random

for i in range(1):
RN1 = random.randint(1,75)

for i in range(1):
RN2 = random.randint(1,75)

for i in range(1):
RN3 = random.randint(1,75)

for i in range(1):
RN4 = random.randint(1,75)

for i in range(1):
RN5 = random.randint(1,75)

for i in range(1):
RMB = random.randint(1,15)

x = raw_input('Money in pennys.')
Plays = int(x) * 100
plays = int(x) * 100
z = 0
Game = ('Game')
while Plays != 0:
Plays = Plays - 1
z = z + 1
for i in range(1):
N1 = random.randint(1,75)

for i in range(1):
N2 = random.randint(1,75)

for i in range(1):
N3 = random.randint(1,75)

for i in range(1):
N4 = random.randint(1,75)

for i in range(1):
N5 = random.randint(1,75)

for i in range(1):
MB = random.randint(1,15)

Game + z = N1 + N2 + N3 + N4 + N5 + MB

z = 0
while plays != 0:
Plays = Plays - 1
z = z + 1
print(Game + str(z))
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] menu-libre broken? :p:

2013-12-20 Thread Pierre Dagenais


On 13-12-20 05:59 AM, Paradox wrote:
 
 On 12/19/2013 10:46 PM, Keith Winston wrote:
 I did this sequence of commands:

 sudo add-apt-repository ppa:menulibre-dev/devel
 sudo apt-get update
 sudo apt-get install menulibre

 But at the end of the update I got:

 W: Failed to fetch
 http://ppa.launchpad.net/menulibre-dev/devel/ubuntu/dists/saucy/main/source/Sources



 Alan is correct, this is an Ubuntu problem rather than a Python problem.
  You may well have better luck getting this answered on the Ubuntu forums.
 
 I have run into this with a few PPAs before, seems like sometimes the
 PPAs are not accessible for whatever reason.  Obviously if the PPA is
 not accessible, you can't install the package.  You may want to try to
 contact the developers of the package (there should be a contact method
 on the PPA's website).
 
 thomas
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 https://mail.python.org/mailman/listinfo/tutor
 
If you go to the website
http://ppa.launchpad.net/menulibre-dev/devel/ubuntu/dists/ you'll see
that precise, quantal and raring are the only distributions offered,
saucy is not. I don't know why, but like Thomas said you should contact
the developers of the package, or just wait, a fix is probably underway.

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


Re: [Tutor] Stuck on error

2013-12-20 Thread Joel Goldstick
On Fri, Dec 20, 2013 at 11:36 AM, NZHacker1 . nikolau...@gmail.com wrote:

 I'm trying to make a lottery in python and i keep getting this error. Cant
 assign to operator.(Mega Millions, line 47)


That isn't your code, or that isn't your error message.  Cut and paste your
actual code and your actual traceback.  What is line 47?




 Here's the code.

 import random

 for i in range(1):
 RN1 = random.randint(1,75)

 for i in range(1):
 RN2 = random.randint(1,75)

 for i in range(1):
 RN3 = random.randint(1,75)

 for i in range(1):
 RN4 = random.randint(1,75)

 for i in range(1):
 RN5 = random.randint(1,75)

 for i in range(1):
 RMB = random.randint(1,15)

 x = raw_input('Money in pennys.')
 Plays = int(x) * 100
 plays = int(x) * 100
 z = 0
 Game = ('Game')
 while Plays != 0:
 Plays = Plays - 1
 z = z + 1
 for i in range(1):
 N1 = random.randint(1,75)

 for i in range(1):
 N2 = random.randint(1,75)

 for i in range(1):
 N3 = random.randint(1,75)

 for i in range(1):
 N4 = random.randint(1,75)

 for i in range(1):
 N5 = random.randint(1,75)

 for i in range(1):
 MB = random.randint(1,15)

 Game + z = N1 + N2 + N3 + N4 + N5 + MB

 z = 0
 while plays != 0:
 Plays = Plays - 1
 z = z + 1
 print(Game + str(z))

 In the above block you have 'plays' and 'Plays'.  I suspect that is a
 problem for you
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 https://mail.python.org/mailman/listinfo/tutor




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


Re: [Tutor] Stuck on error

2013-12-20 Thread Alan Gauld

On 20/12/13 16:36, NZHacker1 . wrote:

I'm trying to make a lottery in python and i keep getting this error.
Cant assign to operator.(Mega Millions, line 47)


Please always send the full error message not just the last part.
There is a lot of useful data missing here.


Here's the code.

import random

for i in range(1):
 RN1 = random.randint(1,75)


Why do you have a for loop if you are only doing it once?
Just assign the value directly


x = raw_input('Money in pennys.')
Plays = int(x) * 100
plays = int(x) * 100
z = 0
Game = ('Game')


You don;t need the parens here, they aren't doing anything.


while Plays != 0:
 Plays = Plays - 1
 z = z + 1
 for i in range(1):
 N1 = random.randint(1,75)
 for i in range(1):
 N2 = random.randint(1,75)


Again, looping over range(1) is pointless.


 Game + z = N1 + N2 + N3 + N4 + N5 + MB


Here is the error. You cannot assign a value(N1+N2+...)
to an expression (Game + z). In fact I'm not even sure
what you thought that might do?

Are you trying to compare the values of the two expressions?
In which case you need to use == instead of =. But then it would
still be pointless because you don't store or use the boolean
outcome. What are you trying to achieve in that line?


z = 0
while plays != 0:
 Plays = Plays - 1
 z = z + 1
 print(Game + str(z))


This is an infinite loop. You are testing the value of plays
(lower case) but modifying the value of Plays (Capitalised)
Because plays is never changed the loop runs forever.

It might help to explain how you think the program should
work and then we can offer some ideas.

--
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] Stuck on error

2013-12-20 Thread Joel Goldstick
On Fri, Dec 20, 2013 at 1:27 PM, Joel Goldstick joel.goldst...@gmail.comwrote:




 On Fri, Dec 20, 2013 at 11:36 AM, NZHacker1 . nikolau...@gmail.comwrote:

 I'm trying to make a lottery in python and i keep getting this error.
 Cant assign to operator.(Mega Millions, line 47)


 That isn't your code, or that isn't your error message.  Cut and paste
 your actual code and your actual traceback.  What is line 47?




 Here's the code.

 import random

 for i in range(1):
 RN1 = random.randint(1,75)

 What do you think these loops do?  They don't do anything except run the
ramdon.randint() stuff once.  So why the loops?

 for i in range(1):
 RN2 = random.randint(1,75)

 for i in range(1):
 RN3 = random.randint(1,75)

 for i in range(1):
 RN4 = random.randint(1,75)

 for i in range(1):
 RN5 = random.randint(1,75)

  for i in range(1):
 RMB = random.randint(1,15)

 x = raw_input('Money in pennys.')
 Plays = int(x) * 100
 plays = int(x) * 100
 z = 0
 Game = ('Game')
 while Plays != 0:
 Plays = Plays - 1
 z = z + 1
 for i in range(1):
 N1 = random.randint(1,75)

 for i in range(1):
 N2 = random.randint(1,75)

 for i in range(1):
 N3 = random.randint(1,75)

 for i in range(1):
 N4 = random.randint(1,75)

 for i in range(1):
 N5 = random.randint(1,75)

 for i in range(1):
 MB = random.randint(1,15)

 Game + z = N1 + N2 + N3 + N4 + N5 + MB

 z = 0
 while plays != 0:
 Plays = Plays - 1
 z = z + 1
 print(Game + str(z))

 In the above block you have 'plays' and 'Plays'.  I suspect that is a
 problem for you
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 https://mail.python.org/mailman/listinfo/tutor




 --
 Joel Goldstick
 http://joelgoldstick.com




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


Re: [Tutor] class variables

2013-12-20 Thread Steven D'Aprano
On Fri, Dec 20, 2013 at 02:04:49AM -0500, Keith Winston wrote:
 I am a little confused about class variables: I feel like I've repeatedly
 seen statements like this:

I don't like the terms class variable and instance variable. In the 
Python community, these are usually called class and instance attributes 
rather than variables or members.

(Sometimes, people will call them members, especially if they are used 
to C#. The meaning here is member as in an arm or leg, as in 
dismember, not member in the sense of belonging to a group.)

Normally, we say that a string variable is a variable holding a string, 
a float variable is a variable holding a float, an integer variable is a 
variable holding an integer. So a class variable ought to be a variable 
holding a class, and an instance variable ought to be a variable holding 
an instance. In Python we can have both of those things!

Unlike Java, classes are first-class citizens and can be treated 
exactly the same as strings, floats, ints and other values. So a class 
variable would be something like this:

for C in list_of_classes:
# Here, C holds a class, and so we might call
# it a class variable, not a string variable
do_something_with(variable)


 There is only one copy of the class variable and when any one object makes a
 change to a class variable, that change will be seen by all the other
 instances.
 Object variables are owned by each individual object/instance of the class.
 In this case, each object has its own copy

Talking about copies is not a good way to understand this. It might make 
sense to talk about copies in some other languages, but not in Python. 
(Or any of many languages with similar behaviour, like Ruby or Java.) 

I'm going to give you a simple example demonstrating why thinking about 
copies is completely the wrong thing to do here. If you already 
understand why copies is wrong, you can skip ahead here, but otherwise 
you need to understand this even though it doesn't directly answer your 
question.

Given a simple class, we can set an attribute on a couple of instances 
and see what happens. Copy and paste these lines into a Python 
interactive session, and see if you can guess what output the print will 
give:


class Test:
pass

spam = Test()
eggs = Test()

obj = []
spam.attribute = obj
eggs.attribute = obj
spam.attribute.append(Surprise!)

print(eggs.attribute)


If you think about *copies*, you might think that spam and eggs have 
their own independent copies of the empty list. But that's not what 
Python does. You don't have two copies of the list, you have a single 
list, and two independent references to it. (Actually, there are three: 
obj, spam.attribute, eggs.attribute.) But only one list, with three 
different names.

This is similar to people. For instance, the President of the USA is 
known as Mr President to his staff, POTUS to the military, Barrack 
to his wife Michelle, Mr Obama to historians and journalists, Dad to 
his children, and so forth. But they all refer to the same person. In a 
few years, Barrack Obama will stand down as president, and somebody else 
will be known as Mr President and POTUS, but he'll still be 
Barrack to Michelle.

Python treats objects exactly the same. You can have lots of names for 
the same object. Some objects, like lists, can be modified in place. 
Other objects, like strings and ints, cannot be.

In Python, we refer to this system as name binding. You have things 
which are names, like obj, and we associate an object to that name. 
Another term for this is a reference, in the generic sense that we 
refer to things.

So we can bind an object to a name:

obj = []

We can *unbind* the name as well:

del obj

In Python, assignment with = is name binding, and not copying:

spam.attribute = obj

does not make a copy of the list, it just makes spam.attribute and 
obj two different names for the same list. And likewise for 
eggs.attribute.


Hopefully now you can understand why it is wrong to talk about copies 
here. In Python, you only get copies when you explicitly call a function 
which makes a copy, and never from = assignment (name binding).


Now let me get back to your original question:
 
 But when I test, I see some interesting things: first (and this is
 consistent with above) the class variables are created when the class is
 defined, and can be used even without any instances of the class being
 created.

Correct. Not only that, but class attributes will show up from instances 
as well:


py class Parrot:
... colour = green
... def description(self):
... return You see a %s coloured bird. % self.colour
...
py polly = Parrot()
py polly.description()
'You see a green coloured bird.'


 Second, initially confusing but maybe I understand... there are pointers to
 the class variables associated with every instance of the object, 

Don't think about pointers. That's too specific. It just so happens that 
the version of Python you are using