3

I have a specific question concerning the python (Python 2.7) IDE Spider (2.3.5.2)

Today I noticed that there is a difference in running my script as a whole, i.e. when I press F5. Or when I run just a single line or selection, by pressing F9.

I noticed this difference, when running specific syntax containing __file__ When I would run the script by line (by pressing F9), I would get the error NameError: name '__file__' is not defined Whereas if I would run the script as a whole (by pressing F5) I would receive no such error, and was able to retrieve my file name using __file__

My question is: What is the difference between running by pressing F5 and running by pressing F9?

Note: there is probably some jargon that I'm missing which would allow me to ask my question better. Please edit the question if needed. I get the feeling I'm dealing with some very basic stuff. If anyone has some good tutorials or documentation, I would love to read it.

Supun Wijerathne
  • 11,964
  • 10
  • 61
  • 87
J.A.Cado
  • 715
  • 5
  • 13
  • 24

1 Answers1

3

It is normal that you find __file__ undefined when running by single line because:

When a module is loaded in Python, __file__ is set to its name. You can then use that with other functions to find the directory that the file is located in.

There is no loaded module when you run by single line.

Assem
  • 11,574
  • 5
  • 59
  • 97