Day 1 : Slides for my training course, Well Grounded Python Coding. I'm using PyCharm Pro and Anaconda along the course. Not much to read but it's the main material for my teaching.
These are the slides of the second part of this multi-part series, from Learn Python Den Haag meetup group. It covers List comprehensions, Dictionary comprehensions and functions.
Introduction to the basics of Python programming (part 3)Pedro Rodrigues
This is the 3rd part of a multi-part series that teaches the basics of Python programming. It covers list and dict comprehensions, functions, modules and packages.
These are the slides of the second part of this multi-part series, from Learn Python Den Haag meetup group. It covers List comprehensions, Dictionary comprehensions and functions.
Introduction to the basics of Python programming (part 3)Pedro Rodrigues
This is the 3rd part of a multi-part series that teaches the basics of Python programming. It covers list and dict comprehensions, functions, modules and packages.
Many developers will be familiar with lex, flex, yacc, bison, ANTLR, and other related tools to generate parsers for use inside their own code. For recognizing computer-friendly languages, however, context-free grammars and their parser-generators leave a few things to be desired. This is about how the seemingly simple prospect of parsing some text turned into a new parser toolkit for Erlang, and why functional programming makes parsing fun and awesome
Inspired by Josh Bloch's Java Puzzlers, we put together our own Python Puzzlers. This slide deck brings you a set of 10 python puzzlers, that are fun and educational. Each puzzler will show you a piece of python code. Your task if to figure out what happens when the code is run. Whether you're a python beginner or a passionate python veteran, we hope that there's something to learn for everybody.
This slide deck was first presented at shopkick. Nandan Sawant and Ryan Rueth are engineers at shopkick. Keeping the audience in mind, most of the puzzlers are based on python 2.x.
In Python, operator overloading is accomplished via "magic methods" -- specially named methods that begin and end with double underscore ("dunder"). Most Python developers know about __init__ and even __str__, but magic methods are used to accomplish many things in the Python world. In this talk, I introduce a number of these methods, and show how they can be used to make our objects more expressive.
Getting started in Python presentation by Laban KGDSCKYAMBOGO
Python Overview and getting started in Python Language. It includes on how to install, run it and carrying out some simple python codes in different environments(IDLEs)
Babar: Knowledge Recognition, Extraction and RepresentationPierre de Lacaze
Babar is a research project in the field of Artificial Intelligence. It aims to bridge together Neural AI and Symbolic AI. As such it is implemented in three different programming languages: Clojure, Python and CLOS.
The Clojure component (Clobar) implements the graphical user interface to Babar. Examples of the Clojure Hiccup library and interfacing Clojure to Javascript will be presented. The Python module (Pybar) implements the web crawling and scraping and the Neural Networks aspect of Babar. The Word Embedding and and LSTM (Long Short-Term Memory) components of Pybar will be described in detail. Finally the Common Lisp module (Lispbar) implements the Symbolic AI aspect of Babar. This latter includes an English Language Parser and Semantic Networks implemented as an in-memory Hypergraph.
We will present each of these components and target individual aspects with code examples. Specifically we will first present the web developments and Neural Networks components. Then the English Language parser will be examined in detail. We will also present the knowledge extraction aspect and bridge this with the Neural Network component.
Ultimately we will argue what can be termed "Neural AI" and "Symbolic AI" are at not at odds with each other but rather complement each other. In summary Artificial Intelligence is not a question of "brain" or "mind", but rather a question of "brain" and "mind".
Beyond xUnit example-based testing: property-based testing with ScalaCheckFranklin Chen
Test-Driven Development has become deservedly popular in the past decade, with easy-to-use xUnit unit testing frameworks leading the way toward encouraging developers to write tests. But xUnit has limitations: how does one know one has written enough test cases for a desired behavior? And what if the behavior is conditional on other behavior? Property-based testing, first popularized for Haskell with the QuickCheck library, but available now for other languages as well, offers a powerful addition to one's testing toolkit.
I will discuss the concepts of property-based testing and illustrate them concretely using ScalaCheck for Scala, and point toward similar test frameworks in other languages.
Presented at 8th Light University London (13th May 2016)
Do this, do that. Coding from assembler to shell scripting, from the mainstream languages of the last century to the mainstream languages now, is dominated by an imperative style. From how we teach variables — they vary, right? — to how we talk about databases, we are constantly looking at state as a thing to be changed and programming languages are structured in terms of the mechanics of change — assignment, loops and how code can be threaded (cautiously) with concurrency.
Functional programming, mark-up languages, schemas, persistent data structures and more are all based around a more declarative approach to code, where instead of reasoning in terms of who does what to whom and what the consequences are, relationships and uses are described, and the flow of execution follows from how functions, data and other structures are composed. This talk will look at the differences between imperative and declarative approaches, offering lessons, habits and techniques that are applicable from requirements through to code and tests in mainstream languages.
Monads and Monoids: from daily java to Big Data analytics in Scala
Finally, after two decades of evolution, Java 8 made a step towards functional programming. What can Java learn from other mature functional languages? How to leverage obscure mathematical abstractions such as Monad or Monoid in practice? Usually people find it scary and difficult to understand. Oleksiy will explain these concepts in simple words to give a feeling of powerful tool applicable in many domains, from daily Java and Scala routines to Big Data analytics with Storm or Hadoop.
Functional Python Webinar from October 22nd, 2014Reuven Lerner
Slides from my free functional Python webinar, given on October 22nd, 2014. Discussion included functional programming as a perspective, passing functions as data, and writing programs that take functions as parameters. Includes (at the end) a coupon for my new ebook, Practice Makes Python.
Many developers will be familiar with lex, flex, yacc, bison, ANTLR, and other related tools to generate parsers for use inside their own code. For recognizing computer-friendly languages, however, context-free grammars and their parser-generators leave a few things to be desired. This is about how the seemingly simple prospect of parsing some text turned into a new parser toolkit for Erlang, and why functional programming makes parsing fun and awesome
Inspired by Josh Bloch's Java Puzzlers, we put together our own Python Puzzlers. This slide deck brings you a set of 10 python puzzlers, that are fun and educational. Each puzzler will show you a piece of python code. Your task if to figure out what happens when the code is run. Whether you're a python beginner or a passionate python veteran, we hope that there's something to learn for everybody.
This slide deck was first presented at shopkick. Nandan Sawant and Ryan Rueth are engineers at shopkick. Keeping the audience in mind, most of the puzzlers are based on python 2.x.
In Python, operator overloading is accomplished via "magic methods" -- specially named methods that begin and end with double underscore ("dunder"). Most Python developers know about __init__ and even __str__, but magic methods are used to accomplish many things in the Python world. In this talk, I introduce a number of these methods, and show how they can be used to make our objects more expressive.
Getting started in Python presentation by Laban KGDSCKYAMBOGO
Python Overview and getting started in Python Language. It includes on how to install, run it and carrying out some simple python codes in different environments(IDLEs)
Babar: Knowledge Recognition, Extraction and RepresentationPierre de Lacaze
Babar is a research project in the field of Artificial Intelligence. It aims to bridge together Neural AI and Symbolic AI. As such it is implemented in three different programming languages: Clojure, Python and CLOS.
The Clojure component (Clobar) implements the graphical user interface to Babar. Examples of the Clojure Hiccup library and interfacing Clojure to Javascript will be presented. The Python module (Pybar) implements the web crawling and scraping and the Neural Networks aspect of Babar. The Word Embedding and and LSTM (Long Short-Term Memory) components of Pybar will be described in detail. Finally the Common Lisp module (Lispbar) implements the Symbolic AI aspect of Babar. This latter includes an English Language Parser and Semantic Networks implemented as an in-memory Hypergraph.
We will present each of these components and target individual aspects with code examples. Specifically we will first present the web developments and Neural Networks components. Then the English Language parser will be examined in detail. We will also present the knowledge extraction aspect and bridge this with the Neural Network component.
Ultimately we will argue what can be termed "Neural AI" and "Symbolic AI" are at not at odds with each other but rather complement each other. In summary Artificial Intelligence is not a question of "brain" or "mind", but rather a question of "brain" and "mind".
Beyond xUnit example-based testing: property-based testing with ScalaCheckFranklin Chen
Test-Driven Development has become deservedly popular in the past decade, with easy-to-use xUnit unit testing frameworks leading the way toward encouraging developers to write tests. But xUnit has limitations: how does one know one has written enough test cases for a desired behavior? And what if the behavior is conditional on other behavior? Property-based testing, first popularized for Haskell with the QuickCheck library, but available now for other languages as well, offers a powerful addition to one's testing toolkit.
I will discuss the concepts of property-based testing and illustrate them concretely using ScalaCheck for Scala, and point toward similar test frameworks in other languages.
Presented at 8th Light University London (13th May 2016)
Do this, do that. Coding from assembler to shell scripting, from the mainstream languages of the last century to the mainstream languages now, is dominated by an imperative style. From how we teach variables — they vary, right? — to how we talk about databases, we are constantly looking at state as a thing to be changed and programming languages are structured in terms of the mechanics of change — assignment, loops and how code can be threaded (cautiously) with concurrency.
Functional programming, mark-up languages, schemas, persistent data structures and more are all based around a more declarative approach to code, where instead of reasoning in terms of who does what to whom and what the consequences are, relationships and uses are described, and the flow of execution follows from how functions, data and other structures are composed. This talk will look at the differences between imperative and declarative approaches, offering lessons, habits and techniques that are applicable from requirements through to code and tests in mainstream languages.
Monads and Monoids: from daily java to Big Data analytics in Scala
Finally, after two decades of evolution, Java 8 made a step towards functional programming. What can Java learn from other mature functional languages? How to leverage obscure mathematical abstractions such as Monad or Monoid in practice? Usually people find it scary and difficult to understand. Oleksiy will explain these concepts in simple words to give a feeling of powerful tool applicable in many domains, from daily Java and Scala routines to Big Data analytics with Storm or Hadoop.
Functional Python Webinar from October 22nd, 2014Reuven Lerner
Slides from my free functional Python webinar, given on October 22nd, 2014. Discussion included functional programming as a perspective, passing functions as data, and writing programs that take functions as parameters. Includes (at the end) a coupon for my new ebook, Practice Makes Python.
This is the third presentation in pySIG 2015 @ BMS College of Engineering, Bangalore. The code and assignments can be found at https://github.com/pranavsb
My Scala by the Bay 2014 talk on exploring the ideas behind the implementation of the generic library shapeless, and general ideas about how to do "type level" programming in Scala.
Learn how to write better code. Follow key software development principles like KISS, DRY, YAGNI, and SOLID. Know how to choose better names, structure your code, write methods, and design classes.
This PPT gives information about:
1. WHERE condintion,
2. Order By,
3. Group By,
4. SQL Standard
5. SQL Queries
6. SQL Database Tables
7. SQL Injection
Code Like Pythonista
Beautifully made PPT.
Ref. http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html
Image ref : https://pixabay.com/ko/ and https://morguefile.com/
licensed under a Creative Commons Attribution/Share-Alike (BY-SA) license.
Slides from Software Testing Techniques course offered at Kansas State University in Spring'16 and Spring'17. Entire course material can be found at https://github.com/rvprasad/software-testing-course.
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Normal Labour/ Stages of Labour/ Mechanism of LabourWasim Ak
Normal labor is also termed spontaneous labor, defined as the natural physiological process through which the fetus, placenta, and membranes are expelled from the uterus through the birth canal at term (37 to 42 weeks
A workshop hosted by the South African Journal of Science aimed at postgraduate students and early career researchers with little or no experience in writing and publishing journal articles.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Safalta Digital marketing institute in Noida, provide complete applications that encompass a huge range of virtual advertising and marketing additives, which includes search engine optimization, virtual communication advertising, pay-per-click on marketing, content material advertising, internet analytics, and greater. These university courses are designed for students who possess a comprehensive understanding of virtual marketing strategies and attributes.Safalta Digital Marketing Institute in Noida is a first choice for young individuals or students who are looking to start their careers in the field of digital advertising. The institute gives specialized courses designed and certification.
for beginners, providing thorough training in areas such as SEO, digital communication marketing, and PPC training in Noida. After finishing the program, students receive the certifications recognised by top different universitie, setting a strong foundation for a successful career in digital marketing.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
How to Build a Module in Odoo 17 Using the Scaffold MethodCeline George
Odoo provides an option for creating a module by using a single line command. By using this command the user can make a whole structure of a module. It is very easy for a beginner to make a module. There is no need to make each file manually. This slide will show how to create a module using the scaffold method.
Executive Directors Chat Leveraging AI for Diversity, Equity, and InclusionTechSoup
Let’s explore the intersection of technology and equity in the final session of our DEI series. Discover how AI tools, like ChatGPT, can be used to support and enhance your nonprofit's DEI initiatives. Participants will gain insights into practical AI applications and get tips for leveraging technology to advance their DEI goals.
The simplified electron and muon model, Oscillating Spacetime: The Foundation...RitikBhardwaj56
Discover the Simplified Electron and Muon Model: A New Wave-Based Approach to Understanding Particles delves into a groundbreaking theory that presents electrons and muons as rotating soliton waves within oscillating spacetime. Geared towards students, researchers, and science buffs, this book breaks down complex ideas into simple explanations. It covers topics such as electron waves, temporal dynamics, and the implications of this model on particle physics. With clear illustrations and easy-to-follow explanations, readers will gain a new outlook on the universe's fundamental nature.
3. 3
EX01 DATA TYPES & STATEMENT
Data types
•Basic [int, float, boolean, string, char]
•Complex [set, tuple, list, dict]
•type()
Coding Language
•Comment
•Assignment
•Expression
•Blocks (if, loop)
4. 4
EX01 DATA TYPES & STATEMENT (CONT.)
Equality
•Is Operator
•Assigned to
•==
•!=
Caution!
•Variable and naming
•Indents
•Common Errors
5. 5
EX02 VIRTUAL ENVIRONMENT
Why you should use ‘virtual environment’?
•What is venv
•How to config and use venv in PyCharm
•How many of them?
•virtualenv
•conda
•pipenv
8. 8
EX01 MATH CALC 1
Write a program that calculate ‘Area of Square, Rectangle, Triangle’
•Use this formulas [ w * w, w * h, 1/2 * b * h ]
•Note about integer or float calculation.
Write a program that calculate ‘VAT’
•Use this calculation [ taxed_price = price + ( 7% of price) ]
Rewrite them again with ‘input()’
•Rewrite all programs above with user’s input for [ w, h, b, price ]
9. 9
EX02 MATH CALC 2 DIVISION
Write a program ‘Does it Odd?’
•Get one user input and show that it is an odd number or not
•Note modulus (%) may be helpful
Write a program ‘FizzBuzz’
•Get one user input and consider if it can be divided by 3 or
5 or both without remainder.
10. 10
EX03 MATH CALC 3 PARENTHESIS, ORDER
Consider this expressions
•print( 100-2/3^5 )
•print( (100-2)/3^5 )
•print( 100-(2/3)^5 )
•print( 100-2/(3^5) )
What make them different?
11. 11
EX04 MATH CALC 4 ‘MATH MODULE’
Try this ‘math’ module by yourself
•math.pi
•math.pow()
•math.random()
Can you explain ‘random()’
12. 12
STRING
What you mostly use for human
communication and presentation
String in many senses; list, chars
and know how to transform them
13. 13
EX01 ASCII, UNICODE • CHAR, STRING
Do you know ‘ASCII’ or ‘Unicode’ Character Code?
•What’s saved in computer when your text has ‘ABCD’ inside?
•Note try to find which text encoding inside your PyCharm files.
Find out more about ‘ASCII’ and ‘Unicode’ tables
•Non-printable characters. [ n, r, t ]
‘Char’ acter and ‘String’
•String made from characters.
14. 14
EX02 STRING OPERATOR
What’s possible to calculate with ‘string’?
•‘concatenate’ or ‘plus’
•‘in’ & ‘not’
•‘multiply’ ? Really?
•len()
•upcase(), lowcase()
‘slice’ is BIGGGGGGGG
•REMEMBER THIS!! [ string[start:stop:step] ]string[start:stop:step]
‘slice’ is BIGGGGGGGG
15. 15
EX03 STRING FORMAT
It’s better to use .format() than multiple plus operators
•‘The {} brown fox jumped over the lazy dog’.format(‘quick’)
•‘Only {0} lived for others is {0} {1}’.format(‘a life’,’worthwhile’}
•# - Albert Einstein
•‘Hi {name}, an announcement has been made from {teacher}, instructor
of {course} and 2 more courses.’
.format(
name=‘Worajedt’,
teacher=‘Holczer’,
course=‘Advanced Algorithms in Java, Data Structures in Java’
)
16. 16
EX04 STRING FORMAT USE CASE
•Can you create a program to print this medication label?
•Note : Use keywords to be placeholders instead of numeric
index
17. 17
SYSTEM THEORY
Do you ever heard of..
Input-Process-Output or..
Garbage in, garbage out?
Learn more
Learn more
19. 19
EX01 GRADING FUNCTION
Write a program that return grade from input score
•Grades are :
• Grade Score Range
A >= 80
B 70 - 79
C 60 - 69
D 50 = 59
F < 50
20. 20
CONDITION
When we have information,
it let us ‘make decision’.
If-else, if-elif-else and
boolean algebra come in.
21. 21
EX01 GRADING REVISIT
Enhance your grading system again with if-elif-else
•Is it a number ?
•Is it within range 0 - 100 ?
•Make your code readable
•Wrap main idea within
•if __name__ == ‘__main__’:
• xxxxx
• xxxxx
22. 22
EX02 FIZZBUZZ APP REVISIT
Enhance your FizzBuzz again with if-elif-else
•Is it a number ?
•Is it within range 0 - 100 ?
•Wrap the main logic within check_fizzbuxz()
•Make your code readable
•Wrap main idea within
•if __name__ == ‘__main__’:
• xxxxx
• xxxxx
23. 23
Information can hold in a variable. But a variable can
hold more than one information. Ordered or
Unordered.
Set, Tuple, List and Dictionary.
All of these come with different kind of
parenthesizes.
COMPLEX DATATYPES
24. 24
EX01 CREATE LIST VS TUPLELIST
What’s the different between ‘tuple’ and ‘list’ ?
•Tuple is Read Only & faster
•Both are ‘array’
•Both are ‘ordered list’
•Both are ‘zero-based index’
tp = (1,5,7,9) # create a tuple
li = [1,5,7,9] # create a list
25. 25
EX02 MODIFY LIST
List can be modified, so these are ways you can do with a list.
•Find size of list
•Pull data from each list
•Add more member(element)
•Remove member (one by one)
•Reverse all members
•Count a selected member
•Find index(position) of a member
•Find if list has this member
LIST
26. 26
EX03 OPERATIONS
We can use some operations, check it out.
•Combine lists ( and tuple! )
•Unpack members to variables
LIST
27. 27
EX04 SLICE
List has one thing you must practice, slicing the list
LIST
list[start:stop:step]
0 1 2 3 4 5 6 7 8
B U T T E R F L Y
-9 -8 -7 -6 -5 -4 -3 -2 -1
28. 28
EX05 LIST COMPREHENSION
List Comprehension helps you define members with condition(s)
•Create a list consists of members in a condition
•You can use condition to create members
•And map() object to help you modified members
•Also, you can use this comprehension with ‘tuple’
LIST
29. 29
EX06 LIST OF LISTS (2D ARRAY)
Just a simple rules, list can have any types of its member. Even list.
•Try to create a simple data made from list of lists
•How can we replace the red location?
LIST
two_d_li = [
[1,3,5,7],
[2,4,6,8],
[5,0,5,0]
]
30. 30
EX01 CREATE DICT
Unordered list of data that comes with pair of {key:value}
•They are paired { “key”: value }
•No ordered
•Access by ‘key’
•Can get a list of keys and a list of values
DICTIONARY
31. 31
EX02 MODIFY DICT
Dictionary can do mostly list can
•You can find if the key exists
•And avoid error with .get()
•Update value and append value
DICTIONARY
32. 32
EX01 COMMON STRUCTURE
The most important and common structure of ‘database’
•1 Root key (option)
•Array (list) at root level
•Consists of dictionary (same structure) as the list members
Database query result, JSON API result are the most common format like this.
LIST OF DICTIONARY
33. 33
EX02 CREATE A JSON DATA
Learn how to create a JSON data
•What’s JSON?
•Try to create a JSON data from your experience
LIST OF DICTIONARY
34. 34
FOR LOOP
Bunch of information may require the
same set of instructions on them.
For-loops have many ways to deal
with each kind of data types.
35. 35
EX01 FOR LOOP WITH COUNTER
‘for in’ LIST
If we deal with ‘ordered list’ , we can use ‘for in’
•for animal in ["dog", "cat", "mouse"]:
•for i in range(4):
•list = ["dog", "cat", "mouse"]
•for i, value in enumerate(list):
• print(i, value)
•x = 0
•while x < 4:
• print(x)
• x += 1 # or x = x+1
36. 36
EX02 FOR + IF ELSE FIZZBUZZ REVISIT
‘for in’ LIST
Can you modify your FizzBuzz?
•Create a list of number, may be from range()
•Then apply fizzbuzz() for every items
•Print the output
37. 37
EX01 FOOTBALL PLAYERS
‘for each’ DICT
Actually, there is NO ‘for each’ in Python.
•a_dict = {'one': 1, 'two': 2, 'thee': 3, 'four': 4}
•new_dict = {}
•for key, value in a_dict.items():
• new_dict[value] = key
•print(new_dict)
•Now create a dict of football players and iterates over them.
38. 38
EX02 FOR + IF ELSE
‘for each’ DICT
You can apply condition to each loop
From the dict of football players, now iterates over them,
only who are older than 30 yrs
39. 39
EX01-10 : CONTINUOUS EXERCISES
RUNNERS
Use the exercises 01-10 about runners,
complete them all!
40. 40
PYCHARM IDE
Do you really know how to use
PyCharm IDE?
I bet you’re not. Not even close.
41. 41
CODING THE RIGHT WAY
Design how your program should work.
•Start from main()
•Write something readable and not too complex
•Create pseudo function and variable then refactor to real one
•Alt+Enter | Opt+Return is god send!
•Migrate each of them to the right files/modules
•Alt+Enter | Opt+Return is god send!
42. 42
TEXT EDITING
To learn a good text editor, learn about this
•Cursor movements
•Multi-Cursor
•Column Selection Mode
•Find and Replace
•Regular-Expression ( an alien language that save your @$$)
44. 44
RUNNING & DEBUGGING
In PyCharm you can set many running configurations.
•(Watch the demo in class)
PyCharm debug features is much more readable, let’s do it!
•(Watch the demo in class)
45. 45
Do you know when your code works?
How you measure it?
Are you sure your measure tool working correctly?
If you’re sure, how long it can be working properly?
TDD techniques and testing frameworks help you sleep
better.
TEST DRIVEN DEVELOPMENT
(TDD)
46. 46
WHAT IS TDD?
• Do you know when your code works?
• How you measure it?
• Are you sure your measure tool working
correctly?
• If you’re sure, how long it can be working
properly?
48. 48
‘pytest’
‘pytest’ is one of the best testing library in Python
• Almost no configuration
• Fast running
• Many extension, even BDD (Behavior-Driven Development)
• Integrate with PyCharm (Professional)
Time to demo !
51. 51
WORKSHOP 02 TDD :
FIND THE RIGHT EAN13 BARCODE CHECK DIGIT
https://www.gs1.org/services/how-calculate-check-digit-manually
The following table gives an example to illustrate how a GTIN-13 Check Digit is calculated:
55. 55
FILE
Any of you have never worked with file?
Since you are all have worked with
it. You better know how to work
with it correctly.
None
56. 56
FILE MODES IN PYTHON
FILE
Mode Description
‘r’ This is the default mode. It Opens file for reading.
‘w’
This Mode Opens file for writing. If file does not exist, it creates a new
file. If file exists it truncates the file.
‘x’ Creates a new file. If file already exists, the operation fails.
‘a’
Open file in append mode.
If file does not exist, it creates a new file.
’t’ This is the default mode. It opens in text mode.
‘b’ This opens in binary mode.
‘+’ This will open a file for reading and writing (updating)
57. 57
EX01 OPEN AND READ A FILE
FILE
Python use concept of open and close file like we had in C, Java
• 1) Open the file in Read mode with open()
• 2) We use the mode function in the code to check that the file is
in open mode. If yes, we proceed ahead
• 3) Use f.read() or f.readline() to read file data and store it in
variable content
• 4) print contents
58. 58
EX02 WRITE A FILE CONTENT
FILE
Python use concept of open and close file like we had in C, Java
• 1) Open the file in Write/Append mode with open()
• 2) Create some content and f.write(‘content inside’)
• 3) Use f.close() to close the file (save)
• 4) To Append, process is the same except open() with ‘a+'
59. 59
EX03 READ / WRITE THE MODERN WAY
FILE
Python 3 can use ‘with’ block to read/write file
# Writing to a file
contents = {"aa": 12, "bb": 21}
with open("myfile2.txt", "w+") as file:
file.write(json.dumps(contents)) # writes an object to a file
# Reading from a file
with open('myfile1.txt', "r+") as file:
contents = file.read() # reads a string from a file
print(contents)
# print: {"aa": 12, "bb": 21}
60. 60
CSV FILE
When we process something, data input or
output may be any formats. CSV is one of the
primitive data since the early age of computer.
And it still very important in this Big
Data Era.
61. 61
EX01 READ CSVCSV
Programming language Designed by Appeared Extension
Python Guido van Rossum 1991 .py
Java James Gosling 1995 .java
C++ Bjarne Stroustrup 1983 .cpp
• 1) import csv
• 2) Open the file in ‘rt' mode with open()
• 3) Use csv.reader() to read the file by Row
• 4) Use csv.DictReader() to read each row, column as Dictionary
62. 62
EX02 WRITE CSVCSV
• 1) import csv
• 2) Open the file in Write/Append mode with open()
• 3) Use writer = csv.writer(file, delimiter=',', quotechar='"',
quoting=csv.QUOTE_MINIMAL)
• 4) writer.writerow(['Programming language', 'Designed by', 'Appeared',
'Extension'])
63. 63
DATABASE
While working with CSV is pretty easy. It’s still very basic in
terms of relationship and connection between each other
entities.
Relational Database Management System (RMDB) and
Structured Query Language (SQL) seems like the
backbone of data management system.
“No matter what it takes. Learn it, you must.”
– Master Yoda
64. 64
BASIC OF RELATIONAL DATABASE Definitions
• Database
• Table
• Field (Column)
• Record (Row)
• Primary Key (PK)
• Foreign Key (FK)
• One to Many
• Many to Many
65. 65
SNIPPETS
Learn How To Create Snippets
To Save Your Time
Of programmers don’t
know How to Create
Snippets.
Is the time you may save writing
code/fix spelling/pull your hair
by using Snippets.
90%
30%
66. 66
SQL LANGUAGE WITH SQLITE
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
""" create a database connection to a SQLite database """
conn = None
try:
conn = sqlite3.connect(db_file)
print(sqlite3.version)
except Error as e:
print(e)
finally:
if conn:
conn.close()
67. 67
SQL LANGUAGE WITH SQLITE (CONT)
. . . . .
conn = None
try:
conn = sqlite3.connect(db_file)
print(sqlite3.version)
except Error as e:
print(e)
finally:
if conn:
conn.close()
if __name__ == '__main__':
create_connection(r"C:sqlitedbpythonsqlite.db")
68. 68
EX01 MANIPULATE TABLE
-- tasks table
-- sql_create_tasks_table =
CREATE TABLE IF NOT EXISTS tasks (
id integer PRIMARY KEY,
name text NOT NULL,
priority integer,
project_id integer NOT NULL,
status_id integer NOT NULL,
begin_date text NOT NULL,
end_date text NOT NULL,
FOREIGN KEY (project_id)
REFERENCES projects (id)
);
-- projects table
-- sql_create_projects_table =
CREATE TABLE IF NOT EXISTS projects (
id integer PRIMARY KEY,
name text NOT NULL,
begin_date text,
end_date text
);
69. 69
EX01 MANIPULATE TABLE (CONT)
def create_table(conn, create_table_sql):
""" create a table from the create_table_sql statement
:param conn: Connection object
:param create_table_sql: a CREATE TABLE statement
:return:
"""
try:
c = conn.cursor()
c.execute(create_table_sql)
except Error as e:
print(e)
70. 70
EX01 MANIPULATE TABLE (CONT)
def main():
database = r"C:sqlitedbpythonsqlite.db"
sql_create_projects_table = """ CREATE TABLE IF NOT EXISTS projects (
sql_create_tasks_table = """CREATE TABLE IF NOT EXISTS tasks (
# create a database connection
conn = create_connection(database)
# create tables
if conn is not None:
# create projects table
create_table(conn, sql_create_projects_table)
# create tasks table
create_table(conn, sql_create_tasks_table)
else:
print("Error! cannot create the database connection.")
71. 71
EX02 SELECT DATA
def select_all_tasks(conn):
"""
Query all rows in the tasks table
:param conn: the Connection object
:return:
"""
cur = conn.cursor()
cur.execute("SELECT * FROM tasks")
rows = cur.fetchall()
for row in rows:
print(row)
72. 72
EX02 SELECT DATA (CONT)
def select_task_by_priority(conn, priority):
"""
Query tasks by priority
:param conn: the Connection object
:param priority:
:return:
"""
cur = conn.cursor()
cur.execute("SELECT * FROM tasks WHERE priority=?", (priority,))
rows = cur.fetchall()
for row in rows:
print(row)
73. 73
EX03 INSERT DATA
def create_task(conn, task):
"""
Create a new task
:param conn:
:param task:
:return:
"""
sql = ''' INSERT INTO tasks(name,priority,status_id,project_id,begin_date,end_date)
VALUES(?,?,?,?,?,?) '''
cur = conn.cursor()
cur.execute(sql, task)
return cur.lastrowid
74. 74
EX03 INSERT DATA (CONT)
def main():
database = r"C:sqlitedbpythonsqlite.db"
# create a database connection
conn = create_connection(database)
with conn:
# create a new project
project = ('Cool App with SQLite & Python', '2015-01-01', '2015-01-30');
project_id = create_project(conn, project)
# tasks
task_1 = ('Analyze the requirements of the app', 1, 1, project_id,
'2015-01-01', '2015-01-02')
task_2 = ('Confirm with user about the top requirements', 1, 1, project_id,
'2015-01-03', '2015-01-05')
# create tasks
create_task(conn, task_1)
create_task(conn, task_2)
75. 75
EX04 UPDATE DATA
def update_task(conn, task):
"""
update priority, begin_date, and end date of a task
:param conn:
:param task:
:return: project id
"""
sql = ''' UPDATE tasks
SET priority = ? ,
begin_date = ? ,
end_date = ?
WHERE id = ?'''
cur = conn.cursor()
cur.execute(sql, task)
conn.commit()
76. 76
EX04 UPDATE DATA (CONT)
def main():
database = r"C:sqlitedbpythonsqlite.db"
# create a database connection
conn = create_connection(database)
with conn:
update_task(conn, (2, '2015-01-04', '2015-01-06', 2))
77. 77
EX05 DELETE DATA
def delete_task(conn, id):
"""
Delete a task by task id
:param conn: Connection to the
SQLite database
:param id: id of the task
:return:
"""
sql = 'DELETE FROM tasks WHERE id=?'
cur = conn.cursor()
cur.execute(sql, (id,))
conn.commit()
def main():
database = r"C:sqlitedbpythonsqlite.db"
# create a database connection
conn = create_connection(database)
with conn:
delete_task(conn, 2);
# delete_all_tasks(conn);