in Education by
I have a custom PyPi package. It is installed under Pyhon\Python38\Lib\site-packages\myCustomPackage. In the __init__ code for myCustomPackage, I perform a few different directory operations, which failed to find the correct files and directories which reside in the Pyhon\Python38\Lib\site-packages\myCustomPackage folder. I looked at the output of os.getcwd() and it showed the cwd to be C:\Users\TestUser, which is the root Windows user folder. I would like the root folder to be the myCustomPackage folder. For example, the file \myCustomPackage\__init__.py would contain import os class myCustomPackage(): def __init__(self): print(os.getcwd()) If I run: from myCustomPackage import myCustomPackage theInstance = myCustomPackage() The output is: C:\Users\TestUser How can I change that to be C:\Users\TestUser\AppData\Local\Programs\Python\Python38\Lib\site-packages\myCustomPackage? Note : I would want it to be dynamic. No hard coding, in case the python version changes or the Windows user changes. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
My solution was the following function: import site import os import traceback def changeCWD(self): try: sitePackages = site.getsitepackages() site_packages_dir = sitePackages[1] top_module_dir = site_packages_dir + os.path.sep + "myCustomPackage" os.chdir(top_module_dir) return True except: self.myLogger.error("An error occurred in changeCWD") tb = traceback.format_exc() self.myLogger.exception(tb) return False

Related questions

0 votes
    I have made a chatroom where users can messages to each other but I want to add a upload file ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I want to log the user session. Currently the code is as follows (setting formatter and handlers is omitted ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 11, 2022 in Education by JackTerrance
0 votes
    I want to log the user session. Currently the code is as follows (setting formatter and handlers is omitted ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    I want to log the user session. Currently the code is as follows (setting formatter and handlers is omitted ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 23, 2022 in Education by JackTerrance
0 votes
    I want to log the user session. Currently the code is as follows (setting formatter and handlers is omitted ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 12, 2022 in Education by JackTerrance
0 votes
    I have a legit situation like this where I need to implement a method that changes the incoming object ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Pandas tidy data, spread variables from one column, gather from another My Problem I need to turn the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    In a script where I create many figures with fix, ax = plt.subplots(...), I get the warning ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    Pandas tidy data, spread variables from one column, gather from another My Problem I need to turn the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    Pandas tidy data, spread variables from one column, gather from another My Problem I need to turn the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    Is there a way to specify the color a text is printed within Idle for Python 3.2? I'm looking ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    Is there a way to specify the color a text is printed within Idle for Python 3.2? I'm looking ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    I am looking to write a pop-up window which asks the user to select a specific option, and if ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    When I run my Dash app from the command line using export PYTHONPATH=./src/ && python ./src/pdv/ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 6, 2022 in Education by JackTerrance
0 votes
    Write the syntax to set the path of the current working directory in R environment? (a) Setwd( dipath ) ... Debugging of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
...