Home>

Help with the code, I can't figure out how to iterate over the list as a loop in one line The bottom line: you need to transfer the following to the command line:

[ '44c703adea2b463f8feda2b87454c4e8.1.jpg', '44c703adea2b463f8feda2b87454c4e8.2.jpg', '44c703adea2b463f8feda2b87454c4e8.3.jpg', '44c703adea2b463f8feda2b87454c4e8.4.jpg', '44c703adea2b463f8feda2b87454c4e8.5.jpg', '44c703adea2b463f8feda2b87454c4e8. 6.jpg ',' 44c703adea2b463f8feda2b87454c4e8.7.jpg ',' 44c703adea2b463f8feda2b87454c4e8.8.jpg ',' 44c703adea2b463f8feda2b87454c4e8.9.jpg ',' 44c703adea2b463f8feda2b87454c4e8.avi ',' 44c703adea2b463f8feda2b87454c4e8.jpg ']

It is necessary that the enumeration of elements from the list is through a plus, for example:

44c703adea2b463f8feda2b87454c4e8.1.jpg + 44c703adea2b463f8feda2b87454c4e8.2.jpg + 44c703adea2b463f8feda2b87454c4e8.3.jpg

and so on.

In the internet I found information only line by line output. And you need one line, thank you for your help.

upd .:

It takes one line to run this into the command line:

s= "+" .join (data)
os.system ('copy' + s + 'check.bin')

The problem is now throwing an error:

Traceback (most recent call last):
  File "C: /Users/PilotDrowa/PycharmProjects/pythonProject/main.py", line 22, in <
module >
    returned_output= subprocess.check_output (cmd) # returned_output contains byte string output
  File "C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ subprocess.py", line 411, in check_output
    ** kwargs) .stdout
  File "C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ subprocess.py", line 488, in run
    with Popen (* popenargs, ** kwargs) as process:
  File "C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "C: \ Program Files (x86) \ Microsoft Visual Studio \ Shared \ Python37_64 \ lib \ subprocess.py", line 1207, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The specified file cannot be found

'+' .join (a). And why exactly in one line?

EzikBro2021-10-17 02:09:12

You need to send the data to the command line

Владислав Швецов2021-10-17 02:09:12

@ VladislavShvetsov Your update is another problem and another question. It is more logical to formulate and set it separately.

Alpensin2021-10-16 07:41:55
  • Answer # 1
    a= ['1.jpg', '2.jpg', '3.jpg']
    

    A string variable in the desired form can be written as follows:

    s= "+" .join (a) # We get the value: '1.jpg + 2.jpg + 3.jpg'
    

    Immediately display it like this:

    print (* a, sep= '+') # The screen will display: 1.jpg + 2.jpg + 3.jpg
    

    Add what the output will look like with your sample data

    CrazyElf2021-10-17 02:09:12

    44c703adea2b463f8feda2b87454c4e8.1.jpg + 44c703adea2b463f8feda2b87454c4e8.2.jpg + 44c703adea2b463f8feda2b87454c4e8.3.jpg + 44c703adea2b463f8feda2b87454c4e8.4.jpg + 44c703adea2b463f8feda2b87454c4e8.5.jpg + 44c703adea2b463f8feda2b87454c4e8.6.jpg + 44c703adea2b463f8feda2b87454c4e8.7.jpg + 44c703adea2b463f8feda2b87454c4e8.8.jpg + 44c703adea2b463f8feda2b87454c4e8. 9.jpg + 44c703adea2b463f8feda2b87454c4e8.avi + 44c703adea2b463f8feda2b87454c4e8.jpg + 44c703adea2b463f8feda2b87454c4e8.xml

    Владислав Швецов2021-10-17 02:09:12
  • Answer # 2
    a= ['1.jpg', '2.jpg', '3.jpg']
    

    A string variable in the desired form can be written as follows:

    s= "+" .join (a) # We get the value: '1.jpg + 2.jpg + 3.jpg'
    

    Immediately display it like this:

    print (* a, sep= '+') # The screen will display: 1.jpg + 2.jpg + 3.jpg
    

    Add what the output will look like with your sample data

    CrazyElf2021-10-17 02:09:12

    44c703adea2b463f8feda2b87454c4e8.1.jpg + 44c703adea2b463f8feda2b87454c4e8.2.jpg + 44c703adea2b463f8feda2b87454c4e8.3.jpg + 44c703adea2b463f8feda2b87454c4e8.4.jpg + 44c703adea2b463f8feda2b87454c4e8.5.jpg + 44c703adea2b463f8feda2b87454c4e8.6.jpg + 44c703adea2b463f8feda2b87454c4e8.7.jpg + 44c703adea2b463f8feda2b87454c4e8.8.jpg + 44c703adea2b463f8feda2b87454c4e8. 9.jpg + 44c703adea2b463f8feda2b87454c4e8.avi + 44c703adea2b463f8feda2b87454c4e8.jpg + 44c703adea2b463f8feda2b87454c4e8.xml

    Владислав Швецов2021-10-17 02:09:12