data = myfile.read()
Python 101
donderdag 20 februari 2020
File in one string
with open('data.txt', 'r') as myfile:
data = myfile.read()
data = myfile.read()
woensdag 19 februari 2020
MD5 File Checksum
import hashlib
for filename in os.listdir(directory):
if filename.endswith(".xml"):
#print(directory+filename)
with open(directory+filename, encoding="utf8") as file_to_check:
# read contents of the file
data = file_to_check.read()
# pipe contents of the file through
md5checksum = hashlib.md5(data.encode('utf-8')).hexdigest()
Till Next Time
for filename in os.listdir(directory):
if filename.endswith(".xml"):
#print(directory+filename)
with open(directory+filename, encoding="utf8") as file_to_check:
# read contents of the file
data = file_to_check.read()
# pipe contents of the file through
md5checksum = hashlib.md5(data.encode('utf-8')).hexdigest()
Till Next Time
woensdag 12 februari 2020
Split files for training en test in 2 directories
import os
from random import randrange
directory = 'C:\\GitHub\\TensorFlow\\workspace\\traininig_demo\\images'
traindir = 'C:\\GitHub\\TensorFlow\\workspace\\traininig_demo\\images\\train'
testdir = 'C:\\GitHub\\TensorFlow\\workspace\\traininig_demo\\images\\test'
for filename in os.listdir(directory):
if filename.endswith(".xml"):
print(os.path.join(directory, filename))
if os.path.isfile(os.path.join(directory, filename[0:-4]+'.jpg')):
x = randrange(100)
if x <= 75:
os.replace(os.path.join(directory, filename), os.path.join(traindir, filename))
os.replace(os.path.join(directory, filename[0:-4]+'.jpg'), os.path.join(traindir, filename[0:-4]+'.jpg'))
else:
os.replace(os.path.join(directory, filename), os.path.join(testdir, filename))
os.replace(os.path.join(directory, filename[0:-4]+'.jpg'), os.path.join(testdir, filename[0:-4]+'.jpg'))
else:
continue
Till Next Time
from random import randrange
directory = 'C:\\GitHub\\TensorFlow\\workspace\\traininig_demo\\images'
traindir = 'C:\\GitHub\\TensorFlow\\workspace\\traininig_demo\\images\\train'
testdir = 'C:\\GitHub\\TensorFlow\\workspace\\traininig_demo\\images\\test'
for filename in os.listdir(directory):
if filename.endswith(".xml"):
print(os.path.join(directory, filename))
if os.path.isfile(os.path.join(directory, filename[0:-4]+'.jpg')):
x = randrange(100)
if x <= 75:
os.replace(os.path.join(directory, filename), os.path.join(traindir, filename))
os.replace(os.path.join(directory, filename[0:-4]+'.jpg'), os.path.join(traindir, filename[0:-4]+'.jpg'))
else:
os.replace(os.path.join(directory, filename), os.path.join(testdir, filename))
os.replace(os.path.join(directory, filename[0:-4]+'.jpg'), os.path.join(testdir, filename[0:-4]+'.jpg'))
else:
continue
Till Next Time
Which enviroment is running?
import sys
print(sys.prefix)
Till Next Time
print(sys.prefix)
Till Next Time
Welcome at Python 101
Welcome at Pyth101.blogspot.com. (Python101 was already taken ;-( )
On a really irregular base I wil drop here pieces of python code. Mostly just for me, but they might be usefull for you!
Till Next Time
On a really irregular base I wil drop here pieces of python code. Mostly just for me, but they might be usefull for you!
Till Next Time
Abonneren op:
Posts (Atom)