Questions tagged [python]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x.

Filter by
Sorted by
Tagged with
2
votes
1answer
192 views

Logic/Code duplication, improve readability?

I have a function that takes a point, and given its velocity, and acceleration, calculates the time(s) for the point to collide with the line: ...
3
votes
2answers
277 views

Robust .mpg file copier

...
3
votes
2answers
2k views

Try every username and password from a list on a website

This code will be brute force specific site using http POST method. ...
4
votes
1answer
203 views

Constantly checking existence of dictionary elements in Python: a better way? [closed]

I use Python dictionaries to count words in a corpus: words[a] = number of times I saw a in the corpus. Every time before ...
3
votes
2answers
3k views

Lazy class instantiation in Python

I've written some class which allows me to derive from it to make objects lazy-instantiated. Do you see notational improvements or maybe even cases where this method might not work (multiple ...
3
votes
2answers
3k views

Default initialization of items using Scrapy [closed]

I am writing a scraper, using Scrapy, in which I need to populate items with default values at first. Could my method be improved? ...
6
votes
1answer
8k views

Convert elementtree to dict

Just needed a quick way to convert an elementtree element to a dict. I don't care if attributes/elements clash in name, nor namespaces. The XML files are small enough. If an element has multiple ...
2
votes
1answer
297 views

Am I being too redundant in this Django view (or can I reduce the repetition in my code)?

I'm new to Django and learning my ways around it. I'm writing a fake basic CRUD app to get me started. In the following code I pretty much copy and paste the same code four times with minor ...
3
votes
3answers
716 views

Simple hashing code with excessive conditional statements

Any thoughts on my code? It's a simple hashing code that runs from the command line. There just appears to be a lot of condition if / ...
5
votes
1answer
213 views

Job queue system

I'm doing a side project at work and I consider it as a learning opportunity more than work itself, but it does hold a purpose if I can complete it. Anyway, I'll post the code, what it actually does ...
3
votes
1answer
2k views

Web crawler in Python

I have written a web crawler. I hope anyone can help me make this code be more better. This is the task to implement a web crawler in Python. ...
2
votes
1answer
103 views

Unneccessary Things to Delets

Do you see any unneccessary code, or code that can be deleted in here? Its not finished... ...
3
votes
2answers
670 views

Improving python3 processing speed (against a reference perl script)

In order to create fast map/reduce processor for hadoop, I'm evaluating many languages. I'm learning python so I would like my python processor to go as fast as my perl processor. So, for this ...
7
votes
4answers
8k views

Python implementation of the longest increasing subsequence

Prompted by this question on Stack Overflow, I wrote an implementation in Python of the longest increasing subsequence problem. In a nutshell, the problem is: given a sequence of numbers, remove the ...
2
votes
1answer
709 views

TornadoWeb Python

I'm currently working with TornadoWeb but appear to have picked up a lot of bad habbits. I'd appreciate some feedback on the code below: ...
8
votes
3answers
693 views

Function for getting URLs

This is a simple Python program I wrote. I hope some one could help me optimize this program. If you found any bad habits, please tell me. ...
0
votes
2answers
114 views

Over-Riding User Input

Here's a trivial example: if type(length) != int: length = 16 as opposed to: ...
1
vote
2answers
969 views

Displaying user-defined functions and their docstrings

Let's say I want to create dynamic documentation of functions I wrote, without using the help() function (I don't want the user to care about arguments accepted by ...
12
votes
4answers
26k views

Python Solution for Project Euler #2 (Fibonacci Sums)

I'm a fairly new programmer (just started yesterday!). I decided to tackle Project Euler #2 today, as I did #1 yesterday without many problems. I came up with what seems to me to be a working solution,...
0
votes
1answer
145 views

Pythonic data processing? Should I use an iterator?

In a data processing and analysis application I have a dataCleaner class that conducts a series of functions that help me to clean raw time series data. One of the problems I see in my data is that ...
1
vote
6answers
2k views

The Next Palindrome - reducing total execution time

I tried to solve one SPOJ problem. I wrote one program in Python, however, it got accepted by the SPOJ judges, but its total execution time is 2.88s. The same algorithm used in C language having ...
21
votes
2answers
57k views

Ultra-Beginner Python FizzBuzz … Am I missing something?

I just started programming in Python this morning, and it is (more or less) my first programming language. I've done a bit of programming before, but never really did much except for "Hello World" in ...
4
votes
4answers
10k views

Comparing 2 CSV files

Here's the exercise in brief: Consider the following file: Code: before.csv A; ; B; B; A; H; C; ; D; D; C; G; E; D; F; F; E; H; G; D; ; H; G; ; ...
3
votes
2answers
6k views

List splitting for RLE compression algorithm

I try to implement a simple RLE compression algorithm as a learning task. In the first step, i need to split my source list to sequences of repeating and non-repeating elements. I've done it, but code ...
1
vote
1answer
2k views

Data cleaning - am I using classes correctly here?

I have a data processing application that does some data cleaning as the first step. This is the module I import for that purpose. The only 'public' part of the api is the 'clean' function which ...
2
votes
1answer
158 views

