Got Python Questions? Ask Our Experts In The Rackspace Community

EDITOR’S NOTE: Update: We got some great feedback about the first AMA with Jesse, so we’re moving the discussion space for Alex’s AMA from the Community to – that way it will be easier to follow the conversation and replies. In addition, we’re tightening up the timeframe – the AMA will happen on Tuesday ONLY, and not Tuesday through Thursday as originally planned. Finally, some of the other devs who work with Alex will be lending a helping hand, so there will be plenty of developer experience on tap for everyone! Hope to see you all there next Tuesday!

We know technical questions come up from time to time; questions that may require a pretty in-depth response. That’s why next week we’re launching a new Ask-Me-Anything three-day event series in partnership with the Rackspace Community. It’s your opportunity to ask ANY development question you like and solicit feedback from Rackspace experts and others in the field. Ok, maybe not any development question: for this series of virtual events we’re focusing mainly on Python.

At Rackspace, we are fortunate to have the best and brightest in the Python community keeping us at the cutting edge, and they want to share some of their expertise and experience with our Community members!

Each month, a Racker Python expert will open a post for questions and reply to every (reasonable!) question asked on that post, over the course of three days. Technical questions might require some additional sourcing, so we encourage you to check back often on the post and your question.

Mark your calendars for August 6 through August 8 and join us for the first session with Jesse Noller. We have Alex Gaynor and Ed Leafe lined up to participate in the months following. We hope you can benefit from the conversations over the next few months.

Python Ask-Me-Anything

  • August 6, 7 & 8Jesse Noller: Jesse is actively involved in the Python Software Foundation and organizing PyCon. Learn more about him on his blog or follow him on Twitter @jessenoller
  • September 3Alex Gaynor: Alex has worked for Rackspace as a software engineer on the Developer Relations Group since May. In his free time he works on many open source software projects, such as Django and PyPy, and serves on the board of directors of the Python Software Foundation. He grew up in Chicago and now lives in San Francisco. Follow him on Twitter @alex_gaynor.
  • October (date TBD)Ed Leafe: Ed has been a developer for over 20 years, and is one of the original developers involved with OpenStack. After leaving the Microsoft world over a decade ago, he has been primarily a Python developer, and has spoken at several US PyCons. He has worked with Rackspace for the past five years (and he also throws a mean Frisbee). Follow him on Twitter @EdLeafe.

No RSVP is required for these events. Simply show up, post your question and watch the conversation take off. Join us again in September and October as the guests change each month. Hope to see you in the Community!


  1. Here I m passing dictionary as command line argument to python script

    >python {“doctype”:”Address”,”address_title”:”Mr.Machha”,”address_line1″:”Vijayanagar”,”city”:”BangLORE”,”phone”:”012345678″}

    And in my python script( I m getting

    data= sys.argv[1]
    print data
    # {doctype:Address,address_title:Mr.Machha,address_line1:Vijayanagar,city:BangLORE,phone:012345678}

    Here I m not getting dictionary as I m passing ie


    How to get dictionary as mentioned above in my script?

  2. why am is getting this error in my program?

    what is thew eror in this:

    Traceback (most recent call last):

    File “F:/coding/python/python programming for absolute beginners/chapter 4/The Jumble”, line 9, in


    AttributeError: ‘str’ object has no attribute ‘randrange’

    import random

    print”tttThe Jumble Game”

    print”In this program you will be given a jumble word and you have to guess that word”









    print(“The jumble word is”,random)

  3. hi this is ramnath reddy . i am using rexster server with Titan cassandra. and all are installed in my local host. me configure my rexster.xml to create a specific graph.



    and i want to add edges and vertices’s to that my new graph . i wrote below code to add
    `from bulbs.rexster import Graph, Config
    config = Config(‘http://localhost:8182/graphs/emptygraph’)
    g = Graph(config)`

    but i am getting error ……if i add below data that will effect to default graph only ….. that code not showing any effect on empgraph …… what i have to do to add a data to my newly created empgraph ?

    from bulbs.rexster import Graph
    config = Config(‘http://localhost:8182/graphs/empgraph’)
    g = Graph()
    class inser_class():
    po = g.vertices.create(name=”po”)
    pr = g.vertices.create(name=”pr”)
    tanuja = g.vertices.create(name=”tanuja”)
    g.edges.create(pr, “knows”, tanuja)

  4. i am new to python and i am facing this problem

    i have two text files

    suppose my file1 is








    file 2 is








    and i want to check each value of file1 with all values of file2

    if there is a mismatch it will print the respective value of file1

    means my o/p will





    i have tried with this codes but didnt get output


    #print f2



    for l2 in f2:


    for j in range(len(i)-1):



    with open(“mismatchid1.txt”, “a”) as myFile:

    myFile.write(‘%5s %8sn’ % (i[index],vals[2]))

  5. I have created an instance tux from class Penguin() in the MainHandler class. The Penguin class has a public attribute named wingspan. How do I print tux’s wingspan to the console from within the MainHandler class?

  6. The below code track the face from input video captured from webcam, but the code tracks the face only once. How to modify the below code to track the face continuously when the face keep on moving?
    import cv
    import numpy
    import time
    class Camera(object):
    def __init__(self, camera = 0): = cv.CaptureFromCAM(camera)
    if not
    raise Exception(“Camera not accessible.”)

    def get_frame(self):
    frame = None
    while not frame:
    frame = cv.QueryFrame(

    return frame

    def get_fps(self):
    fps = cv.GetCaptureProperty(, cv.CV_CAP_PROP_FPS)
    return fps if fps != -1 else 30.0

    def get_size(self):
    w = int(cv.GetCaptureProperty(, cv.CV_CAP_PROP_FRAME_WIDTH))
    h = int(cv.GetCaptureProperty(, cv.CV_CAP_PROP_FRAME_HEIGHT))
    return (w,h)

    class FaceDetector(object):

    def __init__(self, width, height, cascade_file=”haarcascade_frontalface_alt.xml”):
    # Load the cascade
    self.cascade = cv.Load(cascade_file)
    # Storage for the algorithm to use = cv.CreateMemStorage()
    # A grayscale buffer to copy images for processing into
    self.gray = cv.CreateImage((width, height), 8, 1)

    def get_faces(self, image):
    # Convert the image to grayscale and normalise
    cv.CvtColor(image, self.gray, cv.CV_BGR2GRAY)
    cv.EqualizeHist(self.gray, self.gray)
    # Detect faces
    return cv.HaarDetectObjects(self.gray, self.cascade,,
    scale_factor = 1.3,
    min_neighbors = 2,
    flags = cv.CV_HAAR_DO_CANNY_PRUNING,
    min_size = (40,40))

    def get_best_face(self, image):
    return max(self.get_faces(image),
    key = (lambda f: f[1]))
    except ValueError:
    return None

    class FaceTracker(object):

    def __init__(self, frame, face_position,
    fh_x = 0.5, fh_y = 0.13,
    fh_w = 0.25, fh_h = 0.15):
    A motion tracker that can track a face. Note: This class
    simply provides the interface but doesn’t actually track the face as it
    @param frame The first frame containing the face
    @param face_position The position of the face in the frame
    @param fh_x The x-position on the face of the center of the forehead
    @param fh_y The y-position on the face of the center of the forehead
    @param fh_w The width, relative to the face, of the forehead
    @param fh_h The height, relative to the face, of the forehead
    self.face_position = face_position
    self.fh_x = fh_x
    self.fh_y = fh_y
    self.fh_w = fh_w
    self.fh_h = fh_h

    def update(self, time, frame, face_position = None):
    Add a new frame. Will override the face position if specified.
    self.face_position = face_position or self.face_position

    def get_face(self):
    return self.face_position

    class Annotator(object):
    THIN = 1 # Thin line width
    COLOUR_FACE = (0,255,255)

    def __init__(self):
    Can annotate various features onto frames.
    # Setup fonts
    self.small_font = self._get_font(0.5,Annotator.THIN)
    # Text colour
    self.face = (0,0,1,1)

    def _get_font(self, size=1, weight=1, italic=0):
    return cv.InitFont(cv.CV_FONT_HERSHEY_SIMPLEX,
    size, size, italic, weight)

    def set_face(self, face):
    self.face = tuple(map(int, face))

    def metrics(self):
    _,y,_,_ = map(int, self.face)
    return (y)

    def draw_face(self, frame):
    x,y,w,h = self.face

    c = Annotator.COLOUR_FACE
    cv.Rectangle(frame, (int(x),int(y)), (int(x+w),int(y+h)), c, Annotator.THIN)

    class Program(object):

    def __init__(self,
    webcam = 0,
    window_title = “output”): = Camera(webcam)
    self.face_detector = FaceDetector(*
    self.face_tracker = None
    self.annotator = Annotator()
    self.window = window_title


    self.show_face = True

    def find_face(self, frame):
    # Try and find a face
    face = self.face_detector.get_best_face(frame)
    if face is not None:
    # Track the new face
    self.face_tracker = FaceTracker(frame, face[0])

    def update(self):
    Mainloop body. Returns True unless termination requested.
    frame =
    frame_time = time.time()
    if self.face_tracker is None:
    # No face known
    # Track the face
    self.face_tracker.update(frame_time, frame)

    # Draw the OSD
    if self.show_face:
    # Display the (possibly annotated) frame
    cv.ShowImage(self.window, frame)
    # Handle keypresses
    key = cv.WaitKey(10) & 255
    if key == 27: # Escape
    # Exit
    return False

    return True

    def run(self):

    while self.update():

    if __name__==”__main__”:

  7. hi,

    i want to print the string as ‘%h’ %r “%t” %s %d
    i tried using print(”’…….
    ‘%h’ %r “%t” %s %d
    ”’. %())

    i stucked here pls help me out

  8. phonebook = {‘A’: [‘’, ‘905-906-1234’],
    ‘Bob’: [‘bob@gmail’, ‘905-456-5789’],
    ‘R’: [‘’,’905-246-1234′],
    ‘Sj’: [‘’,’905-478-2690′],
    ‘Tr’: [‘’,’647-756-2552′]}
    I am trying to create a program where i can replace either name, email or phone number by user input. So the user has to enter the name they want to change and the name that they want.
    word=input(“Enter the key you would like to change: “)
    word_replace=input(“Enter the value that you would like to change the key to: “)
    for key,value in enumerate(phonebook):
    if value==word:
    print (phonebook)

    I can’t figure out how to do it

  9. Hi Bob,

    Instead of using an array, it may be better to to create an object.

    If you want to access an email address you can access phonebook[word].email instead of having to keep track of any array indices.

    Please try the following:

    word=input(“Enter the key you would like to change: “)
    if(word IN phonebook):
    to_change = phonebook[word]
    word_replace=input(“Enter the value that you would like to change the key to: “)
    field_to_be_changed = input(“enter 1 for changing email, 2 for changing phone number”)
    if(field_to_be_changed == 1):
    to_change[0] = word_replace
    elif(field_to_be_changed == 2):
    to_change[1] = word_replace
    print “enter correct options”
    print phonebook

    print “key does not exist”

    Hope this works for you!


    Information Developer at Rackspace

  10. In python please explain following

    value = ‘100’

    if(value == 100) // gives false (correct)

    if(value == ‘100’) // gives true (correct)

    if((int)value == 100) //gives true (correct)

    if((int)value == ‘100’) // gives true….. How?? interpreter comparing (int, string) gives true result HOW????

  11. Hi, I have a question.
    I need to know how to access each cell of an csv file.
    Then if that cell starts with = I need to do some mathematical operations otherwise to keep the data same as it was. Please can anyone help me?

  12. Hi!
    So I have downloaded Python 3.4 and when I write a program in the IDLE and save it I click on it and I get nothing. The on thing that happens is that is that a small black window looking like the cmd pops up for one tenth of the second and that’s it… how can I do it right?

  13. When I wrote the following line in the Python2.7 IDLE:

    from gi.repository import Gedit

    Everything happens as it should and Python IDLE 2.7 successfully exploring Gedit class.
    But when same content is written in the python3.4 IDLE follows error:

    See the picture below:

    Note: When Gedit runs My plugin which starts by this line of code( and of course with Python3.4), everything is executed without error.
    This means that it works correctly when is called from the other instance but not from Py 3.4 IDLE?

  14. how to create dynamic contact list in pyqt? i am using pyqt designer,using such tool i created one qframe ,inside that frame i want display contact list,like normal contact list in mobiles,is it possible? if its posiible then how?
    thanks in advance


Please enter your comment!
Please enter your name here