On 16:06 Sat 01 Sep , Sean Estabrooks wrote:
>
>
>
> > > Prior to pyeval() function I was using
> > >
> > > vim.command("let dict=%s" % python_dict)
> >
> > I used json.dumps and a self-written dumper for this job. The above code is
> > one of the worst ideas that could go into your head:
>
> This seems a little harsh. The above code is convenient and rather
> straightforward. Shouldn't we find a way to make it work?
>
> >
> > 1. (string % tuple_or_value) notation is deprecated.
> > 2. “"%s" % {u'«»': 1}” produces “{u'\xab\xbb': 1}” which can’t be handled
> > in vim.
> > 3. “"%s" % {'«»': 1}” produces “{'\xc2\xab\xc2\xbb': 1}” which is not
> > handled by vim in a proper way.
> > 4. There is a bunch of other things calling __repl__ on which will result
> > in something vim won’t understand, but in this case vim won’t even
> > understand simple unicode or utf-8 encoded strings as shown above.
> >
> > json.dumps minimizes the amount of problematic things (including converting
> > keys to strings) and throws an exception if it can’t handle something, my
> > interface does this as well. I do not do some type conversions that
> > json.dumps does, json.dumps fails to handle some things which I handle
> > (“pyeval('vim.current.buffer')” produces same output as “getline(1, '$')”,
> > but “json.dumps(vim.current.buffer)” fails).
> >
> > Self-written dumper was used to get binary data: “json.dumps('\x80')”
> > throws an exception while vim is fine with just having it embedded inside a
> > string.
> >
>
> Obviously it would be much better if everyone who is using python inside of
> Vim doesn't have to write their own custom code to transfer these values. Do
> you have a plan in this regard or is this an open problem?
>
> Thanks,
> Sean
This the purpose of pyeval() and py3eval() functions which came with
a recent patch (by Zyx).
Thank you Zyx for showing me the weak points. I only used this for ASCII
and integers, though at some point this would lead to a problem.
Best,
Marcin
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php