Python is a dynamic, high-level language. Its design focuses on clear syntax, an intuitive approach to object-oriented programming, and making the right way to do things obvious. Python supports modules, exceptions, had an extensive standard module library. Python can also be embedded in other ...

learn more… | top users | synonyms (1)

0
votes
0answers
27 views

Problem with quicksort and python [migrated]

I'm writing a python program that plays poker for a class, and I need to sort a list of five card hands. I have a function called wins(), which takes two hands and returns True if the first one beats ...
1
vote
1answer
48 views

When should one create a new py-function rather than tweaking another one?

Me and a co-developer are arguing when it's wise to cast a new function rather than tweaking another one. By tweaking I mean an option or a hidden check in an existing function. The question could be ...
0
votes
3answers
226 views

Socket Connecting to Large number of IPs

I have a text file of ~600 CIDR notation IP blocks which, when expanded, amount to ~17.5M IP addresses. I need to socket connect to each one. If it connects, I add it to a "live" list, if it returns ...
4
votes
4answers
514 views

Multiple sites with the same codebase in Python

I am trying to run a large amount of sites which share about 90% of their code. They are simply designed to query an API and return the results. They will have a common userbase / database but will be ...
-3
votes
0answers
33 views

Algorithm to make sum of elements equal zero [on hold]

I want to make sum of elements in this array equal zero array = [[1, 2, 1], [1, 2, 1]] Need sum of columns and rows equal zero array = [[1, -2, 1], [-1, 2, 1]]
1
vote
2answers
119 views

Efficient datastructure to create size-limited dictionary

I need a class that acts like a dictionary but will constrain the total number of key/value pairs it contains. For instance, let's say the maximum number of entries is 1000 and the class already ...
2
votes
3answers
914 views

Front-end structure of large scale Django project

Few days ago, I started to work in new company. Before me, all front-end and backend code was written by one man. As you know, Django app contains two main directories for front-end: /static - for ...
0
votes
0answers
4 views

How would you search a dictionary and print out entries with same value [migrated]

I've been a little confused on how you would go about this, so what would be a good way to do it. For Example: If I had this as my dictionary dic = [{1:Dog, 2:Cat}{1:Bird, 2:Rat}{1:Turtle, 2:Cat}] ...
0
votes
1answer
34 views

Django urls.py runs only once. Why? How does it call views on next request?

While testing django cashing on our development server, one of our senior asked if is it possible to change the value of caching timeout on urls.py without restarting the http service. On first note, ...
2
votes
1answer
65 views

Python beginner question with Assigning Variables

Coming from C# and now getting my hands dirty with Python. From what I understand, Python is strongly typed: http://stackoverflow.com/questions/11328920/is-python-strongly-typed As stated in the ...
0
votes
0answers
123 views

How to web scrape [on hold]

So I am using a raspberry Pi for displaying calls to our fire department on a big screen. It works great but I want to customize the display. Currently, it takes the information from a webpage that is ...
-4
votes
0answers
11 views

Is it possible to install llvmlite Python package on Cygwin? [migrated]

When I try installing llvmlite Python package on cygwin, I get the following errors. GINMF in this case. I'm currently using Cygwin 1.7.35(0.287/5/3), Python 2.7.8, and Windows 7. $ pip install ...
10
votes
3answers
1k views

Python Multiprocessing with Queue vs ZeroMQ IPC

I am busy writing a Python application using ZeroMQ and implementing a variation of the Majordomo pattern as described in the ZGuide. I have a broker as an intermediary between a set of workers and ...
-2
votes
0answers
89 views

Most concise solution in Golang for Cheryl's birthday problem [closed]

I found the Python code found on this page somewhat fascinating for its brevity https://news.ycombinator.com/item?id=9375643 What would be the most succinct way to code the same logic in Go? import ...
-3
votes
0answers
22 views

Python … Strip carriage returns / line feeds from database records before they are written to csv [closed]

I have the following code that reads lines from a database and writes the matching results to a csv file. The problem I am running into is there are occasionally carriage returns / line feeds in some ...
-2
votes
0answers
30 views

