Miscellaneous
Part I: Module
Import a source file created by ourselves but it’s not in the current working directory
append the target working directory into system path
# Example import sys sys.path.append('/Users/lei/Desktop') import mymax # mymax is self-defined function stored in Desktop mymax.mymax(1,5)
List all local packages
import pip # needed to use the pip functions for i in pip.get_installed_distributions(local_only=True): print(i)
more
Part II: Data structure
When copy a sequence, such as list, tuple, string, integer, etc, use the slicing operation to make a copy. Since copy a sequence is only pointing to a directory where the original sequence is stored. If the original sequence is changed, the copied sequence will also be updated.
new_list = list[:]
more
Last updated
Was this helpful?