Questions tagged [python-os]

The Python os module provides a portable way of using operating system dependent functionality. Use this tag for questions about using the "os" module.

The Python os module provides a portable way of using operating system dependent functionality.

Links

551 questions
0
votes
1 answer

modifying key's name in python dictionary

I am trying to write a python script so that I can find all sub_directories called 'something' within a parent directory.Then I would like to rename the sub directories and move them somewhere else. So far I have my code as: import os,…
Pupusa
  • 167
  • 1
  • 3
  • 14
0
votes
1 answer

Does _spawn_posix in distutils always raise an error?

I'm afraid to send this to the distutils mailing list, because I'm pretty sure I'm making a dumb misinterpretation. Here is the function _spawn_posix in distutils version 2.7.9: def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0): …
abcd
  • 10,215
  • 15
  • 51
  • 85
0
votes
1 answer

keep playing youtube clip in python

I'm trying to write a simple program to keep opening a 3 minute video in youtube over and over , and after aspecific number of pages it closes every browser then start over again But it only run once .. Please advice #Keep playing a youtube…
0
votes
1 answer

Permission denied for mkdir

I installed my own package via sudo python setup.py install locally. In its source code there's the code which causes OSError: (13, 'Permission denied', '....'): curr_dir = os.path.dirname(os.path.realpath(__file__)) if not…
Mario Honse
  • 289
  • 1
  • 3
  • 10
-1
votes
1 answer

Is there a way to use shutil to copy a file when you don’t know the whole file name?

I am trying to use shutil.copy to copy files that I don’t know the whole name for. The names typically are 11_11_2023_functional. The date changes each for each file but they are in separate folders. How can I copy the file based on the fact that it…
Will V
  • 1
  • 1
-1
votes
1 answer

'say' is not recognized as an internal or external command, operable program or batch file

import os def say(text): os.system(f"say {text}") if __name__ == '__main__': print('PyCharm') say("Hello I am Jarvis A.I") Error is 'say' is not recognized as an internal or external command, operable program or batch file.
-1
votes
1 answer

Python create directories named from list elemets

I have the following classifiers: DT = sklearn.tree.DecisionTreeClassifier() LR = sklearn.linear_model.LogisticRegression() SVC = sklearn.svm.SVC() So I created this list of classifiers: classifiers = [DT, LR, SVC] I want to create directories,…
Amina Umar
  • 502
  • 1
  • 9
-1
votes
1 answer

os.listdir getting slower over different runs

dir_ = "/path/to/folder/with/huge/number/of/files" subdirs = [os.path.join(dir_, file) for file in os.listdir(dir_)] # one of subdirs contain huge number of files files = [os.path.join(file, f) for file in subdirs for f in os.listdir(file)] The…
Mann
  • 89
  • 1
  • 7
-1
votes
2 answers

Batch Rename files with different Prefixes but same file type using python

I am trying to rename my files incrementally with a counter starting at 1, which process them in a way depending on their prefix and same file extension. The directory has the following files examples: BS - foo.fxp BS - bar.fxp BS - baz.fxp ... PD -…
Gnai
  • 27
  • 6
-1
votes
1 answer

Linux / Raspberry Pi OS - Systemd not working with python3 script using OS module that accesses enviroment variable

I'm trying to use systemd to run a python3 script, it was working fine, however I changed my python script to use the built in OS module as I wanted to retrieve an enviroment variable from the system to use in the python script as a variable. The…
-1
votes
1 answer

Want to get image size in kilobytes using python

I am trying to get the image name, resolution, and size of the image from the directory. I got image name, resolution and size but image size is not in kilobytes it is getting like pixels. so please suggest me how to get the image size with the…
-1
votes
1 answer

Why I am getting error: 'no such file or directory found'?

Problem: When I try to import data from a text file to python it says no such file or directory. I really am a beginner so I would really appreciate it if someone could provide me with better code for the same purpose. What I want to do: take input…
-1
votes
1 answer

How to scan only some directories or exclude directories while using os.walk()

I would need to exclude a few directories or only scan some of them while using os.walk(). I am trying to get the most recent files. I learned how to do this from this post but it only return back one file. For my project I would need a list of 5 or…
Dodu
  • 109
  • 2
  • 8
-1
votes
2 answers

Python script ends instead of restarting (os.execv)

Whenever I run the following file (and main encounters the WebDriverException exception) my program ends instead of restarting. Would anyone know why that's happening? Any help would be greatly appreciated – thank you. from uploadToBeatstars import…
-1
votes
2 answers

how can i know the path of a file created by os.makedirs() and store it in a variable for later use?

i want to build a function that convert names from csv to a document in word by docx library and i want to create an empty file with os.makedirs(), the file is created but i cant get its path to later join path with word document to save the…