On Mon, Jul 12, 2010 at 2:33 PM, Jia Hu wrote:
> Thank you. It works now.
>
> if I use 'print' to print the whole list, 'print' will add newline
> at the end of the list but not each item in the list. right?
>
> For the code:
> for line in fileName:
> line = line.rstrip('\n')
> I think this
Thomas,
> split() also splits at other whitespace.
Doh! Corrected version follows:
print ''.join( open( 'Direct_Irr.txt' ).read().splitlines() )
Broken out:
- open(): open file
- read(): read its entire contents as one string
- splitlines(): split the contents into a list of lines
(splits
On 07/12/2010 11:29 PM, pyt...@bdurham.com wrote:
> Jia,
>
> print ''.join( open( 'Direct_Irr.txt' ).read().split() )
>
> Broken out:
>
> - open(): open file
> - read(): read its entire contents as one string
> - split(): split the contents into a list of lines
> (splits lines at \n; does not
Thank you. It works now.
if I use 'print' to print the whole list, 'print' will add newline
at the end of the list but not each item in the list. right?
For the code:
for line in fileName:
line = line.rstrip('\n')
I think this will affect 'fileName' because it assign the value to 'line' ?
B
Jia,
print ''.join( open( 'Direct_Irr.txt' ).read().split() )
Broken out:
- open(): open file
- read(): read its entire contents as one string
- split(): split the contents into a list of lines
(splits lines at \n; does not include \n in split values)
- ''.join(): join list of lines with an e
On Mon, Jul 12, 2010 at 1:27 PM, Jia Hu wrote:
> Hi, I just want to delete "\n" at each line. My operating system is ubuntu
> 9.1. The code is as follows
>
> #!/usr/bin/python
> import string
> fileName=open('Direct_Irr.txt', 'r') # read file
> directIrr = fileName.readlines()
> fileName.close()
>
On Mon, Jul 12, 2010 at 2:27 PM, Jia Hu wrote:
> Hi, I just want to delete "\n" at each line. My operating system is ubuntu
> 9.1. The code is as follows
>
> #!/usr/bin/python
> import string
> fileName=open('Direct_Irr.txt', 'r') # read file
> directIrr = fileName.readlines()
> fileName.close()
>
I hope this could help:
>>> f = open('powersave.sh')
>>> map(lambda s: s.strip(), f.readlines())
['echo 1 > /sys/module/snd_hda_intel/parameters/power_save', 'echo
min_power > /sys/class/scsi_host/host0/link_power_management_policy',
'echo 1 > /sys/module/snd_hda_intel/parameters/power_save']
I k