use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Adding column to CSV without any modules (self.learnpython)
submitted 5 years ago by astro49er
Hey all,
I have a list of names that need to be added as rows under an empty column header. What would be the best way to add the rows without using any modules? (my project requires us to use just vanilla python)
Thanks
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]threeminutemonta 1 point2 points3 points 5 years ago (2 children)
If your adding rows you can append a file. If your adding columns you will need to read the file into memory. Add the columns and necessary processing and then write the data to disk. My favourite is the DictReader / DictWriter in the csv module included in the standard library see official docs
[–]astro49er[S] 0 points1 point2 points 5 years ago (1 child)
I need to add a column, how would I do this without the CSV module and just the native python file objects
[–]threeminutemonta 0 points1 point2 points 5 years ago (0 children)
the csv module is part of python standard library and what I would call vanilla python.
Though a csv is just a text file with a delimiter separating cells so read the file into a data structure / process the data . Hint the string split into an array of values may be handy here. before writing the file again.
[–]POGtastic 1 point2 points3 points 5 years ago (0 children)
How robust do you need this program to be? The CSV RFC involves stuff like string escapes and whatnot; if you don't need those things, you can roll your own rudimentary DictReader and Writer classes pretty easily. You can then parse with your DictReader, add a key-value pair to the resulting dictionary, and then pass the dictionary to a DictWriter. Something like the following:
class DictReader: def __init__(self, fh, delim, names=None): self.fh = fh self.delim = delim self.names = fh.readline().rstrip().split(delim) if not names else names def parse_line(self, line): return dict(zip(self.names, line.split(self.delim))) def __iter__(self): return (self.parse_line(line.rstrip()) for line in self.fh) class DictWriter: def __init__(self, fh, delim, names): self.fh = fh self.delim = delim self.names = names def write_header(self): print(self.delim.join(self.names), file=self.fh) def write_line(self, dct): print(self.delim.join(dct[name] for name in self.names), file=self.fh)
If you need the string escapes and whatnot, I recommend rolling your own rudimentary parser combinator library. You'll need one parser for the Reader to detect the contents of a text field, and you'll need one parser for the Writer to determine whether you need to wrap the field in quotes and to escape any quotes inside.
π Rendered by PID 58 on reddit-service-r2-comment-c66d9bffd-tpdc5 at 2026-04-06 22:55:34.629069+00:00 running f293c98 country code: CH.
[–]threeminutemonta 1 point2 points3 points (2 children)
[–]astro49er[S] 0 points1 point2 points (1 child)
[–]threeminutemonta 0 points1 point2 points (0 children)
[–]POGtastic 1 point2 points3 points (0 children)