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 ...
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:
...
-1
votes
0answers
18 views
CPython Function Return Type
I have a python function that returns a set. I want this function to be converted to C so I have defined with cdef, but I am not sure what the return type should be?
For example, let's say I have ...
16
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 ...
-4
votes
0answers
34 views
Is it possible to make a python server that takes commands from netcat? [on hold]
Title says it all. I want to run a python program that takes commands sent by netcat. I don't even know where to start :/ any help would be greatly appreciated
0
votes
0answers
5 views
Why trunc(4.9999999999999999) ==5, but trunc(4.999999999999999) ==4? [migrated]
Why trunc(4.9999999999999999) ==5, but trunc(4.999999999999999) ==4?
-1
votes
2answers
67 views
Detecting Persons In Seats from Image [on hold]
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
0answers
62 views
Does exponentiation bind tighter than multiplication in Python? [closed]
Does exponentiation bind tighter than multiplication in Python? That is, is x * y ** z the same as x * (y ** z) or as (x * y) ** z? Give a test case and argue which one binds tighter!
I got that x * ...
-6
votes
0answers
25 views
divide by zero error exception in a calculator class [closed]
class calculator:
def mult(x,y):
mult=x * y
print(mult)
def sub(x,y):
sub=x-y
print(sub)
def div(x,y):
sub=x/y
print(sub)
try:
...
3
votes
1answer
74 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 ...
0
votes
1answer
40 views
Create arithmetic expression from number using +-/* that equals target
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
0answers
56 views
looking for books to learn [closed]
I am about to get my B.S. in Computer Science and as I start looking for jobs I start to notice that most job posts ask for stuff I do not know. As a solution to this I've started to look up these ...
-1
votes
0answers
36 views
Scraping ebay geographically by state
I'm writing a python script to scrape eBay for all listings that match a certain set of search terms, and are being sold from within a particular state. The basic approach I started out with is:
...
5
votes
3answers
276 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
78 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
89 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 ...
0
votes
0answers
3 views
How to assign a binary zero character to a variable in python? [migrated]
Like in perl we do:
use constant MSG_TERMINATOR => "\0";
where MSG_TERMINATOR is a variable.
What is the way of do the same in python?
0
votes
1answer
46 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
45 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
648 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 ...
2
votes
2answers
105 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
198 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 ...
3
votes
1answer
60 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
125 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
47 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 ...
3
votes
1answer
87 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
93 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
77 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
61 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
91 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
108 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
216 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
886 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
59 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
103 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
180 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
39 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 ...
-1
votes
1answer
90 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
112 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
91 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 ...
5
votes
3answers
440 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
180 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 ...
4
votes
1answer
90 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
93 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
739 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
68 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
80 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
76 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
56 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
123 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"
...