filenames

Directory name error when creating dir in python out of the blue

Directory name error when creating dir in python out of the blue Question: So i am using a method i made to save some plots of data, and i have automated the process by saving the plots in a sub folder in my current working directory, that has the name of the first and last …

Total answers: 1

python: splitting filenames to order sequentially

python: splitting filenames to order sequentially Question: I have filenames like this: ‘./images/X_0_image0.png’, ‘./images/X_0_image1.png’, ‘./images/X_0_image10.png’, ‘./images/X_0_image100.png’, ‘./images/X_0_image101.png’, in a directory containing a lot. How do I read the content such that I obtain a list of paths and filenames sorted in ascending order like for a human count, i.e. not having X_0_image100.png appear after X_0_image10.png. …

Total answers: 1

Add leading zeros to filename

Add leading zeros to filename Question: I have a folder with more than 1.000 files that’s updated constantly. I’m using a script to add a random number to it based on the total of the files, like this: Before file_a file_b After 1_file_a 2_file_b I would like to add leading zeros so that the files …

Total answers: 4

how to not overwrite file in python in different os path

how to not overwrite file in python in different os path Question: so i want to avoid overwrite the file name that existed. but i don’t know how to combine the code with mycode. please help me here’s my code for write file: def filepass(f): print(f) with open (‘media/pass/’+’filepass.txt’, ‘a’) as fo: fo.write(f) fo.close() return …

Total answers: 1

Looping through and renaming files is actually deleting them too. why?

Looping through and renaming files is actually deleting them too. why? Question: I’m looping through files in a directory and changing their names to 1, 2, 3, etc. When I run it once it works fine. But if I run it again it ends up deleting a lot of the files. Can’t figure out why. …

Total answers: 1

How to only get files without extensions?

How to only get files without extensions? Question: My problem is to get ONLY files without extensions. I mean – I have a dictionary and there are some files without extensions and some files with extensions (.xml, .csv, etc) I want that my code would only read files without extensions. Now, it’s reading every file …

Total answers: 3

How do I correctly load data in Python?

How do I correctly load data in Python? Question: I am trying to replicate @miabrahams ACM model which is on Github here: https://github.com/miabrahams/PricingTermStructure I am coming across two errors relating to how I load data. I’m a Python novice so I’m sure it’s a simple solution but I can’t figure out how to fix this …

Total answers: 1

storing a PILLOW image in same name after editing

storing a PILLOW image in same name after editing Question: I want to crop a set of Pillow images and save it with the same name in the same folder, from where it is opened. It is clustered and stored into 4 groups. I wrote the code as below. for c in range(4): for image_file …

Total answers: 1