本文整理汇总了Python中networkx.utils.is_string_like方法的典型用法代码示例。如果您正苦于以下问题:Python utils.is_string_like方法的具体用法?Python utils.is_string_like怎么用?Python utils.is_string_like使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.utils
的用法示例。
在下文中一共展示了utils.is_string_like方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_qstr
# 需要导入模块: from networkx import utils [as 别名]
# 或者: from networkx.utils import is_string_like [as 别名]
def make_qstr(t):
"""Return the string representation of t.
Add outer double-quotes if the string has a space.
"""
if not is_string_like(t):
t = str(t)
if " " in t:
t=r'"%s"'%t
return t
# fixture for nose tests
示例2: make_qstr
# 需要导入模块: from networkx import utils [as 别名]
# 或者: from networkx.utils import is_string_like [as 别名]
def make_qstr(t):
"""Returns the string representation of t.
Add outer double-quotes if the string has a space.
"""
if not is_string_like(t):
t = str(t)
if " " in t:
t = r'"%s"' % t
return t
# fixture for nose tests
示例3: make_qstr
# 需要导入模块: from networkx import utils [as 别名]
# 或者: from networkx.utils import is_string_like [as 别名]
def make_qstr(t):
"""Return the string representation of t.
Add outer double-quotes if the string has a space.
"""
if not is_string_like(t):
t = str(t)
if " " in t:
t = r'"%s"' % t
return t
# fixture for nose tests
示例4: parse_leda
# 需要导入模块: from networkx import utils [as 别名]
# 或者: from networkx.utils import is_string_like [as 别名]
def parse_leda(lines):
"""Read graph in LEDA format from string or iterable.
Parameters
----------
lines : string or iterable
Data in LEDA format.
Returns
-------
G : NetworkX graph
Examples
--------
G=nx.parse_leda(string)
References
----------
.. [1] http://www.algorithmic-solutions.info/leda_guide/graphs/leda_native_graph_fileformat.html
"""
if is_string_like(lines): lines=iter(lines.split('\n'))
lines = iter([line.rstrip('\n') for line in lines \
if not (line.startswith('#') or line.startswith('\n') or line=='')])
for i in range(3):
next(lines)
# Graph
du = int(next(lines)) # -1=directed, -2=undirected
if du==-1:
G = nx.DiGraph()
else:
G = nx.Graph()
# Nodes
n =int(next(lines)) # number of nodes
node={}
for i in range(1,n+1): # LEDA counts from 1 to n
symbol=next(lines).rstrip().strip('|{}| ')
if symbol=="": symbol=str(i) # use int if no label - could be trouble
node[i]=symbol
G.add_nodes_from([s for i,s in node.items()])
# Edges
m = int(next(lines)) # number of edges
for i in range(m):
try:
s,t,reversal,label=next(lines).split()
except:
raise NetworkXError('Too few fields in LEDA.GRAPH edge %d'%(i+1))
# BEWARE: no handling of reversal edges
G.add_edge(node[int(s)],node[int(t)],label=label[2:-2])
return G
示例5: parse_leda
# 需要导入模块: from networkx import utils [as 别名]
# 或者: from networkx.utils import is_string_like [as 别名]
def parse_leda(lines):
"""Read graph in LEDA format from string or iterable.
Parameters
----------
lines : string or iterable
Data in LEDA format.
Returns
-------
G : NetworkX graph
Examples
--------
G=nx.parse_leda(string)
References
----------
.. [1] http://www.algorithmic-solutions.info/leda_guide/graphs/leda_native_graph_fileformat.html
"""
if is_string_like(lines):
lines = iter(lines.split('\n'))
lines = iter([line.rstrip('\n') for line in lines
if not (line.startswith('#') or line.startswith('\n') or line == '')])
for i in range(3):
next(lines)
# Graph
du = int(next(lines)) # -1=directed, -2=undirected
if du == -1:
G = nx.DiGraph()
else:
G = nx.Graph()
# Nodes
n = int(next(lines)) # number of nodes
node = {}
for i in range(1, n + 1): # LEDA counts from 1 to n
symbol = next(lines).rstrip().strip('|{}| ')
if symbol == "":
symbol = str(i) # use int if no label - could be trouble
node[i] = symbol
G.add_nodes_from([s for i, s in node.items()])
# Edges
m = int(next(lines)) # number of edges
for i in range(m):
try:
s, t, reversal, label = next(lines).split()
except:
raise NetworkXError('Too few fields in LEDA.GRAPH edge %d' % (i + 1))
# BEWARE: no handling of reversal edges
G.add_edge(node[int(s)], node[int(t)], label=label[2:-2])
return G