[Baypiggies] line error on no. 7

Simeon Franklin simeonf at gmail.com
Wed Jul 29 00:40:31 CEST 2015

Hey Hal -

The errors in your code seem to me to come from trying to run before you
can walk. Let me give you one example of what should be going through your

>>> list.split()

Why doesn't this work? Well - you have to understand every individual piece
of this statement. Start with "list" - that's a builtin data type in
Python. The builtins are the things you automatically have access to
without importing. If you open a brand new python shell and type list
you'll see that list is already there!

$ python
>>> list
<type 'list'>

Next is the "." character. The dot is the attribute operator which allows
you to look inside the thing on the left for the thing on the right. The
thing on the left is the list type and the thing on the right is named
split. Lastly the line has parens "()" which is the call operator. This
implies that "split" is a thing in list and the kind of thing is something
you can call - a function or a method.

If I try to run this line of code I get an error:

>>> list.split()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'list' has no attribute 'split'

What this is telling me is that the list type has no attribute called
split. I could retrieve all the attributes by using another builtin "dir"
to verify that this is so:

>>> dir(list)
[... a bunch of  __ugly__ attributes and then... 'append', 'count',
'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

Aha! The list type has append, count, extend, index, insert, pop, remove,
reverse, sort methods. There is no split method on lists and that's why
this line of code crashes...

You might already know all this stuff but my impression is you are trying
to debug a program without understanding the basics - you don't know how to
solve your own problems yet because you don't have a firm understanding of
the basic syntax and concepts in python.

Don't feel bad! Everybody is there when they are learning a new language -
when I read Haskell code I spend a lot of time saying "I don't know have
any idea what this piece of punctuation even means!" But if you're not an
experienced developer it helps a lot to get a grounding in the basics of a
language before you try to solve problems with it.

I'd really recommend you try something like Learn Python the Hard Way - see
http://learnpythonthehardway.org/book/ for the free book. Work through each
chapter and don't skip any of the exercises. By the time you hit chapter 10
you ought to be able to complete the exercise you're working on right now
and understand each and every line...

I know it feels like a step back to review basic material instead of
working on your problem. But it might be more efficient in the long run -
I'm sure it feels frustrating to be blocked and waiting for email responses
from the list...

On Tue, Jul 28, 2015 at 1:14 PM, <ltc.hotspot at gmail.com> wrote:

>  Hi Everyone,
> I'm writing python code to read a data text file, split the file into a
> list of words using the split(function) and to print the results in
> alphabetical order.
> The raw python code is located at http://tinyurl.com/oua9uqx
> The sample data is located at
> http://tinyurl.com/odt9nhe
> Desired Output: ['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and',
> 'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'kill', 'light',
> 'moon', 'pale', 'sick', 'soft', 'sun', 'the', 'through', 'what', 'window',
> 'with', 'yonder']
> There is a line error on no. 7
> What is the cause of this error?
> Regards,
> Hal
> Sent from Surface
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> https://mail.python.org/mailman/listinfo/baypiggies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20150728/5ad77655/attachment-0001.html>

More information about the Baypiggies mailing list