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
44 views

Deciding on a Portable Platform (given a set of requirements)

Background Before asking this question, I researched this site and found the following 3 most similar questions have already been asked: When would using a scripting language within a larger program ...
3
votes
1answer
106 views

Avoiding tightly coupled class definitions in Python for has-a relationships

I have the following code: class Car(object): def __init__(self, my_id): self.my_id = my_id self.color = color self.brand = brand self.get_color() ...
1
vote
1answer
59 views

Python's __get/set/delattr__, ordinary assignment versus __setattr__, __dict__ vs dir()

I have a few more related OOP Python questions: What does these attributes do exactly: __get/set/delattr__? Why not use just Myclass.NewAttr = value instead of __setattr__? Why does Python use ...
1
vote
0answers
77 views

Why my greedy algorithm not working for merge stone problem

Merge Stone Problem: You have n piles of stones in a line. For example, [4, 1, 2] means 3 piles of stone, the first pile has 4 stones, the second pile has 1 stone, and so on. You task is to merge ...
1
vote
1answer
119 views

Questions on Python Attributes and dir()

I have two inter-related questions about attributes and dir(): What are attributes? Is it an object inside of another object? Or is it a method, property, etc? When you do dir(), what's the ...
9
votes
3answers
2k views

Ensure unsafe code is not used accidentally

