Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80250 > unrolled thread

Python, VIM: namespace, scope, life of a python object stuck in a << HERE

Started byVeek M <vek.m1234@gmail.com>
First post2014-11-05 12:28 +0630
Last post2014-11-05 08:44 +0100
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Python, VIM: namespace, scope, life of a python object stuck in a << HERE Veek M <vek.m1234@gmail.com> - 2014-11-05 12:28 +0630
    Re: Python, VIM: namespace, scope, life of a python object stuck in a << HERE Peter Otten <__peter__@web.de> - 2014-11-05 08:44 +0100

#80250 — Python, VIM: namespace, scope, life of a python object stuck in a << HERE

FromVeek M <vek.m1234@gmail.com>
Date2014-11-05 12:28 +0630
SubjectPython, VIM: namespace, scope, life of a python object stuck in a << HERE
Message-ID<m3chpj$7qk$1@dont-email.me>
If i have two functions:

function! foo()
python3 << HERE
 import mylib
 pass
HERE

function! bar()
python3 << HERE
 import mylib
 pass
HERE

The src says:

 1. Python interpreter main program
 3. Implementation of the Vim module for Python

So, is the python interpreter embedded in vim AND additionally, are separate 
extensions to python provided (wrapper functions for the VIM API). Mixed 
bindings?

How many times is mylib compiled to bytecode and loaded? Does each vimscript 
function get its own mylib - can I instantiate something and expect it to be 
visible in the other function? I have a bunch of leader (\)-functions that 
share similar code and act on the same buffer so I wanted to know if I could 
reuse that data-structure. How many times is the interpreter loaded into 
memory: once obviously at vim runtime.

[toc] | [next] | [standalone]


#80253

FromPeter Otten <__peter__@web.de>
Date2014-11-05 08:44 +0100
Message-ID<mailman.15482.1415173467.18130.python-list@python.org>
In reply to#80250
Veek M wrote:

> If i have two functions:
> 
> function! foo()
> python3 << HERE
>  import mylib
>  pass
> HERE
> 
> function! bar()
> python3 << HERE
>  import mylib
>  pass
> HERE
> 
> The src says:
> 
>  1. Python interpreter main program
>  3. Implementation of the Vim module for Python
> 
> So, is the python interpreter embedded in vim AND additionally, are
> separate extensions to python provided (wrapper functions for the VIM
> API). Mixed bindings?
> 
> How many times is mylib compiled to bytecode and loaded? Does each
> vimscript function get its own mylib - can I instantiate something and
> expect it to be visible in the other function? I have a bunch of leader
> (\)-functions that share similar code and act on the same buffer so I
> wanted to know if I could reuse that data-structure. How many times is the
> interpreter loaded into memory: once obviously at vim runtime.

I'm not a vim user and I only got to work something similar with Python 2.
I put

print "hello"

into mylib.py

and saw when it was printed with the following script:

function! Foo()
python << HERE
import sys
sys.path.append(".")
import mylib
HERE
endfunction

function! Bar()
python << HERE
import mylib
HERE
endfunction

:so vimscript.txt
:call Foo()
--> hello
:call Bar()
--> (nothing)

Conclusion: both functions share the same Python interpreter.
With a function containing

import os
print os.getpid()

you can also see that the Python interpreter runs in the same process as 
vim.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web