I think, allowing to specify blocks with algol style (for-end, if-end,
etc) will allow to write easy php-like templates
and would attract new web developers to python (as php and ruby do).
It can be straight compilled into Python bytecode cause there is
one-to-one transformation.
So this:
# -*- syntax-style: algol -*-
class asd:
def __init__(self,a ):
if a:
for i in xrange(100):
pass
else:
while false:
pass
else:
pass
end
end
else:
self.a=None
end
end
end
is equivalent for:
class asd:
def __init__(self,a ):
if a:
for i in xrange(100):
pass
else:
while false:
pass
else:
pass
else:
self.a=None
but could be written as:
# -*- syntax-style: algol -*-
class asd: def __init__(self,a ): if a: for i in xrange(100): pass; else:
while false: pass; else: pass; end; end; end; end;
which is easier to embed into http template (php and ruby shows it).
And, maybe, there can web syntax - equivalent for php and ruby template:
<%# -*- syntax: web -*-%>
<%# -*- command: print -*- %>
<%
def print_all(l):%>
<table><%
for k in l:%>
<tr><td>#{k.nam e}</td><td>#{k.surn ame}</td></tr>
<%end%>
</table>
<%end
# -*- command: yield -*-
def yield_all(l):%>
<table><%
for k in l:%>
<tr><td>#{k.nam e}</td><td>#{k.surn ame}</td></tr>
<%end%>
</table>
<%end
# -*- command: S.write -*-
def write_all(S,l): %>
<table><%
for k in l:%>
<tr><td>#{k.nam e}</td><td>#{k.surn ame}</td></tr>
<%end%>
</table>
<%end%>
will be translated as it were written:
def print_all(l):
print (r"<table>")
for k in l:
print (r"<tr><td>"+`k .name`+ r"</td><td>"+`k.sur name`+ r"</td></tr>")
# or print (r"<tr><td>"+st r(k.name)+ r"</td><td>"+str(k. surname)+
r"</td></tr>")
print (r"</table>")
def yield_all(l):
yield (r"<table>")
for k in l:
yield (r"<tr><td>"+`k .name`+ r"</td><td>"+`k.sur name`+ r"</td></tr>")
yield (r"</table>")
def write_all(S.l):
S.write (r"<table>")
for k in l:
S.write (r"<tr><td>"+`k .name`+ r"</td><td>"+`k.sur name`+
r"</td></tr>")
S.write (r"</table>")
I offer to include it into iterpretter, so we can leave another
compilation stage, as it exists with popular
template libraries, which compile their template files into bytecode (or
python source) 3 1584
Sokolov Yura wrote: I think, allowing to specify blocks with algol style (for-end, if-end, etc) will allow to write easy php-like templates and would attract new web developers to python (as php and ruby do). It can be straight compilled into Python bytecode cause there is one-to-one transformation. [snip details]
Standard answer to this kind of question:
You can already do that in Python. It's spelled #end.
/MiO
You didn't quite get the OP's intention, I guess.
The OP wanted Python to be a bit more freeform by adding "end" tags.
That might be an improvement for web scripting, but I haven't seen the
solutions of the existing frameworks and won't dare to compare.
"Christoph Rackwitz" <ch************ ****@gmail.com> writes: You didn't quite get the OP's intention, I guess.
The OP wanted Python to be a bit more freeform by adding "end" tags. That might be an improvement for web scripting, but I haven't seen the solutions of the existing frameworks and won't dare to compare.
Existing frameworks (the one's I've looked at anyway) tend to replace
indents with end tags of some kind. Doing anything else tends to get
ugly unless the language you are templating for treats whitespace the
same way Python does.
I'd argue that you're better off using a real templating system than
trying to mangle Python into becoming a more acceptable templating
system. For templates, you tend to want to access multiple different
names spaces that are only vaguelly related to the Python contextual
name spaces. For example, you may want CGI (or whatever variables)
available directly in the template, rather than as
CGI["foobar"].value. However, you don't want them showing up in front
of your templat variables; you want to be able to say "add CGI
variables foo, bar and foobar to the current name space" in a short
manner.
Templating systems (well, the better ones, anyway) let you manipulate
those name spaces in ways you can't do in python. Cheeta and
ClearSilver come to mind as systems that will let you do this.
<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rob Long |
last post by:
Hey,
I've just noticed a somewhat annoying feature with PHP5 type hinting.
You cannot hint types on optional arguments like this:
class MyClass
{
function someFunc(Type1 $arg1, Type2 $arg2 = new Type2()) { }
|
by: lakshmi |
last post by:
include the following lines of code:
using System.Runtime.InteropServices;
prefix the optional argument with
This takes care if an optional parameter is not supplied
by a VB script client.
>-----Original Message-----
>I found that optional parameters are not supported in C#.
>We are currently rewriting a C++ dll in C#. The C++ dll
|
by: Do |
last post by:
Hi:
What's the syntax for an optional parameter in my function? I've done so
many ASP 3.0 Web Classes that
I haven't experienced the "Optional" parameter.
Eg. Public function adduser(ByVal firstname as String, ByVal Lastname as
String)
End Function
|
by: guy |
last post by:
found this oddity-
copying a vb6 function with optional parameters and pasting it into a vb2003
class, for conversion purposes, it all works fine except that the collapsing
"-" on the LHS goes away, only to return if "Optional" is removed. Strange.
anyone else had this?
guy
|
by: Alan J. Flavell |
last post by:
What I was trying to do: to offer a default stylesheet, plus another
small stylesheet which can be applied additionally to the default
one. Preferably, the optional stylesheet should be initially in
effect, but the user should be able to turn it off.
My reading of the HTML4 spec (which is where this seems to be
documented, though I reckon it's on-topic for this group): it seems to
me that what I want, in the terms described there, is...
| |
by: deko |
last post by:
In VB, I could do this:
MyFuncrion(this As String, that As Integer, Optional otherThing As Boolean)
do stuff here
End Function
In C#, I can use "out" to return multiple values from a method, and "params"
to send in an array, but is it possible to have optional parameters? How do
I do this in C#?
|
by: Nick Hounsome |
last post by:
Can anyone tell me what the rational is for not supporting optional
arguments.
It is obviously a trivial thing to implement and, since C++ has them, I
would not expect them to be omitted without a good reason.
|
by: cody |
last post by:
I got a similar idea a couple of months ago, but now this one will require
no change to the clr, is relatively easy to implement and would be a great
addition to C# 3.0 :)
so here we go..
To make things simpler and better readable I'd make all default parameters
named parameters so that you can decide for yourself which one to pass and
which not, rather than relying on massively overlaoded methods which
hopefully provide the best...
|
by: MisterWilliam |
last post by:
I noticed that in PEP 3105, the PEP about turning print to print(),
the syntax for print() is defined as follows:
def print(*args, sep=' ', end='\n', file=None)
Ignoring the fact that print is a reserved keyword in python, this is
not valid python because extra positional arguments (*args), cannot
come before optional parameters (sep=' ', end='\n', file=None).
File "<stdin>", line 1
def f(*args, sep=' ', end='\n', file=None):
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |