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


Groups > comp.lang.python > #80253

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

Path csiph.com!usenet.pasdenom.info!news.franciliens.net!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'interpreter': 0.05; 'subject:Python': 0.06; 'interpreter.': 0.07; 'python3': 0.07; 'sys': 0.07; 'mixed': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'runs': 0.10; 'python': 0.11; 'bytecode': 0.16; 'conclusion:': 0.16; 'foo()': 0.16; 'function?': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'runtime.': 0.16; 'src': 0.16; 'subject:object': 0.16; 'subject:stuck': 0.16; 'subject:python': 0.16; 'extensions': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'module': 0.19; 'import': 0.22; 'separate': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'visible': 0.24; 'compiled': 0.26; 'pass': 0.26; 'header:X -Complaints-To:1': 0.27; 'function': 0.29; "i'm": 0.30; 'code': 0.31; 'bunch': 0.31; 'could': 0.34; 'something': 0.35; 'similar': 0.36; 'so,': 0.37; 'two': 0.37; 'to:addr:python-list': 0.38; 'expect': 0.39; 'does': 0.39; 'embedded': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'times': 0.62; 'act': 0.63; 'here': 0.66; 'containing': 0.69; 'saw': 0.77; 'functions:': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Python, VIM: namespace, scope, life of a python object stuck in a << HERE
Date Wed, 05 Nov 2014 08:44:13 +0100
Organization None
References <m3chpj$7qk$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p57bd9e98.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15482.1415173467.18130.python-list@python.org> (permalink)
Lines 71
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415173467 news.xs4all.nl 2847 [2001:888:2000:d::a6]:36046
X-Complaints-To abuse@xs4all.nl
X-Received-Body-CRC 3972513786
X-Received-Bytes 4554
Xref csiph.com comp.lang.python:80253

Show key headers only | View raw


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.

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

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

csiph-web