python-os

Why am I unable to import my own os module?

Why am I unable to import my own os module? Question: I am using Python 3.10. I created a module os.py in a directory, my_dir. I am trying to access my os.py using import os, from my_dir directory. But it is loading Python’s os module, not mine. I inserted my_dir in sys.path as a first …

Total answers: 1

Incorrect path to my file when I try to restart it

Incorrect path to my file when I try to restart it Question: I am trying to execute this: os.execv(sys.executable, [‘python’] + sys.argv) The result I am getting: C:Program FilesPython310python.exe: can’t find ‘__main__’ module in ‘c:\Users\user\OneDrive\Рабочий’ As you can see, the path after the ‘module in’ words is improper. I printed sys.argv and got: c:/Users/user/OneDrive/Рабочий стол/myfolder/file.py …

Total answers: 1

Python [Errno 22] Invalid argument when copy a file from one folder to another

Python [Errno 22] Invalid argument when copy a file from one folder to another Question: I am using the files from a video tutorial. At the beginning, it starts to spread the files of input image data by copying them in various folders. The code works in the tutorial but I wonder why I get …

Total answers: 2

Creating pipenv in subprocess

Creating pipenv in subprocess Question: I’m trying to use subprocess to open a pipenv virtualenv in python. I know I am in the correct directory, but pipenv keeps opening in the parent directory. Each time I have physically deleted the parent virtualenv by doing, rm -r $home/.local/share/virtualenvs/….. I verify that they are deleted. Here is …

Total answers: 1

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

PyCharm cannot access files in /usr/lib/ and /usr/bin/ Question: 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 file. # …

Total answers: 1

Python: Get value of env variable from a specific .env file

Python: Get value of env variable from a specific .env file Question: In python, is there a way to retrieve the value of an env variable from a specific .env file? For example, I have multiple .env files as follows: .env.a .env.a … And I have a variable in .env.b called INDEX=4. I tried receiving …

Total answers: 3

How do I get the child folder name of the path besides these methods?

How do I get the child folder name of the path besides these methods? Question: Of the given path like “level1/level2/level3/”, I’d like pass it through some operation and get the result like “level3/”. So I made two trials like these: TRIAL 1: After finding parent property within the Path object, I looked for something …

Total answers: 2

How do I close a file opened using os.startfile(), Python 3.6

How do I close a file opened using os.startfile(), Python 3.6 Question: I want to close some files like .txt, .csv, .xlsx that I have opened using os.startfile(). I know this question asked earlier but I did not find any useful script for this. I use windows 10 Environment Asked By: Learnings || Source Answers: …

Total answers: 6

How to get python script file path that has been compiled in binary .exe?

How to get python script file path that has been compiled in binary .exe? Question: I have python script myscript.py that I compiled with pyinstaller with the following command: pyinstaller -F myscript.py . Now I get a file called myscript.exe . In my script, there are line that I wrote to get the path of …

Total answers: 2

Get name (not full path) of subdirectories in python

Get name (not full path) of subdirectories in python Question: There are many posts on Stack Overflow that explain how to list all the subdirectories in a directory. However, all of these answers allow one to get the full path of each subdirectory, instead of just the name of the subdirectory. I have the following …

Total answers: 4