Using Operations on a List in Python and Aggregating Results in New List [migrated]

I have a list of numbers, all of which need to be divided by the same number. I can do this, no problem, but how do I create a new list featuring these new quotients? I have tried: for n in numbers: ...
0
votes
1answer
265 views

Facing MemoryError in Python

I wrote a program to find prime factors of a number. When I give a large number(600851475143) as input, MemoryError pops up. Below is the code: def fact(a): factors = [] for i in ...
-3
votes
2answers
71 views

How do I fix this if statement? [closed]

Trying to create a program that runs if statements to find the maximum and minimum of the five numbers inputted by the user. I run this code and I keep getting that A is the maximum. a = ...
34
votes
4answers
3k views

Python Forgiveness vs. Permission and Duck Typing

In Python, I often hear that it is better to "beg forgiveness" (exception catching) instead of "ask permission" (type/condition checking). In regards to enforcing duck typing in Python, is this try: ...
1
vote
3answers
5k views

Tips on Converting a C program to Pure Python [closed]

I'd like to convert an open source C application to pure python (not to Cython, IronPython etc). The documentation and presentations of the original creator of the C application has given me a good ...
0
votes
1answer
114 views

Best strategy for converting change in longitude and latitude to north, south, east, west in degrees

This is not a class assignment but a conceptual question I'm struggling with for a personal project. I need to convert a large paired group of long and lat coordinate values that show a ...
0
votes
0answers
52 views

Matching groups of similar lines on a generic matching algorithm

I have to write a program to search through a file containing lines and find lines that match to a degree of tolerance but are not necessarily the same. So for example the following lines would match: ...
1
vote
0answers
75 views

Calculating uncompressed file size without uncompressing file in zlib

I am writing a python program which parses zip (currently only zlib, using DEFLATE compression) files and verifies the correctness of their headers and data. One of the things I'm trying to achieve is ...
0
votes
1answer
87 views

using one database connection across multiple functions in python

whats the best way to go about this in python? I have a number of like so def test1() .... code ..... def test2() .... code ..... def test3() .... code ..... how could I create one ...
0
votes
0answers
30 views

Python socket programming for Webserver [migrated]

I have created a proxy server that receives requests, searches for the requested file in its cache. If available it returns the cached file. If file is not available then it will ask the actual ...
0
votes
0answers
24 views

Designing a task dispatcher for making API calls

In my application, I have a list of users and associated timestamps (with 10 minute granularity): [(u1, t1), (u2, t2), ...]. There are about 10 million such tuples and I need to make an API call to a ...
0
votes
0answers
25 views

Common to include pre-built binaries for supporting build tools? [duplicate]

As part of a Visual Basic 6 project, I have created a python script to provide a CLI to building the project/docs. However, I realize that not all developers who will have access to this project will ...
0
votes
1answer
149 views

Check distance between all elements in a list of numbers in O(n*lg(n))

I have an exercise for my algorithms and data structures class, where I basically have to implement a divide and conquer algorithm or function called check_distance to determine whether all numbers in ...
0
votes
0answers
207 views

What's an elegant way for one loop iteration to affect another? [migrated]

I needed to process a config file just now. Because of the way it was generated, it contains lines like this: ---(more 15%)--- The first step is to strip these unwanted lines out. As a slight ...
2
votes
1answer
2k views

Why isn't there a python compiler to native machine code?

As I understand, the cause of the speed difference between compiled languages and python is, that the first compiles code all way to the native machine's code, whereas python compiles to python ...
0
votes
0answers
21 views

Is Python Logging in a WSGI application a best practice a production environment?

I am trying to log my webpage access to a database. It is a requirement. It seems to be a difficult thing to do outside of Windows IIS, and I do not wish to use Python with IIS. My options seem to ...
0
votes
0answers
16 views

How to access objects in lists? How to create many sequentially named objects at once? [migrated]

Im new at python and programming in general, so forgive me if this question is painfully simple. I could not find an answer using google. Anyway, I want a long list of checkbuttons and entries. I ...
1
vote
1answer
259 views

