So I am trying to switch to PEP8 notation (from a rather personal CamelCase notation) and I was wondering how you guys are tackling the cases where existing functions/variables would be overwritten?
e.g. having something like:
open, high, low, close, sum = row
would already overwrite the "open" and "sum" functions. First, if I wouldn't use a good IDE, I wouldn't even notice that I've just overwritten important basic functions. Second, how would you name the variables instead? In this example I would have used apps hungarian and wouldn't have encountered any potential problem at all.
Thanks!
If they are all values from the same domain, you can use a dictionary:
Then you can access them directly:
val['open']
. You can iterate over themval.iteritems()
and so on.I would use
open_
andsum_
.Pep8 recommends using trailing underscore, however there is also mentioned that in possible cases using synonym word for the variable would be better idea.
Why not just pick non-conflicting names? Such as
opening_price
,closing_price
andtotal
if that's what they represent. While it's possible to qualify the namespace as in the other replies, surely that shouldn't be needed for local variables. Whatever language you program in it's your job to know the reserved words; there aren't that many of them.In this particular case, I'd use a
namedtuple
. This would turn those names into qualified ones (data.open
,data.low
, etc.).This would eliminate the prospect of name clashes with built-in functions, and likely improve the overall readability along the way.