[Tutor] Alert to all Experienced Python Software Object Oriented Programmers-Novice Needs Help In Understanding Textbook

2014-08-17 Thread Stephen Mik
Greetings Python Community:
I am new to Computer Programming with Python,having finished an 8 week 
Introductory Course. The Instructor used the Textbook:"Python Programming,3rd 
Edition (for the absolute beginner) by Michael Dawson;Cengage Learning, Course 
Technology Copyright 2010 ISBN-13: 978-1-4354-5500-9  ISBN-10: 1-4354-5500-2.
The course only covered the Chapters 1-6 in the book. I have accomplished some 
reading of my own,Chapter 7 which I understood; but ran into stiff headwinds 
when I tried to read Ch.8,"Software Objects:The Critter Caretaker Program". I 
hope that some of you have the textbook or can look it up online,because I have 
many questions about the Text's treatment of Software Objects. (I'm scheduled 
to take a JavaScript class shortly and since that is object-oriented I really 
need to get this OOP down). Specifically,the Text on pages 222-232 I am finding 
the whole discussion on "Instantiating an 
Object","Methods","Constructors","Attributes-on page 226-228,Using Class 
Attributes and Static Methods(page 228-230;Creating A Class Attribute,Accessing 
a Class Attribute(Pg. 231);Using and Invoking a Static Method (pages 231-232) 
is all confusing to me and doesn't "congeal" or "come Together" in one coherent 
discussion. Forgive me if I seem dense;but this chapter has a lot
 of heavy reading in it! Please,somebody,explain the magic of Software Objects 
in Python to me ASAP. Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Alert to all Experienced Python Software Object Oriented Programmers-Novice Needs Help In Understanding Textbook

2014-08-17 Thread Alan Gauld

On 17/08/14 03:58, Stephen Mik wrote:


Introductory Course. The Instructor used the Textbook:"Python
Programming,3rd Edition (for the absolute beginner) by Michael
Dawson;...
ran into stiff headwinds when I tried to read Ch.8,"Software Objects



(I'm scheduled to take a JavaScript class shortly and since that

> is object-oriented I really need to get this OOP down).

Actually modern best practice in JavaScript does not use OOP so much as 
Functional Programming. And the OOP parts of JavaScript tend to be very 
different to the traditional style of OOP used in Python. So I wouldn't 
worry too much, you will have a new way of working to learn in 
JavaScript even if you master Python OOP, although at least the basic 
concepts will be familiar.



discussion on "Instantiating an Object","Methods","Constructors",


That's pretty much most of OOP...
Have you tried reading another OOP tutorial? Sometimes a different 
approach can help. You can try my OOP topic in my tutorial(see .sig)



"Attributes-on page 226-228,Using Class
Attributes and Static Methods(page 228-230;Creating A Class
Attribute,Accessing a Class Attribute(Pg. 231);Using and Invoking a
Static Method (pages 231-232) is all confusing to me


Forget about this stuff until you have the basics down. class and static 
methods are quite advanced OOP topics. They won't make much sense until 
you understand classes, instances and instance methods.



Please,somebody,explain the magic of Software Objects in Python to me
ASAP. Thanks!


Try the OOP topic in my tutorial and come back if you are still confused 
about the basics. The more specific the question the better the answers 
will be so try to explain what it is you don't

understand. Include some code samples that you want to have
explained for example.

Also tell us which version of Python you use because some of
the syntax for OOP changed significantly between Python v2
and Python v3.

--
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] python ssl error

2014-08-17 Thread Matthew Ngaha
Hi this might not be the correct place to ask this. I am using the
google api and as soon as I use the build function:

service = build('books', 'v1', developerKey=api_key)

I get an SSL error. I'm not sure what build() does but it triggers an
SSL error. Here's the error message:

 ssl.SSLError: [Errno 185090050] _ssl.c:357: error:0B084002:x509
certificate routines:X509_load_cert_crl_file:system lib

I googled this error but I don't understand the solution. It seems
specific to httplib2:

   https://github.com/kennethreitz/requests/issues/557


Here is the full trace back. Any ideas?

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


Re: [Tutor] Alert to all Experienced Python Software Object Oriented Programmers-Novice Needs Help In Understanding Textbook

2014-08-17 Thread ALAN GAULD
Forwarding to the list, please use ReplyAll to include the list.
 
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/

http://www.flickr.com/photos/alangauldphotos



>
> From: diliup gabadamudalige 
>To: Alan Gauld  
>Sent: Sunday, 17 August 2014, 13:06
>Subject: Re: [Tutor] Alert to all Experienced Python Software Object Oriented 
>Programmers-Novice Needs Help In Understanding Textbook
> 
>
>
>below is a good article.
>
>
>
>http://www.voidspace.org.uk/python/articles/OOP.shtml
>
>
>
>below is another good one.
>
>
>http://www.jeffknupp.com/blog/2014/06/18/improve-your-python-python-classes-and-object-oriented-programming/?utm_source=Python+Weekly+Newsletter&utm_campaign=5a7c0c161f-Python_Weekly_Issue_145_June_26_2014&utm_medium=email&utm_term=0_9e26887fc5-5a7c0c161f-307214369
>
>
>
>
>On Sun, Aug 17, 2014 at 2:25 PM, Alan Gauld  wrote:
>
>On 17/08/14 03:58, Stephen Mik wrote:
>>
>>
>>Introductory Course. The Instructor used the Textbook:"Python
>>>Programming,3rd Edition (for the absolute beginner) by Michael
>>>
Dawson;...
>>>
>>>ran into stiff headwinds when I tried to read Ch.8,"Software Objects
>>>
>>
>>(I'm scheduled to take a JavaScript class shortly and since that
>>>
> is object-oriented I really need to get this OOP down).
>>
>>
Actually modern best practice in JavaScript does not use OOP so much as 
Functional Programming. And the OOP parts of JavaScript tend to be very 
different to the traditional style of OOP used in Python. So I wouldn't worry 
too much, you will have a new way of working to learn in JavaScript even if you 
master Python OOP, although at least the basic concepts will be familiar.
>>
>>
>>
>>discussion on "Instantiating an Object","Methods","Constructors",
>>>
>>
That's pretty much most of OOP...
>>Have you tried reading another OOP tutorial? Sometimes a different approach 
>>can help. You can try my OOP topic in my tutorial(see .sig)
>>
>>
>>
>>"Attributes-on page 226-228,Using Class
>>>Attributes and Static Methods(page 228-230;Creating A Class
>>>Attribute,Accessing a Class Attribute(Pg. 231);Using and Invoking a
>>>Static Method (pages 231-232) is all confusing to me
>>>
>>
Forget about this stuff until you have the basics down. class and static 
methods are quite advanced OOP topics. They won't make much sense until you 
understand classes, instances and instance methods.
>>
>>
>>
>>Please,somebody,explain the magic of Software Objects in Python to me
>>>ASAP. Thanks!
>>>
>>
Try the OOP topic in my tutorial and come back if you are still confused about 
the basics. The more specific the question the better the answers will be so 
try to explain what it is you don't
>>understand. Include some code samples that you want to have
>>explained for example.
>>
>>Also tell us which version of Python you use because some of
>>the syntax for OOP changed significantly between Python v2
>>and Python v3.
>>
>>-- 
>>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
>>
>
>
>
>-- 
>
>Diliup Gabadamudalige
>
>http://www.diliupg.com
>http://soft.diliupg.com/
>
>**
>This e-mail is confidential. It may also be legally privileged. If you are not 
>the intended recipient or have received it in error, please delete it and all 
>copies from your system and notify the sender immediately by return e-mail. 
>Any unauthorized reading, reproducing, printing or further dissemination of 
>this e-mail or its contents is strictly prohibited and may be unlawful. 
>Internet communications cannot be guaranteed to be timely, secure, error or 
>virus-free. The sender does not accept liability for any errors or omissions.
>**
>
>
>
>___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python = {0}.format

2014-08-17 Thread abid saied
Hi,

I’m in the process of teaching myself python. Can someone have a look at the 
text in red and explain please.

# String exercise 2

print("Quote Formatter")
print("This program displays a given quote in different formats")
print() # Why is this needed?
quote = input("Please enter a quote to format: ")
print(quote)
print(quote.upper())
print(quote.lower())
print(quote.capitalize())
print(quote.title())
replaceWord = input("Which word in the quote would you like to replace: ")
replaceWith = input("Please enter the word to replace with: ")
print("The original quote is: {0}".format(quote))
print("The new quote is:{0}".format(quote.replace(replaceWord,replaceWith)))
# Not sure what the {0}.format is doing

Thanks.

Abid 



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


[Tutor] print string

2014-08-17 Thread Sajjadul Islam
Hello forum,

I have started working with python 2.7.6 and i am trying to print the
following string value:

print("Same", "message", "as before")

and i am supposed to get

Same message as before.


But i am getting the following :

("Same", "message", "as before")


Any hint whats wrong?


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


Re: [Tutor] python ssl error

2014-08-17 Thread Danny Yoo
On Sun, Aug 17, 2014 at 5:14 AM, Matthew Ngaha  wrote:
> Hi this might not be the correct place to ask this. I am using the
> google api and as soon as I use the build function:
>
> service = build('books', 'v1', developerKey=api_key)
>
> I get an SSL error. I'm not sure what build() does but it triggers an
> SSL error. Here's the error message:
>
>  ssl.SSLError: [Errno 185090050] _ssl.c:357: error:0B084002:x509
> certificate routines:X509_load_cert_crl_file:system lib


Hi Matthew,

Yeah, this is not quite Python-Tutor material.  Check with the
httplib2 folks: I think this in is their domain.

Anyway, thanks for the detailed error message.  It gives me something
to search.  I'll see if there's something reasonable here...

... ok, found something.  According to:


http://stackoverflow.com/questions/15696526/ssl-throwing-error-185090050-while-authentication-via-oauth

the httplib2 library is having trouble accessing the certificate file.
This appears a bug involved with the pip installer and root
permissions:

https://code.google.com/p/httplib2/issues/detail?id=292


In your case, since your httplib2 is installed in:

/usr/lib/python2.7/site-packages/httplib2-0.9-py2.7.egg/httplib2/

I would recommend checking whether the 'cacerts.txt' file in that
subdirectory is user-readable or not.  Make sure it's readable.  If it
isn't, chmod it and try again: that will probably fix it.


If you do a few more searches, you might run into two dubious recommendations:

   1.  Run as root.
   2.  Disable ssl certficiate validation.

Both of these recommendations look potentially dangerous to me.  Don't
do either of these unless you really know what you're doing.

At the very least, you might try #1 just to see if you see the same
error message: if you do not see that error message when running as
the superuser, then that almost certainly means that the cause is
permission access to the cacerts.txt file.  The fix, then, should be:
correct the permission of that file.  Try not to run programs as
superuser if you can help it.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] print string

2014-08-17 Thread Alan Gauld

On 17/08/14 14:11, Sajjadul Islam wrote:

Hello forum,

I have started working with python 2.7.6 and i am trying to print the
following string value:

print("Same", "message", "as before")


Looks like you are using a Python v3 tutorial on Python 2.7.
The syntax of printing changed a lot in Python 3.

The good news is that you can fake it in Python 2.7 by adding
the line:

from __future__ import print_function

at the start of your session/program.
Then you get Python3 style printing in 2.7.

HTH

--
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] Python = {0}.format

