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
4
votes
1 answer

Use multiple file extensions for glob to find files

I am using glob to list out all my python files in the home directory by this line of code. I want to find all .json files too along with py files, but I couldn't found any to scan for multiple file types in one line code. for file in…
Mohan
  • 145
  • 2
  • 8
4
votes
1 answer

os.rename [Errno 2] No such file or directory

I tried to rename directories in MacOS, even have used codes of others but os.rename still throws me errors, I give the full path of my directories and their new names as path. May someone help to solve this problem? thanks in advance import…
Ivan Shelonik
  • 1,958
  • 5
  • 25
  • 49
4
votes
1 answer

What's going on with closed file descriptors?

In the example code below we open a file descriptor to sandbox.log, provide it as stdout to a subprocess, and then close the file descriptor, yet the subprocess can still write to the file. Is subprocess.Popen duping the file descriptor internally?…
chmod 777 j
  • 547
  • 1
  • 5
  • 15
4
votes
2 answers

os.mkdir under if not working python

I have the below code, the os.mkdir is not working on mine. Compiling does not return any error, but running the code does not create folder. def folder(): timenow = datetime.now().strftime('%Y-%m-%d_%H%M%S') folderpath =…
python novice
  • 379
  • 1
  • 4
  • 18
4
votes
1 answer

AttributeError: 'module' object has no attribute 'scandir'

I have no idea why this is happening. Here's the function: def scanWallDir(basedir, scansubdirs=True): wallsOut = [] for entry in os.scandir(basedir): if entry.is_file(): print(("file " + entry.name)) elif…
Aido
  • 1,524
  • 3
  • 18
  • 41
3
votes
1 answer

Is it possible to open a binary file with os.open and os.fdopen on Unix?

I'm trying to stream a file to clients with Python, and I need to add the HTTP header fields in the response, namely Content-Length and Last-Modified. I found that I can access these fields from the file using os.fstat, which returns a stat_result…
Amir Shabani
  • 3,857
  • 6
  • 30
  • 67
3
votes
2 answers

Read or save a PDF file uploaded to Flask

I'm uploading multiple files to flask using a form, I'm getting the file objects in the flask backend without a problem but the issue is I want to read the PDF files to extract text from them. I can't do it on the file objects I received from the…
Shashank Prasad
  • 474
  • 8
  • 11
3
votes
1 answer

PyCharm cannot access files in /usr/lib/ and /usr/bin/

I am using PyCharm 2020.2.3 with Python 3.8.6 under Pop_OS! 20.10 (you can probably do as if I am using Ubuntu 20.10) which is unable to see files into /usr/bin or /usr/lib. Here is an example if I try to touch the /usr/lib/firefox/firefox binary…
Olivier Melançon
  • 21,584
  • 4
  • 41
  • 73
3
votes
1 answer

smtplib.SMTPSenderRefused: (530, b'5.7.0 Authentication Required.) in flask

I see many solutions but still, I have a problem for send mail and I also set email and password to ~/.bash_profile so please help me. Here my connfig.py file code import os class Config: SECRET_KEY=os.environ.get('SECRET_KEY') …
Malav Mevada
  • 178
  • 11
3
votes
1 answer

multiprocessing.Queue behavior when forking

After a few os.fork(), I am trying to exchange data to and from the children. To do this, I use multiprocessing.Queue instances. The Queues work correctly when the parent puts and the children get; but not in the opposite way. My example…
3
votes
0 answers

Running an executable from Python "This application has requested the Runtime to terminate it in an unusual way."

I'm getting an interesting problem and I can't determine whether it's a problem with my code or the executable that I'm running. Basically I have a Python program that needs to call an external executable to process some data. If I call the…
3
votes
2 answers

How to find out how long a search for files will take on python?

So I have a little app that searches for all xml files on my pc, copying the files that have 44 digits as the filename to the "output" folder. The problem is that the final user needs an indication of the progress and remaining time of the…
3
votes
1 answer

Watchdog Project: Reference before assignment error

I'm trying to create a program that allocates downloaded files to a specific directory of my choosing, however this seems to only work with one if statement, whenever I expanded it to more than one, it just gives me the error shown below. I've tried…
Cybergenik
  • 130
  • 1
  • 5
  • 11
3
votes
3 answers

Why does os.system block program execution?

I am trying to create a program to easily handle IT requests, and I have created a program to test if a PC on my network is active from a list. To do this, I wrote the following code: self.btn_Ping.clicked.connect(self.ping) def ping(self): …
iMBLISH
  • 65
  • 2
  • 7
3
votes
2 answers

python os.rename directory not empty

I'm trying to do mv test-dir/* ./ but in python. I have written the following code but throws OSError: [Errno 66] Directory not empty: import os os.rename( os.getcwd() + '/test-dir', os.path.abspath(os.path.expanduser('.')))
Vaibhav Mule
  • 5,016
  • 4
  • 35
  • 52
1 2
3
36 37