<?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>Intrepid Blog &#187; dynamic</title>
	<atom:link href="http://blog.affien.com/archives/tag/dynamic/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.affien.com</link>
	<description>A few thoughts</description>
	<lastBuildDate>Mon, 23 Jan 2012 08:47:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Python Html Document Abstraction</title>
		<link>http://blog.affien.com/archives/2005/03/06/python-html-document-abstraction/</link>
		<comments>http://blog.affien.com/archives/2005/03/06/python-html-document-abstraction/#comments</comments>
		<pubDate>Sun, 06 Mar 2005 18:15:58 +0000</pubDate>
		<dc:creator>Bas Westerbaan</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.w-nz.com/archives/2005/03/06/python-html-document-abstraction/</guid>
		<description><![CDATA[Python is great!

>>> d = document()
>>> d.html.body [...]]]></description>
			<content:encoded><![CDATA[<p>Python is great!</p>
<blockquote><pre style="font-size: 12px">>>> d = document()
>>> d.html.body.h1.value = "My Site!"
>>> d.html.body.p.value = "Welcome to this python generated site"
>>> str(d)
'&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt; !DOCTYPE html PUBLIC "-//W3C//DTD XHTML
 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt;
&lt;body&gt;&lt;p&gt;Welcome to this python generated site&lt;/p&gt;
&lt;h1&gt;My site!&lt;/h1&gt;&lt;/body&gt;&lt;head&gt;&lt;title&gt;
&lt;/title&gt;&lt;/head>&lt;/html&gt;'
</pre>
</blockquote>
<p>(<em>Ignore the added slashes and the additional line breaks caused by wordpress</em>)</p>
<p>By overloading the <code>__get</code>/<code>set</code>/<code>delattr__</code> functions a html document can be represented like a real python object model. </p>
<p>I&#8217;ve just experimented a little bit with python code to ultimately go to write a framework to write nice dynamic python webbased applications in.</p>
<p>Although it appears that the names of the objects (<code>html</code>, <code>body</code>, <code>p</code>, etc) are the tag names, they aren&#8217;t. They are the identifiers of the tags.. in case the tag isn&#8217;t set by yourself but just created for it didn&#8217;t existed it uses as tag its alleged id.</p>
<p>The default created object when no object exists already with that id is a <code>tag</code>. This abstract document won&#8217;t be limited to tags. I&#8217;ve just made a <code>styleTag</code> class which allows:</p>
<blockquote><pre style="font-size: 12px">d.html.head.style.body["font-family"] = 'verdana'</pre>
</blockquote>
<p>which is basicly the same as</p>
<blockquote><pre style="font-size: 12px">d.html.head.style.["body"].font-family = 'verdana'</pre>
</blockquote>
<p>In contrary to the normal <code>tag</code> class where an <em>item</em> is an attribute, this is different in the style tag for CSS got a lot of characters which python doesn&#8217;t like (like #).</p>
<p>Being able to manipulate a style sheet that easily allows every custom tag (maybe a <code>datetimepickercontrol</code>) to set its own style information by just using simple python code.</p>
<p>For the <code>styletag</code> isn&#8217;t bound to putting its emitted css in the emitted-html string itself in case it is emit-ed in a specific context like a webserver, it can even create a seperate css for this purpose.</p>
<p>Python allows much more dynamic features in a dynamic framework like this than any other language, I`m quite enthousiastic about it and am playing with new idea&#8217;s like a little child <img src='http://blog.affien.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<p>All kinds of idea&#8217;s would be welcome..</p>
<p>Just wondering whether such a thing has already been written for Python.. anyone knows?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.affien.com/archives/2005/03/06/python-html-document-abstraction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The dynamic of python</title>
		<link>http://blog.affien.com/archives/2004/12/29/the-dynamic-of-python/</link>
		<comments>http://blog.affien.com/archives/2004/12/29/the-dynamic-of-python/#comments</comments>
		<pubDate>Wed, 29 Dec 2004 17:21:30 +0000</pubDate>
		<dc:creator>Bas Westerbaan</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.w-nz.com/archives/2004/12/29/the-dynamic-of-python/</guid>
		<description><![CDATA[Python is dynamic (duh)

Dynamic typing
You don't ne [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://python.org">Python</a> is dynamic (duh)</p>
<p><strong>Dynamic typing</strong><br />
You don&#8217;t need to specify the type of an object anywhere.</p>
<blockquote><pre>def PrintSomething(something):
    print something</pre>
</blockquote>
<p><strong>Everything is an object</strong><br />
Everything, yes, <strong>everything</strong> in Python is an object. Even an integer, a method, a class, etc.<br />
Every object has got a type (<code>__class__</code>), which actually can be changed at runtime, which usually results in conflicts about the allocated size for the <code>PyObject</code>.</p>
<p><strong>No typing needed</strong><br />
Python doesn&#8217;t know interfaces, for if a certain object wants to expose certain behaviour it just implements the required methods.<br />
When you want a object to be comparible in python you don&#8217;t inherit something like <code>IComparible</code> like in .Net, but you just create the <code>__cmp__</code> method.</p>
<p><strong>Fields and methods can be changed (and are the same)</strong><br />
A method and a field in python are 2 the same things. They both rely in the object&#8217;s dictionary (<code>__dict__</code>) or of the object&#8217;s type&#8217;s dictionary (<code>__class__.__dict__</code>).<br />
This allows you to use an object which implements <code>__call__</code> instead of a method.<br />
For <code>__dict__</code> is writeable you can change / create <em>attributes</em> (members) at runtime:</p>
<blockquote><pre>&gt;&gt;&gt; sys.__dict__['foo'] = "bar"
&gt;&gt;&gt; sys.foo
'bar'</pre>
</blockquote>
<p><strong>A class member function is a normal method, wrapped</strong></p>
<blockquote><pre>&gt;&gt;&gt; class exampleclass:
	value = &quot;&quot;
	def examplefunction(self):
		print self.value
&gt;&gt;&gt; def examplereplacement(self):
	print &quot;replacement!&quot;
	print self.value
&gt;&gt;&gt; instance = exampleclass()
&gt;&gt;&gt; instance.examplefunction()
&gt;&gt;&gt; instance.value = &quot;foobar&quot;
&gt;&gt;&gt; instance.examplefunction()
foobar
&gt;&gt;&gt; instance.examplefunction = examplereplacement
&gt;&gt;&gt; instance.examplefunction()
Traceback (most recent call last):
  File &quot;&lt;pyshell#15&gt;&quot;, line 1, in -toplevel-
    instance.examplefunction()
TypeError: examplereplacement() takes exactly 1 argument (0 given)
&gt;&gt;&gt; instance.__class__.examplefunction = examplereplacement
&gt;&gt;&gt; instance.examplefunction()
Traceback (most recent call last):
  File &quot;&lt;pyshell#17&gt;&quot;, line 1, in -toplevel-
    instance.examplefunction()
TypeError: examplereplacement() takes exactly 1 argument (0 given)
&gt;&gt;&gt; instance.__class__.__dict__['examplefunction'] = examplereplacement
&gt;&gt;&gt; instance.examplefunction()
Traceback (most recent call last):
  File &quot;&lt;pyshell#19&gt;&quot;, line 1, in -toplevel-
    instance.examplefunction()
TypeError: examplereplacement() takes exactly 1 argument (0 given)
&gt;&gt;&gt; instance = exampleclass()
&gt;&gt;&gt; instance.__class__.__dict__['examplefunction'] = examplereplacement
&gt;&gt;&gt; instance.examplefunction()
replacement!</pre>
</blockquote>
<p>The bound methods seem to work a bit more tricky than they appear to work. Usually editing member functions via the <code>__class__</code>&#8216;s <code>__dict__</code> will result in a proper replacement.</p>
<p>These were just a few examples of what Python has to offer. These features aren&#8217;t limited to Python. <a href="http://www.ironpython.com/">Iron Python</a>, an implementation of Python in .Net is capable of letting usual .Net objects to be manipulated in similar ways with Python via Iron Python. Although this doesn&#8217;t actually change the .Net objects, changing the wrapper resulting in the required similar behaviour is good enough.</p>
<p>The author of Iron Python has been recruited by Microsoft and is now working on making the CLR more dynamic.</p>
<p>I&#8217;d love a static dynamic language.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.affien.com/archives/2004/12/29/the-dynamic-of-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

