Найти - Пользователи
Полная версия: Типограф кавычек
Начало » Python для новичков » Типограф кавычек
1
Enchantner
Товарищи, подскажите типограф, позволяющий преобразовать обычные двойные кавычки (“”) в елочки («»). Обычный smartypants их не умеет, а самому писать велосипедно и лень.
mcnet
  def chg(text = None):
if (not text): return
counter = 0
for i in range(0, len(text)):
if (text[i] == '"'):
counter += 1
if (counter % 2 == 1):
text[i] = '«'
else:
text[i] = '»'

return text
kublo
А вы проверяли свой код ? Или строковый объект уже стал изменяемый ?
def chg(text = None):
if (not text): return
counter = 0
text = list(text)
for i in range(len(text)):
if (text[i] == '"'):
counter += 1
if (counter % 2 == 1):
text[i] = '«'
else:
text[i] = '»'

return ''.join(text)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB