[split] script: remove all "carriage return" from my json variable - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: [split] script: remove all "carriage return" from my json variable (/thread-26555.html) |
[split] script: remove all "carriage return" from my json variable - pete - May-05-2020 I am doing a get request for the api call to verify the values but I am having assert error due to white space \n which is in the json api call. How to handle this? I tired everything possible to replace and string command. with open(“file.csv", "r") as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') next(csv_reader) for lines in csv_reader: indi = lines[0] resource_type = lines[1] source = lines[3] name = lines[4] response = requests.get( 'https://api.somewebsite + indi).json() pp = pprint.PrettyPrinter(indent=4) pp.pprint(json.dumps(response,indent=4)) RE: [split] script: remove all "carriage return" from my json variable - anbu23 - May-05-2020 Search the forum https://python-forum.io/Thread-script-remove-all-carriage-return-from-my-json-variable RE: [split] script: remove all "carriage return" from my json variable - deanhystad - May-05-2020 If you are really sure it is just the carriage return at the end you could use lines[0].strip('\n') etc. |