gpt4 book ai didi

python - 我的变量不包括使用 sublime.get_clipboard() sublime text 插件复制的所有文本

转载 作者:太空宇宙 更新时间:2023-11-03 21:38:09 30 4
gpt4 key购买 nike

我正在尝试创建一个 Sublime Text 3 插件,它从 .html、.css、.js 和 .php 等文件复制代码,然后将其粘贴到 txt 文档中。

我的问题是,有时当我从包含大量代码的文档中复制代码并将其粘贴到文本文档中时,某些代码会消失。

import sublime
import sublime_plugin

def save_code(file):
sublime.active_window().active_view().set_status("","Your file is
saved inside _templates " + file + "!")
text_file = open("path_to_file/_templates"+file, "w")
my_copy = str(sublime.get_clipboard())
text_file.write("%s" % my_copy)
text_file.close()
class MycopypasteCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.window().show_input_panel("Add
filename:","",save_code,None,None)

最佳答案

终于找到解决办法了。我的问题是,当我复制包含“Åäö”的文本时,text_file.write("%s"% my_copy) 无法写入文件。我的解决方案很简单。只需要2在open("path_to_file, "w", open("path_to_file/_templates"+file, "w",encoding="utf-8")末尾添加encoding="utf-8"

关于python - 我的变量不包括使用 sublime.get_clipboard() sublime text 插件复制的所有文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53108814/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com