file

How to combine files in python 3 – with open() as: NOT working

How to combine files in python 3 – with open() as: NOT working Question: I am trying to combine the content of all .txt files in a directory one level above the directory where the .py file below is stored. import os def main(): # Get list of files stored in a dir above this …

Total answers: 3

python can't find file when running script from command promt; it works when ran in pycharm

python can't find file when running script from command promt; it works when ran in pycharm Question: This is my code: import os print(list(os.listdir(‘test’))) When I run the code in Pycharm it outputs the following: [‘test.txt’] However, when I run the same file with windows command prompt I get this output: (MLspraak) C:Usersphili>python C:UsersphiliPycharmProjectsMLspraaktest.py Traceback …

Total answers: 1

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