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

Pandas, convert aggregated dataframe to list of tuples

I am trying to obtain a list of tuples from a panda's DataFrame. I'm more used to other APIs like apache-spark where DataFrames have a method called collect, however I searched a bit and found this approach. But the result isn't what I expected, I…
Alberto Bonsanto
  • 17,556
  • 10
  • 64
  • 93
1
vote
1 answer

Removing DataFrame rows in Pandas based on column type

I have a Panda's DataFrame and in an specific column, there are some values of different type than the desired one. I've tried to use a similar approach like the one exposed here, but it doesn't work. In my case some rows store floats and others…
Alberto Bonsanto
  • 17,556
  • 10
  • 64
  • 93
1
vote
2 answers

Python Imports failing. Relative imports, package recognition, __init__.py , __package__, __all__

I've been reading a lot of threads, the PEP articles related to this problem, which are around 4 of them, but none of them gives a clear idea on some points and I still can't do relative imports. In fact, the contents of my main package is not…
Darkgaze
  • 2,280
  • 6
  • 36
  • 59
1
vote
3 answers

Simple python regex groups can't parse date

I'm trying to parse dates with regex, using groups, but python is returning empty lists. I'm not doing anything fancy, just 12/25/10 sort of stuff. I want it to reject 12/25-10 though. date = re.compile("\d{1,2}([/.-])\d{1,2}\1\d{2}") I've tried…
ehfeng
  • 3,807
  • 4
  • 33
  • 42
1
vote
2 answers

Python operator overloading with multiple operands

I know I can do simple operator overloading in python by the following way. Let say overloading '+' operator. class A(object): def __init__(self,value): self.value = value def __add__(self,other): return self.value + other.value a1 =…
karthi_ms
  • 5,568
  • 11
  • 38
  • 39
1
vote
2 answers

Converting 12 hour format time string (with am/pm) into UTC in 24 hour format

I have time string 11:15am or 11:15pm. I am trying to convert this string into UTC timezone with 24 hour format. FROM EST to UTC For example: When I pass 11:15am It should convert into 15:15 and when I pass 11:15pm then it should convert to 3:15. I…
born2Learn
  • 1,253
  • 5
  • 14
  • 25
1
vote
2 answers

Celery cannot find a worker

I'm using celery with such configuration default_exchange = Exchange('default', type='direct') latest_exchange = Exchange('latest', type='direct') shared_celery_config = { 'BROKER_URL': 'redis://localhost:6379/0', 'CELERY_RESULT_BACKEND':…
Most Wanted
  • 6,254
  • 5
  • 53
  • 70
1
vote
2 answers

math.ceil(0.5) returning different value from math.ceil(1/2)

import math print(math.ceil(0.5)) Returns 1.0 But import math print(math.ceil(1/2)) Returns 0.0 What's going on here? Explanation would be nice.
Oscar Johansson
  • 135
  • 1
  • 2
  • 11
1
vote
3 answers

Scraping YouTube playlist video links

I wanted to download all videos of this Youtube channel. So I tried to write a script with BeautifulSoup to scrape all the links of the videos. I did some inspection and found out that the "tr class="pl-video yt-uix-tile" can be used to get the…
user6739649
  • 35
  • 1
  • 1
  • 5
1
vote
2 answers

Caesar Cipher in python

The error which i am getting is Traceback (most recent call last): File "imp.py", line 52, in mode = getMode() File "imp.py", line 8, in getMode mode = input().lower() File "", line 1, in NameError: name…
Abhijit
  • 11
  • 2
1
vote
0 answers

inversion list for python

Is there a pure python implementation of inversion lists, ideally in the base libraries? an inversion list is a data structure that describes a set of non-overlapping numeric ranges, stored in increasing order. The set is stored in an array. Every…
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
1
vote
2 answers

How do I get my program to only accept certain inputs in python 2.x

I would like this program to only accept as inputted text any of "yes ,"y", "Yes" but for some reason when I input one of them nothing happens and the loop below doesn't seem to run: import time print ("Welcome to my first ever RPG! created…
1
vote
2 answers

Problems with installation of Pillow

I am running Python 2.7.1.1 with Anaconda2 4.0.0 64-bit on a Windows 7 machine. I'm trying to install Pillow for imaging, and after having read through every thread I could find, I am still unable to reach a solution. I have installed and…
DarthVarun
  • 11
  • 1
  • 2
1
vote
3 answers

How come empty value is matching with array value in python

I am matching an empty value with an array element which has one value in it and the array does not have any empty values. However, still this script works. import re b = "" links_check_arr = ['Arunsdsdds'] for links_find in links_check_arr: if…
Mounarajan
  • 1,357
  • 5
  • 22
  • 43
1
vote
1 answer

Tkinter variables

I've made a simple GUI in Tkinter.(Code is below) When I press the "Fetch" botton than I get the text input from the GUI in a Command line. Let's say that in this example the "user" is putting 0.5 in the "Service Points Won" field and 0.7 in the "…
Wouter
  • 173
  • 15