In ruby is something like:
VIM::command("return #{my_ruby_var.inspect}")
I expect to be the same in python.
> --
> You received this message from the "vim_use" 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
>
--
talek
You can do
import vim
and then use
vim.command("let g:return="+str(value))
This works also with dictionaries and lists (though I've encountered that some
times singe quotes inside value when it is a dictionary or a list may couse
troubles). So I would like to know a better method.
Best,
Marcin
It works fine if you call it inside a vim function:
:function Func()
: py vim.command('return 1')
:endfunction
This last one cannot be right: as a minimum, it lacks a backslash left
of "MyCallback".
Best regards,
Tony.
--
Ducharme's Axiom:
If you view your problem closely enough you will recognize
yourself as part of the problem.
If you keep the quotes and backsalshes, but change the rest you can write (
s:SNR -> getcwd(), MyCallback -> /. ) :
:python import os
:exec "python print os.path.exists(\"" . getcwd() . "/.\")"
which works for me (Vim 7.3). If getcwd() returns "/home/user", the generated
Python statement is:
print os.path.exists("/home/user/.")
In the above case you would get the Python statement:
DoSomething("32_MyCallback", ...)
Marko
> Best regards,
> Tony.
no, you would get:
E???: invalid expression
because
>>> exec "python DoSomething(\"" . s:SNR . "MyCallback\", ...)"
string ^---------------------------------^
something Vim cannot understand ^--------...
>
>
> Marko
>
>> Best regards,
>> Tony.
--
Honk if you hate bumper stickers that say "Honk if ..."
P.S. I think you should have written
:exec 'python DoSomething("' . s:SNR . 'MyCallback", ...)'
>
>>
>>
>> Marko
>>
>>> Best regards,
>>> Tony.
--
There's nothing wrong with America that a good erection wouldn't cure.
-- David Mairowitz
1. exec accepts a string
2. the string is a concatenation of 3 strings:
- "python DoSomething(\""
- s:SNR
- "MyCallback\", ...)"
The double quote is preceeded by a backslash in the first and the third string
and is treated as a part of the string. We could rewrite them as:
- 'python DoSomething("'
- 'MyCallback", ...)'
s:SNR is the SID of the script, I think it looks sth. like '42_'.
Now we concatenate:
'python DoSomething("' . '42_' . 'MyCallback", ...)'
to get
'python DoSomething("42_MyCallback", ...)'
which is a perfectly valid string for exec (but not for Python, because of the
dots which should be replaced by the actual parameters, if any).
Marko
This is equivalent to the above. Note that Vim treats "" and '' strings
differently: single-quote strings are accepted as they are written while
double-quote strings undergo some fancy parsing and escaping. The following
strings are equivalent:
"\""
'"'
Marko
you forgot to backslash-escape the opening quote of "MyCallback". Third
edition. Are you blind or what? Or do you need some coffee?
>
> Marko
>
Best regards,
Tony.
--
"It was pleasant to me to get a letter from you the other day. Perhaps
I should have found it pleasanter if I had been able to decipher it. I
don't think that I mastered anything beyond the date (which I knew) and
the signature (which I guessed at). There's a singular and a perpetual
charm in a letter of yours; it never grows old, it never loses its
novelty .... Other letters are read and thrown away and forgotten, but
yours are kept forever -- unread. One of them will last a reasonable
man a lifetime."
-- Thomas Aldrich
Sorry, it's me. You're right, I'm wrong. The string ends at the second
quote after the first backslash.
>
>>
>> Marko
>>
>
> Best regards,
> Tony.
--
Please try to limit the amount of "this room doesn't have any bazingas"
until you are told that those rooms are "punched out". Once punched
out, we have a right to complain about atrocities, missing bazingas,
and such.
-- N. Meyrowitz
Not blind. No need for coffee. Thanks :)
Let me describe it again:
exec "python DoSomething(\"" . s:SNR . "MyCallback\", ...)"
"python ... the opening quote for a Vim string
DoSomething(\" ... the opening quote for a Python string
" ... the closing quote for the Vim string
. s:SNR . ... concatenation
"Mycallback ... the opening quote for the 2nd Vim string
\" ... the closing quote for the Python string
, ...)" ... the closing quote for the 2nd Vim string
It's all there.
Marko