[Tutor] problem with creating paths

Peter Otten __peter__ at web.de
Wed Oct 17 10:58:04 EDT 2018

Shall, Sydney via Tutor wrote:

> There are two items that are 'wrong' in this output.
> 1. The property 'paths' is defined in the program as a list and the
> items are added using paths.append(), yet the test says that when tested
> it is a tuple.

>>> paths = ["foo", "bar"],
>>> paths += "baz",  # ("baz",) leads to the same result
>>> paths
(['foo', 'bar'], 'baz')

This might happen if you have accidental trailing commas in two places, but 
that seems rather unlikely. Maybe you have a function with a star

def f(*args):
    ... # args is a tuple, even if you pass one argument or no arguments
        # to f().


> 2. The tuple arises by the addition of the last entry in the file, AFTER
> the closing bracket of the list which is the first item in the tuple.

Sorry, I don't understand that sentence.

> When I test the length of 'paths' I get a value of 2!

That's because you have a tuple with two entries, one list and one string.

> I apologise for the lengthy explanation, but I am at a loss.
> I have looked for an error that might have added an item as a + and I
> find nothing.
> The character of the final item is also puzzling to me.
> I would much appreciate any guidance as to how I should search for the
> fault or error.

Look at the assignments. If you find the pattern I mentioned above remove 
the commas. 

If you don't see anything suspicious make a test script containing only the 
manipulation of the paths variable. Make sure it replicates the behaviour of 
the bigger script; then show it to us.

More information about the Tutor mailing list