2014-08-17 Thread Ben Finney
abid saied  writes:

> I’m in the process of teaching myself python.

Congratulations, and welcome.

> Can someone have a look at the text in red and explain please.

Text comes through as text. Don't rely on fonts, colours, or other
non-text markup to survive.

If you want to draw attention to some part of code, it is much better to
reduce the example so it is minimal enough to show only what is
relevant, while still exhibiting the behaviour you want to discuss.

> print("The original quote is: {0}".format(quote))
> print("The new quote is:{0}".format(quote.replace(replaceWord,replaceWith)))
> # Not sure what the {0}.format is doing

Every value in Python is an object, with methods according to its type.
A text string has many methods
https://docs.python.org/3/library/stdtypes.html#string-methods>.

The ‘format’ method of the ‘str’ type is used to generate formatted
output from a template string. See
https://docs.python.org/3/library/stdtypes.html#str.format> and
https://docs.python.org/3/library/string.html#formatstrings>.

-- 
 \ “I have yet to see any problem, however complicated, which, |
  `\  when you looked at it in the right way, did not become still |
_o__)more complicated.” —Paul Anderson |
Ben Finney

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


Re: [Tutor] print string

2014-08-17 Thread Ben Finney
Sajjadul Islam  writes:

> I have started working with python 2.7.6

In addition to the other responses: You should use Python 3 if at all
possible. It is in active development and much more suitable for
learning today.

-- 
 \  “Ignorance more frequently begets confidence than does |
  `\   knowledge.” —Charles Darwin, _The Descent of Man_, 1871 |
