{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
},
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"\n",
"Gegeben ist eine binäre Grafikdatei ohm.png
."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"from IPython.display import Image\n",
"Image(filename=\"ohm.png\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
},
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"_Aufgabe 1_\n",
"\n",
"Erstellen Sie ein Python-Programm, dass diese Datei in eine zweite\n",
"Datei logo.png
kopiert. Übertragen Sie die Daten bitte\n",
"in 32 Byte Paketen."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
},
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"from IPython.display import Image\n",
"\n",
"\n",
"with open(\"ohm.png\", \"rb\") as source_file:\n",
" with open(\"logo.png\", \"wb\") as dest_file:\n",
" buffer_size = 32\n",
" buffer = source_file.read(buffer_size)\n",
" while len(buffer)>0:\n",
" dest_file.write(buffer)\n",
" buffer = source_file.read(buffer_size)\n",
"\n",
"\n",
"Image(filename=\"logo.png\")"
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
}
},
"nbformat": 4,
"nbformat_minor": 1
}