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
vote
1answer
81 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 ...
11
votes
3answers
7k 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
140 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
228 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 ...
5
votes
1answer
253 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: http://github.com/mitsuhiko/...
5
votes
1answer
221 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 ...
5
votes
1answer
95 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 custom_decorator(f):...
3
votes
1answer
123 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 ...
4
votes
1answer
192 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
121 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 ...
9
votes
1answer
176 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' ...
-4
votes
2answers
156 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
152 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
74 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
267 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 ...
6
votes
4answers
5k 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 ...
-2
votes
1answer
157 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
146 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
183 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 ...
1
vote
1answer
45 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
167 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 ...
1
vote
0answers
141 views

Is the logic behind `Asyncio.wait()` and async/await, the same, just the code is written differently (syntax)?

I'm learning Python, more specially parallel programming using Python Parallel Programming Cookbook by Giancarlo Zaccone. At the time the book was published async/await was still in the beta version ...
4
votes
3answers
718 views

Why do you need “self.” in Python to refer to instance variables?

I have been programming into a number of languages like Java, Ruby, Haskell and Python. I have to switch between many languages per day due to different projects I work on. Now, the issue is I often ...
0
votes
2answers
227 views

Does Python have any features which can be used for encapsulating private data?

Usually in OOP world we are told that modularity is a good practice and keeping loose coupling between module is a great thing. Encapsulation helps us achieve this loose coupling. In Java ...
5
votes
1answer
96 views

Enclosing main invocation of a function in an if

As a part of my school CS class, I am reading Python Programming by John Zelle. In the book, Zelle talks about surrounding the invocation of a main method with if <condition>: main() ...
4
votes
2answers
159 views

Sort a list while putting together or after?

I have to read through an extremely large amount of network data from various log files, and compile relevant information about that data to perform statistical analysis on it (the top communicators, ...
6
votes
2answers
850 views

Bad practice to define constants based on a function call?

In Python when writing file management scripts I will often have a base path that is a constant, BASE = "C:/" Of course I'll be using that base path to create other paths later on, including other ...
0
votes
0answers
140 views

Why use Python's asyncio with coroutines to implement a server

I use Python's asyncio library to create a server that can handle telnet requests. Because asyncio's server loop is single threaded, I thought it would make more sense that when asyncio tells me that ...
0
votes
1answer
141 views

Parsing conditional statements

I've written a small utility in Python3 to help me copy my music collection from my NAS to a mobile device. The usefulness of this is that it will auto-convert flac files to ogg-vorbis (to save space) ...
0
votes
1answer
152 views

What i and n stand for in python? [duplicate]

I've been writing a program to pick random words from my list. However, to do that I had to imitate some solutions on the internet, and I succeeded. Unfortunately, there is something that I can't ...
0
votes
1answer
505 views

Python - Cache function and decorator

I am playing with cache functions using decorators. First, I use a generic function def memorize(func): cache = {} print "printing cache" print cache print "cache printed" ...
-1
votes
3answers
140 views

Python — Class and Object [closed]

I got a question that quite disturbs me a lot and I think it might help a lot if I had an answer to it. So I got this: class Klasse1: variable1 = "haha" class Klasse2: variable2 = "hoho" ...
2
votes
1answer
91 views

Why is Python sorted() result like this?

I might be missing something obvious here, but why does Python 2.x sorted() function work like this? In [95]: l = [1, '5', 4, 2, '3', 'b', 'c', '-a'] In [96]: sorted(l) Out[96]: [1, 2, 4, '-a', '3', '...
0
votes
1answer
56 views

Are there any pitfalls when replacing a Python module using sys.modules?

In a current project of mine, I have decided to not put any significant amount of code in __init__.py files, simply because I don't like them. In my head, an __init__.py file is just there to inform ...
2
votes
1answer
92 views

How does the Python runtime know which object a method is bound to?

When defining methods in a class we do have an argument for the object on which the method is invoked i.e self. Say I have a class Foo. class Foo: def m(self): pass now when we have an ...
0
votes
1answer
193 views

How to do reports from python [closed]

This is not a question, asking for a (single) tool, although to answer my question, of course tools are involved. The focus of this question is, asking for advice in which direction to head for. I ...
1
vote
2answers
102 views

What is the difference between proxy class and delegation in Python?

Wiki: A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, ...
5
votes
2answers
495 views

How are scripting languages compiled?

I know the term "scripting languages" is just a subset of programming languages, but I want to refer to programming languages such as Python and Ruby among others. First of all, why don't we need a ...
7
votes
2answers
2k views

how to refactor many singletons

I have a medium-sized python program (~5000 lines of code), which I've built up over time, with no particular plan as I went ahead. The architecture I've ended up with consists of 5-6 large Singleton ...
2
votes
0answers
56 views

Assess the quality of third party python packages

I'm developing a application in Python and I've found various packages on pypi which appear to be what I need. However, how do I know I can trust these lesser known packages - it only has a couple ...
0
votes
2answers
1k views

How does the communication between a chat server and client work?

(Socket programming newbie here...) So, for learning purposes I've just started developing a chat server and client in Python, and I was wondering how it is usually implemented. When someone ...
1
vote
0answers
92 views

Eliminate repetitive code with variables? [closed]

I'm trying to eliminate a lot of repetitive code in my Python and this function repeats itself in various forms. Is there not an easier way I can just pass a variable (using a list or similar) to the ...
4
votes
4answers
233 views

Should exceptions be raised higher up or lower down or both? [closed]

When calling some function in a Python application, the function often calls functions deeper down which again call functions deeper down, etc. It is easy to unknowlingly pass a bad value to the top-...
2
votes
2answers
330 views

Python OO problem

I started learning Python yesterday and I ran into a problem. I like to hear some thoughts on it. As an exercise, I decided to build a chatserver. As part of the exercise, I wanted to write some ...
7
votes
1answer
401 views

Why is universal newlines mode deprecated in Python?

I just noticed that the universal newline feature of file operations seems to be on its way out. The documentation for Python 3.5 open's mode parameter indicates that it's deprecated: 'U' ...
2
votes
1answer
168 views

Type checking as opposed to multiple functions?

In statically-typed languages such as Java, code such as the following is common (not much of a realistic example, I know): public String flip(String text) { String result = ""; for (int i = ...
0
votes
1answer
182 views

How to Handle Duplicate Web Requests on Server

I'm running a Twisted web server and trying to figure out a good way to handle retries from the client. In normal operation the client makes a request of the server with some JSON data and receives a ...
5
votes
1answer
122 views

How to organize my module

This is currently the way I'm organizing it. myProject/ README subproject1/ __init__.py classA.py classB.py driver.py basicTest.py Driver imports ...
4
votes
2answers
996 views

Exception handling in Python - Am I doing this wrong (and why?)

I've read many questions and articles on exception handling in Python (and in general), but I still think that it's the most confusing thing ever. I ended up doing something like this: # error class ...