Python Forum
My First Script - Looking For Help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My First Script - Looking For Help
#3
def get_hostname():
    response = raw_input("Please enter your name: ")
    body = '[{{"hostname": "{}"}}]'.format(response)
    return body

print get_hostname()
I expect you want something like this, but not sure about quotes, etc.
Also if you want to create a json, better use json module

import json
def get_hostname():
    response = raw_input("Please enter your name: ")
    body = [{'hostname':response}]
    return json.dumps(body)

print get_hostname()

Also, if you don't have really good reason for using python2 (like maintaining old code base) you should be using python3 (latest is python 3.6.5)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
My First Script - Looking For Help - by dsorci - May-08-2018, 05:52 PM
RE: My First Script - Looking For Help - by wavic - May-08-2018, 06:03 PM
RE: My First Script - Looking For Help - by buran - May-09-2018, 07:17 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020