On Fri, Sep 22, 2017, 4:07 AM jettam <[email protected]> wrote:

> It is a paragraph with a new line character at the end of each line. At
> this stage I am just trying to capture the whole paragraph. I was able to
> do that with your advice by using the name.append() in a for in statement.
> I was confused because I thought this should be captured as a string not a
> list.
>

If you just want the whole file, then you wouldn't need to loop and you
could just call fin.read() to get a big string.

If you need to individually process each line, then looping and storing to
a list means you can join the list later into a string again using:

body = '\n'.join(theWholeQuote)

There are different ways to solve the problem, but it just depends on what
you are doing with each line and what you are doing with the final text.


>
>
> On Wednesday, September 20, 2017 at 12:47:03 PM UTC-7, Justin Israel wrote:
>
>>
>>
>> On Thu, Sep 21, 2017, 5:49 AM jettam <[email protected]> wrote:
>>
>>> I am trying to capture the contents of this text document so I can
>>> operate on it. The contents is several lines making a paragraph.
>>>
>>> This is the approach I was taking but its not working. Any other
>>> suggestions ?
>>>
>>> inFile = r'E:\ProfessionalDevelopment\python\Python Scripting in
>>> Maya\week4\famousQuote.txt'
>>> theWholeQuote = ()
>>> with open (inFile,'r') as fin:
>>>     for line in fin:
>>>         theWholeQuote  = (line)
>>>
>>
>> A paragraph implies that it is a number of sentences followed by a
>> newline character. Is that the case for you, or is it really a number of
>> lines, each with their newline character, followed by extra newlines? First
>> we would need to be explicit about what separates your lines or paragraphs.
>>
>> Second, are you trying to operate on each line, each paragraph, or to
>> just capture the whole document?
>>
>> If you are trying to build up a paragraph by some delimiter, then you
>> should make theWholeQuote a list and then use theWholeQuote.append() to add
>> each component.
>>
>> Justin
>>
>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Python Programming for Autodesk Maya" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/python_inside_maya/27cdd0d9-9c7e-4a8a-b0c3-f041bdd8ac38%40googlegroups.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/27cdd0d9-9c7e-4a8a-b0c3-f041bdd8ac38%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/2b2ab4e7-598f-4a17-8b28-24d16eb3eac5%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/2b2ab4e7-598f-4a17-8b28-24d16eb3eac5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3rKm3YWqctZ%2BFt%3DKpVVC1SiS1bVcYfMEe9xA%2BAOeoAhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to