pdb

C#&.NET高级面试题

大兔子大兔子 提交于 2019-11-27 12:07:49
文章转载自: http://www.pythonheidong.com/blog/article/2557/ 转自 http://chaoyouzhuo.blog.163.com/blog/static/1263760012011109114131316/ 1. DateTime.Parse(myString); 这段代码有什么问题? A:区域信息即CultureInfo没有指定。如果不指定的话,它将采用默认的机器级的设置(见:控制面板->区域和语言选项)并使用这个设置来决定这个字符串即myString怎样被解释。所以如果你传入“5/2/2005”且你的区域设置为En-US,则它会被解释为May 2nd 2005,但是如果你的区域设置为Hindi-India,则它会被解释为5th Feb 2005! 参考下面的代码示例: string sDate = "5/2/2005"; //本意是2005年5月2号 DateTime[] dt = new DateTime[3]; CultureInfo[] cf = new CultureInfo[3]; cf[0] = new CultureInfo("en-US", true); //指定为en-US,字符串将被解释为“MM/DD/YYYY” dt[0] = DateTime.Parse(sDate, cf[0],

Simpler way to put PDB breakpoints in Python code?

橙三吉。 提交于 2019-11-27 10:26:52
Just a convenience question. I've been a bit spoiled with debuggers in IDEs like Visual Studio and XCode. I find it a bit clumsy to have to type import pdb; pdb.set_trace() to set a breakpoint (I'd rather not import pdb at the top of the file as I might forget and leave it in). Is there a simpler way of setting a breakpoint in Python code, as straightforward and unobtrusive as what you see in an IDE? mdeous You can run your program into pdb from the command line by running python -m pdb your_script.py It will break on the 1st line, then you'll be able to add a breakpoint wherever you want in

What is the right way to debug in iPython notebook?

元气小坏坏 提交于 2019-11-27 10:04:39
As I know, %debug magic can do debug within one cell. However, I have function calls across multiple cells. For example, In[1]: def fun1(a) def fun2(b) # I want to set a breakpoint for the following line # return do_some_thing_about(b) return fun2(a) In[2]: import multiprocessing as mp pool=mp.Pool(processes=2) results=pool.map(fun1, 1.0) pool.close() pool.join What I tried: I tried to set %debug in the first line of cell-1. But it enter into debug mode immediately, even before executing cell-2. I tried to add %debug in the line right before the code return do_some_thing_about(b) . But then

Step-by-step debugging with IPython

你。 提交于 2019-11-27 09:57:13
From what I have read, there are two ways to debug code in Python: With a traditional debugger such as pdb or ipdb . This supports commands such as c for continue , n for step-over , s for step-into etc.), but you don't have direct access to an IPython shell which can be extremely useful for object inspection. Using IPython by embedding an IPython shell in your code. You can do from ipython import embed , and then use embed() in your code. When your program/script hits an embed() statement, you are dropped into an IPython shell. This allows the full inspection of objects and testing of Python

Python Unit Testing: Automatically Running the Debugger when a test fails

孤者浪人 提交于 2019-11-27 09:30:12
问题 Is there a way to automatically start the debugger at the point at which a unittest fails? Right now I am just using pdb.set_trace() manually, but this is very tedious as I need to add it each time and take it out at the end. For Example: import unittest class tests(unittest.TestCase): def setUp(self): pass def test_trigger_pdb(self): #this is the way I do it now try: assert 1==0 except AssertionError: import pdb pdb.set_trace() def test_no_trigger(self): #this is the way I would like to do

cannot override sys.excepthook

主宰稳场 提交于 2019-11-27 09:29:19
I try to customize behavior of sys.excepthook as described by the recipe . in ipython: :import pdb, sys, traceback :def info(type, value, tb): : traceback.print_exception(type, value, tb) : pdb.pm() :sys.excepthook = info :-- >>> x[10] = 5 ------------------------------------------------- Traceback (most recent call last): File "<ipython console>", line 1, in <module> NameError: name 'x' is not defined >>> pdb.pm() is not being called. It seems that sys.excepthook = info doesn't work in my python 2.5 installation. ipython, which you're using instead of the normal Python interactive shell,

Visual Studio 2010 “Cannot find or open the PDB file”

断了今生、忘了曾经 提交于 2019-11-27 09:03:05
I try to debug a program in Visual Studio 10, but I have a problem with breakpoints. I put *.pdb files corresponding to the *.dll files to the same directory. But while checking modules, I see that each DLL file is signed as Cannot find or open the PDB file . How can I fix this problem? How can I check where *.pdb files are expected to be located? The modules (Ctrl-D, M) is a good place to sort out whats going on so you're in the right area. Right-click the module/dll you expected the pdb to be found for and select Symbol Load Information It should look in the same directory as your dll to

Remove PDB references from released file

妖精的绣舞 提交于 2019-11-27 08:54:21
I use to take always a look at the final binary executable or dll after debugging and creating a file with any IDE. Now I am trying Visual C++ 2010, in the search for the best release, without trash or unnecessary references. So, I created a new solution with two projects: a executable and its dll. VC++ created a lot of intermediary files between the code and the final file. I opened the .exe and the .dll with a hexadecimal editor and saw something that I don't like. Somewhere inside the file there's an absolute path to the .PDB file. Why? How can I remove it from VC++? There must be some pre

How to debug a Python module run with python -m from the command line?

十年热恋 提交于 2019-11-27 05:48:41
问题 I know that a Python script can be debugged from the command line with python -m pdb my_script.py if my_script.py is a script intended to be run with python my_script.py . However, a python module my_module.py should be run with python -m my_module . Even scripts that contain relative imports should be run with python -m . How can I run python -m my_module under pdb 's control? The following does not work : python -m pdb -m my_module 回答1: You can't do it now, because -m terminates option list

Is it possible to go into ipython from code?

落花浮王杯 提交于 2019-11-27 04:58:11
问题 For my debugging needs, pdb is pretty good. However, it would be much cooler (and helpful) if I could go into ipython . Is this thing possible? 回答1: There is an ipdb project which embeds iPython into the standard pdb, so you can just do: import ipdb; ipdb.set_trace() It's installable via the usual pip install ipdb . ipdb is pretty short, so instead of easy_installing you can also create a file ipdb.py somewhere on your Python path and paste the following into the file: import sys from IPython