Skip to main content

Posts

Showing posts from August 14, 2016

The ABCs of APIs with Node.js with Greg Rewis

Argparse Sub-commands

ArgumentParser. add_subparsers ( [ title ] [ ,  description ] [ ,  prog ] [ ,  parser_class ] [ ,  action ] [ ,  option_string ] [ ,  dest ] [ ,  help ] [ ,  metavar ] ) Many programs split up their functionality into a number of sub-commands, for example, the  svn  program can invoke sub-commands like  svn   checkout ,  svn   update , and  svn   commit . Splitting up functionality this way can be a particularly good idea when a program performs several different functions which require different kinds of command-line arguments.  ArgumentParser  supports the creation of such sub-commands with the  add_subparsers()  method. The  add_subparsers()  method is normally called with no arguments and returns a special action object. This object has a single method,  add_parser() , which takes a command name and any  ArgumentParser  constructor arguments, and returns an  ArgumentParser  object that can be modified as usual. Description of parameters: title - title for the sub-pars

argparse vs optparse

Originally, the  argparse   module had attempted to maintain compatibility with   optparse . However,   optparse   was difficult to extend transparently, particularly with the changes required to support the new   nargs= specifiers and better usage messages. When most everything in   optparse   had either been copy-pasted over or monkey-patched, it no longer seemed practical to try to maintain the backwards compatibility. The  argparse  module improves on the standard library  optparse  module in a number of ways including: Handling positional arguments. Supporting sub-commands. Allowing alternative option prefixes like  +  and  / . Handling zero-or-more and one-or-more style arguments. Producing more informative usage messages. Providing a much simpler interface for custom  type  and  action . A partial upgrade path from  optparse  to  argparse : Replace all  optparse.OptionParser.add_option()  calls with  ArgumentParser.add_argument()  calls. Replace  (options,   args

Argparse mutual exclusion

ArgumentParser. add_mutually_exclusive_group ( required=False ) ¶ Create a mutually exclusive group.  argparse  will make sure that only one of the arguments in the mutually exclusive group was present on the command line: >>> >>> parser = argparse . ArgumentParser ( prog = 'PROG' ) >>> group = parser . add_mutually_exclusive_group () >>> group . add_argument ( '--foo' , action = 'store_true' ) >>> group . add_argument ( '--bar' , action = 'store_false' ) >>> parser . parse_args ([ '--foo' ]) Namespace(bar=True, foo=True) >>> parser . parse_args ([ '--bar' ]) Namespace(bar=False, foo=False) >>> parser . parse_args ([ '--foo' , '--bar' ]) usage: PROG [-h] [--foo | --bar] PROG: error: argument --bar: not allowed with argument --foo The  add_mutually_exclusive_group()  method also accepts a  required  argument, to ind

标  题: 最悲剧的无非是中年的时候才后悔自己走了很多的弯路

发信人: wushen (wushen), 信区: Midlife 标  题: 最悲剧的无非是中年的时候才后悔自己走了很多的弯路 发信站: BBS 未名空间站 (Sun Aug 14 01:18:42 2016, 美东) 公司有个同事,今天估计40岁了,现在还是一个小小的程序员,而且是级别很基础的那 种, 没事看到和一群92、93后的年轻人坐在一起开会的时候真心感觉有点别扭, 我们都很好奇,为什么这么大的岁数还这样的落魄,这么大的岁数自己的经历和学习能 力根本就不能和那些年轻人在一起比较了。 后来有机会在一起的吃饭的时候就聊到了这个事情, 这个同事也是无比感慨的说出自己心里的一些想法, 他年轻的时候总是喜欢放荡不羁 的生活,认为工作中的很多琐事和自己的理想生活是完全不相符的,也是这个哥们去追 求自己的理想,这个哥们的理想就是到处的去闲逛,一般旅行一般干着各种各样的兼职 ,基本上正好可以满足自己的花费, 就这样的日子足足的过了10年,到自己37岁的时候,才发现自己有点走不动了,以前的 那种生活方式可能已经不适应自己现在的阶段了, 这个时候,这个同事才开始去思考是不是要安定下来找份工作,最后去报了一个计算机 的速成班,然后就来这家公司了,话说这种经验的人找工作的时候真心十分的困难, 有点难过这个同事的经历,最困难的事情就是到了中年的时候才发现之前自己的路都是 弯路。 --

标  题: 美国公司基本BENEFIT构成

发信人: withoutacar (我决定好好说话了。), 信区: Military 标  题: 美国公司基本BENEFIT构成 发信站: BBS 未名空间站 (Sat Aug 13 19:07:33 2016, 美东) BENEFIT两个部分,HEALTH PLANS和WELFARE PLANS HEALTH PLANS包括的基本项目有medical,dental,vision,HSA,FSA和wellness plan。 WELFARE PLANS通常有Group life and AD&D,short and long term disability, voluntary supplemental life and AD&D和其它voluntary benefits。 其它voluntary benefits一般有critical illness,group accident,whole life, LTC等等。 Group life and AD&D: no cost to employee,通常BASIC部分是两倍base salary或者 某个金额 max。我们公司是40万美元封顶。IRS对超过5万的保费收税。AD&D差别大一些 ,我们公司是一样。 Short term disability: no cost to employee,benefit paid through company payroll process, 70% basic salary。有期限的,我们公司是52 weeks,听说过26 weeks的。 Long term disability: no cost to employee,60% basic salary或某个金额的max, 我们公司是每月1万2封顶。 Short and long term disability都有waiting period。Short term是7天,Long term 是52周。 voluntary就是自己花钱多买上边的。保费和补偿,年龄都有关系,我们公司发个表格 ,自己去对照看。 给你们讲讲,和国内的人吹牛逼时有个依据。