__name__ == "__main__"
についてQiita
を参考にしたのですが、
python sample.py とかしてるときは、メインプログラムとして走らせてるsample.py内では__name__変数に```__main__```がセットされているということ。
との説明がありましたが、
質問1)__name__変数
とは例えばsample.py内で定義されている変数で
name=test
というふうにtestが格納されたname変数を定義していたら、そのname変数のことを指すのでしょうか?
質問2)「sample.py内では__name__変数
に__main__
がセットされている」とは具体的にどういうことを意味しているのでしょうか?
まず変数__name__
は見たことないので何に使われているか、及びsample.py内での__name__変数
とは具体的に何を指しているかを教えてください。
質問3)下記コードはgoogle APIから持ってきたのですが、このGoogle APIのこのコマンドは、anaconda上でも必要なライブラリをインストールすれば実行できますか?
Google APIコマンド
import argparse import base64 from googleapiclient import discovery from oauth2client.client import GoogleCredentials def main(photo_file): """Run a label request on a single image""" credentials = GoogleCredentials.get_application_default() service = discovery.build('vision', 'v1', credentials=credentials) with open(photo_file, 'rb') as image: image_content = base64.b64encode(image.read()) service_request = service.images().annotate(body={ 'requests': [{ 'image': { 'content': image_content.decode('UTF-8') }, 'features': [{ 'type': 'LABEL_DETECTION', 'maxResults': 1 }] }] }) response = service_request.execute() label = response['responses'][0]['labelAnnotations'][0]['description'] print('Found label: %s for %s' % (label, photo_file)) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('image_file', help='The image you\'d like to label.') args = parser.parse_args() main(args.image_file)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。