Skip to content

Commit a89a508

Browse files
committed
init commit
1 parent 0ec2700 commit a89a508

29 files changed

+852
-0
lines changed

32. systut.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sys
2+
3+
#sys.stderr.write('This is stderr text\n')
4+
#sys.stderr.flush()
5+
#sys.stdout.write('This is stdout text\n')
6+
7+
#print(sys.argv)
8+
def main(arg):
9+
print(arg)
10+
11+
12+
main(sys.argv[1])

33. urllibtutorialvid.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
import urllib.request
3+
import urllib.parse
4+
5+
#x = urllib.request.urlopen('https://www.google.com')
6+
#print(x.read())
7+
'''
8+
url = 'http://pythonprogramming.net'
9+
values = {'s':'basic',
10+
'submit':'search'}
11+
12+
data = urllib.parse.urlencode(values)
13+
data = data.encode('utf-8')
14+
req = urllib.request.Request(url,data)
15+
resp = urllib.request.urlopen(req)
16+
respData = resp.read()
17+
18+
print(respData)
19+
'''
20+
21+
try:
22+
x = urllib.request.urlopen('https://www.google.com/search?q=test')
23+
print(x.read())
24+
25+
except Exception as e:
26+
print(str(e))
27+
28+
29+
try:
30+
url = 'https://www.google.com/search?q=test'
31+
32+
headers = {}
33+
headers['User-Agent'] = 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17'
34+
req = urllib.request.Request(url, headers=headers)
35+
resp = urllib.request.urlopen(req)
36+
respData = resp.read()
37+
38+
saveFile = open('withHeaders.txt','w')
39+
saveFile.write(str(respData))
40+
saveFile.close()
41+
42+
except Exception as e:
43+
print(str(e))
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+

34. regularexpression - video.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
'''
2+
Identifiers:
3+
\d any number
4+
\D anything but a number
5+
\s space
6+
\S anything but a space
7+
\w any character
8+
\W anything but a character
9+
. any character, except for a newline
10+
\b the whitespace around words
11+
\. a period
12+
13+
Modifiers:
14+
{1,3} we're expecting 1-3
15+
+ Match 1 or more
16+
? Match 0 or 1
17+
* Match 0 or more
18+
$ match the end of a string
19+
^ matching the beginning of a string
20+
| either or
21+
[] range or "variance" [1-5a-qA-Z]
22+
{x} expecting "x" amount
23+
24+
White Space Characters:
25+
\n new line
26+
\s space
27+
\t tab
28+
\e escape
29+
\f form feed
30+
\r return
31+
32+
DONT FORGET!:
33+
. + * ? [ ] $ ^ ( ) {} | \
34+
'''
35+
36+
import re
37+
38+
exampleString = '''
39+
Jessica is 15 years old, and Daniel is 27 years old.
40+
Edward is 97, and his grandfather, Oscar, is 102.
41+
'''
42+
43+
ages = re.findall(r'\d{1,3}', exampleString)
44+
names = re.findall(r'[A-Z][a-z]*', exampleString)
45+
46+
print(ages)
47+
print(names)
48+
49+
50+
ageDict = {}
51+
52+
x = 0
53+
for eachName in names:
54+
ageDict[eachName] = ages[x]
55+
x+=1
56+
57+
print(ageDict)
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import urllib.request
2+
import urllib.parse
3+
import re
4+
5+
url = 'http://pythonprogramming.net'
6+
values = {'s':'basics',
7+
'submit':'search'}
8+
data = urllib.parse.urlencode(values)
9+
data = data.encode('utf-8')
10+
req = urllib.request.Request(url, data)
11+
resp = urllib.request.urlopen(req)
12+
respData = resp.read()
13+
14+
#print(respData)
15+
16+
paragraphs = re.findall(r'<p>(.*?)</p>',str(respData))
17+
18+
for eachP in paragraphs:
19+
print(eachP)
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+

