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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:37:06+00:00 2026-06-18T00:37:06+00:00

I am a python beginner and want python to capture all text in quotation

  • 0

I am a python beginner and want python to capture all text in quotation marks from a text file. I have tried the following:

filename = raw_input("Enter the full path of the file to be used: ")
input = open(filename, 'r')
import re
quotes = re.findall(ur'"[\^u201d]*["\u201d]', input)
print quotes

I get the error:

Traceback (most recent call last):
  File "/Users/nithin/Documents/Python/Capture Quotes", line 5, in <module>
    quotes = re.findall(ur'"[\^u201d]*["\u201d]', input)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 177, in findall
    return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer

Can anyone help me out?

  • 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-18T00:37:07+00:00Added an answer on June 18, 2026 at 12:37 am

    As Bakuriu has pointed out, you need to add .read() like so:

    quotes = re.findall(ur'[^\u201d]*[\u201d]', input.read())
    

    open() merely returns a file object, whereas f.read() will return a string. In addition, I’m guessing you are looking to get everything between two quotation marks instead of just zero or more occurences of [\^u201d] before a quotation mark. So I would try this:

    quotes = re.findall(ur'[\u201d][^\u201d]*[\u201d]', input.read(), re.U)
    

    The re.U accounts for unicode. Or (if you don’t have two sets of right double quotation marks and don’t need unicode):

    quotes = re.findall(r'"[^"]*"', input.read(), re.U)
    

    Finally, you may want to choose a different variable than input, since input is a keyword in python.

    Your result might look something like this:

    >>> input2 = """
    cfrhubecf "ehukl wehunkl echnk
    wehukb ewni; wejio;"
    "werulih"
    """
    >>> quotes = re.findall(r'"[^"]*"', input2, re.U)
    >>> print quotes
    ['"ehukl wehunkl echnk\nwehukb ewni; wejio;"', '"werulih"']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python beginner here. I have a text file that is sorted into columns: fields
Python beginner here, I have a list of lists and want to refer to
I'm a beginner in python. All i want to do is create a simple
Python beginner running 2.7 I want to have a list which is constantly summed
Python beginner, I have become familiar with reading through a file and doing basic
beginner to python here. I have 2 nested lists that I want to merge:
Python beginner here. I am iterating through a text file, column by column. for
I am a beginner with Python. I have a script in which I want
I am a complete beginner to Python so dont understand the lingo. I want
I'm a beginner, with programming and Python. What I want to do is read

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.