_o__)  |
Ben Finney

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


Re: [Tutor] Python = {0}.format

2014-08-17 Thread Alan Gauld

On 17/08/14 15:50, abid saied wrote:

Hi,

I’m in the process of teaching myself python. Can someone have a look at
the text in red and explain please.



print("This program displays a given quote in different formats")
print() # Why is this needed?


Its not it only adds a bnlank line. You could achieve the same result by 
adding a \n character at the end of the last line.



quote = input("Please enter a quote to format: ")
print(quote)
replaceWord = input("Which word in the quote would you like to replace: ")
replaceWith = input("Please enter the word to replace with: ")
print("The original quote is: {0}".format(quote))



# Not sure what the {0}.format is doing


String formatting inserts data values into a string.
Notice that the .format() occurs after the striong,
not after the {} marker.

The {} marks the place where the data will be inserted.
The 0 indicates that its the zero'th (or first) item in
the list that should be inserted. The list of data items
is the list of parameters to format(). Here is an example:

print ("{0} x {1} = {2}".format(3,4,12)

And another showing the value of the indexing:

s = "{0} can be written as {0} or {1}".format('four',4)
print(s)

You can have various other codes inside the {} to control
spacing and justification or padding etc.

Here is the official documentation page on the subject:

https://docs.python.org/3/library/string.html#string-formatting

HTH
--
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] Python = {0}.format

