python-2.7

Slice a dictionary value from list of dictionaries in Python

Slice a dictionary value from list of dictionaries in Python Question: I am trying to append a specific value from my List of Dictionary to another list. All_Result={‘Team Name’:[]} Trying to append all_result[‘SupportGroup’].append(issue["fields"]["Team Name"][‘objectId’]) and this gives me TypeError: list indices must be integers or slices, not str How to get the objectId from the …

Total answers: 1

python API connection ID/key

python API connection ID/key Question: I use APIs in my python code often, my questions are: how does an API identify me(e.g. I use different studios and run different codes, however google-API is able to recognize me, is it by my IP? or a key/ID?)? I googled and it is Key/ID, and tied to my …

Total answers: 1

I am trying to rename shapefile with date (.format)

I am trying to rename shapefile with date (.format) Question: Hello I am getting error for this code I couldn’t find the problem Error: File "C:Scheduleopen_restaurants.py", line 74 txtFileNameNoExt = "{}_{}".format(os.path.splitext(txtFileNameWithExt)[0], datetime.datetime.now(%y_%m_%d)) ^ SyntaxError: invalid syntax #rename shapefile txtFileNameWithExt = "Open_Restaurants.shp" txtFileNameNoExt = "{}_{}".format(os.path.splitext(txtFileNameWithExt)[0], datetime.datetime.now(%y_%m_%d)) arcpy.env.workspace = my_Path arcpy.Rename_management(txtFileNameWithExt,"{}.shp".format(txtFileNameNoExt)) Asked By: Kylie || Source Answers: …

Total answers: 1

UnicodeEncodeError: 'charmap' codec can't encode character 'u03a3' in position 409: character maps to <undefined>

UnicodeEncodeError: 'charmap' codec can't encode character 'u03a3' in position 409: character maps to <undefined> Question: I am running Python code to pull the issues from JIRA. This code is provided by Atlassian and they are using JiraOne Library. In the Config.Json file we have the following information. { "user": "[email protected]", "password": "<APITOKEN_HERE>", "url": "https://nexusfive.atlassian.net" } …

Total answers: 1

How to insert all rows from JSON_Object to SQL Table using Python

How to insert all rows from JSON_Object to SQL Table using Python Question: I am new to Python and APIs. Data is a result of API response. I have a json_object like below. json_object = json.dumps(data,indent=2) which has data like below. I successfully connected to SQL server localhost using pymssql but I need help in …

Total answers: 1

How to decrypt or convert Python Dictionary of lists to normal dictionary

How to decrypt or convert Python Dictionary of lists to normal dictionary Question: Very new to python and literally struggling to get this fixed. I have dictionary like below from json file. I believe this is being called as Dictionary of lists. MyDict = [{Key:[1,2,3,4]}, {Summary:[Text 1, Text 2, Text 3, Text 4]}] Expected Result: …

Total answers: 2

Using module as variable

Using module as variable Question: I am parsing through some code for an SSD simulator. The top module imports the package experiment. It later instantiates an object to this module as follows: from config_helper import experiment . . . if __name__ == ‘__main__’: . . experiment = RunFTL(args) experiment.run() Inside the experiment module, there is …

Total answers: 1

Check if a subkey in a JSON file exists

Check if a subkey in a JSON file exists Question: I want to create a condition to check if a subkey in a JSON file exists: with open(‘C:/files/response.json’) as json_file: data = json.load(json_file) if ‘XMLRESPONSE’ in data and data[‘XMLRESPONSE’][‘ITEM’]: print("key exist in JSON data") else: print("Key doesn’t exist in JSON data") input ("Press any key") …

Total answers: 1

JSON File update 2 values without break its structure or other values

JSON File update 2 values without break its structure or other values Question: Hello I have the next code to try to update a JSON file: with open(‘orderprepare.json’, ‘r’) as f: finalorder = json.load(f) finalorder[‘ItemList’][‘Quantity’] = 500 with open(‘orderprepare.json’, ‘w’) as f: json.dump(finalorder, f) But it shows the error “finalorder[‘ItemList’][‘Quantity’] = 500 TypeError: list indices …

Total answers: 2