On Thu, Jan 16, 2014 at 01:45:24AM -0800, 驼峰 wrote:
> Hi, All
> 
> [...]
>
> I run into one issue when running with :pyfile command.
> Traceback (most recent call last):
>   File "<string>", line 1, in <module>
>   File "c:/test.py", line 3, in <module>
>     print os.path.dirname(os.path.abspath(__file__))
> NameError: name '__file__' is not defined
> 
> Is it a bug of vim? or how can I make it works.

I don't think it is a bug.

Because :pyfile just "runs" your file, not "imports" it. That is, you
have __name__ set to '__main__'. Try to put "print(__name__)" into your
Python file and you'll see it.

You can import it with ":py import test" if you insist on __file__.

Note that __file__ is not guaranteed to be set even when you import it
as a module. The Python doc says:

> The loader may set the __file__ attribute of the module. If set, this
> attribute’s value must be a string. The loader may opt to leave
> __file__ unset if it has no semantic meaning (e.g. a module loaded
> from a database).

-- 
Best regards,
lilydjwg

-- 
-- 
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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Raspunde prin e-mail lui