Questions tagged [functools]

functools is a module for the Python language which provides support for working with higher-order functions: functions that act on or return other functions

functools is a module for the Python language which provides support for working with higher-order functions: functions that act on or return other functions.

The official documentation can be found here: here

382 questions
0
votes
0 answers

Python Pool.map deepcopy wearing off

I'm trying to parallelize a task that involves a function which takes a custom object as a parameter. During the body of the function, said object gets manipulated, so I need a deepcopy of the original object at the start of each trial. When I use…
Philip Massey
  • 1,401
  • 3
  • 14
  • 24
0
votes
1 answer

pyqt timer does not return a value or an error

I am trying to use a timer with pyqt. The code is below, but it does not print anything and I do not get an error. Does anyone know what is wrong? Thanks import functools from PyQt4.QtCore import QTimer def onTimer(initParams): print…
user-2147482637
  • 2,115
  • 8
  • 35
  • 56
0
votes
2 answers

Python + Kivy: Clock doesn't work with partial(keywords)

def _procedural_reloading(self,gen=[],*args): if len(gen): gen.pop().reload() Clock.schedule_interval(functools.partial( self._procedural_reloading,gen=gen),.5) In above code, _procedural_reloading() is a method of…
Dusk
  • 1,729
  • 10
  • 17
-1
votes
1 answer

Python/Cython return Chained function

I am trying to return a chained function In the below I would like to give it a list of values that map to functions. For example from the code below get_function([0,1,2]) returns the function fun(x , [a,b,c]) = a*b/x**c =…
tjaqu787
  • 295
  • 2
  • 16
-1
votes
2 answers

Django render_to_string not working inside update of djangoRestFramework serializer

I try to use the render_to_string method of django to generate a html. This function is actually called inside a signal which is sent inside the update method of a djangoRestFramework serializer. By doing that I got the error: AttributeError:…
-1
votes
2 answers

python save computation power with repeatedly called functions

Let's say I have the following function, which takes x and y. def calculate(x, y): return sin(x)**3 + y In my use case, I call the function very often but mainly change y and x only once in a while. Since my function is computationally intense…
Jonathanthesailor
  • 159
  • 1
  • 1
  • 8
-1
votes
1 answer

functools.lru_cache difference between two object with same hash

After reading the code of https://github.com/python/cpython/blob/master/Lib/functools.py I thought that lru_cache use hash to build a key from the function arguments, so if I two object have the same hash they should be the same for lru_cache. If…
santos82h
  • 452
  • 5
  • 15
-1
votes
2 answers

Joining multiple(more than 2) Pyspark Dataframes on multiple conditions dynamically

i have 20 of data frames and i want to combine it into single one having all the columns. my data frames is looking like, course_id course_name 5011 Web Designing 5012 Web Development 5013 Programming subject_id subject_name …
user9946307
-1
votes
1 answer

Clear functool's lru_cache once datastructure is written

I have a problem understanding how to apply the @lru_cache decorator properly. I have a dictionary attribute that computes values by calling another function on a list of values. I want to cache any access to attribute. Is there any way to declare…
-1
votes
1 answer

use winsound in a tkinter program from within a dictionary in python

I have edited the code a bit would this new code work and if not what should i do to get it to work import winsound import tkinter as tk from functools import partial # a quick way to make a callback function import…
-1
votes
1 answer

Parsing: functional inheritance for class methods in Python

For some context I am trying to write a parser for a search language. At the moment I have a bunch of class methods for accepting a token given that it satisfies a certain criterion, however it seems that their general structure/format can be…
James Harrison
  • 323
  • 4
  • 12
-1
votes
2 answers

Python3 functools lru_cache RuntimeError

from functool import lru_cache @lru_cache def fibonacci(n): """0, 1, 1, 2, 3, 5, 8, 13, 21, 34 """ if n == 0: yield 0 elif n == 1: yield 1 else: yield next(fibonacci(n - 1)) + next(fibonacci(n - 2)) If…
Sea Wolf
  • 81
  • 1
  • 6
-1
votes
2 answers

How to write python program to Combine second letters of the two strings using reduce()

Combine second letters of the two strings in the following using reduce(). string1 = [‘Hello’,’Bye’] output should be ‘ey’
Cprk Praveen
  • 129
  • 1
  • 10
-1
votes
3 answers

Preserve exact function signature in chain of decorators using functools.wraps

In Python 3.4+, functools.wraps preserves the signature of the function it wraps. Unfortunately, if you create decorators that are meant to be stacked on top of each other, the second (or later) decorator in the sequence will be seeing the generic…
ely
  • 74,674
  • 34
  • 147
  • 228
-1
votes
2 answers

An error when redirecting a list of objects to reduce function with lambda

Here is the simple code. class C: def __init__(self): self.l = [1,2,3] a = C() b = C() c = C() reduce(lambda x,y: x.l + y.l, [a,b,c]) Traceback (most recent call last): File "", line 1, in File "", line 1, in…
user8709546
1 2 3
25
26