<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Python on Bharath's Blog</title><link>https://bharathbhushan1.github.io/blog/tags/python/</link><description>Recent content in Python on Bharath's Blog</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 29 Jun 2026 08:30:00 +0530</lastBuildDate><atom:link href="https://bharathbhushan1.github.io/blog/tags/python/index.xml" rel="self" type="application/rss+xml"/><item><title>A Tiny Q-learning Example in Python</title><link>https://bharathbhushan1.github.io/blog/posts/2026-06-29-simple-q-learning/</link><pubDate>Mon, 29 Jun 2026 08:30:00 +0530</pubDate><guid>https://bharathbhushan1.github.io/blog/posts/2026-06-29-simple-q-learning/</guid><description>&lt;p&gt;I wanted to get a better sense of the temporal-difference update rule. So took some help
from Claude and wrote a small Q-learning program. Just uses the python stdlib.
The code lives in &lt;a href="https://github.com/bharathbhushan1/ai-learning/tree/main/q-learning"&gt;&lt;code&gt;q-learning&lt;/code&gt;&lt;/a&gt;,
managed with &lt;a href="https://docs.astral.sh/uv/"&gt;uv&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="A 1D line of six cells, 0 through 5; the agent starts at cell 0 and the learned policy points right at every step toward the goal at cell 5, with Q-values discounted back from the goal" loading="lazy" src="https://bharathbhushan1.github.io/blog/images/q-learning.svg"&gt;&lt;/p&gt;</description></item><item><title>A Tiny Agent, v2: Python and the Sarvam API</title><link>https://bharathbhushan1.github.io/blog/posts/2026-06-28-tiny-agent-v2-sarvam/</link><pubDate>Sun, 28 Jun 2026 18:00:00 +0530</pubDate><guid>https://bharathbhushan1.github.io/blog/posts/2026-06-28-tiny-agent-v2-sarvam/</guid><description>&lt;p&gt;After the Go &lt;a href="https://bharathbhushan1.github.io/blog/posts/2026-06-28-building-a-tiny-agent/"&gt;tiny coding agent&lt;/a&gt;,
I rewrote the same thing in Python, this time pointed at the
&lt;a href="https://www.sarvam.ai/"&gt;Sarvam&lt;/a&gt; API instead of Gemini. Sarvam is an Indian
company which is trying to work Indian Sovereign. The models are strong on Indian
languages, which made it interesting to target. The code lives in
&lt;a href="https://github.com/bharathbhushan1/ai-learning/tree/main/test-agent-v2"&gt;&lt;code&gt;test-agent-v2&lt;/code&gt;&lt;/a&gt;,
managed with &lt;a href="https://docs.astral.sh/uv/"&gt;uv&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Functionally it is the same agent: a stdin-driven loop, the same three file
tools (&lt;code&gt;read_file&lt;/code&gt;, &lt;code&gt;list_files&lt;/code&gt;, &lt;code&gt;edit_file&lt;/code&gt;), the same Sudarshana ☸️ agent. I had typed
out most of the v1 agent by hand with as little AI help as possible. I just wanted to
get into the weeds of the mechanics, ser-deser, order of various operations, different
data structures needed etc. This time I felt confident I could relate to the different
parts of the agent. So I just asked Claude to rewrite it in python.&lt;/p&gt;</description></item><item><title>How to use spark with anaconda python</title><link>https://bharathbhushan1.github.io/blog/posts/2015-12-12-spark-anaconda/</link><pubDate>Sat, 12 Dec 2015 08:00:00 +0000</pubDate><guid>https://bharathbhushan1.github.io/blog/posts/2015-12-12-spark-anaconda/</guid><description>&lt;p&gt;The setup is spark 1.5.1 running on yarn (hadoop-2.6.0).&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Install anaconda python on all nodes of the cluster.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Below we are installing anaconda&amp;#39;s python-2.7 64-bit package.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;wget https://3230d63b5fc54e62148e-c95ac804525aac4b6dba79b00b39d1d3.ssl.cf1.rackcdn.com/Anaconda2-2.4.1-Linux-x86_64.sh
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;bash Anaconda2-2.4.1-Linux-x86_64.sh -b -f -p /usr/lib/anaconda2
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Run this on all nodes of the cluster and restart the ResourceManager/NodeManager daemons.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;VIRTUAL_ENV_DISABLE_PROMPT=1 source /usr/lib/anaconda2/bin/activate /usr/lib/anaconda2&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; /usr/lib/hadoop2/etc/hadoop/hadoop-env.sh
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Set some env vars and start pyspark.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;PYSPARK_PYTHON&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/lib/anaconda2/bin/python
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;PYSPARK_DRIVER_PYTHON&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/lib/anaconda2/bin/python
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;/usr/lib/spark/bin/pyspark --master yarn-client --executor-memory 512m --executor-cores &lt;span class="m"&gt;1&lt;/span&gt; --num-executors &lt;span class="m"&gt;2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item></channel></rss>