I want to mock requests.session() in unit test. It works when I don’t use with statement, however it fails when I start using it. This is the code I execute: main.py: test_main.py: Answer Your test setup is ignoring the fact that s comes from the __enter__ method of the context manager class. You need t…
How do I run through a list of links one by one and then scrape data using selenium(driver.get)?
I’m trying to loop through 2 sets of links. Starting with https://cuetracker.net/seasons > click through each season link (Last 5 seasons) and then click through each tournament link within each season link and scrape the match data from each tournament. Using the below code I have managed to get a l…
Cannot access Django administrator site in Django-3
Successfully created an admin user using py manage.py createsuperuser. Entered username, e-mail, password but whenever I try to access this link http://127.0.0.1:8000/admin/ it says “This site can’t be reached” and “127.0.0.1 refused to connect, ” How do I fix this error and access the…
TypeError: Cannot instantiate typing.Optional [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 2 y…
How to read .rtf file and convert into python3 strings and can be stored in python3 list?
I am having a .rtf file and I want to read the file and store strings into list using python3 by using any package but it should be compatible with both Windows and Linux. I have tried striprtf but read_rtf is not working. But in this code, the error is: cannot import name ‘read_rtf’ Please can an…
How can I make this grammar unambiguous?
I’m trying to write a parser for a simple language: When I run it, I get the following error: I understand that this is happening because, if we imagine that the parser was built without an error, and then wrote parser.parse(‘foo’), both arithmetic_expr and boolean_expr would be “corre…
Use PyPDF2 to detect non-embedded fonts in PDF file generated by Google Docs
I was hoping someone could help me write a Python function to detect any fonts in the file which are not embedded in the file. I’ve attempted to use the script linked here, and it can detect the documents fonts, but it does not detect fonts which are embedded. I’ve pasted the script below for conv…
How to evaluate a variable within a dict in jinja
I would like to evaluate a variable within a dict object in Jinja. Is that possible? In the example, {{ obj_list }} is treated as text. Is there a syntax to evaluate this variable within? Answer You can use ~ to include variables within strings: {%- set long_dict_set = {“key”:”text text R…
Assign multiple variables from a list of file names
I have a list of file and a list of variables names I want to assign every item in var_names a read_spss function. so that ill get Thanks Answer Like the comment above the easiest way to do this is with a dictionary. That way then you can just access it like this files[‘var1’] to get the content o…
Python – Filtering dataframe based on 3 columns potentially containing a sought after value
I’m trying to take a query of recent customer transactions and match potential primary phone, cellphone and work phone matches against a particular list of customers I have. Essentially, I am taking one dataframe column (the list of customers I am trying to see if they had transactions recently) against…