#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2017
    Posts
    1
    Rep Power
    0

    NameError: name '__file__' is not defined


    HI

    I'm getting this error after I run stacked denoising autoencoder code http://deeplearning.net/tutorial/code/SdA.py code , how this error can be fixed ?


    NameError Traceback (most recent call last)
    <ipython-input-9-94013ff577e5> in <module>()
    466
    467 if __name__ == '__main__':
    --> 468 test_SdA()

    <ipython-input-9-94013ff577e5> in test_SdA(finetune_lr, pretraining_epochs, pretrain_lr, training_epochs, dataset, batch_size)
    375
    376 print(('The pretraining code for file ' +
    --> 377 os.path.split(__file__)[1] +
    378 ' ran for %.2fm' % ((end_time - start_time) / 60.)), file=sys.stderr)
    379 # end-snippet-4

    NameError: name '__file__' is not defined


    could you please help me
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,921
    Rep Power
    509
    __file__

    __cached__

    __file__ is optional. If set, this attribute’s value must be a string. The import system may opt to leave __file__ unset if it has no semantic meaning (e.g. a module loaded from a database).
    In my experiment, __file__ was defined when investigated from a loaded module, if I wrote it, and undefined in the interactive session. My fie p.py prints __file__ .
    Code:
    >>> import p
    /tmp/p.py
    >>> import sys
    >>> sys.__file__
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: module 'sys' has no attribute '__file__'
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo