├── .gitignore ├── LICENSE ├── README.rst ├── example1.py ├── example2.py ├── example3.py ├── example4.py ├── example4display.py ├── example4unt.py ├── example5.py ├── fileutil.py └── util.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.egg 2 | *.egg-info 3 | .eggs/ 4 | __pycache__/ 5 | *.py[cod] 6 | *$py.class 7 | *~ 8 | .*.swp 9 | .coverage 10 | .coverage.* 11 | .DS_Store 12 | coverage.xml 13 | coverage-*.xml 14 | build/ 15 | .cache/ 16 | dist/ 17 | .idea/ 18 | distribute-*.tar.gz 19 | env*/ 20 | .tox/ 21 | venv/ 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Nathan Jennings 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Python Debugging with pdb 2 | ========================= 3 | 4 | This is the source code for a pdb tutorial I wrote for Real Python: 5 | `Python Debugging with pdb `_. 6 | 7 | Requirements 8 | ------------ 9 | 10 | - `Python `_ 3.6 or later. 11 | 12 | License 13 | ------- 14 | 15 | The MIT License. See `LICENSE `_. 16 | -------------------------------------------------------------------------------- /example1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | filename = __file__ 4 | import pdb; pdb.set_trace() 5 | print(f'path = {filename}') 6 | -------------------------------------------------------------------------------- /example2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | 5 | 6 | def get_path(filename): 7 | """Return file's path or empty string if no path.""" 8 | head, tail = os.path.split(filename) 9 | import pdb; pdb.set_trace() 10 | return head 11 | 12 | 13 | filename = __file__ 14 | print(f'path = {get_path(filename)}') 15 | -------------------------------------------------------------------------------- /example3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | 5 | 6 | def get_path(filename): 7 | """Return file's path or empty string if no path.""" 8 | head, tail = os.path.split(filename) 9 | return head 10 | 11 | 12 | filename = __file__ 13 | import pdb; pdb.set_trace() 14 | filename_path = get_path(filename) 15 | print(f'path = {filename_path}') 16 | -------------------------------------------------------------------------------- /example4.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import util 4 | 5 | filename = __file__ 6 | import pdb; pdb.set_trace() 7 | filename_path = util.get_path(filename) 8 | print(f'path = {filename_path}') 9 | -------------------------------------------------------------------------------- /example4display.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | 5 | 6 | def get_path(fname): 7 | """Return file's path or empty string if no path.""" 8 | import pdb; pdb.set_trace() 9 | head, tail = os.path.split(fname) 10 | for char in tail: 11 | pass # Check filename char 12 | return head 13 | 14 | 15 | filename = __file__ 16 | filename_path = get_path(filename) 17 | print(f'path = {filename_path}') 18 | -------------------------------------------------------------------------------- /example4unt.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | 5 | 6 | def get_path(fname): 7 | """Return file's path or empty string if no path.""" 8 | import pdb; pdb.set_trace() 9 | head, tail = os.path.split(fname) 10 | for char in tail: 11 | pass # Check filename char 12 | return head 13 | 14 | 15 | filename = __file__ 16 | filename_path = get_path(filename) 17 | print(f'path = {filename_path}') 18 | -------------------------------------------------------------------------------- /example5.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import fileutil 4 | 5 | 6 | def get_file_info(full_fname): 7 | file_path = fileutil.get_path(full_fname) 8 | return file_path 9 | 10 | 11 | filename = __file__ 12 | filename_path = get_file_info(filename) 13 | print(f'path = {filename_path}') 14 | -------------------------------------------------------------------------------- /fileutil.py: -------------------------------------------------------------------------------- 1 | def get_path(fname): 2 | """Return file's path or empty string if no path.""" 3 | import os 4 | import pdb; pdb.set_trace() 5 | head, tail = os.path.split(fname) 6 | return head 7 | -------------------------------------------------------------------------------- /util.py: -------------------------------------------------------------------------------- 1 | def get_path(filename): 2 | """Return file's path or empty string if no path.""" 3 | import os 4 | head, tail = os.path.split(filename) 5 | return head 6 | --------------------------------------------------------------------------------