Skip to content

Instantly share code, notes, and snippets.

@abrookins
Created May 19, 2012 22:09
Show Gist options
  • Save abrookins/2732551 to your computer and use it in GitHub Desktop.
Save abrookins/2732551 to your computer and use it in GitHub Desktop.
Open a data file in the same directory as the current file
_, filename, _, _ := runtime.Caller(1)
f, err := os.Open(path.Join(path.Dir(filename), "data.csv"))
@vhmth
Copy link

vhmth commented Sep 16, 2014

Just a head's up that this may not be portable:

https://groups.google.com/forum/#!topic/golang-nuts/XiKfqDO3rKQ

@Thomasdezeeuw
Copy link

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