我正在 Python 脚本中使用该yaml模块来生成 YAML 文件。下面是一个例子:
import yaml
class MyDumper(yaml.Dumper):
def increase_indent(self, flow=False, indentless=False):
return super(MyDumper, self).increase_indent(flow, False)
foo = {
'instance_type': 'test',
'hostname': "\"testhost\"",
'name': 'foo',
'my_list': [
{'foo': 'test', 'bar': 'test2'},
{'foo': 'test3', 'bar': 'test4'}],
'hello': 'world',
}
print yaml.dump(foo, Dumper=MyDumper, default_flow_style=False)
Run Code Online (Sandbox Code Playgroud)
输出:
hello: world
hostname: '"testhost"'
instance_type: test
my_list:
- bar: test2
foo: test
- bar: test4
foo: test3
name: foo
Run Code Online (Sandbox Code Playgroud)
在上面的输出主机名值有单引号和双引号,我只想要双引号。
预期输出:
hello: world
hostname: "testhost"
instance_type: test
my_list:
- bar: test2
foo: test
- …Run Code Online (Sandbox Code Playgroud) 有没有办法我可以使用 paramiko scp 复制以名称“output”结尾的远程文件。
我有下面的代码,仅当我提供完整路径或确切的文件名时才会复制
下面是代码
import paramiko
import os
from paramiko import SSHClient
from scp import SCPClient
def createSSHClient(self, server):
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(server, self.port, self.user, self.password)
return client
def get_copy(self, hostname, dst):
ssh = self.createSSHClient(hostname)
scp = SCPClient(ssh.get_transport())
scp.get(dst)
scp.close()
Run Code Online (Sandbox Code Playgroud)
我正在尝试的是
get_copy(1.1.1.1, "*output")
Run Code Online (Sandbox Code Playgroud)
我收到文件未找到错误