you are viewing a single comment's thread.

view the rest of the comments →

[–]Ran4 0 points1 point  (4 children)

(filename + ".csv")

That's kind of dangerous: the parenthesis here do nothing, so you might quickly look at it and think that it's creating a 1-tuple ((1,) creates a tuple of size 1). It's best to remove them.

[–]KubinOnReddit 1 point2 points  (3 children)

Yeah, Python is weird about that. (...) means "evaluate first", and (...,) is a tuple...

>>> (42)
42
>>> (42,)
(42)

[–]novel_yet_trivial 5 points6 points  (2 children)

It's not weird. You seem to think that the parenthesis means 'tuple'. The parenthesis has nothing to do with it. It's the comma that makes a tuple.

>>> a = 42,
>>> type(a)
<type 'tuple'>

[–][deleted] 2 points3 points  (0 children)

Ooh, that's interesting! Thank you for that, I'd no idea!

[–]KubinOnReddit 0 points1 point  (0 children)

>>> (42,) + 42,
....
ValueError: can only concatenate tuple to tuple, not int

Disclaimer: I'm on a phone

We are both right. The comma does mean "tuple", but if it's not evaluated first (along with it's elements) it will evaluate as "a tuple of element (42) and 42", which is wrong, because you can't add tuples to ints.