docstr: write the image_names and label_names on the txt file like this:
  
  images/image_name labels/label_name
  ...
  
  or this when label is None.
  
  images/image_name
  ...
docstr_tok: ["write","the","image_names","and","label_names","on","the","txt","file","like","this",":","images\/image_name","labels\/label_name","...","or","this","when","label","is","None",".","images\/image_name","..."]
code: def write_txt(txt, image_names, label_names=None):
      """
      write the image_names and label_names on the txt file like this:
  
      images/image_name labels/label_name
      ...
  
      or this when label is None.
  
      images/image_name
      ...
  
      """
      with open(txt, "w") as f:
          for i in range(len(image_names)):
              if label_names is not None:
                  string = "{} {}\n".format(
                      "images/" + image_names[i],
                      "labels/" + label_names[i],
                  )
              else:
                  string = "{}\n".format("images/" + image_names[i])
  
              f.write(string)
  
      print("successfully write to {}".format(txt))
  
imports: import os
  import os.path
  import sys
  import time
  import glob
  import numpy
  import nibabel
  import SimpleITK
  from tqdm import tqdm
  import json
  from medicalseg.utils import get_image_list
  from tools.preprocess_utils import uncompressor, global_var, add_qform_sform, join_paths
label_desc: Use image node_id 8 for calling the Prep obj's underlying member method code with example usage: obj.write_txt(txt, image_names, label_names) without return types