Questions tagged [python-2.x]

For questions about Python programming that are specific to version 2.x of the language. Use the more generic [python] tag for all Python questions, and only add this tag if your question is version-specific.

Python 2 is the version of the Python programming language which was for a long time the most widely deployed in production environments; but it is now in the process of being displaced by Python 3. The two versions of the language are not compatible, though many aspects of the syntax are identical. The latest, and last, released version of Python 2 is Python 2.7.18.

Official support for Python 2 has ended on January 1, 2020.

See also Python2 or Python3.

For information on Python in general, visit the main Python tag wiki.

Tagging recommendation:

Use the tag for all Python related questions. If you believe your question includes issues specific to the incompatible Python 2.x or Python 3.x, in addition to the main tag, use or . If you believe your question may be even more specific, you can include a version specific tag such as .

Please do not mix (or a more specific tag such as and (ditto) unless you are specifically asking a question about an interoperability problem between versions.

Community

Free Python Programming Books

2871 questions
1
vote
2 answers

Unable to encode or decode the string properly

I tried to look at bunch of stackoverflow examples. Python version used: Python 2.7.10 Output of the string s looked like u'bh\xfcghi' where \xfc=ü I am reading this from a webpage. After I encode the string via .encode('utf-8'), it looks…
Jazzy
  • 33
  • 1
  • 8
1
vote
1 answer

Why are integers missing some special methods in python 2?

In python 2 or 3 the built-in classes have the special method defined explicitly. Explicit is better than implicit and all that jazz. 5. > 4. # True (5.).__ge__(4.) # True But in python 2 there are exceptions for some methods, at least in the…
durum
  • 3,316
  • 1
  • 25
  • 30
1
vote
2 answers

Facing Issue on Inserting Data to correct Column in Tkinter TreeView

Can you please take a look at this Tkinter code and let me know why I am not able to insert the values to correct columns? as you can see from the attached image it seems it is adding empty string to first column! from Tkinter import * import…
Suffii
  • 5,694
  • 15
  • 55
  • 92
1
vote
1 answer

How to handle 2 versions of Python on same client?

I use ArcGIS 10.3 at work and it comes with Python 2.7.8; so when I run any of the .py/.pyc/.pyw files, it defaults to the path leading that versions .exe file. Because of some non-ArcGIS related work, we are also being provisioned Python 3.4.2,…
pstatix
  • 3,611
  • 4
  • 18
  • 40
1
vote
1 answer

Unable to capture result of ls -la with subprocess.Popen

I am trying to capture the output when I execute a custom command using Popen: import subprocess def exec_command(): command = "ls -la" # will be replaced by my custom command result = subprocess.Popen(command,…
python dev
  • 219
  • 1
  • 2
  • 9
1
vote
0 answers

Use Pool with apply_async or map_async?

first time poster, please be patient with me. I'm using Python 2.7.12 and I want to use the multiprocessing module to speed up my code. My program get's files in all sort of formats(pdf, xslx, docx, etc.) and extracts the data inside them and saves…
1
vote
1 answer

How to make logic based on `unicode` compatible with python2-3

I want to make this code compatible with python2-3 : def normalize_text(text, ignore_characters=''): if type(ignore_characters) not in [list, str, unicode]: ignore_characters = '' if type(ignore_characters) == str: …
Pooya
  • 992
  • 2
  • 10
  • 31
1
vote
1 answer

Gzip Python 3 vs Gzip Python 2

The problem: I have an older code that it's using Py2 'str' and that is using gzip to compress that string and I want to have the same output from gzip from the same string in Py3 but I can't manage to make it work. Python 2 code #input_buffer is a…
Mark
  • 1,100
  • 9
  • 17
1
vote
2 answers

How to append a new list to an existing CSV file?

I already have a CSV file created from a list using CSV writer. I want to append another list created through a for loop columnwise to a CSV file. The first code to create a CSV file is as follows: with open("output.csv", "wb") as f: writer =…
rex
  • 47
  • 1
  • 7
1
vote
1 answer

Concurrent futures submit task to process pool non-blockingly

This question is Python 2-specific, using the community maintained backport of concurrent.futures. I'm trying to use a ProcessPoolExecutor (with maxWorkers trivially set to 2) to run two tasks in parallel. Those tasks are both Python functions, and…
Greg Nisbet
  • 6,710
  • 3
  • 25
  • 65
1
vote
2 answers

Unicode Cyrillic strings in Python 2.7

I've got a piece of Python 2.7 code that returns a webpage encoded in UTF-8. It essentially does this: arequest=urllib2.urlopen(request.httprequest.host_url[:-1]+record.path) response=arequest.read() parser = etree.HTMLParser() tree =…
Mike
  • 11
  • 4
1
vote
3 answers

Can't access Python function as attribute

Imagine I have the following test.py file import foo class example1(object): MyFunc = foo.func Where foo.py is def func(): return 'Hi' Then I write another file import test test.example1.MyFunc() and get the error 'unbound method…
RFiischer
  • 41
  • 7
1
vote
0 answers

python 2 with opencv 3 - detect object by color

I'm trying to detect object by color, and get some "information" about the object - like size and position. So far I just did this import cv2 import numpy vd1 = cv2.VideoCapture(0) while True: ret, frame = vd1.read() hsv =…
noam
  • 11
  • 2
1
vote
1 answer

ruamel.yaml formatting of TimeStamp after deepcopy seems broken

import copy import ruamel.yaml d = ruamel.yaml.round_trip_load("foo: 2016-10-12T12:34:56\n", preserve_quotes=True) d2 = copy.deepcopy(d) assert ruamel.yaml.round_trip_dump(d) == "foo: 2016-10-12T12:34:56\n" assert ruamel.yaml.round_trip_dump(d2) ==…
Quuxplusone
  • 23,928
  • 8
  • 94
  • 159
1
vote
1 answer

About property class in a python

I saw a python snippet as below when seeking for a tutorial to property in python: class Celsius: def __init__(self, temperature = 0): self.temperature = temperature def to_fahrenheit(self): return (self.temperature * 1.8) +…
ROBOT AI
  • 1,217
  • 3
  • 16
  • 27