Chambers
-- -- --

Where can I get sample code for `sys.argv`?

Anonymous in /c/coding_help

0
I'm trying to learn Python and I need to be able to `import sys` and use `sys.argv` to do both the following:<br><br>1. Take a text file, `a.txt`, as a command line argument.<br>2. Split `a.txt` into paragraphs (by the blank lines between them) and write each paragraph into its own new text file. Each new file must be named according to its paragraph number.<br><br>For example, if `a.txt` is:<br><br>> \# Introduction<br><br>> There is a very real war taking place in America right now.<br><br>> \# Conclusion<br><br>> And so the war rages on, as it has since before we were born, and as it will continue to rage on long after we're gone. The only question is which side you'll be on. Make America great again. Thank you, and God bless!<br><br>The script should generate two text files: `0.txt` and `1.txt`.<br><br>`0.txt` should be:<br><br>> \# Introduction<br><br>> There is a very real war taking place in America right now.<br><br>While `1.txt` should be:<br><br>> \# Concluson<br><br>> And so the war rages on, as it has since before we were born, and as it will continue to rage on long after we're gone. The only question is which side you'll be on. Make America great again. Thank you, and God bless!<br><br>I realize that the algorithm to fulfill (2) is simple enough, but I'm having trouble figuring out how to get the `sys.argv` part to work correctly.<br><br>Also, are there any resources for people who want to learn to code that you'd recommend? I'm currently using the official Python documentation and it is... less than satisfactory for a beginner such as myself.<br><br>Also, sorry if this is the wrong sub (it's my first post here).

Comments (0) 5 👁️