First and Last element of String in brackets when copied to file

huangapple go评论101阅读模式
英文:

First and Last element of String in brackets when copied to file

问题

Here's the translated content you requested:

  1. <h4>Explanation:</h4>
  2. 我有一个名为`text()`的函数,它根据一个变量是`0`还是`1`,将一系列字符串附加到列表`Prüftext`中,并将该字符串复制到我的剪贴板。
  3. 我从两个在函数外部定义的列表中获取要附加的字符串。它们是:
  4. ```py
  5. SetBlock = ["SetBlock1", "SetBlock2", "SetBlock3", "SetBlock4"]

和:

  1. TextBlock = ["TextBlock1", "TextBlock2", "TextBlock3", "TextBlock4"]

我的问题:

当我将字符串复制到文件中时,第一个和最后一个元素都是这样的:
```plaintext
{SetBlock1} TextBlock1 TextBlock2 {SetBlock3}
```

或者当我在函数中切换列表时,我得到这个:

  1. TextBlock1 {SetBlock1} {SetBlock3} TextBlock2

但我想要的是:

  1. SetBlock1 TextBlock1 TextBlock2 SetBlock3

如果我通过Prüftext.append("手动字符串")手动附加一个字符串,它也会出现在大括号中。

因此,这似乎与列表以及它们的访问方式有关?

我已经导入了tkinter作为Tk


该函数:

  1. def text(pfVar):
  2. Prüftext = []
  3. dummy = ""
  4. if pfVar == 0:
  5. Prüftext.append(SetBlock[0])
  6. if pfVar == 1:
  7. Prüftext.append(SetBlock[1])
  8. for i in range(0, len(Indicator)):
  9. if Indicator[i] == 1:
  10. Prüftext.append(TextBlock[i])
  11. if kosten == -1:
  12. Prüftext.append(SetBlock[3])
  13. if kosten == 1:
  14. Prüftext.append(SetBlock[2])
  15. if kosten == 0:
  16. dummy = dummy
  17. r = Tk()
  18. r.withdraw()
  19. r.clipboard_clear()
  20. r.clipboard_append(Prüftext)
  21. r.update()
  22. r.destroy()
  23. print(Prüftext)

我查看了tkinter文档并尝试更改SetBlockTextBlock中的文本,但没有找到我认为会对我有所帮助的内容。

  1. Please note that certain characters like `ü`, `ö`, and `ß` have been retained in the translation.
  2. <details>
  3. <summary>英文:</summary>
  4. &lt;h4&gt;Explaination:&lt;/h4&gt;
  5. I have a function `text()`, which is to append a series of strings to the list `Pr&#252;ftext`, depending on if a variable is `0` or `1`, and copy that string into my clipboard.
  6. I get the strings which are to be appended from two lists, that are defined outside of the function.
  7. These are:
  8. ```py
  9. SetBlock = [&quot;SetBlock1&quot;,&quot;SetBlock2&quot;,&quot;SetBlock3&quot;,&quot;SetBlock4&quot;]

and:

  1. TextBlock = [&quot;TextBlock1&quot;,&quot;TextBlock2&quot;,&quot;TextBlock3&quot;,&quot;TextBlock4&quot;]

<hr>
<h4>My Problem:</h4>
When I copy the string into a file, the first and last elements are in curly brackets like this:

  1. {SetBlock1} TextBlock1 TextBlock2 {SetBlock3}

Or when I switch out the lists in the function I get this:

  1. TextBlock1 {SetBlock1} {SetBlock3} TextBlock2

But I want:

  1. SetBlock1 TextBlock1 TextBlock2 SetBlock3

If I append a string after "manually" by doing Pr&#252;ftext.append(&quot;manual string&quot;), it is also in curly brackets.

So it seems to be related in some kind to the lists and how they are accessed?

I have imported tkinter as Tk

<hr>
<h4>The function:</h4>

  1. def text(pfVar):
  2. Pr&#252;ftext = []
  3. dummy = &quot;&quot;
  4. if pfVar == 0:
  5. Pr&#252;ftext.append(SetBlock[0])
  6. if pfVar == 1:
  7. Pr&#252;ftext.append(SetBlock[1])
  8. for i in range(0, len(Indicator)):
  9. if Indicator[i] == 1:
  10. Pr&#252;ftext.append(TextBlock[i])
  11. if kosten == -1:
  12. Pr&#252;ftext.append(SetBlock[3])
  13. if kosten == 1:
  14. Pr&#252;ftext.append(SetBlock[2])
  15. if kosten == 0:
  16. dummy = dummy
  17. r = Tk()
  18. r.withdraw()
  19. r.clipboard_clear()
  20. r.clipboard_append(Pr&#252;ftext)
  21. r.update()
  22. r.destroy()
  23. print(Pr&#252;ftext)

I have looked at the tkinter documentation and tried to change out the text in the lists SetBlock, and TextBlock but didn't find anything that I think would help me.

答案1

得分: 1

尝试将 r.clipboard_append(Pr&#252;ftext) 更改为 r.clipboard_append(&quot;, &quot;.join(Pr&#252;ftext))

英文:

Try to change r.clipboard_append(Pr&#252;ftext) to r.clipboard_append(&quot;, &quot;.join(Pr&#252;ftext))

huangapple
  • 本文由 发表于 2023年5月21日 03:13:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76296956.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定