Updated Python code to handle empty directive node

Updated python