563 questions
0
votes
0
answers
35
views
how to keep the focus of curser in terminal after opening a url through os/webbrowser.(python)
I'm on windows using vscode,
while True:
command = input("enter to next, 0 to append and next (or type 'e' to quit): ")
if command.lower() == 'e':
print("Exiting ...
0
votes
0
answers
101
views
How to properly import python module from another python file using importlib.import_module?
I'm working on Alembic migration github action and need to import base metadata class inside python migration script which locates in another directory. I can't import it directly inside python ...
1
vote
2
answers
69
views
How to make my program that combines CSVs iterate over multiple subfolders in a directory?
So I'm trying to use Python to analyze images of cells taken in multiple wells of a 96 well plate.
I was able to generate a csv of my data from said images from each field and group them by well.
I ...
0
votes
0
answers
36
views
os.path.join is acting weird when I try to use placeholder format. Can someone point out what I am doing wrong? [duplicate]
data_path = '/Users/acer/Downloads/t-less_v2/'
info_path_mask = os.path.join(data_path, 'test_{}','{:02d}','info.yml')
path_mask = os.path.join(data_path, 'test_{}','{}','info.yml')
print(f"...
0
votes
1
answer
193
views
My python code works fine but gives exception after pyinstaller
Traceback (most recent call last):
File "Ish.py", line 1, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 378, in exec_module
File "...
2
votes
0
answers
74
views
access denied OS module python
Right now I am working on a project a Files manager
#delete file
import os
file_path = r"The\\path_file"
try:
os.remove(file_path)
print("The file has been removed")
...
0
votes
0
answers
68
views
How to create a terminal-like python pipe?
Some programs emit colored text when their output is connected to a terminal, and non colored text when their output goes to a pipe.
Is there a way in Python to open a pipe to a subprocess such that ...
-1
votes
1
answer
44
views
Python Returns Different File Size than OS Property [duplicate]
I am trying to get the size of a a file called fGDB.gdb using python. but while the Windows Property shows the size of file as 146 KB (150,399 bytes)
Using this code
import os
gdb = r"C:\Users\....
0
votes
0
answers
118
views
Python - PIL.save() issue - The fill character must be a unicode character, not bytes
I have some interesting issue with saving Image via PIL library.
Aim:
to change metadata like "Date Taken", "Creation Date" to pictures from picture name (name is standardize by ...
0
votes
1
answer
180
views
File not printed using os.startfile?
i try to print a document on windows using the following code
import os
import sys
os.startfile(r"D:/DEV/Python-Diverses/os/testb.png", "print")
But nothing happens at all - ...
1
vote
1
answer
76
views
Tkinter will not open when I try to import a variable from another Python Program
Tkinter will open a window with buttons, like I want, when I am not trying to import a variable from another Python program I wrote. But when I do, Tkinter will not open. When I use from my_program ...
3
votes
2
answers
133
views
How to differentiate and split `os.environ` into defaults and addons
Is it possible to split os.environ into default environment variables and custom addon variables?
For example, using syntax of sets representing the key/ENV_VAR_NAME:
custom_addon_env_var_keys = set(...
0
votes
2
answers
215
views
How to permanently add a path in the user's `PATH`?
I'm creating an installer for one of my projects, which downloads the binaries of the project (in a ZIP file) and then unzips it into a directory in the programs folder of the OS, and I want to add ...
-2
votes
1
answer
80
views
How do I run a Python file on my Mac that reads and writes txt files to my external hardrive? [closed]
I currently have a folder full of epubs that I would like to read, a folder of epubs I've already read and would like to read again, and a corresponding file with the names of the epub files in each. ...
0
votes
0
answers
76
views
Accessing folder through os.scandir() after changes made to folder
I am trying to iterate through a folder with html files to filter them according to whether they contain a keyword or not in their string form. I download them to a folder through wget and ...
0
votes
1
answer
60
views
os.rename() fails with WinError 3: The system cannot find the path specified on Windows but works on Linux
I am using the following code to semi-automate renaming of media files
def findingmedia(directory):
media=[]
for path,subdir, files in os.walk(directory):
for file in files:
...
0
votes
0
answers
331
views
Install Package in Chroot. Script running outside Chroot
I am trying to do a kind of analyzer. To do that I need to work with different distributions I decided on trying chroot. What im trying to do is,
using a python script on main machine
Go into chroot ...
0
votes
1
answer
72
views
Terminating a python program from within a try block [duplicate]
I have a python program that takes integer only inputs like this:
Valid = False
while not Valid:
try:
x = int(Input("enter integer value"))
Valid = True
except:
...
-1
votes
1
answer
145
views
PermissionError: [Errno 13] Permission denied. How can I rewrite a code to place a folder "a" which is in folder "b" to folder "c" [closed]
def tdata_move():
number_of_acc = len([file for file in os.scandir(fr"D:\tdata for accs")])
for item in range(0, number_of_acc):
for folder in os.listdir(r"D:\tdata for ...
1
vote
0
answers
149
views
Python program: removing a file occasionally hangs the program. Need a way to timeout and keep going
I have a strange program where trying to remove a file in my python program will hang. I have tried multiple methods to remove and they all hang.
The original code had just this command:
os.remove(...
-1
votes
1
answer
131
views
python os module does not rename the file, even if the file exists - os.rename(src, dst)
I am trying to rename files from a directory. But for some reason which I do not know, the files are not getting renamed.
Code:
def extract_info_from_filename(file_name):
parts = file_name.split('...
0
votes
0
answers
51
views
Get output of os.system while the command is running
I am making a program which is an interface for a command-line application. When running the command-line app directly through CMD it opens a new window and shows the percentage complete. I want to ...
-2
votes
4
answers
108
views
File not found in a created directory
I am working to add a file in temporary folder like so:
self._dir = tempfile.mkdtemp()
self._dir = os.path.join(self._dir, "test")
os.mkdir(self._dir)
self.checkpoint = os.path.join(self....
0
votes
1
answer
269
views
PyPDF loader could not convert string to float
I'm trying to load multiple documents using langchain's PyPDF loader using as ususal:
import os
from langchain.document_loaders import PyPDFLoader
documents = []
for file in os.listdir("docs&...
0
votes
1
answer
89
views
Improper permissions/image not found, relative paths
I am working on a project where I am turning my Python file into a .exe at the end, but every time I run it it gives me the following error:
OSError: Failed to read "BIG FILE PATH"\...
0
votes
0
answers
45
views
Access the share folder using Python
# Caminho para o arquivo de origem
caminho_origem = 'C:\\TesteScript/' # Substitua pelo caminho real do arquivo de origem
# Caminho para a pasta de destino compartilhada na rede
caminho_destino = r'\...
-1
votes
1
answer
46
views
Append processed data to a csv file and keep reord of last procssed row
I have 4000 csv files in a folder in windows 10, each files has around 500 rows,where i read text column and few identity column, each file got processed in a loop and saved. Because of system ...
0
votes
1
answer
1k
views
How to loop through each subdirectory and get all files within subdirectory as group in Python?
I need to iterate through folders in a directory, one by one, and perform a function on the files within those folders as a group. Those files need to be passed together, with their respective folder ...
1
vote
0
answers
57
views
Running a bash script that includes java commands from a python program
I have java code corresponding to a policy mining algorithm in a repository and have to execute this using commands on the git bash terminal (Using a Windows PC). I have generated test data and stored ...
-3
votes
1
answer
353
views
os.chdir(folder) doesn't work in Python 3.11
I've just updated to Python 3.11 from 3.9 by reinstalling Anaconda and this super-basic piece of code now doesn't work in Jupyter-lab.
import os
folder = r'Z:\Chris_ResearchDrive\20220520_horopito'
...
1
vote
1
answer
337
views
os.path.getmtime() inconsistent with time.time()
I'm trying to verify the time of most recent modification of a file and got to the following:
print("before", time.time())
with open(file, "wb") as fh:
fh.write(b&...
0
votes
0
answers
25
views
Create folders within folders
My code doesn't work, the intention was to create folders within folders.
import os
path = "D:\DOCS\Desktop"
n_folders = 100
x = 0
y = 0
os.chdir(path)
os.mkdir("Initial_Folder")
...
1
vote
1
answer
983
views
Is there a way to send a scan request to a printer using python OS library? [closed]
I'm currently building a text based console application to manage printing, scanning, etc but as usuall i have stumped my self and have had to come to stackoverflow for help.
Any help is appreciated.
...
1
vote
0
answers
100
views
os.open with non-utf8 characters in file name
I am trying to copy a file from a source NFS volume to destination NFS volume.
The file name has non-utf8 character and I am using bytes to open/read/write.
Using os.open, the path opens fine on the ...
1
vote
1
answer
306
views
Way to Perform Tilde-Expansion on Every Path Evaluated by Python OS Module?
I'm running Linux, and would like for my project to replace the tilde character, '~', at the beginning of a path with my home directory, in the same way the terminal does. I've found a method of the ...
0
votes
0
answers
105
views
Python-Trying to make a file witho os in directory, no errors but the file won't appear
I want to create a txt file in appdata/roaming/Helloworld with os method. The file is my_file.txt and when I launch the programm, there is no error and python says that the file and the folder exists (...
0
votes
2
answers
183
views
How to move files to and from folders using shutil and os in python?
So, I'm looking to move some images from my downloads folder to my pictures folder (Windows 11), but I am continually being met with errors. Here is my code:
import shutil
import os
source = r"...
0
votes
1
answer
61
views
Is it better to do small, more frequent writes or less, bigger writes?
I am using python to develop a json parser. The idea is to write a json that holds a specific token ($$INSERT_VAR$$) Since this is only a single token whose value(s) I obtain through a command, I ...
0
votes
1
answer
58
views
Extract/search for wanted string/text within html tag using Python
I have a html file where consists of 400 html tags and I wanted to extract some specific text from the tag. This file is a local file and not online webpage. I just tried using 1 html file first to ...
1
vote
0
answers
40
views
Reading files in batches and runnng my jupyter notebook
I have a jupyter notebook in which I read files from my desktop and then run my analysis on them resulting in a feature matrix (pandas dataframe). As my files are heavy, my laptop crashes if I read ...
2
votes
1
answer
3k
views
Environment variable is returning 'None'
I am using windows 11 and the latest version of Pycharm.
I try to save environment variable using pycharm termimal by typing 'export API_KEY=dfdfdg'
and when I type 'env' and run then the termianl ...
0
votes
1
answer
25
views
Python 3.10 Tkinter buttons autofiring on start [duplicate]
I was making a simple script for switching between different directories.
However, whenever I run the script, all of the commands attatched to the buttons automatically execute.
import os
from ...
0
votes
1
answer
664
views
Python subprocess.run cannot execute in chroot
I have two files, a.py:
import os, subprocess
os.chroot(".")
subprocess.run(["./b.sh"])
and b.sh:
#!/usr/bin/env bash
echo whateva
in an otherwise empty directory. b.sh has ...
-1
votes
1
answer
104
views
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. ...
0
votes
0
answers
79
views
Clearing terminal causing program to slow down drastically
I was running a program used to find the number with the longest sequence in the collatz conjecture, and I was trying to implement a progress bar. I successfully did so, in my own weird way, but I ...
0
votes
1
answer
100
views
How does the python listing functions like os.listdir() work?
I am trying to understand how the underlying process differs if I call the os.listdir() function as compared to running ls in the terminal.
After much searching, I came across these 2 keypoints
GNU ls ...
0
votes
1
answer
158
views
Running a bash command in Python, when said bash command requires a password?
I'm writing a Python function that requires exporting a MySQL database into a .sql file with bash. For it, I'm using mysqldump.
mysqldump -u bandana -p movies > /Users/Mac/Downloads/testOutput.sql
...
0
votes
0
answers
34
views
Taking average of all files which meets a criterion in Python
I am trying to identify .txt files by scanning every folder which meets a criterion i.e. minimum of the file is less than half of the maximum of that file and then take the average of all these files ...
0
votes
1
answer
27
views
nested for loop giving no output when working with two lists
I am making a file sorter in Python and I have two lists. One is called downloads, which holds the names of all of my files in my downloads directory, and the other is called files, which is intended ...
0
votes
1
answer
677
views
How can I extract and rename specific files from daily compressed zip folders using Python?
Let me preface this by I have never worked with python before but have spent the past several days researching and watching videos. Although I've found solutions that helps with components of this, I'...