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

2013-12-21 Thread Keith Winston
On Sat, Dec 21, 2013 at 2:14 AM, tutor-requ...@python.org wrote:

 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.


Hey Steven, that was a very generous explanation. Thanks! Very clear. I was
floundering over the simple name/concept of attibute, and it had undermined
my reading of other material. Your examples were extremely helpful. I think
I understood everything you said (after a second reading). I keep hearing
about how Python creates namespaces which I think are dictionaries, I'm
going to have to look into that further to understand how some of this fits
together. I think that's where Python is going when you're talking about
looking up attributes (and it would include methods too, unless they're
still functions... maybe they're methods for instances and functions for
classes? Ok, I don't get that part yet).

Anyway, thanks again
-- 
Keith
___
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 99

2013-12-21 Thread Mark Lawrence

On 21/12/2013 07:53, Keith Winston wrote:


On Sat, Dec 21, 2013 at 2:14 AM, tutor-requ...@python.org
mailto:tutor-requ...@python.org wrote:

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.


Hey Steven, that was a very generous explanation. Thanks! Very clear. I
was floundering over the simple name/concept of attibute, and it had
undermined my reading of other material. Your examples were extremely
helpful. I think I understood everything you said (after a second
reading). I keep hearing about how Python creates namespaces which I
think are dictionaries, I'm going to have to look into that further to
understand how some of this fits together. I think that's where Python
is going when you're talking about looking up attributes (and it would
include methods too, unless they're still functions... maybe they're
methods for instances and functions for classes? Ok, I don't get that
part yet).

Anyway, thanks again
--
Keith



I'm unsure as to what the subject line has in common with class and 
instance variables, would you care to explain it please.


--
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] class variables

2013-12-21 Thread eryksun
On Sat, Dec 21, 2013 at 2:14 AM, Steven D'Aprano st...@pearwood.info wrote:

 (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.)

A Python object isn't just a fixed-size block of data with members at
fixed offsets. It stores its data dynamically in a dict.

That said, CPython objects do have members as an implementation
detail, including class-defined __slots__. The member_descriptor type
is used to access members as attributes.

For example, the read-only __base__ attribute of a class uses the
following descriptor:

 vars(type)['__base__']
member '__base__' of 'type' objects

 Suppose we ask Python for polly.colour. Python looks at the instance
 polly, and checks to see if it has an instance attribute called polly.
 If it does, we're done. But if it doesn't, Python doesn't give up
 straight away, it next checks the class of polly, which is Parrot. Does
 Parrot have an attribute called polly? Yes it does, so that gets
 returned.

It first has to check Parrot and its base classes (in Method
Resolution Order, i.e. Parrot.__mro__) for a data descriptor (e.g. a
property) named colour. An instance can't override a data
descriptor.

 So unlike *getting* an attribute, which searches both the instance
 and the class, *setting* or *deleting* an attribute stops at the
 instance.

Setting and deleting an attribute also has to start by searching the
class and bases for data descriptors.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] more html/css question than python

2013-12-21 Thread Matthew Ngaha
hey guys ive got the very basics of django down. i was able to design
a very basic dynamite site and interacted with django. It's basic 
limited in every way, with the little it does, and the plain ugly
design. This won't be good enough to put up anywhere but on localhost.

My question is, How do you guys or designers in general go about
creating a site. do you guys find designing a site from scratch with
html/css fun... or is it so tedious that you just go with an existing
template? I was told people don't design sites with manual  html/css
anymore as they use many tools that can generate web pages without
having to type all that code. i'm wondering if its worth learning
html5/css3 beyond a basic level in conjunction with django, or are
there easier better options.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class variables [was Tutor Digest, Vol 118, Issue 99]

2013-12-21 Thread Steven D'Aprano
(I fixed the subject line for you.)

On Sat, Dec 21, 2013 at 02:53:28AM -0500, Keith Winston wrote:
 On Sat, Dec 21, 2013 at 2:14 AM, tutor-requ...@python.org wrote:
 
  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.
 
 
 Hey Steven, that was a very generous explanation. Thanks! Very clear. I was
 floundering over the simple name/concept of attibute, and it had undermined
 my reading of other material. Your examples were extremely helpful. I think
 I understood everything you said (after a second reading). 

Glad to be of service!


 I keep hearing
 about how Python creates namespaces which I think are dictionaries, I'm
 going to have to look into that further to understand how some of this fits
 together.

Think of a typical family. Unless you're one of George Foreman's five 
sons all called George, chances are that everyone in the family has a 
different name. (Or at least a different nickname.) Fred in your 
family is not the same as Fred in my family. In this case, the family 
plays the role of a namespace: everyone inside the family has a unique 
name that they are known by, but people in different families can have 
the same name.

In general, a namespace is some sort of environment or container that 
holds identifiers (such as names, or ID numbers). Within a single 
namespace, all identifiers have to be unique, but two different 
namespaces can hold the same identifier. For example, in Python, each 
module is a namespace. If you have two files, say spam.py and 
eggs.py, the two modules may include variables with the same name:

spam.thing = 23
eggs.thing = 42

Even though they are both called thing, they live in different 
namespaces so they can have different values.

Python namespaces are usually dictionaries. The globals() function 
returns the global namespace, which is a dict. You will find all your 
global variables in it. Here's an example:

py x = 23
py d = globals()
py d['x']
23
py d['x'] = 42
py x
42


(Note: operating directly on globals(), as I do in that example, is not 
a common thing to do. Python gives you the ability to do so, but it's 
quite rare to actually need it.)

Classes and instances also behave as namespaces. Both normally have a 
special attribute called __dict__ (that's two underscores at the start 
and end of the name). Class.__dict__ holds the class attributes, 
including methods. The instance __dict__ holds the instance attributes.

Rather than access the __dict__ directly, it is nearly always better to 
use getattr and setattr functions. That is:

# don't do this
obj.__dict__['attribute'] = 23

# this is better
setattr(obj, 'attribute', 23)

# but this is even better
obj.attribute = 23


The main reason for using getattr and setattr is when you don't know the 
name of the attribute when you write the code, but only at runtime. For 
example:

name = get_some_name()  # returns some attribute name
getattr(obj, name)

You can't use obj.name, since that will return the attribute called 
literally name. In this case, you want the attribute named *by* name 
instead -- if name == colour, you want obj.colour, if name == height, 
you want obj.height, and so on.


 I think that's where Python is going when you're talking about
 looking up attributes (and it would include methods too, unless they're
 still functions... maybe they're methods for instances and functions for
 classes? Ok, I don't get that part yet).

Methods and functions are another story, but in a nutshell, methods are 
just like functions except that they live inside classes, and when you 
call a method, it automatically gets the instance as the first argument. 
Confused? Here's an example, using a string method.

Strings have a method, replace, that works like this:

py the cat in the hat eats green ham.replace(cat, dog)
'the dog in the hat eats green ham'


If replace were a function, we would write it something like this:

# simplified version
def replace(s, old, new):
...


and you would call it like this:


replace(the cat in the hat eats green ham, cat, dog)
= returns the dog in the hat eats green ham


So you can think of the difference between methods and functions that 
methods use the syntax:

arg1.method(arg2, arg3, ...)

instead of:

function(arg1, arg2, arg3, ...)


There are other differences, but that is the most important one.



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


Re: [Tutor] class variables

2013-12-21 Thread Steven D'Aprano
On Sat, Dec 21, 2013 at 08:41:17AM -0500, eryksun wrote:
 On Sat, Dec 21, 2013 at 2:14 AM, Steven D'Aprano st...@pearwood.info wrote:
 
  (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.)
 
 A Python object isn't just a fixed-size block of data with members at
 fixed offsets. It stores its data dynamically in a dict.

Yes, but that's just an implementation detail. There's no fundamental 
difference between attribute, member and (instance/class) 
variable. Different languages give them different names according to 
whatever vagaries the language creator considers important. C# happens 
to use fixed-sized records, Python happens to (usually) use dicts.

Having said that, I do think it is useful to reserve the term member 
for the fixed-size block type, and attribute for the general term. At 
least when talking about Python.

[...]
 For example, the read-only __base__ attribute of a class uses the
 following descriptor:
 
  vars(type)['__base__']
 member '__base__' of 'type' objects

Oooh, nice! I always forget about vars(), and end up messing about with 
__dict__.


  Suppose we ask Python for polly.colour. Python looks at the instance
  polly, and checks to see if it has an instance attribute called polly.
[...]

 It first has to check Parrot and its base classes (in Method
 Resolution Order, i.e. Parrot.__mro__) for a data descriptor (e.g. a
 property) named colour. An instance can't override a data
 descriptor.

I did say it was an over-simplified description. I didn't think it was 
helpful to start talking about descriptors to a beginner :-)

For what it's worth, descriptors are both absolutely fundamental to how 
Python operates, and an advanced feature that newbies don't need to 
understand immediately,


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


Re: [Tutor] more html/css question than python

2013-12-21 Thread Alan Gauld

On 21/12/13 15:07, Matthew Ngaha wrote:


My question is, How do you guys or designers in general go about
creating a site.


Most of my personal websites are so trivial that I just
hand craft everything in vim. If I had to do something
bigger where looks were important I'd probably go with
a simple word processor like Libre/OpenOffice anmd
then hand tweak the html and css as needed.

