Issue with simple code

The variable file is not defined. You need to define it like this:

import os
file = "c:\myprogram\myfile.txt"
script_directory = os.path.dirname(os.path.abspath(file))
os.chdir(script_directory)
  1. And why are you changing the directory when you are already in that directory? That seems unnecessary.
  2. What are you trying to achieve? This looks like a stub program, or template for other programs that you always start with.

Help us help you. Read this link first and learn how to format code so we can help you better. Formatting code Do not use a screen shot of your code, instead paste your code in as preformatted code, as some of us will copy and paste the code to get it to work for you, so you can learn from this. You will get more help this way.