file

os.path.isfile() returns False for a file that can be found with the explorer

os.path.isfile() returns False for a file that can be found with the explorer Question: Hi I am trying to read in and display a picture with cv2 for further analysis with the following code: Edit: I added the path with my username being clear to prove it doesn’t contain wacky characters. I also tried with …

Total answers: 2

Ambiguous output with python and files

Ambiguous output with python and files Question: I was testing how filestreams work in python and I wrote some code as follows: with open(‘test2.txt’) as f: while r := f.read(1): print(repr(r), f.tell(), sep=’tindex:’, end=’n***************n’) Contents of test2.txt are as follows: 012345 6789 I ran the code and the output is as follows: ‘0’ index:1 *************** …

Total answers: 1

What does [Errno 2] mean in python?

What does [Errno 2] mean in python? Question: I was playing around with python, and I was trying to open a file. I accidentally made a typo, and got the expected error: FileNotFoundError: [Errno 2] No such file or directory: ‘tlesting.py’ It was supposed to be testing.py if you are wondering. Of course, I expected …

Total answers: 2

Trying to write an edited string into a file in python, but nothing happens

Trying to write an edited string into a file in python, but nothing happens Question: I am trying to create a program that copies a file, makes a cipher for the copied file and writes the ciphered text back into the copied file. I have tested the cipher and the final string and it works …

Total answers: 1

How to efficiently read a GLB file in Python 3.11.1 and extract formatted triangle data?

How to efficiently read a GLB file in Python 3.11.1 and extract formatted triangle data? Question: What I need How to efficiently extract formatted triangle data from the GLB file in this data type: triangles = [triangle1,triangle2,…] triangle = [x1,y1,z1,x2,y2,z2,x3,y3,z3] (1,2,3 – points, values – their coords, x,y,z – dimensions) Here is example of the …

Total answers: 1

how to get a value from a string line of a file

how to get a value from a string line of a file Question: I have a log file which contains multiple lines and I want to get the value of the string WorkerThreads="20" from specific line of the below log content 10000 2aa0 03/29 17:02:30 ### Context="cvd.exe" Module="ThreadPool" Instance="cvstatanalysis" Type="Delta" TaskAdded="0" TaskDone="0" 10000 2aa0 03/29 …

Total answers: 1

Create dictionary through text file

Create dictionary through text file Question: In a lab for class we are to read from a text file containing line by line world cup winners with their country name, year, captain, and coach. We are expected to make a dictionary using the country name as keys. I was trying to make a dictionary in …

Total answers: 4

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