Rename
This commit is contained in:
23
Pass3/databases.py
Executable file
23
Pass3/databases.py
Executable file
@@ -0,0 +1,23 @@
|
||||
import sqlite3
|
||||
|
||||
conn = sqlite3.connect('test.db')
|
||||
print("Databas öppnad!")
|
||||
|
||||
#create table
|
||||
#conn.execute('''CREATE TABLE test (ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL,AGE INT NOT NULL);''')
|
||||
#print("Tabell skapad!")
|
||||
|
||||
#insert data
|
||||
#conn.execute("INSERT INTO test (ID,NAME,AGE) VALUES (1, 'Elvis', 99)")
|
||||
#conn.execute("INSERT INTO test (ID,NAME,AGE) VALUES (2, 'Stephen Hawking', 76)")
|
||||
#conn.execute("INSERT INTO test (ID,NAME,AGE) VALUES (3, 'Shaq', 50)")
|
||||
#conn.commit()
|
||||
|
||||
#read data
|
||||
cursor = conn.execute("SELECT id, name, age from test")
|
||||
for row in cursor:
|
||||
print ("ID = ", row[0])
|
||||
print ("NAME = ", row[1])
|
||||
print ("AGE = ", str(row[2]), "\n")
|
||||
|
||||
conn.close()
|
||||
14
Pass3/files.py
Executable file
14
Pass3/files.py
Executable file
@@ -0,0 +1,14 @@
|
||||
|
||||
file = open("log.txt","w")
|
||||
|
||||
file.write("Hej världen!!\n")
|
||||
file.write("Lite mer text")
|
||||
|
||||
file.close()
|
||||
|
||||
file = open("log.txt","r")
|
||||
print(file.read())
|
||||
|
||||
#with open("log.txt") as file:
|
||||
#data = file.read()
|
||||
#do something with data
|
||||
23
Pass3/graphics.py
Executable file
23
Pass3/graphics.py
Executable file
@@ -0,0 +1,23 @@
|
||||
import turtle #har tagit koden från Stack Overflow
|
||||
|
||||
smiles = turtle.Turtle()
|
||||
smiles.penup()
|
||||
smiles.goto(-75,150)
|
||||
smiles.pendown()
|
||||
smiles.circle(10) #eye one
|
||||
|
||||
smiles.penup()
|
||||
smiles.goto(75,150)
|
||||
smiles.pendown()
|
||||
smiles.circle(10) #eye two
|
||||
|
||||
smiles.penup()
|
||||
smiles.goto(0,0)
|
||||
smiles.pendown()
|
||||
smiles.circle(100,90) #right smile
|
||||
|
||||
smiles.penup()
|
||||
smiles.setheading(180) # <-- look West
|
||||
smiles.goto(0,0)
|
||||
smiles.pendown()
|
||||
smiles.circle(-100,90)
|
||||
22
Pass3/gui_example1.py
Executable file
22
Pass3/gui_example1.py
Executable file
@@ -0,0 +1,22 @@
|
||||
from tkinter import Tk, Label, Button
|
||||
|
||||
class MyFirstGUI:
|
||||
def __init__(self, master):
|
||||
self.master = master
|
||||
master.title("A simple GUI")
|
||||
|
||||
self.label = Label(master, text="This is our first GUI!")
|
||||
self.label.pack()
|
||||
|
||||
self.greet_button = Button(master, text="Greet", command=self.greet)
|
||||
self.greet_button.pack()
|
||||
|
||||
self.close_button = Button(master, text="Close", command=master.quit)
|
||||
self.close_button.pack()
|
||||
|
||||
def greet(self):
|
||||
print("Greetings!")
|
||||
|
||||
root = Tk()
|
||||
my_gui = MyFirstGUI(root)
|
||||
root.mainloop()
|
||||
6
Pass3/gui_example2.py
Executable file
6
Pass3/gui_example2.py
Executable file
@@ -0,0 +1,6 @@
|
||||
import wx
|
||||
|
||||
app = wx.App(redirect=True)
|
||||
top = wx.Frame(None, title="Hello World", size=(300,200))
|
||||
top.Show()
|
||||
app.MainLoop()
|
||||
16
Pass3/gui_example3.py
Executable file
16
Pass3/gui_example3.py
Executable file
@@ -0,0 +1,16 @@
|
||||
import sys
|
||||
sys.path.append(r'C:\Python24\Lib')
|
||||
|
||||
import clr
|
||||
clr.AddReference("System.Windows.Forms")
|
||||
|
||||
from System.Windows.Forms import Application, Form
|
||||
|
||||
class HelloWorldForm(Form):
|
||||
|
||||
def __init__(self):
|
||||
self.Text = 'Hello World'
|
||||
self.Name = 'Hello World'
|
||||
|
||||
form = HelloWorldForm()
|
||||
Application.Run(form)
|
||||
8
Pass3/images.py
Executable file
8
Pass3/images.py
Executable file
@@ -0,0 +1,8 @@
|
||||
from PIL import Image #måste installera pillow
|
||||
try:
|
||||
myimage = Image.open("Python.png")
|
||||
except:
|
||||
print("Unable to load image")
|
||||
myimage.load()
|
||||
print(myimage.format, myimage.size, myimage.mode)
|
||||
myimage.show()
|
||||
17
Pass3/import.py
Executable file
17
Pass3/import.py
Executable file
@@ -0,0 +1,17 @@
|
||||
import os, math, random, statistics
|
||||
|
||||
#lite os saker
|
||||
print(os.getcwd())
|
||||
print(os.listdir('.'))
|
||||
|
||||
#lite matte och random
|
||||
print(math.pi)
|
||||
print(math.e)
|
||||
print(random.randrange(1,1000))
|
||||
|
||||
#lite statistik
|
||||
liteData = [12,324,345,234,1231,56,7,56,78,5567,5,45]
|
||||
print(statistics.mean(liteData))
|
||||
print(statistics.median(liteData))
|
||||
|
||||
|
||||
24
Pass3/internet.py
Executable file
24
Pass3/internet.py
Executable file
@@ -0,0 +1,24 @@
|
||||
from urllib.request import urlopen
|
||||
with urlopen('https://crossfit.com/workout/') as response:
|
||||
for line in response:
|
||||
line = line.decode('utf-8') # Decoding the binary data to text.
|
||||
if 'Wednesday' in line: # leta efter något
|
||||
print(line)
|
||||
|
||||
from lxml import html
|
||||
import requests #måste installera lxml and requests!
|
||||
page = requests.get('https://www.antagning.se/se/search?publishers=hv&period=VT_2018&searchableOnly=on&semesterPart=0')
|
||||
tree = html.fromstring(page.content)
|
||||
rows = tree.xpath('//h3[@class="heading4 moreinfolink"]/text()')
|
||||
print(rows)
|
||||
|
||||
resp = requests.get('http://api.icndb.com/jokes/random/1')
|
||||
data = resp.json()
|
||||
joke = data['value'][0]["joke"]
|
||||
print(joke)
|
||||
|
||||
"""import smtplib
|
||||
server = smtplib.SMTP('localhost') # fungerar bara med en mailserver på localhost så klart
|
||||
server.sendmail('william.jobe@hv.se', 'thedonald@whitehouse.gov',
|
||||
"To: thedonald@whitehouse.gov From: william.jobe@hv.se Testar SMTP från Python")
|
||||
server.quit()"""
|
||||
Reference in New Issue
Block a user