我有一个菜鸟问题。我需要做这个类,它在 init 打开文件和其他函数中只是附加到这个打开的文件文本。我怎么能做到这一点?需要做这样的事情,但这不起作用,所以帮助。
文件1.py
from logsystem import LogginSystem as logsys
file_location='/tmp/test'
file = logsys(file_location)
file.write('some message')
Run Code Online (Sandbox Code Playgroud)
文件2.py
class LogginSystem(object):
def __init__(self, file_location):
self.log_file = open(file_location, 'a+')
def write(self, message):
self.log_file.write(message)
Run Code Online (Sandbox Code Playgroud)
谢谢
请帮助理解如何创建这样的东西?
data "aws_iam_policy_document" "assume_role_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
dynamic "statement" {
for_each = var.assume_role_identities != [] ? [true] : []
content {
actions = ["sts:AssumeRole"]
principals {
type = "AWS"
identifiers = var.assume_role_identities
}
}
}
dynamic "statement" {
for_each = var.assume_role_services != [] ? [true] : []
content {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = var.assume_role_services
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码的问题是,如果我不指定任何应该具有访问权限的角色或服务,则会退出并出现没有主体的错误。是否可以在动态块上设置一些计数条件?或者如何解决它?
问题说明:
问题是,如果我只想传递某个值,它将无法工作,因为它会形成一个空值 …