Skip to content

Instantly share code, notes, and snippets.

@indig0fox
Created June 1, 2018 18:39
Show Gist options
  • Save indig0fox/f9dbf8348e09c2f7bf2b2b172acbea95 to your computer and use it in GitHub Desktop.
Save indig0fox/f9dbf8348e09c2f7bf2b2b172acbea95 to your computer and use it in GitHub Desktop.
Outputs a plain-text formatted explicity declared Powershell array from a new-line separated list of items that is pasted or manually typed by the user. Written in Python 3.6.2
# Outputs a plain-text formatted explicity declared Powershell array from a new-line separated list of items that is pasted or manually typed by the user.
# Written in Python 3.6.2.
# [email protected]
items = []
userinput = input("Please enter the first list item: ")
items.append(userinput)
i = 2
while userinput != "":
userinput = input("Enter item %s: " % (i))
items.append(userinput)
i += 1
# items = """test1
# test2
# test3"""
# itemarray = items.splitlines()
#
# print(itemarray)
# print(items)
arraycontents = "@("
# arraycontents += itemarray[0]
arraycontents += '"' + items[0] + '"'
# i = 1
# while i < len(itemarray):
# arraycontents += ", " + itemarray[i]
# i += 1
i = 1
while i < len(items) - 1:
arraycontents += ", " + '"' + items[i] + '"'
i += 1
arraycontents += ")"
print(arraycontents)
print("\n\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment