• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.print函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.print函数的典型用法代码示例。如果您正苦于以下问题:Python print函数的具体用法?Python print怎么用?Python print使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了print函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: filter_invalid_abs_states

def filter_invalid_abs_states(state_list, pi_seq_list, ci_seq_list, A, init_cons):
    valid_idx_list = []

    for idx, abs_state in enumerate(state_list):
        ival_cons = A.plant_abs.get_ival_cons_abs_state(abs_state.plant_state)

        # ##!!##logger.debug('ival_cons: {}'.format(ival_cons))

        # find the intersection b/w the cell and the initial cons
        # print('init_cons', init_cons)

        ic = ival_cons & init_cons
        if ic is not None:
            valid_idx_list.append(idx)
            #valid_state_list.append(abs_state)

    # TODO: this should be logged and not printed
    if valid_idx_list == []:
        for abs_state in state_list:
            ival_cons = A.plant_abs.get_ival_cons_abs_state(abs_state.plant_state)
            print(ival_cons)

    valid_state_list = []
    respective_pi_seq_list = []
    respective_ci_seq_list = []
    for i in valid_idx_list:
        valid_state_list.append(state_list[i])
        respective_pi_seq_list.append(pi_seq_list[i])
        respective_ci_seq_list.append(ci_seq_list[i])
    return valid_state_list, respective_pi_seq_list, respective_ci_seq_list
开发者ID:zutshi,项目名称:S3CAMX,代码行数:30,代码来源:scattersim.py


示例2: on_status

 def on_status(self, status):
     global HAD_ERROR
     global HANG_TIME
     global TWEETS_READ
     HANG_TIME = time.time()
     tweet, command = acceptable_tweet(status)
     if not command:
         return True
     try:
         open(update['is_busy_file'], 'w')
     except PermissionError:
         # This wont happen all the time, the file is probably busy
         pass
     print("[{0}] Reading: {1} ({2}): {3}".format(
         time.strftime("%Y-%m-%d %H:%M"),
         status.user.screen_name, status.user.id, status.text))
     tweet_command(API, status, tweet, command)
     HAD_ERROR = False
     TWEETS_READ.append(str(status.id))
     with open(os.path.join(settings['ignore_loc'],
                            "tweets_read.txt"),
               'w') as file:
         file.write("\n".join(TWEETS_READ))
     try:
         os.remove(update['is_busy_file'])
     except (PermissionError, FileNotFoundError):
         # Related to above PermissionError.
         pass
开发者ID:Dimpsy,项目名称:AcePictureBot,代码行数:28,代码来源:acepicturebot.py


示例3: test_model_

def test_model_(abs_state, AA, sp, am, step_sim):
    test_samples = sp.sampler.sample(abs_state, AA, sp, AA.num_samples*MORE_FACTOR*TEST_FACTOR)
    X, Y = getxy(abs_state, test_samples, step_sim)
    e = am.model_error(X, Y)
    if __debug__:
        print(e)
    return e
开发者ID:zutshi,项目名称:S3CAMR,代码行数:7,代码来源:modelrefine.py


示例4: run_secam

def run_secam(sys, prop, opts):
    MODE = opts.MODE
    #plot = opts.plot

    if MODE == 'simulate':
        if not isinstance(
                opts.property_checker,
                properties.PropertyChecker):
            raise err.Fatal('property checker must be enabled when '
                            'random testing!')
        start_time = time.time()
        trace_list = simulate(sys, prop, opts)
        #if plot:
        if opts.dump_trace:
            dump_trace(trace_list)
        opts.plotting.plot_trace_list(trace_list, opts.plots)
        opts.plotting.show()
    elif MODE == 'falsify':
        # ignore time taken to create_abstraction: mainly to ignore parsing
        # time
        current_abs, sampler = create_abstraction(sys, prop, opts)
        start_time = time.time()
        falsify(sys, prop, opts, current_abs, sampler)
    else:
        raise err.Fatal('bad MODE supplied: {}'.format(MODE))

    stop_time = time.time()
    print('*'*20)
    print('time spent(s) = {}'.format(stop_time - start_time), file=SYS.stderr)
    return
开发者ID:zutshi,项目名称:S3CAMR,代码行数:30,代码来源:secam.py


示例5: handle_stream

def handle_stream(sapi, status_api=False):
    stream_sapi = start_stream(sapi)
    global HANG_TIME
    while True:
        time.sleep(5)
        elapsed = (time.time() - HANG_TIME)
        if elapsed > 600:
            # TODO: Temp to try and stop crash tweet spam for now
            if os.path.exists(update['last_crash_file']):
                if time.time() - os.path.getctime(update['last_crash_file']) > 80000:
                    os.remove(update['last_crash_file'])
                    open(update['last_crash_file'], 'w')
                    msg = """[{0}] Restarting!
The bot will catch up on missed messages now!""".format(
                        time.strftime("%Y-%m-%d %H:%M"))
                    if status_api:
                        post_tweet(status_api, msg)
                    else:
                        print(msg)
            stream_sapi.disconnect()
            time.sleep(3)
            if not stream_sapi.running:
                stream_sapi = start_stream(sapi)
            Thread(target=read_notifications,
                   args=(API, True, TWEETS_READ)).start()
            HANG_TIME = time.time()
开发者ID:Dimpsy,项目名称:AcePictureBot,代码行数:26,代码来源:acepicturebot.py


示例6: build_pwa_model

def build_pwa_model(AA, abs_obj, sp, tol, include_err, model_type):
    """build_pwa_model
    Builds both dft and rel models

    Parameters
    ----------
    AA : AA
    abs_obj : Either abs_states (for dft models) or relations
              [tuple(abs_state_src, abs_state_target)] for rel model
    sp : system params
    tol : modeling error tolerance
    include_err : include error in determining next state
                  x' = x +- errror
    """
    dt = AA.plant_abs.delta_t
    step_sim = simsys.get_step_simulator(sp.controller_sim, sp.plant_sim, dt)

    #abs_state_models = {}
    modelers = {
            'dft': (pwa.PWA, abs_state_affine_models),
            'rel': (rel.PWARelational, abs_rel_affine_models),
            }
    M, model = modelers[model_type]
    pwa_model = M()

    for a in abs_obj:
        print('modeling: {}'.format(a))
        for sub_model in model(a, AA, step_sim, tol, sp, include_err):
            if sub_model is not None:
                pwa_model.add(sub_model)
            #abs_state_models[abs_state] = sub_model
    return pwa_model
开发者ID:zutshi,项目名称:S3CAMR,代码行数:32,代码来源:modelrefine.py


示例7: handle_stream

def handle_stream(status_api=False):
    stream = start_stream()
    global HANG_TIME
    try:
        while True:
            time.sleep(5)
            elapsed = (time.time() - HANG_TIME)
            if elapsed > 600:
                # TODO: Temp to try and stop crash tweet spam for now
                if os.path.exists(update['last_crash_file']):
                    if time.time() - os.path.getctime(
                            update['last_crash_file']) > 80000:
                        os.remove(update['last_crash_file'])
                        open(update['last_crash_file'], 'w')
                        msg = """[{0}] Restarting!
The bot will catch up on missed messages now!""".format(
                            time.strftime("%Y-%m-%d %H:%M"))
                        if status_api:
                            status_api.update_status(status=msg)
                        else:
                            print(msg)
                stream.disconnect()
                threading.Thread(target=read_notifications,
                                 args=(API, True, TWEETS_READ)).start()
                time.sleep(5)
                stream = start_stream()
                HANG_TIME = time.time()
    except (KeyboardInterrupt, SystemExit):
        sys.exit(0)
开发者ID:Okonorn,项目名称:AcePictureBot,代码行数:29,代码来源:acepicturebot.py


示例8: on_success

 def on_success(self, data):
     global HAD_ERROR
     global HANG_TIME
     global TWEETS_READ
     tweet_datetime = datetime.datetime.strptime(
             data['created_at'], '%a %b %d %H:%M:%S %z %Y')
     days_past = datetime.datetime.now(datetime.timezone.utc) - tweet_datetime
     if days_past.days > 1:
         return False
     # Fri Apr 15 16:59:09 +0000 2016
     if data['id_str'] in TWEETS_READ:
         return True
     TWEETS_READ.append(data['id_str'])
     HANG_TIME = time.time()
     tweet, command = acceptable_tweet(data)
     if not command:
         return True
     try:
         open(update['is_busy_file'], 'w')
     except PermissionError:
         # This wont happen all the time, the file is probably busy
         pass
     print("[{0}] {1} ({2}): {3}".format(
         time.strftime("%Y-%m-%d %H:%M"),
         data['user']['screen_name'], data['user']['id_str'], data['text']))
     tweet_command(API, data, tweet, command)
     HAD_ERROR = False
     with open(os.path.join(settings['ignore_loc'],
                            "tweets_read.txt"), 'w') as file:
         file.write("\n".join(TWEETS_READ))
     try:
         os.remove(update['is_busy_file'])
     except (PermissionError, FileNotFoundError):
         # Related to above PermissionError.
         pass
