Python Forum
Passing List of Objects in Command Line Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing List of Objects in Command Line Python
#1
I am trying to pass a argument to command line for running a python program which takes list of Field Objects and send an email. The program is running fine when the list of objects is already set in my program.


a=[{"name": "productname_0", "type": "html", "content": "A Cool Shirt"}, {"name": "productname_1", "type": "html", "content": "Some Nice Shoes"}, {"name": "productname_2", "type": "html", "content": "A Trendy Hat"}, {"name": "productprice_0", "type": "html", "content": "20.99"}, {"name": "productprice_1", "type": "html", "content": "50.99"}, {"name": "productprice_2", "type": "html", "content": "FREE"}]
sendmail(a)
But when I pass this list in command line ,it did not work for me.
a = json.loads(sys.argv[1])
sendmail(a)
Running Program from Command Line
mailscript.py '[{"name": "productname_0", "type": "html", "content": "A Cool Shirt"}, {"name": "productname_1", "type": "html", "content": "Some Nice Shoes"}, {"name": "productname_2", "type": "html", "content": "A Trendy Hat"}, {"name": "productprice_0", "type": "html", "content": "20.99"}, {"name": "productprice_1", "type": "html", "content": "50.99"}, {"name": "productprice_2", "type": "html", "content": "FREE"}]'
Error : json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Python Version :3.8.5
Reply


Messages In This Thread
Passing List of Objects in Command Line Python - by usman - Sep-27-2020, 06:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 690 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  Command line argument issue space issue mg24 5 1,280 Oct-26-2022, 11:05 PM
Last Post: Yoriz
  Creating list of lists, with objects from lists sgrinderud 7 1,564 Oct-01-2022, 07:15 PM
Last Post: Skaperen
  accept command line argument mg24 5 1,242 Sep-27-2022, 05:58 PM
Last Post: snippsat
Question Keyword to build list from list of objects? pfdjhfuys 3 1,500 Aug-06-2022, 11:39 PM
Last Post: Pedroski55
  How to store the resulting Doc objects into a list named A xinyulon 1 1,855 Mar-08-2022, 11:49 PM
Last Post: bowlofred
  multi-line CMD in one-line python kucingkembar 5 3,862 Jan-01-2022, 12:45 PM
Last Post: kucingkembar
  Grouping and sum of a list of objects Otbredbaron 1 3,132 Oct-23-2021, 01:42 PM
Last Post: Gribouillis
  Accessing varying command line arguements Rakshan 3 2,009 Jul-28-2021, 03:18 PM
Last Post: snippsat
  passing php variable to python file jerald 1 2,631 Jul-07-2021, 11:46 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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