本文整理汇总了Python中utils.print函数的典型用法代码示例。如果您正苦于以下问题:Python print函数的具体用法?Python print怎么用?Python print使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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
示例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
示例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()
示例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
示例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)
示例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
示例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))
示例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)
示例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
示例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
示例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
示例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]
示例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)