{"id":7740,"date":"2019-01-09T23:26:59","date_gmt":"2019-01-09T23:26:59","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=7740"},"modified":"2019-01-12T09:47:01","modified_gmt":"2019-01-12T09:47:01","slug":"want-to-learn-python-starter-pack-aixpert-blog","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/01\/09\/want-to-learn-python-starter-pack-aixpert-blog\/","title":{"rendered":"Want to Learn Python &#8211; Starter Pack (AIXpert Blog)"},"content":{"rendered":"<h4 class=\"min-h4\">Want to Learn Python &#8211; Starter Pack<\/h4>\n<div id=\"css-entry\">\n<p dir=\"ltr\">I am not going to cover actual Python coding here (well, may be, a little at the end) but the good and bad places to start and things to avoid.<\/p>\n<p dir=\"ltr\">First used at the Hollywood, Florida and Rome, Italy IBM Technical University conferences &#8211; we call them TechU<\/p>\n<p dir=\"ltr\"><strong>Alternatives<\/strong><\/p>\n<ul dir=\"ltr\">\n<li>You could just search Google, YouTube, and many other places and find 10 billion hits<\/li>\n<li>You will quickly get totally swamped with options<\/li>\n<li>This is Nigel&#8217;s starter pack for\u00a0 a quick start.<\/li>\n<li>This is what I found very useful\u00a0&#8211; You, of course, may be different !!!<\/li>\n<\/ul>\n<p dir=\"ltr\"><strong>What is Python good for?<\/strong><\/p>\n<ul dir=\"ltr\">\n<li>Data Scientist job &amp; serious mega-bucks &#8211;\u00a0<strong>You can double your already large salary!<\/strong><\/li>\n<li>New new technology areas line\u00a0PowerAI, Artificial Intelligence , Machine Learning, Deep Learning, etc.<\/li>\n<li>Data manipulation fixing a file format and restructuring the data<\/li>\n<li>Web 2.0 web pages + REST API<\/li>\n<\/ul>\n<h3 dir=\"ltr\"><strong>How to develop code &amp; run Python<\/strong><\/h3>\n<ol dir=\"ltr\">\n<li>Edit file and run file<\/li>\n<li>IDE (integrated development environment)<\/li>\n<\/ol>\n<ul dir=\"ltr\">\n<li>Initially IDE is a pain in the backside\n<ul>\n<li>As you have to learn both the IDE and Language together<\/li>\n<li>This sets you back 1 month!<\/li>\n<li>But good for a full time developer<\/li>\n<\/ul>\n<\/li>\n<li>I recommend: edit and run but also you can run the python in console mode to try things out.<\/li>\n<li>Having Programmed in Python for about a year I think I am ready to try a IDE for slicker editing and debugging.\n<ul>\n<li>Probably the PyCharm Community Edition IDE for a start.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3 dir=\"ltr\"><strong>Environments<\/strong><\/h3>\n<ul dir=\"ltr\">\n<li>Windows = yuck!<\/li>\n<li>Tablet &#8211; you can run PyCharms IDE but get yourself a Keyboard for typing.<\/li>\n<li>OSX = if you really have too!\u00a0 Sorry never really got on with the Mac<\/li>\n<li>Linux = this is the natural home of Python.\n<ul>\n<li>I am using a 160 CPU, 256 GB RAM, POWER8 S922LC &#8211; rather overkill but it is fast \ud83d\ude42<\/li>\n<li>I also use a Raspberry Pi &#8211; that is pretty quick too if the data files are not about a few 1\/2 GB. The Raspberry Pi memory is limited.<\/li>\n<\/ul>\n<\/li>\n<li>AIX\n<ul>\n<li>it is in the AIX Open Source toolbox for downloading<\/li>\n<li>take care with exotic modules as\u00a0might have to use git &amp; compile them yourself<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3 dir=\"ltr\"><strong>How does Python actually run?<\/strong><\/h3>\n<ul dir=\"ltr\">\n<li>Compiled &#8211; No like say C<\/li>\n<li>Interpreted\u00a0&#8211; Yes but highly optimised, cached and parallelised.\u00a0 I have had some code that finishes so fast I assumed it crashed but it actually work.<\/li>\n<\/ul>\n<h3 dir=\"ltr\"><strong>Which Python version 2.7 or 3.x ?<\/strong><\/h3>\n<ul dir=\"ltr\">\n<li>3.&lt;latest&gt; &#8211; at the rime of writing 3.5 to 3.7 depending on how current your OS is!<\/li>\n<li>No one is writing 2.7 any more<\/li>\n<li>But there is lots of it in use today but declining over time<\/li>\n<li>Not a massive difference but best to learn Python 3<\/li>\n<\/ul>\n<h3 dir=\"ltr\"><strong>Quick Assumption: You have in the past done at least some of these?<\/strong><\/h3>\n<ul dir=\"ltr\">\n<li>C, Korn or bash\u00a0shell script writing &#8211; excellent<\/li>\n<li>C programming &#8211; brilliant<\/li>\n<li>JavaScript programs &#8211; very good<\/li>\n<li>Python Programming &#8211; why are you reading this???<\/li>\n<\/ul>\n<p dir=\"ltr\">Then you are already done the heavy lifting<\/p>\n<h3 dir=\"ltr\"><strong>Everyone can write a simple program!<\/strong><\/h3>\n<pre dir=\"ltr\">A=42\r\nprint \"The number is \" $A\r\n\r\nif [[ $A == 42 ]]\r\nthen\r\n        print \"eureka\"\r\nfi<\/pre>\n<p dir=\"ltr\">Plus For loop &amp; Functions<\/p>\n<p dir=\"ltr\">What is this? Well is work on my Korn Shell OK on AIX.<\/p>\n<h3 dir=\"ltr\"><strong>Mega Tip 1:\u00a0\u00a0If you know any of the languages above then Python is going to be very simple<\/strong><\/h3>\n<p dir=\"ltr\"><a href=\"https:\/\/www.ibm.com\/developerworks\/community\/blogs\/aixpert\/resource\/BLOGS_UPLOADED_IMAGES\/Python_Prog.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/www.ibm.com\/developerworks\/community\/blogs\/aixpert\/resource\/BLOGS_UPLOADED_IMAGES\/Python_Prog.png\" alt=\"image\" \/><\/a><\/p>\n<ul dir=\"ltr\">\n<li><strong>\u00a0\u00a0Updated\u00a0\u00a0<\/strong>Read the magic Python by Example or watch the video by the originator\u00a0<a class=\"yt-simple-endpoint style-scope yt-formatted-string\" spellcheck=\"false\" href=\"https:\/\/www.youtube.com\/channel\/UCwRXb5dUK4cvsHbx-rGzSgw\">Derek Banas<\/a>\n<ul>\n<li>A big thanks for GjB in the comments for finding the link. I had completely lost it.<\/li>\n<li>YouTube link (which is includes a link to the code exam<wbr \/>ples<wbr \/>):<wbr \/>\u00a0<a href=\"https:\/\/www.youtube.com\/watch?v=N4mEzFDjqtA&amp;t=3s\">htt<wbr \/>ps:\/<wbr \/>\/www<wbr \/>.you<wbr \/>tube<wbr \/>.com<wbr \/>\/wat<wbr \/>ch?v<wbr \/>=N4m<wbr \/>EzFD<wbr \/>jqtA<wbr \/>&amp;t=3<wbr \/>s<\/a><\/li>\n<li>Approaching 5 million YouTube views &#8211; amazing for a techie video<\/li>\n<li>The video is 43 minutes and fast paced.\u00a0 A whole language with examples in under an hour.<\/li>\n<li>The web page dire<wbr \/>ctly<wbr \/>:\u00a0<wbr \/>\u00a0<a href=\"http:\/\/www.newthinktank.com\/2014\/11\/python-programming\/\">htt<wbr \/>p:\/\/<wbr \/>www.<wbr \/>newt<wbr \/>hink<wbr \/>tank<wbr \/>.com<wbr \/>\/201<wbr \/>4\/11<wbr \/>\/pyt<wbr \/>hon-<wbr \/>prog<wbr \/>ramm<wbr \/>ing<wbr \/>\/<\/a><\/li>\n<li>Full marks to\u00a0<a class=\"yt-simple-endpoint style-scope yt-formatted-string\" spellcheck=\"false\" href=\"https:\/\/www.youtube.com\/channel\/UCwRXb5dUK4cvsHbx-rGzSgw\">Derek Banas<\/a>\u00a0the content.<\/li>\n<\/ul>\n<\/li>\n<li>Briefly the contents<\/li>\n<\/ul>\n<ol dir=\"ltr\">\n<li>Data types:<\/li>\n<\/ol>\n<ul dir=\"ltr\">\n<li>string,<\/li>\n<li>integers &amp; float,<\/li>\n<li>tuples,<\/li>\n<li>lists,<\/li>\n<li>dictionary<\/li>\n<\/ul>\n<ol dir=\"ltr\">\n<li>Converting between them<\/li>\n<li>Conditionals:\u00a0 if, then, else<\/li>\n<li>Loops:\u00a0 for, while<\/li>\n<li>Functions<\/li>\n<li>User input<\/li>\n<li>String manipulation<\/li>\n<li>File I\/O: read and write<\/li>\n<li>Classes and objects<\/li>\n<li>Inheritance\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;&#8211; IMHO very advanced and for class module developers<\/li>\n<li>Polymorphism\u00a0 \u00a0 \u00a0 \u00a0&lt;&#8211; IMHO\u00a0very advanced and for class module developers<\/li>\n<\/ol>\n<h3 dir=\"ltr\"><strong>Mega Tip 2:\u00a0Socratica videos on YouTube<\/strong><\/h3>\n<h3 dir=\"ltr\">We looks at many training course, Online content and YouTube series&#8217; and these are by far the best and absolutely free.<\/h3>\n<ul dir=\"ltr\">\n<li>Python Programming Tutorials (Computer Science)<\/li>\n<li>Concise with dry humour and some computer jokes &#8211; see recursion<\/li>\n<li>Mostly with worked example<\/li>\n<li>Excellent style<\/li>\n<li>Caltech grads<\/li>\n<li>33 videos (Don&#8217;t watch the two or\u00a0three for Python2)<\/li>\n<li>Most ~8 minutes<\/li>\n<li>Total 3.5 hours<\/li>\n<li>15 million views<\/li>\n<li><strong><a href=\"https:\/\/www.youtube.com\/watch?v=bY6m6_IIN94&amp;list=PLi01XoE8jYohWFPpC17Z-wWhPOSuh8Er-\" target=\"_blank\" rel=\"noopener\">YouT<wbr \/>ube\u00a0<wbr \/>Socr<wbr \/>atic<wbr \/>a\u00a0Pl<wbr \/>ayli<wbr \/>st\u00a0V<wbr \/>ideo<wbr \/>s<\/a><\/strong><\/li>\n<li>A Geek person told me Socraticia is the female for of Socrates &#8211; I think the creators are female. They also cover maths.<\/li>\n<li><a href=\"https:\/\/www.ibm.com\/developerworks\/community\/blogs\/aixpert\/resource\/BLOGS_UPLOADED_IMAGES\/Python_Socratica.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/www.ibm.com\/developerworks\/community\/blogs\/aixpert\/resource\/BLOGS_UPLOADED_IMAGES\/Python_Socratica.png\" alt=\"image\" \/><\/a><\/li>\n<li><\/li>\n<li>I have watched all of these twice &#8211; about 6 months apart<\/li>\n<li>They are short but to consolidate what your learn try to have a quick go yourself on each topic<\/li>\n<\/ul>\n<h3 dir=\"ltr\"><strong>Mega Tip 3:\u00a0 python.org = This is the Python Mother Ship!!<\/strong><\/h3>\n<ul dir=\"ltr\">\n<li><a href=\"https:\/\/python.org\/\">https:\/\/python.org<\/a><\/li>\n<li>Then Downloads then Alternative Platforms<\/li>\n<li>For all the official documentation\u00a0\u00a0<a href=\"https:\/\/docs.python.org\/3\/tutorial\/\">http<wbr \/>s:\/\/<wbr \/>docs<wbr \/>.pyt<wbr \/>hon.<wbr \/>org\/<wbr \/>3\/tu<wbr \/>tori<wbr \/>al<wbr \/>\/<\/a><\/li>\n<li>Tiny example<\/li>\n<\/ul>\n<p dir=\"ltr\"><a href=\"https:\/\/www.ibm.com\/developerworks\/community\/blogs\/aixpert\/resource\/BLOGS_UPLOADED_IMAGES\/python_dot_org_example2.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/www.ibm.com\/developerworks\/community\/blogs\/aixpert\/resource\/BLOGS_UPLOADED_IMAGES\/python_dot_org_example2.png\" alt=\"image\" \/><\/a><\/p>\n<ul dir=\"ltr\">\n<li>Also if you are stuck for the syntax of a statement or the details of some module or function then\u00a0use then\u00a0<strong>Google: python3 &lt;your questions spelt out in full&gt;<\/strong><\/li>\n<li>Often you get\u00a0<strong><a href=\"http:\/\/python3.org\/\">http:\/\/<\/a><a>Python3.org<\/a>\u00a0<\/strong>but\u00a0<strong><a href=\"http:\/\/stackoverflow.com\/\">http<wbr \/>:\/\/s<wbr \/>tack<wbr \/>over<wbr \/>flow<wbr \/>.co<wbr \/>m<\/a><\/strong>\u00a0answer with worked examples is very good but scan down the answer a bit\u00a0(the first might not be the best answer or exactly what you want)<\/li>\n<\/ul>\n<h3 dir=\"ltr\"><strong>Mega Tip 4:\u00a0Get yourself a project to force you to code and work though problems and new features<\/strong><\/h3>\n<ul dir=\"ltr\">\n<li>Something simple<\/li>\n<li>Something you are interested in<\/li>\n<li>Specially web focused<\/li>\n<li>Python strong at\n<ul>\n<li>Website interaction<\/li>\n<li>REST API to an online service<\/li>\n<li>Data mani<wbr \/>pula<wbr \/>tion<wbr \/>\/tra<wbr \/>nsfo<wbr \/>rmat<wbr \/>io<wbr \/>n<\/li>\n<li>File conversion \/ filtering<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3 dir=\"ltr\"><strong>Mega Idiot:\u00a0My first project was the REST API to a HMC to extract Temp, Watts + performance stats for SSP, server &amp; VM<\/strong><\/h3>\n<ul dir=\"ltr\">\n<li>It was a\u00a0BIG mistake<\/li>\n<li>The bad news was the API was so badly documented it was actually impossible to use!<\/li>\n<li>With totally unnecessarily complicated XML &#8211; using features that are very rarely used by anyone.<\/li>\n<li>I had to interview the developers in the end to workout the hidden details of the REST API<\/li>\n<li>In simple terms it was the &#8220;REST API from Hell!&#8221;<\/li>\n<li>But I learnt a lot<\/li>\n<\/ul>\n<ul dir=\"ltr\">\n<li>In the end wrote a Python class module to hid the horrible REST API from Python programmers &#8211; its 1100 line of code.<\/li>\n<li>It returns simple to use Python data structures<\/li>\n<li>So\u00a0in simply \u00a0~40 lines of Python to extract, manipulate &amp; save in:\n<ul>\n<li>CSV file,<\/li>\n<li>.html with GoogleChart graphs<\/li>\n<li>Insert into an influxDB database<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p dir=\"ltr\"><strong>Mega Tip 5:\u00a0JSON format files are exactly the same as the Python native data type called Dictionaries<\/strong><\/p>\n<ul dir=\"ltr\">\n<li>So when learning Python concentrate on Dictionaries<\/li>\n<li>These are (very simple)\u00a0\u00a0 { &#8220;some label&#8221;: data, more here }<\/li>\n<li>and the data can be\n<ul>\n<li>&#8220;Strings&#8221; in double or single quote<\/li>\n<li>Integers like 12345 or -42<\/li>\n<li>Floating point numbers 123.456 (note the decimal point)<\/li>\n<\/ul>\n<\/li>\n<li>Often we have a list of dictionaries &#8211; lists look like [ item, item, item, . . . ]<\/li>\n<\/ul>\n<p dir=\"ltr\"><strong>JSON file example of stats called &#8220;mydata.json&#8221;:<\/strong><\/p>\n<pre dir=\"ltr\">[               # list of samples\r\n{               # 1st sample = Python dictionary\r\n\"datetime\": \"201<wbr \/>8-04<wbr \/>-16T<wbr \/>00:0<wbr \/>6:32<wbr \/>\",\r\n\"cpus_active\": 32,\r\n\"mhz\": 3521,\r\n\"cpus_description\": \"PowerPC_POWER9.,\r\n\"cpu_util\": {\r\n          \"user\": 50.4,\r\n          .sys\": 9.0,\r\n          \"idle\": 40.4,\r\n          \"wait\": 0.2\r\n          }\r\n},              .# end of 1st sample\r\n{ . . . }       # 2nd sample = Python dictionary\r\n]\r\n<\/pre>\n<p dir=\"ltr\"><strong>Python Program to load the data file above &#8211;\u00a0\u00a0NEW\u00a0\u00a0Fixed a few Typos here, due to Cut&#8217;n&#8217;paste issues i.e. double quotes became full stops.<\/strong><\/p>\n<pre dir=\"ltr\"># Read the file as plain text\r\n\r\nf = open<wbr \/>(\"my<wbr \/>data<wbr \/>.jso<wbr \/>n\",\"<wbr \/>r\")\r\ntext = f.read()\r\nf.close()\r\n\r\n# convert to Dictionary\r\nimport json         #module to handle JSON format\r\njdata = json.loads(text)<\/pre>\n<ul dir=\"ltr\">\n<li>That json.loads() function converts a string (text) to the dictionary called jdata at 10&#8217;s of MBs of JSON a second.<\/li>\n<li>Now lets extract certain fields using a natural Python syntax<\/li>\n<\/ul>\n<pre dir=\"ltr\"># get the Mhz from the first record (numbers zero)\r\n\r\nprin<wbr \/>t(\"M<wbr \/>Hz=%<wbr \/>d\"%(<wbr \/>jdat<wbr \/>a[0]<wbr \/>[\"mh<wbr \/>z\"])<wbr \/>)\r\n\r\n# Loop through all the records pulling out the MHz numbers and the CPU utilisation user mode percent (its in sub dictionary called cpu_util)\r\n\r\nfor sample in jdata:\r\n    prin<wbr \/>t(\"M<wbr \/>Hz=%<wbr \/>d\"%(<wbr \/>samp<wbr \/>le[\"<wbr \/>mhz\"<wbr \/>]))\r\n    print(\"User perc<wbr \/>ent=<wbr \/>%d\"%<wbr \/>(sam<wbr \/>ple[<wbr \/>\"cpu<wbr \/>_uti<wbr \/>l\"][<wbr \/>\"use<wbr \/>r\"])<wbr \/>)\r\n<\/pre>\n<h3 dir=\"ltr\"><strong>Latest project using Python is njmon for AIX and Linux &#8211; the new turbo nmon.\u00a0<\/strong><\/h3>\n<ul dir=\"ltr\">\n<li>\n<h3 dir=\"ltr\">The J is for JSON and we use Python to make data handling very easy<\/h3>\n<\/li>\n<li>For AIX uses libperfstat C library &#8211; if you want details see: man libperfstat on AIX\u00a0or vi \/usr<wbr \/>\/inc<wbr \/>lude<wbr \/>\/lib<wbr \/>perf<wbr \/>stat<wbr \/>.h\n<ul>\n<li>Or find the worked example C code in KnowledgeCenter<\/li>\n<\/ul>\n<\/li>\n<li>Status quirky but usable for expert C programmer<\/li>\n<li>Vast quantity of perf stats running in to 1000 stats for AIX and VIOS\u00a0 (if you have many disks, nets or ask for processes stats\u00a0then that grows rapidly)<\/li>\n<li>And for a bonus libperfstat gives us the current CPU MHz<\/li>\n<li>Similar for Linux<\/li>\n<li>njmon written in C to use C function into the UNIX kernel generates JSON data. Then we use Python to accept the data and inject it live in to a Time Series Data fro graphing in real-time<\/li>\n<\/ul>\n<h3 dir=\"ltr\"><strong>Stand by for something strange<\/strong><\/h3>\n<ul dir=\"ltr\">\n<li>Well known programming problem = swamping the values of two variables a and b. Classic solution is using a temporary variable.<\/li>\n<\/ul>\n<pre dir=\"ltr\">temp = a\r\na = b\r\nb = temp<\/pre>\n<ul dir=\"ltr\">\n<li>But can you do that without the temp variable?<\/li>\n<li>No in C &#8211; I have known this to 40 years!!<\/li>\n<li>Python answer<\/li>\n<\/ul>\n<pre dir=\"ltr\">a,b = b,a<\/pre>\n<ul dir=\"ltr\">\n<li>It is using a native data structure called a tuple.\u00a0 As its a common programming task they built it into the language.<\/li>\n<li>Warning weirdness next:<\/li>\n<li>How about this?<\/li>\n<li>\n<pre>a = a + b\r\nb = a - b\r\na = a - b<\/pre>\n<\/li>\n<li>Wow! I thought it was impossible!<\/li>\n<\/ul>\n<h3 dir=\"ltr\"><strong>Next a tiny Web grabbing Python example<\/strong><\/h3>\n<ul dir=\"ltr\">\n<li>Lots of websites and web services keep stats that you can download with your browser.<\/li>\n<li>I have used sourcfogre.net (used below) and youtube.com\u00a0for examples.<\/li>\n<li>They are most often in JSON and Python has a requests module that makes &#8220;talking&#8221; to website very simple<\/li>\n<li>As an example bung this in your browser (\u00a0<strong>NOT Internet Explorer\u00a0<\/strong>)<\/li>\n<li><a href=\"https:\/\/sourceforge.net\/projects\/nmon\/files\/stats\/json?start_date=2000-10-29&amp;end_date=2020-12-31&amp;os_by_country=false\">http<wbr \/>s:\/\/<wbr \/>sour<wbr \/>cefo<wbr \/>rge.<wbr \/>net\/<wbr \/>proj<wbr \/>ects<wbr \/>\/nmo<wbr \/>n\/fi<wbr \/>les\/<wbr \/>stat<wbr \/>s\/js<wbr \/>on?s<wbr \/>tart<wbr \/>_dat<wbr \/>e=20<wbr \/>00-1<wbr \/>0-29<wbr \/>&amp;end<wbr \/>_dat<wbr \/>e=20<wbr \/>20-1<wbr \/>2-31<wbr \/>&amp;os_<wbr \/>by_c<wbr \/>ount<wbr \/>ry=f<wbr \/>als<wbr \/>e<\/a><\/li>\n<li>And you should get a load of JSON date back that Firefox and Chrome will organise and make pretty.<\/li>\n<li><\/li>\n<li>Using Python, requests module and one of my own for graphing we can draw t downloads from the nmon project on SourceForge over time<\/li>\n<\/ul>\n<ul dir=\"ltr\">\n<li>We also need to change the date format from which shows of some of Pythons simple data manipulation<\/li>\n<li>,[2018-09-17 00:00:00],2<\/li>\n<li>to<\/li>\n<li>,[&#8216;D<wbr \/>ate(<wbr \/>2018<wbr \/>,9,1<wbr \/>7,00<wbr \/>,00,<wbr \/>00)&#8217;<wbr \/>, 2]<\/li>\n<li>Below is the source code &#8211; with many extra print lines and comments so if you run it would will see the data structures.<\/li>\n<li><strong>\u00a0NEW\u00a0\u00a0Changes the code here to NOT relying on my\u00a0 nchart Python Module<\/strong><\/li>\n<li><strong>Green\u00a0bits a debug but useful it you run it to see the data<\/strong><\/li>\n<li><strong>Red\u00a0bits are the webpage preable and postamble to setup the Googlecahert library graph.<\/strong><\/li>\n<\/ul>\n<pre dir=\"ltr\">#!\/usr\/bin\/python3\r\n#---<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>-- Get the data using REST API from sourceforge.net\r\nimport requests\r\nURL=<wbr \/>'htt<wbr \/>ps:\/<wbr \/>\/sou<wbr \/>rcef<wbr \/>orge<wbr \/>.net<wbr \/>\/pro<wbr \/>ject<wbr \/>s\/nm<wbr \/>on\/f<wbr \/>iles<wbr \/>\/sta<wbr \/>ts\/j<wbr \/>son?<wbr \/>star<wbr \/>t_da<wbr \/>te=2<wbr \/>000-<wbr \/>10-2<wbr \/>9&amp;en<wbr \/>d_da<wbr \/>te=2<wbr \/>020-<wbr \/>12-0<wbr \/>4&amp;os<wbr \/>_by_<wbr \/>coun<wbr \/>try=<wbr \/>fals<wbr \/>e'\r\nret = requests.get(URL)\r\nprin<wbr \/>t(re<wbr \/>t.st<wbr \/>atus<wbr \/>_cod<wbr \/>e)\r\n#print(\"return code was %d\"%<wbr \/>(ret<wbr \/>.sta<wbr \/>tus_<wbr \/>code<wbr \/>))\r\n#print(\"characters returned %d\"%<wbr \/>(len<wbr \/>(ret<wbr \/>.tex<wbr \/>t))<wbr \/>)\r\n#---<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>--- Create dictionay\r\nimport json\r\njdata = json<wbr \/>.loa<wbr \/>ds(r<wbr \/>et.t<wbr \/>ext)\r\n#print(jdata)\r\nmonths=0\r\ncount=0\r\nfor row in jdata['downloads']:\r\n#    print(row)\r\n    months=months+1\r\n    count=count+row[1]\r\nprin<wbr \/>t(\"m<wbr \/>onth<wbr \/>s=%d<wbr \/>\"%(m<wbr \/>onth<wbr \/>s))\r\nprint(\"count =%d\"%(count))\r\n#---<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>----<wbr \/>--- Create web page+graph using Googlechart library\r\nfile = open<wbr \/>(\"do<wbr \/>wnlo<wbr \/>ads.<wbr \/>html<wbr \/>\",\"w<wbr \/>\")\r\nfile<wbr \/>.wri<wbr \/>te('<wbr \/>&lt;htm<wbr \/>l&gt;\\n<wbr \/>'\r\n'  &lt;head&gt;\\n'\r\n'    &lt;script type<wbr \/>=\"te<wbr \/>xt\/j<wbr \/>avas<wbr \/>crip<wbr \/>t\" src=<wbr \/>\"htt<wbr \/>ps:\/<wbr \/>\/www<wbr \/>.gst<wbr \/>atic<wbr \/>.com<wbr \/>\/cha<wbr \/>rts\/<wbr \/>load<wbr \/>er.j<wbr \/>s\"&gt;&lt;<wbr \/>\/scr<wbr \/>ipt&gt;<wbr \/>\\n'\r\n'    &lt;script type<wbr \/>=\"te<wbr \/>xt\/j<wbr \/>avas<wbr \/>crip<wbr \/>t\"&gt;\\<wbr \/>n'\r\n'      goog<wbr \/>le.c<wbr \/>hart<wbr \/>s.lo<wbr \/>ad(\"<wbr \/>curr<wbr \/>ent\"<wbr \/>, {\"pa<wbr \/>ckag<wbr \/>es\":<wbr \/>[\"co<wbr \/>rech<wbr \/>art\"<wbr \/>]});<wbr \/>\\n'\r\n'      goog<wbr \/>le.c<wbr \/>hart<wbr \/>s.se<wbr \/>tOnL<wbr \/>oadC<wbr \/>allb<wbr \/>ack(<wbr \/>draw<wbr \/>Char<wbr \/>t);\\<wbr \/>n'\r\n'      function drawChart() {\\n'\r\n'        var data = goog<wbr \/>le.v<wbr \/>isua<wbr \/>liza<wbr \/>tion<wbr \/>.arr<wbr \/>ayTo<wbr \/>Data<wbr \/>Tabl<wbr \/>e([\\<wbr \/>n'\r\n'[{type: \"datetime\", label: \"Date\"},\"Files\"]\\n' )\r\n\r\nfor row in jdata['downloads']:\r\n    str=row[0]\r\n    str = str.<wbr \/>repl<wbr \/>ace(<wbr \/>\"-\",<wbr \/>\",\")\r\n    str = str.replace(\" \",\",\")\r\n    str = str.<wbr \/>repl<wbr \/>ace(<wbr \/>\":\",<wbr \/>\",\")\r\n    file<wbr \/>.wri<wbr \/>te(\"<wbr \/>,['D<wbr \/>ate(<wbr \/>%s)'<wbr \/>,%d]<wbr \/>\\n\"%<wbr \/>(str<wbr \/>,row<wbr \/>[1])<wbr \/>)\r\n\r\nfile.write('        ]);\\n'\r\n'        var options = {title: \"nmon Downloads\", vAxis: {minValue: 0}};\\n'\r\n'        var chart = new goog<wbr \/>le.v<wbr \/>isua<wbr \/>liza<wbr \/>tion<wbr \/>.Are<wbr \/>aCha<wbr \/>rt(d<wbr \/>ocum<wbr \/>ent.<wbr \/>getE<wbr \/>leme<wbr \/>ntBy<wbr \/>Id(\"<wbr \/>char<wbr \/>t_di<wbr \/>v\"))<wbr \/>;\\n'\r\n'        chart.draw(data, options);\\n'\r\n'      }\\n'\r\n'    &lt;\/script&gt;\\n'\r\n'  &lt;\/head&gt;\\n'\r\n'  &lt;body&gt;\\n'\r\n'    &lt;div id=\"chart_div\" style=\"width: 100%; height: 500px;\"&gt;&lt;\/div&gt;\\n'\r\n'  &lt;\/body&gt;\\n'\r\n'&lt;\/html&gt;\\n')\r\nfile.close()<\/pre>\n<ul dir=\"ltr\">\n<li>The output &#8211; skipping the dump of the JSON and the 105 rows of monthly stats looks like this<\/li>\n<\/ul>\n<pre dir=\"ltr\">['2018-05-01 00:00:00', 14153]\r\n['2018-06-01 00:00:00', 12794]\r\n['2018-07-01 00:00:00', 12422]\r\n['2018-08-01 00:00:00', 13127]\r\n['2018-09-01 00:00:00', 11872]\r\n['2018-10-01 00:00:00', 13628]\r\n['2018-11-01 00:00:00', 12805]\r\n['2018-12-01 00:00:00', 15611]\r\nmonths=114\r\ncount =686634\r\n\r\n<\/pre>\n<ul dir=\"ltr\">\n<li>So that was captured in Jan\u00a0 2019 and so far 686,634 downloads of nmon and its tools and the monthly download generated graph looks like this:<\/li>\n<li><strong>\u00a0NEW\u00a0\u00a0<\/strong>The generated downloads.html file has the following contents &#8211; note I removed a few 100 lines of data in the middle. Colours are from the vim editor &#8211; see later comments.<\/li>\n<li><a href=\"https:\/\/www.ibm.com\/developerworks\/community\/blogs\/aixpert\/resource\/BLOGS_UPLOADED_IMAGES\/python_starter_pack_html.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/www.ibm.com\/developerworks\/community\/blogs\/aixpert\/resource\/BLOGS_UPLOADED_IMAGES\/python_starter_pack_html.png\" alt=\"image\" \/><\/a><\/li>\n<li>So that was captured in Jan\u00a0 2019 and so far 686,634 downloads of nmon and its tools and the monthly download generated graph looks like this:<\/li>\n<li><strong>\u00a0NEW\u00a0\u00a0Simpler graph<\/strong><\/li>\n<li><a href=\"https:\/\/www.ibm.com\/developerworks\/community\/blogs\/aixpert\/resource\/BLOGS_UPLOADED_IMAGES\/python_starter_pack_graph.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/www.ibm.com\/developerworks\/community\/blogs\/aixpert\/resource\/BLOGS_UPLOADED_IMAGES\/python_starter_pack_graph.png\" alt=\"image\" \/><\/a><\/li>\n<\/ul>\n<h3 dir=\"ltr\"><strong>C Programmers be aware:<\/strong><\/h3>\n<p dir=\"ltr\">I keep making the same mistakes in writing Python.<\/p>\n<ol dir=\"ltr\">\n<li>On Linux with the right\u00a0<strong>export TERM=linux\u00a0<\/strong>setting\u00a0and using vi (actually vim) then you have syntax highlighting which reduces errors a lot &#8211; go for a white background or comments in dark blue are unreadable. See the picture below &#8211; I have not done that colouring &#8211; it is all vim.<\/li>\n<li>vim also helps with auto indentation.<\/li>\n<li>If, for and while statements have a &#8220;:&#8221; at the end of the line.<\/li>\n<li>In Python it is print and in C it is printf &#8211; I had to teach my fingers to miss out the final &#8220;f&#8221;<\/li>\n<li>Those maddening 4 stop indentations have to be exactly right!<\/li>\n<li>Anything I missed?<\/li>\n<\/ol>\n<p dir=\"ltr\"><a href=\"https:\/\/www.ibm.com\/developerworks\/community\/blogs\/aixpert\/resource\/BLOGS_UPLOADED_IMAGES\/python_starter_pack_vim.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/www.ibm.com\/developerworks\/community\/blogs\/aixpert\/resource\/BLOGS_UPLOADED_IMAGES\/python_starter_pack_vim.png\" alt=\"image\" \/><\/a><\/p>\n<p dir=\"ltr\">&#8211; &#8211; &#8211; The End &#8211; &#8211; &#8211;<\/p>\n<\/div>\n<p><a href=\"https:\/\/www.ibm.com\/developerworks\/community\/blogs\/aixpert\/entry\/What_to_Learn_Python_Starter_Pack?lang=en\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Want to Learn Python &#8211; Starter Pack I am not going to cover actual Python coding here (well, may be, a little at the end) but the good and bad places to start and things to avoid. First used at the Hollywood, Florida and Rome, Italy IBM Technical University conferences &#8211; we call them TechU &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/01\/09\/want-to-learn-python-starter-pack-aixpert-blog\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Want to Learn Python &#8211; Starter Pack (AIXpert Blog)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7740","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/7740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=7740"}],"version-history":[{"count":3,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/7740\/revisions"}],"predecessor-version":[{"id":7982,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/7740\/revisions\/7982"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=7740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=7740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=7740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}