Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3120e94

Browse files
committed
Extra topics added
1 parent 8a6b072 commit 3120e94

17 files changed

+456
-36
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/src.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
python-tutorials
2-
===============
2+
================
33

4-
Intro is from "Intro to Development with Python" - Presented at Code District LA, April 2015
5-
http://www.meetup.com/code-district/events/221345836/
4+
"Beginning Python" - Presented by Patrick Wolf at Code District LA, July 2015
5+
https://www.eventbrite.com/e/beginning-python-training-registration-17137879860
6+
7+
8+
References:
9+
Python docstring styles:
10+
http://stackoverflow.com/a/24385103/91799
11+
Google style guide
12+
http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Comments

pyintro_a_basics/t_functions_test.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

pyintro_a_for_pycharm.zip

-3.1 KB
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
# Can be changed in: Preferences > IDE Settings > File and Code Templates

pyintro_c_extra/z1_naming.py renamed to pyintro_c_extra/convention_naming.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
'''
2-
@summary: Python Intro - Naming rules
3-
'''
4-
# ---------------------------
5-
# naming rules
6-
# ---------------------------
1+
#!/usr/bin/env python
2+
#-*- coding: utf-8 -*-
3+
4+
"""
5+
@summary: Python Intro - Naming rules
6+
7+
References:
8+
Python docstring styles:
9+
http://stackoverflow.com/a/24385103/91799
10+
Google style guide
11+
http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Comments
12+
"""
713

814
# Python is case sensitive
915
# Variables can't start with a number

pyintro_c_extra/exception_a_intro.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
6+
# exception handling syntax
7+
try:
8+
raise ValueError("ValueError raised")
9+
except ValueError as ex:
10+
print ex
11+
except IOError as ex:
12+
print ex
13+
# Multiple Exception as tuple
14+
except (IOError, EOFError) as ex:
15+
print type(ex), ex
16+
# as is not required if no reference to the exception is needed
17+
except MemoryError:
18+
print "Out of memory"
19+
# this catches any uncaught exception
20+
except:
21+
# throw the same exception again
22+
raise
23+
else:
24+
print "No exception was raised"
25+
finally:
26+
print "Finally is always called"
27+
28+
# exercise: devide number by 0 and catch the error
29+
30+
# exception strategy
31+
32+
33+
34+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
6+
# exception example
7+
try:
8+
f = open('myfile.txt')
9+
s = f.readline()
10+
i = int(s.strip())
11+
except IOError as e:
12+
print "I/O error({0}): {1}".format(e.errno, e.strerror)
13+
except ValueError:
14+
print "Could not convert data to an integer."
15+
except:
16+
print "Unexpected error:", sys.exc_info()[0]
17+
raise
18+
19+
# exception example
20+
while True:
21+
try:
22+
x = int(raw_input("Please enter a number: "))
23+
break
24+
except ValueError:
25+
print "Oops! That was no valid number. Try again..."
26+
27+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
def divide(x, y):
5+
try:
6+
result = x / y
7+
#TODO: Catch error when 2,0 is given
8+
else:
9+
print "result is", result
10+
finally:
11+
print "executing finally clause"
12+
13+
divide(2, 1)
14+
divide(2, 0)
15+
divide("2", "1")

0 commit comments

Comments
 (0)