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

Python: UnicodeDecodeError: 'utf8' codec can't decode byte 0x91

I'm parsing a CSV as follows: with open(args.csv, 'rU') as csvfile: try: reader = csv.DictReader(csvfile, dialect=csv.QUOTE_NONE) for row in reader: ... where args.csv is the name of my file. One of the…
anon_swe
  • 8,791
  • 24
  • 85
  • 145
1
vote
1 answer

Python strange bitwise and (&) output

While using bitwise and operator (&) in my code I observed a strange behavior of python shell. While 10 and 10 gives 10 but 010 & 010 gives 8. These series follows for all the numbers with 0 in front like 011, 012, etc Also, till 07 & 07 it works…
Amit Tripathi
  • 7,003
  • 6
  • 32
  • 58
1
vote
2 answers

reordering fixed legth array in python

I'm looking for the best way to perform this task in Python 2.x I have an array of given size, with some element that have to stay at given position identified by attribute. I have to remove an element from the array, and move all the non fixed…
Luca
  • 11
  • 1
1
vote
1 answer

Ansible lineine file with regex is adding new line when it shouldn't

I currently have this file for configuring nagios nrpe: /etc/xinetd.d/nrpe: # default: on # description: NRPE (Nagios Remote Plugin Executor) service nrpe { flags = REUSE socket_type = stream port …
Mitch
  • 1,604
  • 4
  • 20
  • 36
1
vote
2 answers

optparse handling ArugmentException

So what i am trying to do is simple is launch a simple help dialog when i do -h.. That works fine, the issue comes when i try to do anything besides -h. what is the best practice of taking care of this. There will be many more paramters being passed…
user3753693
  • 225
  • 1
  • 5
  • 13
1
vote
1 answer

Sorting in sparse matrix (Python 2.*)

I'm solving a task in coursera and get stuck with sorting in sparse matrix. The problem is: i make a support vector classification (sklearn.svm.SVC) clf = SVC(C=1, kernel='linear', random_state=241) clf.fit(X, y) and as a result got a…
Sasha Korekov
  • 323
  • 3
  • 16
1
vote
1 answer

Python 2 error:"Internal Python error in the inspect module

I have written this code to calculate the quadratic formula: from numpy.lib.scimath import sqrt as csqrt a = raw_input("a?") b = raw_input("b?") c = raw_input("c?") def numcheck(x): try: i = float(x) return True except…
Expain
  • 19
  • 5
1
vote
1 answer

Python 3.5 App to .exe or copy libraries to another PC

I got the next problem. During the last 3 months, I was building an application in Python 3.5 to test luminaries. For this application I used the next libraries, "tkinter", "sys", "threading", "os", "time", "shutil" that are included on the main…
1
vote
3 answers

How to find prime number's but theres bugs. I can't find out

I write a program that find the prime numbers . My teacher told me to do that in three steps . Firstly i had to generate all odds numbers . Then i need to check if it is devigable or not . To do that he tell me to use % operator . Here is my code…
Tanzir Uddin
  • 51
  • 1
  • 9
1
vote
1 answer

How to define a new class with methods via the C API with Python 3?

Short version: If we use PyObject_CallFunctionObjArgs with PyType_Type in Python 3 as a replacement for PyClass_New, then the dictionary has to be populated before the creation of the class. However, PyMethod_New requires the class to be known…
1
vote
0 answers

Hash collision with 2 strings in Python

In the MIT OpenCourseWare YouTube lecture on hashing, the professor gives an example of two strings causing a hash collision in Python: >>> hash('\0B') 64 >>> hash('\0\0C') 64 Why does this happen?
SeanPlusPlus
  • 8,663
  • 18
  • 59
  • 84
1
vote
1 answer

Python numpy uint64 gets converted to float on division

I wanted to do a simple integer division e.g. 1/3=0, but uint64 behaves very weirdly, resulting in my result being casted to float. Why? python> uint64(100)/3 Out[0]: 33.333333333333336 python> uint64(100)/uint64(3) Out[1]: 33 python>…
mxmlnkn
  • 1,887
  • 1
  • 19
  • 26
1
vote
1 answer

How to store non-english text?

I have a text file. It consists of many non-english character. I want to store this file as a number sequences such as ascii. How can I represent a non-english character? >>> str(ord('x')) '120' >>> str(ord('ç')) Traceback (most recent call last): …
user2362956
1
vote
2 answers

String Slicing in python UDF

I am trying to write a UDF in python that will be called from a pig script. The UDF needs to accept the date as a string in DD-MMM-YYYY format and return DD-MM-YYYY format. Here MMM will be like JAN, FEB.. DEC and the return MM will be 01, 02...…
Kiran Vajja
  • 23
  • 1
  • 3
1
vote
2 answers

iPython crashes on printing Fibonacci Series

While attempting to print a fibonacci series using tuples, iPython tends to crash. Here is the code I am trying to execute. n = raw_input("Please enter a number: ") a = 0 b = 1 while b < n: (b,a) = (a,b+a) print b However, if I replace n…
user2762934
  • 2,332
  • 10
  • 33
  • 39