Python

Map with two functions

I have a list of items, coming from one object which are of type A, and a library that operates on object of type B. I would like to convert A to B, and later call B’s function in a pythonic way. What I have come up with so far: def convert_A_to_B(A): return B(A.something, A.something_else) def doStuff(a_list): converted_to_b = list(map(convert_A_to_B,…
Read more

average speed checks for cars

I have a school assessment on average speed checks for cars. so when the car passes one speed camera it starts a timer and when it passes the next speed camera at a given distance it stops the timer. then it takes the speed it took for the car to drive the given distance and then divide it by the…
Read more

How do I get ALL Combination of Sequential elements of list Pythonically?

Given an Array say x = [‘A’,’I’,’R’] I would want output as an [[‘A’,’I’,’R’],[‘A’,’I’],[‘I’,’R’],[‘A’],[‘I’],[‘R’]] What I don’t want as output is : [[‘A’,’I’,’R’],[‘A’,’I’],[‘I’,’R’],[‘A’,’R’],[‘A’],[‘I’],[‘R’]] # extra [‘A’,’R’] which is not in sequence . Below is the code which gives the output I don’t want: letter_list = [a for a in str] all_word = [] for i in xrange(0,len(letter_list)): all_word = all_word…
Read more

Any big projects using Pypy?

I have a very large heterogeneous Python codebase that uses Django as the front-end. This codebase is deployed alongside several servers that are beginning to show the strain and we’re looking for ways to speed things up while we re-architect the codebase, and to keep the new code running fast. We’re currently looking at Pypy but it seems a bit…
Read more

How to attach to running python script via PTVS at beginning of execution

I want to attach to a python script that is called by another program (.exe). I am developing the python script. Right now, I am using (Python 2.7) raw_input(“Press Enter to continue and/or attach debugger…”) to make the script wait and attach the debugger. Is there some convenient way, like C# Debugger.Break() (see http://stackoverflow.com/a/105599/586754 ) to directly prompt me to…
Read more

TCP devices do not end connection and a single device ends up with many inactive connections

I have a strange problems as follows. I am preparing a Device Client with Python 2.7. There are Tracking devices (amount ~1100 active and running) which sends signals to server. They have periodic signal that is sent once every hour. (Signal sent frequency is changing according to situation but they must sent at least one GPS Position Data signal once…
Read more

Django ValidationError in view?! not form

i have problem with validating Django Form because i can’t save model before cleaning of course. I have reservation model: class Reservation(models.Model): from = models.DateTimeField() to = models.DateTimeField() total_price = models.DecimalField() def calculate_price(self): return some_magic(self.from, self.to) and form: class ReservationForm(forms.ModelForm): amount = forms.DecimalField() class Meta: model = Reservation def clean(self): ???? I want to verify in clean method if amount…
Read more

python huge file reading increasing the key value

I have an input file word.txt as follows 8 0:38 1:13 2:9 3:13 4:11 5:9 6:4 7:13 8:4 9:3 10:6 9 1:44 44:23 55:10 3:13 4:11 5:9 6:4 7:13 8:4 9:3 10:6 10 3:13 4:11 5:9 6:4 7:13 8:4 9:3 10:6 ……………………………….. ……………………………….. I want to increase the each key value by 1 and split the input file in half…
Read more