0
votes
0answers
24 views

Should instance variables be bound to the instance right in the beginning of the method they are created in?

A common problem for me - and it's not really a problem, but somehow I again and again ask myself, what is the normal way to handle this - is that there is a method and within this method a couple of ...
-2
votes
0answers
18 views

REST server design and implementation question: using reddit as an example

I am studying different implementation of REST api in various open source projects. In this question I would to like to use reddit as case study. Here is the url to the API module ...
-3
votes
0answers
26 views

Creating an R package with Python source code [migrated]

I have some python code that I want to integrate into an R package. I figured out how to make the R package with python source code (via R's shell or system commands), but it still requires that the ...
-3
votes
0answers
40 views

Ant Colony optimization applied to a road network in tkinter window [on hold]

I'm trying to use an Ant Colony optimization algorithm and apply it to a road network. My ant colony is working on a blank canvas at the moment, but i would like to incorporate a real road network. ...
-4
votes
0answers
11 views

custom gui notifications in python [on hold]

i have to develop a software that runs in background and constantly poll a database searching for new messages to be displayed in the right down corner in windows (linux and max as well) like ...
-2
votes
0answers
14 views

how do I create normally distributed object using scipy [on hold]

I am trying to create a normally distributed object in python, how do I set it to have a normal distribution of 1 and a mean of 4?
2
votes
0answers
41 views

Building a string parser for user command and control?

My goal is to build a command parser that has basic syntax and multiple possible branches at each point. These commands come from users of the system and are text input (no GUI). The basic syntax is ...
-1
votes
0answers
34 views

Language to implement GNU toolchain type pipelines? [on hold]

I have some quick and dirty pipelines implemented as bash scripts that : consume a stream of data from a socket using CURL do some regexp matching and reformating (grep | awk | grep -v | sed | ... ) ...
2
votes
1answer
44 views

Python property best practices [on hold]

Is there any situation where it makes sense to define a python property, where getting (not setting) it would raise an exception? I don't think this ever happens for fields in classes, hence the ...
0
votes
2answers
107 views

Is this a pattern: stand-alone classes

Having recently discovered python, I attempted to write a simple logger. Data is read from a device, processes, displayed and stored on disc. Those different tasks belong to different modules, of ...
1
vote
1answer
52 views

writing functional/integration tests for python

I am new to python and functional/integration tests as a whole. I know how to write unit tests, but in this case i do not need isolation for specific functions, rather i need my python script to be ...
-4
votes
0answers
30 views

Dictionary - Find the key by entering the value [migrated]

i have a little code but i don't know how to find the key in a dictionary by using the value. Here i have my code and what i want to do: NAMES = ['Alice', 'Bob', 'Cathy', 'Dan', 'Ed', 'Frank', ...
-4
votes
1answer
33 views

How to make use of a foreign host's “Date” output in a program on my local computer [closed]

How can I SSH via python script into a linux box run a command (Date) and use the output in the local script?
3
votes
2answers
123 views

Is a bad practice create database structure on the runtime?

Im creating a crawler app that will always in the beggining, when the Class constructor, ensure that the basic database structure exists. Is this a bad practice? What is the advantage os creating the ...
0
votes
0answers
5 views

Python - How To Get Cursor Position in Tkinter Text Widget [migrated]

I want to get the cursor position (line and column) of the insertion point of a Tkinter.Text, but for the specific situation below. PROBLEM: My text editor project requires a custom undo/redo for ...
0
votes
0answers
5 views

Python Socket Scripting. What am i doing wrong? [migrated]

My socket program hangs at clientsocket, address) = serversocket.accept() and doesn't spit our an error or anything. I followed directions on https://docs.python.org/3/howto/sockets.html I've been ...
-1
votes
1answer
92 views

Unevenly distributed random number generation [duplicate]

Let's say I have to generate random number from 1 to 100, however, the probability of each number is not 1/100, but a predefined probability. How to generate that number? I use Ruby/Python.
1
vote
4answers
116 views

