Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing the profile to a file #10629

Closed
ViralBShah opened this issue Mar 25, 2015 · 9 comments
Closed

Writing the profile to a file #10629

ViralBShah opened this issue Mar 25, 2015 · 9 comments
Labels
status:help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@ViralBShah
Copy link
Member

We already allow Profile.print() to take an IO object. It would be very convenient if it could take a string representing the filename to write to, and save the profile to a file. Otherwise, one has to do:

f = open(filename, "w")
Profile.print(f)
close(f)

Instead, just doing this would be much more convenient, and user-friendly:

Profile.print(filename)
@StefanKarpinski
Copy link
Sponsor Member

I don't disagree but you can just do open(Profile.print, filename).

@ViralBShah
Copy link
Member Author

Yeah that works - but it has to be open(Profile.print, filename, "w").

@StefanKarpinski
Copy link
Sponsor Member

Sure.

@ViralBShah ViralBShah added the status:help wanted Indicates that a maintainer wants help on an issue or pull request label Mar 25, 2015
@ivarne
Copy link
Sponsor Member

ivarne commented Mar 25, 2015

So this is about adding:

function print{T<:Unsigned}(filename::AbstractString, data::Vector{T} = fetch(), lidict::Dict = getdict(data); kwargs...)
    open(filename) do io
        print(io, data, lidict; kwargs...)
    end
end

about here, and testing to see that I didn't make a typo?

@timholy
Copy link
Sponsor Member

timholy commented Mar 25, 2015

Yes, these types of fixes are usually easier to just make than they are to file an issue about 😄.

@ivarne
Copy link
Sponsor Member

ivarne commented Mar 25, 2015

At least the code is clearer than the written description, but tests and docs are also required, so still work to do,

@ViralBShah
Copy link
Member Author

I mainly filed it as a reminder for myself to get to it next week- but I was pretty sure it was a simple fix. Tests, docs etc. are usually why I try not to do things in a hurry...

@JeffBezanson
Copy link
Sponsor Member

I dislike having lots of functions that accept either an I/O stream or a file name. In the long run it's easier to keep things orthogonal, learn how to write to a file once, and use that everywhere, rather than looking up which options every function supports.

@mbauman
Copy link
Sponsor Member

mbauman commented Mar 26, 2015

For accepting a file name, eventually I'd love to try to implement the proposal in #7299 (comment) … probably as a package first. If that were implemented, you would say: save("profile.txt", Profile.fetch()) (.txt would just print the object when saved, and read it in as a string when loaded).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

No branches or pull requests

7 participants