Python is a dynamically typed, high-level interpreted programming 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 and exceptions, and has an extensive standard module library. ...
0
votes
0answers
9 views
Proper position to insert extra field/subfield
Background
I am working with JSON data.I have defined a fixed schema for my db table customer:
"name":["fname":"string","lname":"string"],"location":"string"
Now my json data is dynamic,certain ...
-4
votes
1answer
34 views
Python - units for a slope calculation
Simple question: is the result of a slope calculation in Python (say, stats.linregress() function) in units of radians, or unitless (e.g. what's 18 deg or 0.314 rad would be equivalent to 0.2 in the ...
-4
votes
0answers
21 views
Python unit testing coding standard [on hold]
I am writing code in Python and need to perform unit tests. I also need to produce a Python Unit Test Coding Standard based around unittest module of PyUnit framework. Is there a standard that could ...
-1
votes
1answer
69 views
Why do we use 'assert not' in this example?
My code takes 2 dates and finds the age of those dates in days. In my daysBetweenDates method the instructor uses an assert statement:
assert not dateIsBefore(year2, month2, day2, year1, month1, day1)...
-2
votes
0answers
22 views
Text from QlineEdit using objectName [on hold]
Is it possible to read text from QlineEdit using objectName ? If yes, how can I do it?
-5
votes
0answers
35 views
ncurses inside a window (for Windows ease of use). Possible?
I think I vaguely recall a game or two that were made with ncurses and you could just double click the .exe on Windows and get a normal game screen.
In other words, I believe the .exe contains a ...
0
votes
0answers
17 views
Python - getting record count from a streaming socket
Some context - I'm converting a function from another language (source) which has the following structure:
CompoundValue(int length, IDataHolder visible data, IDataHolder historical data)
an ...
0
votes
2answers
56 views
How to name variables that clash with functions?
As an example, in Python I have a lowest_prime_factor function which does it exactly what it says it does. Then, in another function, I need to call this function and store it. In another language ...
-1
votes
2answers
54 views
Variable can't hold str() method information with “pure” word in brackets… why?
I've recently bumped into string methods and mainly
str()
method caught my interest because, it makes string out of every type of data?
integers, booleans and so on. And if you want, they can be ...
0
votes
0answers
11 views
Python inheritance/import - parent file imported modules, should child import too or thru parent?
My apology if this question is already answered & accessible through search - not quite sure how to phrase this particular query. So, here's scenario & question:
File a.py imports several ...
-1
votes
0answers
5 views
How should we save a random value in Django views for later comparison like captcha value?
How should I save a random value in Django view that is going to be compared with user input, like a captcha string that is going to be compared within seconds or minutes?
Should I save it in ...
0
votes
0answers
42 views
Function that has too many parameters [duplicate]
I'm a junior developer learning programming in Python. I found that some of functions I write uses too many parameter, like
def f(a,b,c,d,e,g,h):
What would one recommend to avoid such a situations?...
-3
votes
0answers
28 views
Dynamic digital wallboard scala/django/php? [closed]
I want to build a system where I have to create dynamic charts using MySQL database and display the charts on scala based digital wall boards. I am not sure how to go about it? Some of the options I ...
4
votes
2answers
139 views
Not understanding the concept of how to make my GUI application
I am making a program that primarily deals with heavy data mining and analysis. It is primarily a back-end type algorithm, with no GUI elements or console windows seen as it runs. Occasionally though, ...
26
votes
8answers
3k views
Are there any design patterns that are possible only in dynamically typed languages like Python?
I've read a related question Are there any design patterns that are unnecessary in dynamic languages like Python? and remembered this quote on Wikiquote.org
The wonderful thing about dynamic ...
1
vote
1answer
45 views
Using Python, what's an effective way to wrap a command line utility?
I want to write a Python application that "wraps" a command line utility, passing through all parameters intact, except for the parameters that I choose to modify.
I imagine there's an easy way to do ...
3
votes
0answers
103 views
Advanced Job Shop Scheduling Algorithm Question
I've looked into numerous solutions for the simple version of this problem, but I've found no solutions for advanced cases, short of sorting through all possible permutations.
I don't know where to ...
0
votes
0answers
47 views
How to implement user-defined formulas (including arithmetic and if-statements)
Consider the case where a user can save a formula that may include a few predetermined variables. Say these are called words and numbers. An expression in some format might then look like this:
if(...
-2
votes
0answers
18 views
Architecture & Libraries To Use Feedback
I'm a frontend developer, fairly new to backend. I have a project I'm working on and would like feedback on how to best architect it and what libraries to use so I dont build something that ends up ...
0
votes
2answers
95 views
Finding total number of subarrays from given array of numbers with equal elements. Better approach
Given an array of numbers, count the total number of subarrays (consecutive elements) where all elements are equal.
Example: For below array
[1,1,3]
Ans: 4
Below are desired subarrays:
[1]...
0
votes
2answers
78 views
Parallel vs Simple Assignment question
I'm quite new to Python and learning it on Lynda.com, which does not seem to have any way to ask questions about lesson content. In a video about while loops there is this code:
a, b = 0, 1
while b &...
-2
votes
0answers
18 views
Locating a graphic function (Python) [migrated]
First off, thanks to the site and everybody on it. I am taking my first python class and have come across this site many times when trouble-shooting coding problems. Thanks to everybody who have ...
4
votes
2answers
207 views
Is there a convention for returning multiple items?
In Python specifically (I don't know if this generalizes) is there a "best" way to return multiple items from a function?
def func1():
return a,b #equivalent to (a,b)
def func2():
return[a,...
0
votes
4answers
233 views
How deal with negative feedback on code style from senior developer? [closed]
Background
I have been programming mainly in Python in the past years and mostly on my own projects. I have developed some of my own small stilistic conventions like leaving 4 numbers of empty lines ...
0
votes
1answer
115 views
How does one “secure” a python CLI-based application? [duplicate]
I have to provide a Python CLI-based program to one of my clients. I will give him both the compiled version (using py2exe or something simillar) of the application and the source code.
The ...
1
vote
2answers
86 views
Is it poor practice to have dynamically updated docstrings?
When I'm creating a docstring, sometimes I want to refer to a value, for instance:
def try_download(data, path):
"""Tries to download ATTEMPTS times, catching socket errors."""
Where ATTEMPTS ...
1
vote
1answer
61 views
centralize internationalized strings to prevent DRY in the tests suite vs readability
I have a program already internationalized with gettext module, however it bugs me for days whether should I centralized the strings (make them as variables, so they can be referred by the main ...
3
votes
1answer
156 views
Is it considered a bad practice to oversize an array so that negative indices behave well?
I have been practicing implementing some classic dynamic programming algorithms and was wondering if my implementation of the longest common subsequence search has a significant code smell.
In python,...
1
vote
1answer
94 views
Why is flask CLI recommended over Flask.run?
In Flask 0.11 a flask CLI was introduced. Both the docs and the changelog state this is recommended.
Development Server docs:
Starting with Flask 0.11 there are multiple built-in ways to run a ...
0
votes
0answers
25 views
Coverage report influenced by “with suppress” vs. try statement
I have some test code that does this at one point:
from contextlib import suppress
from datetime import datetime
import unittest
class BirthdayParser(object):
@staticmethod
def parse(...
0
votes
1answer
34 views
Controlling a sensor network
I am having a problem developing an object-orientated architecture to manage a network of sensors and controls. Currently, I am writing in Python, but this is more of a conceptual question.
I have an ...
1
vote
2answers
53 views
Using NotImplementedError instead of abstract classes
MyBase is forcing implementation of method f() in all children. This can be achieved either by using abc.ABCMeta to make f() an abstractmethod:
import abc
class MyBase(metaclass=abc.ABCMeta):
@...
0
votes
0answers
40 views
Pcregrep vs Perl vs Python for bash scripting when needing advanced regex features
I've lately been using pcregrep to do Perl-style group matching when doing my bash scripts.
The problem with pcregrep is that it's not readily available on Linux machines in general.
An alternative ...
0
votes
0answers
33 views
Is there a cross-platform way to execute a Python3 script fullscreen?
I'm currently developing a small CLI game in Python for practice. While I can set the shell width and height quite easily, there are lots of different screen sizes in use right now, and I would like ...
0
votes
3answers
218 views
When NOT to use a class / member variable?
I am trying to learn WHEN NOT to use:
classes
member variables
HERE IS THE CODE
access_point_detection_classes.py
from scapy.all import *
class Handler :
def __init__(self) :
...
0
votes
2answers
59 views
Object Oriented Python methods and their parameters
Let's say I have a class MyClass ... which has a data member x
class MyClass1 :
def __init__(self) :
self.x = 1
Also a method which does something with x
Should I pass self.x as a ...
-2
votes
1answer
62 views
Do .pyc files in Python contain mnemonics
I'm interested for some time in CPython implementation of Python. I understand that .pyc files contain serialized bytecode, including opcodes. However do these files contain mnemonics? I think that ...
-3
votes
0answers
25 views
Minimum value of a node in a binary search tree
I am making a program that returns the minimum value of a binary search tree recursively and I don't know how to implement it. I am stucked here, please help
def bst_min(t):
if t.is_leaf == True:
...
0
votes
0answers
38 views
Inaccurate fractional exponentiation / accurate fractional exponentiation in Python? [duplicate]
In Python, 9 ** 3 obviously is 729; why is 729 ** (1 / 3) 8.999999999999998? 9 == 8.999999999999998 gives False. Is this problem solvable?
0
votes
0answers
30 views
Developing Python Scripting API using Petrel Ocean SDK (C#/.NET)
I use a commercial software called Petrel. Petrel has a software development kit (SDK) that allows the user to develop plugins in C#/.NET via the Ocean core API.
At our offices, we have installed a ...
-3
votes
2answers
42 views
Using Python to start up multiple programs simultaneously
I am attempting to write a python script that with remove some of the tedium of my everyday actions. Specifically, I always need to run Eclipse, Java VisualVM, and a docker container.
I had planned ...
0
votes
0answers
31 views
Store as much code as possible in single folder to allow easier upgrading
I have a rather large Python code with a structure that looks like this:
my_code.py
+-- packages/
|-- __init__.py
+-- pack1/
|-- modu_11.py
|-- modu_12.py
+-- ...
4
votes
1answer
53 views
How to redistribute modified code under PSF license
I spent a few hours cleaning up a really old Python library, ProxyTypes. Two days from now will mark 10 years since it was updated. Today, I updated it to support the newer Python 3, and to be ...
2
votes
5answers
82 views
How do I systematically evaluate the performance of my Python script?
How do I know if my code is running fast enough? Is there a measurable way to test the speed & performance of my code?
For example, I have script that is reading CSV files and writing new CSV ...
-4
votes
1answer
38 views
How do I get python to recognize my DLL file as import(able)
I ran into an error stating:
"ImportError: No module named 'pywintypes'", and after some reading around, I have discovered that the DLL for pywintypes is in C:\Python35-32\Lib\site-packages\...
1
vote
1answer
91 views
Making a member function treat two objects differently in Python
I have in my program a class with a member function that should treat certain objects slightly differently than others. In order to do this, it needs to know which object was passed to it, because ...
2
votes
1answer
34 views
Variables (scalars and matrices) assignment in Python
Here are the two cases under consideration. (a)Scalars and (b) Numpy matrices. My query is about initialization and assignment.
1 Perfect
y = x = 0;
x = 7
print(x,y)
y = 8
print(x,y)
x=10
...
0
votes
1answer
59 views
Should I always use prefix private methods with an underscore in Python?
Prefixing methods and members with an underscore indicates internal use. For simple classes, I sometimes find the easier reading and typing of self.foo outweighing the indent of self._foo. Especially ...
3
votes
1answer
54 views
Reraising exception explicitly or passing it on?
This question is about coding style.
Say I have a function, f. f depends on a condition C. It calls another function g as a subroutine. g also depends on condition C. If it finds condition C is not ...
0
votes
1answer
87 views
Designing a RESTful API for a file manager
I am building a file manager web UI (front end ReactJS, back end Flask). RESTful API seems to be very suitable in this situation at first sight, but I get into trouble.
I need API contain:
List ...