2014-08-17 Thread Danny Yoo
> print("The original quote is: {0}".format(quote))
> print("The new quote is:{0}".format(quote.replace(replaceWord,replaceWith)))

Hi Abid,


You should be able to change this to the equivalent code:

print("The original quote is: " + quote)
print("The new quote is:" + quote.replace(replaceWord,replaceWith))

which does not use string formatting, but just plain string
concatenation.  I believe it should have the same meaning, since we
know the things we're concatenating are strings.


Python includes a mini "templating language" for having a strings with
fill-me-ins, and letting you fill in the fill-me-ins later.  In such a
small example as the one above, I'd argue that templates are overkill.
You'll note that the non-templated version is even shorter than the
original code that uses templates.

String templating makes a lot more sense outside of a toy context,
when the output isn't a one-liner.  If you have access to a good
public library, find the classic book Jon Bentley's "Programming
Pearls" and read Chapter 3 on Data Structures Programs: it discusses a
rationale for "Form Letter Programming".
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Building Starships -- object of type 'int' has no len()

2014-08-17 Thread Terry--gmail
WOW! There is a lot of help on this mailing list! I want to thank 
everyone for their valuable input! Thanks!  (I am working my way through 
the replies.)


Sorry about the HTML. I think I have it turned off now in Thunderbirdy 
for this address. If so, then what follows should not be flat. If it is 
flat, please tell me.


The problem portion of the program now works, as I have corrected where 
my strings were getting converted to integers. However, if it is OK. I'd 
like to discuss and ask a few questions on a few things that have been 
brought up.


Mark:

You commented on the non-Pythonic nature of my program. HA HA HA! I 
don't doubt it!


I am coming from a BASIC background based on line numbers and GOTO and 
GOSUB statements, and when I read this book on Python I am sure I 
understood it in terms of that old BASIC. Hence, my nested FOR 
statements have been laid out in layers as I did it in this Python 
program because that is how I envisioned those statements through BASIC 
eyes. BUT, they might also have looked something like:


30 FORX=1TOZ:FORC=1TOE::NEXTE:NEXTZ

The fact is, I am VERY interested in acquiring that 'Pythonic' view you 
mention and I have encountered that term bandied about on the Internet, 
but have come away confused as to exactly what Pythonic Thinking really 
is! The writers seem to take it for granted I know. I don't.


After all, the way I laid the code out in my program is actually 
functional. So, I am really curious about the benefit of a Pythonic Way, 
and what it looks and reads like...


Is their a Pythonic Table anywhere on the Internet, where various 
possible coding methods in Python are contrasted to the real Pythonic 
Way? -So I can examine and study the contrasted structure to understand 
what the Pythonic Structure is accomplishing? (Maybe I am asking the 
wrong question here.)


