I have the following bizarre set up. Consider 3 scripts in different directories: root1/folderA/scriptA.py root2/folderB/scriptB.py root2/folderC/scriptC.py The first file and it’s location are fully modifiable. The second and third are completely fixed. scriptA.py contains a parent class: scriptB.py co…
Tag: filepath
Why won’t pd.read_csv accept a variable name within the file path in windows?
I’m trying to put a variable name into a file path to open a csv using spyder 5, python 3.7.9, in windows. It worked fine on the raspberry pi and also on Ubuntu but I can’t figure out the windows file path conventions. Code below I get the error of a red circle with a white cross in the middle
How to avoid rewriting filepaths when running a python script on a different computer?
I wrote a script in Jupyter Notebook and the script is using a series of files. I want to send this script and run it on a different computer. Is there any way to avoid having to rewrite each individual filepath when running tje script on the different computer? Answer You should checkout os module in Python.…
absolute path for file not working properly python
basically, I’m trying to store the full path for a file in a list but for some reason os.path.abspath() doesnt seem to work properly but my output seems to output this : ‘C:Users******Documentsfolderexample’ the problem is that it should be : ‘C:Users******DocumentsfolderTRACKERexample…
Python get filepath
I’m trying to create a simple script to copy the filepath of a selected file (in windows explorer) to the clipboard in python. I’ve been looking at pyperclip and tkinter but I’m unsure how exactly to proceed. The askopenfilename in tkinter seems promising, but I’d like to select the fi…
Get Path of File Relative Path of File that Imported Module in Python
I have this code in my_program.py: And this is my_module.py: A file not found error arises when my_module.py is not in the same directory as my_program.py. This problem was solved using this code (my_module.py). The issue arises when my_program.py is imported by a file in a different directory. How can I fix …
Python string format
I have defined the string variable I need to use this variable in another string like I tried adding the rf option like this But it’s printing only until c:/program, white spaces are neglected. Is there any way to use entire path in Bashcmd and can’t remove spaces in directory path because many system share s…
How do I remove the file path from the console window of python exe file?
I have made a simple “Hello World” app in python and turned it into a standalone exe file using pyinstaller. The problem is, the title bar of the console always shows the file path of the exe file. Is there any way to remove the filepath from the window? here is the image Answer Change the name of the console…
Extract a part of the filepath (a directory) in Python
I need to extract the name of the parent directory of a certain path. This is what it looks like: I would like to extract directory_i_need. Answer And you can continue doing this as many times as necessary… Edit: from os.path, you can use either os.path.split or os.path.basename: