我正在尝试使用Python 我尝试过: 但是它返回: 而不是我所期望的: 我要去哪里错了? 答案 0 :(得分:1) 括号表示您需要括号内的其他成员(字符)。试试这个: 此处的简单示例:public static IEnumerable<object> CreateClass<T>(this T[,] array)
{
int rowCount = array.GetLength(0);
int columnCount = array.GetLength(1);
var fields = array.SliceHeaderRow().ToList(); //convert 1st row to 1d array
var properties = fields
.Select(f => new DynamicProperty(f, f.GetType()))
.ToList();
Type dynoType = DynamicClassFactory.CreateType(properties);
object obj = Activator.CreateInstance(dynoType);
int jj;
for (int ii = 1; ii < rowCount; ii++) //skip first row
{
jj = 0;
foreach (var field in fields)
dynoType.GetProperty(field).SetValue(obj, array[ii, jj], null);
jj++;
yield return obj;
}
}
public static string[] SliceHeaderRow<T>(this T[,] array)
{
string[] fieldNames = new string[array.GetLength(0) - 1];
for (int jj = 0; jj < array.GetLength(1); jj++)
fieldNames[jj] = array[0, jj].ToString();
return fieldNames;
}
模块将字符串中的日期替换为<Month Year>
。re
import re
s = "Wikipedia articles containing buzzwords from April 2014\t23"
s = re.sub(r"[January|April|March]\s+\d{1,4}", "<Month Year>", s)
'Wikipedia articles containing buzzwords from Apri<Month Year>\t23'
1 个答案:
s = re.sub(r"(January|April|March)\s+\d{1,4}", "<Month Year>", s)
>>> import re
>>> s = "Wikipedia articles containing buzzwords from April 2014\t23"
>>> s = re.sub(r"(January|April|March)\s+\d{1,4}", "<Month Year>", s)
>>> s
'Wikipedia articles containing buzzwords from <Month Year>\t23'