When running a python with pdb, like
python -m pdb myscript.py some_arg another_arg
I don't want it to ask me what to do. I want it to "continue" immediately. Is there a way to do that? Is there a way to do that without editing the global pdb configuration in ~/.pdbrc?
python -m pdb -c continue myscript.py some_argument another_argument
From pdb docs:
pdb.py accepts a -c option that executes commands as if given in a .pdbrc file, see Debugger Commands.
Related
Is it possible to specify commands for a breakpoint in a .pdbrc file?
I tried this in my .pdbrc:
break myscript.py:1
commands 1
!print('hello, world!')
continue
But when I run python -m pdb myscript.py, I am prompted to enter the commands interactively, instead of them being set from .pdbrc:
>>> python -m pdb myscript.py
Breakpoint 1 at myscript.py:1
(com)
Only after I enter the commands does pdb finish executing the .pdbrc:
(com) continue
hello, world!
# Script runs
Obviously this severely constrains what kind of automated debugging setup is possible with the .pdbrc file. Is there a solution?
Typing python -i file.py at the command line runs file.py and then drops into the python terminal preserving the run environment.
https://docs.python.org/3/using/cmdline.html
Is there an equivalent in R?
I may be misinterpreting what python -i file.py does, but try:
From inside R, at the terminal, you can do:
source('file.R')
and it will run file.R, with the global environment reflecting what was done in file.R
If you're trying to run from the command line, review this post
I need to run a python script that changes user, sets a enviroment variable and executes a command and return the output.
1.) The way I am currently doing this is I am creating a shell script that does this for me:
tmpshell.sh
su - grid -c "echo +ASM1 | . oraenv; asmcmd volinfo -a"
The command fails because the environment is not being set.
2.) The second way I tried was by changing user is python script itself and then creating the shell script.
tmp.py
os.system('su - grid')
TMPFILE="/tmp/tmpfile.sh"
filehandle=open(TMPFILE,'w')
filehandle.write('+ASM1|. oraenv')
filehandle.write('asmcmd volinfo -a')
filehandle.close()
os.chmmod(TMPFILE,0755)
Here the problem is that the python script changes the user but the rest of the script doesn't run until I enter exit.
OUTPUT
[root#odadev1 oakvmclientlib]# python test.py
[grid#odadev1 ~]$ exit
[root#odadev1 oakvmclientlib]#
Any suggestions/better ways to do this ??
p.s.(edit) ". oraenv" is for setting the environment and +ASM1 is the environment variable it expects.
Try something like this:
$ sudo -u grid sh -c ". oraenv; echo +ASM1|asmcmd volinfo -a"
This will launch a shell as user grid, set up the environment in it and execute the command. I'm not sure what the second part of your command does, though - I suspect you want to pipe +ASM1 into the standard input of asmcmd, but you haven't given enough context to be sure.
I wrote a very simple vim plugin and python script trying to test some communication between the two. My vim-script looks like this:
function! HelloWorld()
silent :!python helloworld.py
endf
nmap <C-P> :call HelloWorld()<CR>
then my python script looks like this:
import os;
os.system( 'mvim --servername VIM -u NONE -U NONE --remote-send \"<C-\\\\><C-N>:echo \'Hello World!\'<CR>\"' )
If I am in vim and press , use the ":call HelloWorld()" command, or just type ":!python helloworld.py" from the same or another mvim or vim instance, nothing happens. However, if I call the script from the command line separately, mvim responds appropriately: shows "Hello World!" along the bottom.
Does anyone have any idea why it is not working when called from vim?
Try replacing
silent :!python helloworld.py
with
silent :!(sleep 0.5s && python helloworld.py) &
redraw!
(the point is in returning to vim before remote command arrives). If it works, then the problem is in processing remote commands while receiving shell output. You can also try another workarounds:
call system('python helloworld.py')
,
call system('python helloworld.py &')
and
pyfile helloworld.py
(Note that the last one requires vim compiled with +python feature and also alters the state of python interpreter used by vim).
By the way, use system() call instead of ! when you don't want to see the script output. Also use redraw! after silent !.
I've got python script (ala #! /usr/bin/python) and I want to debug it with pdb. How can I pass arguments to the script?
I have a python script and would like to debug it with pdb. Is there a way that I can pass arguments to the scripts?
python -m pdb myscript.py arg1 arg2 ...
This invokes pdb as a script to debug another script. You can pass command-line arguments after the script name. See the pdb doc page for more details.
usually I use ipython
-i
If running code from the command line, become interactive afterwards.
It is often useful to follow this with `--` to treat remaining flags as
script arguments.
ipython --pdb -i -- test.py -a
python3 -m pdb myscript.py -a val if using argparse with flag "a" and value "val"
If, like me, you prefer the more graphical pudb debugger, you can pass the arguments of your script directly by doing:
pudb myscript.py arg1 arg2 ...
Indeed, invoking:
python -m pudb myscript.py arg1 arg2 ...
won't work will return with the following error:
No module named pudb.__main__; 'pudb' is a package and cannot be directly executed