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
1
vote
0 answers

ImportError: No module named os | trying to run .exe programm

I'm using Ubuntu 20.10 and I am relatively new to Linux so I would like to kindly ask you to tell me if there is any info needed. I am trying to install Ableton Live 10 in Ubuntu but I get this when I try to wine program_name.exe wine Ableton\ Live\…
The1Jaf
  • 11
  • 1
1
vote
2 answers

ValueError: bad file descriptor, width = os.get_terminal_size().columns

I am getting this error: Traceback (most recent call last): File "C:\Users\myname\OneDrive\Desktop\DxubleG's follwo bot\bot.py", line 10, in width = os.get_terminal_size().columns ValueError: bad file descriptor The part of code…
NewYorker
  • 11
  • 1
1
vote
1 answer

What does the dir_fd argument of os.fwalk() do?

If I assign an integer to the dir_fd argument of os.fwalk(), a fourth value ist added to each of the tuples generated by list(os.fwalk()). I understand that they have something to do with the hierarchy in which the files and directories are…
1
vote
1 answer

Python How to save image to different directory?

import os import glob from PIL import Image files = glob.glob('/Users/mac/PycharmProjects/crop001/1/*.jpg') for f in files: img = Image.open(f) img_resize = img.resize((int(img.width / 2), int(img.height / 2))) title, ext =…
DSC
  • 13
  • 3
1
vote
1 answer

Python os how to accept verification for SSH key

So basically I have a function that launches a glue development endpoint, and I want to programmatically launch zeppelin, then use the IP from the endpoint to ssh into it with my local browser. To do so, I run the following commands in the…
DBA108642
  • 1,995
  • 1
  • 18
  • 55
1
vote
2 answers

How can I recreate folder on each download?

I want to do the following if the folder doesn't exist then create it, but if I execute my script (second time) obviously will be already so I need to remove the folder and download the file inside, but my current script overwrites the location, and…
jahjh21a
  • 89
  • 11
1
vote
2 answers

OS independent path import in Python

I'm working on the development of a some small Python packages in parallel, and I have organized my repository as follow: |- root_folder |- source_code_folder |- package1 |- package2 |-... |- test_folder |-…
andrew-94
  • 27
  • 4
1
vote
1 answer

Can os.path return a file that needs root access?

I am trying to test if python can access a core file on a Mac. The file I have used as an example is one of the bpf file's (the reason I use a plural files is because it will take on the form bpf0, bpf1, bpf2, etc..). I know for a fact that the file…
Sam Moldenha
  • 463
  • 2
  • 11
1
vote
1 answer

Optimizing a function that returns paths of a folder in python

I am looking to write a function that looks into a given directory and gives me a list of paths of all folders of a particular name. Let's say I need to search the Desktop and all its subdirectories for folders named "Test". The original code to do…
Nikit Parakh
  • 65
  • 1
  • 7
1
vote
1 answer

Changing File Name Based on User Input

I am trying to create a project that will allow the user to automatically sort their files in the downloads folder based on keywords in the file name. Part of this program is allowing the user to choose their file name, so that it may be sorted…
user13436510
1
vote
2 answers

How to remove the "Traceback most recent call last" in Python when raising an exception?

I am creating a Python program that requires the use of the OS module, and I would like to custom-report error messages. I am using try and except to accomplish this: try: os.mkdir(name) except FileExistsError: raise FileExistsError(name +…
1
vote
1 answer

Find path of a package (e.g. pandas) in Python

Is there a way to programmatically find the location of a python package once it is imported? For example: import os import pandas os.get_package_directory(panda) >>> C:\Users\username\miniconda3\pkgs\pandas-1.0.5-py37h47e9c7a_0
Blithering
  • 560
  • 5
  • 14
1
vote
2 answers

Unable to get environment variables using os python

I recently created two environment variables in my terminal as shown below export SPARK_HOME='/opt/spark/' export HAIL_HOME='/home/ABCD/.pyenv/versions/3.7.2/envs/bio/lib/python3.7/site-packages/hail/' When I use echo $SPARK_HOME or echo…
The Great
  • 7,215
  • 7
  • 40
  • 128
1
vote
1 answer

os.getenv returns empty output - python

I am new to python and encountering some issues while executing os commands. I have set my environment variables like as shown below SPARK_HOME = '/opt/spark' HAIL_HOME = '/opt/hail/hail' When I type os.getenv('SPARK_HOME'), I get the below…
The Great
  • 7,215
  • 7
  • 40
  • 128
1
vote
1 answer

I have been experiencing this NOT ADirectory Error while running a code in Python

The ERROR Traceback (most recent call last): File "images.py", line 11, in for filename in os.listdir(path): NotADirectoryError: [Errno 20] Not a directory: 'images.py' I m using this code but the above error keeps coming, don't know…
Rishabh Jain
  • 15
  • 1
  • 4