how to always open a file in your project folder - python-3.x

Right now, whenever I open a file in my python folder, I would have to do this:
f = open("/Users/LazyLinh/PycharmProjects/TimeGenGUI/mass.mas12.txt", "r")
Even though TimeGenGUI is my python folder, and the file mass.mas12.txt does show up under my project files. Is there a way I can always address this file as part of my python folder or find the full directory of this file, as the full directory can change if I change the folder's location?
Thank you!

Oh thanks to #zondo's recommendation, I've figured out the problem. My __init__.py is in a package under TimeGenGUI, so as soon as I put the file into the folder for this package instead of parent folder TimeGenGUI, I can use open("mass.mas12.txt", "r")!

Related

List files in a folder, in the parent directory

I know you can list the files of a directory with:
os.listdir('FOLDER_DIR')
But how do i list the files in a folder that exists in a directory above where i am right now?
For example, consider the following folder structure:
----PARENT
-------sub_dir1
-------sub_dir2
If my python program is in sub_dir2, how can i list the contents of folder sub_dir1, without changing directory?
The answer is os.listdir('../sub_dir1')

getting a spec file instead of a exe with pyinstaller [duplicate]

I am completely new to python and trying to create an application (or .exe) file for python using pyinstaller. I ran the command pyinstaller -[DIRECTORY].py and it saved it to an output directory "C:\Windows\System32\Dist\Foo", however when i tried to locate the directory it did not seem to exist (Dist).
NOTE: i'm trying to convert a .py file to .exe file in Python 3.5
Thanks for any help :)
If you set your command directory to the .py script location and run pyinstaller yourscript.py, it will generate folders in the same location as your script. The folder named dist/ will contain the .exe file.
Could you please try easily the command:
`pyinstaller yourscript.py`
You will get your output folder anyway if everything is correct with your software/module.
Second you can have no rights into System32 folder, so you could try a different folder.
Third you might have inconsistency with the path \ or /.
Hope those three suggestions will lead you to the correct solution :-)
Have a nice day.

How can I find ._6182142_V1.csv in my folder?

I write this code in jupyther with python, to get the files in the folder
import os
path, dirs, files = next(os.walk("/Volumes/Samsung_T5/6182142"))
print(files)
and I get this result
Files in the folder
But I don't understand why this file "._6182142_V1.csv" is displayed to me even though I can't see it in the folder.
Real Folder
Can someone tell me how to view this file in the folder?
Thank you
A file starting with ._ is likely hidden on your OS. If you view the hidden files, you should see it.

no such file or directory (cygwin)

I am trying to install a solver (SCIP) with cygwin. After unpacking the folder consists of another 5 folders. The manual says I have to go in folder A and use make. Here, I get the message that one file was not found:
zimpl/bool.h: No such file or directory
This file is in folder B in the path zimpl/src/bool.h. How can I link this file from folder B that cygwin can use it while using make in folder A?
The support says:
Blockquote The error you postet looks like your zimpl softlink is incorrect. If you use a relative path, make sure that it is relative to the position where
the link is created. Most softlinks are created directly in the lib
directory, the zimpl softlink, however, is in a subdirectory of the lib
directory, so you have to go up two directories to get to the main SCIP
directory.
However I am not sure how to check the softlinks.
Thanks!

Nsis Zip2Exe leaves out log named folders

Im new to Nsis so pardon me if my problem is easly solveable.
I wanted to make an exe from my freshly zipped Xampp folder (it is a webserver software).
When i zipped this with total commander every folder was at the right place.
But when i run the Zip2Exe nsis application wouldn't compress into the exe my "log" named folders EVEN if they aren't empty.
Any help would greatly appriciated.
Solution:
I had to revoke the Read only permission on the folders

Resources