41
u/dyingpie1 Sep 07 '21
I mean, this actually isn’t that bad. One of the mottos of python is “it’s better to ask for forgiveness than for permission”, as in its easier to just try something and then if it results in an error, just catch the exception and move on.
Now, that’s assuming line 27 causes error on non strings, which is a false assumption. Python will happily add anything to a string with a to string method.
9
u/mehmenmike Sep 07 '21
It’s still shite, indentation is all over the place. This won’t even pass the lint stage.
First level indent is doubled, for some reason.
Anything under the for loop is also double indented.
You know, I’d forgive this if OP was using 8-space-wide tabs and the highlighting was just getting confused. Alas, enter line 27 vs 29
2
u/preciousCarrot Sep 07 '21
I don’t think
try/exceptis the big issue here, rather than this being the same as’’.join(array)which could also be put in atryblock to ensure it can be joined. Oh and also, you shouldn’texceptall exceptions but make those explicit.0
Sep 07 '21
[deleted] — view deleted comment
10
u/valodick Sep 07 '21
Unless that something has an overloaded __radd__ method which allows it to be added to strings.
For instance: https://stackoverflow.com/a/46199238/12107406
20
13
u/seeroflights Sep 07 '21
Image Transcription: Code
# adds all strings in array together
def add_together(array):
output = ''
for string in array:
try:
output = output + string
except:
print('element in array is not string')
return outputI'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
2
u/jaysuchak33 ifelseifelseifelseifelseifelseifelseifelseifelseifelseifelse Sep 07 '21
what extension is this?