当前位置: 首页>>代码示例>>Python>>正文


Python utils.is_string_like方法代码示例

本文整理汇总了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 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:14,代码来源:pajek.py

示例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 
开发者ID:holzschu,项目名称:Carnets,代码行数:14,代码来源:pajek.py

示例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 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:14,代码来源:pajek.py

示例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 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:54,代码来源:leda.py

示例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 
开发者ID:holzschu,项目名称:Carnets,代码行数:56,代码来源:leda.py


注:本文中的networkx.utils.is_string_like方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。