m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.1 KiB

6 months ago
  1. from __future__ import print_function, unicode_literals, absolute_import
  2. import sys
  3. success = True
  4. in_ironpython = "IronPython" in sys.version
  5. if in_ironpython:
  6. try:
  7. from .ironpython_clipboard import GetClipboardText, SetClipboardText
  8. except ImportError:
  9. from .no_clipboard import GetClipboardText, SetClipboardText
  10. else:
  11. try:
  12. from .win32_clipboard import GetClipboardText, SetClipboardText
  13. except ImportError:
  14. from .no_clipboard import GetClipboardText, SetClipboardText
  15. def send_data(lists):
  16. SetClipboardText(make_tab(lists))
  17. def set_clipboard_text(toclipboard):
  18. SetClipboardText(str(toclipboard))
  19. def make_tab(lists):
  20. if hasattr(lists, "tolist"):
  21. lists = lists.tolist()
  22. ut = []
  23. for rad in lists:
  24. if type(rad) in [list, tuple]:
  25. ut.append("\t".join(["%s"%x for x in rad]))
  26. else:
  27. ut.append("%s"%rad)
  28. return "\n".join(ut)
  29. def make_list_of_list(txt):
  30. def make_num(x):
  31. try:
  32. return int(x)
  33. except ValueError:
  34. try:
  35. return float(x)
  36. except ValueError:
  37. try:
  38. return complex(x)
  39. except ValueError:
  40. return x
  41. return x
  42. ut = []
  43. flag = False
  44. for rad in [x for x in txt.split("\r\n") if x != ""]:
  45. raden=[make_num(x) for x in rad.split("\t")]
  46. if str in list(map(type,raden)):
  47. flag = True
  48. ut.append(raden)
  49. return ut, flag
  50. def get_clipboard_text_and_convert(paste_list=False):
  51. """Get txt from clipboard. if paste_list==True the convert tab separated
  52. data to list of lists. Enclose list of list in array() if all elements are
  53. numeric"""
  54. txt = GetClipboardText()
  55. if txt:
  56. if paste_list and "\t" in txt:
  57. array, flag = make_list_of_list(txt)
  58. if flag:
  59. txt = repr(array)
  60. else:
  61. txt = "array(%s)"%repr(array)
  62. txt = "".join([c for c in txt if c not in " \t\r\n"])
  63. return txt