简体   繁体   中英

Syntax error when trying to create and print out a series of command-line commands

I'm trying to write a Python 3 script that will print out a series of command-line commands using variables.

Here's an example of the commands I'm trying to replicate:

filemorph cp testBitmap_1 gs://mapper-bitmap/TestBitmaps
filemorph cp gs://mapper-bitmap/TestBitmaps/testBitmap_1.svs /mnt/pixels/bitmaps
mkdir -p /mnt/pixels/1024/testBitmap_1
image_rotate --image_rotate-progress bitsave "/mnt/pixels/bitmaps/testBitmap_1.svs" /mnt/pixels/1024/testBitmap_1/ --pixel-size 1024
filemorph -m rsync -d -r /mnt/pixels/1024/testBitmap_1 gs://mapper-pixels/1024/testBitmap_1

Whenever I run my script, I get this error:

G:\Projects\Python\BitmapBot
λ python bitmapbot.py
  File "bitmapbot.py", line 26
    commands = """\
    ^
SyntaxError: invalid syntax

I checked all my intentations and they all seem correct so I'm not sure why it's giving me an error.

I'm not quite sure what I'm doing wrong.

If anyone sees anything, please let me know.

Thanks!

Oh here's the script:

import os

# define variables
data = dict(
    Bitmap_Name = 'testBitmap_1.svs',
    Bitmap_Title = 'testBitmap_1',
    Bitmap_Folder_Name = 'TestBitmaps',
    Cloud_Bitmap_Directory = 'gs://mapper-bitmap/',
    Pixel_Bitmap_Engine = '/mnt/pixels/bitmaps',
    Local_Bitmap_Directory = '',
    Local_Pixel_Directory = '/mnt/pixels/1024/',
    Cloud_Pixel_Directory = 'gs://mapper-pixels/1024/'

# create commands with Python:



commands = """\
filemorph cp {Bitmap_Name} {Cloud_Bitmap_Directory}/{Bitmap_Folder_Name}
filemorph cp {Cloud_Bitmap_Directory}/{Bitmap_Folder_Name}/{Bitmap_Name} {Pixel_Bitmap_Engine} 
mkdir -p {Local_Pixel_Directory}/{Bitmap_Title}
image_rotate --image_rotate-progress bitsave {Pixel_Bitmap_Engine}/{Bitmap_Name} {Local_Pixel_Directory}/{Bitmap_Title}/ --pixel-size 1024
filemorph -m rsync -d -r {Local_Pixel_Directory}/{Bitmap_Title} {Cloud_Pixel_Directory}/{Bitmap_Title}
"""

# loop through commands and print
for command in commands.splitlines():
    command = command.format(**data) # populate command
    # os.system(command) # execute command
    print(command)

data = dict(…

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM