240
This presentation cannot be shared unless the course is completed. The slides can be shared by the course provider end of the session only. 1

Python Orientation

Embed Size (px)

DESCRIPTION

Python Basics Tutorial, Intro to Python Python Data types  Functions, method Basic Elements, program structure Exceptions, Errors Strings, methods Python module OO Python:inheritance, staticmethod, classmethod, abc, Regular Expressions File I/O, SQlite DB Intro to Python, web framework dJango, testing

Citation preview

Page 1: Python Orientation

This presentation cannot be shared unless the course is completed. The slides can be shared by the course provider end of the session only.

1

Page 2: Python Orientation

2

Page 3: Python Orientation

Gives a brief overview of the Python programming. Describe the major focus of the presentation and why it is important. Introduce each of the major topics. To provide a road map for the audience, you can repeat this Overview slide throughout the presentation, highlighting the particular topic you will discuss next.

3

Page 4: Python Orientation

4

Page 5: Python Orientation

https://wiki.python.org/moin/WebFrameworks

5

Page 7: Python Orientation

Qt Cross platform framework (Win/Mac/X11, soon S60) Native look and feel Modular (Core, GUI, Network, OpenGL, SQL, WebKit, etc)

Mature Internationalization Excellent documentation Available under both commercial and Open Source licenses

7

Page 8: Python Orientation

This is another option for an Overview slides using transitions.

8

Page 9: Python Orientation

9

Page 10: Python Orientation

10

Page 11: Python Orientation

11

Page 12: Python Orientation

12

The purpose of this presentation is to make the case for three technologies ... (see next slide)

Page 13: Python Orientation

13

Page 14: Python Orientation

14

There is no standard definition of "scripting language", but this set of criteria pretty much captures what most people mean by the term.

Note that Java is interpreted (it requires a JVM) but it is statically (strongly) typed and requires a compilation step, so it is not a scripting language.

Page 15: Python Orientation

15

Page 16: Python Orientation

16

Page 17: Python Orientation

17

Page 18: Python Orientation

18

Page 19: Python Orientation

19

Page 20: Python Orientation

20

Page 21: Python Orientation

21

Page 22: Python Orientation

22

I got tired of cutting and pasting in pictures. This selection is possibly one-third of the Python books on the market in May of 2003.

One way to judge the acceptance of a language is by how many O'Reilly books cover it! Note that there are several O'Reilly books on this page, including "Python in a Nutshell" (a VERY good book), and there are others not shown – "Learning Python" by Lutz, the "Python Cookbook", etc.

Page 23: Python Orientation

23

Page 24: Python Orientation

24

Page 25: Python Orientation

25

Page 26: Python Orientation

26

Page 27: Python Orientation

27

Page 28: Python Orientation

28

Page 29: Python Orientation

29

Page 30: Python Orientation

30

Page 31: Python Orientation

31

Page 32: Python Orientation

32

Page 33: Python Orientation

33

Page 34: Python Orientation

34

Page 35: Python Orientation

35

Page 37: Python Orientation

37

Page 38: Python Orientation

http://stackoverflow.com/questions/4877290/what-is-the-dict-dict-attribute-of-a-python-class

38

Page 39: Python Orientation

39

Page 40: Python Orientation

40

Page 41: Python Orientation

41

Page 42: Python Orientation

42

Page 43: Python Orientation

43

Page 44: Python Orientation

44

Page 46: Python Orientation

46

Page 47: Python Orientation

47

Page 48: Python Orientation

48

Page 49: Python Orientation

49

Page 50: Python Orientation

50

Page 51: Python Orientation

51

Page 52: Python Orientation

52

Page 53: Python Orientation

53

Page 54: Python Orientation

54

Page 55: Python Orientation

55

Page 56: Python Orientation

Bool True = 1 False = 0

56

Page 57: Python Orientation

57

Page 58: Python Orientation

58

Page 59: Python Orientation

59

Page 60: Python Orientation

60

Page 61: Python Orientation

61

Page 62: Python Orientation

62

Page 63: Python Orientation

# Fibonacci a, b = 0, 1 while b < 1000:

print b a, b = b, a +b

63

Page 64: Python Orientation

64

Page 65: Python Orientation

What a function is Defining a function in Python Adding a docstring in Python

Function execution Function Assignment Return from function Inner function Default values of function parameters Keyword argument Lambda expression

65

Page 67: Python Orientation

67

Page 69: Python Orientation

69

Page 70: Python Orientation

70

Page 71: Python Orientation

71

Page 72: Python Orientation

Recursion is not a best practice for automations. Most preferred way is using loops

72

Page 73: Python Orientation

73

Page 74: Python Orientation

74

Page 75: Python Orientation

75

Page 76: Python Orientation

76

Page 77: Python Orientation

77

Page 78: Python Orientation

78

Page 79: Python Orientation

79

Page 80: Python Orientation

hi

bye 80

Page 81: Python Orientation

81

Page 82: Python Orientation

82

Page 83: Python Orientation

hi

bye 83

Page 84: Python Orientation

Try to see y value not having the string in the x.

84

Page 85: Python Orientation

This will help user when dealing with currency, Symbols, Specific Non English Languages

85

Page 86: Python Orientation

86

Page 87: Python Orientation

87

Page 88: Python Orientation

The approach using string.Template is easy to learn and should be familiar to bash users. It is suitable for exposing to end-users. This style became available in Python 2.4.

The percent-style will be familiar to many people coming from other programming languages. Some people find this style to be error-prone because of the trailing "s" in %(name)s, because the %-operator has the same precedence as multiplication, and because the behavior of the applied arguments depends on their data type (tuples and dicts get special handling). This style has been supported in Python since the beginning. The curly-bracket style is only supported in Python 2.6 or later. It is the most flexible style (providing a rich set of control characters and allowing objects to implement custom formatters).

88

Page 89: Python Orientation

89

Page 90: Python Orientation

90

Page 91: Python Orientation

91

Page 92: Python Orientation

92

Page 93: Python Orientation

93

Page 94: Python Orientation

94

Page 95: Python Orientation

95

Page 96: Python Orientation

96

Page 97: Python Orientation

97

Page 98: Python Orientation

98

Page 99: Python Orientation

99

Page 100: Python Orientation

100

Page 101: Python Orientation

101

Page 102: Python Orientation

102

Page 103: Python Orientation

103

Page 104: Python Orientation

104

Page 105: Python Orientation

105

Page 106: Python Orientation

106

Page 107: Python Orientation

107

Page 108: Python Orientation

108

Page 109: Python Orientation

109

Page 110: Python Orientation

110

Page 111: Python Orientation

http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2011/lectures/

111

Page 112: Python Orientation

112

Page 113: Python Orientation

113

Page 114: Python Orientation

Standard Python Modules http://www.python.org/doc/current/modindex.html PyPI: the Python Package Index :

third-party Python packages. http://www.python.org/pypi

114

Page 115: Python Orientation

115

Page 116: Python Orientation

116

Page 117: Python Orientation

117

Page 118: Python Orientation

118

Page 119: Python Orientation

119

Page 120: Python Orientation

120

Page 121: Python Orientation

121

Page 122: Python Orientation

122

Page 123: Python Orientation

123

Page 124: Python Orientation

124

Page 125: Python Orientation

125

Page 126: Python Orientation
Page 127: Python Orientation

127

Page 128: Python Orientation

128

Page 129: Python Orientation

129

Page 130: Python Orientation

130

Page 131: Python Orientation

131

Page 132: Python Orientation

132

Page 133: Python Orientation

133

Page 134: Python Orientation

134

Page 135: Python Orientation

135

Page 136: Python Orientation

136

Page 137: Python Orientation

137

Page 138: Python Orientation

138

Page 139: Python Orientation

139

Page 140: Python Orientation

140

Page 141: Python Orientation

141

Page 142: Python Orientation

142

Page 143: Python Orientation

143

Page 144: Python Orientation

144

Page 145: Python Orientation

145

Page 146: Python Orientation

Because Python doesn't have (and doesn't need) a formal Interface contract, the Java-style distinction between abstraction and interface doesn't exist. If someone goes through the effort to define a formal interface, it will also be an abstract class.

The only differences would be in the stated intent in the docstring. And the difference between abstract and interface is a hairsplitting thing when you have duck typing. Java uses interfaces because it doesn't have multiple inheritance.

146

Page 147: Python Orientation

147

Page 148: Python Orientation

148

Page 149: Python Orientation

Shape=type(“Shape”,(object,),{}) def area():

