yield
andyield from
This blog post gives a good introduction of how to use
yield
andyield from
in Python.add local path with conda
Similar to a normal IDE where a project root is required to import local modules, with emacs and lsp, I first need to include the path in the environment. To check current local paths, open a Python interpreter and use
1 2 3
import sys for p in sys.path: print(p)
To add a path with conda, use
conda develop <path>
inside the environment, note that redundant paths should be avoided, e.g., if both~/src/
and~/src/modulea
are present in the paths, there could be a module resolvation issue. After adding the path, need to activate conda environment and ananconda mode in emacs. To remove a path, useconda develop --uninstall <path>
.pdb
pdb
is a python debugger in emacs, to startpdb
I first need to be in the buffer of the specific file, the keywords are similar to gdb:s
goes into a function,n
skips entering inner functions,b
lists current breakpoints andb <line-number>
set a breakpoint at the given line,c
continues the execution until reaching a breakpoint. Sometimes, there is error in the python interpreter but works fine inpdb
, restart the python interpreter process would likely solve the problem.
Python hints
This post is licensed under CC BY 4.0 by the author.