Closed guy-attali closed 1 year ago
Hi! Thanks for the feedback and I'm glad that you find the extension useful.
As for running the script, did you mean to run the .py
as a script and not as a module? I.e., skipping __name__ == '__main__'
?
If so, from IPython %run documentation, the -n
option might be the solution.
This is supported via the Ipython: Run Arguments
setting of the extension. The default keyboard mapping for run
command currently are:
f5
: do %run file.py -cli
with -cli
the file command line arguments shift + f5
: do %run -args file.py -cli
with -args
the %run
command line arguments So if your script.py
got
# ... other code above
if __name__ == '__main__':
print('Run __main__')
else:
print('Skip __main__')
Change or add -n
to setting Ipython: Run Arguments
list. Using shift + f5
for running the file should print to the terminal something like this:
In [1]: %run -n "script.py"
....
Out[1]: ...
Skip __main__
Now try just f5
, you should get
In [1]: %run "script.py"
....
Out[1]: ...
Run __main__
Hi! Thanks for the feedback and I'm glad that you find the extension useful.
As for running the script, did you mean to run the
.py
as a script and not as a module? I.e., skipping__name__ == '__main__'
?If so, from IPython %run documentation, the
-n
option might be the solution.This is supported via the
Ipython: Run Arguments
setting of the extension. The default keyboard mapping forrun
command currently are:
f5
: do%run file.py -cli
with-cli
the file command line argumentsshift + f5
: do%run -args file.py -cli
with-args
the%run
command line argumentsSo if your
script.py
got# ... other code above if __name__ == '__main__': print('Run __main__') else: print('Skip __main__')
Change or add
-n
to settingIpython: Run Arguments
list. Usingshift + f5
for running the file should print to the terminal something like this:In [1]: %run -n "script.py" .... Out[1]: ... Skip __main__
Now try just
f5
, you should getIn [1]: %run "script.py" .... Out[1]: ... Run __main__
Hi, does this solves your issue? Thanks.
Yes! I'm sorry, I've missed that option. Thank you very much!
Hey! Great plugin. was thinking maybe an option to run the file as a module, so it won't run the main() function. To do so, run ipython with -m current_file and drop the %run part.