开发者ID:Okonorn,项目名称:AcePictureBot,代码行数:35,代码来源:acepicturebot.py


示例9: on_server_remove

async def on_server_remove(server):
    """Called when kicked or left the server.

    Remove the server from server_settings.ini
    :param server: Discord.Server object.
    """
    func.config_delete_section(server.id, discord_settings['server_settings'])
    print("$ Left server: {} ({})".format(server, server.id))
开发者ID:Dimpsy,项目名称:AcePictureBot,代码行数:8,代码来源:DiscordBot.py


示例10: handle_tcp

def handle_tcp(c):
    filter = config.get_filter()
    for tcp in get_tcpconn(c.infile):
        if filter.index != None and tcp.index not in filter.index:
            continue
        tcp_msg = "\033[31;2m%s [%s:%d] -- -- --> [%s:%d]\033[0m\n" % \
                (tcp.index, tcp.con_tuple[0], tcp.con_tuple[1],
                        tcp.con_tuple[2], tcp.con_tuple[3])
        utils.print(tcp_msg)
开发者ID:fengidri,项目名称:netdump,代码行数:9,代码来源:__main__.py


示例11: on_error

 def on_error(self, status_code):
     global LAST_STATUS_CODE
     global HANG_TIME
     HANG_TIME = time.time()
     if int(status_code) != int(LAST_STATUS_CODE):
         LAST_STATUS_CODE = status_code
         msg = ("[{0}] Twitter Returning Status Code: {1}.\n"
                "More Info: https://dev.twitter.com/overview/api/response-codes").format(
                 time.strftime("%Y-%m-%d %H:%M"), status_code)
         print(msg)
         post_tweet(func.login(status=True), msg)
     return True
开发者ID:MegaRobotMan,项目名称:AcePictureBot,代码行数:12,代码来源:acepicturebot.py


示例12: start_stream

def start_stream(sapi=None):
    if sapi is None:
        sapi = func.login(rest=False)
    try:
        stream_sapi = tweepy.Stream(sapi, CustomStreamListener())
        print("[INFO] Reading Twitter Stream!")
        stream_sapi.filter(
            track=[x.lower() for x in settings['twitter_track']], async=True)
    except (KeyboardInterrupt, SystemExit):
        stream_sapi.disconnect()
        sys.exit(0)
    return stream_sapi
开发者ID:Dimpsy,项目名称:AcePictureBot,代码行数:12,代码来源:acepicturebot.py


示例13: simulate

def simulate(AA, s, sp, pwa_model, max_path_len, S0):
    NUM_SIMS = 100
    # sample only initial abstract state
    x0_samples = (sp.sampler.sample_multiple(S0, AA, sp, NUM_SIMS)).x_array
    #print(x0_samples)
    # sample the entire given initial set
    #X0 = sp.init_cons
    #x0_samples = sample.sample_ival_constraints(X0, n=1000)

    print('path length: {}'.format(max_path_len))
    traces = [i for i in simulate_pwa(pwa_model, x0_samples, N=max_path_len)]
    return traces
开发者ID:zutshi,项目名称:S3CAMR,代码行数:12,代码来源:modelrefine.py


示例14: cell_affine_models