Efficient “Object with weights” structure

I need to find an "efficient" data structure / set of algorithms to do the following things: I have a list of objects. I need to assign them weights and later on increase or decrease these weights. ...
0
votes
1answer
110 views

Simple unicode application?

I want to create simple language learning applications to help friends in learning languages. A simple Java console application would do the trick, but the Windows console does not seem to handle ...
0
votes
2answers
121 views

At what point should you start putting functions in a new file? [closed]

I'm currently writing a python script. It's currently about 400 lines long, and it seems like it's getting a bit long, as when I'm trying to scroll through it with eclipse it takes a bit to get from ...
0
votes
1answer
71 views

Should an object query its owner?

I have a World class World: def __init__(self): self.size = 10 self.n_busStops = 10 self.busStopMatrix = SpatialGraph(self.size, self.n_busStops, 1.0) self.buses ...
1
vote
2answers
61 views

Should I store x,y coordinates as an array, a class object, or two variables?

I have a MyObject which has an x and y coordinate. as far as I can see, I can store it in three ways: class MyObject: def __init__(self, x, y): self.x = x self.y = y class ...
-2
votes
0answers
10 views

Notepad++ For Normal Text and Syntax Highlight? [migrated]

I want to use Notepadd++ for taking notes on python programming language. I want to write some normal sentences and also write codes on same page simultaneously. I don't want to show line numbers for ...
0
votes
0answers
20 views

Python IZIP list comprehension returns empty list [migrated]

I have a list of strings that I am sorting. There are 12 different key strings within the list that I am using to sort by. So instead of writing 12 separate list comprehensions I would like to use a ...
13
votes
5answers
1k views

Is it a good practice to declare instance variables as None in a class in Python?

Consider the following class: class Person: def __init__(self, name, age): self.name = name self.age = age My coworkers tend to define it like this: class Person: name = ...
1
vote
2answers
106 views

Is creating and writing to one large file faster than creating and writing to many smaller files in Python on Linux?

If using Python on a Linux machine, which of the following would be faster? Why? Creating a file at the very beginning of the program, writing very large amounts of data (text), closing it, then ...
-2
votes
1answer
98 views

Where does the name “psycopg” come from? [closed]

Apologies if here is not the place to ask, but so far google, the documentation and the faq page are not giving me an answer.
36
votes
2answers
4k views

How do I move away from the “for-loop” school of thought?

This is a rather conceptual question, but I was hoping I could get some good advice on this. A lot of the programming I do is with (NumPy) arrays; I often have to match items in two or more arrays ...
0
votes
0answers
3 views

How can I set “no subprocess” for Python IDLE other than shortcut [migrated]

I have been able to get my favorite Python tool, Python iDLE, to work by starting it with a windows shortcut to IDLE.BAT with a -n (no subprocess) at the end of the TARGET string. Is there a ...
3
votes
2answers
198 views

Which programming idiom to choose for this open source library?

I have an interesting question about which programming idiom is easier to use for beginner developers writing concrete file parsing classes. I'm developing an open source library, which one of the ...
1
vote
0answers
12 views

Is this a good place to ask a question i have about programing? [migrated]

I have asked the same question twice about a program on python and it keeps getting put on hold and i thought this was a good place to ask programming questions and I just wanted to make sure.
2
votes
2answers
200 views

Why doesn't Python have a “flatten” function for lists?

Erlang and Ruby both come with functions for flattening arrays. It seems like such a simple and useful tool to add to a language. One could do this: >>> mess = [[1, [2]], 3, [[[4, 5]], 6]] ...
4
votes
4answers
601 views

How does Python compile some its code in C?

I read that some constructs of Python are more efficient because they are compiled in C. https://wiki.python.org/moin/PythonSpeed/PerformanceTips Some of the examples used were map() and filter(). I ...
3
votes
1answer
143 views

What is the right way to process inconsistent data files?

