Repository navigation
-i and -c <code>? #994
Description
Activity
The behavior is consistent with running those commands with
python3. Do you see a difference?Well,
python3never prints the banner when using-c.Also,
python3doesn't uses ncurses, so a comparison is not really possible.Since
bpythonuses ncurses, it should do so in all interactive cases, includingbpython -i -c 'from mymodule import *', no?Well,
python3never prints the banner when using-c.In which case does
bpythonprint a banner when using-c?Also,
python3doesn't uses ncurses, so a comparison is not really possible.The goal is that the common command line options behave the same. If they don't, that's a bug. If they are consistent with
python3, it's not.The goal is that the common command line options behave the same. If they don't, that's a bug. If they are consistent with
python3, it's not.Then perhaps a new command line switch (which injects an initial command into the interactive session) would be best.
For the record: both
bpython -i file.pyand settingPYTHONSTARTUP=/path/to/file.pywould work, but for a short simple oneliner, having to create a file is not that convenient. That probably is also the reason of having a-ccommand line switch inpython, although that could be intended for different usecases than interactive sessions.A similar option exists called
--pastethat reads from a file. I see, you'd like this from the command line.--pastepastes from file. In this scenario it doesn't add anything to-i(see above).Pasting from a string would make sense.
If I have gone thru the effort of putting my
from mymodule import *line into a file, then alsobpython -i file.pywould work, as I already said above; or the same work can be off-loaded to the shell (YMMV), e.g. with zsh, there are two ways.- process substitution, but bpython won't work with a fd:
❯ bpython -p <(echo 'from mymodule import *') bpython version 0.24 on top of Python 3.11.4 /opt/homebrew/opt/python@3.11/bin/python3.11 Traceback (most recent call last): File "/opt/homebrew/bin/bpython", line 8, in <module> sys.exit(main()) ^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/bpython/curtsies.py", line 248, in main repl.mainloop(True, paste) File "/opt/homebrew/lib/python3.11/site-packages/bpython/curtsies.py", line 170, in mainloop self.process_event(paste) File "/opt/homebrew/lib/python3.11/site-packages/bpython/curtsiesfrontend/repl.py", line 656, in process_event return self.process_control_event(e) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/bpython/curtsiesfrontend/repl.py", line 681, in process_control_event ctrl_char = compress_paste_event(e) ^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/bpython/curtsiesfrontend/repl.py", line 2228, in compress_paste_event event = paste_event.events[0] ~~~~~~~~~~~~~~~~~~^^^ IndexError: list index out of range- temp file substitution:
❯ bpython -p =(echo 'from mymodule import *') bpython version 0.24 on top of Python 3.11.4 /opt/homebrew/opt/python@3.11/bin/python3.11 >>> from mymodule import * >>>The second form works, but it creates a temp file, so I somewhat still dislike that (I think as a temp file as the very last resort workaround, the apotheosis of failed integration between two programs).
Reading from a fd (named pipe)
<(echo 'from mymodule import *')would be slightly better, but the best I think is supporting also an actual string to paste.Also,
--paste -would not work (in most command line programs, passing-where an input file is expected, means "use stdin"), so it is not possible to useecho 'from mymodule import *' | bpython -p -orbpython -p - <<<'from mymodule import *', but maybe stdin cannot be used like that if we want an interactive session.
Running:
imports the desiret items correctly, but then doesn't drop into the python shell (it quits instead).
Reversing the order of arguments:
has a "strange" effect: the bpython banner (the line with bpython & python version) is not printed anymore, also
$PYTHONSTARTUPis ignored, and all the nice ncurses-based highlighting and completion functionalities are disabled. Is this the intended behavior? Why?Currently, to automate importing a module (e.g. for doing interactive testing during development on that module) I have to put my import line in a file, and do
bpython -i import_mymodule.py. (I tend to use$PYTHONSTARTUPjust for importing some commonly used modules).