tabs in template.py

9 views
Skip to first unread message

Aaron Swartz

unread,
Dec 15, 2006, 6:37:58 PM12/15/06
to we...@googlegroups.com
Won't using .expandtabs() change tabs to eight spaces and screw things
up because t.py only expects four?

Adam Atlas

unread,
Dec 15, 2006, 8:28:26 PM12/15/06
to web.py
It has an optional tab size parameter. Just call expandtabs(4).

(Ideally, though, template.py shouldn't care how many spaces/tabs are
used. It would be best if it could handle any indentation scheme that
you could do in plain Python.)

Anand

unread,
Dec 15, 2006, 8:59:37 PM12/15/06
to we...@googlegroups.com

On 16-Dec-06, at 5:07 AM, Aaron Swartz wrote:

>
> Won't using .expandtabs() change tabs to eight spaces and screw things
> up because t.py only expects four?
>


no it doesnt.

The following test failes. but it gives resonable result.

lambda: t('$for x in [1, 2, 3]:\n\t$x')
(), '1\n2\n3\n',

AssertionError:
expected: '1\n2\n3\n'
got: ' 1\n 2\n 3\n'


That is perfectly fine for html.
If you try to make tabsize to 4, there can be problems in someother
places.

Python also treats tab as 8 spaces.

>>> exec("for i in range(3):\n a = i*i\n\tprint i,a")
0 0
1 1
2 4
>>> exec("for i in range(3):\n a = i*i\n\tprint i,a")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 3
print i,a
^
SyntaxError: invalid syntax
>>>

In the first example, i used 8 spaces and 4 in the latter one.

Anand

unread,
Dec 19, 2006, 12:22:35 PM12/19/06
to we...@googlegroups.com

On 16-Dec-06, at 7:29 AM, Anand wrote:

>
> On 16-Dec-06, at 5:07 AM, Aaron Swartz wrote:
>
>>
>> Won't using .expandtabs() change tabs to eight spaces and screw
>> things
>> up because t.py only expects four?
>>
>
>
> no it doesnt.
>

fixed. r134.

Aaron Swartz

unread,
Dec 20, 2006, 8:58:12 PM12/20/06
to we...@googlegroups.com
What I'm really worried about is the 2-deep nesting scenario, like
'$for i in x:\n\t$if i:\n\t\tfoo'. That should work.

Anand

unread,
Dec 21, 2006, 7:52:43 AM12/21/06
to we...@googlegroups.com

On 21-Dec-06, at 7:28 AM, Aaron Swartz wrote:

>
> What I'm really worried about is the 2-deep nesting scenario, like
> '$for i in x:\n\t$if i:\n\t\tfoo'. That should work.

Yes, it doesnt work. I will try to find a solution.

Reply all
Reply to author
Forward
0 new messages