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)

-2
votes
0answers
16 views

How many ways to get a fixed number that is the sum of three numbers?

Let's say you want to find out how many ways there is to make the number 5 using three numbers, which are added together. These are some of the ways: 005 => 0 + 0 + 5 = 5 122 => 1 + 2 + 2 = 5 ...
-5
votes
0answers
12 views

How do I write a reddit bot which will post stuff on a daily base? [on hold]

I want to program a bot for reddit. Where do I start? I need to solve following things (in pyhton): Log in with an account. Post comments on threads in a special subreddit. On a Daily base. For the ...
1
vote
2answers
69 views

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

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
44 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, ...
0
votes
2answers
72 views

Better way to check multiple variables equal a single value in Python

In Python I want to check the following: if x is None and y is None and z is None and ... I'd rather say something like: if x, y, z is None: But that's not valid syntax. Is there a better way to ...
0
votes
0answers
20 views

How can I make a Python deserialization function useable from another module? [migrated]

I have some serialization and deserialization code which works well within one module (and within the universe of classes I care about). E.g. class A(...): ... class B(...): ... def ...
0
votes
0answers
50 views

Python Micro-services Architecture

I have a Python-Flask webapp that stores data in MongoDB using an ORM. I want to extend this app and add a Apache Storm based micro-service that will require read & write access to dbs of the ...
1
vote
1answer
68 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
71 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
22 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
52 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 ...
1
vote
4answers
178 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
166 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
109 views

How to approach hours forecasting

I have a django web app and I basically 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 ...
0
votes
1answer
56 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
27 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
57 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
76 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
0answers
58 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 ...
0
votes
0answers
3 views

Subprocess writing stdin and reading stdout python 3.4 [migrated]

I am writing a script which would run a Linux command and write a string (up to EOL) to stdin and read a string (until EOL) from stdout. The easiest illustration would be cat - command: ...
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 ...
-1
votes
2answers
74 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 ...
2
votes
1answer
85 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 ...
-1
votes
1answer
75 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
301 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
83 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
100 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 ...
1
vote
1answer
57 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
51 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 ...
8
votes
3answers
778 views

What are “class methods” and “instance methods”, in Python?

There has been a discussion in chat relating to a question (the question itself being irrelevant to this one), that has revealed I may not know Python whatsoever. In my mind, although terminology ...
1
vote
2answers
112 views

python - differences between reusable code vs. code for solving specific tasks

Reusable code (ex. libraries and frameworks) and code written to solve a specific task and not meant to be reused as a general tool (for example, code being used only by my 6 person team in a private ...
9
votes
1answer
213 views

Python's join seems to focus not on the items to join, but on the symbol, as compared to Ruby or Smalltalk, for a design reason?

I thought one of the cornerstone of OOP is that, we have objects, which are the items we are interested in dealing with, and then we send messages to them. So it may seem natural that, I have a ...
4
votes
1answer
88 views

Explicitly fill in requirements.txt for our Python projects?

As a user of pip install package and then pip freeze > requirements.txt, I was surprised to see a requirements.txt like this: # Flask # License: BSD # Upstream url: ...
4
votes
1answer
131 views

What is the most efficient way to implement a RESTful client app?

I am working on a web application for ranking some products based on some factors. The user send a search query to 5 restful webservices which by their turn send a response in a JSON format and ...
4
votes
1answer
50 views

Signature-changing decorator: properly documenting additional argument

Let's say I have a custom decorator, and I want it to properly handle docstring of decorated function. Problem is: my decorator adds an argument. from functools import wraps def ...
2
votes
1answer
93 views

How to move Python doctest examples into another unit test framework?

Years ago AFAIK the mathematitician and software developer Tim Peters discovered that very often the documentation of APIs tends to get out of date over time during the software live cycle, because ...
3
votes
0answers
102 views

Refactoring of a client API for avoid duplicated code and unclear passage of parameters

I need to develop an API, the functions of the API are requests that call the service exposed by a server. Initially the API worked like this: class Server: def firstRequest(self, arg1, arg2): ...
6
votes
1answer
85 views

Python: Control subprocess from calling thread

I am working on a database interface to a MongoDB using Python Eve as an API. The database stores several documents containing parameters and values needed for some calculations. I wrote a Python ...
5
votes
0answers
65 views

Unit testing for data munging pipelines made up of one-line functions

Reading Mary Rose Cook's Practical Introduction to Functional Programming, she give as an example of an anti-pattern def format_bands(bands): for band in bands: band['country'] = 'Canada' ...
-3
votes
2answers
104 views

Am i looking at HTML / Django the wrong way? [closed]

So I'm comfortable programming in Python, I love the minimalist nature of the language. However, I haven't been exposed to any Django yet. I do know html, css etc for web design but when making ...
1
vote
3answers
114 views

How To Extend Parent Methods in Children Classes?

There is a parent class with a method which many children use but many children extend the method, what is the best way to extend it without violating DRY? Here are my 2 current solutions: 1: The ...
0
votes
1answer
70 views

How to periodically serialise object's state and deserialise on initialisation in Python?

We're designing an application that is supposed to monitor a system for certain events, email interested parties to prompt them to take action when relevant and parse their replies. The application ...
1
vote
3answers
225 views

Function Overloading in Python

My book says that function overloading is not possible in python but it asks me questions like: WAP to find out the volume of a cube,cuboid and cylinder using function overloading. Do I have to ...
4
votes
4answers
894 views

Why is %s better than + for concatenation?

I understand that we should use %s to concatenate a string rather than + in Python. I could do any of: hello = "hello" world = "world" print hello + " " + world print "%s %s" % (hello, world) print ...
-1
votes
1answer
67 views

Can I use Qt open-source for my web-scraping website? [closed]

I apologize if I should be understanding this more readily but I'm a little new to this and dont understand the LGPL license. Here is the FAQ for it: http://www.qt.io/qt-licensing-terms/ I am making ...
0
votes
1answer
108 views

How to document **kwargs in python? [closed]

I have a function which has a large number of arguments. I want to have the names of the arguments available in the help() function, but I want the results as a dict. At the moment, I have the ...
3
votes
2answers
181 views

Where to put very specialised functions which heavily use one class?

I have a class which is centred around lower-level methods, to make this class much more useful it would be great to put some middle or higher level methods (i.e. methods which make a series of calls ...
0
votes
1answer
41 views

Architecture/technology for implementing Management console [closed]

I'm having a distributed environment which include several machines under the same network , which are being controlled by another computer in another network which is also running a UI for doing the ...
0
votes
1answer
103 views

Docstring convention for Python __str__, __unicode__, and __repr__ class methods

What is the docstring convention in Python for the following "magic" class methods: __str__ __unicode__ __repr__ Should I add docstrings for these? If yes, what should they say (for each)?
3
votes
1answer
113 views

A condition on an argument used in multiple calls of a method: enforced by caller or by the method?

Let's assume I have an object a of a class A. It has a method that needs an argument in form of another object of a particular type - but the argument should also be in particular state, because the ...