Convert a String representation of a Dictionary to a dictionary?

How can I convert the str representation of a dict, such as the following string, into a dict? s = "{'muffin' : 'lolz', 'foo' : 'kitty'}" I prefer not to use eval. What else can I use? The main...

Multiple conditions bulk update in SQL & PHP

If I want to update a column value base on a condition I can just use the below query for a simpel +1 -1 case (translate into proper PHP call or ORM equivalent, of course): UPDATE articles SET...

How to properly subclass dict and override __getitem__ & __setitem__

I am debugging some code and I want to find out when a particular dictionary is accessed. Well, it's actually a class that subclass dict and implements a couple extra features. Anyway, what I...

How to cast Django form to dict where keys are field id in template and values are initial values?

I have a huge django form and I need to create dict where keys are field id in template and values are initial values? Something like this: {'field1_id_in_template': value1, ...} Does somebody...

How to save a dictionary to a file?

I have problem with changing a dict value and saving the dict to a text file (the format must be same), I only want to change the member_phone field. My text file is the following...

How to access deeply nested dictionaries in Swift

I have a pretty complex data structure in my app, which I need to manipulate. I am trying to keep track of how many types of bugs a player has in thier garden. There are ten types of bugs, each...

'utf-8' codec can't decode byte reading a file in Python3.4 but not in Python2.7

I was trying to read a file in python2.7, and it was readen perfectly. The problem that I have is when I execute the same program in Python3.4 and then appear the error: 'utf-8' codec can't decode...

Removing empty dictionary elements in Python

My program would scrape some website and create two lists, one for category, the other for content. I then use dict(zip(......)) command to match them and put them into a dict. Something like...

Loop dictionary in ansible template

I'm trying to loop a dictionary through an ansible template using jinja2 to create a number of datasources but receive this error [{'msg': "AnsibleUndefinedVariable: One or more undefined...

Optional command line arguments

Given code like this, how do I actually set a file in the run options? I am using Spyder and have put -h -s -p -o as arguments, but I'm not sure how to specify a named file for the -o...

curl: (35) Unknown SSL protocol error in connection at first request

im trying to authenticate user via xbox live Oauth2.0, but im experiencing this error which appears only at first request (after that it working for few minutes). Im already tried with --sslv*,...

python private attribute name mangling inheritance

This is an example from "Effective Python", that I am clearly missing something on. I added a few print's to help convince myself, but I'm still a little unclear. I understand that when you...

curl: how to use Kerberos instead of NTLM authentication on Windows?

I'm trying to connect to a Livy REST service under Kerberos security. On Linux CentoS curl works fine with negotiate, after receiving a Kerberos kinit ticket the connection through curl...

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table

I am fresh to flask and was trying to build a blog on my own, and I ran into an issue with SQLite operation error. I have researched similar problem on Github and Stackoverflow but none of the...

Applying a function in each row of a big PySpark dataframe?

I have a big dataframe (~30M rows). I have a function f. The business of f is to run through each row, check some logics and feed the outputs into a dictionary. The function needs to be performed...

Can memmap pandas series. What about a dataframe?

It seems that I can memmap the underlying data for a python series by creating a mmap'd ndarray and using it to initialize the Series. def assert_readonly(iloc): try: ...

How to align trace text to center in a stacked horizontal bar chart

I have a stacked horizontal bar and I want text defined for each trace to be placed at the center of the corresponding bar. I can't find an attribute that sets this without using anotations, but...

pytest setup_class method and db access

import pytest from . import utilization pytestmark = pytest.mark.django_db some_period = 'test' @pytest.mark.django_db class TestUtilization(object): @classmethod def...

creating a dictionary using two lists (no zip) PYTHON

I am trying to create a dictionary using two lists without the use of zip. can someone help me to finish the code. The function should return an empty dictionary if the lists were...

pip install web3 not installing

any advice would be greatly appreciated. I have installed visual studio like it tells me in the error and I have also attempted to pip install this in a venv environment however its still not...

Custom Choropleth Labels in Geopandas

I am attempting to make a choropleth plot in geopandas. Because of the large number of objects and a highly skewed distribution, I am binning into quantiles using the built in mapclassify support....

How can I fix my bash script to find a random word from a dictionary?

I'm studying bash scripting and I'm stuck fixing an exercise of this site: https://ryanstutorials.net/bash-scripting-tutorial/bash-variables.php#activities The task is to write a bash script to...

decision_function and precidt_proba yield different ROC graphs in sklearn

I'm following the ROC graph example given in sklearn docs here (you can download a Jupyter notebook from here). It generates a ROC graph for the multi-class problem over the Iris dataset. In the...

AttributeError: 'dict' object has no attribute 'to_capabilities' when using splinter to webscrape

I am running into an issue with my code and I'm not sure why this is happening as I didn't change anything and it was working fine last night. Here is my code: from bs4 import BeautifulSoup from...

python flask spawn jobs with multiprocessing

I have a python flask app that waits for requests from user app and then spawns a process with job based on the request it receives. It keeps the status and queue of the jobs in memory. The...

google dataflow job cost optimization

I have run the below code for 522 gzip files of size 100 GB and after decompressing, it will be around 320 GB data and data in protobuf format and write the output to GCS. I have used n1 standard...

How to interpret response for bounding box , google cloud endpoint

I have trained and deployed End Point of a custom object detection model using new Vertex AI in google cloud. When I test the model on cloud I see perfect bounding boxes on a image. But when I...

How do I Authenticate my FTX_Client in Python

I have looked through the FTX api documentation found here: https://docs.ftx.us/#overview And I've looked at example code found in this repo: https://github.com/ftexchange/ftx/tree/master/rest I...

Writing a Python pdfrw PdfReader object to an array of bytes / filestream

I'm currently working on a simple proof of concept for a pdf-editor application. The example is supposed to be a simplified python script showcasing how we could use the pdfrw library to edit PDF...

Flask, flask_login, pytest: How do I set flask_login's current_user?

I am trying to use pytest to unit test my Flask app. I have the following test case for an endpoint that requires information from flask_login's current_user: def test_approval_logic(): with...