file-handling

Why isn't the JSON file being outputted to the folder being created?

Why isn't the JSON file being outputted to the folder being created? Question: I am trying to implement openpose on google colab on a set of videos. My problem is I want to specifically output the JSON files to folders named according to the name of the video file. For example, the JSON files of …

Total answers: 1

Update same object in a JSON file without creating a new object inside it

Update same object in a JSON file without creating a new object inside it Question: I have an empty json file which I’m trying to update based on user input. Initially there is no content inside the json file. I’ve created an endpoint to take input from the user in following format via Flask app …

Total answers: 1

NameError: name '__file__' is not defined , os.path.dirname(os.path.abspath(__file__))

NameError: name '__file__' is not defined , os.path.dirname(os.path.abspath(__file__)) Question: I’m trying to use os.path.dirname(os.path.abspath(file)) for tracking my file txt but i don’t why its not working with me: import os print(os.getcwd()) # Get Working directory print(os.path.dirname(os.path.abspath(__file__))) file = open("Youness.txt") NameError: name ‘__file__’ is not defined. Asked By: Error 404 || Source Answers: There is a …

Total answers: 1

excess blank line is printing

excess blank line is printing Question: so I want to read a text file and print its all content in uppercase character. I written the code and it’s correct also. But I don’t know why the excess blank line is printing between the two line. import pickle file=open("STORY.TXT",’r’) string=file.readlines() for x in string: print(x.upper()) file.close() …

Total answers: 1

Processing large files in chunks: inconsistent seek with readline

Processing large files in chunks: inconsistent seek with readline Question: I am trying to read and process a large file in chunks with Python. I am following this blog that proposes a very fast way of reading and processing large chunks of data spread over multiple processes. I have only slightly updated the existing code, …

Total answers: 4

.write() is only writing to output file in the last iteration of a loop

.write() is only writing to output file in the last iteration of a loop Question: I’m trying to open a bunch of files in a directory, remove some words from those files and write the output to a file in the same directory. I’m having problems when trying to write to the output file. There …

Total answers: 1

Why does my Python code print the extra characters "" when reading from a text file?

Why does my Python code print the extra characters "" when reading from a text file? Question: try: data=open(‘info.txt’) for each_line in data: try: (role,line_spoken)=each_line.split(‘:’,1) print(role,end=”) print(‘ said: ‘,end=”) print(line_spoken,end=”) except ValueError: print(each_line) data.close() except IOError: print(“File is missing”) When printing the file line by line, the code tends to add three unnecessary characters in …

Total answers: 3