python打乱数组顺序
2017年6月22日 23:44
1 2 3 4 5 | import random a = [ 1 , 2 , 3 , 4 , 5 ]; random.shuffle(a) print a #[2, 3, 1, 5, 4] |
此生必看的科学实验-水知道答案
为什么观看这部记录片
精神病为什么治不好
百病之源
净土大经科注2014
1 2 3 4 5 | import random a = [ 1 , 2 , 3 , 4 , 5 ]; random.shuffle(a) print a #[2, 3, 1, 5, 4] |
1 2 3 4 5 6 7 | #取文件后缀 >>> os.path.splitext( "/root/a.py" ) ( '/root/a' , '.py' ) #取目录与文件名 >>> os.path.split( "/root/a.py" ) ( '/root' , 'a.py' ) |
1 2 3 | >>> import locale >>> locale.getdefaultlocale() ( 'zh_CN' , 'cp936' ) |
1 2 3 | import locale cmd = cmd.encode(locale.getdefaultlocale()[ 1 ]) subprocess.Popen(cmd) |
exe路径
1 2 | >>> sys.executable 'C:\\Python27\\python.exe' |
lib路径
1 2 | >>> sys.prefix 'C:\\python27' |
1 | subprocess.Popen(cmd, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
1 | ValueError: close_fds is not supported on Windows platforms if you redirect stdin /stdout/stderr |
1 | 在windows上subprocess.Popen的参数close_fds=True与stdin /stdout/stderr 不能共存 |
1 2 3 4 5 6 7 | s = ( 'select *' 'from atable' 'where id=888' ) print s, type (s) #输出 select * from atablewhere id = 888 < type 'str' > |
1 2 3 4 5 | C:\WINDOWS\system32>w32tm /resync 发生下列错误: 服务尚未启动。 (0x80070426) C:\WINDOWS\system32> echo %errorlevel% -2147023834 |
1 2 3 | >>> os.system( "w32tm /resync" ) 发生下列错误: 服务尚未启动。 (0x80070426) -2147023834 |
1 2 3 | >>> os.system( "w32tm /resync" ) 发生下列错误: 服务尚未启动。 (0x80070426) 0 |
1 | 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) |
1 2 3 4 5 6 7 8 9 10 | #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) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #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 |
1 | sched.add_job(child_job, max_instances=10, trigger=DateTrigger(), id = "123" ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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() |
1 2 3 4 5 6 7 | 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 |
1 2 3 4 5 6 7 8 9 10 11 | 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() |
1 | sudo yum install gettext |
1 2 3 4 5 6 7 8 | #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" ) |
1 | xgettext -L python -o zh_CN.po demo.py |
1 2 3 4 5 6 7 8 9 | ... #修改编码为utf-8 "Content-Type: text/plain; charset=utf-8\n" ... #加上翻译 #: demo.py:6 msgid "hello world" msgstr "你好,世界" |
1 | mkdir -p locale /zh_CN/LC_MESSAGES |
1 | msgfmt -o ~ /locale/zh_CN/LC_MESSAGES/demo .mo zh_CN.po |
1 2 | ➜ ~ python demo.py 你好,世界 |