36. tkinter basics 1 - Intro.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'''
2+
Hello and welcome to a basic intro to TKinter, which is the Python
3+
binding to TK, which is a toolkit that works around the Tcl language.
4+
5+
The tkinter module purpose to to generate GUIs, like windows. Python is not very
6+
popularly used for this purpose, but it is more than capable of being used
7+
8+
'''
9+
10+
11+
# Simple enough, just import everything from tkinter.
12+
from tkinter import *
13+
14+
15+
# Here, we are creating our class, Window, and inheriting from the Frame
16+
# class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__)
17+
class Window(Frame):
18+
19+
# Define settings upon initialization. Here you can specify
20+
def __init__(self, master=None):
21+
22+
# parameters that you want to send through the Frame class.
23+
# self, and this is the parent widget
24+
25+
# if you are wondering what self is... it is the object
26+
# created from the class. You can actually call it anything
27+
# you want... people just use "self"
28+
Frame.__init__(self, master)
29+
30+
#reference to the master widget, which is the tk window
31+
self.master = master
32+
33+
#with that, we want to then run init_window, which doesn't yet exist
34+
#self.init_window()
35+
36+
#Creation of init_window
37+
#def init_window(self):
38+
39+
# changing the title of our master widget
40+
# self.master.title("GUI")
41+
42+
43+
44+
45+
46+
47+
48+
# root window created. Here, that would be the only window, but
49+
# you can later have windows within windows.
50+
root = Tk()
51+
52+
#///root.geometry("250x150+300+300")
53+
54+
#creation of an instance
55+
app = Window(root)
56+
57+
#mainloop
58+
root.mainloop()
59+

37. tkinter basics 2 - buttons.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'''
2+
Hello and welcome to a basic intro to TKinter, which is the Python
3+
binding to TK, which is a toolkit that works around the Tcl language.
4+
5+
The tkinter module purpose to to generate GUIs, like windows. Python is not very
6+
popularly used for this purpose, but it is more than capable of being used
7+
8+
'''
9+
10+
11+
# Simple enough, just import everything from tkinter.
12+
from tkinter import *
13+
14+
15+
# Here, we are creating our class, Window, and inheriting from the Frame
16+
# class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__)
17+
class Window(Frame):
18+
19+
# Define settings upon initialization. Here you can specify
20+
def __init__(self, master=None):
21+
22+
# parameters that you want to send through the Frame class.
23+
Frame.__init__(self, master)
24+
25+
#reference to the master widget, which is the tk window
26+
self.master = master
27+
28+
#with that, we want to then run init_window, which doesn't yet exist
29+
self.init_window()
30+
31+
#Creation of init_window
32+
def init_window(self):
33+
34+
# changing the title of our master widget
35+
self.master.title("GUI")
36+
37+
# allowing the widget to take the full space of the root window
38+
self.pack(fill=BOTH, expand=1)
39+
40+
# creating a button instance
41+
quitButton = Button(self, text="Quit")#,command=self.quit)
42+
43+
# placing the button on my window
44+
quitButton.place(x=0, y=0)
45+
46+
47+
48+
49+
50+
51+
52+
# root window created. Here, that would be the only window, but
53+
# you can later have windows within windows.
54+
root = Tk()
55+
56+
root.geometry("400x300")
57+
58+
#creation of an instance
59+
app = Window(root)
60+
61+
#mainloop
62+
root.mainloop()
63+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'''
2+
Hello and welcome to a basic intro to TKinter, which is the Python
3+
binding to TK, which is a toolkit that works around the Tcl language.
4+
5+
The tkinter module purpose to to generate GUIs, like windows. Python is not very
6+
popularly used for this purpose, but it is more than capable of being used
7+
8+
'''
9+
10+
11+
# Simple enough, just import everything from tkinter.
12+
from tkinter import *
13+
14+
15+
# Here, we are creating our class, Window, and inheriting from the Frame
16+
# class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__)
17+
class Window(Frame):
18+
19+
# Define settings upon initialization. Here you can specify
20+
def __init__(self, master=None):
21+
22+
# parameters that you want to send through the Frame class.
23+
Frame.__init__(self, master)
24+
25+
#reference to the master widget, which is the tk window
26+
self.master = master
27+
28+
#with that, we want to then run init_window, which doesn't yet exist
29+
self.init_window()
30+
31+
#Creation of init_window
32+
def init_window(self):
33+
34+
# changing the title of our master widget
35+
self.master.title("GUI")
36+
37+
# allowing the widget to take the full space of the root window
38+
self.pack(fill=BOTH, expand=1)
39+
40+
# creating a button instance
41+
quitButton = Button(self, text="Exit",command=self.client_exit)
42+
43+
# placing the button on my window
44+
quitButton.place(x=0, y=0)
45+
46+
47+
48+
49+
def client_exit(self):
50+
exit()
51+
52+
53+
54+
55+
56+
57+
58+
# root window created. Here, that would be the only window, but
59+
# you can later have windows within windows.
60+
root = Tk()
61+
62+
root.geometry("400x300")
63+
64+
#creation of an instance
65+
app = Window(root)
66+
67+
#mainloop
68+
root.mainloop()
69+

0 commit comments

Comments
 (0)