Created
May 19, 2012 22:09
-
-
Save abrookins/2732551 to your computer and use it in GitHub Desktop.
Open a data file in the same directory as the current file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_, filename, _, _ := runtime.Caller(1) | |
f, err := os.Open(path.Join(path.Dir(filename), "data.csv")) |
Another head's up, this checks which function called the current function (which calls runetime.Caller). You need to use runtime.Caller(0)
to get the current function's filepath.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a head's up that this may not be portable:
https://groups.google.com/forum/#!topic/golang-nuts/XiKfqDO3rKQ