Rect=type(“Rect”,(Shape,),{l=2,b=4}

149

Page 150: Python Orientation

150

Page 151: Python Orientation

151

Page 152: Python Orientation

152

Page 153: Python Orientation

153

Page 154: Python Orientation

154

Page 155: Python Orientation

155

Page 156: Python Orientation

156

Page 157: Python Orientation

157

Page 158: Python Orientation

158

Page 159: Python Orientation

159

Page 160: Python Orientation

160

Page 161: Python Orientation

161

Page 162: Python Orientation

162

Page 163: Python Orientation

163

Greedy means match longest possible string. Lazy means match shortest possible string. For example, the greedy h.+l matches 'hell' in 'hello' but the lazy h.+?l matches 'hel'.

Page 164: Python Orientation

164

>>> s = ‘<a href=“index.html”>HERE</a><font size=“10”>’

Page 165: Python Orientation

165

Page 166: Python Orientation

166

Page 167: Python Orientation

167

Page 168: Python Orientation

168

Page 169: Python Orientation

169

Page 170: Python Orientation

170

Page 171: Python Orientation

171

Page 172: Python Orientation

172

Page 173: Python Orientation

173

Page 174: Python Orientation

174

Page 175: Python Orientation

175

Page 176: Python Orientation

176

Page 177: Python Orientation

177

Page 178: Python Orientation

178

Page 179: Python Orientation

179

Page 180: Python Orientation

180

Page 181: Python Orientation

As you can see, the method split has two optional parameters. If none is given (or is None) , a string will be separated into substring using whitespaces as delimiters, i.e. every substring consisting purely of whitespaces is used as a delimiter.

181

Page 182: Python Orientation

182

Page 183: Python Orientation

ZIP http://pythonprogramming.language-tutorial.com/2012/10/python-script-to-zip-and-unzip-files.html

183

Page 184: Python Orientation

184

Page 185: Python Orientation

185

Page 186: Python Orientation

186

Page 187: Python Orientation

hi

bye 187

Page 188: Python Orientation

188

Page 189: Python Orientation

Remember that print >> automatically appends an end-of-line marker Which is why the program above strips whitespace off the end of the string before printing it

189

Page 190: Python Orientation

190

Page 191: Python Orientation

YouTube: TheMonkeyLords Tutorial: 24 >>> with open('c:/pbin/pystudent2/foo.txt','rt') as fin:

... print fin.read()

... This is testing text file new line some more text

191

Page 192: Python Orientation

The whence argument is optional and defaults to os.SEEK_SET or 0 (absolute file positioning); other values are os.SEEK_CUR or 1 (seek relative to the current position) and

os.SEEK_END or 2 (seek relative to the file’s end).

192

Page 193: Python Orientation

http://pymotw.com/2/ospath/

193

Page 194: Python Orientation

The CSV (comma separated value) format is a common format used for spreadsheets and databases, for importing and exporting of data. Each line or record in the file has its fields separated by a delimiter, which can be a comma, tab, etc.

194

Page 195: Python Orientation

This is another option for an Overview slides using transitions. http://zetcode.com/db/sqlitepythontutorial/

http://www.tutorialspoint.com/sqlite/sqlite_python.htm

195

Page 196: Python Orientation

196

Page 197: Python Orientation

197

Page 198: Python Orientation

198

Page 199: Python Orientation

This is another option for an Overview slides using transitions.

199

Page 200: Python Orientation

200

Page 201: Python Orientation

201

Page 202: Python Orientation

202

Page 203: Python Orientation

203

Page 204: Python Orientation

204

Page 205: Python Orientation

205

Page 206: Python Orientation

Set the path to this directory

206

Page 207: Python Orientation

207

Page 208: Python Orientation

208

Page 209: Python Orientation

209

Page 210: Python Orientation

210

Page 211: Python Orientation

211

PhoneNumberField, EmailField, URLField 같이 DB차원의 Low-level ….이 아닌 사용자입장에서 모델링 가능..

적절한 validation도 자동으로 됨

Page 212: Python Orientation

212

Page 213: Python Orientation

213

Page 214: Python Orientation

214

startproject startapp settings.py, urls.py

models.py 복사 manage.py syncdb manage.py runserver http://localhost:8000/admin/

Page 215: Python Orientation

215

Page 216: Python Orientation

216

Page 217: Python Orientation

217

Page 218: Python Orientation

218

Page 219: Python Orientation

219

Page 220: Python Orientation

220

Page 221: Python Orientation

221

Page 222: Python Orientation

222

Page 223: Python Orientation

This is another option for an Overview slides using transitions.

223

Page 224: Python Orientation

224

Page 225: Python Orientation

225

Page 226: Python Orientation

http://effbot.org/zone/element-index.htm

226

Page 227: Python Orientation

227

Page 228: Python Orientation

228

Page 229: Python Orientation

229

Page 230: Python Orientation

230

Page 231: Python Orientation

231

Page 232: Python Orientation

232

Page 233: Python Orientation

Add a case study or class simulation to encourage discussion and apply lessons.

233

Page 234: Python Orientation

Discuss outcomes of the case study or class simulation. Cover best practices.

234

Page 235: Python Orientation

Microsoft Engineering Excellence

Microsoft Confidential 235

Page 236: Python Orientation

236

Page 237: Python Orientation

Microsoft Engineering Excellence

Microsoft Confidential 237

http://zetcode.com/db/sqlitepythontutorial/

Page 238: Python Orientation

Microsoft Engineering Excellence

Microsoft Confidential 238

Page 239: Python Orientation

You can contact us by email.

239

Page 240: Python Orientation

Microsoft Engineering Excellence

Microsoft Confidential 240

Presentation available on sildeshare and authorstream. Free to share it!