1

New to python here so this is mostly a syntax & library question. I'm looking for the most efficient way to create a dynamic url within python that is built on user input to later search and parse.

Example of the code I have so far:

collection = "MERRA"
version = "5.12.4"

url = "https://misc.gov/search/granules.umm_json?short_name=" , {collection}, "&" , "Version=" ,{version}, "&pretty=true'"

Output:

>>> print(url)
('https://misc.gov/search/granules.umm_json?short_name=', {'M2I1NXASM'}, '&', 'Version=', {'5.12.4'}, "&pretty=true'")

Goal Output:

>>> print(url)
https://misc.gov/search/granules.umm_json?short_name=M2I1NXASM&Version=5.12.4&pretty=true

collection and version are manually defined by the user for now.

Which python libraries (if needed) are best to use for this? How can I fix my syntax so that my output doesn't contain spaces, quotes, or curly brackets?

1 Answer 1

1

Try this method to string concatenation with variable value substitution:

collection = "MERRA"
version = "5.12.4"
url = "https://misc.gov/search/granules.umm_json?short_name="+str(collection)+"&"+"Version="+str(version)+"&pretty=true"
print('#'*100)
print(url)

####################################################################################################
https://misc.gov/search/granules.umm_json?short_name=MERRA&Version=5.12.4&pretty=true
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.