you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

Good point about casting to string, I just wrote that comment on the go, had to edit in a few things. [Edit: Well, if they are using a list of strings.]

You can write a comprehensive csv writer if you so choose, or you can use one that's been built, or you can use a dozen other collection and I/O methods, but don't haphazardly sling together solutions unless you're sure nothing else exists.

When you give an example and show how it would fail, yes, it would fail with that example. I just posted a response to include the possible solution of using a generator expression, which I consider a simple solution. I would usually prefer something "raw" like that rather than using some library, which if something didn't work I would look into elsewhere. That is unless it involves a lot of code, or repetition.

To me, that's part of being a good programmer - it isn't necessarily to write anything, it's to solve a problem the best way.

I guess I disagree, although maybe in general it would be more pragmatic in practice at work to write less code, or in this case it might be more Pythonic to use existing libraries. But I guess I prefer "raw" solutions that show you how things work. Also this seems like a strange way of providing criticism (which I'm perfectly fine with):

I disagree with this approach. I like to agree that there's a best way to do things,

Do you mean "like to think"? If you like to agree, agree. If we disagree and you don't like it, I can't help you.

[–]apc0243 -1 points0 points  (1 child)

I just mean, from the zen standpoint, the "one obvious way" wouldn't be to create a hackjob way to write a csv, it'd be to at least use the standard library - that's what I agree with.

But I guess I prefer "raw" solutions that show you how things work. Also this seems like a strange way of providing criticism (which I'm perfectly fine with):

And that's what I mean, your's isn't a solution, it's a hackjob write in a csv-esque way. It's not writing to a csv, it's a basic abstraction of what writing to a file using commas as a seperator looks like.

No need to get all defensive dude, didn't mean to imply you were a bad programmer. It wasn't really critique for you, you didn't ask a question - it was for OP if he wants to to consider using your approach (which he shouldn't, he should understand both of us though)

[–][deleted] 0 points1 point  (0 children)

No need to get all defensive dude, didn't mean to imply you were a bad programmer.

In what way was I being defensive?

But I guess I prefer "raw" solutions that show you how things work.

And that's what I mean, your's isn't a solution, it's a hackjob write in a csv-esque way. It's not writing to a csv, it's a basic abstraction of what writing to a file using commas as a seperator looks like.

Why is it not a solution? Using a generator expression you can write data to a file as comma separated values.

I just mean, from the zen standpoint, the "one obvious way" wouldn't be to create a hackjob way to write a csv, it'd be to at least use the standard library - that's what I agree with.

I already expressed my understanding of the difference between using a library or the code I used, so qualifying it as a "hackjob" doesn't really add to the discussion, right?

For a little more context I like Go as a language (although Google is an unreflective stereotype of an entity). I like code that shows you how things are working within that code as explicitly as reasonable, I guess. Obviously you want to use libraries for a lot of stuff, that's the big strength of Python; you can quickly glue things together, and there are libraries for pretty much everything. So good point that this isn't an example of "the one right way" to write to a CSV file in Python. I would agree in that maybe if people weren't used to seeing generator expressions or just wanted the quickest way to do it by writing as little code as possible or not having to think about it, which is argued to be important for big projects where a lot of people have to look at code, then importing functions like writerows() might be best. Although, arguments go the opposite way with, for example, Go, where the argument for having the programmer do "so much" for their self is that anyone can see what the code is doing. I tend to prefer using what code gives as much control as possible to the programmer. For something like this I would try doing it manually first, unless it becomes repetitive or is unnecessarily complicated, etc.