Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008.

learn more… | top users | synonyms

0
votes
2answers
156 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
1answer
54 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
votes
0answers
7 views

How to determine a class objective in a list in Python? [migrated]

I create a class below, class Card: suitList = ["Clubs", "Diamonds", "Hearts", "Spades"] rankList = ["1", "2", "3", "4"] def __init__(self, suit=0, rank=0): self.suit = suit ...
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: ...
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
1answer
52 views

Multiprocessing usage and limitations [closed]

I'm not able to find any definite answers in the Python Docs. I'm looking for the limitations in 3.5 on MultiProcessing and using a worker pool. Are worker pools functionally limited to the number ...
5
votes
1answer
90 views

Object-Oriented design to create Images in Python

I'm creating images with centered text. I use Python but I'm faced with many question regarding how to write my class. I know that A class must aim to do one thing and do it well. Well, the ...
1
vote
0answers
101 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 ...
0
votes
0answers
77 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
82 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
43 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
76 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 ...
1
vote
2answers
103 views

How to achieve inheritance when using just modules and vanilla functions in Python?

Python doesn't enforce any paradigm. It gives you freedom. Python provides encapsulation at module level. If I have a module A and have a module B with same interface. How do I sort of inherit B ...
3
votes
3answers
75 views

Premature memoization on obvious cases

In the code below there will be several instances of MainClass. class MainClass(object): def f(self, x): # expensive operations. # ... return 'something' Each instance ...
0
votes
2answers
197 views

Ensuring program output is always the same [closed]

I am working on a +10k LOC program, and I need to ensure its output is always the same for given input. The program consists of dozens of modules and classes, inherited by a MainClass. (The examples ...
0
votes
1answer
81 views

How to properly handle indefinite generators in Python

Let's say we have a generator that is indefinite, where new elements can arrive at any moment with significant (up to indefinite) delay. An example of such generator is tail -F command. In python ...
0
votes
1answer
111 views

Can I listen on a port without interrupting traffic?

I have developed the bare bones on a socket server in Python. I'm trying to capture the HTTP packets going to a web server without blocking them. try: self.socket = ...
5
votes
2answers
982 views

Does this code follow duck typing?

The principle of duck typing says that you shouldn't care what type of object you have - just whether or not you can do the required action with your object. For this reason the isinstance keyword ...
0
votes
0answers
32 views

Ipython3 development cycle

I am new to python (python3) and am using Ipython3 while writing the code just in my preferred text editor. I am not yet sure what is a good development cycle as I keep getting problems with reloading ...
2
votes
1answer
50 views

log method calls per object

How to log method calls on a per object basis for a particular class? I.e. after instanciating a = myClass() I somehow want to keep a log for what methods have been called on a like a.reverse() ...
-2
votes
1answer
528 views

Dictionary representation of an object

As python memory model is dictionaries of dictionaries, looks like any object in JavaScript has similar representation. Below code, > foo = {} makes foo as an empty dictionary {}. fine. If ...
2
votes
1answer
130 views

Break big method into 2 methods, first containing a “for” loop and second a “break”

A method grew too big for its own good, and I need to break it up into two separate methods. def big_method(dct): # Initial code # ... for i in dct: # More code # ... ...
4
votes
3answers
114 views

Parent class using methods defined in child

I am working on a large program (more than 10k lines of code). Below is a (hopefully not over-simplified) example of a problem I sometimes face: class MyClass1(object): def func_1(self): ...
0
votes
0answers
209 views

“Python interpreter vs Javascript engine” memory model

I learnt that memory model of python interpreter is dictionaries of dictionaries, where each module is a dictionary. Let me elaborate more on this with an example, After i run >>> python ...
-1
votes
2answers
422 views

'Tuple' vs 'List' operations in python

Only two operations are allowed on tuple, as shown below. Operations like insert / delete at an index is not allowed. I learnt that tuple is an immutable data model. list allows insert and delete ...
1
vote
1answer
108 views

More efficient alternative that checks if a list can be made a palindrome

I asked this question on Stackoverflow, but they told me this is the best place to ask. For my algorithms and data structures class, I have to write an algorithm that is more efficient in the worst ...
3
votes
3answers
208 views

closure property of datatype “tuple” in python

From this link, below is the slide that I would like to understand: The Closure Property of Data Types A method for combining data values satisfies the closure property if: The result of ...
1
vote
1answer
289 views

Building Data abstraction for rational numbers using “objects”

I follow this definition of "object":An object is a value exporting a procedural interface to data or behavior. Objects use procedural abstraction for information hiding, not type abstraction. Object ...
-3
votes
1answer
219 views

Why every value is an object in python? [closed]

I know about writing programs (using C) that have: Data values, that are manipulated. For example: integer, float values etc.. functions (rules), by which data values are manipulated. object is a ...
-1
votes
1answer
157 views

Significance of '__name__ ' attribute in python

1) Below python code, >>> def f(): return creates a function type object which has __name__ attribute with value 'f' which looks fine. But, 2) Below line of code, >>> x = ...
1
vote
1answer
137 views