I must confess that I had, when first writing the code to discover the 
maximum size of each column for later print to screen, searched the 
Internet for a python statement or an import of some kind that I could 
simply hand my block of data to, and have it come back with the maximum 
sizes of the columns. (Yes. I'm an optimist! :) ). But, I did find the 
below piece of code which sounded like it was doing what I wanted, so I 
tested it and then integrated into my program:


lens = [max(map(len, col)) for col in zip(*catalog2)]


It worked great! So I kept it (as a thing of utter beauty) as I was awed 
by it. -until I started getting that syntactic error pointing to that 
line. The problem is, I didn't understand the commands within the above 
statement (max, map, zip, and the * usage) and how they were 
interactively accomplishing things (the statement was utterly over my 
head at this juncture), and when it came to debugging, after a few 
embedded print statements failed to tip me off to the problem and the 
bug persisted, I kept suspecting the statement..so I decided to 
replace the above code with something that was very familiar and 
understandable to me (albeit, not a thing of pythonic beauty):


lens = [0] * len(catalog2[0])

for line_number in range(len(catalog2)):

for col in range(len(catalog2[line_number])):

if lens[col] < len(catalog2[line_number][col]):

lens[col] = len(catalog2[line_number][col])


-And was surprised to discover the same bug persisted! The situation 
buffaloed me into thinking there was something about the language I was 
not comprehending in this section, when the actual problem, as we 
discovered, was elsewhere.some of the string data had been converted 
to integers, and thus expecting a string instead of an integer, I got 
the Type Error.


But I am now very curious to see how this same coding would be 
accomplished in a Pythonic Way, so, letting the statement you gave me 
redefine the entire flow of thought in that area of code--


catalog2 = [

["Drives", "Type", "Price", "Max Speed", "Energy Drain", "Rq-Crew", "", 
"", ""],

["Drives", "Solar Sail", "3", "1", "None", "2", "", "", ""],

["Drives", "Bussard Ramjet", "10", "7", "2", "3", "", "", ""],

["Drives", "Fusion", "70", "15", "5", "8", "", "", ""],

["Drives", "Matter-Antimatter", "1500", "145", "15", "13", "", "", ""],

["Drives", "Warp Drive", "2500", "250", "45", "17", "", "", ""],

]


We want to find the maximum size for each column--

lens = [0] * len(catalog2[0])

for line_number, row in enumerate(catalog2):
for col, item in enumerate(row):
if lens[col] < len(item):
lens[col] = len(item)

print(lens)


[6, 17, 5, 9, 12, 7, 0, 0, 0] <<-that is the correct answer.


Did I do this correctly? Or, was there a way to compact it more?


What have we gained?


We have grabbed the entire row of data, and then looped through it 
without setting indexes when referring to the parts of each line...thus 
less clutter. Did we do this because there is less overhead generated as 
we sweep through the data?



It is the same number of lines, BUT there is less typing in most of the 
lines.



D

Re: [Tutor] python ssl error

2014-08-17 Thread Matthew Ngaha
On Sun, Aug 17, 2014 at 11:26 PM, Danny Yoo  wrote:

> I would recommend checking whether the 'cacerts.txt' file in that
> subdirectory is user-readable or not.  Make sure it's readable.  If it
> isn't, chmod it and try again: that will probably fix it.
>

Thanks ever so much for your efforts! I'm glad to say your suggestion
above fixed the problem.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Alert to all Experienced Python Software Object Oriented Programmers-Novice Needs Help In Understanding Textbook

2014-08-17 Thread ALAN GAULD
Forwarding to list, Use ReplyAll to respond to the list.

Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/

http://www.flickr.com/photos/alangauldphotos


> requirement to see hard copy of your material,which my printer seems to balk 
> at


Try the PDF version ofthe  v2 tutor - I haven't got around to converting the v3 
one yet!...

Or you can open the link from the table of contents in a new tab and it should 
print ok from there.

> work with the Google Chrome browser because of its' Development Tools. 

I completely understand that, I'd hate to develop Javascript in anything other 
than Chrome nowadays. Its simply the best toolset for that job IMHO.
Very similar to using the Python interactive prompt and IDLE debugger.

> Alas,I tried to Download Chrome from a suggested Google site,but it would 
> not be "docked". 

Not sure why, it works for me on a Macbook Air.

> At the Community College we used Python version 3.4.0 which I guess is up to 
> date. 

Yes indeed, the latest and greatest.

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


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-17 Thread Alan Gauld

On 18/08/14 00:48, Terry--gmail wrote:


Sorry about the HTML. I think I have it turned off now in Thunderbirdy
for this address. If so, then what follows should not be flat. If it is
flat, please tell me.


Still flat for me... Sorry.



The fact is, I am VERY interested in acquiring that 'Pythonic' view you
mention and I have encountered that term bandied about on the Internet,
but have come away confused as to exactly what Pythonic Thinking really
is! The writers seem to take it for granted I know. I don't.


It just means using the "normal" Python idioms - and they are learned by 
reading other Python code. Gradually it permeats your brain and seems 
second nature.


There are a few guidelines published but mostly its just local style.


But I am now very curious to see how this same coding would be
accomplished in a Pythonic Way, so, letting the statement you gave me
redefine the entire flow of thought in that area of code--

catalog2 = [
["Drives", "Type", "Price", "Max Speed", "Energy Drain", "Rq-Crew", "",
"", ""],
["Drives", "Solar Sail", "3", "1", "None", "2", "", "", ""],
["Drives", "Bussard Ramjet", "10", "7", "2", "3", "", "", ""],
["Drives", "Fusion", "70", "15", "5", "8", "", "", ""],
["Drives", "Matter-Antimatter", "1500", "145", "15", "13", "", "", ""],
["Drives", "Warp Drive", "2500", "250", "45", "17", "", "", ""],
]


We want to find the maximum size for each column--

lens = [0] * len(catalog2[0])

for line_number, row in enumerate(catalog2):
for col, item in enumerate(row):
if lens[col] < len(item):
lens[col] = len(item)


You don't need the enumerate() for the first loop
since you aren't using the index.

for row in catalog2[1:]:   # miss the header row
for col,item in enumerate(row):
if lens[col] < len(item):
   lens[col] = len(item)

Another way to do it would be to store a list of
lengths for each field then get the max of each list,
like this:

lens = [] * len(catalog2[0])
for row in catalog2[1:]:   # miss the first row
for col,item in row:
   lens[col].append(len(item))

lens = [max(col) for col in lens]

I suspect the first one is quicker but without timing them
I'm not sure.

I'm also not sure which I'd consider most Pythonic...


Do we anticipate an execution speed increase doing it this way also?


Sometimes, but its also usually more reliable - less chance of
dropping off the end of a row or missing one out.


Or have we altered the way we think to fit a Pythonic Way of structuring
that will help us with other portions of the language???


yes a bit of that.
More thinking about the intent - to process all items - than about  the 
how of the implementation - counting indexes up to the length.



pattern of it become more easily readable at a glance after we have
gotten used to it?)


