I am having a hard time passing the arguments as value for my script in python. Here's my code:
import request, json, sys
def main():
url = 'https://jsonplaceholder.typicode.com/posts'
r = requests.get(url)
data = json.loads(r.text)
if len(sys.argv) != 3:
print("Usage must equal [userId] [postId]")
exit()
for user in data:
if user['userId'] == sys.argv[1] and user['id'] == sys.argv[2]:
print('here i am')
print(user)
if __name__ == "__main__":
main()
When I run python -m test 1 1, nothing happens. But it does trigger when I don't have enough arguments or too many.
mainso no code runs.