Home > Blockchain >  How solve Pyhton getting invalid syntax error
How solve Pyhton getting invalid syntax error

Time:09-19

I'm trying typing

command = "aws ec2 describe-instances --query "Reservations[*].Instances[].{ instance_id: InstanceId, type: InstanceType, stats: State.Name, disks: BlockDeviceMappings[*].Ebs.VolumeId, p_ip: NetworkInterfaces[*].PrivateIpAddresses[].PrivateIpAddress, name: Tags[?Key == `Name`].Value, cpu: CpuOptions.CoreCount, platform: PlatformDetails}" > output.json"
os.system(command)

I got an error when debbuging. Is there anyone correct this syntax.

CodePudding user response:

You have to escape the double quotes:

command = "aws ec2 describe-instances --query \"Reservations[*].Instances[].{ instance_id: InstanceId, type: InstanceType, stats: State.Name, disks: BlockDeviceMappings[*].Ebs.VolumeId, p_ip: NetworkInterfaces[*].PrivateIpAddresses[].PrivateIpAddress, name: Tags[?Key == `Name`].Value, cpu: CpuOptions.CoreCount, platform: PlatformDetails}\" > out22.json"
os.system(command)
  • Related