473,379 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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

Aug 18 '06 #1
5 1396
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

Aug 18 '06 #2

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

Aug 19 '06 #3
At Saturday 19/8/2006 01:16, ti*****@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

Aug 19 '06 #4

Gabriel Genellina wrote:
At Saturday 19/8/2006 01:16, ti*****@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

Aug 20 '06 #5
At Saturday 19/8/2006 23:43, ti*****@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

Aug 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andy Jacobs | last post by:
Hi all I have a search function on a site of mine. At the moment, the content is delivered using this: <?php echo $row_Recordset1; ?> The search function goes through the table and...
4
by: Ken Fine | last post by:
I'm looking to find or create an ASP script that will take a string, examine it for a search term, and if it finds the search term in the string, return the highlighted search term along with the...
14
by: vic | last post by:
My manager wants me to develop a search program, that would work like they have it at edorado.com. She made up her requirements after having compared how search works at different websites, like...
19
by: RAJASEKHAR KONDABALA | last post by:
Hi, Does anybody know what the fastest way is to "search for a value in a singly-linked list from its tail" as oposed to its head? I am talking about a non-circular singly-linked list, i.e.,...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
1
by: jrs_14618 | last post by:
Hello All, This post is essentially a reply a previous post/thread here on this mailing.database.myodbc group titled: MySQL 4.0, FULL-TEXT Indexing and Search Arabic Data, Unicode I was...
3
by: Harry Haller | last post by:
What is the fastest way to search a client-side database? I have about 60-65 kb of data downloaded to the client which is present in 3 dynamically created list boxes. The boxes are filled from 3...
3
by: Richard S | last post by:
CODE: ASP.NET with C# DATABASE: ACCES alright, im having a problem, probably a small thing, but i cant figure out, nor find it in any other post, or on the internet realy (probably cuz i wouldnt...
4
by: MrWelfare | last post by:
Hi Everyone, I'm currently trying to follow an example I found in a book a while ago to try to create a spotlight (mac-like) search that filters results as one types. The script that I have works...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.