Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pyperclip仅将列表共分类中的最后一项复制到剪贴板_Python_Python 3.x - Fatal编程技术网

Python pyperclip仅将列表共分类中的最后一项复制到剪贴板

Python pyperclip仅将列表共分类中的最后一项复制到剪贴板,python,python-3.x,Python,Python 3.x,完全是python的新手。请,我需要pyperclip将打印结果复制到此代码上的剪贴板 print ('These generates image variation titles and a .jpg file extension added to each number.') vartop = [] while True: print('Enter the variation ID ' + str(len(vartop) + 1) + ' (or Enter to Generate.):')

完全是python的新手。请,我需要pyperclip将打印结果复制到此代码上的剪贴板

print ('These generates image variation titles and a .jpg file extension added to each number.')
vartop = []
while True:
print('Enter the variation ID ' + str(len(vartop) + 1) + ' (or Enter to Generate.):')
myVar = input()
if myVar == '':
    break
    vartop = vartop + [myVar]
print('Variations are: ')
for myVar in vartop:
print (myVar + '.jpg') #I want this result to be copied to the clipboard.
import pyperclip
pyperclip.copy(myVar + '.jpg') #This code copies only the last generated line to the clipboard.
print ('Variations Copied to clipboard.')
这是我想要复制的结果

10.jpg
20.jpg
但只有最后一行“20.jpg”复制到剪贴板

20.jpg
pyperclip.copy()
接受单个字符串。使用修改后的示例:

给定的

import pyperclip


filenames = [f"{x}.jpg" for x in range(10, 30, 10)]
结果是一组字符串:

filenames
# ['10.jpg', '20.jpg']
代码

将文件名合并为一个字符串,以换行符分隔:

"\n".join(filenames)
# '10.jpg\n20.jpg'
演示

用下划线
复制最后一个结果:

pyperclip.copy(_)
粘贴结果,例如
Ctrl+V

10.jpg
20.jpg
pyperclip.copy()
接受单个字符串。使用修改后的示例:

给定的

import pyperclip


filenames = [f"{x}.jpg" for x in range(10, 30, 10)]
结果是一组字符串:

filenames
# ['10.jpg', '20.jpg']
代码

将文件名合并为一个字符串,以换行符分隔:

"\n".join(filenames)
# '10.jpg\n20.jpg'
演示

用下划线
复制最后一个结果:

pyperclip.copy(_)
粘贴结果,例如
Ctrl+V

10.jpg
20.jpg

我遇到一个问题,
pyperclip.copy
只将打印函数的最后一个字符串复制到剪贴板,我希望它复制整个输出。这就是我从@pylang中提出的解决方案

print ('These generates image variation titles and a .jpg file extension added to    each number.')
vartop = []
while True:
print('Enter the variation ID ' + str(len(vartop) + 1) + ' (or Enter to Generate.):')
myVar = input()
if myVar == '':
    break
vartop = vartop + [myVar + '.jpg'] #I added the file extension to the list Concatenation
print('Variations are: ')
for myVar in vartop:
print(myVar)
import pyperclip
pyperclip.copy("\n".join(vartop + [myVar])) #Using a list separator "\n", i added the code i wanted in my clipboard to the pyperclip.copy without the file extension.
print ('Variation Titles Copied to clipboard.')

现在,使用pyperclip生成了带有
'.jpg'
扩展名的整个用户
input()
,并将其复制到剪贴板。

我遇到了一个问题,
pyperclip.copy
只将打印函数的最后一个字符串复制到剪贴板,我希望它复制整个输出。这就是我从@pylang中提出的解决方案

print ('These generates image variation titles and a .jpg file extension added to    each number.')
vartop = []
while True:
print('Enter the variation ID ' + str(len(vartop) + 1) + ' (or Enter to Generate.):')
myVar = input()
if myVar == '':
    break
vartop = vartop + [myVar + '.jpg'] #I added the file extension to the list Concatenation
print('Variations are: ')
for myVar in vartop:
print(myVar)
import pyperclip
pyperclip.copy("\n".join(vartop + [myVar])) #Using a list separator "\n", i added the code i wanted in my clipboard to the pyperclip.copy without the file extension.
print ('Variation Titles Copied to clipboard.')

现在,整个用户
input()
'.jpg'
扩展名被生成,并使用pyperclip复制到剪贴板。

您可以创建一个字符串,然后使用
pyperclip
复制它。感谢您的回复。你能详细解释一下吗?谢谢。您可以制作一个字符串,然后用
pyperclip
复制它。谢谢您的回复。你能详细解释一下吗?谢谢。非常感谢@pylang。如果我想生成一个特定的范围,您的解决方案
filenames=[f“{x}.jpg”对于范围(10,30,10)中的x)]
是有效的。但在这里,我想从多用户输入()中生成“文件名”,并使用pyperclip打印。谢谢@pylang在这么多小时后,我设法解决了这个问题。谢谢你帮我指点。我很感激。我会马上发布解决方案。非常感谢@pylang。如果我想生成一个特定的范围,您的解决方案
filenames=[f“{x}.jpg”对于范围(10,30,10)中的x)]
是有效的。但在这里,我想从多用户输入()中生成“文件名”,并使用pyperclip打印。谢谢@pylang在这么多小时后,我设法解决了这个问题。谢谢你帮我指点。我很感激。我会马上发布解决方案。干得好。很高兴你自己解决了。欢迎来到Python!干得好。很高兴你自己解决了。欢迎来到Python!