Python
  Home arrow Python arrow Page 3 - Karrigell for Python
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PYTHON

Karrigell for Python
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 13
    2006-01-03


    Table of Contents:
  • Karrigell for Python
  • Scripts and Services
  • Being HIP
  • A Few More Features

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Karrigell for Python - Being HIP
    ( Page 3 of 4 )

    In askName.py, one thing seems to be very noticeable: there are a lot of print statements in the code. Wouldn't it be nice if we could eliminate them? Fortunately, Karrigell provides a method that does just that. It's called HTML Inside Python, and it allows all those nasty print statements to be eliminated. It isn't very hard to convert askName.py to an HTML in Python file, either. We simply need to remove the print statements and change the extension. Delete askName.py's print statements and rename it to askName.hip:

    if QUERY.has_key ( "name" ):
       "Your name is", _name + "."
    else:
       "What is your name?<br />"
       "<form method='POST'>"
       "<input type='text' name='name' /><br />"
       "<input type='submit' value='Proceed' />"
       "</form>"

    Truthfully, that's all there is to HTML Inside Python. Karrigell will examine your file and add print statements when necessary. HTML Inside Python is a wonderful demonstration of the simplicity of Karrigell.

    Python Inside HTML

    Since Karrigell features HTML Inside Python, it's only logical to contain Python Inside HTML. The underlying idea – and even the look of the finished code – is common, and it's been featured in other frameworks. Special tags are wrapped around Python code, and the overall result is sent to the user's browser. Let's create a simple example, random.pih:

    <% import random %>
    Random number: <b><% print random.random() %></b>

    As you can see, the concept behind Python Inside HTML is pretty simple. Also, note that the block of code that prints the random number could be shortened even more:

    <%= random.random() %>

    However, what about more complex operations, such as handling form data? Form data can be accessed just like it can be in Python scripts. Here is a recreation of the askName.py script, called askName.pih:

    <% if QUERY.has_key ( "name" ): %>
       Your name is <%= _name %>.
    <% end %>
    <% else: %>
       What is your name?<br />
       <form method='POST'>
       <input type='text' name='name' /><br />
       <input type='submit' value='Proceed' />
       </form>
    <% end %>

    Notice the use of <% end %>. This simply marks the end of a block of indentation, such as the indentation called for by our conditional statement. An alternative is the indent tag, which uses the indentation present in the code:

    <indent>
    <% if QUERY.has_key ( "name" ): %>
       Your name is <%= _name %>.
    <% else: %>
       What is your name?<br />
       <form method='POST'>
       <input type='text' name='name' /><br />
       <input type='submit' value='Proceed' />
       </form>
    </indent>



     
     
    >>> More Python Articles          >>> More By Peyton McCullough
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek