[Tutor] Automated Breadcrumb -- help for a PHP user

Chris Heisel chris at heisel.org
Wed Nov 26 10:22:12 EST 2003


I aplogize, I didn't mean to indicate that I wanted to write PHP in 
python, I'm trying to migrate to python because I enjoy the elegance of 
the language, I should have clarified my question a bit.

I'm used to the PHP environment where I can access a page's URL and 
other attributes by accessing the various global system arrays.

I have not done any traditional CGI programming, so I'm not sure about 
how to pass information, such as an HTML page's URI, to my python script.

I'd love to use some of the frameworks you mentioned but I'm in a 
corporate environment designing a system for other Web producers who 
will be editing pages via BBEdit and then uploading to the server, so 
I'm trying to keep the set up as simple as possible.

Danny's answer was helpful because its sent me down the cgi path and I'm 
doing some RTFM about cgi and the various variables available...

So apologies all around, I should have clarieid that I wasn't used to 
the python way of accessing global page variables when being used as a 
CGI script, and not that I was confused about the language constructs to 
  output the trail...

Chris

Daniel Ehrenberg wrote:
> Chris Heisel wrote:
> 
>>Hi,
>>
>>I'm a n00b to python coming from PHP land.
>>
>>I'd like to create an automated breadcrumb script
>>that would inspect the 
>>URL and create an appropriate bread crumb navigation
>>set.
>>
>>In PHP I'd so something like
>>function makeBread($url) {
>>     $path_parts = explode('/', $url);
>>     echo('<p class="trail">');
>>     foreach ($path_parts as $key => $value) {
>>         $where_at = $where_at + $value;
>>         echo('<a
>>href="$where_at">'.$where_at.'</a>');
>>     }
>>}
>>
> 
> If I understand what that does correctly, it's
> probably something like this:
> 
> def makeBread(url):
>     path_parts = url.split('/')
>     output = '<p class="trail">'
>     where_at = ''
>     for value in path_parts:
>         where_at += value
>         output += '<a href="%s">%s</a>' % (where_at,
> where_at)
>     return output
> 
> 
>>I'd put this function in an external file include()
>>it and make a call with:
>><?php
>>makeBread($PHP_SELF)
>>?>
>>(Disclaimer: this code is really ugly its just an
>>example...)
>>
>>I'd like to do this in Python and make it a cgi-bin
>>file so I could have 
>>something like this:
>><!--#include virtual="/cgi-bin/bread.py" -->
>>
>>But I'm not sure where to start. How can I pass the
>>URL of the page 
>>making the include call to the script?
>>
>>One its there I'm sure I can muddle through some
>>flow control structures 
>>and what not to massage the URL into the various
>>breadcrumb pieces...
>>
>>Any help would be greatly appreciated.
>>
>>Thanks in advance,
>>
>>Chris
> 
> 
> It looks kind of like you're trying to write PHP in
> Python. There's nothing wrong with PHP, but it is not
> that popular to try to emulate other languages. (If
> you still want to, try the replcode module at
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52217,
> but it doesn't handle CGI automatically.) For advanced
> website templating, you should try CherryPy, or Zope's
> DTML. DTML does a good job of seperating style and
> coding, and CherryPy  is very good object system and
> is easy to use. If you still want to use your weird
> comment syntax, a regexp would probably be necessary,
> but I don't know anything further.
> 
> Daniel Ehrenberg
> 
> __________________________________
> Do you Yahoo!?
> Free Pop-Up Blocker - Get it now
> http://companion.yahoo.com/
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list