python中的方法获取如下模式字符串
Method in python to obtain the following pattern string
我正在使用 tylertreat/BigQuery-Python
从 BigQuery 获取表格列表,下面的代码在这里,
class get_Tables:
def GET(self,r):
web.header('Access-Control-Allow-Origin', '*')
web.header('Access-Control-Allow-Credentials', 'true')
tables = []
datasetID = web.input().dataSetID
client = get_client(project_id, service_account=service_account,
private_key_file=key, readonly=True)
result = client._get_all_tables(datasetID,cache=False)
tablesWithDetails = result["tables"]
for inditable in tablesWithDetails:
tables.append(inditable["id"])
print(json.dumps(tables))
return json.dumps(tables)
上面的方法returns一个JSON这样的,
["thematic-scope-112013:Demo.Airport_Traffic",
"thematic-scope-112013:Demo.Alcohol_Consumption",
"thematic-scope-112013:Demo.Flight_paths",
"thematic-scope-112013:Demo.GDP_Country_Wise",
"thematic-scope-112013:Demo.like_data",
"thematic-scope-112013:Demo.medicare_cost"]
但我只想要没有项目和数据集名称,
获取以下格式的模式或正则表达式是什么,
["Airport_Traffic", "Alcohol_Consumption", "Flight_paths",
"GDP_Country_Wise", "like_data", "medicare_cost"]
不需要regex,一个split方法就够了。即,根据点拆分每个列表项,然后从该拆分列表中获取最后一个元素。
[i.split('.')[-1] for i in data]
示例:
>>> data = ["thematic-scope-112013:Demo.Airport_Traffic", "thematic-scope-112013:Demo.Alcohol_Consumption", "thematic-scope-112013:Demo.Flight_paths", "thematic-scope-112013:Demo.GDP_Country_Wise", "thematic-scope-112013:Demo.like_data", "thematic-scope-112013:Demo.medicare_cost"]
>>> [i.split('.')[-1] for i in data]
['Airport_Traffic', 'Alcohol_Consumption', 'Flight_paths', 'GDP_Country_Wise', 'like_data', 'medicare_cost']
我正在使用 tylertreat/BigQuery-Python
从 BigQuery 获取表格列表,下面的代码在这里,
class get_Tables:
def GET(self,r):
web.header('Access-Control-Allow-Origin', '*')
web.header('Access-Control-Allow-Credentials', 'true')
tables = []
datasetID = web.input().dataSetID
client = get_client(project_id, service_account=service_account,
private_key_file=key, readonly=True)
result = client._get_all_tables(datasetID,cache=False)
tablesWithDetails = result["tables"]
for inditable in tablesWithDetails:
tables.append(inditable["id"])
print(json.dumps(tables))
return json.dumps(tables)
上面的方法returns一个JSON这样的,
["thematic-scope-112013:Demo.Airport_Traffic", "thematic-scope-112013:Demo.Alcohol_Consumption", "thematic-scope-112013:Demo.Flight_paths", "thematic-scope-112013:Demo.GDP_Country_Wise", "thematic-scope-112013:Demo.like_data", "thematic-scope-112013:Demo.medicare_cost"]
但我只想要没有项目和数据集名称,
获取以下格式的模式或正则表达式是什么,
["Airport_Traffic", "Alcohol_Consumption", "Flight_paths", "GDP_Country_Wise", "like_data", "medicare_cost"]
不需要regex,一个split方法就够了。即,根据点拆分每个列表项,然后从该拆分列表中获取最后一个元素。
[i.split('.')[-1] for i in data]
示例:
>>> data = ["thematic-scope-112013:Demo.Airport_Traffic", "thematic-scope-112013:Demo.Alcohol_Consumption", "thematic-scope-112013:Demo.Flight_paths", "thematic-scope-112013:Demo.GDP_Country_Wise", "thematic-scope-112013:Demo.like_data", "thematic-scope-112013:Demo.medicare_cost"]
>>> [i.split('.')[-1] for i in data]
['Airport_Traffic', 'Alcohol_Consumption', 'Flight_paths', 'GDP_Country_Wise', 'like_data', 'medicare_cost']