How do I enforce 'referential transparency' in this program?

Below is the python program written to follow the rule of thumb in functional programming. The simple rule of thumb is: if you can replace any expression, sub-expression or subroutine call with ...
1
vote
1answer
138 views

Persist data downloaded by Celery workers

I'm working in a tool that downloads tweets from Twitter to process them later. For this purpose I'm using Celery with RabbitMQ, sending task with the keywords that must be tracked by the workers. My ...
0
votes
1answer
66 views

how python updates references to variables

For this while loop below. It is clear how the v1,v2,v3 are updated to new data objects based on the equation. But I do not understand how u1,u2,u3 retains the original values of v1,v2,v3.Can someone ...
1
vote
1answer
91 views

Is this type of data insertion safe and can stop sql injection in Python?

I am learning Database connection from MySQL Connector/Python Developer Guide. This is the code I am using to insert data: conn = mysql.connector.connect(user="user", password="password", ...
40
votes
2answers
4k views

Why do some languages round to the nearest EVEN integer?

Programming languages like Scheme (R5RS) and Python (see this Question) round towards the nearest even integer when value is exactly between the surrounding integers. What is the reasoning behind ...
17
votes
2answers
11k views

Why doesn't Python have a “flatten” function for lists?

Erlang and Ruby both come with functions for flattening arrays. It seems like such a simple and useful tool to add to a language. One could do this: >>> mess = [[1, [2]], 3, [[[4, 5]], 6]] ...
2
votes
2answers
181 views

Is this looping solution possible with recursion?

Eventually, I would like to generalize this solutions to work with a Tuple of any length. I think recursion is required for that, but I haven't been able to do it. def combineRanges(maxValues) : ...
1
vote
1answer
190 views

Additional actions in setup.py for install

Background So, I'm developing a project, and I'm writing setup.py script for it, using distutils. I'm using CPython3.3. I use some libraries that have invalid distributions in PyPI, so they have to ...
1
vote
2answers
208 views

Is using os.environ to store the value of command line switches pythonic?

I write CLI-executable Python 3 scripts regularly to do data compilation and some maintenance tasks, and try to adhere to PEP 8 and the Google Python Style Guide when doing so. Google's guide says to ...
2
votes
2answers
467 views

What was the need of introducing Python 3 when we already had Python 2 [duplicate]

I am still learning python and I started with Python 3. This question not Python 2 vs 3 or difference between them like print() is a function and not language construct and 3/2 = 1.5 My question is ...
3
votes
1answer
235 views

What is the advantage of determining scopes statically and using them dynamically in case of Python?

Firstly let me clarify that I know C and am learning Python. So my OOPS is kind of bad. I was reading the official tutorial and found this Although scopes are determined statically, they are ...
0
votes
2answers
1k views

Why do people consider Python a weak language? [closed]

I've been using Python for a little while now and I am enjoying it, but a few of my friends are telling me to start using a language like C# or Java instead and give these reasons: Python is a ...
16
votes
1answer
694 views

What are the problems python 3 new features solve? [closed]

Python 3 new features say: we’re mostly fixing well-known annoyances and warts, and removing a lot of old cruft It mentions what is different (the fix) but not why (the problems). I have have ...
3
votes
1answer
2k views

understanding the encoding scheme in python 3

I got this error in my program which grab data from different website and write them to a file: 'charmap' codec can't encode characters in position 151618-151624: character maps to <undefined> ...
1
vote
1answer
317 views

What features are missing from Python IDE tools?

What are the most desired features currently lacking in any Python IDE tools? I'm also interested in what's missing in Komodo 6 but available in other tools (I currently use Komodo 6 for Python 3 ...