将 dat 内容写入 pth 中, 如果写入成功, 返回为空, 否则返回失败信息

    :type append: ``bool``
    :param append: 写入模式
    :type append: ``bool``
    :param dat: 待写入内容
    :type dat: ``str``
    :param pth:
    :type pth: ``str``
    :return:
    :rtype:
548066
def write_file(dat, pth, append=False):
    
    err = None

    _d, _nm = os.path.split(pth)
    if _d and not os.path.exists(_d):
        os.makedirs(_d)

    try:
        mode = 'ab' if append else 'wb'

        with open(pth, mode) as _fp:
            dat = to_bytes(dat)
            _fp.write(dat)
    except Exception as _err:
        err = _err
    return err
1310541
function IDPTYPE() {
		let make = ()=>(Math.random().toString(36).slice(2)), rslt = make();
		while (global.__PTYPES__.has(rslt)) { rslt = make(); }
		return rslt;
	}
1308009
def cp(args):
    
    p = OptionParser(cp.__doc__)
    fp = sys.stdin

    for link_name in fp:
        link_name = link_name.strip()
        if not op.exists(link_name):
            continue

        source = get_abs_path(link_name)
        link_name = op.basename(link_name)
        if not op.exists(link_name):
            os.symlink(source, link_name)
        logging.debug(" => ".join((source, link_name)))
309636
def p_if_expr_header(p):
    
    global ENABLED

    IFDEFS.append((ENABLED, p.lineno(1)))
    ENABLED = bool(int(p[2])) if p[2].isdigit() else ID_TABLE.defined(p[2])
1068873
def append_delta_index(self, ts_data=None, data_delta=None, key=KEY_DATA):
        """"""
        reasign = False
        if data_delta is None:
            if self.data is not None:
                data_delta = self.data[key]
            else:
                self.printif('NO HAY DATOS PARA AÑADIR DELTA', 'error')
                return None
            reasign = True
        data_delta['delta'] = data_delta.index.tz_convert('UTC')
        if ts_data is not None:
            data_delta['delta'] = (data_delta['delta'] - data_delta['delta'].shift(1)).fillna(ts_data)
            data_delta['delta_T'] = data_delta['delta'].apply(lambda x: pd.Timedelta(x).seconds) / ts_data
        else:
            data_delta['delta'] = (data_delta['delta'] - data_delta['delta'].shift(1)).fillna(0)
        if reasign:
            self.data[key] = data_delta
        else:
            return data_delta
422302
static private void append(StringBuilder tgt, String pfx, int dgt, long val) {
		tgt.append(pfx);
		if (dgt > 1) {
			int pad = (dgt - 1);
			for (long xa = val; xa > 9 && pad > 0; xa /= 10) {
				pad--;
			}
			for (int xa = 0; xa < pad; xa++) {
				tgt.append('0');
			}
		}
		tgt.append(val);
	}
506869
def join_path(*path_to_join, **kwargs):
    
    if "get_root" in kwargs:
        get_root = kwargs["get_root"]
    else:
        # default value
        get_root = False
    sdp = dataset_path(get_root=get_root)
    pth = os.path.join(sdp, *path_to_join)
    logger.debug("sample_data_path" + str(sdp))
    logger.debug("path " + str(pth))
    return pth
246909
def __dump_stack(self):
        
        maxdepth = len(self._mode_stack)
        maxdepth_strlen = len(str(maxdepth))
        index_width = 4 - (-maxdepth_strlen) % 4 + 4
        index_str = lambda i: '{:<{}d}'.format(i, index_width)

        self.stdout.write(index_str(0) + self.root_prompt)
        self.stdout.write('\n')

        tree_prefix = '└── '
        for i in range(maxdepth):
            index_prefix = index_str(i + 1)
            whitespace_prefix = ' ' * len(tree_prefix) * i
            mode = self._mode_stack[i]
            line = index_prefix + whitespace_prefix + \
                    tree_prefix + mode.prompt + \
                    ': {}@{}'.format(mode.cmd, mode.args)
            self.stdout.write(line)
            self.stdout.write('\n')