At work we did much bigger and more complex sites.
For those we had a team of graphics designers who
developed the html and css files using a standard
web design tool (DreamWeaver I think)  and some
company based rules to fit our design.

The developers then worked against a template system
using whatever web tools they were working with:
ASP.Net, JSP, WebLogic, OracleAppServer etc.

Oddly, I've never worked on anything between
those extremes. Its either been a tiny site for
a few hundred hits per day or a huge site
expecting millions of hits per day.


do you guys find designing a site from scratch with
html/css fun... or is it so tedious that you just go with an existing
template?


I only once used a template and hated it so much
I redid it by hand. I don't consider html/css fun
but I don't consider it any more of a chore than
writing a requirements spec or test spec or
architecture/design document. They are necessary
evils on any project.


I was told people don't design sites with manual  html/css
anymore as they use many tools that can generate web pages without
having to type all that code.


I suspect that's true, most sites are built using tools
like Dreamweaver or even MS FrontPage or a web tool
like WordPress.


html5/css3 beyond a basic level in conjunction with django, or are
there easier better options.


You really need to know html and css if you are building
modern web UIs. That's because most good modern web sites
use a lot of client side(browser) scripting, usually using
JQuery. JQuery requires that you really understand how
html tags and css styles work. So you may get out of
creating the bulk of the code but you still need to
understand the detail of what the tool produces. More
so today that, say, 10 years ago. Finally, I'd really
aim for xhtml rather than html since it's easier to
parse and not too much extra work to produce. (htmltidy
can convert to xhtml for you if you prefer)

--
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] more html/css question than python

2013-12-21 Thread Timo

op 21-12-13 16:07, Matthew Ngaha schreef:

hey guys ive got the very basics of django down. i was able to design
a very basic dynamite site and interacted with django. It's basic 
limited in every way, with the little it does, and the plain ugly
design. This won't be good enough to put up anywhere but on localhost.

My question is, How do you guys or designers in general go about
creating a site. do you guys find designing a site from scratch with
html/css fun... or is it so tedious that you just go with an existing
template? I was told people don't design sites with manual  html/css
anymore as they use many tools that can generate web pages without
having to type all that code. i'm wondering if its worth learning
html5/css3 beyond a basic level in conjunction with django, or are
there easier better options.
I always use the Twitter Bootstrap boilerplate. Here are the docs: 
http://getbootstrap.com/


Everything is set up for you already so you can create good looking 
websites in a flash.


Timo


___
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] more html/css question than python

2013-12-21 Thread Matthew Ngaha
On Sat, Dec 21, 2013 at 5:56 PM, Alan Gauld alan.ga...@btinternet.com wrote:

 You really need to know html and css if you are building
 modern web UIs. That's because most good modern web sites
 use a lot of client side(browser) scripting, usually using
 JQuery. JQuery requires that you really understand how
 html tags and css styles work. So you may get out of
 creating the bulk of the code but you still need to
 understand the detail of what the tool produces. More
 so today that, say, 10 years ago. Finally, I'd really
 aim for xhtml rather than html since it's easier to
 parse and not too much extra work to produce. (htmltidy
 can convert to xhtml for you if you prefer)

so xhtml even over html5? isn't html5 the new thing these days? I know
basic javascript, so it's definately  better to also learn jquery?
I've always pushed it to the side :(
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] more html/css question than python

2013-12-21 Thread Devin Jeanpierre
On Sat, Dec 21, 2013 at 11:10 AM, Matthew Ngaha chigga...@gmail.com wrote:
 so xhtml even over html5? isn't html5 the new thing these days? I know
 basic javascript, so it's definately  better to also learn jquery?
 I've always pushed it to the side :(

HTML5 has an XML representation (called XHTML5) which works even in IE.

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


Re: [Tutor] class variables

2013-12-21 Thread eryksun
On Sat, Dec 21, 2013 at 12:40 PM, Steven D'Aprano st...@pearwood.info wrote:
 On Sat, Dec 21, 2013 at 08:41:17AM -0500, eryksun wrote:

  vars(type)['__base__']
 member '__base__' of 'type' objects

 Oooh, nice! I always forget about vars(), and end up messing about with
 __dict__.

It's a bit more efficient to use the __dict__ attribute, but I like
built-in vars().

vars(obj) is basically doing the equivalent of getattr(obj,
'__dict__'), so there's that plus the overhead of the call. vars has
to play it safe. A class may define a custom __dict__ property, such
as the tuple subclass created by namedtuple:

from collections import namedtuple

Point = namedtuple('Point', 'x y')
p = Point(1, 2)

 type(vars(Point)['__dict__'])
class 'property'

 vars(p)
OrderedDict([('x', 1), ('y', 2)])

