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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
SunQuest
 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? 
PYTHON

Karrigell for Python
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 11
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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
     
    IBM developerWorks
     
    ADVERTISEMENT

    At the virtual BlackBerry Technical Seminar 2008, you can ask your development questions directly of Research In Motion® (RIM) experts, and take advantage of learning opportunities designed uniquely for BlackBerry solution developers. Register Today!

    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


       · Hello, all.Karrigell definitely isn't the most popular Python framework out...
       · I figure for heavy lifting we have either TurboGears, or CherryPy(unadorned)....
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...

    SunQuest




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway