Chewing one's arm off to avoid VBScript (was RE: Serious privacy leak in Pytho

gbreed at cix.compulink.co.uk gbreed at cix.compulink.co.uk
Thu Jan 17 11:50:49 EST 2002


Mark McEahern wrote:

>     ' let's create a dictionary
>     set dict = createobject("scripting.dictionary")
>     dict.add "a", "first letter"
>     dict.add "b", "second letter"
>     k = dict.keys()
>     s = ""
>     for i = 0 to ubound(k)
>       s = s & "k = " & dict.item(k(i)) & vbCrLf
>     next
>     msgbox s ' or response.write s for asp

You can re-write that (in ASP, in <PRE> context)

    ' let's create a dictionary
    set dict = createobject("scripting.dictionary")
    dict("a") = "first letter"
    dict("b") = "second letter"
    for each key in dict.keys()
      response.write(key&" = "&dict(key)&vbNewLine)
    next


>   btw, this is an example of what people mean when they say vb is 
> verbose.

Can't you think of a better one?
 
> in python, if you want a dictionary, you can just write it.  not so in
> vbscript.

That's the only clear advantage in this example

>  likewise, consider this abomination of syntax for accessing 
> an
> item:
> 
>       dict.item(k(i))
> 
> i mean, what the f*** is that?  ;-)  compare that to:
> 
>       dict[key]

This is silly.  You can write dict[dict.keys()[i]] in Python, and 
dict(key) in VBScript.  I'm not aware of a VBScript equivalent of this 
twist

    # let's create a dictionary
    dict = {'a': 'first letter', 'b': 'second letter'}
    for item in dict.items():
      print "%s = %s" % item

let alone

# let's create a dictionary
dict = {'a': 'first letter', 'b': 'second letter'}
# let's do the whole thing on one line
print '\n'.join(['%s = %s'%x for x in dict.items()])
# and again!
print '\n'.join(map(' = '.join, dict.items()))


Incidentally, does it matter that Python prints the second letter before 
the first letter?


                    Graham



More information about the Python-list mailing list