def cell_affine_models(cell, step_sim, ntrain, ntest, tol, include_err):
    """cell_affine_models

    Parameters
    ----------
    cell : cell
    step_sim : 1 time step (delta_t) simulator
    tol : each abs state is split further into num_splits cells
    in order to meet: modeling error < tol (module ntests samples)

    Returns
    -------
    pwa.SubModel()

    Notes
    ------
    """
    # XXX: Generate different samples for each time step or reuse?
    # Not clear!
    sub_models = []

    X, Y = getxy_ignoramous(cell, ntrain, step_sim)
    rm = RegressionModel(X, Y)
    X, Y = getxy_ignoramous(cell, ntest, step_sim)
    e_pc = rm.error_pc(X, Y) # error %
    if __debug__:
        print('error%:', e_pc)
    #error = np.linalg.norm(e_pc, 2)
    # error exceeds tol in error_dims
    error_dims = np.arange(len(e_pc))[np.where(e_pc >= tol)]

    if len(error_dims) > 0:
        err.warn('splitting on e%:{}, |e%|:{}'.format(
            e_pc, np.linalg.norm(e_pc, 2)))
        for split_cell in cell.split(axes=error_dims):
            sub_models_ = cell_affine_models(
                    split_cell, step_sim, ntrain, ntest, tol, include_err)
            sub_models.extend(sub_models_)
        return sub_models
    else:
        #print('error%:', rm.error_pc(X, Y))
        A, b = rm.Ab
        C, d = cell.ival_constraints.poly()
        e = rm.error(X, Y) if include_err else None
        dmap = pwa.DiscreteAffineMap(A, b, e)
        part = pwa.Partition(C, d, cell)
        sub_model = pwa.SubModel(part, dmap)
        if __debug__:
            print('----------------Finalized------------------')
    return [sub_model]
开发者ID:zutshi,项目名称:S3CAMR,代码行数:50,代码来源:modelrefine.py


示例15: load_accounts

def load_accounts():
    accounts = sorted(
        [p for p in pathlib.Path(
            os.path.join(BASE_DIR, 'accounts')).iterdir() if p.is_file()])
    account_count = 0
    print(os.path.join(BASE_DIR, 'accounts'))
    print(accounts)
    for acc in accounts:
        bot_name = os.path.basename(str(acc)).split(".")[0]
        if DEBUG:
            if bot_name not in DEBUG_ACCS:
                continue
        elif not DEBUG:
            if "example" in bot_name.lower():
                continue
        account_count += 1
        account_list[bot_name] = OrderedDict()
        Config = ConfigObj(str(acc))
        has_cred = False
        has_sett = False
        for sec in (Config.iteritems()):
            sec = tuple(sec)
            if sec[0] == "credentials":
                has_cred = True
            elif sec[0] == "settings":
                has_sett = True
            if "-thread" in sec[0]:
                # Start thread import setttings and creds
                pass
            account_list[bot_name][sec[0].lower()] = (sec[1].copy())
        if not has_cred:
            print("Credentials not found for bot: {}".format(bot_name))
            input("Press ENTER to close.")
            sys.exit(0)
        elif not has_sett:
            print("No settings are set for bot: {}".format(bot_name))
            input("Press ENTER to close.")
            sys.exit(0)
        temp = OrderedDict()
        for k, v in account_list[bot_name].items():
            for a, b in v.items():
                a = a.lower()
                try:
                    temp[k][a] = b
                except:
                    temp[k] = {a: b}
        account_list[bot_name] = temp.copy()
        del temp
    print("Running {0} Accounts!\n".format(account_count))
    return(account_list)
开发者ID:Kuppey,项目名称:Shiinabot,代码行数:50,代码来源:imagetweet.py


示例16: train

def train(net, optimizer, num_epochs, batch_size, trn_set, vld_set=None):
    assert isinstance(net, NeuralNetwork)
    assert num_epochs > 0
    assert batch_size > 0

    trn_x, trn_y = trn_set
    inputs = [(x, y) for x, y in zip(trn_x, trn_y)]

    for i in range(num_epochs):
        np.random.shuffle(inputs)

        # divide input observations into batches
        batches = [inputs[j:j+batch_size] for j in range(0, len(inputs), batch_size)]
        inputs_done = 0
        for j, batch in enumerate(batches):
            net.backpropagate(batch, optimizer)
            inputs_done += len(batch)
            u.print("Epoch %02d %s [%d/%d]" % (i+1, u.bar(inputs_done, len(inputs)), inputs_done, len(inputs)), override=True)

        if vld_set:
            # test the net at the end of each epoch
            u.print("Epoch %02d %s [%d/%d] > Testing..." % (i+1, u.bar(inputs_done, len(inputs)), inputs_done, len(inputs)), override=True)
            accuracy = test(net, vld_set)
            u.print("Epoch %02d %s [%d/%d] > Validation accuracy: %0.2f%%" % (i+1, u.bar(inputs_done, len(inputs)), inputs_done, len(inputs), accuracy*100), override=True)
        u.print()
开发者ID:alangwansui,项目名称:dl,代码行数:25,代码来源:network.py


示例17: post_tweet

