Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

learn more… | top users | synonyms

1
vote
0answers
11 views

Meta-class to allow inspection of all __slots__of a class in Python

If classes provide __slots__ and at the same time inherit from another class also providing __slots__, there is no ...
1
vote
0answers
19 views

Slow data processing problem (looping over an array with context to prior elements)

I have a binary file with alternating uint8 and uint64 data stamps. I read those in by using the following line: ...
0
votes
0answers
15 views

Implementation options for alternate behaviour of methods [on hold]

I am working on an API that is mostly intended to be used interactively/little scripts. There are some classes with methods that could act slightly differently depending on the intention of the user, ...
1
vote
0answers
29 views

Python XML - extracting information

I am very new to Python, and also this is my first time trying to parse XML. I am interested in information within str elements. I can identify that information ...
-4
votes
0answers
16 views

Please help me by solving the problems [on hold]

Perform the following Create 3 text files with names d1.txt, d2.txt, and d3.txt, having no more than two pages of text Write a program to perform the following Tokenize the files and save the ...
-1
votes
1answer
34 views

Local variable vs. object attribute access when firing callbacks for added and removed entities

I just realized that I have a habit of optimizing attribute access. Here's a code example: ...
2
votes
0answers
19 views

Python CSV command line tool to import CSV into MySQL

I've written my first Python program longer than 15 rows and, of course, it looks terrible. I'd be very glad to receive comments and suggestion about how to implement a similar tool correctly. ...
4
votes
2answers
65 views

Creating lists of events (pitches, velocities, delta-times, durations) from a MIDI track

I am trying to understand good design patterns in Python and I cannot think of a way to break this huge function into smaller parts without making the code cluttered, overly complex or plain ugly. I ...
0
votes
1answer
31 views

Add user to a database and perform relevant checks

Below is a function that adds a new user to the database using their email and password. I am using Flask and SQLAlchemy. ...
3
votes
2answers
110 views

FreeDNS update script

I tried to write a script which takes a list of URLs, checks if their FreeDNS record points to the current IP, and updates the record if not. Intended use is that the script will be run periodically ...
4
votes
3answers
72 views

Pythonic implementation of Conway's Game of Life

I've just finished with my python implementation of Conway's Game of Life. Can I get some opinions on it? ...
-3
votes
0answers
21 views
8
votes
3answers
918 views

Transform snake_case to camelCase

I want to convert db columns such as is_deleted or product_code which consist of xx_xx to ...
5
votes
2answers
126 views

Get external IP via email

I wrote a script for my Raspberry Pi that keeps checking my external IP. If it changes, the Raspberry Pi will send me the new IP via email. Any suggestions for improvements? ...
0
votes
2answers
45 views

Transferring a CSV file to a database while merging some columns

Say I am given a csv file that I want to import into an sqlite3 database. The first two columns in the csv file contain unique, important information while the rest of the columns are really a list ...
3
votes
3answers
41 views

Computation of inter-grid distance array for 2D lattice

I have a 2D lattice with U × U number of grids. My goal is to create an array – of shape U^2 × U^2 – where each entry denotes the least-distance between each grid and any other grid. Currently, for ...
-1
votes
0answers
7 views
6
votes
2answers
140 views

Extracting keywords from 3 billion CSV records

I am processing around 3 billion records using this piece of code. It's pretty slow; it would be really helpful if you could suggest better ways to do this. Update #1 Based on Nizam Mohammed ...
-1
votes
0answers
27 views

Error in python script for Scatter plot [on hold]

I am trying to create a graph with this script, but I get an error if someone sees the error, please I ask you to help me find it, because I do not know python. ...
1
vote
2answers
35 views

Counting length-2 substrings that are common to two strings at the same offset — Python

I solved the CodingBat task: Given 2 strings, a and b, return the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", ...
2
votes
1answer
36 views

Optimization for calculating statistics

I have collected a large amount of data about the train network in my country. Now, I am writing some code that calculates the average amount of delay on the entire train network, for each day, in a ...
4
votes
0answers
29 views

Generic Pickle-Aware Super-Class for Mixing Classes with and without __slots__ in Python

I want a generic super-class that I can easily subclass - and if desired add slots to my class - without having to worry about any pickle issues (with the lowest protocol). Is this in general a good ...
3
votes
1answer
47 views

Program for compacting other given code

I've just finished a small function that will reduce the size of code as much as possible without breaking anything. Obviously it makes everything a bit unreadable so it's not really for cleaning the ...
2
votes
1answer
41 views

Vitaly & Pie Programming challenge

I've been trying to solve this problem on Codeforces: Challenge description: After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. ...
3
votes
1answer
45 views

Efficient Ring Buffer (FIFO)

I need to implement a Ring Buffer/FIFO for data coming from a TCP socket. It must support the following operations: Append a the recv()'ed chunk of bytes. Allow me to peek at the beginning of the ...
8
votes
1answer
51 views

Ring datatype in Python

I wanted to write something that would be useful for the indices of a grid where if one walked off the edge of the grid they would re enter on the opposite side. This could in theory help with ...
3
votes
1answer
53 views

Rectangularize a list-of-lists structure

Considering I have an iterated "lists of lists ..." (up to 4 dimensions), now I wish to make the full list "rectangular" (or well each dimension equal in size). For a 4 dimensional case I've written ...
-3
votes
0answers
23 views

Runtime inheritance in Python [closed]

I would like to support inheritance at runtime. For example, accepting user input to tell it which class to inherit from. Here's what I've done, it works, but I'm unsure if it's the right solution: ...
-3
votes
0answers
26 views

Parsing apache log files [closed]

I am quite new with Python. My goal is to extract all information from the apache log file. The file has the format like: ...
1
vote
1answer
36 views

Conversion functions between binary, hexadecimal and ASCII

I've written a small suite to easily convert my data between binary, hexadecimal and ASCII: ...
0
votes
0answers
22 views

Can I condense these values with a loop? [migrated]

I have a set of values that get modified like so: ...
2
votes
3answers
60 views

Torrent File Remover

This script to locate torrent files in a given directory, and if they have been seeding for 2 weeks, delete the files. I realize the comments are overboard. The reason for that is it's being shared ...
-5
votes
1answer
25 views

Identifying the final rule from result [closed]

I am getting dictionary with different rules result, starting from two to five. rule two has lowest priority and rule five highest. For processed_output like: ...
1
vote
1answer
55 views

Python script that launches a process that it needs to clean up after and kill on receiving SIGTERM/SIGINT

I'm using a Python script to run a particular program that occasionally may need to be terminated (by receiving a SIGINT or SIGTERM) in which case a clean up process needs to be invoked (before ...
-2
votes
0answers
29 views

Strip non [A-z|0-9|.|_] from string? [closed]

Input ^#%foo.bar#%#%canhaz%# Output foo.bar#%#%canhaz Function (attempts 0-1) ...
7
votes
1answer
73 views

Calculating 24 from 4 numbers (math Poker game)

This is a game of math in Poker. Two people each have a pile of cards. They then each place 2 cards on the table at the same time. Every card is treated as a number. The players need to find a way to ...
4
votes
1answer
138 views

Finding whether there exists a pair of numbers in a set having a given product

Devise an algorithm that will operate on a number x and a set of n distinct numbers such that in \$O(n \lg n)\$ time, the algorithm indicates whether or not there are two numbers in the set ...
-2
votes
0answers
36 views

Python SOS! program looping only once [closed]

So I'm writing this program that receives the input from mysql it compiles correctly but just once. Python can't do {} while could anybody help because even two while true loops did not do the trick ...
-2
votes
0answers
32 views

The Time Complexity for sort_it

What is the time complexity for the code below? My answer is n*size_of_list ...
2
votes
1answer
48 views

Implementation of quicksort algorithm

I'm currently doing an algorithms course and implemented this version of the quicksort algorithm. I would like to know if it is an efficient implementation. I've seen a couple others where there is a ...
6
votes
5answers
461 views

Simple technology quiz

This is my first program that uses more than just boring ol' if/else statements - I made a whole 246 line game that's still a ...
3
votes
2answers
84 views

Cook and Felderman analysis to perform data reduction on heated surfaces

This is a "pain", but I wonder if I can get any real speedup with the follow Python script - it is taking well over 10 minutes to calculate the way it is written now. (And that's only when feeding ...
1
vote
2answers
50 views

Binning and calculating a huge range of data

I have a code that I'm fairly certain does what I want. Bear with me as I explain what I'm doing: Imagine that there is 10 houses, where there can be one to an infinite number of persons. Each of ...
1
vote
2answers
36 views

Lazy properties for the angle and length of a line segment

The code below shows the pattern I use to manage properties in my classes when I have the following requirements: Some properties are slow to calculate and are rarely used, so I want them to be lazy ...
2
votes
1answer
55 views

Lattice lotka-volterra

Can anyone comment on the efficiency of my code? I am new with Python using NumPy/SciPy and I am trying to program a lattice biological model where a certain (one and only one) species (represented by ...
0
votes
1answer
31 views

Simple Batch Templating Utility in Python

I would like to present for review my (much) revised batch templating utility which had it's humble beginnings here in a previous post. As I mentioned there, this program is my entry into python ...
3
votes
1answer
45 views

Find the highest number satisfying a condition in an infinite range

I wrote the below function for doing a variation of bisection search that I came up with. This can be useful when the higher bound is not known. It assumes that as number increases the result of the ...
1
vote
0answers
27 views

Creating a Python namedtuple class that forces some of its fields to be floats

I've got a use case for namedtuple that requires some of the fields to be floats. I could require the code that's constructing the namedtuple to supply floats, but I'd like for the namedtuple class to ...
2
votes
1answer
29 views

Scale object based on distance between 2 vertices

I made this script so that I can scale objects for 3D printing from Maya. I had fun making it and I'm sure it could be cleaned up or improved. If it can be cleaned up please let me know. ...
0
votes
1answer
33 views

Loop an array of dictionary with keys containg sets; comparing each {key, value} pair; and combining dictionaries

I'm trying to optimize a nested for loops that compares an element in the array with the rest of the element in the array. There's two part, the first part is for example, an Array has 3 elements, ...