<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Maxim Kim: Blog &#187; python</title>
	<atom:link href="http://habamax.ru/blog/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://habamax.ru/blog</link>
	<description></description>
	<lastBuildDate>Tue, 24 Aug 2010 18:53:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Python folding in Vim</title>
		<link>http://habamax.ru/blog/2009/05/python-folding-in-vim/</link>
		<comments>http://habamax.ru/blog/2009/05/python-folding-in-vim/#comments</comments>
		<pubDate>Fri, 22 May 2009 08:59:20 +0000</pubDate>
		<dc:creator>Maxim Kim</dc:creator>
				<category><![CDATA[vim]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://habamax.ru/blog/?p=380</guid>
		<description><![CDATA[There are several ftplugins at www.vim.org that fold python code. I could have used one of them and be happy but the burden of my ex-prog-life leads me to my own wheel to be reinvented. Brief description Folds are created for: let g:python_fold_block = "all"&#160;&#8212; all python code blocks; let g:python_fold_block = "def"&#160;&#8212; defs and [...]]]></description>
			<content:encoded><![CDATA[<p>There are several ftplugins at <a href="http://www.vim.org">www.vim.org</a> that fold python code. I could have used one of them and be happy but the burden of my ex-prog-life leads me to my own wheel to be reinvented.</p>
<h2>Brief description</h2>
<ul>
<li>Folds are created for: </li>
<ul>
<li><code>let g:python_fold_block = "all"</code>&nbsp;&mdash; all python code blocks;</li>
<li><code>let g:python_fold_block = "def"</code>&nbsp;&mdash; defs and classes. <strong>[DEFAULT]</strong></li>
</ul>
<li>The way empty lines are folded controlled by <code>g:python_fold_keep_empty_lines</code> variable:</li>
<ul>
<li><code>let g:python_fold_keep_empty_lines = "all"</code>&nbsp;&mdash; keep empty lines between code blocks; <strong>[DEFAULT]</strong></li>
<li><code>let g:python_fold_keep_empty_lines = "top"</code>&nbsp;&mdash; keep empty lines between top level code blocks;</li>
<li><code>let g:python_fold_keep_empty_lines = "top-one"</code>&nbsp;&mdash; keep one empty line between top level code blocks;</li>
<li><code>let g:python_fold_keep_empty_lines = "one"</code>&nbsp;&mdash; keep one empty line between code blocks.</li>
</ul>
<li>Comment&#8217;s folding:</li>
<ul>
<li><code>let g:python_fold_comments = 1</code>&nbsp;&mdash; fold comments; <strong>[DEFAULT]</strong></li>
<li><code>let g:python_fold_comments = 0</code>&nbsp;&mdash; do not fold comments.</li>
</ul>
<li>Import&#8217;s folding:</li>
<ul>
<li><code>let g:python_fold_imports = 1</code>&nbsp;&mdash; fold imports; <strong>[DEFAULT]</strong></li>
<li><code>let g:python_fold_imports = 0</code>&nbsp;&mdash; do not fold imports.</li>
</ul>
<li>Docstring&#8217;s folding:</li>
<ul>
<li><code>let g:python_fold_docstrings = 1</code>&nbsp;&mdash; fold docstrings; <strong>[DEFAULT]</strong></li>
<li><code>let g:python_fold_docstrings = 0</code>&nbsp;&mdash; do not fold docstrings.</li>
</ul>
</ul>
<h2>Screenshots</h2>
<table>
<tr>
<td><a href="http://habamax.ru/blog/wp-content/uploads/2009/05/p_fold_all.png"><img src="http://habamax.ru/blog/wp-content/uploads/2009/05/p_fold_all-300x231.png" alt="p_fold_all" title="p_fold_all" width="300" height="231" class="aligncenter size-medium wp-image-384" /></a><br /><code>let g:python_fold_keep_empty_lines = "all"</code></td>
<td><a href="http://habamax.ru/blog/wp-content/uploads/2009/05/p_fold_top.png"><img src="http://habamax.ru/blog/wp-content/uploads/2009/05/p_fold_top-300x231.png" alt="p_fold_top" title="p_fold_top" width="300" height="231" class="aligncenter size-medium wp-image-385" /></a><br /><code>let g:python_fold_keep_empty_lines = "top"</code></td>
</tr>
<tr>
<td><a href="http://habamax.ru/blog/wp-content/uploads/2009/05/p_fold_top-one.png"><img src="http://habamax.ru/blog/wp-content/uploads/2009/05/p_fold_top-one-300x231.png" alt="p_fold_top-one" title="p_fold_top-one" width="300" height="231" class="aligncenter size-thumbnail wp-image-386" /></a><br /><code>let g:python_fold_keep_empty_lines = "top-one"</code></td>
<td><a href="http://habamax.ru/blog/wp-content/uploads/2009/05/p_fold_one.png"><img src="http://habamax.ru/blog/wp-content/uploads/2009/05/p_fold_one-300x231.png" alt="p_fold_one" title="p_fold_one" width="300" height="231" class="aligncenter size-medium wp-image-402" /></a><br /><code>let g:python_fold_keep_empty_lines = "one"</code></td>
</tr>
</table>
<h2>Install</h2>
<ol>
<li><a href="http://habamax.ru/myvim/data/.vim/ftplugin/python.vim">Download <code>python.vim</code></a></li>
<li>Place <code>python.vim</code> to</li>
<ul>
<li>Windows: <code>~/vimfiles/ftplugin/</code></li>
<li>Linux: <code>~/.vim/ftplugin/</code></li>
</ul>
</ol>
<p>Note: Folding is <code>shiftwidth</code> dependent. If a code indented with 2 spaces make sure <code>shiftwidth</code> is 2 spaces too.</p>
<p>PS: It works for me and it may work for you too despite evil bugs that could live in it. <img src='http://habamax.ru/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://habamax.ru/blog/2009/05/python-folding-in-vim/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Indenting Python with Vim 2</title>
		<link>http://habamax.ru/blog/2009/02/indenting-python-with-vim-2/</link>
		<comments>http://habamax.ru/blog/2009/02/indenting-python-with-vim-2/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 19:23:26 +0000</pubDate>
		<dc:creator>Maxim Kim</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://habamax.ru/blog/?p=250</guid>
		<description><![CDATA[Not that long time ago I began exploring Python. As a Vim adept I write almost all my code using it. And I was really disappointed with the way vim72 indents python&#8217;s code. Consider the following snippet that is indented by built in indent/python.vim script: for file in files: mkdir_copy(os.path.join(root, file), divider, os.path.join(BACKUP_DIR, dest_subdir)) The [...]]]></description>
			<content:encoded><![CDATA[<p>Not that long time ago I began exploring Python. As a Vim adept I write almost all my code using it. And I was really disappointed with the way vim72 indents python&#8217;s code. Consider the following snippet that is indented by built in <code>indent/python.vim</code> script:</p>
<pre class="brush: python;">
for file in files:
    mkdir_copy(os.path.join(root, file), divider,
        os.path.join(BACKUP_DIR, dest_subdir))
</pre>
<p>The code layout should look like (according to <a href="http://www.python.org/dev/peps/pep-0008/">PEP-8</a>):</p>
<pre class="brush: python;">
for file in files:
    mkdir_copy(os.path.join(root, file), divider,
               os.path.join(BACKUP_DIR, dest_subdir))
</pre>
<p>I googled up <a href="http://henry.precheur.org/2008/4/18/Indenting_Python_with_VIM.html">Indenting Python with VIM</a>&nbsp;&mdash; it suggests to use <a href="http://www.vim.org/scripts/script.php?script_id=974">Eric Mc Sween&#8217;s</a> script to solve most of indenting &#8220;problems&#8221;.  It is really nice&#8230; until you have a colon in a docstring or comment. And if you have it&nbsp;&mdash; <code>gg=G</code> will mess your python code right after it:</p>
<pre class="brush: python;">
# TODO:
    # this is an example of bad indenting
    if this_is_an_issue:
        print(&quot;Issue message&quot;)
</pre>
<p>This is definitly not what you want. Although it could be fixed quite easily (and actually I have fixed it) I think builtin script is more robust, so&#8230;<br />
I have fixed builtin <code>indent/python.vim</code> script too. Now it makes &#8220;sexy&#8221; braces indenting just like it should.<br />
But!<br />
Lack of &#8220;sexy&#8221; braces indenting in vim is not a big problem at all. Both &#8212; standard and suggested scripts &#8212; have indent error:</p>
<pre class="brush: python;">
if fullscreen:
    self.win_main = pyglet.window.Window(fullscreen=True, visible=False)
else:
    self.win_main = pyglet.window.Window(width=config.width,
            height=config.height,
            visible=False,
            vsync=True)

self.win_main.set_caption(&quot;Belveder %s&quot; % config.version)
</pre>
<p>Press <code>gg=G</code> :</p>
<pre class="brush: python;">
if fullscreen:
    self.win_main = pyglet.window.Window(fullscreen=True, visible=False)
else:
    self.win_main = pyglet.window.Window(width=config.width,
            height=config.height,
            visible=False,
            vsync=True)

    self.win_main.set_caption(&quot;Belveder %s&quot; % config.version)
</pre>
<p>The last line is indented. Code is broken!</p>
<p>I tried to address all mentioned issues in the fixed <a href="http://habamax.ru/myvim/data/.vim/indent/python.vim">indent/python.vim</a>.<br />
Use it with caution! <img src='http://habamax.ru/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://habamax.ru/blog/2009/02/indenting-python-with-vim-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Маленький баг в indent/python.vim</title>
		<link>http://habamax.ru/blog/2009/02/%d0%bc%d0%b0%d0%bb%d0%b5%d0%bd%d1%8c%d0%ba%d0%b8%d0%b9-%d0%b1%d0%b0%d0%b3-%d0%b2-indentpythonvim/</link>
		<comments>http://habamax.ru/blog/2009/02/%d0%bc%d0%b0%d0%bb%d0%b5%d0%bd%d1%8c%d0%ba%d0%b8%d0%b9-%d0%b1%d0%b0%d0%b3-%d0%b2-indentpythonvim/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 08:29:40 +0000</pubDate>
		<dc:creator>Maxim Kim</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://habamax.ru/blog/?p=235</guid>
		<description><![CDATA[В vim, чтобы писать программы на питоне, для правильной расстановки отступов, советуют использовать следующий indent/python.vim (ver 0.3). Потому как, встроенный в редактор не соответстует PEP 8. Однако есть там маленькая ошибка. Вот такой вот код: # TODO: # this is an example if this_is_an_issue: print(&#34;Issue message&#34;) будет отформатирован следующим образом: # TODO: # this is [...]]]></description>
			<content:encoded><![CDATA[<p>В vim, чтобы писать программы на питоне, для правильной расстановки отступов, <a href="http://henry.precheur.org/2008/4/18/Indenting_Python_with_VIM.html">советуют использовать</a> следующий <a href="http://www.vim.org/scripts/script.php?script_id=974">indent/python.vim (ver 0.3)</a>. Потому как, встроенный в редактор не соответстует <a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a>.</p>
<p>Однако есть там маленькая ошибка. Вот такой вот код:</p>
<pre class="code">
# TODO:
# this is an example
if this_is_an_issue:
    print(&quot;Issue message&quot;)
</pre>
<p>будет отформатирован следующим образом:</p>
<pre class="code">
# TODO:
    # this is an example of bad indenting
    if this_is_an_issue:
        print(&quot;Issue message&quot;)
</pre>
<p>Что, как видно, не верно.</p>
<p>Скрипт я для себя поправил, вечером отошлю исправления Eric Mc Sween&#8217;у.</p>
<p><strong>Update.</strong><br />
Его email помер.<br />
Тогда покажу, где и что на что поправить. В его indent/python.vim строчку под номером 179:</p>
<pre class="code">
    if pline =~ ':\s*$'
</pre>
<p>поменять на:</p>
<pre class="code">
    if pline =~ '^[^#]\+:\s*$'
</pre>
<p><strong>Update 2.</strong><br />
В итоге, все равно пользуюсь стандартным файлом. <img src='http://habamax.ru/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Пришлось, правда, его немного допилить. Чтобы после скобок ставил правильный &laquo;сдвиг&raquo; на следующих строках. Про это написал уже в <a href="http://habamax.ru/blog/2009/02/indenting-python-with-vim-2/">Indenting Python with Vim 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://habamax.ru/blog/2009/02/%d0%bc%d0%b0%d0%bb%d0%b5%d0%bd%d1%8c%d0%ba%d0%b8%d0%b9-%d0%b1%d0%b0%d0%b3-%d0%b2-indentpythonvim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Удаление пустых каталогов</title>
		<link>http://habamax.ru/blog/2008/07/%d1%83%d0%b4%d0%b0%d0%bb%d0%b5%d0%bd%d0%b8%d0%b5-%d0%bf%d1%83%d1%81%d1%82%d1%8b%d1%85-%d0%ba%d0%b0%d1%82%d0%b0%d0%bb%d0%be%d0%b3%d0%be%d0%b2/</link>
		<comments>http://habamax.ru/blog/2008/07/%d1%83%d0%b4%d0%b0%d0%bb%d0%b5%d0%bd%d0%b8%d0%b5-%d0%bf%d1%83%d1%81%d1%82%d1%8b%d1%85-%d0%ba%d0%b0%d1%82%d0%b0%d0%bb%d0%be%d0%b3%d0%be%d0%b2/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 11:12:39 +0000</pubDate>
		<dc:creator>Maxim Kim</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://habamax.ru/?p=17</guid>
		<description><![CDATA[Мой MediaMonkey в&#160;процессе работы оставляет пустые каталоги в&#160;библиотеке с&#160;музыкой. И&#160;убирать их&#160;совсем не&#160;хочет&#160;&#8212; приходится делать это за&#160;него. Питон, который я&#160;не&#160;очень сильно люблю, неплохо с&#160;этим справляется: #### ## Delete empty directories in a given TOPDIR ## Author: Maxim Kim ## PS: ## I use it to keep my music library out of empty dirs. #### TOPDIR = [...]]]></description>
			<content:encoded><![CDATA[<p>Мой <a href="http://www.mediamonkey.com/">MediaMonkey</a> в&nbsp;процессе работы оставляет пустые каталоги в&nbsp;библиотеке с&nbsp;музыкой. И&nbsp;убирать их&nbsp;совсем не&nbsp;хочет&nbsp;&#8212; приходится делать это за&nbsp;него.<br />
Питон, который я&nbsp;не&nbsp;очень сильно люблю, неплохо с&nbsp;этим справляется:</p>
<pre class="brush:python">
####
## Delete empty directories in a given TOPDIR
## Author: Maxim Kim
## PS:
## I use it to keep my music library out of empty dirs.
####

TOPDIR = 'D:/muzik/'

import os

print &quot;=&quot; * 80
print &quot;Deleting empty directories in %s...&quot; % TOPDIR

count = 0
for root, dirs, files in os.walk(TOPDIR, topdown=False):
    for name in dirs:
        dirpath = os.path.join(root, name)
        if len(os.listdir(dirpath)) == 0:
            os.rmdir(dirpath)
            print &quot;%s deleted.&quot; % dirpath
            count+=1

print &quot;Deleted %d directories&quot; % count
print &quot;=&quot; * 80
</pre>
]]></content:encoded>
			<wfw:commentRss>http://habamax.ru/blog/2008/07/%d1%83%d0%b4%d0%b0%d0%bb%d0%b5%d0%bd%d0%b8%d0%b5-%d0%bf%d1%83%d1%81%d1%82%d1%8b%d1%85-%d0%ba%d0%b0%d1%82%d0%b0%d0%bb%d0%be%d0%b3%d0%be%d0%b2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
