Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Python – my experience so far Jason Chapman © JAC2 Consultancy Ltd 2015 [email protected] 07966 211 959 www.jac2.co.uk The Next 60 mins • Us • Why are we looking at Python • The Journey – – – – – Find out about it Install it (may skip this bit) Watch sum tuts (maybe [down with the lingo]) Look at some code Have a discussion about uses / weaknesses / alternatives The Crew • Me • Jan • Graham (blame him about the python talk) – Doing an OU course where python is a module • Neil • Andy • Kath Our Issue • A lot of repetitive daily / weekly / monthly functions • Disparate systems we need to consume data from – – – – Wiki’s Robots (as in small semi automates programs) MS SBS report EDI formats from suppliers • They (suppliers) offer a mix of – – – – – API’s E-mail notifications Various format FTP ….. Python • • • • • 2 major versions in use 2.x & 3.x Huge Dev community Known as a data manipulation language Interpreted Interactive (type straight into the console). – Demo a,b,c • Case sensitive • Layout / indent for compound statements, not bracing • where to get python from 3.4 Todays use cases • Line of business firebird backup – – – – – – Backup on server (server side batch) Zip Copy off server to a local machine Copy off sider on a “pull” from a remote machine Restore every day Send me an e-mail that all went wonderfully • Usage stats from PBWorks – Have to do manually – Or use their API’s Getting up to speed • Graham took a course module • Take a look at python env • Komodo Edit 8.5 – Free version – Paid for version has a debugger – I think. • I watched google 2.x lesson: – https://developers.google.com/edu/python/introduction • Demo…. hello, if, help etc More stuff • Strings & slices – String.lower – String[0] – a[1:3] (0 based, based up to, but not including) • From 1..3, so the 2nd, 3rd and 4th char – a[1:] – a[-1] • Lists – a little like strings • Docs: https://docs.python.org/3/contents.html • Modules: https://docs.python.org/3/tutorial/modules.html Package Installer – Python 3.4 includes a module called "pip" which helps greatly with installing 3rd party modules, in the past you had to install this manually. – You can use pip to easily install new modules in a very linux commandline type way: – In Windows open a cmd window and type: • py -m pip install <module name> – That's it couldn't be easier! Strings • Strings: – In Python Strings are immutable, they cannot change e.g. • myVar = "graham" • myVar = "jason" – # all that has happened is myVar no longer points to "graham", a new string was created containing "jason" and variable repointed to it. "graham" is lost – Benefit of immutable Strings? – In python if a String variable has the same value as another variable the interpreter tries to recognise this and actually points both variables to the same string in memory! This is known as String interning. Lets look at some code • C:\cubbyjac2\Matt\JasonUKBug – Backup Check – wikistats • Things to pick out – Sets – “with” to limit scope Gotcha’s & Comments • Seemed slow to run scripts • Hurt my head a bit • Tabs vs spaces – We broke one of the files by annotating in notepad++ and mixing tabs and spaces – -tt flag on invocation • Google it, anything Conclusion • Very impressed with Grahams deliverables • Why use Python and not Delphi – Notepad & py and you are away – Like batch files on steroids • What is next for us – Very early days, I like what I see I think – Build some core modules – Consider a py debugger • Resources – https://docs.python.org/3/ - v3 official docs website – https://docs.python.org/3/tutorial/index.html - v3 official tutorials