os.path

os.path.abspath() returning different results for same file

os.path.abspath() returning different results for same file Question: I am getting a different result for a file in os.path.abspath() when it is run in a unit test versus when it is run in the code being tested: The code I am testing contains: abspath = os.path.abspath(filepath) My test for the code copies the file into …

Total answers: 1

How can I find out which path os.path points to?

How can I find out which path os.path points to? Question: i am a web developer (php, js, css and …). i order a python script for remove image background. it worked in cmd very well but when running it from php script, it dosnt work. i look at the script for find problem and …

Total answers: 2

cv2.imread file with accent (unicode)

cv2.imread file with accent (unicode) Question: I am trying to load the following file: ‘data/chapter_1/capd_yard_signs\Dueñas_2020.png’ But when I do so, cv2.imread returns an error: imread_(‘data/chapter_1/capd_yard_signsDue├▒as_2020.png’): can’t open/read file: check file path/integrity load file When I specified the file name with os.path.join, I tried encoding and decoding the file f = os.path.join("data/chapter_1/capd_yard_signs", filename.encode().decode()) But that didn’t …

Total answers: 2

python use os.path.join to take specific location

python use os.path.join to take specific location Question: I need to save a folder called D:MyPc if the hostname is MyPc name_file = open("D:/Others/name.txt" , "r") data = name_file.readline() name_file.close() print(os.path.join("D:", data)) the output is D: MyPc Asked By: Kafası Güzel Penguen || Source Answers: To check the hostname: How can I use Python to …

Total answers: 1

Split pathname in python

Split pathname in python Question: I’m trying to rename a filename with python. the thing is, the filename has a specific amount of characters, 48 to be exactly, and i need to split this name into some variables, like split the file name into 10 characters, then into 20, then 16 and finally into 2. …

Total answers: 2

Saving files to different folder

Saving files to different folder Question: I´m trying to save converted excel files from different paths, to the same folder. How can I pass the path to the function correctly? Now what is happening is that it is attaching the original path to the save path I have given to the function. So my solution …

Total answers: 1

How to get a list of installed windows fonts using python?

How to get a list of installed windows fonts using python? Question: How do I get a list of all the font names that are on my computer’s system? Asked By: Paitor || Source Answers: This is just a matter of listing the files in Windowsfonts: import os print(os.listdir(r’C:Windowsfonts’)) The output is a list that …

Total answers: 4

How can I ignore or remove ".ipynb_checkpoints" in colab?

How can I ignore or remove ".ipynb_checkpoints" in colab? Question: My code in tf.keras is given below. I want to retrieve a file(Xscale.npy) in each sub_directory(component_0, component_1) of model_cnn folder. root_dir = ‘/content/drive/My Drive/DeepCID/model_cnn’ i=0 for (root, dirs, files) in os.walk(root_dir): for d in dirs: print(dirs) os.chdir(os.path.join(root, d)) print(os.getcwd()) datafile3 = ‘./Xscale.npy’ Xscale = np.load(datafile3) …

Total answers: 4

Python 3: search subdirectories for a file

Python 3: search subdirectories for a file Question: I’m using Pycharm on a Mac. In the script below I’m calling the os.path.isfile function on a file called dwnld.py. It prints out “File exists” since dwnld.py is in the same directory of the script (/Users/BobSpanks/PycharmProjects/my scripts). If I was to put dwnld.py in a different location, …

Total answers: 5