Simple utility/convenience module - am I doing it right?

I have a large library (four packages) of data processing code that I have written over the last 12 months. I am quite new to python and would like to see if I am doing things correctly. This utility/...
3
votes
2answers
718 views

Symlinking git-managed dotfiles into a home directory

As a learning exercise, I decided to write a script for helping me maintain my Unix configuration/dot-files under a git repository. I check out a copy of the repository in my home directory called ....
2
votes
2answers
222 views

Removing C++ template arguments from a C++ function name

I'm working on some code that deals with mangled C++ function names. I'm displaying these to the user, so to help with readability of some of the really long C++ template class/function names, I'm ...
3
votes
1answer
556 views

Mobile content delivery system

For flexing my newly acquired Django & Python muscles, I have set up a mobile content delivery system via Wap Push (Ringtones, wallpapers, etc). The idea is that a keyword comes in from an sms ...
2
votes
2answers
1k views

Python memoization decorator

I have spent all night whipping up this recipe. It's my first Python decorator. I feel like I have a full understanding of how decorators work now and I think I came up with a good object-oriented ...
1
vote
4answers
12k views

Simple palindrome function for single words

I have created a simple palindrome function that works only on single words. It is working as intended, but I feel that it definitely needs improvement. ...
2
votes
2answers
1k views

Data extraction

I wrote this code in Python/ Scrapy for data extraction. It works fine for me, but I am a newbie in Python, so any suggestions for code optimization would be welcome. ...
4
votes
1answer
9k views

Reading a .gz file

I am using Python 2.6.5 and am trying to find the fastest way to print out the contents of a .gz file. It's my understanding that prior to v2.5, zcat was much faster than gzip (see here)....I guess ...
3
votes
2answers
374 views

GtkInfobars for a GTK+ application

I instantiate GtkInfobars a lot in my GTK+ application in order to communicate with the user. There are various types of infobars, depending on the message. Basically, any infobar could be a ...
1
vote
1answer
85 views

How to verify if value already added to the list and if so, then update the value? [closed]

I use 3 lists to store field name, its value and score. If field name is already added to according list, then I just need to update other 2 lists. If it is not there, then I need to add it. I do the ...
1
vote
1answer
1k views

Linear Regression and data manipulation

How could I improve the following code that runs a simple linear regression using matrix algebra? I import a .csv file (link here) called 'cdd.ny.csv', and perform the matrix calculations that solve ...
4
votes
2answers
5k views

Better way to do multiple try/except in Python [closed]

I have this code: ...
1
vote
2answers
425 views

Range of ordinal numbers

My disgusting list comprehension in the return statement is quite a headful. ...
1
vote
3answers
389 views

Returning the sum of all multiples of a number up to 1000

I've been learning Python and in order to put my skills to the test, I created a simple program that returns the sum of all of the multiples of number num up to ...
4
votes
1answer
2k views

Monkeypatching builtin open and File Mock-Up for unit testing

For a specific test-scenario I wanted: avoid accessing the file system through pythons builtin open-function don't want to use 3rd party libraries like Michael ...
10
votes
2answers
28k views

Calculating population standard deviation

This is a script I have written to calculate the population standard deviation. I feel that this can be simplified and also be made more pythonic. ...
1
vote
1answer
1k views

randrename — insert random nums in filenames

I have an old mp3 player with a broken screen. Consequently, it's a real pain to turn shuffle mode on and off; however, there are a few albums that I wanted to mix together and have shuffled for when ...
2
votes
2answers
133 views

All possible lists from ups and downs between elements in python list

I have a function that compares sequential elements from a python list and returns 1 and -1: >>> up_down([0, 2, 1, 3]) [1, -1, 1] I need a function to ...
4
votes
2answers
548 views

Display data based on read configuration file from ssh sessions

I started playing with Python last week. This is a section of code from an application which reads a configuration file and launches ssh sessions and continuously ...
3
votes
2answers
383 views

code review for count then sort problems (go lang)

the question is simple, for a input [apple, banana, orange, apple, banana, apple], the program will count it as a map: {apple : 3, orange: 1, banana: 2}, then sort this map by it's values, get [(apple,...
1
vote
1answer
7k views

Method to count interior nodes of a binary tree

I'm not a programmer, but am playing around with a binary tree Class in Python and would like help with a recursive method to count interior nodes of a given tree. The code below seems to work, but ...
2
votes
2answers
5k views

Replace match inside tags

The problem I want to solve is to replace a given string inside tags. For example, if I'm given: Some text abc [tag]some text abc, more text abc[/tag] still some more text I want to replace ...
2
votes
1answer
569 views

Calculating reverse dependencies of a Debian package

It works pretty well, but I suspect there's too many variables, and I wonder what else. I'm using this library: Python APT. ...
1
vote
1answer
4k views

Moving a game character around the screen

I'm a newbie to Python, and I was wondering whether anyone could give me any pointers on improving the following code: ...
6
votes
1answer
4k views

n largest files in a directory

This is a script I wrote to find the n biggest files in a given directory (recursively): ...

1
267 268
269
270 271
274