file

How can I locate where in a JSON file a key is located?

How can I locate where in a JSON file a key is located? Question: I’m writing a parser that uses a JSON file for configuration, and if it detects an invalid value, I want to be able to output the location of the problematic data in the form of the line and column number in …

Total answers: 1

How to store a tuple of floats into a file, open and read it to extract the mean per column?

How to store a tuple of floats into a file, open and read it to extract the mean per column? Question: I am computing the following scores iteratively which generates a new set of the following scores in each iteration: add_score, keep_score, del_score = get_corpus_sari_operation_scores(sources, prediction, references) I first want to store them into a …

Total answers: 2

How to copy contents of a directory with the same name into another directory in python

How to copy contents of a directory with the same name into another directory in python Question: How can I copy contents of a directory with the same name into another directory? Directory1 File1.txt Directroy1 File2.txt I want it to end up like Directory1 File1.txt File2.txt Right now I am trying to use the shutil.move() …

Total answers: 2

Is there any efficient way to store large raw data as text in a .py file?

Is there any efficient way to store large raw data as text in a .py file? Question: This may be a little bit confusing, but I will explain. Basically, there is a contest platform for a chess game. Everyone needs to upload only one .py file to it as their own AI program, and matches …

Total answers: 1

How to generate heartbeat sounds in Python given beats per minute?

How to generate heartbeat sounds in Python given beats per minute? Question: I’m looking to pass in an integer beats per minute (bpm) variable value (e.g. 62) into a function in Python that outputs the accompanying heartbeat noises (i.e. 62 heart beat sounds in a minute). I can’t find any libraries that can help with …

Total answers: 1

Python reading text file every second line skipped

Python reading text file every second line skipped Question: I am processing a shell script in Python. My first step is to comb through the file and save only the important lines in a list (of strings). However, I have isolated a problem where every second line is ignored. Why is the second, fourth, etc. …

Total answers: 1

writing Yaml file in python with no new line

writing Yaml file in python with no new line Question: Let’s say I have the following snippet : import yaml Key = ["STAGE0", "STAGE1"] dict = {} dict[Key[0]] = [‘ ‘] dict[Key[1]] = [‘ ‘] dict[Key[0]][0]="HEY" dict[Key[0]][0]="WHY newline?" with open("SUMMARY.YAML", "w") as file_yaml: yaml.dump(dict, file_yaml) The output SUMMARY.YAML file looks like this : STAGE0: – …

Total answers: 2

How to write multiple dictionaries to a file?

How to write multiple dictionaries to a file? Question: enter image description hereWhen I run the above code only the Games_shop dictionary is getting written to the something.txt not the Fruit_shop. Can u please help me know what change should i make in the code to get the Fruit_shop dictionary written to the file along …

Total answers: 2

Reading and decoding bytes after modification by external process raises UnicodeDecodeError

Reading and decoding bytes after modification by external process raises UnicodeDecodeError Question: I’m trying to encrypt a string with ansible-vault. To do this, I open two temporary files, one to hold the value to be encrypted and one to hold the password to encrypt with. Reproducible example: import os import subprocess import tempfile value = …

Total answers: 1