python-3.x

Dutch National Flag Problem Running in O(n)

亡梦爱人 提交于 2021-02-11 14:37:55
问题 I am a 10th-grade student in CompSci 1. In our textbook, Practical Programming 3rd Edition, An Introduction to Computer Science Using Python 3.6, it mentions the Dutch National Flag Problem. The following is how it states the exercise, word for word: Edsgar Dijkstra is known for his work on programming languages. He came up with a neat problem that he called the Dutch National Flag problem: given a list of strings, each of which is either "red", "green", or "blue" (each is represented several

Does Microsoft MSAL Resource Owner Password Credentials(ROPC) Grant authorization support ClientConfidentialApplicaton class to acquire Token?

丶灬走出姿态 提交于 2021-02-11 14:35:42
问题 MSAL for Python supports ROPC flow(Resource Owner Password Credentials Grant) supports token retrieve for Public Applications, Can we similarly use confidential client class in MSAL for python? The following links seem to say no--> https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki/Username-Password-Authentication Also, if we can use both Public & Confidential client, which is recommended from a security standpoint? The application is a service app that runs behind

Decode image bytes data stream to JPEG

守給你的承諾、 提交于 2021-02-11 14:35:31
问题 I am struggling to successfully decode a JPEG image from bytes, back to JPEG again. I started from encoded frame from a MJPG bytes stream, which I want to decode in order to manipulate with OpenCV. I am a bit of a newbie at Python, numpy, opencv etc! I now have the frame JPG data in a text file as: b'\xf\xd8\xff\xdb\x00....etc etc for purposes of testing: code seems to fail when I try to Resize the numpy array to the original video stream resolution (640, 480) on line 14 (npFlat.reshape((640

Threading event wait in django application

浪子不回头ぞ 提交于 2021-02-11 14:32:58
问题 I have DRF API consumed by a front-end application. I need to handle a special feature: the user clicks a button, he's being asked to scan a RFID card on an external device (he has 30 seconds to do so, he must not be able to do anything else during this time), then after the scan or timeout he gets the focus back. So far I've been able to deal with the scanning part, but troubles comes with the timeout. Here's my setup: The endpoint /rfid/create/ is called by the front when the user clicks

Openpyxl corrupts xlsx on save. Even when no changes were made

。_饼干妹妹 提交于 2021-02-11 14:30:13
问题 TL;DR; Using Openpyxl to save changes to a large excel file results in a corrupted xlsx file The Excel file is made of several tabs with graphs, formulae, and images, and tables. Powershell script can save edits to the xlsx file with no issues. I can read the cell values from the excel file with Openpyxl, I am also able to edit & save the xlsx file manually. Excel file is unprotected. All errors and code snippets have been provided below. I'm unable to add data to an excel file that one of

Openpyxl corrupts xlsx on save. Even when no changes were made

牧云@^-^@ 提交于 2021-02-11 14:28:49
问题 TL;DR; Using Openpyxl to save changes to a large excel file results in a corrupted xlsx file The Excel file is made of several tabs with graphs, formulae, and images, and tables. Powershell script can save edits to the xlsx file with no issues. I can read the cell values from the excel file with Openpyxl, I am also able to edit & save the xlsx file manually. Excel file is unprotected. All errors and code snippets have been provided below. I'm unable to add data to an excel file that one of

regex for catching abbreviations

雨燕双飞 提交于 2021-02-11 14:27:49
问题 I am trying to make a regex that matches abbreviations and their full forms in a string. I have a regex that catches some cases but on the example below, it catches more words than it should. Could anyone please help me fix this? x = 'Confirmatory factor analysis (CFA) is a special case of what is known as structural equation modelling (SEM).' re.findall(r'\b([A-Za-z][a-z]+(?:\s[A-Za-z][a-z]+)+)\s+\(([A-Z][A-Z]*[A-Z]\b\.?)',x) out: [('Confirmatory factor analysis', 'CFA'), ('special case of

Combine Numpy “where” statements

这一生的挚爱 提交于 2021-02-11 14:21:36
问题 I am trying to speed up a code that is using Numpy's where() function. There are two calls to where() , which return an array of indices for where the statement is evaluated as True , which are then compared for overlap with numpy's intersect1d() function, of which the length of the intersection is returned. import numpy as np def find_match(x,y,z): A = np.where(x == z) B = np.where(y == z) #A = True #B = True return len(np.intersect1d(A,B)) N = np.power(10, 8) M = 10 X = np.random.randint(M,

Why does a Python iterator need a dunder iter function?

﹥>﹥吖頭↗ 提交于 2021-02-11 14:21:33
问题 According to the documentation, a container that needs to be iterable should supply an __iter__() function to return an iterator. The iterator itself is required to follow the iterator protocol, meaning that it has to provide __iter__() that returns itself, and __next__() that provides the next item, or raises a StopIterator exception. Now I understand why both of those would be required in a container that does its own iteration, since you have to both provide an iterator and a next item:

how to pass variable in pywinauto.Application().start(cmd_line='')

谁说胖子不能爱 提交于 2021-02-11 14:21:27
问题 I have this code below: from pywinauto.application import Application '''user-defined package user_input1''' from user_input1 import Get_USER,Get_TOKEN import time server='host.domain.com' cwd=r'C:\Program Files (x86)\PuTTY' user = 'uname' '''user = Get_USER()''' password = Get_TOKEN() app = Application().start(cmd_line='putty -ssh uname@host.domain.com') putty = app.PuTTY putty.wait('ready') time.sleep(1) putty.type_keys(password) putty.type_keys("{ENTER}") time.sleep(1) putty.type_keys(