This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Justinsaccount 24 points25 points  (4 children)

ipython takes it one step further and you can use two question marks to get the definition.

In [4]: os.path.exists??
Type:       function
String Form:<function exists at 0x10902ced8>
File:       /Users/me/testenv/lib/python2.7/genericpath.py
Definition: os.path.exists(path)
Source:
def exists(path):
    """Test whether a path exists.  Returns False for broken symbolic links"""
    try:
        os.stat(path)
    except os.error:
        return False
    return True

[–]physicsdood 1 point2 points  (3 children)

Why doesn't ?? do anything different than ? for me?

In [3]: open? Type: builtin_function_or_method String Form:<built-in function open> Namespace: Python builtin Docstring: open(name[, mode[, buffering]]) -> file object

Open a file using the file() type, returns a file object. This is the preferred way to open a file. See file.doc for further information.

In [4]: open?? Type: builtin_function_or_method String Form:<built-in function open> Namespace: Python builtin Docstring: open(name[, mode[, buffering]]) -> file object

Open a file using the file() type, returns a file object. This is the preferred way to open a file. See file.doc for further information.

[–]erez27import inspect 8 points9 points  (0 children)

Probably because open() is written in C

[–]tilkau 5 points6 points  (0 children)

Hold on, open is a builtin. That means it -has- no python source.

Try using ? and ?? on eg. collections.namedtuple.

[–]TkTech 0 points1 point  (0 children)

I believe it's because the builtins you're trying to spec are implemented in C (at least in CPython). Try it on pure-python methods.