Questions tagged [python-2.7]

Python 2.7 is the last major version in the 2.x series, and is no longer maintained since January 1st 2020. Use the generic [python] tag on all Python questions. Do not add this tag simply to convey the version of Python you're using, unless the question concerns an issue specific to Python 2.7.

Documentation for Python 2.7.

For an explanation as to why it's the last 2.x release, see PEP 404.

The End-of-life date for Python 2.7 was set as the 1st of Jan 2020, see PEP 373. The last release of Python 2.7 was 2.7.18, released April 20, 2020.

This guide explains how to choose a Python version for development. All new projects should now target Python 3 unless you have external requirements which still force you to stay on the old version.


Tagging recommendation:

Use the tag for all Python related questions. If you believe your question includes issues where the version incompatibilities between Python 2.x and Python 3.x are relevant, then add the or in addition to the main tag. 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.

95376 questions
18
votes
4 answers

Unittest - Assert a set of items of a list are (or not) contained in another list

Hello I am new to programming and and trying to make a test that checks whether any items in a list of items are present in another list (using unittest in Python 2.7). For example if I have a list ["dog", "cat", "frog] and the result of the method…
RubyJane
  • 185
  • 1
  • 1
  • 6
18
votes
2 answers

Pass data frame through Tkinter classes

I am using Python 2.7 and Tkinter. I am almost new to Object Oriented programs. I have a long program with many Tkinter windows and at some point I ask the user to load an Excel file that I read with Pandas, and want to permanently use and update…
sarangof
  • 181
  • 4
18
votes
4 answers

How to make worker threads quit after work is finished in a multithreaded producer-consumer pattern?

I am trying to implement a multithreaded producer-consumer pattern using Queue.Queue in Python 2.7. I am trying to figure out how to make the consumers, i.e. the worker threads, stop once all required work is done. See the second comment by Martin…
Lone Learner
  • 18,088
  • 20
  • 102
  • 200
18
votes
5 answers

Generating own key with Python Fernet

from cryptography.fernet import Fernet import base64 # Put this somewhere safe! key = Fernet.generate_key() f = Fernet() token = f.encrypt(b"A really secret message. Not for prying eyes.") token print f.decrypt(token) How can I generate my own…
Anonymous
  • 596
  • 1
  • 9
  • 26
18
votes
2 answers

TypeError: unhashable type: 'list' when use groupby in python

There is something wrong when I use groupby method: data = pd.Series(np.random.randn(100),index=pd.date_range('01/01/2001',periods=100)) keys = lambda x: [x.year,x.month] data.groupby(keys).mean() but it has an error: TypeError: unhashable type:…
littlely
  • 1,368
  • 3
  • 18
  • 36
18
votes
3 answers

Forward slash in json file from pandas dataframe

I'm a complete newbie to json, any help is appreciated. I'm trying to convert a dataframe to a json file. import pandas as pd df = pd.DataFrame({ 'A' : [1., 2.5], 'B' : ['img/blue.png', 'img/red.png']}) print df Output is …
edge-case
  • 1,128
  • 2
  • 14
  • 32
18
votes
3 answers

How to install snappy C libraries on Windows 10 for use with python-snappy in Anaconda?

I want to install parquet for python using pip within an Anaconda 2 installation on Windows 10. While installing I ran into the error that is described here, the installer can't find snappy-c.h. There is no mention on how to install this on Windows…
Khris
  • 3,132
  • 3
  • 34
  • 54
18
votes
1 answer

Get length of Queue in Python's multiprocessing library

I have a multiprocessing.Manager object that contains a multiprocessing.Queue to manage all of the work that I want a group of processes to do. I would like to get the number of elements left in this queue and was wondering how to do this? Python's…
lachy
  • 1,833
  • 3
  • 18
  • 27
18
votes
5 answers

Pandas: How to make apply on dataframe faster?

Consider this pandas example where I'm calculating column C by multiplying A with B and a float if a certain condition is fulfilled using apply with a lambda function: import pandas as pd df =…
Khris
  • 3,132
  • 3
  • 34
  • 54
18
votes
2 answers

python: argparse throwing value error when combining positional and optional argument

I'm trying to use the argparse library in python to read in optional and required arguments. So far I'm doing this: import argparse parser = argparse.ArgumentParser(description='Cleanup Script for…
Mischa Obrecht
  • 2,737
  • 6
  • 21
  • 31
18
votes
8 answers

how to print Arabic text correctly in PYTHON

I am using Python 2.7 and i try to print Arabic strings like these print "ذهب الطالب الى المدرسة" it's give the following output: ط°ظ‡ط¨ ط§ظ„ط·ط§ظ„ط¨ ط§ظ„ظ‰ ط§ظ„ظ…ط¯ط±ط³ط© The purpose is to print the text correctly, and not how to print each…
Mohammed Sy
  • 240
  • 1
  • 4
  • 14
18
votes
7 answers

How to activate the process queue in "django-background-tasks"

I am new to Django and the django-background-tasks package. I am facing an issue that I couldn't do/start background task unless I forcefully run the command process_tasks , that is python manage.py process_tasks. I want to do/start background task…
user7139313
18
votes
6 answers

How to find the first empty row of a google spread sheet using python GSPREAD?

I am struggling to write codes that find me the first empty row of a google sheet. I am using gspread package from github.com/burnash/gspread I would be glad if someone can help :) I currently have just imported modules and opened the…
Thành Đạt
  • 317
  • 2
  • 3
  • 15
18
votes
1 answer

How to get the 3 items with the highest value from dictionary?

Suppose I have this dictionary: {"A":3,"B":4,"H":1,"K":8,"T":0} I want to get the keys of the highest 3 values. So in this case I will get the keys: K, B and A
Liron Cohen
  • 321
  • 1
  • 3
  • 6
18
votes
1 answer

Cannot import urllib in Python

I would like to import urllib to use the function 'request'. However, I encountered an error when trying to download via Pycharm: "Could not find a version that satisfies the requirement urllib (from versions: ) No matching distribution found for…
Square9627
  • 869
  • 3
  • 10
  • 15
1 2 3
99
100