The tutorial I created is a test and use Probabilistic Graphical Models for the most basic problem the coin problem with the pgmpy python module.
This tutorial can be found on my GitHub account.
Is a blog about python programming language. You can see my work with python programming language, tutorials and news.
C:\Python310>python
Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
...
SyntaxError: '{' was never closed
...
>>> foo(a, b for b in range(5), c)
...
foo(a, b for b in range(5), c)
^^^^^^^^^^^^^^^^^^^
SyntaxError: Generator expression must be parenthesized
...
>>> {a, b for (a, b) in zip("a", "b")}
...
{a, b for (a, b) in zip("a", "b")}
^^^^
SyntaxError: did you forget parentheses around the comprehension target?
...
SyntaxError: expected ':'
...
SyntaxError: invalid syntax. Perhaps you forgot a comma?
...
SyntaxError: ':' expected after dictionary key
...
SyntaxError: expected 'except' or 'finally' block
...
SyntaxError: cannot assign to attribute here. Maybe you meant '==' instead of '='?
...
IndentationError: expected an indented block after 'if' statement in line ...
...
>>> import collections
>>> collections.namedtoplo
...
AttributeError: module 'collections' has no attribute 'namedtoplo'. Did you mean: 'namedtuple'?
...
>>> a = 0
>>> aa
...
NameError: name 'aa' is not defined. Did you mean: 'a'?
$ pip install pyqt5
class TileServer(object):
def __init__(self):
self.imagedict = {}
self.mydict = {}
self.layers = 'ROADMAP'
self.path = './'
self.urlTemplate = 'http://ecn.t{4}.tiles.virtualearth.net/tiles/{3}{5}?g=0'
self.layerdict = {'SATELLITE': 'a', 'HYBRID': 'h', 'ROADMAP': 'r'}
def tiletoquadkey(self, xi, yi, z, layers):
quadKey = ''
for i in range(z, 0, -1):
digit = 0
mask = 1 << (i - 1)
if(xi & mask) != 0:
digit += 1
if(yi & mask) != 0:
digit += 2
quadKey += str(digit)
return quadKey
def loadimage(self, fullname, tilekey):
im = Image.open(fullname)
self.imagedict[tilekey] = im
return self.imagedict[tilekey]
def tile_as_image(self, xi, yi, zoom):
tilekey = (xi, yi, zoom)
result = None
try:
result = self.imagedict[tilekey]
print(result)
except:
print(self.layers)
filename = '{}_{}_{}_{}.jpg'.format(zoom, xi, yi, self.layerdict[self.layers])
print("filename is " + filename)
fullname = self.path + filename
try:
result = self.loadimage(fullname, tilekey)
except:
server = random.choice(range(1,4))
quadkey = self.tiletoquadkey(*tilekey)
print (quadkey)
url = self.urlTemplate.format(xi, yi, zoom, self.layerdict[self.layers], server, quadkey)
print ("Downloading tile %s to local cache." % filename)
urllib.request.urlretrieve(url, fullname)
#urllib.urlretrieve(url, fullname)
result = self.loadimage(fullname, tilekey)
return result
import sys
from PyQt6.QtWidgets import QApplication, QWidget
def main():
app = QApplication(sys.argv)
w = QWidget()
w.resize(250, 200)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
sys.exit(app.exec())
if __name__ == '__main__':
main()
[root@desk mythcat]# dnf search PyQt6
Last metadata expiration check: 2:03:10 ago on Tue 06 Jul 2021 08:52:41 PM EEST.
No matches found.
[mythcat@desk ~]$ /usr/bin/python3 -m pip install --upgrade pip
...
WARNING: The scripts pip, pip3 and pip3.9 are installed in '/home/mythcat/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning,
use --no-warn-script-location.
Successfully installed pip-21.1.3
[mythcat@desk ~]$ pip install PyQt6 --user
...
import sys
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QApplication, QLabel
def main():
app = QApplication(sys.argv)
win = QLabel()
win.resize(640, 498)
win.setText("Qt is awesome!!!")
win.show()
app.exec()
if __name__ == "__main__":
main()
import os
import io
import sys
import glob
from PIL import Image
from PIL import UnidentifiedImageError
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QMainWindow, QApplication, QLabel
import argparse
from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument("files_path", type=Path, help='PATH of folder with files ')
parser.add_argument('-p','--print_files', action='store_true',
help='Print files from folder ')
parser.add_argument('-s','--show', action='store_true',
help='Show image in PyQt5 canvas!')
args = vars(parser.parse_args())
p = parser.parse_args()
print(p.files_path, type(p.files_path), p.files_path.exists())
print(p.show)
files = os.listdir(p.files_path)
file_list = []
image_list = []
bad_files_list =[]
if args['print_files']:
print("These are files from folder "+str(p.files_path))
for f in file_list:
print(f)
images_ext = str(Path(p.files_path))+'/*.png'
print("images_ext: "+images_ext)
for filename in glob.glob(images_ext): #assuming png
try:
f = open(filename, 'rb')
file = io.BytesIO(f.read())
im = Image.open(file)
image_list.append(filename)
print(str(len(image_list))+" good file is"+filename)
except Image.UnidentifiedImageError:
bad_files_list.append(str(p.files_path)+"/"+str(filename))
for f in bad_files_list:
print("bad file is : " + f)
if args['show']:
value = input("Please enter the index of PNG image :\n")
try:
int(value)
print("Image number select default : " + value)
value = int(value)
if value <= len(image_list):
value = int(value)
else:
print("The number image selected is greater then len of list images!")
value = len(image_list)
except:
print("This is not a number, I set first image number.")
value = 1
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.title = "Image Viewer"
self.setWindowTitle(self.title)
label = QLabel(self)
pixmap = QPixmap(image_list[int(value)])
label.setPixmap(pixmap)
self.setCentralWidget(label)
self.resize(pixmap.width(), pixmap.height())
app = QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
[mythcat@desk PIL001]$ python tool001.py
usage: tool001.py [-h] [-p] [-s] files_path
tool001.py: error: the following arguments are required: files_path
[mythcat@desk PIL001]$ python tool001.py ~/Pictures/
/home/mythcat/Pictures True
False
images_ext: /home/mythcat/Pictures/*.png
1 good file is/home/mythcat/Pictures/keyboard.png
2 good file is/home/mythcat/Pictures/Fedora_The_Pirate_CaribbeanHunt.png
3 good file is/home/mythcat/Pictures/website.png
4 good file is/home/mythcat/Pictures/Screenshot from 2021-02-19 19-24-32.png
...
97 good file is/home/mythcat/Pictures/Screenshot from 2021-07-03 17-31-23.png
98 good file is/home/mythcat/Pictures/Screenshot from 2021-07-03 17-46-05.png
bad file is : /home/mythcat/Pictures//home/mythcat/Pictures/Screenshot from 2021-02-07 14-58-56.png
bad file is : /home/mythcat/Pictures//home/mythcat/Pictures/evolution_logo.png
[mythcat@desk PIL001]$ python tool001.py ~/Pictures/ -p
/home/mythcat/Pictures True
False
These are files from folder /home/mythcat/Pictures
images_ext: /home/mythcat/Pictures/*.png
1 good file is/home/mythcat/Pictures/keyboard.png
2 good file is/home/mythcat/Pictures/Fedora_The_Pirate_CaribbeanHunt.png
3 good file is/home/mythcat/Pictures/website.png
...
97 good file is/home/mythcat/Pictures/Screenshot from 2021-07-03 17-31-23.png
98 good file is/home/mythcat/Pictures/Screenshot from 2021-07-03 17-46-05.png
bad file is : /home/mythcat/Pictures//home/mythcat/Pictures/Screenshot from 2021-02-07 14-58-56.png
bad file is : /home/mythcat/Pictures//home/mythcat/Pictures/evolution_logo.png
[mythcat@desk PIL001]$ python tool001.py ~/Pictures/ -s
/home/mythcat/Pictures True
True
images_ext: /home/mythcat/Pictures/*.png
...
97 good file is/home/mythcat/Pictures/Screenshot from 2021-07-03 17-31-23.png
98 good file is/home/mythcat/Pictures/Screenshot from 2021-07-03 17-46-05.png
bad file is : /home/mythcat/Pictures//home/mythcat/Pictures/Screenshot from 2021-02-07 14-58-56.png
bad file is : /home/mythcat/Pictures//home/mythcat/Pictures/evolution_logo.png
Please enter the index of PNG image :
6
Image number select default : 6