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)

-4
votes
0answers
9 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?
1
vote
0answers
26 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
33 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 | ... ) ...
1
vote
1answer
36 views

Python property best practices

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
102 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', ...
3
votes
2answers
118 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 ...
-4
votes
1answer
33 views

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

How can I SSH via python script into a linux box run a command (Date) and use the output in the local script?
-1
votes
1answer
225 views

How do I create every permutation [closed]

I have a list of letters, this is just an example list: ['a','b','c','d','e'] How do I compute every combination of the list? The letters cannot repeat, for example. a,b,c,d,e a,c,b,d,e a,c,d,b,e ...
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). ...
-5
votes
0answers
42 views

What is the most concise solution for text and file processing? [closed]

I need to do text processing in files such as "replace the second column of the third line of all files in the current folder with the string 'hello'" or "list all files in folder ./Hello and write ...
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 ...
16
votes
8answers
1k views

What are good unit tests to cover the use case of rolling a die?

I'm trying to get to grips with unit testing. Say we have a die which can has a default number of sides equal to 6 (but can be 4, 5 sided etc.): import random class Die(): def __init__(self, ...
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
91 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.
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 ...
0
votes
2answers
134 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 ...
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 ...
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. ...
3
votes
1answer
142 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
119 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 ...
1
vote
2answers
60 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 ...
25
votes
4answers
3k views

Why aren't there other programming languages that compile to Python bytecode?

In Java, there are multiple languages that compile to Java bytecode and can run on the JVM -- Clojure, Groovy, and Scala being the main ones I can remember off the top of my head. However, Python ...
-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 ...
1
vote
2answers
555 views

What is the proper name for this design pattern in Python? [closed]

In Python, is the proper name for the PersonXXX class below PersonProxy, PersonInterface, etc? import rest class PersonXXX(object): def __init__(self,db_url): self.resource = ...
1
vote
2answers
408 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 (oh my...). As you know, Django app contains two main directories for front-end: ...
1
vote
1answer
183 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 ...
7
votes
3answers
307 views

Does it make sense to develop open source python library for database inspection? [closed]

Some time ago I came up with an idea for a library for database inspection. I started developing it and got some very basic functionality, just to check if that's possible. Recently however, I get ...
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 ...
2
votes
2answers
199 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]] ...
7
votes
6answers
2k views

Python mutable default argument: Why?

I know that default arguments are created at the function initialisation time and not every time the function is called. See the following code: def ook (item, lst=[]): lst.append(item) ...
4
votes
3answers
685 views

What's the best way to create a static utility class in python? Is using metaclasses code smell?

Ok so I need to create a bunch of utility classes in python. Normally I would just use a simple module for this but I need to be able to inherit in order to share common code between them. The common ...
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 = ...
3
votes
2answers
196 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
2answers
105 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 ...
1
vote
4answers
3k views

Using Django without a database

Is Django a good solution for creating applications that won't use any database and communicate only through an internal API?
0
votes
3answers
92 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
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 ...
0
votes
2answers
92 views

Need help understanding a recursion example in Python

Python is my first programming language, and I'm learning it from "How to Think Like a Computer Scientist". In Chapter 5 the author gives the following example on recursion: def factorial(n): if n ...
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.
4
votes
4answers
597 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 ...
17
votes
9answers
4k views

Why hasn't C# gained much traction within the opensource community? [closed]

I'm not expecting C# to be on par with say Java or Python in the open source community, but it still surprises me just how far behind it is. 'Multi language' open source repos like google code or ...
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 ...
8
votes
5answers
913 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 ...
3
votes
2answers
90 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 ...
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 ...