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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:05:50+00:00 2026-05-30T07:05:50+00:00

import string file = open(‘Text.txt’) dataArray = file.read() file.close() dataArray = str(dataArray) letters =

  • 0
import string

file = open('Text.txt')
dataArray = file.read()
file.close()

dataArray = str(dataArray)
letters = []

qString = ""
for j in dataArray:
    if j.islower() == True:
    qString = qString + "l"
else:
    qString = qString + "u"

for i in range(0,len(dataArray)):
    indexNum = qString.find("luuuluuul")
    letters.append(dataArray[indexNum+4])
    qString.replace(indexNum+4,"-")

print letters

I’m programming in python, and attempting to find a sequence of letters in a text file that goes 1 lowercase letter, 3 uppercase letters, 1 lowercase letter, 3 uppercase letters, 1 lowercase letter. What I have should work as far as I know, but it gives an an error “expected character buffer object”. I’m wondering if anyone can see where I’m going wrong. The error is ocuring from:
qString.replace(indexNum+4,”-“)

  • 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-05-30T07:05:52+00:00Added an answer on May 30, 2026 at 7:05 am
    1. str.replace is not for replacing at an index–it’s for replacing based on content.

      >>> "abc".replace("b","44")
      'a44c'
      

      The line that gives you your error is qString.replace(indexNum+4,"-") for that reason. The most obvious workaround is probably to slice off either side and re-join the pieces back with the new content.

    2. Growing a string by repeated appends q = q + ... is inefficient. Most of the time what we do instead is

      pieces = []
      for something in some_things:
          pieces.append(make_piece_of_string(something))
      s = ''.join(pieces)
      
    3. You do not need to import string here.

    4. Using str.find without checking if result == -1 is always wrong. Consider using str.index instead.

    5. Checking if x == True is silly (and sometimes buggy)–just check if x. In your case, if j.islower().

    6. You have an indentation error in the code you posted. Try to post code that is exactly the code you’ve run (and preferably self-contained, not reading files you don’t provide, etc.) to get the best answers possible.

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

Sidebar

Related Questions

In Python, I can do this: >>> import string >>> string.letters 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' Is there
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateDemo { public static void main(String[]
#!/usr/bin/python import random import string appendToFile = open(appendedFile, a ) # Generator for i
import java.io.*; public class Demo{ public static void main(String[] args){ File f = new
I have created a file reader class called ECGFilereader which should open a .txt
This is good: import string string.capwords("proper name") Out: 'Proper Name' This is not so
I have the following code: import string import random d =[random.choice(string.uppercase) for x in
It seems like there should be a simpler way than: import string s =
Please have a look at the code below: import string from collections import defaultdict
My users will import through cut and paste a large string that will contain

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.