Note: I do know eval() is dangerous and can usually be replaced by something safe. My goal is to learn rather than find a solution to an existing problem (Besides, I will be replacing completely the ...
1
vote
1answer
99 views

Is this the right way to use classes on this project?

Before any down voting or blaming, please bear in mind that this is my first "serious" Python project. Before this I have only coded a program that uses several Google API's to do stuff, and not much ...
0
votes
1answer
113 views

How to structure huge conditional statement?

I'm creating some kind of a "personal assistant" application which is basically a web service that receives a message and then does something according to it. For example I send "what time is it?" ...
4
votes
2answers
112 views

If I create a desktop application using Tkinter, PyGTK or PyGame does my app have to be open source?

I intent to start learning desktop gui programming, so I've been looking to Python and it's Tkinter, PyGTK and PyGame. But I want to make proprietary software, so I'm concerned because of the licences ...
0
votes
0answers
73 views

Class design of keyboard interpreter to execute commands

I'm designing a keyboard interpreter that will map typed characters to a (or many) command(s) via a hierarchical menu-style structure, taking into consideration testability (ideally TDD). However I'm ...
1
vote
0answers
72 views

Does PyPy or Jython run untrusted Python 3 code more secure while still being fast?

I know that one can not securely restrict normal CPython's capabilities to properly run foreign code without allowing it to access some builtins like open() or allowing other kinds of I/O. So I ...
3
votes
1answer
177 views

Etiquette: How to respond to a Open source release Mail? [closed]

So I was lucky to be able to contribute to DateUtil in python(just a small documentation). I recently received a mail regarding the release 2.5.0 . So I was all exited because it was the first time I ...
0
votes
1answer
105 views

Database vs. Pickle (Python) [closed]

I'm writing a small application in Python that stores data via pickle. Initially, I was trying to decide between pickle and a database solution, and went with pickle to try something new. What I want ...
3
votes
1answer
116 views

Confused about approach I should take to designing classes for a card game

My primary goal is to create a Euchre game in Python. Euchre card games are rare on the Linux platform, no matter the language or the desktop flavor of choice. For now I want to be able to just ...
2
votes
1answer
120 views

Should I store cryptographic hashes as a blob or as a string?

I'm new to MongoDB and am wondering how to decide to store some cryptographic hashes. Should I store the binary data itself, as a blob, or should I store its string representation as a string? My ...
3
votes
0answers
81 views

How to think about a schedule that pulls from a database as objects

I am working on a personal project using Python. I have been using version control to the best of my abilities and if you would like to check it out and run the app ...
4
votes
2answers
491 views

Why do textbooks use pseudocode rather than real languages?

In colleges and in algorithm textbooks, it is quite common for the teacher and author to explain control flow in pseudo-code. With the advent of more expressive languages like Python and Haskell among ...
1
vote
0answers
20 views

Python: architecture implications of using external subprocess or API

I maintain a Python 3 package (ocrmypdf) that works with other programs primarily by making subprocess calls. This is partly for historical reasons – it is shell script that grew up. I have since ...
2
votes
2answers
52 views

Pattern for requests with long response times?

We are currently maintaining a homegrown python "web server" where generating the response for some requests can take a very long time mostly due to heavy computations - these requests are basically ...
2
votes
1answer
58 views

Initializing composite classes in Python

I am writing a Python system where I have a major class(PlayerModel) that has two another classes as members (StateModel and ActionModel). I was wondering, what is the correct way to initialize such ...
7
votes
1answer
196 views

How should the code for a program outputting to command line be tested/designed?

Imagine a program similar to this in Python: import subprocess class Example(): _cmd_args = (['ls', '-a', '/usr/bin/'], ['ls', '-al', '/usr/local/bin/']) _default_args = 0 def ...
0
votes
1answer
81 views

What is considered best practice for custom exception classes?

Python has many strong conventions but I'm unclear on how best to manage exceptions for my module. I know it's generally good practice to define a custom exception for your module. E.g.: class ...
0
votes
0answers
43 views

How to distribute a project with all its dependencies?

We are developing a system for a customer that does not want to allow installation of packages from outside repositories. The project is in Python and defines its dependencies via setuptools; most of ...
0
votes
1answer
100 views

How to make it clear I'm violating Command Query Separation

Command Query Separation is a useful principle, though it's not always ideal. Sometimes you need to run a process, which will result in useful data you need to return. My specific case is uploading a ...
0
votes
3answers
125 views

Why don't empty iterables in python raise Exceptions when you try to iterate over them [duplicate]

I find this behaviour in Python quite peculiar and I believe it can lead to many bugs especially if you have a function/method that takes in a list and returns another list after carrying out some ...
-2
votes
1answer
98 views

Dynamic things to test, does it make sense? [closed]

I wrote like seven tests for testing if our network topology was working fine. Each one in a file, so I had test1, test2, test3... However, right now my boss is asking me for something more dynamic, ...
1
vote
1answer
80 views

Parsing JSON and creating analytics out of the data, what is the best way to do it?

I am on a project where I call an API and I want to make statistics with the data returned. It returns a big .json object. As that is not possible to flatten, and I am not interested on all the data ...
7
votes
4answers
294 views

For Python programming and being Pythonic, why “never is often better than *right* now”? [closed]

In the Zen of Python, I can understand most parts of it, except: Now is better than never. Although never is often better than *right* now So I think doing it now or getting results now is better ...
1
vote
1answer
59 views

Is it a common pattern in Python to have instance variables assigned in a constructor start with an underscore?

I recently started using UtilSnips, a Vim plugin allowing for a certain level of automation while coding by using template-like code snippets for common code fragments (class and function definitions, ...
1
vote
1answer
388 views

Python file naming convention?

I've seen this part of PEP-8 https://www.python.org/dev/peps/pep-0008/#package-and-module-names I'm not clear on whether this refers to the file name of a module/class/package. If I had one example ...
1
vote
1answer
80 views

Does exception handling belong at the lowest level of the runtime?

I'm designing a fairly simplistic stack-based programming language, and implementing it in Python. (no link, because it's not fully implemented yet.) The language itself is essentially intended to be ...
0
votes
0answers
28 views

How can word lists be used as supervised data in finding the score of the report?

We have got historical reports and we need to find the score (whether report is effective or useful or not) based on supervised learning. While doing the supervised learning process, we have to ...
1
vote
2answers
75 views

Should I include scripts inside a Python package?

In my Python application, I can distinguish between entry points (scripts) and what I think of as library code. My instinct is to put the library code inside a package, and the scripts elsewhere ...
5
votes
4answers
249 views

Handling exceptions I don't know about

When I work with handling exceptions, I notice that I often have to deal with the ones I had no idea about. Especially it is noticeable when I program a method that grabs data from web. An error may ...
0
votes
2answers
641 views

Why is Python 3.4 still developed after the release of 3.5? [closed]

The lastest version of Python is 3.5.1. However, the latest release is 3.4.4. Why is 3.4.x still developed? Are there breaking changes in 3.5 with respect to 3.4? https://www.python.org/downloads/
0
votes
2answers
235 views

How to approach hours forecasting

I need to forecast budgeted hours for 2 departments to help them schedule staff as currently the best they can do is just wing it. When we receive a job proposal I'll have the person submitting the ...
-1
votes
1answer
88 views

Developing an app using Django. Do I design front-end after app? Or develop Django to fit UI? [duplicate]

Edit: this differs from a similar question because I'm interested specifically in how Django works with the front-end. I.e. what is considered best practice when developing using the Django framework. ...
1
vote
0answers
32 views

How do I minimize the number of database queries in a GeoJson API (of countries, and smaller areas) with custom data?

The general version of the question is above - a a little more detail, I am using Django Rest Framework, but am happy for answers to be dealing with the problem in abstract. So, I have data with ~200 ...
2
votes
1answer
66 views

Passing in objects to __init__ or passing a common param to and constructing objects inside __init__?

I have a class Foo that creates instances of other classes A, B, and C in its constructor. A, B, and C share the same constructor parameter and are used in other parts of the codebase, not just in ...
0
votes
1answer
88 views

How can you catch all index out of range errors in python?

Our program does these kinds of operations hundreds of times for many different variables and lists, then uses them throughout the program: variable = values[5] The list values are coming from the ...
2
votes
1answer
88 views

How to find related articles among a set of articles?

I'm utilising OpenCalais API to tag the articles from multiple news sources. I know which category each article belongs to (e.g. crime, politics etc). Also each article has three social tags ...
23
votes
1answer
2k views

Why does the documentation on some languages say “equivalent to” rather than “is”?

Why does the documentation on some languages say "equivalent to" rather than "is"? For example, the Python Docs say itertools.chain(*iterables) ... Equivalent to: def ...
-2
votes
2answers
86 views

Detecting Persons In Seats from Image [closed]

I am attempting to build an attendance program which could analyze if someone is sitting in a seat. The seats are fixed making knowing where each seat is easy, but I don't really know where to start ...
3
votes
1answer
90 views

How do I manage quickly changing python modules

I write Python code for scientific computation. As it is research I face among other two problems: the demands are quickly changing results need to stay reproducable Imagine you have a package A ...
-2
votes
1answer
161 views

Create arithmetic expression from number using +-/* that equals target [duplicate]

For example, you are given the source 1234 and the target 24. The task is to use the standard arithmetic operators +-/* placed within source, without changing the order of the digits of source to ...
4
votes
3answers
342 views

Is it ok to have multiple classes in the same file in Python?

I'm freshly coming to the Python world after years of Java and PHP. While the language itself is pretty much straightforward, I'm struggling with some 'minor' issues that I can't wrap my head around — ...
4
votes
1answer
88 views

Is Python's inheritance an “is-a” style of inheritance or a compositional style?

Given that Python allows for multiple inheritance, what does idiomatic inheritance in Python look like? In languages with single inheritance, like Java, inheritance would be used when you could say ...
4
votes
1answer
133 views

Using Python's Method Resolution Order for Dependency Injection - is this bad?

I watched Raymond Hettinger's Pycon talk "Super Considered Super" and learned a little bit about Python's MRO (Method Resolution Order) which linearises a classes "parent" classes in a deterministic ...
2
votes
1answer
62 views

Question regarding the names of OrderedDict and defaultdict functions in Python

While reading Python Cookbook I came across these two lines: from collections import OrderedDict from collections import defaultdict Now see the naming conventions of the functions in ...
1
vote
1answer
60 views

How to choose python module license as python itself

I would like to publish a python module and would like to publish it as the same license of python Below is a example of how Perl module does: This library is free software; you can redistribute ...