Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8479129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:56:20+00:00 2026-06-10T18:56:20+00:00

Have an odd issue while using the active_directory module, which is amazing BTW… awesome

  • 0

Have an odd issue while using the active_directory module, which is amazing BTW… awesome wrapper.

Anyhow, I have a need to make sure that a username is unique… heres my function:

import active_directory

def creative_name(fname, lname, n=1):
    uname = fname[:n] + lname
    x = active_directory.find_user(uname)
    if x: creative_name(fname, lname, n+1)
    else: return uname

if __name__=='__main__':
    print creative_name("Sarah", "Smith")

it keeps coming up with None… I would expect it to return uname… or

fname[:n+1] + lname

its strange because if I run the function like this:

def creative_name(fname, lname, n=1):
    uname = fname[:n] + lname
    x = active_directory.find_user(uname)
    if x: creative_name(fname, lname, n+1)
    else: print uname

>>>
SaSmith
>>>

SaSmith is returned… why won’t it return the value?!?! print uname works but return uname returns None!

Please help!

Thanks all,

Randy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:56:21+00:00Added an answer on June 10, 2026 at 6:56 pm

    It wasn’t returning SaSmith because the recursive part wasn’t being returned, so if x was true the function returned None. Adding in one return should fix:

    def creative_name(fname, lname, n=1):
        if n > len(fname): return None
        uname = fname[:n] + lname
        x = active_directory.find_user(uname)
        if x: return creative_name(fname, lname, n+1)
        else: return uname
    

    .

    Note: the first line prevents an infinite loop if active_directory.find_user(fname[:n]_lname) is True for every n.

    I agree with @Randall that using a for loop is probably more readable, it returns None in the above case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an odd issue while using FlashCS4. I have a textfield that, when
I have run into an odd casting issue while using generics. The following code
I have an odd situation in which I need to modify the position of
I'm having a particularly odd issue when developing Chrome extensions using jQuery. I have
I have a very odd issue. When I execute a specific database stored procedure
I have an odd linq subquery issue. Given the following data structure: Parents Children
I am learning JQuery, and I have ran into an odd issue. I made
This is very odd. I have never had this issue with ShowDialog in C#.
I have an odd problem with mapping in Vim. I am using an Azerty
I seem to be having an odd issue w/ the ApplicationDeployment.CheckForUpdateAsync Method. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.