def post_tweet(_API, tweet, media="", command=False, rts=False):
    try:
        if media:
            media = media.replace("\\", "\\\\")
        if rts and command:
            print("[{0}] Tweeting: {1} ({2}): [{3}] {4}".format(
                time.strftime("%Y-%m-%d %H:%M"),
                rts.user.screen_name, rts.user.id,
                command, tweet))
        else:
            print("[{0}] Tweeting: {1}".format(
                time.strftime("%Y-%m-%d %H:%M"),
                tweet))
        if rts:
            if media:
                print("(Image: {0})".format(media))
                _API.update_with_media(media, status=tweet,
                                       in_reply_to_status_id=rts.id)
            else:
                _API.update_status(status=tweet,
                                   in_reply_to_status_id=rts.id)
        else:
            if media:
                print("(Image: {0})".format(media))
                _API.update_with_media(media, status=tweet)
            else:
                _API.update_status(status=tweet)
    except:
        pass
开发者ID:Dimpsy,项目名称:AcePictureBot,代码行数:29,代码来源:acepicturebot.py


示例18: printheaders

 def printheaders(headers):
     l = 0
     for k in headers.keys():
         if l < len(k):
             l = len(k)
     for k, v in headers.items():
         utils.print(k.ljust(l))
         utils.print(': ')
         utils.print(v)
         utils.print('\n')
开发者ID:fengidri,项目名称:netdump,代码行数:10,代码来源:__main__.py


示例19: start_stream

def start_stream():
    try:
        stream = TwitterStream(credentials['consumer_key'],
                               credentials['consumer_secret'],
                               credentials['access_token'],
                               credentials['access_token_secret'])
        print("[INFO] Reading Twitter Stream!")
        # TODO: Start Thread here
        stream_thread = StoppableThread(
            target=stream.statuses.filter,
            kwargs={'track': ', '.join(
                [x.lower() for x in settings['twitter_track']])})
        stream_thread.daemon = True
        stream_thread.start()
    except (KeyboardInterrupt, SystemExit, RuntimeError):
        stream_thread.stop()
        stream.disconnect()
        sys.exit(0)
    return stream
开发者ID:Okonorn,项目名称:AcePictureBot,代码行数:19,代码来源:acepicturebot.py


示例20: get_reachable_abs_states

    def get_reachable_abs_states(
            self,
            intermediate_state,
            A,
            system_params,
            ):

        state = intermediate_state
        total_num_samples = state.n

        property_checker = lambda t, Y: Y in system_params.final_cons
        rchd_concrete_state_array = cp.compute_concrete_plant_output(
                A,
                system_params.plant_sim,
                state,
                total_num_samples,
                property_checker)
        #print(rchd_concrete_state_array)
        #exit()

        # ================= DIRECT MANIPULATION ===================
        # of StateArray object
        # rchd_cont_state_array = rchd_concrete_state_array.cont_states

        # for each reached state, get the abstract state
        pi_ref = system_params.pi_ref
        ci_ref = system_params.ci_ref

        abs2rchd_abs_state_ci_pi_list = []
        for rchd_concrete_state in rchd_concrete_state_array.iterable():

            rchd_abs_state = \
                A.get_abs_state_from_concrete_state(rchd_concrete_state)
            ci = rchd_concrete_state.ci
            pi = rchd_concrete_state.pi
            pi_cell = self.cell_id_from_concrete(pi, pi_ref.eps)
            ci_cell = self.cell_id_from_concrete(ci, ci_ref.eps)

            if rchd_concrete_state.x in system_params.final_cons:
                if not system_params.is_final(A, rchd_abs_state):
                    print(rchd_concrete_state)
                    print(self.get_ival_cons_abs_state(rchd_abs_state.ps))
                    print(rchd_concrete_state.x)
                    print(system_params.final_cons)
                    raise err.Fatal('cant happen!')

            if rchd_abs_state is not None:
                abs2rchd_abs_state_ci_pi_list.append((rchd_abs_state, ci_cell, pi_cell))

                # ##!!##logger.debug('abs_state obtained {} from concrete_state {}'.format(rchd_abs_state, rchd_concrete_state))

        return abs2rchd_abs_state_ci_pi_list
开发者ID:zutshi,项目名称:S3CAMX,代码行数:52,代码来源:PACell.py



注:本文中的utils.print函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.print_log函数代码示例发布时间:2022-05-26
下一篇:
Python utils.pretty_http_error函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap