python打乱数组顺序
2017年6月22日 23:44
import random a = [1, 2, 3, 4, 5]; random.shuffle(a) print a #[2, 3, 1, 5, 4]
此生必看的科学实验-水知道答案
为什么观看这部记录片
精神病为什么治不好
百病之源
净土大经科注2014
import random a = [1, 2, 3, 4, 5]; random.shuffle(a) print a #[2, 3, 1, 5, 4]
#取文件后缀 >>> os.path.splitext("/root/a.py") ('/root/a', '.py') #取目录与文件名 >>> os.path.split("/root/a.py") ('/root', 'a.py')
>>> import locale >>> locale.getdefaultlocale() ('zh_CN', 'cp936')
import locale cmd = cmd.encode(locale.getdefaultlocale()[1]) subprocess.Popen(cmd)
exe路径
>>> sys.executable 'C:\\Python27\\python.exe'
lib路径
>>> sys.prefix 'C:\\python27'
subprocess.Popen(cmd, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
ValueError: close_fds is not supported on Windows platforms if you redirect stdin/stdout/stderr
在windows上subprocess.Popen的参数close_fds=True与stdin/stdout/stderr不能共存
s = ('select *' 'from atable' 'where id=888') print s, type(s) #输出 select *from atablewhere id=888 <type 'str'>
C:\WINDOWS\system32>w32tm /resync 发生下列错误: 服务尚未启动。 (0x80070426) C:\WINDOWS\system32>echo %errorlevel% -2147023834
>>> os.system("w32tm /resync") 发生下列错误: 服务尚未启动。 (0x80070426) -2147023834
>>> os.system("w32tm /resync") 发生下列错误: 服务尚未启动。 (0x80070426) 0
2015-12-04 19:10:22,227 - apscheduler.scheduler - WARNING - Execution of job "TaskHandle.progress_job (trigger: date[2015-12-04 19:10:22 CST], next run at: 2015-12-04 19:10:22 CST)" skipped: maximum number of running instances reached (1)
#apscheduler/schedulers/base.py if run_times: try: executor.submit_job(job, run_times) except MaxInstancesReachedError: self._logger.warning( 'Execution of job "%s" skipped: maximum number of running instances reached (%d)', job, job.max_instances) except: self._logger.exception('Error submitting job "%s" to executor "%s"', job, job.executor)
#apscheduler/executors/base.py def submit_job(self, job, run_times): """ Submits job for execution. :param Job job: job to execute :param list[datetime] run_times: list of datetimes specifying when the job should have been run :raises MaxInstancesReachedError: if the maximum number of allowed instances for this job has been reached """ assert self._lock is not None, 'This executor has not been started yet' with self._lock: if self._instances[job.id] >= job.max_instances: raise MaxInstancesReachedError(job) self._do_submit_job(job, run_times) self._instances[job.id] += 1
sched.add_job(child_job, max_instances=10, trigger=DateTrigger(), id="123")
import time import tornado.ioloop from apscheduler.triggers.date import DateTrigger from apscheduler.schedulers.tornado import TornadoScheduler sched = TornadoScheduler() def child_job(): print "start" time.sleep(60) print "end" def main_job(): sched.add_job(child_job, trigger=DateTrigger(), id="123") sched.add_job(main_job, 'interval', seconds=5) sched.start() tornado.ioloop.IOLoop.instance().start()
job_id: 7279209ab6c2498698f2117bb97e18a1, instances: 0, max_instances: 1 job_id: 123, instances: 0, max_instances: 1 start job_id: 7279209ab6c2498698f2117bb97e18a1, instances: 0, max_instances: 1 job_id: 123, instances: 1, max_instances: 1 WARNING:apscheduler.scheduler:Execution of job "child_job (trigger: date[2015-12-07 15:27:11 CST], next run at: 2015-12-07 15:27:11 CST)" skipped: maximum number of running instances reached (1) job_id: 7279209ab6c2498698f2117bb97e18a1, instances: 0, max_instances: 1
import paramiko ssh = paramiko.SSHClient() ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname="xxx.xxx.xxx.xxx", port=22, username="xxx", password="xxx") stdin, stdout, stderr = ssh.exec_command("vmstat 1 1") content = stdout.readlines() for r in content: print r ssh.close()
sudo yum install gettext
#encoding=utf-8 import gettext # demo对应mo文件名,locale为locale目录地址,zh_CN为locale目录下目录名 zh = gettext.translation("demo", "locale", languages=["zh_CN"]) # 激活_() zh.install(True) print _("hello world")
xgettext -L python -o zh_CN.po demo.py
... #修改编码为utf-8 "Content-Type: text/plain; charset=utf-8\n" ... #加上翻译 #: demo.py:6 msgid "hello world" msgstr "你好,世界"
mkdir -p locale/zh_CN/LC_MESSAGES
msgfmt -o ~/locale/zh_CN/LC_MESSAGES/demo.mo zh_CN.po
➜ ~ python demo.py 你好,世界