I'm working at a company that uses Excel files to store product data, specifically, test results from products before they are shipped out. There are a few thousand spreadsheets with anywhere from ...
0
votes
2answers
136 views

One boilerplate class or many similar classes?

Lets say I'm trying to model a variety of objects that are virtually identical, the only difference being their class variables. Am I better off creating one boilerplate class and just calling the ...
3
votes
2answers
92 views

Should I use nested matrices or dictionaries?

As per Should I ask my question about which data structure to use here? I'm asking this here. Hopefully this isn't too implementation specific. I'm currently developing a program that will represent ...
0
votes
1answer
59 views

Where to save something between invocations?

The 2nd time I run this program I'd like it to start in the same HDD location as the previous instance. How should I save, or remember, where I was so the program starts in the same place? I'd like ...
1
vote
3answers
160 views

How do I test my code in Python other than by doing it by hand?

I am used to user testing in Java, and I also manually test each section of code I write, but now, I want to automate it. There is no GUI for this project, so user testing is not required and I can ...
0
votes
1answer
136 views

Best Practices For Temporary Scripts (Python)

I am running two separate programs which are similar enough that they share a lot of code. I run these programs often and after I evaluate the output. This is a very fluid process and everytime is ...
0
votes
1answer
89 views

Python case statement? [duplicate]

I made a simple Python script that takes user input in order to generate a series of mathematical responses. In one part I did this: while True: And iterated through the loop until I used an if ...
0
votes
2answers
101 views

How to route messages between clients using a central server in Python

I've got three Raspberry Pis sitting around. I want 2 of them to be able to chat while the 3rd routes the messages (acts as a server between them). The general flow of events should be something like ...
2
votes
1answer
197 views

How do you make decorators as powerful as macros?

Quick background: I am designing a Pythonic language that I want to be as powerful as Lisp while remaining easy to use. And by "powerful", I mean "flexible and expressive". I've just been introduced ...
0
votes
3answers
94 views

How to convert this recursive problem to iterative? Line Simplification algorithm fails to run due to Maximum Recursion Depth being hit

I am implementing the Douglas, Peucker's Line Simplification algorithm in Python. I started with this implementation. However, it fails to run in Python due to Maximum Recursion Depth being hit. How ...
0
votes
1answer
75 views

Running Python script in background on Mac

I have a Python script that counts the number of file in a folder, and if the number of files exceeds 10 then it creates a popup window to ask the user to clean up the folder (I use tkMessageBox). ...
1
vote
1answer
135 views

Is Lambda Still Supported In Python?

Only one or two years ago, I remember reading Python constructs that would be removed from Python -- reduce was one of them -- and other constructs that would be emphasized like comprehensions and ...
1
vote
1answer
131 views

Should I separate a web api from the webserver?

Lets say I'm building a site similar to this or Quora (or some arbitrary blog-like site). I need a real-time component that will be using web-sockets/long-polling to notify the user of new posts, ...
8
votes
5answers
915 views

Are there technical limitations or language features that prevent my Python script from being as fast as an equivalent C++ program?

I'm a long-time Python user. A few years ago, I started learning C++ to see what it could offer in terms of speed. During this time, I would continue to use Python as a tool for prototyping. This, it ...
1
vote
2answers
50 views

Django CBVs vs FBVs

For creating a large Django project with many apps, my first initial thought was to used Class Based Views (as the Django tutorials seem to emphasize). However, I noticed that due to a lot of the ...
3
votes
1answer
261 views

Good practice for returns in Python

I was recently working on some prototype code in Python. The code worked great, then I realized that I needed a little more feedback from one of my functions so I changed the return statement from ...
0
votes
2answers
108 views

the perils of using eval() for dynamic object creation — is this a valid argument in a consenting-adults culture?

I've read on stackoverflow explicit warnings against using eval() to create objects. The reason that seems to be given is that malicious code could be injected and blindly created objects could ...