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)

-1
votes
2answers
42 views

Function has two sets of arguments, the latter of which calls a nested function?

The function foo, has a nested function; bar. Calling foo with a second set of arguments feeds them into bar if bar is returned at the end of foo. How does this work and what is it called? Are there ...
-3
votes
0answers
33 views

Can you run a Python shell on a website page? [on hold]

I am currently working on a python built Choose Your Own Adventure game, which runs in the python shell, with ASCII art and such. Out of interest, is it possible to host this on a web page so the user ...
0
votes
0answers
63 views

Is there a way to prevent variables from changing their type in Python?

It is useful to have the interpreter derive the type of a variable automatically. This on its own is similar to the auto keyword in C++11. However, in Python variables can change their type after ...
0
votes
0answers
36 views

Functional dependencies diagram

I'm searching for the correct type of diagram in which I can see all dependencies between the functions, classes and files of my Python program (multiple files). It's for cleaning purposes. So my ...
-2
votes
1answer
151 views

Base Class, with method that returns Derived Class. design flaw?

I'm writing a Math equation solver in python (for fun). The first design that came to my mind: Expression: base class for every item in an equation (maybe bad name). BinaryExpression extends ...
-2
votes
0answers
18 views

ML on text / documents [on hold]

I have numerous amount of explanations of one term. I want to classify them on the based on simplicity or understanding. How to go about it?
-2
votes
0answers
14 views

Print the longest common sequence [migrated]

I am trying to implement solution of the classical problem, but I am confused as I get some cases where I don't find good results. Output: "The Longest common sequence", "Length" def ...
-6
votes
1answer
85 views

“if” statements within a function [closed]

Tell me what's wrong with this code, I'm a newbie: def func(): variable = str(raw_input("Enter a Capital Letter: ")) if variable == "A": return "Z" elif variable ...
-4
votes
0answers
14 views

how to sum lists in lists pairwise in python and put this sum in a new list [migrated]

the question is pretty clear but an example: a = [[1,2],[3,4],[5,6],[7,8]] then the list I want to make is: a_new = [ 1+3+5+7 , 2+4+6+8] The lists within the list are always of the same length ...
2
votes
3answers
63 views

Lambda expressions with no parameters in Haskell and / or lambda calculus

In eager languages like Scheme and Python, you can use a lambda expression without parameters to delay evaluation, e.g. in Scheme (Chicken Scheme): #;1> (define (make-thunk x) (lambda () (+ x 1))) ...
0
votes
1answer
58 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 ...
-3
votes
0answers
28 views

Creating an R package with Python source code [closed]

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 ...
2
votes
0answers
60 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 ...
2
votes
1answer
48 views

Python property best practices [closed]

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
115 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
57 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
134 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
94 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
112 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
122 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 ...
4
votes
6answers
147 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
110 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 ...
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 ...
3
votes
2answers
199 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 ...
2
votes
2answers
206 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
608 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
144 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 ...
1
vote
2answers
495 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
93 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
163 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
138 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
92 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
203 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
95 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
76 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
139 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
132 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
917 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
52 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 ...