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 8070949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:32:49+00:00 2026-06-05T13:32:49+00:00

For some reason my code works for all the 10 digit numbers but not

  • 0

For some reason my code works for all the 10 digit numbers but not for the 3-4 digit numbers. I created a sample concept to try to simplify this so that I could see where my logic went wrong. But my sample works perfectly, yet my actual code doesn’t. My conclusion is that it has to be something with reading data from SQLite or CSV. Here is the sample concept code which works great:

test_list = [ (1, 1234567890), (2, 987654321), (3, 123), (4, 4567) ]
# showing all contents
print test_list

# proving it is a list
print type(test_list)

# comparison list
new_list = [ 1234567890, 987654321, 123, 4567, 1567839890, 987654321 ]

# find k given matching v
for num in new_list:
  for k, v in test_list:
    if v == num:
      print 'the key of ' + str(num) + ' = ' + str(k)

Here is the non-working code:

def populateTextMsgs(csvfile, db):
  conn = sqlite3.connect(db)
  conn.text_factory = str  # 8-bit bytestrings
  cur = conn.cursor()

  # get subscribers and write to subscriber_list, no problems here
  cur.execute('SELECT subscriber_id, phone_number FROM subscriber')
  subscriber_list = cur.fetchall()  # this is getting all the subscribers

  # no problems here
  # read values from tab-delimited csv file
  i = 1  # do not use first line (contains headers)
  reader = csv.reader(open(csvfile, "rU"), delimiter = '\t')
  for Number, Name, Message, Datetime, Type in reader:
    # check to ensure name/number not null and not first record
    if Number and Name and i > 1:
      # if number starts with '1' then remove first digit
      if str(Number)[0] == '1':
        Number = int(str(Number)[1:])

      # this is where I think the problem is, but cannot figure out why
      # return subscriber_id (sid) given phone number
      for sid, num in subscriber_list:
        if num == Number:
          # insert messages into textmsg table
          cur.execute('INSERT OR IGNORE INTO textmsg (subscriber_id, msg, datetime, type) VALUES (?,?,?,?)', (sid, Message, Datetime, Type))
          conn.commit()

    i += 1  # iterator to ensure first line is not used but others are

  cur.close()
  conn.close()
  print '...Successfully populated textmsg table.'

This works for all the long numbers, but it does not get the data with the short numbers. Why?

  • 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-05T13:32:50+00:00Added an answer on June 5, 2026 at 1:32 pm

    Simply replace if num == Number: with if num == int(Number): and you should be good, you were already converting some of them, those that began with 1 but not others, the csv reader only returns strings while sqlite returns different types depending on the column … and hence you were comparing string and ints …

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

Sidebar

Related Questions

For some reason, this code works all chrome, safari, and ei but not on
For some reason, when I try to generate this code all at once, the
ok, this code works just fine in Chrome. But, for some reason it does
For some reason this code is not checking the current password with the database
For some reason my code works perfectly for Froyo(API 8) but gives me a
for some reason this code wont work, it doesn't seem to read the javascript.php
For some reason my code here (this is the entire thing) doesnt actually render
for some reason after having changed my code from this: <script type=text/javascript> $(document).ready(function(){ $(recipebutton1).click(function(){
For some reason the following code doesn't work on Windows XP. new URL(file:// +
For some reason my bind events won't work. You can see my code here:

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.