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


Python Network.from_file方法代码示例

本文整理汇总了Python中network.Network.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Network.from_file方法的具体用法?Python Network.from_file怎么用?Python Network.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在network.Network的用法示例。


在下文中一共展示了Network.from_file方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import from_file [as 别名]
from urllib.parse import quote, unquote, parse_qs

from jinja2 import Environment, FileSystemLoader

from network import Network

filename = 'network0.pimesh'

with open(filename) as net_file:
    net = Network.from_file(net_file)

jinja_env = Environment(loader=FileSystemLoader('./html'),
                        extensions=['jinja2.ext.autoescape'],
                        autoescape=True)

tpl_list = jinja_env.get_template('list.html')
tpl_view = jinja_env.get_template('view.html')

def application(env, start_response):

    path = env.get('PATH_INFO', "").lstrip('/')
    cmd, *rest = path.split("/", 1)
    arg = unquote(rest[0]).strip() if rest else ""

    try:
        request_body_size = int(env.get('CONTENT_LENGTH', 0))
    except (ValueError):
        request_body_size = 0
    request_body = env['wsgi.input'].read(request_body_size).decode()

    status = "200 OK"
开发者ID:FLHerne,项目名称:PIMesh,代码行数:33,代码来源:netui.py

示例2: open

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import from_file [as 别名]
#!/usr/bin/env python3
#Top-level wrapper script for a general-purpose information-management tool

import sys
from network import Network
from cliui import UI

try:
  filename = sys.argv[1]
  try:
      networkfile = open(filename, 'r+')
      network = Network.from_file(networkfile)         # Note that this does not (and should not) create a new file
      print("Loaded PIMesh network from file")
  except FileNotFoundError:
      network = Network()
      print("Created empty network (file not found)")

  ui = UI(network)

  try:
      ui.run()
  except KeyboardInterrupt:
      print("Caught leopard interrupt")
      
  try:
      network.to_file(networkfile)
      print("Saved session changes to file.")
  except:
      print("Saving to file failed!")
     
except IndexError:
开发者ID:BinkyToo,项目名称:PIMesh,代码行数:33,代码来源:pimesh.py

示例3: open

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import from_file [as 别名]
#!/usr/bin/env python3
#Top-level wrapper script for a general-purpose information-management tool

import sys
from network import Network
from cliui import UI

try:
    filename = sys.argv[1]
    try:
        networkfile = open(filename, 'r+')
        # Note that this does not (and should not) create a new file
        network = Network.from_file(networkfile)
        print("Loaded PIMesh network from file")
    except FileNotFoundError:
        networkfile = open(filename, 'w')
        network = Network()
        print("Created empty network (file not found)")

    ui = UI(network)

    try:
        ui.run()
    except KeyboardInterrupt:
        print("Caught leopard interrupt")

    networkfile.seek(0)
    try:
        network.to_file(networkfile)
        networkfile.truncate()
        print("Saved session changes to file.")
开发者ID:FLHerne,项目名称:PIMesh,代码行数:33,代码来源:pimesh.py

示例4: __init__

# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import from_file [as 别名]
class UI:
  def __init__(self, lines, cols):
    self.mode = Mode.list
    self.status = "Started PIMesh"
    self.lines = lines
    self.cols = cols

UI = UI(shutil.get_terminal_size()[0], shutil.get_terminal_size()[1])

print("\x1B]0;%s\x07" % "PIMesh") # Set window title

filename = "network0.pimesh"            # Currently fixed filename - should it really be an argument when starting the script?

try:
    network = Network.from_file(open(filename))
    UI.status = "Loaded PIMesh network from file"
except FileNotFoundError:
    network = Network()
    UI.status = "Created empty network (file not found)"

def print_entity_list():
    """Print a list of entitites which have one of more links to/from them"""
    #global UI.status
    if len(network) == 0:
        print("(No entities in network)")           # Could be slightly confusing, but saves a big empty space
        return 1
    for n, name in enumerate(network.origins):
        print(str(n) + " | " + name)
    return len(network)         # number of lines printed by this function, needed to pad vertically by the right amount
开发者ID:BinkyToo,项目名称:PIMesh,代码行数:31,代码来源:interactiveUI.py


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