This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 我们创建了一个generator后,基本上永远不会调用next(),而是通过for循环来迭代它,并且不需要关心StopIteration的错误 | |
>>> g = (x * x for x in range(10)) | |
>>> for n in g: | |
... print(n) | |
... | |
0 | |
1 | |
4 | |
9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import os # 导入os模块,模块的概念后面讲到 | |
>>> [d for d in os.listdir('.')] # os.listdir可以列出文件和目录 | |
['.emacs.d', '.ssh', '.Trash', 'Adlm', 'Applications', 'Desktop', 'Documents', 'Downloads', 'Library', 'Movies', 'Music', 'Pictures', 'Public', 'VirtualBox VMs', 'Workspace', 'XCode'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> list(range(1, 11)) | |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python内置的enumerate函数可以把一个list变成索引-元素对,这样就可以在for循环中同时迭代索引和元素本身: | |
>>> for i, value in enumerate(['A', 'B', 'C']): | |
... print(i, value) | |
... | |
0 A | |
1 B | |
2 C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 判断对象是否是可以迭代的对象 | |
>>> from collections import Iterable | |
>>> isinstance('abc', Iterable) # str是否可迭代 | |
True | |
>>> isinstance([1,2,3], Iterable) # list是否可迭代 | |
True | |
>>> isinstance(123, Iterable) # 整数是否可迭代 | |
False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 获取controller中的所有action和description | |
Assembly asm = Assembly.GetAssembly(typeof(NjModelmgr.MvcApplication)); | |
var controlleractionlist = asm.GetTypes() | |
.Where(type => typeof(System.Web.Mvc.Controller).IsAssignableFrom(type)) | |
.SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public)) | |
.Where(m => !m.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), true).Any()) | |
.Select(x => new | |
{ | |
Controller = x.DeclaringType.Name, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//新增或者更新SPListItem中的多选字段 | |
SPFieldMultiChoiceValue values = new SPFieldMultiChoiceValue(); | |
foreach (JObject item7 in item3) | |
{ | |
var itemChoiceName = item7.GetValue("key").ToString(); | |
//var itemChoiceValue = item7.GetValue("value").ToString(); | |
values.Add(itemChoiceName); | |
} | |
spListItem[itemName] = values; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApp14 | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.SharePoint; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using System.Text; | |
namespace ConsoleApplication2 | |
{ | |
class Program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using AutoMapper; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApp10 | |
{ | |
class Program |