Bad:Can't finish “os.path.dirname(__file)” in ubuntu (python)(google cloud speech)

Multi tool use


Bad:Can't finish “os.path.dirname(__file)” in ubuntu (python)(google cloud speech)
thanks for helping me!
I just set up google cloud speech and tried to run the code in "Make an audio transcription request" in this website: Quickstart: Using Client Libraries
the code is shown below after I open ubuntu terminal:
export GOOGLE_APPLICATION_CREDENTIALS="/home/luffy/Lumariatuan-xxxxxxxxxxxx.json"
python
import io
import os
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
client = speech.SpeechClient()
# The name of the audio file to transcribe
file_name = os.path.join(
os.path.dirname(__file__),
'resources',
'audio.raw')
However, when I run the last part os.path.dirname(__file)
in Ubuntu 18.04 terminal in python, the error happens like below:
os.path.dirname(__file)
* NameError: name '__file__' is not defined*
How can I solve the problem?
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.