python-3.11

Python 3.11 worse optimized than 3.10?

Python 3.11 worse optimized than 3.10? Question: I run this simple loop with Python 3.10.7 and 3.11.0 on Windows 10. import time a = ‘a’ start = time.time() for _ in range(1000000): a += ‘a’ end = time.time() print(a[:5], (end-start) * 1000) The older version executes in 187ms, Python 3.11 needs about 17000ms. Does 3.10 …

Total answers: 2

pyFirmata gives error: module 'inspect' has no attribute 'getargspec'

pyFirmata gives error: module 'inspect' has no attribute 'getargspec' Question: I’m trying to use pyFirmata, but I can’t get it to work. Even the most basic of the library does not work. I guess there is something wrong with the library code. from pyfirmata import Arduino,util import time port = ‘COM5’ board = Arduino(port) I …

Total answers: 3

Different result when i switch positions of my two different functions

Different result when i switch positions of my two different functions Question: Note – I am using VSCode Sample 1: In this example my function nextSquare() is been executed, but aFunc() is not been executed, as in, i get no output for my 2nd function def nextSquare(): i = 1 while True: yield i*i i …

Total answers: 1

Why sum function is slower if the start argument is an instance of custom class?

Why sum function is slower if the 'start' argument is an instance of custom class? Question: I was playing around with sum function and observed the following behaviour. case 1: source = """ class A: def __init__(self, a): self.a = a def __add__(self, other): return self.a + other; sum([*range(10000)], start=A(10)) """ import timeit print(timeit.timeit(stmt=source)) As …

Total answers: 2

Why is not my discord code working? When i run the progam, it gives an error saying: TypeError: 'module' object is not callable

Why is not my discord code working? When i run the progam, it gives an error saying: TypeError: 'module' object is not callable Question: Here is my code: import discord from discord.ext import commands bot = discord.bot(command_prefix="!", help_command=None) @bot.event async def on_ready(): print(f"Bot logged in as {bot.user}") bot.run("TOKEN") The error i am getting: File "c:UsersuserOneDriveDesktopcodingdiscordserver …

Total answers: 2

Why does this specific code run faster in Python 3.11?

Why does this specific code run faster in Python 3.11? Question: I have the following code in a Python file called benchmark.py. source = """ for i in range(1000): a = len(str(i)) """ import timeit print(timeit.timeit(stmt=source, number=100000)) When I tried to run with multiple python versions I am seeing a drastic performance difference. C:UsersUsernameDesktop>py -3.10 …

Total answers: 1

How to print Arabic and English text together using Python's fpdf library

How to print Arabic and English text together using Python's fpdf library Question: pdf.multi_cell(w=150, h=5, txt="تمانتمانتمانتمانتم English Letters") "English Letters" is rendered as a row of rectangles in the output: I also tried using arabic_reshaper Example code snippet: import arabic_reshaper from bidi.algorithm import get_display reshaped_text = arabic_reshaper.reshape(text) bidi_text = get_display(reshaped_text) pdf.set_xy(9, 132) pdf.multi_cell(w=150, h=5, txt=bidi_text) …

Total answers: 1