12
12

More than 5 years have passed since last update.

iPythonで実装のソースコードを見る

Last updated at Posted at 2014-05-08

超具体的に言うと、WebDriverのPython APIでByを使うんですがこれが何宣言してんのか知りたい。By.NAMEは覚えたけどBy.CLASS_NAMEなのかBy.CLASSなのかどっちだっけ。

……というときにlocate '/usr*python*webdriver*by*'とかやるの、なんだかアホいなぁと。

> locate '/usr*python*/webdriver*by*'
/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/by.py
/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/by.pyc
(viewとかemacsで見る)

豆知識としてipythonの方法を紹介します。?を2個つけるだけです。

In [1]> from selenium.webdriver.common.by import By
In [2]> By??
Type:        type
String form: <class 'selenium.webdriver.common.by.By'>
File:        /usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/by.py
Source:
class By(object):
    """
    Set of supported locator strategies.
    """

    ID = "id"
    XPATH = "xpath"
    LINK_TEXT = "link text"
    PARTIAL_LINK_TEXT = "partial link text"
    NAME = "name"
    TAG_NAME = "tag name"
    CLASS_NAME = "class name"
    CSS_SELECTOR = "css selector"

    @classmethod
    def is_valid(cls, by):
        for attr in dir(cls):
            if by == getattr(cls, attr):
                return True
        return False

『Pythonによるデータ分析入門』という本で何故かipythonの入門記事がありまして、自分の使ってるツール知らないのは恥だぁと改めて思いました。

なおiPythonのチートシートは以下の通り。

おまけ

これも同書籍からですが、地味に衝撃を覚えたので参考まで (python-matplotlib パッケージ等が先に必要です)

> ipython --pylab
In [1]> plot(np.random.randn(100).cumsum())

どう動作するかは https://www.youtube.com/watch?v=BrDJssegqwo からどうぞ

12
12
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
12
12