简体   繁体   中英

How can I start the Python debugger from the command line without a script argument?

I'd like to poke around with some Python syntax, but don't want to write a full script. In Perl I would say

perl -demo

What's the equivalent in Python?

The easiest I've found is

python -im pdb /dev/null

but that seems long-winded, especially when showing someone else.

Edit1:

For those confused about the debugger, here is the help after invoking it as above:

> pydemo
> /dev/null(1)<module>()
(Pdb) h

Documented commands (type help <topic>):
========================================
EOF    bt         cont      enable  jump  pp       run      unt   
a      c          continue  exit    l     q        s        until 
alias  cl         d         h       list  quit     step     up    
args   clear      debug     help    n     r        tbreak   w     
b      commands   disable   ignore  next  restart  u        whatis
break  condition  down      j       p     return   unalias  where 

Miscellaneous help topics:
==========================
exec  pdb

Undocumented commands:
======================
retval  rv

You can open the Python IDLE and import pdb like so. From the command line, open the IDLE with python and then import pdb like you would any other module with import pdb . You can then test some snippet of code with pdb.run('ENTER CODE SNIPPET HERE') .

You can run the pdb command direcly (not using python -m pdb ), which is shorter:

% pdb /dev/null

If all you want is "to poke around with some Python syntax", you don't need a debugger for that, just run python :

% python
Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
>>> print "That was easy!"
That was easy!
>>> 

You might be also be interested in using ipython , which is a very popular, feature-rich, interactive python shell, and ipdb which is a pdb-like debugger with a bunch of ipython features.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM