Search or compai problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gallagher, Tim (NE)

    #1

    Search or compai problem

    I am new to python and I want to compare 2 strings, here is my code:
    [start]

    import active_director y
    import re

    lstUsers = []
    users = active_director y.root()
    for user in users.search ("sn='gallagher '"):
    lstUsers.append (user.samAccoun tName)

    print "----------------------------------------"
    lstUsers.sort()

    ## Printing out what is inside of the arrar(list)
    x = 0
    while x < len(lstUsers):
    if re.compile(lstU sers[x]).match("None", 0):
    print "Somthing here"

    x = x + 1

    [/end]

    When I do the:
    if re.compile(lstU sers[x]).match("None", 0):
    print "Somthing here"

    Some of the items in lstUsers[x] are the word None. I am not sure why I
    cant do this

    I want to compare lstUsers[x] to the word "None", how can I do this.
    Thanks

    Timothy F. Gallagher
    CSC Systems Engineer

  • John Machin

    #2
    Re: Search or compai problem

    Gallagher, Tim (NE) wrote:
    I am new to python and I want to compare 2 strings, here is my code:
    [start]
    >
    import active_director y
    import re
    >
    lstUsers = []
    Using "lst" or "l" as a variable name is bad news in any language; with
    many fonts they are too easily misread as "1st" or "1" respectively.
    users = active_director y.root()
    for user in users.search ("sn='gallagher '"):
    **** Insert here:
    print type(user.samAc countName), repr(user.samAc countName)
    **** that may indicate where your problem *starts*
    **** Then read the documentation for the active_director y module, in
    particular what it says about the attributes of the objects in the
    sequence returned by users.search.

    lstUsers.append (user.samAccoun tName)
    >
    print "----------------------------------------"
    lstUsers.sort()
    >
    ## Printing out what is inside of the arrar(list)
    What is "arrar(list )" ??

    **** Here insert this code:
    print lstUsers
    **** Look at the elements in the list; do you see ..., 'None', ... or
    do you see ..., None, ...
    x = 0
    while x < len(lstUsers):
    *Please* consider using a "for" statement:

    for item in lstUsers:
    do_something_wi th(item)
    if re.compile(lstU sers[x]).match("None", 0):
    1. Python or not, using regular expressions to test for equality is
    extreme overkill. Use
    if lstUsers[x] == "None":
    2. Python or not, it is usual to do
    re.compile(cons tant pattern).match( variable_input)
    not the other way around.
    3. The second arg to match defaults to 0, so you can leave it out.

    print "Somthing here"
    >
    x = x + 1
    >
    [/end]
    >
    When I do the:
    if re.compile(lstU sers[x]).match("None", 0):
    print "Somthing here"
    >
    Some of the items in lstUsers[x] are the word None.
    I am not sure why I cant do this
    >
    I want to compare lstUsers[x] to the word "None", how can I do this.
    You *have* compared lstUsers[x] to the word "None" -- with the re
    sledgehammer, but you've done it. Maybe what's in there is *not* the
    string "None" :-)

    HTH,
    John

    Comment

    • timgerr@gmail.com

      #3
      Re: Search or compai problem


      John Machin wrote:
      Gallagher, Tim (NE) wrote:
      I am new to python and I want to compare 2 strings, here is my code:
      [start]

      import active_director y
      import re

      lstUsers = []
      >
      Using "lst" or "l" as a variable name is bad news in any language; with
      many fonts they are too easily misread as "1st" or "1" respectively.
      >
      users = active_director y.root()
      for user in users.search ("sn='gallagher '"):
      >
      **** Insert here:
      print type(user.samAc countName), repr(user.samAc countName)
      **** that may indicate where your problem *starts*
      **** Then read the documentation for the active_director y module, in
      particular what it says about the attributes of the objects in the
      sequence returned by users.search.
      >
      >
      lstUsers.append (user.samAccoun tName)

      print "----------------------------------------"
      lstUsers.sort()

      ## Printing out what is inside of the arrar(list)
      >
      What is "arrar(list )" ??
      >
      **** Here insert this code:
      print lstUsers
      **** Look at the elements in the list; do you see ..., 'None', ... or
      do you see ..., None, ...
      >
      x = 0
      while x < len(lstUsers):
      >
      *Please* consider using a "for" statement:
      >
      for item in lstUsers:
      do_something_wi th(item)
      >
      if re.compile(lstU sers[x]).match("None", 0):
      >
      1. Python or not, using regular expressions to test for equality is
      extreme overkill. Use
      if lstUsers[x] == "None":
      2. Python or not, it is usual to do
      re.compile(cons tant pattern).match( variable_input)
      not the other way around.
      3. The second arg to match defaults to 0, so you can leave it out.
      >
      >
      print "Somthing here"

      x = x + 1

      [/end]

      When I do the:
      if re.compile(lstU sers[x]).match("None", 0):
      print "Somthing here"

      Some of the items in lstUsers[x] are the word None.
      I am not sure why I cant do this

      I want to compare lstUsers[x] to the word "None", how can I do this.
      >
      You *have* compared lstUsers[x] to the word "None" -- with the re
      sledgehammer, but you've done it. Maybe what's in there is *not* the
      string "None" :-)
      >
      HTH,
      John
      it is really lstusers (it is an L not a # 1), Some of the output from
      print lstUsers has the output of None. I and trying to filter the None
      out of the list. I come from a perl background and this is how I do
      thing in perl

      TIm

      Comment

      • Gabriel Genellina

        #4
        Re: Search or compai problem

        At Saturday 19/8/2006 01:16, timgerr@gmail.c om wrote:
        >it is really lstusers (it is an L not a # 1), Some of the output from
        >print lstUsers has the output of None. I and trying to filter the None
        >out of the list. I come from a perl background and this is how I do
        >thing in perl
        None is a unique object used as "nothing" or "no value".
        Try reading the Python tutorial, it's easy and you will learn a lot of things.


        Gabriel Genellina
        Softlab SRL





        _______________ _______________ _______________ _____
        Preguntá. Respondé. Descubrí.
        Todo lo que querías saber, y lo que ni imaginabas,
        está en Yahoo! Respuestas (Beta).
        ¡Probalo ya!


        Comment

        • timgerr@gmail.com

          #5
          Re: Search or compai problem


          Gabriel Genellina wrote:
          At Saturday 19/8/2006 01:16, timgerr@gmail.c om wrote:
          >
          it is really lstusers (it is an L not a # 1), Some of the output from
          print lstUsers has the output of None. I and trying to filter the None
          out of the list. I come from a perl background and this is how I do
          thing in perl
          >
          None is a unique object used as "nothing" or "no value".
          Try reading the Python tutorial, it's easy and you will learn a lot of things.
          >
          >
          Gabriel Genellina
          Softlab SRL
          >
          >
          >
          >
          >
          Thanks, I did not know that. Then I should look for a null value?

          Tim

          Comment

          • Gabriel Genellina

            #6
            Re: Search or compai problem

            At Saturday 19/8/2006 23:43, timgerr@gmail.c om wrote:
            >it is really lstusers (it is an L not a # 1), Some of the output from
            >print lstUsers has the output of None. I and trying to filter the None
            >out of the list. I come from a perl background and this is how I do
            >thing in perl
            None is a unique object used as "nothing" or "no value".
            Try reading the Python tutorial, it's easy and you will learn a
            lot of things.
            >
            >Thanks, I did not know that. Then I should look for a null value?
            Yes; I don't know where your items come from, but usually None is
            used to represent an empty/null value. It's not the same as "".


            Gabriel Genellina
            Softlab SRL





            _______________ _______________ _______________ _____
            Preguntá. Respondé. Descubrí.
            Todo lo que querías saber, y lo que ni imaginabas,
            está en Yahoo! Respuestas (Beta).
            ¡Probalo ya!


            Comment

            Working...