Awesome Python Scripts

<p>Higuys! Today I want to share with you some useful scripts for python.<br /> I am a big fan of scripts, because they facilitate routine work, improve projects, as well as give a visual representation of the use of knowledge in practice</p> <p>Let&rsquo;s go!</p> <p><img alt="" src="https://miro.medium.com/v2/resize:fit:630/1*5wfVRjG3XQSVlOaA601YZg.jpeg" style="height:525px; width:700px" /></p> <h2>1. Convert JSON to CSV</h2> <pre> import json if __name__ == &#39;__main__&#39;: try: with open(&#39;input.json&#39;, &#39;r&#39;) as f: data = json.loads(f.read()) output = &#39;,&#39;.join([*data[0]]) for obj in data: output += f&#39;\n{obj[&quot;Name&quot;]},{obj[&quot;age&quot;]},{obj[&quot;birthyear&quot;]}&#39; with open(&#39;output.csv&#39;, &#39;w&#39;) as f: f.write(output) except Exception as ex: print(f&#39;Error: {str(ex)}&#39;)</pre> <h2>2. Password Generator</h2> <pre> import random import string total = string.ascii_letters + string.digits + string.punctuation length = 16 password = &quot;&quot;.join(random.sample(total, length)) print(password)</pre> <p><a href="https://medium.com/@dmitrijkumancev571/awesome-python-scripts-6711873a35c3">Website</a></p>
Tags: Python Scripts