Miscellaneous

Part I: Module

  1. 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)
  2. List all local packages

    • import pip # needed to use the pip functions 
      for i in pip.get_installed_distributions(local_only=True):
          print(i)
  3. more

Part II: Data structure

  1. 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[:]
  2. more

Last updated