That too, and also for other Python programmers.


--
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] Building Starships -- object of type 'int' has no len()

2014-08-17 Thread Marc Tompkins
On Sun, Aug 17, 2014 at 4:48 PM, Terry--gmail  wrote:
> WOW! There is a lot of help on this mailing list! I want to thank everyone
> for their valuable input! Thanks!  (I am working my way through the
> replies.)
>
> Sorry about the HTML. I think I have it turned off now in Thunderbirdy for
> this address. If so, then what follows should not be flat. If it is flat,
> please tell me.

It's not only flat, but appears in a confusing array of sizes and
styles - VERY SHOUTY bold 18-point for most of the text; 12.8 regular
for code; 15.8 regular for the text that appears after the code.  Hard
to read the prose, never mind that it wiped out the indentation of
your code.

>
> Mark:
>
> You commented on the non-Pythonic nature of my program. HA HA HA! I don't
> doubt it!

What I was getting at is a sort of feeling.  Taking the length of a
list, then using that length as the end value for range(), then
counting up to the end of that range to step through the list...  does
it not feel like you've got unnecessarily far from the subject at
hand?  The Pythonic way would be to step through the list itself - or,
if you must have a numeric index, to get it from enumerate()ing the
list.

As for a general theory of Pythonicity... it's a bit like all of those
Zen koans where a novice monk asks the master "Does (x) have
Buddha-nature?"  (Not _quite_ as impossible to grasp as that, though!)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-17 Thread Terry--gmail

I found another place in Thunderbirdy to set 'plain text'.

This is a test.

Does the below code look correct now?

--And did I reply correctly this time?  (Reply-All and keep only 
tutor@python.org address...)


for line_number, row in enumerate(catalog2):

for col, item in enumerate(row):

if lens[col] < len(item):

