Questions tagged [python-2.6]

For issues that are specific to Python 2.6. If your question applies to Python in general, use the tag [python].

Use this tag if your question is specifically about Python 2.6. If your question applies to Python in general, use the tag . If your question applies to Python 2.x but not to Python 3, use the tag . If you aren't sure, tag your question and mention which version you're using in the body of your question.

1318 questions
629
votes
39 answers

bash: pip: command not found

I downloaded pip and ran python setup.py install and everything worked just fine. The very next step in the tutorial is to run pip install but before it even tries to find anything online I get an error "bash: pip: command not…
Trindaz
  • 17,029
  • 21
  • 82
  • 111
597
votes
4 answers

Get all object attributes in Python?

Is there a way to get all attributes/methods/fields/etc. of an object in Python? vars() is close to what I want, but it doesn't work unless an object has a __dict__, which isn't always true (e.g. it's not true for a list, a dict, etc.).
user541686
  • 205,094
  • 128
  • 528
  • 886
545
votes
15 answers

Suppress InsecureRequestWarning: Unverified HTTPS request is being made in Python2.6

I am writing scripts in Python2.6 with use of pyVmomi and while using one of the connection methods: service_instance = connect.SmartConnect(host=args.ip, user=args.user, …
Patryk
  • 22,602
  • 44
  • 128
  • 244
263
votes
5 answers

Python try...except comma vs 'as' in except

What is the difference between ',' and 'as' in except statements, eg: try: pass except Exception, exception: pass and: try: pass except Exception as exception: pass Is the second syntax legal in 2.6? It works in CPython 2.6 on…
Peter Graham
  • 11,323
  • 7
  • 40
  • 42
177
votes
9 answers

Visibility of global variables in imported modules

I've run into a bit of a wall importing modules in a Python script. I'll do my best to describe the error, why I run into it, and why I'm tying this particular approach to solve my problem (which I will describe in a second): Let's suppose I have a…
Nubarke
  • 2,020
  • 2
  • 13
  • 12
163
votes
9 answers

How to convert a set to a list in python?

I am trying to convert a set to a list in Python 2.6. I'm using this syntax: first_list = [1,2,3,4] my_set=set(first_list) my_list = list(my_set) However, I get the following stack trace: Traceback (most recent call last): File "", line…
gath
  • 24,504
  • 36
  • 94
  • 124
120
votes
6 answers

Why does sys.exit() not exit when called inside a thread in Python?

I am confused as to why the following code snippet would not exit when called in the thread, but would exit when called in the main thread. import sys, time from threading import Thread def testexit(): time.sleep(5) sys.exit() print…
Shabbyrobe
  • 12,298
  • 15
  • 60
  • 87
119
votes
13 answers

Get class that defined method

How can I get the class that defined a method in Python? I'd want the following example to print "__main__.FooClass": class FooClass: def foo_method(self): print "foo" class BarClass(FooClass): pass bar = BarClass() print…
Jesse Aldridge
  • 7,991
  • 9
  • 48
  • 75
115
votes
3 answers

Pipe subprocess standard output to a variable

I want to run a command in pythong, using the subprocess module, and store the output in a variable. However, I do not want the command's output to be printed to the terminal. For this code: def storels(): a =…
Insomaniacal
  • 1,907
  • 3
  • 14
  • 10
102
votes
6 answers

Any gotchas using unicode_literals in Python 2.6?

We've already gotten our code base running under Python 2.6. In order to prepare for Python 3.0, we've started adding: from __future__ import unicode_literals into our .py files (as we modify them). I'm wondering if anyone else has been doing…
Jacob Gabrielson
  • 34,800
  • 15
  • 46
  • 64
95
votes
9 answers

sort dict by value python

Assume that I have a dict. data = {1:'b', 2:'a'} And I want to sort data by 'b' and 'a' so I get the result 'a','b' How do I do that? Any ideas?
kingRauk
  • 1,259
  • 1
  • 11
  • 24
77
votes
5 answers

Random strings in Python 2.6 (Is this OK?)

I've been trying to find a more pythonic way of generating random string in python that can scale as well. Typically, I see something similar to ''.join(random.choice(string.letters) for i in xrange(len)) It sucks if you want to generate long…
mikelikespie
  • 5,682
  • 3
  • 31
  • 36
77
votes
8 answers

How do I get Python's ElementTree to pretty print to an XML file?

Background I am using SQLite to access a database and retrieve the desired information. I'm using ElementTree in Python version 2.6 to create an XML file with that information. Code import sqlite3 import xml.etree.ElementTree as ET # NOTE: Omitted…
Kimbluey
  • 1,199
  • 2
  • 12
  • 23
67
votes
19 answers

No module named _cffi_backend

I have Python 2.6 in my Linux rhel-5. I have installed pip and required CFFI packages. When I try to run a sample CFFI program: ffi = FFI() it says: File "/usr/lib/python2.6/site-packages/cffi/api.py", line 56, in __init__ import _cffi_backend…
Ash
  • 809
  • 1
  • 8
  • 14
63
votes
3 answers

How to stop Python parse_qs from parsing single values into lists?

In python 2.6, the following code: import urlparse qsdata = "test=test&test2=test2&test2=test3" qs = urlparse.parse_qs(qsdata) print qs Gives the following output: {'test': ['test'], 'test2': ['test2', 'test3']} Which means that even though there…
Shabbyrobe
  • 12,298
  • 15
  • 60
  • 87
1
2 3
87 88