TypeError: int argument required

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Wed Jun 17 13:07:15 CEST 2009


In message <N4QZl.19093$y61.17109 at news-server.bigpond.net.au>, Lie Ryan 
wrote:

> out.write (
> '''
> function JSString(Str)
>   {
>     var Result = '\"'
>     for (var i = 0; i < Str.length; ++i)
>       {
>         var ThisCh = Str.charAt(i)
>         if (ThisCh == '\\')
>           {
>             ThisCh = '\\\\'
>           }
>         else if (ThisCh == '\"')
>           {
>             ThisCh = '\\\"'
>           }
>         else if (ThisCh == '\t')
>           {
>             ThisCh = '\\t'
>           }
>         else if (ThisCh == '\n')
>           {
>             ThisCh = '\\n'
>           } /*if*/
>         Result += ThisCh
>       } /*for*/
>     return Result + '\"'
> } /*JSString*/
> '''
> )

You haven't managed to get rid of the backslashes.

> I might go even further:
> 
> out.write (
> '''
> function JSString(Str)
>   {
>     const dq = '\"'
>     const slash = '\\'
> 
>     var Result = dq
>     for (var i = 0; i < Str.length; ++i)
>       {
>         var ThisCh = Str.charAt(i)
>         if (ThisCh == slash)
>           {
>             ThisCh = slash + slash
>           }
>         else if (ThisCh == dq)
>           {
>             ThisCh = slash + dq
>           }
>         else if (ThisCh == '\t')
>           {
>             ThisCh = slash + 't'
>           }
>         else if (ThisCh == '\n')
>           {
>             ThisCh = slash + 'n'
>           } /*if*/
>         Result += ThisCh
>       } /*for*/
>     return Result + dq
> } /*JSString*/
> '''
> )

Now you've lost track of the original point of the discussion, which is 
about using alternate quotes to avoid backslashes.




More information about the Python-list mailing list