<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>python on Jaaved Ali Khan</title><link>https://jaaved.netlify.app/tags/python/</link><description>Recent content in python on Jaaved Ali Khan</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sat, 02 Nov 2024 17:29:11 +0530</lastBuildDate><atom:link href="https://jaaved.netlify.app/tags/python/index.xml" rel="self" type="application/rss+xml"/><item><title>pytest</title><link>https://jaaved.netlify.app/notes/20210809095552-pytest/</link><pubDate>Sat, 02 Nov 2024 17:29:11 +0530</pubDate><guid>https://jaaved.netlify.app/notes/20210809095552-pytest/</guid><description>Summary # Awesome testing framework for python.
Setting up Django project # Create pytest.ini file in the Django root directory # pytest.ini
[pytest] DJANGO_SETTINGS_MODULE = epay.settings # in KFUPM settings loads local_settings # -- recommended but optional: python_files = tests.py test_*.py *_tests.py Run tests # Directory structure:
epay # repo root epay # django root epay settings.py# loads local_settings.py __init__.py local_settings.py app # application tests views_tests.py pytest.init conftest.py From the repository root</description></item><item><title>Regular Expressions</title><link>https://jaaved.netlify.app/notes/202105111004-regular_expressions/</link><pubDate>Tue, 12 Sep 2023 12:34:17 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202105111004-regular_expressions/</guid><description>re CS # Look-arounds # Lookahead and lookbehind, collectively called “lookaround” Lookarounds are zero width assertions. They check for a regex (towards right or left of the current position - based on ahead or behind), succeeds or fails when a match is found (based on if it is positive or negative) and discards the matched portion. metaphor of ahead and behind is used wrt to left to right direction (?</description></item><item><title>uWSGI</title><link>https://jaaved.netlify.app/notes/202106151600-uwsgi/</link><pubDate>Mon, 21 Aug 2023 18:09:09 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202106151600-uwsgi/</guid><description>Server # tag Python, Python Apps Python server used for serving Django web requests at ICTC Solution Delivery
Commands # Restart service uwsgi-emperor status service uwsgi-emperor restart Installation # Emperor # - name: Install uWSGI emperor apt: name=uwsgi-emperor state=present - name: Configure uWSGI emperor template: src: emperor.ini.j2 dest: /etc/uwsgi-emperor/emperor.ini owner: root group: root mode: 0644 notify: Restart uWSGI Emperor - name: Create log directory file: path: /var/log/uwsgi/vassals state: directory owner: root group: root notify: Restart uWSGI Emperor - name: Enable app server configuration (uWSGI emperor) template: src: uwsgi.</description></item><item><title>Encode/Decode in Python3</title><link>https://jaaved.netlify.app/notes/202105111623-encode_decode_in_python3/</link><pubDate>Sat, 29 Jul 2023 19:46:02 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202105111623-encode_decode_in_python3/</guid><description>tags Python Real Python ref
Decoding # Decode(v):convert (a coded message) into intelligible language. From this definition it means, in context of python, to convert a string of bytes(coded) to Unicode(intelligible).
In python3, strings are already decoded with Unicode. ref.
More about encoding/decoding in context of Unicode is found in there. There is no string without encoding # If you followed the discussion so far, you probably already picked up on a crucial point about saving and reading text on a computer: Having a string without knowing its encoding makes no sense at all.</description></item><item><title>Curl vs Python Requests SSL verification</title><link>https://jaaved.netlify.app/notes/curl_vs_python_requests_ssl_verification--20210929-180640/</link><pubDate>Sat, 29 Jul 2023 17:33:28 +0400</pubDate><guid>https://jaaved.netlify.app/notes/curl_vs_python_requests_ssl_verification--20210929-180640/</guid><description>curl vs
Having only the intermediate CA in the trust store is not sufficient for validation of the certificate, at least not with the current versions of Python. This feature would require the use of the OpenSSL flag X509_V_FLAG_PARTIAL_CHAIN for verification, which is neither currently exposed by Python nor set by default.
Contrary to this curl sets this flag by default in newer versions and thus works.</description></item><item><title>File Object in Python</title><link>https://jaaved.netlify.app/notes/202104051142-file_object_in_python/</link><pubDate>Mon, 10 Jul 2023 14:22:06 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202104051142-file_object_in_python/</guid><description>An Object in Python: File Object # ref These are just like another object with standard methods or interfaces- read(), write(), etc - . They allow interactions with underlying resource through the standard interface.
Good tutorial on File Object methods An object exposing a file-oriented API (with methods such as read() or write()) to an underlying resource. Depending on the way it was created, a file object can mediate access to a real on-disk file or to another type of storage or communication device (for example standard</description></item><item><title>Difference between Open(), StringIO and BytesIO?</title><link>https://jaaved.netlify.app/notes/202104051153-difference_between_open_stringio_and_bytesio/</link><pubDate>Sat, 14 Jan 2023 20:17:12 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202104051153-difference_between_open_stringio_and_bytesio/</guid><description>Summary # ref: link and stackoverflow
StringIO and BytesIO are methods(objects) that manipulate string and bytes data in memory(RAM). StringIO is used for string data and BytesIO is used for binary data. This classes create file like object() that operate on string data. The StringIO and BytesIO classes are most useful in scenarios where you need to mimic a normal file. Example # import io s = io.StringIO() print(s.write(&amp;#34;Hello World/n&amp;#34;)) # -------&amp;gt;Output: 13 # adding to the memory buffer using print statement print(&amp;#34;adding using the print&amp;#34;,file = s) # get all of the data written in the file print(s.</description></item><item><title>Buffer</title><link>https://jaaved.netlify.app/notes/202104051114-buffer/</link><pubDate>Sat, 14 Jan 2023 20:15:40 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202104051114-buffer/</guid><description>Semantic meaning # https://merriam-webster.com/dictionary/buffer
any of various devices or pieces of material for reducing shock or damage due to contact a means or device used as a cushion against the shock of fluctuations in business or financial activity a substance capable in solution of neutralizing both acids and bases and thereby maintaining the original acidity or basicity of the solution also : a solution containing such a substance a section of computer memory for temporarily storing information especially : one that accepts information at one rate and delivers it at another The streaming video feed continues to download into the buffer while the computer starts playing the movie.</description></item><item><title>Difference between File and Stream?</title><link>https://jaaved.netlify.app/notes/202104051145-difference_between_file_and_stream/</link><pubDate>Sat, 14 Jan 2023 20:12:21 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202104051145-difference_between_file_and_stream/</guid><description> Summary # tags :
Stream is a representation of flow of data from one side to another e.g. from disk to memory and from memory to diskBuffer is used to hold stream data temporarily.
File is a representation to store data on disk file.
File uses streams to store and load data.
Nice tutorial about the Python file: https://www.knowledgehut.com/tutorials/python-tutorial/python-file-io
Related #</description></item><item><title>Image object in Pillow</title><link>https://jaaved.netlify.app/notes/202104061056-image_object_in_pillow/</link><pubDate>Sat, 14 Jan 2023 20:07:11 +0400</pubDate><guid>https://jaaved.netlify.app/notes/202104061056-image_object_in_pillow/</guid><description>Summary # https://pillow.readthedocs.io/en/stable/reference/Image.html
PIL.Image.open(fp, mode=&amp;lsquo;r&amp;rsquo;, formats=None)
fp – A filename (string), pathlib.Path object or a file object. classPIL.Image.Image[source] # This class represents an image object. To create Image objects, use the appropriate factory functions. There’s hardly ever any reason to call the Image constructor directly.
open() new() frombytes() An instance of the Image class has the following methods. Unless otherwise stated, all methods return a new instance of the Image class, holding the resulting image.</description></item><item><title>Open function in python</title><link>https://jaaved.netlify.app/notes/202104051140-open_function_python/</link><pubDate>Mon, 12 Dec 2022 00:15:06 +0300</pubDate><guid>https://jaaved.netlify.app/notes/202104051140-open_function_python/</guid><description>Function # tags Python, File Object in Python ref: https://docs.python.org/3/library/functions.html#open
open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)
Open file and return a corresponding file object(). If the file cannot be opened, an OSError is raised. See Reading and Writing Files for more examples of how to use this function. file is a path-like object giving the pathname (absolute or relative to the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped.</description></item><item><title>Storing Pillow Image object to Django FileField(ImageField)</title><link>https://jaaved.netlify.app/notes/202104061159-storing_pillow_image_object_to_django_filefield_imagefield/</link><pubDate>Mon, 04 Apr 2022 10:31:54 +0300</pubDate><guid>https://jaaved.netlify.app/notes/202104061159-storing_pillow_image_object_to_django_filefield_imagefield/</guid><description>Requirement # Image object in Pillow to File Object in Django and save them as FileField and FieldFile
Methods # From Stackoverflow # ref: link
import StringIO from django.core.files.uploadedfile import InMemoryUploadedFile # Create a file-like object to write thumb data (thumb data previously created # using PIL, and stored in variable &amp;#39;thumb&amp;#39;) thumb_io = StringIO.StringIO() thumb.save(thumb_io, format=&amp;#39;JPEG&amp;#39;) # Create a new Django file-like object to be used in models as ImageField using # InMemoryUploadedFile.</description></item></channel></rss>