Coder Social home page Coder Social logo

hansalemaos / getfilenuitkapython Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 6 KB

A function that locates files in python environments and compiled exe files (Nuitka)

Home Page: https://pypi.org/project/getfilenuitkapython

License: MIT License

Python 100.00%
files locate nuitka

getfilenuitkapython's Introduction

A function that locates files in python environments and compiled exe files (Nuitka)

nuitka is certainly the best py2exe- compiler, but it is not always easy to include additional files. 

The first time I tried that, the compiled EXE wasn't able to find the included files, and it took me some time to make all the necessary code adjustments.  This is why I wrote a little function that locates files in the most likely locations (python env/nuikta exe).

pip install getfilenuitkapython

This module contains a function called get_filepath which returns the full path to a file, given its filename. It uses the os and sys modules to search for the file in multiple locations.

Parameters
----------
filename: A string representing the name of the file to locate.

Returns
----------
A string representing the full path to the file, if it is found.
If the file is not found in any of the locations, the function returns the filename itself.

Description
----------
The get_filepath function searches for the file in the following locations:

1. The directory containing the script that was invoked from the command line.
2. The directory containing the current module file (__file__).
3. The parent directory of the directory containing the script that was invoked from the command line.
4. The parent directory of the directory containing the current module file (__file__).
5. The directory containing the calling function (sys._getframe(1)).
6. The parent directory of the directory containing the calling function.
7. Search in PATH
8. Search in every folder in basedirs 

If the file is found in any of these locations, the function returns the full path to the file. If the file is not found in any of these locations, the function returns the filename itself.


from getfilenuitkapython import get_filepath
get_filepath('pythonw.exe')
Out[3]: 'C:\\ProgramData\\anaconda3\\envs\\dfdir\\pythonw.exe'

getfilenuitkapython's People

Contributors

hansalemaos avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.