<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2793531</guid>
        <pubDate>Sun, 02 Jan 2011 10:22:36 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2793531</link>
        <description><![CDATA[Ho Im: Какая сказочная бредятина космического масштаба.<br><br>А для Фаренгейта мы вместо &quot;-&gt;&gt;&quot; сделаем &quot;&gt;-(**)-&lt;&quot; (оператор-крабе). Просто чтобы жизнь малиной не казалась (и чтобы нанотехнологии прославить, оператор «шмеле» еще надо придумать).<br><br>И не дай Бог надо из Фаренгейта в Реомюра перевести, потому что мы умеем только из Фаренгейта в Цельсия, а из Реомюра только в Ромера, а из Ромера только в Ньютона...]]></description>
        <author>Ho Im</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2793528</guid>
        <pubDate>Sun, 02 Jan 2011 10:19:03 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2793528</link>
        <description><![CDATA[amk: Во-первых, у тебя неправильный сдвиг шкал градусы Кельвина - градусы Цельсия<br>Вдобавок, для Фаренгейта придется, кроме сдвига шкал еще и масштаб придется менять так что твой конструктор функций не сработает, придется новый писать.<br>Шкала Реомюра не помню чем отличается - слишком старая.<br>То, что ты предложил, еще хуже чем мультиметоды. Тебе в каждом месте придется ручками вписывать из каких конкретно единиц в какие другие единицы ты собираешься преобразовывать, и никакой проверки при этом.]]></description>
        <author>amk</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2793486</guid>
        <pubDate>Sun, 02 Jan 2011 06:43:48 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2793486</link>
        <description><![CDATA[Vadim11: Зачем к лопате приделывать грабли и вилы - работать не удобно.<br>Лучше разделять, примерно так:<br><br>def make_inc(t): return lambda x,y=t: x+t<br>cel2kel = make_inc(237) # Цельсий-Кельвин<br>kel2cel = make_inc(-237) # Кельвин-Цельсий<br><br>Можно обобщить (хотя это не есть хорошо)<br>def CelKel(s,t): <br>    if s == &quot;-&gt;&gt;&quot;: return cel2kel(t)<br>    if s == &quot;&lt;&lt;-&quot;: return kel2cel(t)<br>Так же можно сделать для других шкал, например для Фаренгейта или Руомера.]]></description>
        <author>Vadim11</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2793191</guid>
        <pubDate>Sat, 01 Jan 2011 09:26:54 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2793191</link>
        <description><![CDATA[Мяут-Настоящий: Может ребят вы в холивары?  :)]]></description>
        <author>Мяут-Настоящий</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2793102</guid>
        <pubDate>Sat, 01 Jan 2011 00:51:37 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2793102</link>
        <description><![CDATA[Ho Im: Как пример, можно себе представить задачу с конвертированием символов из одной кодировки в другую. В прошлом веке, когда юникод был экзотикой или даже до того, каждый русскоязычный компьютерщик рано или поздно постигал, что такое Codepage 866, 1125, 1251, KOI8-R/U, ISO8859-5. Сейчас это не так актуально, но все же необходимость перекодировывать тексты из и в случается. У нас в юниксах для этого есть утилиты iconv и recode, какую использовать — дело вкуса и религии, но.<br>
<br>
Вот что говорит мне iconv, когда я прошу вывести список поддерживаемых кодировок.<br>
<br>
<div class="tag-spoiler spoiler closed"><div class="spoiler_header" onclick="openCloseParent(this)">Сразу говорю, там 143 кодировки</div><div class="body">ANSI_X3.4-1968 ANSI_X3.4-1986 ASCII CP367 IBM367 ISO-IR-6 ISO646-US ISO_646.IRV:1991 US US-ASCII CSASCII<br>
UTF-8<br>
UTF-8-MAC UTF8-MAC<br>
ISO-10646-UCS-2 UCS-2 CSUNICODE<br>
UCS-2BE UNICODE-1-1 UNICODEBIG CSUNICODE11<br>
UCS-2LE UNICODELITTLE<br>
ISO-10646-UCS-4 UCS-4 CSUCS4<br>
UCS-4BE<br>
UCS-4LE<br>
UTF-16<br>
UTF-16BE<br>
UTF-16LE<br>
UTF-32<br>
UTF-32BE<br>
UTF-32LE<br>
UNICODE-1-1-UTF-7 UTF-7 CSUNICODE11UTF7<br>
UCS-2-INTERNAL<br>
UCS-2-SWAPPED<br>
UCS-4-INTERNAL<br>
UCS-4-SWAPPED<br>
C99<br>
JAVA<br>
CP819 IBM819 ISO-8859-1 ISO-IR-100 ISO8859-1 ISO_8859-1 ISO_8859-1:1987 L1 LATIN1 CSISOLATIN1<br>
ISO-8859-2 ISO-IR-101 ISO8859-2 ISO_8859-2 ISO_8859-2:1987 L2 LATIN2 CSISOLATIN2<br>
ISO-8859-3 ISO-IR-109 ISO8859-3 ISO_8859-3 ISO_8859-3:1988 L3 LATIN3 CSISOLATIN3<br>
ISO-8859-4 ISO-IR-110 ISO8859-4 ISO_8859-4 ISO_8859-4:1988 L4 LATIN4 CSISOLATIN4<br>
CYRILLIC ISO-8859-5 ISO-IR-144 ISO8859-5 ISO_8859-5 ISO_8859-5:1988 CSISOLATINCYRILLIC<br>
ARABIC ASMO-708 ECMA-114 ISO-8859-6 ISO-IR-127 ISO8859-6 ISO_8859-6 ISO_8859-6:1987 CSISOLATINARABIC<br>
ECMA-118 ELOT_928 GREEK GREEK8 ISO-8859-7 ISO-IR-126 ISO8859-7 ISO_8859-7 ISO_8859-7:1987 ISO_8859-7:2003 CSISOLATINGREEK<br>
HEBREW ISO-8859-8 ISO-IR-138 ISO8859-8 ISO_8859-8 ISO_8859-8:1988 CSISOLATINHEBREW<br>
ISO-8859-9 ISO-IR-148 ISO8859-9 ISO_8859-9 ISO_8859-9:1989 L5 LATIN5 CSISOLATIN5<br>
ISO-8859-10 ISO-IR-157 ISO8859-10 ISO_8859-10 ISO_8859-10:1992 L6 LATIN6 CSISOLATIN6<br>
ISO-8859-11 ISO8859-11 ISO_8859-11<br>
ISO-8859-13 ISO-IR-179 ISO8859-13 ISO_8859-13 L7 LATIN7<br>
ISO-8859-14 ISO-CELTIC ISO-IR-199 ISO8859-14 ISO_8859-14 ISO_8859-14:1998 L8 LATIN8<br>
ISO-8859-15 ISO-IR-203 ISO8859-15 ISO_8859-15 ISO_8859-15:1998 LATIN-9<br>
ISO-8859-16 ISO-IR-226 ISO8859-16 ISO_8859-16 ISO_8859-16:2001 L10 LATIN10<br>
KOI8-R CSKOI8R<br>
KOI8-U<br>
KOI8-RU<br>
CP1250 MS-EE WINDOWS-1250<br>
CP1251 MS-CYRL WINDOWS-1251<br>
CP1252 MS-ANSI WINDOWS-1252<br>
CP1253 MS-GREEK WINDOWS-1253<br>
CP1254 MS-TURK WINDOWS-1254<br>
CP1255 MS-HEBR WINDOWS-1255<br>
CP1256 MS-ARAB WINDOWS-1256<br>
CP1257 WINBALTRIM WINDOWS-1257<br>
CP1258 WINDOWS-1258<br>
850 CP850 IBM850 CSPC850MULTILINGUAL<br>
862 CP862 IBM862 CSPC862LATINHEBREW<br>
866 CP866 IBM866 CSIBM866<br>
CP1131<br>
MAC MACINTOSH MACROMAN CSMACINTOSH<br>
MACCENTRALEUROPE<br>
MACICELAND<br>
MACCROATIAN<br>
MACROMANIA<br>
MACCYRILLIC<br>
MACUKRAINE<br>
MACGREEK<br>
MACTURKISH<br>
MACHEBREW<br>
MACARABIC<br>
MACTHAI<br>
HP-ROMAN8 R8 ROMAN8 CSHPROMAN8<br>
NEXTSTEP<br>
ARMSCII-8<br>
GEORGIAN-ACADEMY<br>
GEORGIAN-PS<br>
KOI8-T<br>
CP154 CYRILLIC-ASIAN PT154 PTCP154 CSPTCP154<br>
KZ-1048 RK1048 STRK1048-2002 CSKZ1048<br>
MULELAO-1<br>
CP1133 IBM-CP1133<br>
ISO-IR-166 TIS-620 TIS620 TIS620-0 TIS620.2529-1 TIS620.2533-0 TIS620.2533-1<br>
CP874 WINDOWS-874<br>
VISCII VISCII1.1-1 CSVISCII<br>
TCVN TCVN-5712 TCVN5712-1 TCVN5712-1:1993<br>
ISO-IR-14 ISO646-JP JIS_C6220-1969-RO JP CSISO14JISC6220RO<br>
JISX0201-1976 JIS_X0201 X0201 CSHALFWIDTHKATAKANA<br>
ISO-IR-87 JIS0208 JIS_C6226-1983 JIS_X0208 JIS_X0208-1983 JIS_X0208-1990 X0208 CSISO87JISX0208<br>
ISO-IR-159 JIS_X0212 JIS_X0212-1990 JIS_X0212.1990-0 X0212 CSISO159JISX02121990<br>
CN GB_1988-80 ISO-IR-57 ISO646-CN CSISO57GB1988<br>
CHINESE GB_2312-80 ISO-IR-58 CSISO58GB231280<br>
CN-GB-ISOIR165 ISO-IR-165<br>
ISO-IR-149 KOREAN KSC_5601 KS_C_5601-1987 KS_C_5601-1989 CSKSC56011987<br>
EUC-JP EUCJP EXTENDED_UNIX_CODE_PACKED_FORMAT_FOR_JAPANESE CSEUCPKDFMTJAPANESE<br>
MS_KANJI SHIFT-JIS SHIFT_JIS SJIS CSSHIFTJIS<br>
CP932<br>
ISO-2022-JP CSISO2022JP<br>
ISO-2022-JP-1<br>
ISO-2022-JP-2 CSISO2022JP2<br>
CN-GB EUC-CN EUCCN GB2312 CSGB2312<br>
GBK<br>
CP936 MS936 WINDOWS-936<br>
GB18030<br>
ISO-2022-CN CSISO2022CN<br>
ISO-2022-CN-EXT<br>
HZ HZ-GB-2312<br>
EUC-TW EUCTW CSEUCTW<br>
BIG-5 BIG-FIVE BIG5 BIGFIVE CN-BIG5 CSBIG5<br>
CP950<br>
BIG5-HKSCS:1999<br>
BIG5-HKSCS:2001<br>
BIG5-HKSCS BIG5-HKSCS:2004 BIG5HKSCS<br>
EUC-KR EUCKR CSEUCKR<br>
CP949 UHC<br>
CP1361 JOHAB<br>
ISO-2022-KR CSISO2022KR<br>
CP856<br>
CP922<br>
CP943<br>
CP1046<br>
CP1124<br>
CP1129<br>
CP1161 IBM-1161 IBM1161 CSIBM1161<br>
CP1162 IBM-1162 IBM1162 CSIBM1162<br>
CP1163 IBM-1163 IBM1163 CSIBM1163<br>
DEC-KANJI<br>
DEC-HANYU<br>
437 CP437 IBM437 CSPC8CODEPAGE437<br>
CP737<br>
CP775 IBM775 CSPC775BALTIC<br>
852 CP852 IBM852 CSPCP852<br>
CP853<br>
855 CP855 IBM855 CSIBM855<br>
857 CP857 IBM857 CSIBM857<br>
CP858<br>
860 CP860 IBM860 CSIBM860<br>
861 CP-IS CP861 IBM861 CSIBM861<br>
863 CP863 IBM863 CSIBM863<br>
CP864 IBM864 CSIBM864<br>
865 CP865 IBM865 CSIBM865<br>
869 CP-GR CP869 IBM869 CSIBM869<br>
CP1125<br>
EUC-JIS-2004 EUC-JISX0213<br>
SHIFT_JIS-2004 SHIFT_JISX0213<br>
ISO-2022-JP-2004 ISO-2022-JP-3<br>
BIG5-2003<br>
ISO-IR-230 TDS565<br>
ATARI ATARIST<br>
RISCOS-LATIN1</div></div><br>
<br>
В общем и целом предлагаю охватить масштабность проекта «конвертор из любой кодировки в любую» на мультиметодах. Если исключить варианты «в самого себя», получим 20306 методов. Возможно, если автор — рантье и ему не надо работать, чтобы себя кормить, он сможет до пенсии это написать, правда, кому оно надо, еще вопрос.<br>
<br>
Ну и появление новой кодировки — это неизменный facepalm для любителя мультиметодов.]]></description>
        <author>Ho Im</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2792749</guid>
        <pubDate>Fri, 31 Dec 2010 14:59:49 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2792749</link>
        <description><![CDATA[amk: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2792694'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>korvin &#064; <time class="tag-quote__quoted-time" datetime="2010-12-31T11:53:02+00:00">31.12.10, 11:53</time></span><div class='quote '>ой ли?</div></div><br>
Ну смотри, если у тебя есть десяток конвертируемых вариантов, то тебе нужно написать 100 (&#33;) мультиметодов, включая десяток тривиальных. Для варианта исходный-основа-итоговый только 20, и из них только 2 тривиальных для основного варианта.<br>
При добавлении еще одного варианта в случае мультиметода тебе придется написать еще 21 конвертор (1 тривиальный), а для варианта исходный-основа-итог только два - для нового варианта.<br>
Работать будет может быть чуть медленнее, но зато куда проще сопровождать.]]></description>
        <author>amk</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2792694</guid>
        <pubDate>Fri, 31 Dec 2010 11:53:02 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2792694</link>
        <description><![CDATA[korvin: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2791924'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>amk &#064; <time class="tag-quote__quoted-time" datetime="2010-12-30T11:44:27+00:00">30.12.10, 11:44</time></span><div class='quote '><div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2791412'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>korvin &#064; <time class="tag-quote__quoted-time" datetime="2010-12-29T17:57:56+00:00">29.12.10, 17:57</time></span><div class='quote '>мне вообще мультиметоды больше нравятся</div></div> Только вот именно в этой задаче пара конверторов из/в работает и сопровождается лучше.</div></div><br>
ой ли? <br>
<br>
<span class="tag-color tag-color-named" data-value="gray" style="color: gray"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2010-12-31T11:56:40+00:00">31.12.10, 11:56</time></span></span><br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2791488'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Lumberjack &#064; <time class="tag-quote__quoted-time" datetime="2010-12-29T23:31:42+00:00">29.12.10, 23:31</time></span><div class='quote '>Ты можешь не заморачиваться и воспользоваться непечатаемыми символами Юникода чтобы не нагромождать пробелами или табами текст. А вообще по сути ты рассуждаешь не как программист а как капризный пацан, реально метод предложенный Ho Im я поддерживаю, т.к он во всех книгах написан и еще ни один учебник мне не показал что нужно &quot;принтить&quot;. Да прибудет с тобой сила Any key</div></div><br>
я как бы стараюсь придерживаться отступов, выпирающие строки выглядят просто ужасно. я не знаком с питоном, но меня бы вполне устроил вариант а ля:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">...</div><div class="code_line">&nbsp;&nbsp; &nbsp;...</div><div class="code_line">&nbsp;&nbsp; &nbsp;...</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;print</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;abcde&quot;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;fghij&quot;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;klmno&quot;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;...</div><div class="code_line">&nbsp;&nbsp; &nbsp;...</div><div class="code_line">...</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script> <br>
<br>
<span class="tag-color tag-color-named" data-value="gray" style="color: gray"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2010-12-31T11:58:42+00:00">31.12.10, 11:58</time></span></span><br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2792321'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Dark_Sup &#064; <time class="tag-quote__quoted-time" datetime="2010-12-30T19:36:26+00:00">30.12.10, 19:36</time></span><div class='quote '>Дык на то нам дана подсветка кода&#33; :-?  У меня на этих &quot;длинных строках&quot; глаз даже не задерживается.</div></div><br>
а меня жутко раздражает, независимо от подцветки. вообще полагаться на подцветку при написании кода -- не очень здравая затея.]]></description>
        <author>korvin</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2792321</guid>
        <pubDate>Thu, 30 Dec 2010 19:36:26 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2792321</link>
        <description><![CDATA[Dark_Sup: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2791412'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>korvin &#064; <time class="tag-quote__quoted-time" datetime="2010-12-29T17:57:56+00:00">29.12.10, 17:57</time></span><div class='quote '>а мне не нравится портить форматирование кода &quot;многострочными строками&quot;,</div></div><br>
Дык на то нам дана подсветка кода&#33; :-?  У меня на этих &quot;длинных строках&quot; глаз даже не задерживается.<br>
<br>
Кстати, функции в таблице по ключу - прикольно... возьму на вооружение.  :)]]></description>
        <author>Dark_Sup</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2792005</guid>
        <pubDate>Thu, 30 Dec 2010 13:14:03 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2792005</link>
        <description><![CDATA[amk: Эта проблема - преобразование из всего во все иногда встречается и в реальной работе. Почему бы не выделить ее в отдельную задачу?]]></description>
        <author>amk</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2791957</guid>
        <pubDate>Thu, 30 Dec 2010 12:25:26 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2791957</link>
        <description><![CDATA[Мяут-Настоящий: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2791924'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>amk &#064; <time class="tag-quote__quoted-time" datetime="2010-12-30T11:44:27+00:00">30.12.10, 11:44</time></span><div class='quote '>Только вот именно в этой задаче пара конверторов из/в работает и сопровождается лучше. </div></div><br>
Это можно назвать задачей?  :huh:]]></description>
        <author>Мяут-Настоящий</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2791924</guid>
        <pubDate>Thu, 30 Dec 2010 11:44:27 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2791924</link>
        <description><![CDATA[amk: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2791412'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>korvin &#064; <time class="tag-quote__quoted-time" datetime="2010-12-29T17:57:56+00:00">29.12.10, 17:57</time></span><div class='quote '>мне вообще мультиметоды больше нравятся</div></div> Только вот именно в этой задаче пара конверторов из/в работает и сопровождается лучше.]]></description>
        <author>amk</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2791488</guid>
        <pubDate>Wed, 29 Dec 2010 23:31:42 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2791488</link>
        <description><![CDATA[Lumberjack: Ты можешь не заморачиваться и воспользоваться непечатаемыми символами Юникода чтобы не нагромождать пробелами или табами текст. А вообще по сути ты рассуждаешь не как программист а как капризный пацан, реально метод предложенный Ho Im я поддерживаю, т.к он во всех книгах написан и еще ни один учебник мне не показал что нужно &quot;принтить&quot;. Да прибудет с тобой сила Any key]]></description>
        <author>Lumberjack</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2791412</guid>
        <pubDate>Wed, 29 Dec 2010 17:57:56 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2791412</link>
        <description><![CDATA[korvin: ну вот, заодно и я может питон изучу =) <br>
<br>
<span class="tag-color tag-color-named" data-value="gray" style="color: gray"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2010-12-29T18:00:13+00:00">29.12.10, 18:00</time></span></span><br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2787743'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Ho Im &#064; <time class="tag-quote__quoted-time" datetime="2010-12-23T20:24:13+00:00">23.12.10, 20:24</time></span><div class='quote '>А вообще путь настоящих джедаев — это таблица конверсий всего в кельвины и из кельвинов во все. Таким образом можно избежать комбинаторного взрыва при попытки создать таблицы перевода из всего во все.</div></div><br>
мне вообще мультиметоды больше нравятся <br>
<br>
<span class="tag-color tag-color-named" data-value="gray" style="color: gray"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2010-12-29T18:04:45+00:00">29.12.10, 18:04</time></span></span><br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2788444'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Ho Im &#064; <time class="tag-quote__quoted-time" datetime="2010-12-25T10:29:22+00:00">25.12.10, 10:29</time></span><div class='quote '>Тем более. Меня просто один вид шести подряд идущих print&#39;ов покоробил, помню, на одной из прошлых работ за подобное за горло брали и канделябрами били.</div></div><br>
а мне не нравится портить форматирование кода &quot;многострочными строками&quot;, впрочем может я не знаю, но как поступать в этом случае:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">...</div><div class="code_line">...</div><div class="code_line">&nbsp;&nbsp; &nbsp;...</div><div class="code_line">&nbsp;&nbsp; &nbsp;...</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;print &quot;&quot;&quot;abcdef</div><div class="code_line">ghjklm</div><div class="code_line">nopqrs</div><div class="code_line">tuvwxyz&quot;&quot;&quot;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;...</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;...</div><div class="code_line">&nbsp;&nbsp; &nbsp;...</div><div class="code_line">...</div></ol></div></div></div></div><br>
?]]></description>
        <author>korvin</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2788444</guid>
        <pubDate>Sat, 25 Dec 2010 10:29:22 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2788444</link>
        <description><![CDATA[Ho Im: Тем более. Меня просто один вид шести подряд идущих print&#39;ов покоробил, помню, на одной из прошлых работ за подобное за горло брали и канделябрами били.]]></description>
        <author>Ho Im</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2788431</guid>
        <pubDate>Sat, 25 Dec 2010 09:33:12 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2788431</link>
        <description><![CDATA[Мяут-Настоящий: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2787743'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Ho Im &#064; <time class="tag-quote__quoted-time" datetime="2010-12-23T20:24:13+00:00">23.12.10, 20:24</time></span><div class='quote '>Современные ребята делают так:</div></div><br>
Я тут узнал, что современные ребята делают так:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&nbsp;&nbsp; &nbsp;parser = OptionParser()</div><div class="code_line">&nbsp;&nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;parser.add_option(&#39;-d&#39;, &#39;--directory&#39;, action=&quot;store&quot;, </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;type=&quot;string&quot;, dest=&quot;directory&quot;, metavar=&#39;DIR&#39;,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;help=&#39;Explorer directory path&#39;)</div><div class="code_line">&nbsp;&nbsp; &nbsp;parser.add_option(&#39;-t&#39;, &#39;--tar-file&#39;, action=&quot;store&quot;, </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;type=&quot;string&quot;, dest=&quot;tarfile&quot;, metavar=&#39;TARFILE&#39;,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;help=&#39;Explorer tar file path&#39;)</div><div class="code_line">&nbsp;&nbsp; &nbsp;parser.add_option(&#39;-c&#39;, &#39;--config&#39;, action=&quot;store&quot;, </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;type=&quot;string&quot;, dest=&quot;config&quot;, metavar=&#39;CONFIG&#39;,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;help=&#39;Explorer analyzer configuration file&#39;)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;(options, args) = parser.parse_args()</div></ol></div></div></div></div><br>
<br>
И не парятся :D]]></description>
        <author>Мяут-Настоящий</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2788374</guid>
        <pubDate>Sat, 25 Dec 2010 03:51:02 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2788374</link>
        <description><![CDATA[Lumberjack: Ho Im, жжошь :D]]></description>
        <author>Lumberjack</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2787743</guid>
        <pubDate>Thu, 23 Dec 2010 20:24:13 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2787743</link>
        <description><![CDATA[Ho Im: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2688490'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>korvin &#064; <time class="tag-quote__quoted-time" datetime="2010-09-05T07:39:50+00:00">05.09.10, 07:39</time></span><div class='quote '>print &gt;&gt; sys.stderr, &#39;wrong integer: %s&#39; % arg</div></div><br>
<br>
Современные ребята делают так:<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">sys.stderr.wrtite(&quot;Wrong integer: {0}\n&quot;.format(arg))</div></ol></div></div></div></div><br>
<br>
<div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <div class='quote '><div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">def usage():</div><div class="code_line">&nbsp;&nbsp; &nbsp; print &#39;usage:&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp; print &#39;\t-h, &nbsp; &nbsp; --help &nbsp; &nbsp; \tprint usage summary&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp; print &#39;\t &nbsp; &nbsp; &nbsp; &nbsp;--modes &nbsp; &nbsp;\tprint available modes&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp; print &#39;\t-d &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \tshow debugging information while running&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp; print &#39;\t-m &#60;m&#62;, --mode=&#60;m&#62; \tuse &#60;m&#62; as conversion mode&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp; print &#39;\t-t &#60;t&#62;, --temp=&#60;t&#62; \tuse &#60;t&#62; as temperature to convert&#39;</div></ol></div></div></div></div></div></div><br>
<br>
За это убивают. На каждую строчку print? Помилуйте, это же не GW-BASIC&#33;<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">def usage():</div><div class="code_line">&nbsp;&nbsp; &nbsp;usage = &quot;&quot;&quot;Usage:</div><div class="code_line">&nbsp;&nbsp; &nbsp;-h, --help print this message</div><div class="code_line">&nbsp;&nbsp; &nbsp;--modes &nbsp; &nbsp;print available modes</div><div class="code_line">&nbsp;&nbsp; &nbsp;-d &nbsp; &nbsp; &nbsp; &nbsp; show debugging information while running</div><div class="code_line">&nbsp;&nbsp; &nbsp;-m MODE, --mode=MODE</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; use MODE as conversion mode</div><div class="code_line">&nbsp;&nbsp; &nbsp;-t TEMP, --temp=TEMP</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; use TEMP as temperature to convert</div><div class="code_line">&nbsp;&nbsp; &nbsp;\n&quot;&quot;&quot;</div><div class="code_line">&nbsp;&nbsp; &nbsp;sys.stdout.write(usage)</div></ol></div></div></div></div> <br>
<br>
<span class="tag-color tag-color-named" data-value="gray" style="color: gray"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2010-12-23T20:28:18+00:00">23.12.10, 20:28</time></span></span><br>
А вообще путь настоящих джедаев — это таблица конверсий всего в кельвины и из кельвинов во все. Таким образом можно избежать комбинаторного взрыва при попытки создать таблицы перевода из всего во все.<br>
<br>
И тогда режим задается как:<br>
tempconv --from F --to C 100]]></description>
        <author>Ho Im</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2787736</guid>
        <pubDate>Thu, 23 Dec 2010 20:08:43 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2787736</link>
        <description><![CDATA[Мяут-Настоящий: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2787572'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>purpe &#064; <time class="tag-quote__quoted-time" datetime="2010-12-23T15:11:47+00:00">23.12.10, 15:11</time></span><div class='quote '>А какова цель ? </div></div><br>
Выучить питон  :tong:]]></description>
        <author>Мяут-Настоящий</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2787628</guid>
        <pubDate>Thu, 23 Dec 2010 16:36:09 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2787628</link>
        <description><![CDATA[Ho Im: Ты не поверишь: рубить капусту.]]></description>
        <author>Ho Im</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2787572</guid>
        <pubDate>Thu, 23 Dec 2010 15:11:47 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2787572</link>
        <description><![CDATA[purpe: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2668059'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Мяут&#045;Настоящий &#064; <time class="tag-quote__quoted-time" datetime="2010-08-12T20:10:20+00:00">12.08.10, 20:10</time></span><div class='quote '>Учу питон</div></div><br>
А какова цель ?]]></description>
        <author>purpe</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2688490</guid>
        <pubDate>Sun, 05 Sep 2010 07:39:50 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2688490</link>
        <description><![CDATA[korvin: вобщем, я бы сделал так:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#!/usr/bin/python</div><div class="code_line"># -*- coding: utf-8 -*-</div><div class="code_line">&nbsp;</div><div class="code_line">import sys</div><div class="code_line">import getopt</div><div class="code_line">&nbsp;</div><div class="code_line">Mode = dict()</div><div class="code_line">Mode[&#39;c2f&#39;] = lambda temp: temp * 9 / 5 + 32</div><div class="code_line">Mode[&#39;f2c&#39;] = lambda temp: (temp - 32) * 5 / 9</div><div class="code_line">&nbsp;</div><div class="code_line">def modes():</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#39;available modes:&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp;for m in Mode.keys():</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;print &#39;\t%s&#39; % m</div><div class="code_line">&nbsp;</div><div class="code_line">def usage():</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#39;usage:&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#39;\t-h, &nbsp; &nbsp; --help &nbsp; &nbsp; \tprint usage summary&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#39;\t &nbsp; &nbsp; &nbsp; &nbsp;--modes &nbsp; &nbsp;\tprint available modes&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#39;\t-d &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \tshow debugging information while running&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#39;\t-m &#60;m&#62;, --mode=&#60;m&#62; \tuse &#60;m&#62; as conversion mode&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#39;\t-t &#60;t&#62;, --temp=&#60;t&#62; \tuse &#60;t&#62; as temperature to convert&#39;</div><div class="code_line">&nbsp;</div><div class="code_line">def convert(mode, temp):</div><div class="code_line">&nbsp;&nbsp; &nbsp;if mode in Mode.keys():</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return Mode[mode](temp)</div><div class="code_line">&nbsp;&nbsp; &nbsp;else:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;print &#62;&#62; sys.stderr, &#39;wrong mode &quot;%s&quot;&#39; % mode</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;modes()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;sys.exit(2)</div><div class="code_line">&nbsp;</div><div class="code_line">def main(argv):</div><div class="code_line">&nbsp;&nbsp; &nbsp;temp = 0</div><div class="code_line">&nbsp;&nbsp; &nbsp;mode = Mode.keys()[0]</div><div class="code_line">&nbsp;&nbsp; &nbsp;try:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;opts, args = getopt.getopt(argv, &quot;hm:t:d&quot;, [&quot;help&quot;, &quot;mode=&quot;, &quot;temp=&quot;, &quot;modes&quot;])</div><div class="code_line">&nbsp;&nbsp; &nbsp;except getopt.GetoptError:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;usage()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;sys.exit(2)</div><div class="code_line">&nbsp;&nbsp; &nbsp;for opt, arg in opts:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if opt in (&quot;-h&quot;, &quot;--help&quot;):</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;usage()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sys.exit()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;elif opt == &#39;--modes&#39;:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;modes()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sys.exit()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;elif opt == &#39;-d&#39;:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;global _debug</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_debug = 1</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;elif opt in (&quot;-m&quot;, &quot;--mode&quot;):</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mode = arg</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;elif opt in (&quot;-t&quot;, &quot;--temp&quot;):</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;temp = int(arg)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;except ValueError:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print &#62;&#62; sys.stderr, &#39;wrong integer: %s&#39; % arg</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sys.exit(2)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;usage()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sys.exit()</div><div class="code_line">&nbsp;&nbsp; &nbsp;print convert(mode, temp)</div><div class="code_line">&nbsp;</div><div class="code_line">if __name__ == &quot;__main__&quot;:</div><div class="code_line">&nbsp;&nbsp; &nbsp;main(sys.argv[1:])</div></ol></div></div></div></div><br>
=)]]></description>
        <author>korvin</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2688095</guid>
        <pubDate>Sat, 04 Sep 2010 17:37:12 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2688095</link>
        <description><![CDATA[korvin: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=310710&view=findpost&p=2668059'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Мяут&#045;Настоящий &#064; <time class="tag-quote__quoted-time" datetime="2010-08-12T20:10:20+00:00">12.08.10, 20:10</time></span><div class='quote '>Всем привет. Написал первую программу на питоне. Поругайте, ЧЯДНТ, что можно сделать лучше  8-) <br>
Задача классическая - температурный конвертер в обе стороны<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#!/usr/bin/python</div><div class="code_line"># -*- coding: utf-8 -*-</div><div class="code_line">&nbsp;</div><div class="code_line">import sys</div><div class="code_line">&nbsp;</div><div class="code_line">mode = &#39;NULL&#39;</div><div class="code_line">mlist = (&#39;c2f&#39;, &#39;f2c&#39;)</div><div class="code_line">print &#39;Temperature converter&#39;</div><div class="code_line">while mode != &#39;exit&#39;:</div><div class="code_line">&nbsp;&nbsp;# Вводим режим перевода</div><div class="code_line">&nbsp;&nbsp;mode = raw_input(&#39;Enter mode [exit, c2f, f2c]:\t&#39;)</div><div class="code_line">&nbsp;&nbsp;if mode == &#39;exit&#39;:</div><div class="code_line">&nbsp;&nbsp; &nbsp;break</div><div class="code_line">&nbsp;&nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp;# Проверяем режим</div><div class="code_line">&nbsp;&nbsp;if not mlist.count(mode):</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#62;&#62; sys.stderr, &#39;You\&#39;d entered wrong conv. mode&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp;continue</div><div class="code_line">&nbsp;&nbsp;</div><div class="code_line">&nbsp;&nbsp;# Вводится температура</div><div class="code_line">&nbsp;&nbsp;rtr = 5</div><div class="code_line">&nbsp;&nbsp;while rtr:</div><div class="code_line">&nbsp;&nbsp; &nbsp;try:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;temp = int(raw_input(&#39;Enter temperature in %s: \t&#39; % {&#39;c2f&#39;: &#39;C&#39;, &#39;f2c&#39; : &#39;F&#39;}[mode] ))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;rtr = 0</div><div class="code_line">&nbsp;&nbsp; &nbsp;except ValueError:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;rtr -= 1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if not rtr:</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#62;&#62; sys.stderr, &#39;Failed five times, exiting&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;sys.exit()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;print &#62;&#62; sys.stderr, &#39;Wrong integer. %d retries left&#39; % rtr;</div><div class="code_line">&nbsp;&nbsp;</div><div class="code_line">&nbsp;&nbsp;#Переводим фарингейты</div><div class="code_line">&nbsp;&nbsp;if mode == &#39;c2f&#39;:</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#39;Temperature %d C or %d F&#39; % (temp, temp * 9 / 5 + 32)</div><div class="code_line">&nbsp;&nbsp;else:</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#39;Temperature %d F or %d C&#39; % (temp, (temp - 32) * 5 / 9)</div><div class="code_line">&nbsp;&nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp;print &#39;\n--------------------\n&#39;</div></ol></div></div></div></div></div></div><br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">while mode != &#39;exit&#39;:</div><div class="code_line">&nbsp;&nbsp;# Вводим режим перевода</div><div class="code_line">&nbsp;&nbsp;mode = raw_input(&#39;Enter mode [exit, c2f, f2c]:\t&#39;)</div><div class="code_line">&nbsp;&nbsp;if mode == &#39;exit&#39;:</div><div class="code_line">&nbsp;&nbsp; &nbsp;break</div></ol></div></div></div></div><br>
двойная проверка -- как-то тупо, лучше наверное сделать так:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">prompt = &#39;Enter mode [exit, c2f, f2c]:\t&#39;</div><div class="code_line">mode = raw_input(prompt)</div><div class="code_line">while mode != &#39;exit&#39;:</div><div class="code_line">&nbsp;&nbsp; &nbsp;# ...</div><div class="code_line">&nbsp;&nbsp; &nbsp;# и в самом конце тела цикла</div><div class="code_line">&nbsp;&nbsp; &nbsp;mode = raw_input(prompt)</div></ol></div></div></div></div><br>
<br>
и ещё, &quot;задача&quot; конечно простая и особо изощрятся может и не стоит, но я бы разместил (лямбда-)функции конвертации в хеш-таблице с ключём mode =)<br>
<br>
и если не ошибаюсь, отступ в два пробела не принят, лучше ставить 4]]></description>
        <author>korvin</author>
        <category>Python</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2668059</guid>
        <pubDate>Thu, 12 Aug 2010 20:10:20 +0000</pubDate>
        <title>[Py] Учу питон, поругайте за код</title>
        <link>https://forum.sources.ru/index.php?showtopic=310710&amp;view=findpost&amp;p=2668059</link>
        <description><![CDATA[Мяут-Настоящий: Всем привет. Написал первую программу на питоне. Поругайте, ЧЯДНТ, что можно сделать лучше  8-) <br>
Задача классическая - температурный конвертер в обе стороны<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#!/usr/bin/python</div><div class="code_line"># -*- coding: utf-8 -*-</div><div class="code_line">&nbsp;</div><div class="code_line">import sys</div><div class="code_line">&nbsp;</div><div class="code_line">mode = &#39;NULL&#39;</div><div class="code_line">mlist = (&#39;c2f&#39;, &#39;f2c&#39;)</div><div class="code_line">print &#39;Temperature converter&#39;</div><div class="code_line">while mode != &#39;exit&#39;:</div><div class="code_line">&nbsp;&nbsp;# Вводим режим перевода</div><div class="code_line">&nbsp;&nbsp;mode = raw_input(&#39;Enter mode [exit, c2f, f2c]:\t&#39;)</div><div class="code_line">&nbsp;&nbsp;if mode == &#39;exit&#39;:</div><div class="code_line">&nbsp;&nbsp; &nbsp;break</div><div class="code_line">&nbsp;&nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp;# Проверяем режим</div><div class="code_line">&nbsp;&nbsp;if not mlist.count(mode):</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#62;&#62; sys.stderr, &#39;You\&#39;d entered wrong conv. mode&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp;continue</div><div class="code_line">&nbsp;&nbsp;</div><div class="code_line">&nbsp;&nbsp;# Вводится температура</div><div class="code_line">&nbsp;&nbsp;rtr = 5</div><div class="code_line">&nbsp;&nbsp;while rtr:</div><div class="code_line">&nbsp;&nbsp; &nbsp;try:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;temp = int(raw_input(&#39;Enter temperature in %s: \t&#39; % {&#39;c2f&#39;: &#39;C&#39;, &#39;f2c&#39; : &#39;F&#39;}[mode] ))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;rtr = 0</div><div class="code_line">&nbsp;&nbsp; &nbsp;except ValueError:</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;rtr -= 1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if not rtr:</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#62;&#62; sys.stderr, &#39;Failed five times, exiting&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp;sys.exit()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;print &#62;&#62; sys.stderr, &#39;Wrong integer. %d retries left&#39; % rtr;</div><div class="code_line">&nbsp;&nbsp;</div><div class="code_line">&nbsp;&nbsp;#Переводим фарингейты</div><div class="code_line">&nbsp;&nbsp;if mode == &#39;c2f&#39;:</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#39;Temperature %d C or %d F&#39; % (temp, temp * 9 / 5 + 32)</div><div class="code_line">&nbsp;&nbsp;else:</div><div class="code_line">&nbsp;&nbsp; &nbsp;print &#39;Temperature %d F or %d C&#39; % (temp, (temp - 32) * 5 / 9)</div><div class="code_line">&nbsp;&nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp;print &#39;\n--------------------\n&#39;</div></ol></div></div></div></div>]]></description>
        <author>Мяут-Настоящий</author>
        <category>Python</category>
      </item>
	
      </channel>
      </rss>
	