0

I'm converting a set to a list, and then to a string in Python. I can remove the brackets in the string output, but I also want to remove the quotes around the string.

This is what I tried:

 instance_list = ec2.describe_instances()
    for reservation in instance_list["Reservations"]:
            for instance in reservation.get("Instances", []):
                tree = objectpath.Tree(instance)
                private_ips =  set(tree.execute('$..PrivateIpAddress'))
                if len(private_ips) == 0:
                    private_ips = None
                if private_ips:
                private_ips_list = list(private_ips)
                private_ips_list = str(private_ips_list).replace('[','').replace(']','').replace('\','')
               else:
                   public_ips_list = None

This is the error I get:

  File ".\aws_ec2_list_instances.py", line 64
    private_ips_list = str(private_ips_list).replace('[','').replace(']','').replace('\','')
                                                                                           ^
SyntaxError: EOL while scanning string literal

If I change the bottom line to this, without the final replace, the script works.

private_ips_list = str(private_ips_list).replace('[','').replace(']','')

But the quotes are still there:

Private IP: '10.48.136.41'

How can I remove the quotes from the output?

bluethundr
  • 1,005
  • 17
  • 68
  • 141

1 Answers1

0

you can do:

a = set(["Blah", "Hello"])
str1 = ''.join(a)
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97