[Python-ideas] PEP 315: do-while
Ethan Furman
ethan at stoneleaf.us
Thu Jun 27 01:40:52 CEST 2013
On 06/26/2013 04:25 PM, Joshua Landau wrote:
> On 27 June 2013 00:17, Andrew Barnert <abarnert at yahoo.com> wrote:
>>
>> In case it's not obvious how ridiculous it is to extrapolate MISRA-C to other languages…
>>
>> I went through the 127 rules in MISRA-C 1998. About 52 of them could be extrapolated to Python. Of those, 20 make some sense; the other 32 would be either ridiculous or disastrous to apply in Python. (In fact, much the same is true even for more closely-related languages like C++ or JavaScript.)
>>
>> If you're curious about the details, see http://stupidpythonideas.blogspot.com/2013/06/misra-c-and-python.html.
>
> "67. rcm: Don't rebind the iterator in a for loop."
>
> That sounds quite sane to me...
def NameCase(*names):
'''names should already be stripped of whitespace'''
if not any(names):
return names
final = []
for name in names:
pieces = name.lower().split()
result = []
for i, piece in enumerate(pieces):
if '-' in piece:
piece = ' '.join(piece.replace('-',' ').split())
piece = '-'.join(NameCase(piece).split())
elif alpha_num(piece) in ('i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix', 'x'):
piece = piece.upper()
elif piece in ('and', 'de', 'del', 'der', 'el', 'la', 'van', 'of'):
pass
elif piece[:2] == 'mc':
piece = 'Mc' + piece[2:].title()
else:
possible = mixed_case_names.get(piece, None)
if possible is not None:
piece = possible
else:
piece = piece.title()
if piece[-2:].startswith("'"):
piece = piece[:-1] + piece[-1].lower()
result.append(piece)
if result[0] == result[0].lower():
result[0] = result[0].title()
if result[-1] == result[-1].lower():
result[-1] = result[-1].title()
final.append(' '.join(result))
return final
--
~Ethan~
More information about the Python-ideas
mailing list