QuestionId
int64
74.8M
79.8M
UserId
int64
56
29.4M
QuestionTitle
stringlengths
15
150
QuestionBody
stringlengths
40
40.3k
Tags
stringlengths
8
101
CreationDate
stringdate
2022-12-10 09:42:47
2025-11-01 19:08:18
AnswerCount
int64
0
44
UserExpertiseLevel
int64
301
888k
UserDisplayName
stringlengths
3
30
75,503,112
11,389,265
Bug in Boto3 AWS S3 generate_presigned_url in Lambda Python 3.X with specified region?
<p>I tried to write a python lambda function that returns a pre-signed url to put an object.</p> <pre><code>import os import boto3 import json import boto3 session = boto3.Session(region_name=os.environ['AWS_REGION']) s3 = session.client('s3', region_name=os.environ['AWS_REGION']) upload_bucket = 'BUCKER_NAME' # Re...
<python><amazon-web-services><aws-lambda><boto3><aws-sdk-nodejs>
2023-02-19 20:07:54
1
557
leos
75,503,034
9,757,174
ValueError: [TypeError("'_cffi_backend.FFI' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')] in FastAPI
<p>I am working with FastAPI and Firestore and I created a very basic endpoint to read all the documents in a collection. However, I get the following error when I run my code and I can't seem to figure out where it's coming from.</p> <p><code>ValueError: [TypeError(&quot;'_cffi_backend.FFI' object is not iterable&quot...
<python><google-cloud-firestore><fastapi>
2023-02-19 19:51:15
1
1,086
Prakhar Rathi
75,503,027
1,431,255
Programmatically register function as a test function in pytest
<p>I would like to programmatically add or mark a function as a test-case in pytest, so instead of writing</p> <pre><code>def test_my_function(): pass </code></pre> <p>I would like to do something like (pseudo-api, I know neither <code>pytest.add_test</code> nor <code>pytest.testcase</code> exist by that identifie...
<python><pytest>
2023-02-19 19:50:53
1
3,299
wirrbel
75,502,998
774,133
Lists become pd.Series, the again lists with one dimension more
<p>I have another problem with pandas, I will never make mine this library.</p> <p>First, this is - I think - how <code>zip()</code> is supposed to work with lists:</p> <pre><code>import numpy as np import pandas as pd a = [1,2] b = [3,4] print(type(a)) print(type(b)) vv = zip([1,2], [3,4]) for i, v in enumerate(vv):...
<python><pandas><dataframe><numpy>
2023-02-19 19:46:48
3
3,234
Antonio Sesto
75,502,993
14,141,126
Looping thru file types and attaching them into email
<p>I have a list of text files and html files generated by two distinct functions. Each file is labeled signal1.txt, signal2, etc. and signal1.html, signal2.html, etc. I need to send an email with each file pair (signal1.txt and signal1.html, signal2.txt and signal.2.html, and so forth).</p> <p>I've tried several diffe...
<python>
2023-02-19 19:46:21
1
959
Robin Sage
75,502,964
2,607,447
Different behavior between multiple nested lookups inside .filter and .exclude
<p>What's the difference between having multiple nested lookups inside <code>queryset.filter</code> and <code>queryset.exclude</code>?</p> <p>For example car ratings. User can create ratings of multiple types for any car.</p> <pre><code>class Car(Model): ... class Rating(Model): type = ForeignKey('RatingType')...
<python><django><django-queryset><django-orm>
2023-02-19 19:42:43
1
18,885
Milano
75,502,794
5,197,329
pytest unittest, how to group test cases?
<p>I am new to unit testing and trying to implement some in my latest project. However, I can't seem to get the structure quite right. In the following example I have a bunch of redundant code and it still isn't working, with the @pytest.mark.parametrize</p> <p>What I would like ideally is for my test_select_childnode ...
<python><unit-testing><pytest>
2023-02-19 19:15:32
2
546
Tue
75,502,642
12,858,691
Pyplot: change size of tick lines on axis
<p>Consider this reproducable example:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt labels = ['0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21'] fig, axes = plt.subplots(nrows=3, ncols=3,figsize=(6, 3.5),dpi=300) plt.subplots_adjust(wspace=0.025, hs...
<python><matplotlib>
2023-02-19 18:53:34
3
611
Viktor
75,502,494
18,749,472
Django ORM vs raw SQL - security
<p>My django project makes use of lots and lots of database queries, some are complex and some are basic SELECT queries with no conditions or logic involved.</p> <p>So far I have been using the <code>sqlite3</code> module to manage my database, instead of the django ORM which has worked very well. One problem or drawba...
<python><sql><django><security><sql-injection>
2023-02-19 18:30:50
0
639
logan_9997
75,502,448
654,019
split a string and get the first two sections (if they exist) in python
<p>I have these strings in Python:</p> <pre><code>a=['One','one_two','one_two_three','one_two_three_four'] </code></pre> <p>And I need to get the two first parts (splitting based on '_').</p> <p>I can write something like this:</p> <pre><code>for c in a: x=c.split(&quot;_&quot;, 2) if(len(x)&gt;=2): ...
<python>
2023-02-19 18:23:08
4
18,400
mans
75,502,400
9,983,652
why installed new version of a package is not available in my virtual environment?
<p>I use to have yfinance 0.1.67 installed and today I installed a new version of yfinance 0.2.12 using conda install -c conda-forge yfinance. However I didn't see this new version. I was still using old version. so I decided to remove yfinance and do it again from start.</p> <p>after removing all yfinance, I used cond...
<python><conda>
2023-02-19 18:15:48
0
4,338
roudan
75,502,336
1,549,736
How to properly implement single source project versioning in Python?
<p>I love the way <em>CMake</em> allows me to single source version my C/C++ projects, by letting me say:</p> <pre><code>project(Tutorial VERSION 1.0) </code></pre> <p>in my <code>CMakeLists.txt</code> file and, then, use placeholders of the form:</p> <pre class="lang-c prettyprint-override"><code>#define ver_maj @Tuto...
<python><cmake><versioning>
2023-02-19 18:06:30
1
2,018
David Banas
75,502,132
354,420
Using date picker as filter in django admin
<p>How to get date picker in Django Admin Filter?</p> <p>using simple list_filter will get me text selection: Any date, last 7 days, last months etc. But I want simple datepicker, so i can choose just one date... I found django-admin-daterange but I don't need range - just ONE date..</p>
<python><django><django-admin>
2023-02-19 17:38:12
2
1,544
Tomasz Brzezina
75,502,050
8,913,338
share enum between c and python
<p>I have enum that used for communication between python server and c client.</p> <p>I want to have the enum just in single file, prefer to use python enum class.</p> <p>Also I prefer to avoid mixing with runtime parsing of C enum in python.</p>
<python><c><enums>
2023-02-19 17:25:54
1
511
arye
75,501,913
2,026,022
How do I download PDF invoices from stripe.com for previous year?
<p>I need to download all invoices from stripe.com for the past year for accounting purposes. I didn't find a button for that, and when I contacted stripe.com support, they said it's not possible and I should use API if I can.</p> <p>I found <a href="https://modernwebtools.com/stripe-invoice-exporter/" rel="nofollow no...
<python><stripe-payments><invoice>
2023-02-19 17:08:56
1
2,347
Lucas03
75,501,499
9,601,748
Can't run a Flask server
<p>I'm trying to follow <a href="https://levelup.gitconnected.com/using-tensorflow-with-flask-and-react-ba52babe4bb5" rel="nofollow noreferrer">this</a> online tutorial for a Flask/Tensorflow/React application, but I'm having some trouble at the end now trying to run the Flask server.</p> <p>Flask version: 2.2.3</p> <p...
<python><flask>
2023-02-19 16:07:47
1
311
Marcus
75,501,283
2,221,360
Slice array based by providing string ':' as index in Numpy
<p>I am in a position to extract whole data from an array. The simplest method would be simply passing <code>array[:]</code>. However, I want to make it automated as part of the larger project where the index would be varying with the data format. Therefore, is it possible to extract the whole data by passing a slicing...
<python><numpy><numpy-slicing>
2023-02-19 15:39:29
0
3,910
sundar_ima
75,501,243
6,366,251
How to install a package with pip from VCS URL only if not already installed?
<p>With pip’s legacy resolver, it was possible to install a package from a VCS URL only if it is not already installed:</p> <pre><code>% pip install 'git+https://test.invalid/#egg=pip' --use-deprecated=legacy-resolver Requirement already satisfied: pip from git+https://test.invalid/#egg=pip in ./.virtualenvs/test_vcs_i...
<python><pip>
2023-02-19 15:33:29
0
2,014
Manuel Jacob
75,501,212
12,276,690
Create a specific amount of function duplicates and run them simultaneously
<p>I have an async program based around a set of multiple infinitely-running functions that run simultaneously.</p> <p>I want to allow users to run a specific amount of specific function duplicates.</p> <p>A code example of what I have now:</p> <pre class="lang-py prettyprint-override"><code>async def run(): await as...
<python><multithreading><algorithm><concurrency><python-asyncio>
2023-02-19 15:28:55
1
620
TimesAndPlaces
75,501,133
1,614,466
Unsupported Interpolation Type using env variables in Hydra
<p>What I'm trying to do: use environment variables in a Hydra config.</p> <p>I worked from the following links: <a href="https://omegaconf.readthedocs.io/en/1.4_branch/usage.html#environment-variable-interpolation" rel="noreferrer">OmegaConf: Environment variable interpolation</a> and <a href="https://hydra.cc/docs/co...
<python><hydra><omegaconf>
2023-02-19 15:17:16
1
839
KSHMR
75,500,991
5,197,270
Spoof ongoing datetime in Python
<p>I am looking for the simplest solution to spoof live <code>datetime</code>, specifically, I would like it to start at a specific time, say <code>2023-01-03 15:29</code>, and make it go on, so that the clock is ticking, so to speak.</p> <p>There are plenty of ways to spoof current <code>datetime</code>, but I haven't...
<python><datetime>
2023-02-19 14:55:10
2
411
scott_m
75,500,948
12,248,328
Python arbritary keys in TypedDict
<p>Is it possible to make a TypedDict with a set of known keys and then a type for an arbitrary key? For example, in TypeScript, I could do this:</p> <pre><code>interface Sample { x: boolean; y: number; [name: string]: string; } </code></pre> <p>What is the equivalent in Python?</p> <hr /> <p>Edit: My problem is...
<python><python-3.x><python-typing><typeddict>
2023-02-19 14:48:37
1
423
Epic Programmer
75,500,937
19,771
Setting colors on a trimesh union mesh according to the original component meshes
<p>I'm working with the <a href="https://trimsh.org/" rel="nofollow noreferrer">trimesh</a> Python library, and I couldn't wrap my head around working with colors from reading the docs (a Spartan API reference) and examples. I'm not even sure if I'm setting the face colors right, if I can modify <code>mesh.visual.face_...
<python><trimesh>
2023-02-19 14:45:45
0
368
villares
75,500,915
5,912,144
Imported python class instance inheritance
<p>Currently I'm inheriting from an external class and importing another one locally:</p> <pre><code>from locust.contrib.fasthttp import FastHttpUser from local_helper import TaskDetails class User_1(FastHttpUser): @task def iteration_task(self): self.client.get(url) </code></pre> <p>I wan...
<python><python-3.x><oop><inheritance><locust>
2023-02-19 14:42:53
0
3,035
Ardhi
75,500,906
19,325,656
Combine models to get cohesive data
<p>I'm writing app in witch I store data in separate models. Now I need to combine this data to use it.</p> <p><strong>The problem</strong></p> <p>I have three models:</p> <pre><code>class User(AbstractBaseUser, PermissionsMixin): email = models.EmailField(unique=True) first_name = models.CharField(max_length=5...
<python><django><django-models><django-rest-framework><django-serializer>
2023-02-19 14:42:06
1
471
rafaelHTML
75,500,838
13,803,549
How to change Discord.py button color and disable on interaction
<p>I am trying to change the button color to grey and disable it once it is clicked but nothing I find seems to be working. It really seems like it should be simple enough to do and I tried 'edit_message' but maybe I used it wrong. Here is the code for my button, I took out all the irrelevant code.</p> <p>I really appr...
<python><discord><discord.py>
2023-02-19 14:31:06
1
526
Ryan Thomas
75,500,774
1,934,903
executing java command from script gives error even though same command from cli works fine
<p>I'm writing a python script that amongst other things launches a jar file.</p> <p>I'm using the following method to fire the java command:</p> <pre><code> def first_launch(self): if self.is_initialize: subprocess.run( [f&quot;-Xmx{self.max_memory}M&quot;, f&quot;-Xms{self.min_memo...
<python><java>
2023-02-19 14:18:50
1
21,108
Chris Schmitz
75,500,758
19,115,554
What is the Group.lostsprites attribute for in pygame?
<p>In pygame, groups have a <code>lostsprites</code> attribute. What is this for?<br /> Link to where its first defined in the code: <a href="https://github.com/pygame/pygame/blob/main/src_py/sprite.py#L361" rel="nofollow noreferrer">pygame/src_py/sprite.py</a></p> <p>It seems to be some sort of internal thing as I was...
<python><pygame><sprite><internals>
2023-02-19 14:16:54
1
602
MarcellPerger
75,500,738
15,724,084
python selenium getting urls from google search results
<p>I am trying to get firt 10 urls from google search results with selenium. I knew that there was other term than <code>inerHTML</code> which will give me the text inside <code>cite</code> tags.</p> <p>here is code</p> <pre><code>#open google from selenium.webdriver.chrome.options import Options from selenium import w...
<python><selenium-webdriver><getattribute>
2023-02-19 14:15:01
2
741
xlmaster
75,500,723
8,792,159
How to allow each subplot in hvplot to have it's own x-axis scaling?
<p>I have a data frame that has three columns: <code>stage</code> (which has two values, <code>&quot;before&quot;</code> and <code>&quot;after&quot;</code>, which stands for &quot;before and after preprocessing&quot;), <code>variable</code> (holding the name for each variable) and <code>value</code> (holding the values...
<python><holoviews><hvplot>
2023-02-19 14:12:33
1
1,317
Johannes Wiesner
75,500,672
12,285,101
pandas changed column value condition of three other columns
<p>I have the following pandas dataframe:</p> <pre><code>df = pd.DataFrame({'pred': [1, 2, 3, 4], 'a': [0.4, 0.6, 0.35, 0.5], 'b': [0.2, 0.4, 0.32, 0.1], 'c': [0.1, 0, 0.2, 0.2], 'd': [0.3, 0, 0.1, 0.2]}) </code></pre> <p>I want to change value...
<python><pandas>
2023-02-19 14:05:28
2
1,592
Reut
75,500,585
4,686,346
Does Python load a directory of parquet files in order while creating a Dataframe?
<p>A large dataframe is sorted using OrderBy in Spark. The output generated is a directory with 200 parquet files containing the sorted data.</p> <p>To combine all parquet into one single parquet file, I'm using python. When the directory is loaded into the dataframe using <code>pandas.read_parquet(&quot;Path_to/Direct...
<python><apache-spark><sorting><pyspark><parquet>
2023-02-19 13:50:14
0
620
TheLastCoder
75,500,307
13,184,183
How to vectorize slicing operations on torch tensors?
<p>I have a bunch of variables expressed by list comprehensions. I want to turn it into <code>torch.tensor</code>, so far I got</p> <pre><code>import torch n = 10 y = torch.rand(n ** 2, requires_grad=True) one_node_per_position = torch.FloatTensor([sum(y[k:k + n]) - 1 for k in range(0, n ** 2, n)]) one_node_per_point =...
<python><torch>
2023-02-19 12:58:08
1
956
Nourless
75,500,303
65,545
pip wxpython gives ModuleNotFoundError: No module named 'attrdict'
<p>Installing wxpython with pip gives the error <code>ModuleNotFoundError: No module named 'attrdict'</code></p> <h2>Details:</h2> <p>py -3.10-64 -m pip install -U wxpython</p> <pre><code>Collecting wxpython Using cached wxPython-4.2.0.tar.gz (71.0 MB) Preparing metadata (setup.py) ... error error: subprocess-exi...
<python><pip><wxpython>
2023-02-19 12:57:36
1
5,146
Bernard Vander Beken
75,499,934
10,499,034
How to populate an 2D array from a list left to right with the diagonal being all zeroes
<p>I have a list:</p> <pre><code>idmatrixlist=[0.61, 0.63, 0.54, 0.82, 0.58, 0.57] </code></pre> <p>I need to populate an array from left to right while maintaining the zeroes on the diagonal so that the resulting array looks like.</p> <p><a href="https://i.sstatic.net/FwOUe.png" rel="nofollow noreferrer"><img src="htt...
<python><arrays><numpy><sorting><numpy-ndarray>
2023-02-19 11:51:16
1
792
Jamie
75,499,884
15,704,286
count number of pages in a pdf file using python's pypdf2 library
<p>what is the exact code to find the total number of pages in a PDF using Py2PDF library? The old method that is <code>.numPages</code> is deprecated</p>
<python><python-3.x><pdf>
2023-02-19 11:42:57
1
842
Mounesh
75,499,602
19,115,554
Pass `special_flags` argument to group.draw in pygame
<p>Is there a way to pass the <code>special_flags</code> argument to <code>Group.draw</code> so that it calls the <code>.blit</code> method with those flags? I've tried just passing it as a keyword argument like this:</p> <pre class="lang-py prettyprint-override"><code>group.draw(surface, special_flags=pygame.BLEND_SOU...
<python><pygame><drawing><pygame-surface><group>
2023-02-19 10:53:36
1
602
MarcellPerger
75,499,365
9,827,719
Python matplotlib dodged bar (series, data and category)
<p>I have series, data and categories that I feed into a function to create a dodged bar using matplotlib.</p> <p>I have managed to created a stacked chart, however I want to create a dodged bar.</p> <p>This is what I have managed to create (stacked bar): <a href="https://i.sstatic.net/58IlU.png" rel="nofollow noreferr...
<python><matplotlib>
2023-02-19 10:11:45
1
1,400
Europa
75,499,340
7,318,120
get position of mouse in python on click or button press
<p>I want to get the <code>x, y</code> position of the mouse (in <code>windows 11</code>) and use this position in the rest of the code.</p> <p>I have tried two different modules but neither seem to work.</p> <ol> <li>pyautogui (for a mouse click or button press)</li> <li>keyboard (for a button press)</li> </ol> <p>So...
<python><keyboard><pyautogui>
2023-02-19 10:06:59
2
6,075
darren
75,499,291
1,593,107
Why Cheerio XML parsing with Crawlee doesn't return text() for *some* keys?
<p>Considering an <code>XML</code> file like <a href="https://news.google.com/rss/search?q=test&amp;hl=fr&amp;gl=FR&amp;ceid=FR:fr" rel="nofollow noreferrer">this one</a> (Google New RSS feed) and <code>item</code> like this:</p> <pre><code>&lt;item&gt; &lt;title&gt;Test Like a Dragon Ishin...&lt;/title&gt; &lt;lin...
<python><javascript><xml><parsing><cheerio>
2023-02-19 09:59:13
2
2,955
charnould
75,499,220
386,861
Writing to sql database with pandas
<p>Confused. Trying to build a scraper of UK news in python.</p> <pre><code>import feedparser import pandas as pd def poll_rss(rss_url): feed = feedparser.parse(rss_url) for entry in feed.entries: print(&quot;Title:&quot;, entry.title) print(&quot;Description:&quot;, entry.description) ...
<python><mysql><sql><pandas><sqlalchemy>
2023-02-19 09:44:31
2
7,882
elksie5000
75,499,144
5,833,865
Grouping and summing cloudwatch log insights query
<p>I have about 10k logs from log insights in the below format (cannot post actual logs due to privacy rules). I am using boto3 to query the logs.</p> <p>Log insights query:</p> <pre><code>filter @message like /ERROR/ </code></pre> <p>Output Logs format:</p> <pre><code> timestamp:ERROR &lt;some details&gt;Apache error....
<python><regex><reporting><amazon-cloudwatchlogs><aws-cloudwatch-log-insights>
2023-02-19 09:27:58
1
770
Devang Sanghani
75,499,068
7,212,686
How to iterate over XML children with same name as current element and avoid current element in iteration?
<h3>I have</h3> <p>A given XML (can't change naming) that have same name for a node and its direct children, here <code>items</code></p> <h3>I want</h3> <p>To iterate on the children only, the <code>items</code> that have a <code>description</code> field</p> <h3>My issue</h3> <p>The parent node of type <code>items</cod...
<python><xml><elementtree>
2023-02-19 09:10:37
1
54,241
azro
75,499,048
6,734,243
how to reference metadata in a pyproject.toml file?
<p>I was previously using setup.py to package my Python libs. As it seems pyproject.toml is the future way of setuptools I decided to migrate before my next releases.</p> <p>In setup.py I was using the following string to define the link to the downloadable tarball:</p> <pre class="lang-py prettyprint-override"><code>s...
<python><setuptools><pyproject.toml>
2023-02-19 09:06:32
0
2,670
Pierrick Rambaud
75,498,943
5,278,594
Calling a recursive function inside a class
<p>I am trying to call a recursive method in order to find path from root to node in a binary tree. There are few solns. for this problem on the internet, but I am trying to use slightly different approach by implementing a method inside a <code>Node</code> class.</p> <p>Here is my logic for the soln.</p> <pre><code> ...
<python><recursion>
2023-02-19 08:44:30
1
1,483
jay
75,498,889
5,281,012
How to generate 10 digit unique-id in python?
<p>I want to generate 10 digit unique-id in python. I have tried below methods but no-one worked</p> <ul> <li>get_random_string(10) -&gt; It generate random string which has probability of collision</li> <li>str(uuid.uuid4())[:10] -&gt; Since I am taking a prefix only, it also has probability of collision</li> <li>sequ...
<python><django><architecture><unique-key>
2023-02-19 08:33:06
2
2,985
SHIVAM JINDAL
75,498,815
1,319,998
What's the chance of a collision in Python's secrets. compare_digest function?
<p>The closest function I can find to a constant time compare in Python's standard library is <a href="https://docs.python.org/3/library/secrets.html#secrets.compare_digest" rel="nofollow noreferrer">secrets.compare_digest</a></p> <p>But it makes me wonder, if in the case of using it to verify a secret token:</p> <ul> ...
<python><security><hash><cryptography>
2023-02-19 08:17:38
1
27,302
Michal Charemza
75,498,789
16,591,526
FastAPI with request queue
<p>I have developed an application that takes an image and does some hard work on the GPU. The problem is that if a request is currently being processed (processing some image on the GPU) and another request for image processing comes to the server, then an error occurs related to the logic of using the GPU. Thus, I ...
<python><request><queue><fastapi><synchronous>
2023-02-19 08:11:39
0
909
padu
75,498,562
8,076,158
attrs - how to validate an instance of a Literal or None
<p>This is what I have. I believe there are two problems here - the Literal and the None.</p> <pre><code>from attrs import frozen, field from attrs.validators import instance_of OK_ARGS = ['a', 'b'] @field class MyClass: my_field: Literal[OK_ARGS] | None = field(validator=instance_of((Literal[OK_ARGS], None))) </...
<python><python-attrs>
2023-02-19 07:17:05
1
1,063
GlaceCelery
75,498,238
19,583,053
Fullstack web-hosting services
<p>I am totally new to web development, and I am trying to create a website. From what I understand, if you create websites on Wix, Squarespace or GoDaddy, then there is a lot of security protection included. They will prevent spamming and things of that nature.</p> <p>I want to create a website that has both a front-e...
<python><web-deployment-project><godaddy-api>
2023-02-19 05:46:03
1
307
graphtheory123
75,498,232
10,033,434
Convert specific columns to list and then create json
<p>I have a spreadsheet like the following: <a href="https://i.sstatic.net/orDPq.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/orDPq.png" alt="enter image description here" /></a></p> <p>As you can see, there are multiple &quot;tags&quot; columns like this: &quot;tags_0&quot;, &quot;tags_1&quot;, &quot...
<python><json><pandas><list>
2023-02-19 05:44:14
3
465
user10033434
75,498,132
14,917,676
Is there any method to find the next possible element following the list's pattern?
<p>I want a method to get the next possible element as a continuation of the list following the pattern on the list.</p> <p>Say, there is a list ls, <code>ls = [1,2,2,3,2,2,1,2,2,3]</code></p> <p>And I want to get the next possible element of the list.. In this case, &quot;2&quot;.</p>
<python><list><probability>
2023-02-19 05:10:24
2
487
whmsft
75,498,096
13,176,726
Django Rest Framework Password Rest Confirm Email not showing Form and returning as none
<p>In my Django Rest Framework, the users request to reset the password and when the email is received and the link is clicked, the url <code>password-reset-confirm/&lt;uidb64&gt;/&lt;token&gt;/</code> as comes up requested but the form is not showing and when I added it as {{ form }} is displayed NONE</p> <p>The passw...
<python><django><django-rest-framework><django-urls><django-rest-auth>
2023-02-19 04:56:57
1
982
A_K
75,498,019
6,791,416
Tensorflow : Trainable variable not getting learnt
<p>I am trying to implement a custom modified ReLU in Tensorflow 1, in which I use two learnable parameters. But the parameters are not getting learnt even after running 1000 training steps, as suggested by printing their values before and after training. I have observed that inside the function, when I execute the com...
<python><tensorflow>
2023-02-19 04:33:28
1
386
psj
75,497,969
10,863,293
How can I resolve the error 'str' object has no attribute 'is_paused' in discord.py?
<blockquote> <p>[2023-02-19 05:14:12] [ERROR ] discord.ext.commands.bot: Ignoring exception in command play Traceback (most recent call last): File &quot;C:\Users\toto\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py&quot;, line 229, in wrapped ret = await coro(*args, **kwargs) F...
<python><discord.py>
2023-02-19 04:22:11
1
898
user10863293
75,497,932
107,083
Why does multiprocessing.Queue.put() seem faster at pickling a numpy array than actual pickle?
<p>It appears that I can call <code>q.put</code> 1000 times in under 2.5ms. How is that possible when just pickling that very same array 1000 times takes over 2 seconds?</p> <pre><code>&gt;&gt;&gt; a = np.random.rand(1024,1024) &gt;&gt;&gt; q = Queue() &gt;&gt;&gt; timeit.timeit(lambda: q.put(a), number=1000) 0.0025581...
<python><numpy><python-multiprocessing>
2023-02-19 04:08:56
1
18,077
chaimp
75,497,593
3,078,473
How to correctly use WebDriverWait & presence_of_element_located() in 2023?
<p>Here is the HTML I am detecting:</p> <pre><code>&lt;div class=&quot;arrowPopup arrowPopup-start&quot;&gt; &lt;div class=&quot;arrowPopupText arrowPopupTextTwoLine arrowPopupText-flashOn&quot; style=&quot;white-space: nowrap;&quot;&gt;type&lt;br&gt;this&lt;/div&gt; &lt;/div&gt; </code></pre> <p>Here is my code</p...
<python><selenium-webdriver><webdriverwait>
2023-02-19 02:15:22
1
419
JackOfAll
75,497,585
257,583
Evaluate ANSI escapes in Python string
<p>Say I have the string <code>'\033[2KResolving dependencies...\033[2KResolving dependencies...'</code></p> <p>In the Python console, I can print this, and it'll only display once</p> <pre><code>Python 3.10.9 (main, Jan 19 2023, 07:59:38) [GCC 9.3.0] on linux Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits...
<python><string><tty><ansi-escape>
2023-02-19 02:12:52
0
18,996
wrongusername
75,497,581
4,372,759
How to embed Python code in a fish script?
<p>I'm trying to convert over a Bash script that includes the following commands:</p> <pre><code>PYCODE=$(cat &lt;&lt; EOF #INSERT_PYTHON_CODE_HERE EOF ) RESPONSE=$(COLUMNS=999 /usr/bin/env python3 -c &quot;$PYCODE&quot; $@) </code></pre> <p>The idea being that a <code>sed</code> find/replace is then used to inject an...
<python><fish>
2023-02-19 02:10:24
1
3,981
flybonzai
75,497,503
8,713,442
How to generate Pyspark dynamic frame name dynamically
<p><a href="https://i.sstatic.net/5s4r0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/5s4r0.png" alt="enter image description here" /></a></p> <p>I have a table which has data as shown in the diagram . I want to create store results in dynamically generated data frame names.</p> <p>For eg here in the b...
<python><apache-spark><pyspark>
2023-02-19 01:44:14
2
464
pbh
75,497,496
3,163,618
Why is 0/1 faster than False/True for this sieve in PyPy?
<p>Similar to <a href="https://stackoverflow.com/questions/57838797/why-use-true-is-slower-than-use-1-in-python3">why use True is slower than use 1 in Python3</a> but I'm using pypy3 and not using the sum function.</p> <pre><code>def sieve_num(n): nums = [0] * n for i in range(2, n): if i * i &gt;= n: b...
<python><performance><pypy>
2023-02-19 01:43:16
1
11,524
qwr
75,497,331
468,807
python, woocommerce: how to add categories with translations?
<p>I need a python snippet to create categories with translation. Python 3.8 with woocommerce package.</p> <p>Wordpress with woocommerce plugin in version 7.3</p> <p>WPML Multilingual CMS: 4.5.14</p> <p>I have this snippet in python:</p> <pre class="lang-py prettyprint-override"><code>from woocommerce import API # cr...
<python><wordpress><woocommerce><wordpress-rest-api><wpml>
2023-02-19 00:50:07
1
799
gerpaick
75,497,304
17,696,880
Remove consecutively repeated substring in a string using regex
<pre class="lang-py prettyprint-override"><code>import re input_text = &quot;((PERS)Yo), ((PERS)Yo) ((PERS)yo) hgasghasghsa ((PERS)Yo) ((PERS)Yo) ((PERS)Yo) ((PERS)yo) jhsjhsdhjsdsdh ((PERS)Yo) jhdjfjhdffdj ((PERS)ella) ((PERS)Ella) ((PERS)ellos) asassaasasasassaassaas ((PERS)yo) ssdsdsd&quot; pattern = re.compi...
<python><python-3.x><regex><replace><regex-group>
2023-02-19 00:40:07
0
875
Matt095
75,497,274
914,641
Symbolic simplification of algebraic expressions composed of complex numbers
<p>I have a question concerning the symbolic simplification of algebraic expressions composed of complex numbers. I have executed the following Python script:</p> <pre><code>from sympy import * expr1 = 3*(2 - 11*I)**Rational(1, 3)*(2 + 11*I)**Rational(2, 3) expr2 = 3*((2 - 11*I)*(2 + 11*I))**Rational(1, 3)*(2 + 11*I)*...
<python><sympy>
2023-02-19 00:27:35
2
832
Klaus Rohe
75,497,265
2,166,823
How to modify which properties show up in the JupyterLab help pop up?
<p>For most classes and functions the help pop-up in JupyterLab shows the signature and the docstring, as in this picture:</p> <p><a href="https://i.sstatic.net/fWy9J.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fWy9J.png" alt="enter image description here" /></a></p> <p>However, for some classes, the...
<python><ipython><jupyter-lab><docstring>
2023-02-19 00:24:40
0
49,714
joelostblom
75,497,033
9,008,162
How to join different dataframe with specific criteria?
<p>In my MySQL database <code>stocks</code>, I have 3 different tables. <strong>I want to join all of those tables to display the EXACT format that I want to see</strong>. Should I join in mysql first, or should I first extract each table as a dataframe and then join with pandas? How should it be done? I don't know the...
<python><pandas><dataframe><join><mysql-python>
2023-02-18 23:27:42
1
775
saga
75,496,854
7,019,069
How can I make a variable a constant in python for pylint?
<p>I'm trying to solve most of the issues I find with pylint, but I'm having troubles with this one:</p> <blockquote> <p>C0103: Variable name &quot;ELEMENT_CLASS&quot; doesn't conform to snake_case naming style (invalid-name)</p> </blockquote> <p>This is an example of the piece of code:</p> <pre class="lang-py prettypr...
<python><pylint>
2023-02-18 22:47:43
0
2,288
nck
75,496,722
4,496,756
Error: Unable to extract uploader id (yt-dlp Library)
<p>I'm running yt-dlp in an iOS App, and 2 days ago they just fixed it because of a YouTube code change: <a href="https://github.com/yt-dlp/yt-dlp/issues/6247" rel="nofollow noreferrer">https://github.com/yt-dlp/yt-dlp/issues/6247</a></p> <p>The problem is that I already updated from the yt-dlp library file from the ne...
<python><ios><yt-dlp>
2023-02-18 22:15:57
3
577
Dani G.
75,496,582
2,607,447
Django - generate a unique suffix to an uploaded file (uuid is cut and django adds another suffix)
<p>I'm going to use DigitalOcean Spaces as a file storage and I want to add suffixes to uploaded filenames for two reasons:</p> <ul> <li>impossible to guess file url with bruteforce</li> <li>ensure it is unique, as I'm not sure if Django can check for filename uniqueness on S3</li> </ul> <p>This is the method:</p> <pre...
<python><django><django-file-upload><django-storage>
2023-02-18 21:45:14
0
18,885
Milano
75,496,537
4,573,162
Python AWS Apprunner Service Failing Health Check
<p>New to Apprunner and trying to get a vanilla Python application to deploy successfully but continuing to fail the TCP Health Checks. The following is some relevant portions of the service and Apprunner console logs:</p> <p>Service Logs:</p> <pre><code>2023-02-18T15:20:20.856-05:00 [Build] Step 5/5 : EXPOSE 80 2023...
<python><tcpserver><amazon-app-runner>
2023-02-18 21:36:11
0
4,628
alphazwest
75,496,527
20,038,123
Keras Transformer - Test Loss Not Changing
<p>I'm trying to create a small transformer model with Keras to model stock prices, based off of <a href="https://keras.io/examples/timeseries/timeseries_transformer_classification/" rel="nofollow noreferrer">this tutorial</a> from the Keras docs. The problem is, my test loss is massive and barely changes between epoch...
<python><tensorflow><machine-learning><keras><transformer-model>
2023-02-18 21:34:32
0
429
Twisted Tea
75,496,045
4,723,405
Displaying all the columns of a dataframe after aggregating on one column in a groupby
<p>I have a dataframe of games played by different number of players for each game. Simplified, it looks like this:</p> <pre><code>GameID Player Score ------ ------ ----- 1 John 10 1 Alice 20 1 Bob 30 2 John 15 2 Alice 25 </code></pre> <p>I'm trying to display the dataframe of the winn...
<python><pandas>
2023-02-18 20:00:35
0
628
Cirrocumulus
75,495,963
5,212,614
How can I find the Optimal Price Point and Group By ID?
<p>I have a dataframe that looks like this.</p> <pre><code>import pandas as pd # intialise data of lists. data = {'ID':[101762, 101762, 101762, 101762, 102842, 102842, 102842, 102842, 108615, 108615, 108615, 108615, 108615, 108615], 'Year':[2019, 2019, 2019, 2019, 2020, 2020, 2020, 2020, 2021, 2021, 2021, 20...
<python><python-3.x><pandas><dataframe><optimization>
2023-02-18 19:44:15
0
20,492
ASH
75,495,814
7,946,143
Understanding binary addition in python using bit manipulation
<p>I am looking at solutions for this <a href="https://leetcode.com/problems/sum-of-two-integers/description/" rel="nofollow noreferrer">question</a>:</p> <blockquote> <p>Given two integers <code>a</code> and <code>b</code>, return the sum of the two integers without using the operators <code>+</code> and <code>-</code...
<python><bit-manipulation>
2023-02-18 19:21:50
2
3,110
Dracula
75,495,800
21,055,247
Error: Unable to extract uploader id - Youtube, Discord.py
<p>I have a very powerful bot in discord (discord.py, PYTHON) and it can play music in voice channels. It gets the music from youtube (youtube_dl). It <strong>worked perfectly before</strong> but now it doesn't want to work with any video. I tried updating youtube_dl but it still doesn't work I searched everywhere but ...
<python><ffmpeg><discord><youtube-dl>
2023-02-18 19:19:23
9
979
nikita goncharov
75,495,715
14,088,584
TFIDFVectorizer making concatenated word tokens
<p>I am using the <a href="https://ir.dcs.gla.ac.uk/resources/test_collections/cran/" rel="nofollow noreferrer">Cranfield Dataset</a> to make an Indexer and Query Processor. For that purpose I am using TFIDFVectorizer to tokenize the data. But after using TFIDFVectorizer when I check the vocabulary,there were lot of to...
<python><scikit-learn><nlp><tfidfvectorizer>
2023-02-18 19:03:13
2
422
SHIVANSHU SAHOO
75,495,667
16,363,897
Reference dataframes using indices stored in another dataframe
<p>I'm trying to reference data from source dataframes, using indices stored in another dataframe.</p> <p>For example, let's say we have a &quot;shifts&quot; dataframe with the names of the people on duty on each date (some values can be NaN):</p> <pre><code> a b c 2023-01-01 Sam Max NaN 2023-01-0...
<python><pandas><dataframe>
2023-02-18 18:55:18
2
842
younggotti
75,495,451
5,378,816
How to combine two "mypy: disable-error-code = ERR" comments?
<p>I put these on the top of a module:</p> <pre><code># mypy: disable-error-code=misc # mypy: disable-error-code=attr-defined </code></pre> <p>but only the last line is honoured, the first one is ignored. The same with reversed order or with three lines. In each case all lines except the last one are ignored. I was als...
<python><mypy><python-typing>
2023-02-18 18:22:47
1
17,998
VPfB
75,495,329
1,377,912
How to terminate FFMPEG running from Python
<p>If I send SIGTERM to FFMPEG it finishes with non-zero status. I found a solution with &quot;q&quot; to the STDIN but it doesn't work in my case.</p> <p>I try to do it this way: I launch FFMPEG from Python like this:</p> <pre class="lang-py prettyprint-override"><code>stop_file_fd, _ = tempfile.mkstemp() with os.fdop...
<python><ffmpeg>
2023-02-18 18:01:24
0
1,409
andre487
75,495,278
578,749
How to prevent VSCode from reordering python imports across statements?
<p>This is the <a href="https://pygobject.readthedocs.io/en/latest/" rel="noreferrer">correct way</a> to import Gtk3 into python:</p> <pre class="lang-py prettyprint-override"><code>import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk, GObject </code></pre> <p>When I save such code in VSCode wi...
<python><visual-studio-code><code-formatting>
2023-02-18 17:52:21
3
13,621
lvella
75,495,212
1,273,987
Type hinting numpy arrays and batches
<p>I'm trying to create a few array types for a scientific python project. So far, I have created generic types for 1D, 2D and ND numpy arrays:</p> <pre class="lang-py prettyprint-override"><code>from typing import Any, Generic, Protocol, Tuple, TypeVar import numpy as np from numpy.typing import _DType, _GenericAlias...
<python><numpy><mypy><python-typing>
2023-02-18 17:42:51
1
2,105
Ziofil
75,495,158
544,884
Calculating Expected Value With Matrix Values
<p>I have the following input data</p> <pre><code>class_p = [0.0234375, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1748046875, 0.0439453125, 0.0, 0.35302734375, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3828125] league_p = [0.4765625, 0.0, 0.00634765625, 0.4658203125, 0.0, 0.0, 0.046875, 0.0, 0.0, 0.0029296875, 0.0, 0.0, 0....
<python><numpy><statistics><matrix-multiplication>
2023-02-18 17:35:50
2
1,982
Adam
75,495,108
16,363,897
Fast way to get index of non-blank values in row/column
<p>Let's say we have the following pandas dataframe:</p> <pre><code>df = pd.DataFrame({'a': {0: 3.0, 1: 2.0, 2: None}, 'b': {0: 10.0, 1: None, 2: 8.0}, 'c': {0: 4.0, 1: 2.0, 2: 6.0}}) a b c 0 3.0 10.0 4.0 1 2.0 NaN 2.0 2 NaN 8.0 6.0 </code></pre> <p>I need to get a dataframe with, for each row, ...
<python><pandas><dataframe><numpy>
2023-02-18 17:28:45
1
842
younggotti
75,494,833
13,874,745
Why are the weights not updating when splitting the model into two `class` in pytorch and torch-geometric?
<p>I tried two different ways to build my model:</p> <ul> <li>First approach: split the model into two <code>class</code>, one is <code>MainModel()</code> and the other is <code>GinEncoder()</code>, and when I call the <code>MainModel()</code>, it would also call <code>GinEncoder()</code> too.</li> <li>Second approach:...
<python><pytorch><neural-network><pytorch-geometric><graph-neural-network>
2023-02-18 16:47:41
1
451
theabc50111
75,494,820
491,894
How do I create an entrypoint in a custom location and activate its virtual environment when executed?
<p>I've searched, but either I'm phrasing the question wrong, or it's an anti-pattern.</p> <p>While I'm not new to python, I've only ever hacked on existing packages.</p> <p>I'm working on a package that will only be run from wherever its repository has been cloned. I can use <code>pip install -e .</code> during develo...
<python><virtualenv>
2023-02-18 16:44:41
0
1,304
harleypig
75,494,698
4,560,509
Celery Module Tasks are Cached so edits in dev environment do not apply
<p>I have a problem which makes local development with Celery very difficult.</p> <p>If I edit my local files and restart docker containers none of the CODE changes are applied. Not talking about task result caching here... just the actual function execution.</p> <p>I have to prune everything for them to be applied. Do...
<python><docker><celery><supervisord>
2023-02-18 16:22:42
0
2,897
Michael Paccione
75,494,645
11,380,409
Python wildcard search
<p>I have a Lambda python function that I inherited which searches and reports on installed packages on EC2 instances. It pulls this information from SSM Inventory where the results are output to an S3 bucket. All of the installed packages have specific names until now. Now we need to report on Palo Alto Cortex XDR. Th...
<python><python-3.x><aws-lambda>
2023-02-18 16:15:27
2
625
TIM02144
75,494,626
4,402,572
Comment / documentation as metadata
<p>If I type-annotate my code properly, and use something like Pylance in my IDE, when I hover over a method or function I get helpful information about that code's 'signature': the variables it expects, their types, and what I can expect from that code in terms of a response. All that is great, and I have come to rely...
<python><metadata>
2023-02-18 16:11:39
0
1,264
Jeff Wright
75,494,613
16,723,327
override a value in async function
<p>I have this function in <code>my_module.py</code>:</p> <pre class="lang-py prettyprint-override"><code>async def foo(): a = 10 b = 10 return a+b </code></pre> <p>I am trying to override the value of <code>a</code> in <code>unittesting</code> using <code>aiohttp.test_utils.AioHTTPTestCase</code> and <code...
<python><unit-testing><mocking><python-asyncio>
2023-02-18 16:08:57
0
333
alibustami
75,494,440
15,637,940
import python module with one file inside
<p>I packaged one file:</p> <pre><code>proxy_master ├── __init__.py └── proxy_master.py </code></pre> <p>After installing it, i need to type:</p> <pre><code>from proxy_master import proxy_master </code></pre> <p>I want to know is it even possible just type?</p> <pre><code>import proxy_master </code></pre> <p>Thanks! Ad...
<python><python-3.x><python-packaging>
2023-02-18 15:41:45
0
412
555Russich
75,494,363
2,991,243
Substitute a part of string (ignoring special characters)
<p>Suppose that I have a list of strings, and I want to substitute different parts of it by <code>re.sub</code>. My problem is that sometimes this substitution contains special characters inside so this function can't properly match the structure. One example:</p> <pre><code>import re txt = 'May enbd company Ltd (Pty)...
<python><string><replace>
2023-02-18 15:29:07
1
3,823
Eghbal
75,494,208
2,485,063
Efficient way to drop subset of columns using a threshold of row numbers
<p>I have a 10 million row dataframe like this</p> <pre><code>&gt;&gt;&gt; df.info(show_counts=True) # Column Non-Null Count Dtype --- ------ -------------- ----- 0 date 10000000 non-null datetime64[ns] 1 cust1 6000647 non-null float64 2 cust2 6001585 non-null ...
<python><pandas><dataframe>
2023-02-18 15:03:19
1
732
szimon
75,494,190
12,439,119
VSCode IntelliSense thinks a Python 'function()' class exists
<p>VSCode / IntelliSense is completing a Python class called <code>function()</code> that does not appear to exist.</p> <p>For example, this appears to be valid code:</p> <pre><code>def foo(value): return function(value) foo(0) </code></pre> <p>But <code>function</code> is not defined in this scope, so running thi...
<python><visual-studio-code><intellisense><pylance>
2023-02-18 14:59:35
1
4,303
Alexander L. Hayes
75,494,055
1,668,622
Why is reading a file asynchronously (with aiofile) so much (15x) slower than its synchronous equivalent?
<p>I'm experimenting mit named pipes and <code>async</code> approaches and was a bit surprised, how slow reading the file I've created seems to be.</p> <p>And as <a href="https://stackoverflow.com/questions/68957147/aiofiles-take-longer-than-normal-file-operation">this question</a> suggests, this effect is not limited ...
<python><asynchronous><python-asyncio><named-pipes><python-aiofiles>
2023-02-18 14:37:46
1
9,958
frans
75,493,970
19,369,310
New column based on last time row value equals some numbers in Pandas dataframe
<p>I have a dataframe sorted in descending order date that records the Rank of students in class and the predicted score.</p> <pre><code>Date Student_ID Rank Predicted_Score 4/7/2021 33 2 87 13/6/2021 33 4 88 31/3/2021 33 7 88 28/2/2021 33 2 ...
<python><python-3.x><pandas><dataframe><group-by>
2023-02-18 14:23:09
3
449
Apook
75,493,853
5,070,460
Tensorflow: Shape of 3D tensor (of an image) in Filter has None
<p>I am following <a href="https://www.tensorflow.org/guide/data#preprocessing_data" rel="nofollow noreferrer">this tutorial</a> on <a href="https://www.tensorflow.org/" rel="nofollow noreferrer">tensorflow.org</a>.</p> <p>I have folder <em>images</em> with two folders <em>cat</em> and <em>dog</em> in it. Following abo...
<python><numpy><machine-learning><deep-learning><tensorflow2.0>
2023-02-18 14:03:38
1
4,502
Dheemanth Bhat
75,493,772
8,127,672
Python Error : Importing library : ModuleNotFoundError: No module named 'InitProject'
<p>I am setting up a python project using RobotFramework and it is throwing No module named error even if I have added a Library entry in init.resource.</p> <p>Also, I created an empty <strong>init</strong>.py in the folder in which the file exists so that the python file can be located.</p> <p>My project structure is ...
<python><python-3.x><robotframework>
2023-02-18 13:48:55
1
534
JavaMan
75,493,729
552,916
Create python class with type annotations programatically
<p>I want to be able to create a python class like the following programmatically:</p> <pre class="lang-py prettyprint-override"><code>class Foo(BaseModel): bar: str = &quot;baz&quot; </code></pre> <p>The following almost works:</p> <pre class="lang-py prettyprint-override"><code>Foo = type(&quot;Foo&quot;, (BaseMo...
<python><metaprogramming><python-typing>
2023-02-18 13:41:38
1
3,097
Nat
75,493,512
5,618,339
Updated Macbook to Ventura - now getting 'command not found: Flutter'
<p>Oddly enough I'm able to run my flutter applications, but I'd like to upgrade. However since I've updated to MacOS Ventura Flutter can't be found anymore...</p> <p>output of <code>echo $PATH</code>:</p> <pre><code>/Users/me/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/...
<python><flutter><macos><dart><macos-ventura>
2023-02-18 13:03:06
1
972
King
75,493,434
11,665,178
How can i delete specific sub-directories google cloud storage python SDK
<p>I have the following code :</p> <pre><code>storage_client = storage.Client() bucket = storage.Bucket(storage_client, name=&quot;mybucket&quot;) blobs = storage_client.list_blobs(bucket_or_name=bucket, prefix=&quot;content/&quot;) print('Blobs:') for blob in blobs: print(blob.name) </code></pre> <p>My storage hier...
<python><google-cloud-storage>
2023-02-18 12:45:05
0
2,975
Tom3652