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
1 answer

handling iTunes plist with 3,006 values for key in python 2 with plistlib

I'm trying to handle iTunes plist with plistlib under Python 2.7 on a Mac OS El Capitan system. The problem is get('Tracks') returns 3,006 values that have apparently lost their sub-keys. How do I handle this if my goal is to locate and alter…
Bryan Dunphy
  • 799
  • 1
  • 10
  • 22
1
vote
0 answers

PyBrain QTable (ActionValueTable) not changing

I followed a blog post (here) where the author wrote a program with PyBrain to learn how to play Blackjack. He outlines that he is using a Q-Table that was initialized with zeros. At the very end he shows his results (the final Q-Table) after the…
Patrick Cook
  • 458
  • 12
  • 27
1
vote
1 answer

convert file:// URI to open parameter string in Python 2

given a URI such as "file:///Volumes/Shared/1-05%20Born%20to%20be%20Wild.m4a". What is the easiest way to convert this to "/Volumes/Shared/1-05 Born to be Wild.m4a" so I could pass it as a parameter to open() or something similar?
Bryan Dunphy
  • 799
  • 1
  • 10
  • 22
1
vote
1 answer

pyforms cannot import conf from pysettings

This is my python file: import pyforms import pyside from pyforms import BaseWidget from pyforms.Controls import ControlText from pyforms.Controls import ControlButton class SimpleExample1(BaseWidget): def __init__(self): …
Ashish Aware
  • 169
  • 2
  • 15
1
vote
3 answers

Use iteritems in a dictionary with datetime as key

I have a dictionary update_fields that has key/value pairs where the value is another dictionary: {datetime.date(2016, 12, 2): {'t1030': 0, 't1045': 0, 't0645': 0, 't1645': 0, 't0600': 0, 't1415': 0, 't1000': 0, 't1430': 0, 't0700': 0, 't1800': 0,…
voodoo-burger
  • 2,123
  • 3
  • 22
  • 29
1
vote
2 answers

Read text file over internet on python

Here's a text file on the internet (http) http://hughchalmers.com/example.txt. How would I print that in Python 2? People are saying this is a duplicate, I would like to say that it is not a duplicate, any other script I found gave Error 412.
Hugh Chalmers
  • 49
  • 1
  • 9
1
vote
4 answers

reading lines of a file between two words

I have a file containing numbers and 2 words : "start" and "middle" I want to read numbers from "start" to "middle" in one array and numbers from "middle" to end of the file into another array. this is my python code: with open("../MyList","r") as…
Shi.Bi
  • 57
  • 7
1
vote
1 answer

Are the subprocess/commands modules Unicode aware with Python2?

Is the stdout/stderr captured from the various functions in the subprocess or the commands module for Python2 guaranteed to be a standard string, or is it possible under certain conditions that a Unicode object is returned? ... And if a standard…
R.M.
  • 3,461
  • 1
  • 21
  • 41
1
vote
1 answer

What's the relationship between str and bytes in python?

Consider the following typescript: >>> s = 'a' >>> isinstance(s, bytes) True >>> isinstance(s, str) True >>> isinstance(s, unicode) False >>> isinstance(s.decode('utf-8'), unicode) True How come s is both a str and a bytes? Is one of those a…
x-yuri
  • 16,722
  • 15
  • 114
  • 161
1
vote
2 answers

Why this single quotes and braces in output in python?

I am using ipython notebook in ubantu version 16.04 and I run this code, word = 'Rushiraj' length = 0 for char in 'rushiraj': length = length + 1 print('There are', length,'character') I get this output: ('There are', 8, 'character') What is…
R.Brahmbhatt
  • 67
  • 1
  • 3
  • 7
1
vote
1 answer

Unicode to String Python 2

I am trying to convert an plain string into the special character to work it in my logic in python 2. word = 'Tb\u03b1' word = unicode('Tb\u03b1') if word.encode('utf-8') == u'Tb\u03b1'.encode('utf-8'): print 'They are equals' print…
user2288043
  • 241
  • 4
  • 15
1
vote
0 answers

python's urlparse.urljoin removes path when concatenating

Documentation of urlparse.urljoin, mentions that: "Informally, this uses components of the base URL, in particular the addressing scheme, the network location and (part of) the path" Thus I expect that: urljoin('http://localhost:3000/foo',…
stelios
  • 2,679
  • 5
  • 31
  • 41
1
vote
1 answer

Checking new mails of Gmail account through python

I'm using this code to check for new mails with a 10 seconds delay. import poplib from email import parser import time def seeit(): pop_conn = poplib.POP3_SSL('pop.gmail.com') pop_conn.user('xxx') pop_conn.pass_('xx') #Get messages…
1
vote
1 answer

Recursive dictionary walking in python

I am new to python and trying to create a recursive dictionary walker that outputs a path to each item in the dictionary. Below is my code including some sample data. The goal is to import weather data from weather underground and publish into mqtt…
Graham
  • 318
  • 1
  • 16
1
vote
1 answer

using C types declared in .h file

I want to use in my .pyx C types that are typedef declarated in my .h file: //decls.h typedef double Doub typedef long int LInt //etc... My easy work around has been to redeclare them in my *.pxd (i.e. copy-paste that block of my .h into my .pxd…
jimmy
  • 21
  • 5