ervikrant06 / Python_basic

Learning Basics of Python
2 stars 1 forks source link

Parsing JSON issues #1

Open psachin opened 7 years ago

psachin commented 7 years ago
psachin@nubia:[refactor-parseJSON :( ]$ python Parsing_JSON.py instackenv.json 
0 b'arch'
1 b'cpu'
2 b'disk'
3 b'mac'
4 b'memory'
5 b'pm_addr'
6 b'pm_password'
7 b'pm_type'
8 b'pm_user'
Traceback (most recent call last):
  File "Parsing_JSON.py", line 20, in <module>
    inputvalues=raw_input("Enter the comma separated numeric values. ")
NameError: name 'raw_input' is not defined
psachin@nubia:[refactor-parseJSON :( ]$ python Parsing_JSON.py instackenv.json 
0 b'arch'
1 b'cpu'
2 b'disk'
3 b'mac'
4 b'memory'
5 b'pm_addr'
6 b'pm_password'
7 b'pm_type'
8 b'pm_user'
Enter the comma separated numeric values. 1
Traceback (most recent call last):
  File "Parsing_JSON.py", line 52, in <module>
    input_validation()
  File "Parsing_JSON.py", line 46, in input_validation
    if (len(sorted(data['nodes'][0].keys()))-1) > each_input_number:
TypeError: unorderable types: int() > str()
psachin commented 7 years ago

This works for me on python-3.5(You may need to adapt it for 2.7)

https://gist.github.com/psachin/792bb478f68629bd559911ad5ec8ef29

psachin commented 7 years ago

Refactored + implemented argparser

https://gist.github.com/psachin/c70c960c60f0f0b56320e1900c1ae073