有用的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中的Thymleaf,在满足条件后如何中断/退出th:each循环   如何使用java和jconnector插入带有撇号的字符串作为mysql数据库字段的值?   java为什么我在hector的Cassandra中插入了双/浮点列,却在数据库中得到了不正确的值   java在两个不同的类中使用相同的对象   java Jetty 9与Spring 2兼容   java DAL应该作为类库实现还是在EJB中实现?   java对象类型列表和扩展类型的对象列表之间的区别   java使活动中的自定义视图无效   java JPA通用存储库,不适用于特定名称   java在服务调用时发送和管理事件   java读取大型json文件   JAVA将二维数组的对角线写入一维数组   java如果在'CharBuffer'或'Buffer'中没有任何相应的(allocateDirect)方法,我们如何分配直接CharBuffer?   java我无法安装EclipseIDE。错误为“*加载JNI共享库失败*”。我如何安装它?   java Solr搜索没有响应   java为什么我的两个JComponents实例中只有一个出现在大型机中   JavaGuice是否对特定实例使用注入?   JavaMaven程序集:我可以在另一个依赖项中的附加zip中包含文件吗?   Derby嵌入式数据库中的java查询