Where should I place a config.txt in my python project

a4aravind

The project folder hierarchy looks like

ProjectName
   ->src
      ->Project.sikuli
          ->myFile.py
          ->config.txt

Now, I have all the settings variables being stores in my config.txt and I'm using ConfigParser to fetch the values from it. The reason why I'm using this config file here is that, when this sikuli script is moved to another machine for running I can just change the values in it (like paths, username, password) rather than editing the main python script 'myFile.py'.
But the issue I'm encountering now is that I don't want the config file to be placed some where outside the project so that in my script when I try to fetch the values from it, I don't have to mention the absolute path again in the myFile.txt like:

configParser = ConfigParser.RawConfigParser()
configfilePath = r'D:\MyWorkspace\ProjectName\src\Project.sikuli\config.txt'

Instead I want to have the relative path here so that while migrating the project from machine to machine I don't have to do any manipulations in the main script 'myFile.py'

So what I'm trying to achieve is like: I should be able to refer the config.txt file by giving it's relative path:

configfilePath = r'D:\MyWorkspace\ProjectName\src\Project.sikuli\config.txt'
a4aravind

First, get the path of the currently executed python script:

myPath = os.path.abspath(os.path.dirname(sys.argv[0]))

and then do a join of myPath and 'config.txt'

configfilePath = os.path.join(myPath, 'config.txt')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Where should I place my lib tests

From Dev

Where should I place my global macros?

From Dev

Where should I place my bootloader?

From Dev

Where should I place manifest.json in my Laravel 5.3 project?

From Dev

Where should I place my .sql files containing records that I am using in my Database Seeders in laravel project hierarchy folder

From Dev

Where should I place a pdf to be download in a Java web app project?

From Dev

Where Exactly Should I Place .GitIgnore File in Android Studio Project

From Dev

Where should I place XSD files/content in a SSIS project

From Java

Where should I place my global 'gitattributes' file?

From Java

Where should I place my Vaadin 10+ static files?

From Dev

Where should i place the route

From Dev

Where should i place the route

From Dev

How and where should I add the Glyphicons folder to my project?

From Dev

Where should I put new Session in my project?

From Dev

Where can I/should I place files outside my home directory?

From Dev

Where to place Scala Lenses in my project?

From Dev

Where should I place try catch?

From Dev

Where should I place the rspec helper functions?

From Dev

Where should I place the secret key in Flask?

From Dev

Where should I place interface actions in Angular?

From Dev

Where should I place setOnClickListener in a RecyclerView Adapter

From Dev

Where should I place the event listener?

From Dev

Where should I place the .htpasswd file (phpMyAdmin)?

From Dev

Where should I place a downloaded tarball?

From Dev

Where should I place my java test resources if they're relatively large (over 100MB)?

From Dev

Where should I place my app's yiic file to execute console commands?

From Dev

Where should I place my domain model to view model mapping code?

From Dev

Where should I place my context for the forms_as.p to work properly

From Dev

Where should I place my app's yiic file to execute console commands?

Related Related

  1. 1

    Where should I place my lib tests

  2. 2

    Where should I place my global macros?

  3. 3

    Where should I place my bootloader?

  4. 4

    Where should I place manifest.json in my Laravel 5.3 project?

  5. 5

    Where should I place my .sql files containing records that I am using in my Database Seeders in laravel project hierarchy folder

  6. 6

    Where should I place a pdf to be download in a Java web app project?

  7. 7

    Where Exactly Should I Place .GitIgnore File in Android Studio Project

  8. 8

    Where should I place XSD files/content in a SSIS project

  9. 9

    Where should I place my global 'gitattributes' file?

  10. 10

    Where should I place my Vaadin 10+ static files?

  11. 11

    Where should i place the route

  12. 12

    Where should i place the route

  13. 13

    How and where should I add the Glyphicons folder to my project?

  14. 14

    Where should I put new Session in my project?

  15. 15

    Where can I/should I place files outside my home directory?

  16. 16

    Where to place Scala Lenses in my project?

  17. 17

    Where should I place try catch?

  18. 18

    Where should I place the rspec helper functions?

  19. 19

    Where should I place the secret key in Flask?

  20. 20

    Where should I place interface actions in Angular?

  21. 21

    Where should I place setOnClickListener in a RecyclerView Adapter

  22. 22

    Where should I place the event listener?

  23. 23

    Where should I place the .htpasswd file (phpMyAdmin)?

  24. 24

    Where should I place a downloaded tarball?

  25. 25

    Where should I place my java test resources if they're relatively large (over 100MB)?

  26. 26

    Where should I place my app's yiic file to execute console commands?

  27. 27

    Where should I place my domain model to view model mapping code?

  28. 28

    Where should I place my context for the forms_as.p to work properly

  29. 29

    Where should I place my app's yiic file to execute console commands?

HotTag

Archive