795225
def pickle_m2f(dat, pth):
    
    mkdir_p(pth)
    # 为了2与3兼容, 设置 dump 的协议为 2
    with open(pth, 'wb') as f:
        pickle.dump(dat, f, 2)
762898
def clean_add_strdec(*args, prec=28):
    """"""

    # load modules
    import pandas as pd
    import numpy as np
    import re
    from decimal import Decimal, getcontext
    getcontext().prec = prec

    # initialize result as 0.0
    def proc_elem(*args):
        t = Decimal('0.0')
        for a in args:
            if isinstance(a, str):
                a = re.sub('[^0-9\.\-]+', '', a)

            if a and pd.notnull(a):
                t += Decimal(a)

        return str(t)

    def proc_list(arr):
        return [proc_elem(*row) for row in arr]

    def proc_ndarray(arr):
        return np.array(proc_list(arr))

    # transform depending on provided datatypes
    if isinstance(args[0], (list, tuple)):
        return proc_list(args[0])
    elif isinstance(args[0], np.ndarray):
        return proc_ndarray(args[0])
    elif isinstance(args[0], pd.DataFrame):
        return pd.DataFrame(proc_ndarray(args[0].values),
                            index=args[0].index)
    else:
        return proc_elem(*args)
787529
def get_dotstr(self):
        """"""
        dotobj = self.gosubdagplot.get_pydot_graph() # pydot.Dot
        dotstr = dotobj.create_dot()
        return dotstr
248244
def stdlib(self):
        
        if self.module == 'pkg_resources' or self.module.startswith('pkg_resources.'):
            return False
        elif self.filename.startswith(SITE_PACKAGES_PATHS):
            # if it's in site-packages then its definitely not stdlib
            return False
        elif self.filename.startswith(SYS_PREFIX_PATHS):
            return True
        else:
            return False
1166730
def _get_stddevs(self, C, mag, stddev_types, num_sites):
        
        std = C['c16'] + np.zeros(num_sites)

        if mag < 7.4:
            std -= 0.07 * mag
        else:
            std -= 0.518

        # only the 'total' standard deviation is supported, therefore the
        # std is always the same for all types
        stddevs = [std for _ in stddev_types]

        return stddevs
457433
function putStackTogether(st) {
	var out = '';
	// put the main elements together... stacked with "+" unless it's a regular stack
	if (tib_stack(st.cons_str)) {
	    out += st.stack.join("");
	} else out += (st.cons_str);
	// caret (tsa-phru) goes here as per some (halfway broken) Unicode specs...
	if (st.caret) out += ("^");
	// vowels...
	if (st.vowels.length > 0) {
		out += st.vowels.join("+");
	} else if (!st.prefix && !st.suffix && !st.suff2
	&& (st.cons_str.length == 0 || st.cons_str.charAt(st.cons_str.length - 1) != 'a')) {
		out += "a"
	}
	// final stuff
	out += st.finals.join("");
	if (st.dot) out += ".";
	return out;
}
730465
def in6_isaddrTeredo(x):
    
    our = inet_pton(socket.AF_INET6, x)[0:4]
    teredoPrefix = inet_pton(socket.AF_INET6, conf.teredoPrefix)[0:4]
    return teredoPrefix == our
1295683
def strToGUID(s):
    
    dat = uuid.UUID(hex=s)
    if isinstance(dat.bytes_le, str):
        # Python 2
        dat = [ord(e) for e in dat.bytes_le]
    else:
        # Python 3
        dat = list(dat.bytes_le)
    return dat
253564
def ReadDataFile(self):
        
        if os.path.isfile(self.filename[0:-4] + '.dat'):
            filename = self.filename[0:-4] + '.dat'
    
        elif os.path.isfile(self.filename[0:-4] + '.DAT'):
            filename = self.filename[0:-4] + '.DAT'
        
        else:
            print "Data file File not found."
            return 0
        
        self.filehandler = open(filename,'rb')
        self.DatFileContent = self.filehandler.read()
    
        # END READING .dat FILE.
        self.filehandler.close() # Close file.        
        
        return 1