Merge two different API calls into One

I have two different apps in my django project. One is "comment" and an other one is "files". A comment might save some file attached to it. The current way of creating a comment with attachments is ...
0
votes
1answer
128 views

How to structure GUI program with a database

I am fairly experienced with web design and programming, C, C++ and a little java (used it to build some small GUI). I am trying to work with Python, and I am faced with some technical structuring ...
0
votes
0answers
34 views

Extending the interface of existing (python) classes

I use a library with an existing well-defined interface, that I have extended for my purposes. I.e. most classes in that library inherit of one abstract base class class Parent(object): def ...
3
votes
1answer
65 views

Structure project based on platform or design?

I have a medium sized project (~10,000 lines) that runs on Windows and Linux. However it is only specific components of the program that are platform dependent and are located in a folder called ...
8
votes
4answers
1k views

Returning a boolean when success or failure is the sole concern

I often find myself returning a boolean from a method, that's used in multiple locations, in order to contain all the logic around that method in a single place. All the (internal) calling method ...
1
vote
2answers
94 views

Technique to synchronize error codes in a same-project-API

In the project I am working right now, we have some python and some C# code. At some point, I call from python a subprocess which starts a C# executable. This C# code returns an error code, which has ...
-1
votes
0answers
16 views

How can I pass String value from EditText In Android Activity to Python Script and also retrieve the result from a function in the python script? [migrated]

How can I pass String value from EditText In Android Activity to Python Script and also make the activity able to retrieve the String result from a function in the python script such as displaying ...
3
votes
3answers
112 views

How to write tests for function that depends on a config file?

I have a function that uses information from a config file. How do I test the function? Ideally, I'd want to inject my own version of the config file and test from there, but I'm not using dependency ...
1
vote
1answer
120 views

What is ## used for?

I have looked at other questions about this and the general consensus seems to be that ## is used for commenting out code. However, in the Interactive Editor for Python, prefixing a line with ## ...
0
votes
1answer
56 views

Program design - how to improve it and how to avoid coupling (Python)?

In the Python program structure below there are two modules with functions. Problem description: Functions are used inside other functions all over the place. Strong coupling (dependency). For ...
0
votes
1answer
107 views

Does the phrase “range for R1-1 through R10H” actually have an agreed-upon meaning?

I was recently sent a code test by a potential employer to complete on my own time. The first question has to do with identifying whether a given zoning code falls within a range of codes. I'm not ...
0
votes
1answer
68 views

Is it reasonable to use a decorator to instantiate a singleton in Python?

Suppose I have a class like this: class Foo(object): # some code here As it happens, Foo is a singleton. There are numerous ways to write singletons in Python, but most of them don't really ...
-5
votes
0answers
21 views

How can I make a Python function examine every element of a list? [migrated]

I was ordered to build a Bulean Function that takes a list of numbers and execute "True" if the list is a proper grade list(i.e every number is between 0 to 100) and "False" otherwise. I however ...
0
votes
1answer
77 views

Python, namespace vs module with underscores

I'm developing a project that uses several independent modules, but all related to the same project. However, I face this choice: module names with underscore vs. namespaces. For example there is ...
0
votes
1answer
35 views

Aggregate documentation comments from multiple scripts into README?

After having written some python scripts with comments for documentation inside, is it a good idea and possible to aggregate the documentation comments from multiple scripts into some standalone ...
2
votes
3answers
82 views

Preferred way to expand a command line script to be used as a library in Python

I have a useful Python script that I've been invoking from the command line. It has decent number of options, maybe 20, and it's not unusual to run the script with six or seven flags. Then the rest of ...
8
votes
4answers
1k views

Write two versions of class with two different super classes without violating DRY?

I have a class called LimitedDict which is a dictionary that limits the number of entries it can contain by deleting old entries when a new one is added. It currently inherits from Python's dict ...
0
votes
0answers
56 views

Ordering of methods in class [duplicate]

How do you order the methods in your classes? I am aware of the alphabetical approach and the telling a story approach and so far I prefer the story approach, but how do you handle private/helper ...