Even if an object has a dict, it would be wrong for vars to naively
return a reference. A class might be overriding __getattribute__ to
create dynamic attributes or raise an AttributeError for '__dict__'.
Also, bypassing the descriptor would bypass the proxy protecting a
class dict, enabling silliness:

from ctypes import pythonapi, py_object

# 3.3+
pythonapi.PyObject_GenericGetDict.restype = py_object
pythonapi.PyObject_GenericGetDict.argtypes = [py_object]

str_dict = pythonapi.PyObject_GenericGetDict(str)
str_dict['lower'] = str_dict['upper']

 'abc'.lower()
'ABC'
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] more html/css question than python

2013-12-21 Thread Alan Gauld

On 21/12/13 19:10, Matthew Ngaha wrote:

On Sat, Dec 21, 2013 at 5:56 PM, Alan Gauld alan.ga...@btinternet.com wrote:



basic javascript, so it's definately  better to also learn jquery?
I've always pushed it to the side :(


In reality JavaScript is the only game in town for browser
scripting. And if you want to have all those sexy modern features
like popup menus, drag n' drop, rollovers, dynamic panels etc
then JQuery is so much easier than raw Javascript and works
in almost every browser too.

You don't need it, in that you can build applications without
it. But if you want something that looks like it was built
this century then JQuery is pretty important.

And as an added bonus it makes Ajax style programming a cinch too.
Or as much of a cinch as Ajax ever can be.

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


[Tutor] The Charms of Gmail

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

 I'm unsure as to what the subject line has in common with class and
 instance variables, would you care to explain it please.



I'm sorry Mark, I'm stuck with using gmail where I have to remember to
delete the (essentially invisible) included text of the entire digest I'm
responding to, and change the (entirely invisible) subject line. It

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


[Tutor] Global namespace/dictionary

2013-12-21 Thread Keith Winston
On Sat, Dec 21, 2013 at 12:56 PM, tutor-requ...@python.org wrote:

 py x = 23
 py d = globals()
 py d['x']
 23
 py d['x'] = 42
 py x
 42



Well this is sort of fascinating, but a bit confusing: I was playing with
this, and it seems like the global dictionary includes not just the name
but the entire contents of every dictionary within it... that seems
implausibly redundant, so maybe that's just something about how exploring a
dictionary functions recursively, or something? Maybe it's correct to say
that any dictionaries within a namespace are stored in that namespace,
though that doesn't really sound right.

 d = globals()
 fubar = {1: 'spam', 'eggs': 2}
 d
{'__name__': '__main__', '__builtins__': module 'builtins' (built-in),
'__doc__': None, '__loader__': class '_frozen_importlib.BuiltinImporter',
'fubar': {1: 'spam', 'eggs': 2}, 'd': {...}, '__package__': None}

And yes, I did change up my string/int order in key/value positions: I'm
fascinated by the flexibility of the data structure. I suspect the answer
to my question lies in exactly this facet.

-- 
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-21 Thread NZHacker1 .
I'm trying to make a lottery in python and I keep getting this error.

There's an error in your program:
***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))





Line 47 in highlighted in red.
I'm not finished with the program and I put Plays = int(x) * 100,
plays = int(x) * 100
on purpose.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Global namespace/dictionary

2013-12-21 Thread Dave Angel
On Sat, 21 Dec 2013 14:22:32 -0500, Keith Winston 
keithw...@gmail.com wrote:

Tutor maillist  -  Tutor@python.org


Please stick with text mail, not html.

--
DaveA

___
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-21 Thread Marc Tompkins
On Sat, Dec 21, 2013 at 12:36 PM, NZHacker1 . nikolau...@gmail.com wrote:


 I'm not finished with the program and I put Plays = int(x) * 100,
 plays = int(x) * 100
 on purpose.


I don't think you understood what people were trying to tell you.  Python
is case-sensitive; plays and Plays are NOT the same variable.

The problem with line 47 is that you have this on the left side of the
equals sign: Game + z.
Can't assign to operator means that Python thinks you are trying to
assign a value to the plus sign, which is obviously impossible.

I'm not sure I understand what you really wanted to do in line 47.  I don't
know what your Game variable is supposed to be - is it a string?  A list of
strings?

Leaving aside the fact that what you've written is a syntax error... your
line 47 is trying to do this:
String + int = int + int + int + int + int + int

which wouldn't make any sense, and is probably not what you had in mind
anyway.

I think you're trying to get Game to contain a string that says something
like Game 5: 45 57 38 24 66 89, right?  If so, you want to use string
formatting for that, NOT addition.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The Charms of Gmail

2013-12-21 Thread Dominik George
 I'm sorry Mark, I'm stuck with using gmail [...]

Use sane e-mail, then.

-- 
# apt-assassinate --help
Usage: apt-assassinate [upstream|maintainer] package

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