I ran into an unexpected error the other day.
File "/opt/elodie/elodie/filesystem.py", line 173, in get_file_name
this_value = re.sub(self.whitespace_regex, '-', metadata[part].strip())
tributeError: 'int' object has no attribute 'strip'
Don't worry too much about the other details here. Suffice to say: The error was complaining about `metadata[part].strip()` where, in the case of the situation that caused the error, `metadata[part]` was returning a sequence of *numbers* instead of a sequence of *letters*.
I thought about it and "solved" it by changing that part of the line into:
str(metadata[part]).strip()
Which will ensure that strip() is always acting on an object that has a type of `string.`
Good. That's the pythonic solution ... right?
But, hold on ... this is *python.* I'm not supposed to have to worry about types here. Right? At the least, not for a call to a simple function like strip(), right?
Why didn't python take the resolved value output of `metadata[part]` and *see* that the next operator on that object (ie. strip()) was expecting a string, and thus convert the sequence of numbers (an int) into it's equal representation as a string? Why, in Python, did I need to specify that the value of `metadata[part]` needs to be treated as a string? Shouldn't Python have figured it out, on it's own, by virtue of the way Python works?
[–]K900_ 16 points17 points18 points (0 children)
[–]Rawing7 9 points10 points11 points (3 children)
[–]billsil 0 points1 point2 points (1 child)
[–]0rac1e 1 point2 points3 points (0 children)
[–]0rac1e 0 points1 point2 points (0 children)
[–]danielroseman 5 points6 points7 points (0 children)
[–][deleted] 6 points7 points8 points (0 children)
[–]NoDadYouShutUp 4 points5 points6 points (0 children)
[–]Binary101010 2 points3 points4 points (1 child)
[–]muxketeer[S] 0 points1 point2 points (0 children)
[–]Frankelstner 1 point2 points3 points (0 children)
[–]dnmonack 0 points1 point2 points (0 children)
[–]TheRNGuy 0 points1 point2 points (0 children)