# Name Error \_\_file\_\_

**URL:** <https://root-forum.cern.ch/t/name-error-file/41005>\
**Category:** Newbie\
**Tags:** python\
**Created:** [August 15, 2020, 9:04pm UTC](https://root-forum.cern.ch/t/name-error-file/41005 "2020-08-15T21:04:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [August 15, 2020, 9:04pm UTC](https://root-forum.cern.ch/t/name-error-file/41005/1 "2020-08-15T21:04:07Z")

</div>

Hello,  
I am trying to understand how some code works, so I am trying to run it line by line.

```auto
from ROOT import *
import sys
sys.path.append("modules/")
import math

print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
print 'Use as: script.py -b 0 (or 1,2)'
myinput="interactive"
xdir=""
cross=0
expected_pb=1000.
if (len(sys.argv) ==2):
   myinput = sys.argv[1]
   

print 'Mode=',myinput
gROOT.Reset()
figdir="figs/"

```

This all works, until I execute the next line

```auto
epsfig=figdir+ __file__.replace(".py",".eps")

```

Then I get the error

```auto
NameError: name ' __file__' is not defined

```

Does somebody know how to fix this? I am running Python 2.7.16  
Any help is appreciated.  
\_ROOT Version: 6.23/01

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [August 17, 2020, 8:43am UTC](https://root-forum.cern.ch/t/name-error-file/41005/2 "2020-08-17T08:43:12Z")

</div>

Hello,

That line can only work if you run the code as a script, not from the Python prompt. In the Python prompt, there is no attribute ` __file__ ` since no file is being executed.

Cheers,  
Enric
