Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Attributes
argparse.FileType Class Reference
Inheritance diagram for argparse.FileType:
Inheritance graph
[legend]
Collaboration diagram for argparse.FileType:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __call__
def __repr__

Public Attributes

_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Attributes

 _mode
 _bufsize

Detailed Description

Factory for creating file object types

Instances of FileType are typically passed as type= arguments to the
ArgumentParser add_argument() method.

Keyword Arguments:
    - mode -- A string indicating how the file is to be opened. Accepts the
        same values as the builtin open() function.
    - bufsize -- The file's desired buffer size. Accepts the same values as
        the builtin open() function.

Definition at line 1112 of file argparse.py.


Constructor & Destructor Documentation

def argparse.FileType.__init__ (   self,
  mode = 'r',
  bufsize = -1 
)

Definition at line 1125 of file argparse.py.

01125 
01126     def __init__(self, mode='r', bufsize=-1):
01127         self._mode = mode
01128         self._bufsize = bufsize

Here is the caller graph for this function:


Member Function Documentation

def argparse.FileType.__call__ (   self,
  string 
)

Definition at line 1129 of file argparse.py.

01129 
01130     def __call__(self, string):
01131         # the special argument "-" means sys.std{in,out}
01132         if string == '-':
01133             if 'r' in self._mode:
01134                 return _sys.stdin
01135             elif 'w' in self._mode:
01136                 return _sys.stdout
01137             else:
01138                 msg = _('argument "-" with mode %r') % self._mode
01139                 raise ValueError(msg)
01140 
01141         # all other arguments are used as file names
01142         try:
01143             return open(string, self._mode, self._bufsize)
01144         except IOError as e:
01145             message = _("can't open '%s': %s")
01146             raise ArgumentTypeError(message % (string, e))

Definition at line 1147 of file argparse.py.

01147 
01148     def __repr__(self):
01149         args = self._mode, self._bufsize
01150         args_str = ', '.join(repr(arg) for arg in args if arg != -1)
01151         return '%s(%s)' % (type(self).__name__, args_str)
01152 
01153 # ===========================
01154 # Optional and Positional Parsing
01155 # ===========================


Member Data Documentation

Definition at line 1127 of file argparse.py.

Definition at line 1126 of file argparse.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.


The documentation for this class was generated from the following file: