Questions tagged [python-2.x]

Python 2 is the predecessor of Python 3 and its last version, Python 2.7 was formally released on July 3, 2010. Use this tag along with the main python tag to denote programs that are meant to be run on a Python 2 interpreter only. Do not mix this tag with the python-3.x tag.

Filter by
Sorted by
Tagged with
1
vote
1answer
26 views

Finding data relations of json paths in python

I am kind of new to python, so I am pretty sure there are way better elegant ways to do this. I have made a function that is able to compare two list of possible json object paths, and detect what ...
2
votes
1answer
67 views

Linux bonding status check

I have created the below code which works for me, but I feel there might be a better way to accomplish this in a new Pythonic way or better Python syntactic way. Code snippet: ...
1
vote
2answers
70 views

Better pythonic way to pass condition to multiple functions [closed]

I have the following scenario where most of my functions require to return different things based on a condition. ...
-1
votes
1answer
99 views

Foo Bar - Power Hungry challenge test case failing on unknown edge cases [closed]

The challenge is to find the maximum product of a subset of a given array. Here's the problem: Write a function solution(xs) that takes a list of integers representing the power output levels of ...
3
votes
1answer
60 views

Estimation of min_samples for DBSCAN

I'm attempting to speed up some python code that is supposed to automatically pick the minimum samples argument in DBSCAN. Currently the execution time grows exponentially as the number of training ...
7
votes
2answers
118 views

Pythonic attempt at conversion of length

I'm trying to learn Python, so I started with a program to convert length units, mixing imperial and metric. First I wrote a bunch of small simple functions, but then I wanted to solve the issue of ...
2
votes
2answers
102 views

Python - Hexadecimal to Decimal conversions

I have written a python 2 program for a school project to convert from hexadecimal to decimal without using built-in functions and vice versa in python. I would like to know how I can make my code ...
3
votes
0answers
62 views

Store special deals, like 3 for 2

I have to apply two deals on the cart. Buy 3 (equal) items and pay for 2 Buy 3 (in a set of items) and the cheapest is free Items in cart: ...
1
vote
0answers
49 views

Reading attachment data from a PostgreSQL table with python

I have developed this script to find the counts of attachment records stored in a table in PostgreSQL for different other tables. I check if the res_id field of <...
1
vote
1answer
190 views

Reading employee data from a PostgreSQL database

I have developed this script to read employee_language table records of a PostgreSQL database using Python 2 (due to some OS limitation). I want to find duplicate ...
2
votes
1answer
33 views

Reload polyline midpoints into parallel tables

I have an Oracle GIS database that has spatial tables. The records in the spatial tables have a geometry column that contains polylines. I've written a Python 2.7.16 script that calculates the ...
5
votes
0answers
48 views

Python - Displaying messages in ArcPy/IDLE

I have created a wrapper for displaying messages with ArcPy and IDLE (as that is all I have available to myself due to certain circumstances) as I frequently use both to test and develop new tools. ...
1
vote
1answer
25 views

Executing Scipy Tensor Product [closed]

Can anyone advise on how to use the SymPy TensorProduct function without having to explicitly indicate the full sequence of objects to take the product of. Below (for the simple case N=3) you can see ...
2
votes
1answer
55 views

Weaving multiple lists into one

I have this code to weave the split_input ['5,4 4,5 8,7', '6,3 3,2 9,6 4,3', '7,6', '9,8', '5,5 7,8 6,5 6,4'] together. However I feel like this can be done more ...
0
votes
1answer
58 views

Pyg Latin Translator [closed]

I have a code for a short Python 2 Pig Latin translator. Is it a good code, or should it be revised? ...
5
votes
0answers
67 views

Python Project Template

What's up smart people. A little backstory for context: I'm a completely self taught dev, and the only person ever looking at my code for the past 6 years is myself. I realize that's not the best idea ...
2
votes
1answer
182 views

Simulate Tic-Tac-Toe game in Python

Simulate a tic-tac-toe game Requirements A player is picked at random as a first player. The two players plays tic tac toe game. The game ends when the board is full or either one of the player ...
6
votes
1answer
153 views

Universal string conversion

Below there is a function eating all strings and convert it to Unicode. It works fine. But is it the best way to do so? Is there maybe already an existing function for it? The reason was a German ...
2
votes
1answer
42 views

An imitation of reading a C Struct from binary file in python 2.7

Preliminary I need to read a binary file constructed by writing a Struct to it with Python. So I decided to write a simple wrapper using ...
1
vote
0answers
72 views

AWS plugin to create a CloudFormation stack if it doesn't exist

The following Python class is what I am trying to refactor in the case where I have to add validation of the existence of an AWS cloudformation stack before creating it in the method create_cfn_stack :...
1
vote
3answers
36 views

`set_includes` (string subsequence-containment) in Python 2

I've implemented C++'s std::includes algorithm in Python, so that I can use it to efficiently implement a Scrabble "can I make this word" function: ...
4
votes
2answers
170 views

Print a pattern of text based on a line from an Excel file

I started to learn Python not long ago to automate certain tasks I work on. I want to optimize a script I wrote that takes a line in an Excel file and prints a pattern of text based on this line's ...
1
vote
1answer
79 views

Django view of reward points that heavily filters and sorts (many) database results

My page (even when it has no data) takes 10+ seconds to load. That's just too long, considering when you finally get to it there's no data. When it has data, it takes even longer. Here is my view, ...
5
votes
2answers
99 views

Program to delete directories that do not contain a file

I'm an intern and have an ETL project I'm doing in python. Part of it is to make sure after I move files I delete empty directories. I wrote this code to clean up directories that are empty and in ...
1
vote
1answer
804 views
6
votes
2answers
271 views

Guttag's Finger Exercises: Enter 10 integers, find largest odd integer and print result

I'm making my way through the Intro to Computation and Programming test by John Guttag and he gives these small exercises to practice gearing up into computational thinking. As of Ch.2, we've covered ...
3
votes
0answers
87 views

Animation of an incremental rotary encoder

While reworking my teaching materials for an exercise of an introductory course on mobile robotics, I recently created a animation/simulation of an incremental rotary encoder, e.g. often used for ...
2
votes
0answers
73 views

Extract cell values from multiband rasters

I have the following function and code snippet to extract cell values for multiple years, format it, and save to a list. Each raster has 365 bands — one for each day. A separate operation is performed ...
4
votes
0answers
37 views

Combining CSV files of simulation results

This script is a subset of a larger script where I have the output of many test simulations in the form of CSVs. Each file starts with the model name and includes the number of elements in my file. ...
7
votes
2answers
140 views

Count reoccurring elements in multiple lists in Python

I have a number of names divided into several lists. I am printing all the names which occur in more than one list, sorted by the number of occurrences. What is a better/easier/more pythonic way of ...
5
votes
1answer
114 views

Run a command for all files in a directory

I have a program that needs to run an command on all the files in a folder: ...
2
votes
1answer
825 views

Python script for sorting a huge log file based on timestamps

I want to write a python script to sort a huge file, say 2 GB in size, which contains logs in the following format - ...
3
votes
0answers
56 views

Pygame : processing speed independant image loop displayer

I made this in order to teach myself pygame. This displays an images loop at the same speed on any computer (It will lag on a slow computer). Is my time management good or do my datetime call could ...
2
votes
2answers
62 views

Trellis Generator

I've been tasked with writing a simple trellis generator. The user is prompted with entering the height and width of the desired trellis, and gets a printed result of a trellis with the entered ...
5
votes
1answer
439 views

Improving the speed of creation for three Perlin Noise Maps in Python?

I am interested in learning how I can improve the speed of the code in this pygame file. I iterate over 6400 * 1800 * 3 or 34,560,000 elements of various numpy arrays here to apply noise values to ...
4
votes
2answers
193 views

automating to push changes to github for multiple repos using python

This Python script does following activities: clone repo, as provided from the list creating a new branch "jenkinsMigrate" rename Jenkinsfile to Jenkinsfile.migrate push code to GitHub in a new ...
6
votes
1answer
183 views

Plotting terrain pixels with PyGame based on random NumPy array

I am experimenting with Perlin Noise and random map generation. I have a 2D numpy ndarray full of 16-bit floats called map_list that I call from the singleton ...
-2
votes
1answer
52 views

Functional vs non functional approach in python [closed]

This is not a task, but I want to know what the general consensus is on functional programming. Particularly functional programming in Python. The two snippets of code I am comparing are the ...
3
votes
1answer
115 views

First python program: basic calculator

I want to start learning python for fun and so I could dig into machine learning projects later in the future maybe. I started off with a small calculator project just to get the hang of the language ...
3
votes
2answers
725 views

Capitalize a sequence of lines entered via console input and print/return

I'm running through the popular python practice exercises located at github: https://github.com/zhiwehu/Python-programming-exercises/blob/master/100%2B%20Python%20challenging%20programming%20exercises....
2
votes
3answers
129 views

Free time calculator

I started learning Python 2 about a week ago, using Codecademy and Stack Overflow answers to help me learn. I wrote a code to calculate the user's free time based on user sleep and work time. It also ...
4
votes
2answers
395 views

Guess-the-number game by a Python beginner

For some background I'm pretty much a beginner and attempting to learn Python currently. So I decided after a few days of lessons I'd look for some beginner projects to test my knowledge. A website ...
2
votes
1answer
79 views

Application to monitor device power levels for deviations

I have a high performance, computation intensive application that runs on a Centos 7 machine with Python 2.7.5. I'll try to explain what the application does: The application runs an infinite loop, ...
4
votes
1answer
194 views

Looping through multiple regex efficiently

I'm writing a program that adds all network interfaces with multiple parameters to a list. I have written the following code, which should work out of the box on any Linux system with Python and ...
2
votes
1answer
68 views

Most efficient way to find spatial order from a list of tuples (Python)

I have a circle-growth algorithm (line-growth with closed links) where new points are added between existing points at each iteration. The linkage information of each point is stored as a tuple in a ...
1
vote
1answer
69 views

Python Firewall-Connection-Event Filter too slow

I've written a little piece of code to filter Firewall-Connection-Events by a certain group of IPs. But the code can't keep up since the input is fairly huge. I am looking for ways to make this code ...
1
vote
0answers
35 views

Managing multiple sockets in a network client in Python

I'm writing a small FIX client in Python (2.7, constraint I cannot waive for now, unfortunately). There will be multiple sockets, connecting to different ports, so I thought I'd create a ...
6
votes
3answers
564 views

Implementing a customized helpful hints function which includes docstring but much shorter than Python help()

When I show others how to use this module I have them make a PROJECT instance and then add other objects. ...
3
votes
1answer
262 views

Bin packing variant

As in classical bin packing problem, this is an algorithm that optimises the number of bins of a certain size used to hold a list of objects of varying size. In my variant I also work with a second ...
1
vote
1answer
51 views

List directories, subdirectories and files, while ignoring some dirs

In my application, the user may or may not want to ignore some directories. I can do that, but it seems like I am repeating myself. Does anyone have an idea to refactor that? ...

1
2 3 4 5
25