Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Search or compai problem

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


Tim.Gallagher at gd-ais

Aug 18, 2006, 2:12 PM

Post #1 of 6 (144 views)
Permalink
Search or compai problem

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

import active_directory
import re

lstUsers = []
users = active_directory.root()
for user in users.search ("sn='gallagher'"):
lstUsers.append(user.samAccountName)

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

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

x = x + 1

[/end]

When I do the:
if re.compile(lstUsers[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

--
http://mail.python.org/mailman/listinfo/python-list


sjmachin at lexicon

Aug 18, 2006, 3:55 PM

Post #2 of 6 (136 views)
Permalink
Re: Search or compai problem [In reply to]

Gallagher, Tim (NE) wrote:
> I am new to python and I want to compare 2 strings, here is my code:
> [start]
>
> import active_directory
> 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_directory.root()
> for user in users.search ("sn='gallagher'"):

**** Insert here:
print type(user.samAccountName), repr(user.samAccountName)
**** that may indicate where your problem *starts*
**** Then read the documentation for the active_directory module, in
particular what it says about the attributes of the objects in the
sequence returned by users.search.


> lstUsers.append(user.samAccountName)
>
> 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_with(item)

> if re.compile(lstUsers[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(constant 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(lstUsers[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

--
http://mail.python.org/mailman/listinfo/python-list


timgerr at gmail

Aug 18, 2006, 9:16 PM

Post #3 of 6 (137 views)
Permalink
Re: Search or compai problem [In reply to]

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_directory
> > 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_directory.root()
> > for user in users.search ("sn='gallagher'"):
>
> **** Insert here:
> print type(user.samAccountName), repr(user.samAccountName)
> **** that may indicate where your problem *starts*
> **** Then read the documentation for the active_directory module, in
> particular what it says about the attributes of the objects in the
> sequence returned by users.search.
>
>
> > lstUsers.append(user.samAccountName)
> >
> > 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_with(item)
>
> > if re.compile(lstUsers[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(constant 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(lstUsers[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

--
http://mail.python.org/mailman/listinfo/python-list


gagsl-py at yahoo

Aug 18, 2006, 11:00 PM

Post #4 of 6 (131 views)
Permalink
Re: Search or compai problem [In reply to]

At Saturday 19/8/2006 01:16, timgerr[at]gmail.com 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!
http://www.yahoo.com.ar/respuestas


timgerr at gmail

Aug 19, 2006, 7:43 PM

Post #5 of 6 (141 views)
Permalink
Re: Search or compai problem [In reply to]

Gabriel Genellina wrote:
> At Saturday 19/8/2006 01:16, timgerr[at]gmail.com 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

--
http://mail.python.org/mailman/listinfo/python-list


gagsl-py at yahoo

Aug 21, 2006, 10:02 PM

Post #6 of 6 (129 views)
Permalink
Re: Search or compai problem [In reply to]

At Saturday 19/8/2006 23:43, timgerr[at]gmail.com 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!
http://www.yahoo.com.ar/respuestas

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.