2015年6月17日 星期三

[ Python 常見問題 ] How do I manipulate a variable whose name conflicts with PDB commands?

Source From Here
Question
My code is, for better or worse, rife with single letter variables (it's physics stuff, so those letters are meaningful), as well as NumPy's, which I'm often interacting with. When using the Python debugger, occasionally I'll want to look at the value of, say, n. However, when I hit n, that's the PDB command for(n)ext, which has a higher priority. print n works around looking at it, but how can I set it?

How-To
Use an exclamation mark ! before a statement to have it run. Consider we have a test.py
- test.py
  1. #!/usr/bin/env python  
  2. print("foo")  
  3. print("bar")  
Run it this way:
# python -m pdb test.py
> /home/user/test.py(1)()
-> print('foo')
(Pdb) !n = 77
(Pdb) !n
77
(Pdb) n
foo
> /home/user/test.py(2)()
-> print('bar')

(Pdb)


沒有留言:

張貼留言

[ Java 文章收集 ] 局部敏感哈希 (Locality-Sensitive Hashing, LSH) 方法介紹

Source From  Here   Preface   本文主要介紹一種用於海量高維數據的近似最近鄰快速查找技術—— 局部敏感哈希  ( Locality-Sensitive Hashing, LSH ),內容包括了 LSH 的原理、LSH 哈希函數集、以及 LSH 的一...