|
1 | 1 | Debugging
|
2 | 2 | ---------
|
3 | 3 |
|
4 |
| -Debugging is also something which once mastered can greatly enhance your |
5 |
| -bug hunting skills. Most of the newcomers neglect the importance of the |
6 |
| -Python debugger (``pdb``). In this section I am going to tell you only a |
7 |
| -few important commands. You can learn more about it from the official |
8 |
| -documentation. |
| 4 | +Debugging é algo que uma vez compreendido pode te ajudar enormemente |
| 5 | +em sua capacidade de encontrar erros (bugs). A maioria dos iniciantes |
| 6 | +negligencia a importancia do Python debugger (``pdb``). Nesta seção, |
| 7 | +eu vou mostrar alguns comandos importantes. Você pode aprender mais |
| 8 | +sobre isso a partir da documentação oficial. |
9 | 9 |
|
10 |
| -**Running from commandline** |
| 10 | +**Rodando a partir da linha de comando** |
11 | 11 |
|
12 |
| -You can run a script from the commandline using the Python debugger. |
13 |
| -Here is an example: |
| 12 | +Quando você roda um script a partir da linha de comando usando um |
| 13 | +Python debugger. Aqui está um exemplo: |
14 | 14 |
|
15 | 15 | .. code:: python
|
16 | 16 |
|
17 | 17 | $ python -m pdb my_script.py
|
18 | 18 |
|
19 |
| -It would cause the debugger to stop the execution on the first statement |
20 |
| -it finds. This is helpful if your script is short. You can then inspect |
21 |
| -the variables and continue execution line-by-line. |
| 19 | +Este comando faz com que o debuuger pare a execução do código na primeira |
| 20 | +linha de comando que ele encontrar. Isso é muito útil se o seu script for |
| 21 | +pequeno. Você pode inspecionar as variáveis e continuar a execução linha |
| 22 | +por linha. |
22 | 23 |
|
23 |
| -**Running from inside a script** |
| 24 | +**Rodando de dentro de um script** |
24 | 25 |
|
25 |
| -You can set break points in the script itself so that you can inspect |
26 |
| -the variables and stuff at particular points. This is possible using the |
27 |
| -``pdb.set_trace()`` method. Here is an example: |
| 26 | +Você pode inserir pontos de quebra (break points) dentro do próprio script |
| 27 | +para que você inspecione as variáveis e demais itens em pontos específicos do |
| 28 | +seu código. Isso é possível utilizando o método ``pdb.set_trace()``. |
| 29 | +Aqui está um exemplo: |
28 | 30 |
|
29 | 31 | .. code:: python
|
30 | 32 |
|
31 | 33 | import pdb
|
32 | 34 |
|
33 | 35 | def make_bread():
|
34 | 36 | pdb.set_trace()
|
35 |
| - return "I don't have time" |
| 37 | + return "Eu não tenho tempo" |
36 | 38 |
|
37 | 39 | print(make_bread())
|
38 | 40 |
|
39 |
| -Try running the above script after saving it. You would enter the |
40 |
| -debugger as soon as you run it. Now it's time to learn some of the |
41 |
| -commands of the debugger. |
| 41 | +Tente rodar o script acima após salvá-lo. Você irá entrar no debugger |
| 42 | +assim que você o rodar. Agora é hora de aprender alguns dos comandos |
| 43 | +do debugger. |
42 | 44 |
|
43 |
| -**Commands:** |
| 45 | +**Comandos:** |
44 | 46 |
|
45 |
| -- ``c``: continue execution |
46 |
| -- ``w``: shows the context of the current line it is executing. |
47 |
| -- ``a``: print the argument list of the current function |
48 |
| -- ``s``: Execute the current line and stop at the first possible |
49 |
| - occasion. |
50 |
| -- ``n``: Continue execution until the next line in the current function |
51 |
| - is reached or it returns. |
| 47 | +- ``c``: continua a execução |
| 48 | +- ``w``: mostra o contexto da linha atual que ele estpa executando |
| 49 | +- ``a``: mostra a lista de argumentos da função atual |
| 50 | +- ``s``: executa a linha atual e para a execução assim que possível |
| 51 | +- ``n``: continua a execução até a próxima linha da função atual ou o seu retorno |
52 | 52 |
|
53 |
| -The difference between ``n``\ ext and ``s``\ tep is that step stops |
54 |
| -inside a called function, while next executes called functions at |
55 |
| -(nearly) full speed, only stopping at the next line in the current |
56 |
| -function. |
| 53 | +A diferença entre ``n``\ ext e ``s``\ tep é que o método step para a execução |
| 54 | +dentro da função que foi chamada, enquanto o método next executa a função |
| 55 | +chanada em (quase) velocidade total, apenas parando na próxima linha da função |
| 56 | +onde o pdb foi inserido. |
57 | 57 |
|
58 |
| -These are just a few commands. ``pdb`` also supports post mortem. It is |
59 |
| -also a really handy function. I would highly suggest you to look at the |
60 |
| -official documentation and learn more about it. |
| 58 | +Esses são apenas alguns comandos. ``pdb`` também suporta post mortem. Esta é |
| 59 | +realmente uma função muito útil. Eu também sugiro que você olhe a documentação |
| 60 | +oficial e aprenda mais sobre isso. |
0 commit comments