有用的python函数集合

ssutils的Python项目详细描述


s直到

有用的python函数集合

编剧

使用ScreenWriter为屏幕打印添加前缀

示例:

1-默认前缀

fromssutilsimportScreenwritersw=Screenwriter()sw.echo('my output')
Output:
2019-07-26-11:16:04 my output

2-日期时间部分前缀

fromssutilsimportScreenwritersw=Screenwriter('%Y-%m-%d %H:%M:%S.%f ')sw.echo('my output')
Output:
2019-07-26 11:16:04 my output

3-错误、警告和信息标准前缀

fromssutilsimportScreenwritersw=Screenwriter()sw.error('an error message')sw.warn('a warming message')sw.info('an informational message')
Output:
2019-07-29-11:39:00 ERROR: an error message
2019-07-29-11:39:00 WARN:  a warming message
2019-07-29-11:39:00 INFO:  an informational message

4-修剪内容长度

默认情况下,日志字符串被修剪为1000个字符。 您可以更改此设置:

fromssutilsimportScreenwritersw=Screenwriter()sw.set_maxlen(80)#Set maximum length to 80

有关格式选项,请参见http://strftime.org/

SFDC

使用sfdc查询sfdc。

示例:

1-列出对象

fromssutilsimportSfdcsf=Sfdc('userid','password','token',False)# last Param turns off verbosesf.connect()sf.load_metadata()forapininsf.object_labels.keys():print("API Name ["+apin+"], Label ["+sf.object_labels[apin]+"]")forapininsf.standard_object_names:print("Standard Object ["+apin+"]")forapininsf.custom_object_names:print("Custom Object ["+apin+"]")forapininsf.custom_setting_names:print("Custom Setting ["+apin+"]")

2-描述对象

fromssutilsimportSfdcsf=Sfdc('userid','password','token')sf.connect()sf.load_metadata()defprint_line(a,b,c,d,e):s='{:7}'.format(a)+'{:50}'.format(b)s+='{:20}'.format(c)+'{:20}'.format(d)+eprint(s)print_line('Seq','API Name','Type','Length','Label')print_line('---','--------','----','------','-----')fn=1forfldinsf.describe_object('Contact'):pfx="#"+str(fn).ljust(3)+" - "print_line(pfx,fld['name'],fld['type'],str(fld['length']),fld['label'])fn+=1

3-外汇兑换率

fromssutilsimportSfdcsf=Sfdc('userid','password','token')sf.connect()sf.load_fx_rates()print(sf.get_amount_in_USD(999,'EUR'))

4-根据传递的过滤器从表中查询

fromssutilsimportSfdcsf=Sfdc('userid','password','token')sf.connect()tcols=['Id','Account.Name']conds=[]conds.append("CloseDate >= "+str(date.today()+timedelta(days=-7)))conds.append("CloseDate <= "+str(date.today()))conds.append("StageName IN ('7. Closed Won')")sf.load_data('Opportunity',tcols,conds)forrecinsf.table_data['Opportunity']:print(rec)

5-从另一个表中具有匹配值(join)的表查询

在下面的示例中,变量jcond是一个3成员数组,它描述连接条件

  • 第一个值是需要连接的列
  • 第二个值是要连接的表
  • 第三个值是联接表中要与之匹配的列
fromssutilsimportSfdcsf=Sfdc('userid','password','token')sf.connect()tcols=['Id','Product2Id','TotalPrice','OpportunityId','CurrencyIsoCode']conds=["TotalPrice > 0"]jcond=['OpportunityId','Opportunity','Id']sf.load_data('OpportunityLineItem',tcols,conds,jcond)

日期

使用日期对日期进行一些计算

示例:

1-从日期

fromssutilsimportDatesd=Date()print('Quarter = '+sd.get_quarter('2019-04-15'))print('Quarter = '+sd.get_quarter())print('Month = '+sd.get_month('2019-04-15'))print('Month = '+sd.get_month())
Output (when run in August):
Quarter = Q2
Quarter = Q3
Month = April
Month = August

2-从日期

开始获取财政年度界限
fromssutilsimportDatesd=Date()print('Finacial Year Start = '+sd.get_year_start('2018-04-15'))print('Finacial Year End = '+sd.get_year_end('2018-04-15'))print('Finacial Year Start = '+sd.get_year_start())print('Finacial Year End = '+sd.get_year_end())
Output (when run in 2019):
Finacial Year Start = 2018-01-01
Finacial Year End = 2018-12-31
Finacial Year Start = 2019-01-01
Finacial Year End = 2019-12-31

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Swing会在减少Windows时间后忽略第一次单击   java使用Jsoup从网页获取价格   JavaSpringbeans,使它们可用于其他类?我的组件为空?   java如何实现Servlet的渐进响应?   java使3个视图可见,然后根据条件隐藏其他视图   列出如何根据Java中ArrayList的大小为变量分配字符?   将p5js草图转换为处理的javascript问题   java如何在推送时对mongodb中的数组元素进行排序?   Java中基于字段将csv文件拆分为多个文件   java boolean onClickEventListener返回的目的   java开关和if/else的哪种组合更快?为什么?   java在其他静态方法中调用局部变量?   编码风格Java枚举应该在它们自己的文件中定义吗?   java绘制jtable单元格编辑器(位于jtable上方)   java是否可以在tomcat中编辑类文件并重新编译单个文件?   java使用基类中泛型方法的方法引用,这给了我NoSuchMethodError   Java泛型与使用参数化类有关   Java类型转换的加密输出   我对eclipse上的以下Java代码有一个问题(无法访问的代码)