<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def safe_open(filename, *args, **kwargs):
 """Open a file safely, ensuring that its directory exists. :API: public """

  safe_mkdir_for(filename)
  return open(filename, *args, **kwargs)