lens[col] = len(item)




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


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-17 Thread Marc Tompkins
On Sun, Aug 17, 2014 at 9:40 PM, Terry--gmail  wrote:
> I found another place in Thunderbirdy to set 'plain text'.
>
> This is a test.
>
> Does the below code look correct now?
>
> --And did I reply correctly this time?  (Reply-All and keep only
> tutor@python.org address...)
>
>
> for line_number, row in enumerate(catalog2):
>
> for col, item in enumerate(row):
>
> if lens[col] < len(item):
>
> lens[col] = len(item)

1)  It's plain text - no more funky font changes.
2)  Addressing is good.
3)  Indentation is still flat.

Ah well.  As Meat Loaf sang, two out of three ain't bad...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-17 Thread Marc Tompkins
On Sun, Aug 17, 2014 at 9:49 PM, Marc Tompkins  wrote:
> On Sun, Aug 17, 2014 at 9:40 PM, Terry--gmail  
> wrote:
>> I found another place in Thunderbirdy to set 'plain text'.
>>
>> This is a test.
>>
>> Does the below code look correct now?
>>
>> --And did I reply correctly this time?  (Reply-All and keep only
>> tutor@python.org address...)
>>
>>
>> for line_number, row in enumerate(catalog2):
>>
>> for col, item in enumerate(row):
>>
>> if lens[col] < len(item):
>>
>> lens[col] = len(item)
>
> 1)  It's plain text - no more funky font changes.
> 2)  Addressing is good.
> 3)  Indentation is still flat.

It just occurred to me: how are you indenting?  If you're using tabs,
that would explain the problem (TBird might be helpfully converting
tabs to newlines); in any case, the usual Python convention is to use
four spaces for indentation (it's pretty easy to set your text editor
to convert tabs to spaces on-the-fly, too.)
If you're already using spaces, please disregard.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-17 Thread Cameron Simpson

On 17Aug2014 22:40, Terry--gmail  wrote:

I found another place in Thunderbirdy to set 'plain text'.
This is a test.


You message is plain text now. Thank you!


Does the below code look correct now?

--And did I reply correctly this time?  (Reply-All and keep only 
tutor@python.org address...)


Basicly, yes!

This is sometimes a matter for debate.

In personal email I always reply-all (I never use the reply-only-to-author 
button), and then (rarely) prune the To/CC list of unwanted recipients.


On a mailing list it is always good to reply to the list unless you're 
departing wildly off topic. On some mailing lists it may be acceptable to CC 
the author (and possibly other individuals as they accrue in the to/cc lines).  

Many people would rather you replied only to the list (reply-all and prune, as 
you have done); that is always safe.


Some people prefer or accept replies that go to the list and also to others; by 
naming them individually it can make the message more visible in their mailer, 
depending on their personal arrangements. For me, for example, a message which 
CCs me specificly gets filed to the "python" folder and also my main inbox, so 
I will notice it more immediately.


As personal etiquette, these days I: reply-all, then remove everything except 
the list address unless there are already extra people in the To/CC.


Some mail programs have a "list-reply" function; I don't think Thunderbird is 
one of them.



for line_number, row in enumerate(catalog2):

for col, item in enumerate(row):

if lens[col] < len(item):

lens[col] = len(item)


The above code has no indentation. Was it indented when you wrote it?

Cheers,
Cameron Simpson 

Having been erased,
The document you're seeking
Must now be retyped.
- Haiku Error Messages 
http://www.salonmagazine.com/21st/chal/1998/02/10chal2.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-17 Thread Terry--gmail
I'm copy and pasting from Ninja-IDE, which I thought was created 
specifically to do python programming...so I never checked to see if it 
needs to have the tab set to enter 4 spaces, as it appeared visually to 
be doing that.  But, I don't remember whether I used their tab or 
manually typed 4 spaces. SO, I have typed the lines below in manually:


for line_number, row in enumerate(catalog2):
for col, item in enumerate(row):
if lens[col] < len(item):
lens[col] = len(item)

How's that?

--Terry




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


Re: [Tutor] Alert to all Experienced Python Software Object Oriented Programmers-Novice Needs Help In Understanding Textbook

2014-08-17 Thread Chris “Kwpolska” Warrick
On 18 August 2014 02:45 "ALAN GAULD"  wrote:
> > At the Community College we used Python version 3.4.0 which I guess is
up to date.
>
> Yes indeed, the latest and greatest.

The “latest and greatest” is actually 3.4.1.

-- 
Chris “Kwpolska” Warrick 
Sent from my SGS3.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor