The 'import' key in Zed's Learn Python the hard way Exercise 25
Question: I'm having trouble importing my code into the python interpreter (powershell).
I open python through powershell and when I type in "import ex24" simply
nothing appears, this is using the code I copy and pasted from his site (Just
to be sure):

    
    
    def break_words(stuff):
        """This function will break up words for us."""
        words = stuff.split(' ')
        return words
    
    def sort_words(words):
        """Sorts the words."""
        return sorted(words)
    
    def print_first_word(words):
        """Prints the first word after popping it off."""
        word = words.pop(0)
        print word
    
    def print_last_word(words):
        """Prints the last word after popping it off."""
        word = words.pop(-1)
        print word
    
    def sort_sentence(sentence):
        """Takes in a full sentence and returns the sorted words."""
        words = break_words(sentence)
        return sort_words(words)
    
    def print_first_and_last(sentence):
        """Prints the first and last words of the sentence."""
        words = break_words(sentence)
        print_first_word(words)
        print_last_word(words)
    
    def print_first_and_last_sorted(sentence):
        """Sorts the words then prints the first and last one."""
        words = sort_sentence(sentence)
        print_first_word(words)
        print_last_word(words)
    

When he executes it he gets this:

    
    
    >>> import ex25
    >>> sentence = "All good things come to those who wait."
    >>> words = ex25.break_words(sentence)
    >>> words
    ['All', 'good', 'things', 'come', 'to', 'those', 'who', 'wait.']
    >>> sorted_words = ex25.sort_words(words)
    >>> sorted_words
    ['All', 'come', 'good', 'things', 'those', 'to', 'wait.', 'who']
    >>> ex25.print_first_word(words)
    All
    >>> ex25.print_last_word(words)
    wait.
    >>> wrods
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'wrods' is not defined
    >>> words
    ['good', 'things', 'come', 'to', 'those', 'who']
    >>> ex25.print_first_word(sorted_words)
    All
    >>> ex25.print_last_word(sorted_words)
    who
    >>> sorted_words
    ['come', 'good', 'things', 'those', 'to', 'wait.']
    >>> sorted_words = ex25.sort_sentence(sentence)
    >>> sorted_words
    ['All', 'come', 'good', 'things', 'those', 'to', 'wait.', 'who']
    >>> ex25.print_first_and_last(sentence)
    All
    wait.
    >>> ex25.print_first_and_last_sorted(sentence)
    All
    who
    

Also, when I manually type out the code like I usually do, I get this error. I
can't to seem what mistake I made:

> > > import ex25 Traceback (most recent call last): File "", line 1, in File
> "ex25.py", line 1 SyntaxError: Non-ASCII character '\xff' in file ex25.py on
> line 1, but no encoding declared; eps/pep-0263.html for details

This is my manual copy (ex25):

    
    
    def break_words(stuff):
        """This function will break up words for us."""
        words = stuff.split('  ')
        return words
    
    def sort_words(words):
        """Sorts the words"""
        return sorted (words)
    
    def print_first_word(words):
        """Prints the first word after popping it off"""
        word = words.pop(0)
        print word
    
    def print_last_word(words):
        """Prints the last word after popping it off"""
        word = words.pop(-1)
        print word
    
    def sort_sentence(sentence):
        """Takes in a full sentence and returns the sorted words."""
        words = break_words(sentence)
        return sort_words(words)
    
    def print_first_and_last(sentence):
        """Prints the first and last words of the sentence."""
        words = break_words(sentence)
        print_first_word(words)
        print_last_word(words)
    
    def print_first_and_last_sorted(sentence):
        """Sorts the words then prints the first and last one."""
        words = sort_sentence(sentence)
        print_first_word(words)
        print_last_word(words)
    


Answer: Seems like your editor is putting a
[BOM](https://en.wikipedia.org/wiki/Byte_order_mark) at the file start. These
marks are invisible in many editors.

BOM makes no sense in UTF-8, so just **set your editor for saving in "unicode
without BOM"** or equivalent (should be somewhere in `settings` or
`preferences`).

> The byte order mark (BOM) is a Unicode character used to signal the
> endianness (byte order) of a text file or stream. It is encoded at U+FEFF
> byte order mark (BOM). BOM use is optional, and, if used, should appear at
> the start of the text stream.

In UTF-16 or UTF-32, the 16 or 32 bit units may be represented in [big-
endian](https://en.wikipedia.org/wiki/Endianess) or [little-
endian](https://en.wikipedia.org/wiki/Endianess) byte order, depending on the
platform.

Since UTF-8 is stored in bytes and bytes are the same in every platform,
signaling the endianness is useless. Why the Unicode Standard permits the BOM
in UTF-8 - and worst yet, why some editors do it if not required nor
recommended, is beyond my reach (dumb and dumber).

