我正在写一个多行文件,像这样的行:
func data() -> Data {
var imageData = UIImagePNGRepresentation(self)
// Resize the image if it exceeds the 2MB API limit
if (imageData?.count)! > 2097152 {
let oldSize = self.size
let newSize = CGSize(width: 800, height: oldSize.height / oldSize.width *
800)
let newImage = self.resizeImage(self, size: newSize)
imageData = UIImageJPEGRepresentation(newImage, 0.7)
}
return imageData!
}
在某些情况下,当我使用以下命令时,我需要使用一个包含文件路径的变量:
@IBOutlet weak var thumbImg: UIImageView!
let picture = Image()
let imageDownSizing = thumbImg.image?.data()
//thumbImg.image is of type UIImage type, so convert UIImage -> Data.
//picture.image is of type Data.
picture.image = UIImagePNGRepresentation(thumbImg.image!)
picture.image = imageDownSizing
let item = Item()
item.toImage = picture
do{
let realm = try! Realm()
try realm.write {
realm.add(item)
}
}catch{
print("Error saving context \(error)")
}
结果:
workspace -fr "fluidCache" "cache/nCache/fluid";
我需要的结果是带有引号的render_output:
render_output = os.path.join(project_root, r'common\render_output')
ws_file.write("""workspace -fr "images" {0};""".format(render_output))
我应该如何设置render_output的格式,以便在三引号的write参数中保留其字符串值的引用?
答案 0 :(得分:2)
ws_file.write("""workspace -fr "images" "{0}";""".format(render_output))