[Pythonmac-SIG] inputing multi-digit numbers
Kirk Durston
kdurston at uoguelph.ca
Thu Nov 10 15:26:20 CET 2005
On 11/10/05 8:01 AM, "Henning.Ramm at mediapro-gmbh.de"
<Henning.Ramm at mediapro-gmbh.de> wrote:
>> I¹m having a hard time figuring out how to input a list of numbers, each one
>> of which can be 1, 2, or 3 digits in length. First, I select a column in an
>> Excel file, and copy and past it into a Word file. I then save it as a text
>> file. I then open a new window in Python and copy and paste the column of
>> numbers from the text file into the window and save it as Function ID¹
>>
>> In my main program, I type
>>
>> input=open('Function ID', 'r')
>> x=input.readlines()
>> input.close()
>> print x
>>
> Try open (or file) with mode 'rU' (universal newline support), apparently the
> \r is not recognized as \n
>
> Best regards,
> Henning Hraban Ramm
> Südkurier Medienhaus / MediaPro
> Support/Admin/Development Dept.
>
Thank you. That gives me something closer to a list, but the output is now:
['939\n', '936\n', '937\n', '885\n', '886\n', '887\n', '171\n', '19\n', ...]
Question: how do I get rid of the \n attached to each member in my list? I
still need to do a lot of work with the contents of the list. I could run
each member of the list through a loop and slice off the \n, but I imagine
there is a more efficient way to do the job. Is there?
Thank you for your help.
Kirk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythonmac-sig/attachments/20051110/925fcca0/attachment.html
More information about the Pythonmac-SIG
mailing list