Re: [Tutor] Understanding Classes

2014-01-21 Thread spir
On 01/21/2014 05:20 AM, Christian Alexander wrote: Alan, The concept and purpose of classes is starting to sink in a little bit, but I still haven't had my "Ah-ha" moment yet. I just can't seem to visualize the execution of classes, nor am I able to explain to myself how it actually works. Fo

[Tutor] How to print certain elements

2014-01-21 Thread Adriansanchez
Hello everyone, I am newbie to Python and programming in general. My question is, given a list: X=['washington','adams','jefferson','madison','monroe'] And a string: Y='washington,adams,jefferson,madison,monroe' How would I print washington and monroe using [:]? How would I print every element b

Re: [Tutor] Understanding Classes

2014-01-21 Thread Christian Alexander
Alan, The concept and purpose of classes is starting to sink in a little bit, but I still haven't had my "Ah-ha" moment yet. I just can't seem to visualize the execution of classes, nor am I able to explain to myself how it actually works. For example: class Person: def __init__ (

Re: [Tutor] Understanding Classes

2014-01-21 Thread Alan Gauld
On 21/01/14 04:20, Christian Alexander wrote: class Person: def __init__ (self, name, age):# is self just a placeholder for an arbitrary object? Yes. If you create say 4 persons, John, Paul, Ringo and George. When you call any method on those people objects the same code

Re: [Tutor] How to print certain elements

2014-01-21 Thread Alan Gauld
On 21/01/14 06:18, Adriansanchez wrote: Hello everyone, I am newbie to Python and programming in general. My question is, given a list: X=['washington','adams','jefferson','madison','monroe'] And a string: Y='washington,adams,jefferson,madison,monroe' How would I print washington and monroe usin

Re: [Tutor] How to print certain elements

2014-01-21 Thread spir
On 01/21/2014 07:18 AM, Adriansanchez wrote: Hello everyone, I am newbie to Python and programming in general. My question is, given a list: X=['washington','adams','jefferson','madison','monroe'] And a string: Y='washington,adams,jefferson,madison,monroe' Side note: you can generate X automati

Re: [Tutor] Understanding Classes

2014-01-21 Thread Steven D'Aprano
On Mon, Jan 20, 2014 at 09:33:29AM +, Alan Gauld wrote: > >However, I understand that classes are > >parallel to that of a blueprint, > > Yes, they define what the objects will look like, what data and what > methods they contain. But to use those objects you have to instantiate > them and

Re: [Tutor] How to print certain elements

2014-01-21 Thread eryksun
On Tue, Jan 21, 2014 at 5:18 AM, Alan Gauld wrote: > > for name in X: > if name not in (X[0], X[-1]): >print name > > For the special case of excluding the first and > last names you could use the [:] notation like > this: > > print X[1:-1] > > But that only works where you want *all*

Re: [Tutor] Understanding Classes

2014-01-21 Thread Steven D'Aprano
On Sun, Jan 19, 2014 at 04:59:58PM -0500, Christian Alexander wrote: > Hello Tutorians, > > Looked all over the net for class tutorials > Unable to understand the "self" argument > Attempting to visual classes Let me explain classes by analogy. Classes are best as representing things, that is, n

Re: [Tutor] How to print certain elements

2014-01-21 Thread Keith Winston
If you are playing around at the Python prompt (the >>>), which you really should be to get the hang of this stuff, you might notice that the bracket indexing that you and everyone is talking about works both on strings (Y) and on lists (X: in this case, a list of strings). They may not behave the

Re: [Tutor] Understanding Classes

2014-01-21 Thread eryksun
On Tue, Jan 21, 2014 at 7:18 AM, Steven D'Aprano wrote: > The same applies to methods, with just one additional bit of magic: when > you call a method like this: > > instance.method(a, b, c) # say > > Python turns it into a function call: > > method(instance, a, b, c) > > [For advanced

Re: [Tutor] when is "pythondontwritebytecode" useful?

2014-01-21 Thread Albert-Jan Roskam
>On Mon, Jan 20, 2014 at 5:42 AM, Albert-Jan Roskam wrote: >> >> When is setting a PYTHONDONTWRITEBYTECODE environment variable useful? Or >> set sys.dont_write_bytecode to True? Or start Python with the -B option? >> I know what it does >> (http://docs.python.org/2/using/cmdline.html#envvar-PYT

Re: [Tutor] How to print certain elements

2014-01-21 Thread Mkhanyisi Madlavana
How would I print washington and monroe using [:]? print X[::3] How would I print every element but those two names? print X[1::2] On 21 January 2014 12:18, Alan Gauld wrote: > On 21/01/14 06:18, Adriansanchez wrote: > >> Hello everyone, >> I am newbie to Python and programming in general. My

Re: [Tutor] How to print certain elements

2014-01-21 Thread Mark Lawrence
On 21/01/2014 10:24, Mkhanyisi Madlavana wrote: How would I print washington and monroe using [:]? print X[::3] How would I print every element but those two names? print X[1::2] On 21 January 2014 12:18, Alan Gauld mailto:alan.ga...@btinternet.com>> wrote: On 21/01/14 06:18, Adriansanch