LoginSignup
1
1

More than 3 years have passed since last update.

RubyとPythonにおける、外部ソースコードを読み込む書き方の違い

Posted at

これは何?

RubyとPythonの両方でプログラムを書いていると、外部ソースコードを読み込む書き方が「どっちがどっちだっけ?」と混乱することがあります。そうした場合に向けての備忘録です。

Rubyの場合

require './foobar'
  • モジュール名を含むパス全体をrequireの後に書く
  • モジュール名を引用符で囲う必要がある

Pythonの場合

from . import foobar
  • パス指定でモジュールをインポートする場合、モジュール名を除くパスを、fromの後・importの前に書く
  • モジュール名はimportの後に書く
  • モジュール名を引用符で囲う必要はない

Pythonの場合、「パッケージ」やらなんやらの関連概念があるが、今回はそうした項目には触れない。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1