0

I decided to start using Eclipse to code in python, but I am having problems getting the filename of the current script. To get the current filenam I use:

#!/usr/bin/env python2.7
import os
os.path.basename(__file__)

My code works flawlessly when using the bash terminal or Geany, but with Eclipse Interactive Console I get:

 name '__file__' is not defined

Any ideas?

UPDATE

When I run my code using python filename.py it works perfectly, but when I try running it from the python or ipython consoles I get the same error

jorgehumberto
  • 1,047
  • 5
  • 15
  • 33

1 Answers1

0

Ok, found an alternative method that works with PyDev's interactive console from:

How to properly determine current script directory in Python?

The solution is:

#!/usr/bin/env python2.7
import inspect
filename = inspect.getframeinfo(inspect.currentframe()).filename.split('/')[-1]
Community
  • 1
  • 1
jorgehumberto
  • 1,047
  • 5
  • 15
  • 33