Re: Passing python3 file arguments seems failing py3f

17 views
Skip to first unread message

Marius Gedminas

unread,
Feb 10, 2023, 4:01:52 AM2/10/23
to vim...@googlegroups.com
On Thu, Feb 09, 2023 at 11:50:19AM -0800, N i c o l a s wrote:
> Following vim's python help, 
>
> "To pass arguments you need to set sys.argv[] explicitly.  Example: >
>
>     :python sys.argv = ["foo", "bar"]
>     :pyfile myscript.py
> "

That is not a very good example, since sys.argv[0] contains the name of
the script. It would be less confusing if the example said

:python sys.argv = ["myscript.py", "foo", "bar"]
:pyfile myscript.py

> I tried to pass argues to python file as this 
>
> export def PyLinter(): void
>   py3 import sys
>   py3 sys.argv = ["--version"]
>   exe 'py3f ' .. "path/to/somepythonfile.py"
> enddef
>
> It's like as if it had no effect :   py3 sys.argv = ["--version"]

Try

py3 sys.argv = ["somepythonfile.py", "--version"]

Marius Gedminas
--
We have enough youth, how about a fountain of SMART?
signature.asc

Bram Moolenaar

unread,
Feb 10, 2023, 9:51:15 AM2/10/23
to vim...@googlegroups.com, N i c o l a s

> Following vim's python help,
>
>
> *"To pass arguments you need to set sys.argv[] explicitly. Example: > *
> :python sys.argv = ["foo", "bar"]
> :pyfile myscript.py
> *"*
>
>
> I tried to pass argues to python file as this
>
> export def PyLinter(): void
> py3 import sys
> py3 sys.argv = ["--version"]
> exe 'py3f ' .. "path/to/somepythonfile.py"
> enddef
>
> It's like as if it had no effect : py3 sys.argv = ["--version"]
>
> Is it due to python3 file?

It works for me. Typing these commands in sequence:

py3 sys.argv = ["argument"]
py3file /tmp/test.py

With /tmp/test.py:

print("testing pyfile")
print(sys.argv)
print("testing end")

Output:

testing pyfile
['argument']
testing end

This is on Ubuntu, Python 3.10.


--
hundred-and-one symptoms of being an internet addict:
107. When using your phone you forget that you don't have to use your
keyboard.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages