Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
2
votes
1answer
26 views
Interfacing with instruments using pyvisa
I'm new to Python, and after running through some introductory exercises I wrote a class definition for working with some hardware, specifically a Signal Recovery model 7230 lockin amplifier. In the ...
5
votes
0answers
57 views
Python program that scrapes my CS teacher's website
I am new to programming, and I'm looking forward to seeing what I can do to improve my code.
I've been working on creating an individual final project for my python CS class that checks my teacher's ...
8
votes
4answers
241 views
Checking if a string is a pangram
This checker works perfectly but I have a strong feeling that I could make this script much more compliant with the "Zen of Python", especially having read a book about it recently. There is no doubt ...
2
votes
1answer
13 views
1-D intersection of lines given begin and end points
I have a fairly basic question here: I want to find if two lines on a 1-D plane intersect. I know of two simple ways to solve this, but I wanted to know if Python has a more elegant way to solve this.
...
3
votes
0answers
25 views
Implementing common random numbers in a simulation
I originally posted this on stackoverflow, but the came across this site which I think the question is better suited for.
I am building a small simulation in Python and I would like to use Common ...
-2
votes
1answer
36 views
Simplify python conditional
This is a follow up to Log probe requests of WiFi devices focussing on a specific element of the code.
Can I simplify this code and make it more readable?
...
-1
votes
1answer
38 views
Formatting a long filesystem path in Python
This is a follow up to Log probe requests of WiFi devices focussing on a specific element of the code.
I have this line of code:
...
1
vote
1answer
28 views
Argparse implementation
This is a follow up to Log probe requests of WiFi devices focussing on a specific element of the code.
How can I indent this code to make it look great and be well formatted?
...
6
votes
1answer
34 views
3
votes
1answer
20 views
Convert points into an octree
I set about doing it as a challenge (and it's still far from finished) but I hit lots of problems. The main one that caused most of them was it can't deal with even numbers (it can be ...
3
votes
2answers
36 views
Time Code with Microsecond Conversion
The function below converts a time code into seconds, while maintaining the decimal value (fractions of seconds). The time code fed to this function will always contain microseconds. This currently ...
3
votes
3answers
94 views
Multiple for loops in Sudoku solver
I have an assignment for writing a Sudoku solver and have achieved the functionality required but a lot of the code is "ugly" and I'm wanting to simplify it but unsure how to.
...
3
votes
0answers
20 views
MS Access to PostgreSQL converter
I was hoping to get some feedback on the implementation of this class for programmatically converting an access file into a PostgreSQL schema (works by obtaining schema data from the cursor object).
...
11
votes
3answers
871 views
PyDOS shell simulation
I have a big project called 'PyDOS', written in Python 3.4, and it's going very well. Post your answers of anything that could make it look cleaner.
...
7
votes
1answer
85 views
Log probe requests of WiFi devices
I developed a program that collect probe requests from WiFi devices. It already works but I think that a programmer can improve it.
...
2
votes
2answers
43 views
Interactive HTML stories creator
I decided to write a small script to make writing HTML interactive stories less tedious:
...
3
votes
3answers
71 views
Simple list comprehension
As far as I can tell, there is no network access happening at this stage in the code. I am accessing Reddit's API via the PRAW module. However, it is crawling, and I think it should be faster, ...
4
votes
0answers
52 views
Building Data abstraction and ADT for rectangle using “objects”
For the below given exercise:
Exercise 7: Abstracting Rectangles
Implement a representation for rectangles in a plane. (Hint: You may want to make use of your procedures from exercise 5). ...
7
votes
1answer
57 views
Depth First Backtracking Puzzle Solver
There is this type of puzzle
that can easily be solved with a depth-first backtracking solver. I wrote one in python 3.4 and like to get some feedback.
I'm especially interested in the following ...
-2
votes
0answers
26 views
Print different results in Python a dictionary [closed]
I'm writing a words unjumble program. Here is my code:
...
2
votes
1answer
30 views
Performance of parsing math functions
I wrote the following code as part of a larger application. This code takes a string that defines a mathematical function on such as r,y x[0], x[1] etc. or any ...
1
vote
1answer
28 views
Optimizing the performance of a nested for loop over millions of messages from SQLite Query - v2
I've posted and gotten help to optimize my code before here and here. Now I have implemented the following changes, after very helpful advice:
I have implemented a Dictionary instead of using list ...
6
votes
2answers
138 views
Project Euler Problem 12 in Python
I'm trying to do Project Euler Problem 12, which reads as:
The sequence of triangle numbers is generated by adding the natural
numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 ...
0
votes
0answers
35 views
Finding common ancestor in a binary tree
Following is a Python program I wrote to find the common ancestor in a binary tree (not BST) with no link to parent node. Please review.
...
2
votes
2answers
39 views
Bubble sort a list of integers for a number of iterations
I wrote a program for this problem, but it stopped because it took too much time. Any tips?
The Problem:
Bubble sort is the simplest algorithm for elements sorting. At each iteration we sequentially ...
4
votes
1answer
109 views
Abstracting the process of finding the index of the maximum in Python
Suppose I want to find the index of the maximal value of a given sequence. In Matlab, this is:
[value, index] = max(x)
In Python, I would abstract the following ...
0
votes
0answers
12 views
Guess the number game - improving the game ending on running out of available guesses [closed]
Consider this function for a handler of user input in the "guess the number" game.
...
4
votes
1answer
157 views
Check whether a number is positive, negative, or zero
I have a program which generates a number between 0 and 4 for both the player and the computer. If the number is positive the player wins, and if it is negative the computer wins.
...
3
votes
1answer
64 views
Python Longest Repeat
I am trying to find the longest repeated string in text with python, both quickly and space efficiently. I created an implementation of a suffix tree in order to make the processing fast, but the ...
3
votes
0answers
23 views
Writing data into an image
I've done a script that will write things as images, which can then be read elsewhere (eg. you could share an mp3 through imgur). This is the first one I've done where I've been trying to improve my ...
1
vote
1answer
90 views
Find the highest frequency of messages inside a time slot of 24 hours
I have a very large number (millions) of messages, each labeled with the unixtime it was sent in a SQLite database. Each message has its own userid, for the user that have sent it. I want to know ...
2
votes
3answers
65 views
Force params to lowercase
I think there must be a more pythonic way to achieve the lowercase-forcing that I need to do here. The keys in my lookup (self.adjustments) are all lc, params sent in to function can be any case ...
1
vote
1answer
38 views
Building Data abstraction for line segments using “objects”
I follow this definition of "object":...
-2
votes
0answers
33 views
Tile colored based on “shape”.shape “one” = all tiles last column of the cell to be colored. “two” = top and bottow rows colored, and diagonal
A Cell can be of width and height UP TO 5x5, and only "one" and "two" shapes will be used.
...
3
votes
1answer
47 views
Optimizing a Tic-Tac-Toe AI
I built a Tic-Tac-Toe game in Python. The board is made of ASCII characters and it is the user versus an AI. The user chooses a number (1-9) and if the corresponding spot is open then either an 'X' or ...
2
votes
2answers
51 views
Fraction Class in Python
I decided to train myself in OOP with a simple perfect precision Fraction class.
...
4
votes
2answers
157 views
Return a random line from a file when user enters a specific text
I am a beginner trying to fetch a random line from a file and wondering if this code can be improved. Should I use try and catch in this case? Should I take a parameter for the function "quote"? How ...
2
votes
1answer
34 views
Uploading and downloading files with FTP
I'm learning Python and decided to rewrite my FTP tool from Perl to Python. The program is able to up/download files, change the directory and list the files of the current directory.
Is there ...
1
vote
0answers
11 views
Universal nested get/set for trees in Python
Based on this source, I've made the following universal get / set function, to make it possible to work on OrderedDict trees for example.
...
1
vote
0answers
11 views
Optimizing a drawing a circular gradient in Python (aggdraw, PIL or SDL2)
I need to reduce the latency in creating a circular gradient of arbitrary radius that's then mapped to the current mouse position.
Though the project uses OpenGL for video-card interaction, alas, ...
0
votes
1answer
64 views
“Data Abstraction” and “Abstract Data Type” for a rational number [closed]
Below is implementation 1 of data abstraction for rational number using functional paradigm written in Python:
...
0
votes
0answers
28 views
Object Oriented design - connection to multiple databases
I have a Python application which uses both SQLite and Postgresql. It has a connector class for each database:
...
1
vote
1answer
38 views
User input function keep looping until valid filename entered
The following function is basically asking the user to input a file name for a file that the calling program is going to do something with. If the user enters an invalid file name, I want the program ...
1
vote
1answer
28 views
Parsing specifically nested XML Tags
I've written a function that works however I'm sure there is a better way. I need to parse specific tags from an xml document (Microsoft Word docx document.xml).
Here is the general structure of the ...
4
votes
0answers
57 views
Parsing > 30 GB file in least amount of time
My Goal: To efficiently move data from Amazon S3 to Amazon Redshift.
Basically, I am moving all CSV files on my S3 to Redshift using the below code. I parse through part of the file, build a table ...
3
votes
1answer
179 views
Labeling alternating max/mins based on a user defined delta
Given a set of values (points on a graph) find all the max/min points such that
there is no max is followed by a max (i.e. the max and min points alternate)
there is some minimum amount of change ...
1
vote
0answers
29 views
Conference track management
I was learning my way on designing real world OOP problems and I was trying to solve this problem in the OOP way. The problem statement is as follows:
...
4
votes
1answer
62 views
Number-guessing game with simple GUI
This is my second program in Python. I am aware that globals are a bad idea, but that is what I have learned so far in my course.
Right now the program is doing what it's supposed to do, my only ...
3
votes
1answer
72 views
Iterative equation solver in Python
In order to solve a equation where the left hand side appears under an integral on the right hand side:
$$
B(p^2) = C\int_0^{p^2}f_1\left(B(q^2),q^2\right)\mathrm{d}q^2 + C\int_{p^2}^{\Lambda^2} ...
1
vote
0answers
12 views