Re: [Tutor] printing files

2009-03-26 Thread Alan Gauld

"Kent Johnson"  wrote
On Thu, Mar 26, 2009 at 2:58 PM, ALAN GAULD  
wrote:

Use '\n'.join(handle[1:])
It will create a string from your list with newline as separator.


The lines from readlines() include the newlines already.


Ah, OK, I couldn't remember if readlines stripped them off or not.


print>>out, handle[1:]

 In the out file, it saves the lines as a list rather than as a string.



use
 out.writelines(handle[1:])


Or if you really want to use the print style

print>>out, ''.join(handle[1:])

ie join the lines using an empty string.

Alan G



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Updating Python on Mac OS X 10.5.6

2009-03-26 Thread Alan Gauld


"NBarnes"  wrote 


Fortress).  It seems like Python would be a good choice for such a
relatively simple project, and I've been wanting to learn Python.

seems reasonable), but I understand that we've since moved on to
Python 2.6?  And that Python 3.0 is out?  Is 3.0 mature enough to
support this sort of programming?


I'd go with Python 2.6 for learning.

Most tutorials are still either upgrading to v3 or stuck at v2.
Once you are comfortable with 2 you can set a flag on v2.6 that 
will flag any v3 incompatibilities so that you can fix them and get 
used to the diffrences before finally moving to v3. And by that time 
most of the 3rd party tools etc will be ported too!


HTH,

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] printing files

2009-03-26 Thread Kent Johnson
On Thu, Mar 26, 2009 at 2:58 PM, ALAN GAULD  wrote:
> Use '\n'.join(handle[1:])
> It will create a string from your list with newline as separator.

The lines from readlines() include the newlines already.

> When i use the following
>
> print>>out, handle[1:]
>
> In the out file, it saves the lines as a list rather than as a string. How
> to avoid this.

use
  out.writelines(handle[1:])

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Updating Python on Mac OS X 10.5.6

2009-03-26 Thread NBarnes
I'm wanting to put together a simple helper application for a game (a
better version of Dwarf Foreman for the highly addictive Dwarf
Fortress).  It seems like Python would be a good choice for such a
relatively simple project, and I've been wanting to learn Python.

But I'm not sure what version of Python to use or how to update my
Macbook's Python framework.  Idle claims that I have Python 2.5 (which
seems reasonable), but I understand that we've since moved on to
Python 2.6?  And that Python 3.0 is out?  Is 3.0 mature enough to
support this sort of programming?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Posting to Tkinter NG in new.gmane.org

2009-03-26 Thread Robert Berman
Is this a news group or a list group. If it is a news group, you can't 
use your regular email. I use T-Bird and to subscribe to 'news groups' 
you must have access to a news group server. If you look under the news 
properties under servers, you must provide a news group server (NNTP). 
Your email server(usually POP) will not work.


Robert Berman

Alan Gauld wrote:


"Wayne Watson"  wrote



   My e-mail address is valid. Any ideas? I've compacted related 
Trash folders, etc



 It should be news.gmane.org... Or is that just a typo?


In that case you probably need to tell us more.
Can you read the group OK in TBird?

What other settings are you using?
I can't help much as I don't use TBird...

Alan G

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] printing files

2009-03-26 Thread ALAN GAULD
Use '\n'.join(handle[1:])

It will create a string from your list with newline as separator.

 Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/






From: Bala subramanian 
To: Alan Gauld 
Sent: Thursday, 26 March, 2009 6:11:59 PM
Subject: Re: [Tutor] printing files

yes you are right,
When i use the following

print>>out, handle[1:]

In the out file, it saves the lines as a list rather than as a string. How to 
avoid this. 

Bala


On Thu, Mar 26, 2009 at 7:05 PM, Alan Gauld  wrote:


"Bala subramanian"  wrote


for files in flist:
 handle=open(flist).readlines()
 print>>out, handle  


 print>>out, handle[1:]

Should do it? You might need to handle line endings though...  
Alan G.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Posting to Tkinter NG in new.gmane.org

2009-03-26 Thread Alan Gauld


"Wayne Watson"  wrote



   My e-mail address is valid. Any ideas? I've compacted related Trash 
folders, etc



 It should be news.gmane.org... Or is that just a typo?


In that case you probably need to tell us more.
Can you read the group OK in TBird?

What other settings are you using?
I can't help much as I don't use TBird...

Alan G 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] printing files

2009-03-26 Thread Alan Gauld


"Bala subramanian"  wrote


for files in flist:
  handle=open(flist).readlines()
  print>>out, handle  


  print>>out, handle[1:]

Should do it? You might need to handle line endings though...  


Alan G.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] printing files

2009-03-26 Thread Marc Tompkins
On Thu, Mar 26, 2009 at 10:56 AM, Marc Tompkins wrote:

> Without changing anything else, you could do it with a slice:
>

You should probably also close your input files when you're done with them.

-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] printing files

2009-03-26 Thread Marc Tompkins
On Thu, Mar 26, 2009 at 10:42 AM, Bala subramanian <
bala.biophys...@gmail.com> wrote:

>print>>out, handle  <-- Here i want to write only from second line. I
> dnt want to loop over handle here and putting all lines except the first one
> in
> another variable. Is there any
> fancy way of doing it.
>


Without changing anything else, you could do it with a slice:

flist=glob.glob(*.txt)
> out=open('all','w')
>
> for files in flist:
>handle=open(flist).readlines()
>print>>out, handle[1:]  # start with second item (indexes start at 0,
> remember) and go to end
> out.close()
>


-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] printing files

2009-03-26 Thread Bala subramanian
Friends,
My files are like below
file1  file2
RemarkRemark
  ---
  ---

I have huge number of such files. I want to concatenate all files in one
huge file. I could do it with a script. But i want to omit the first line
(ie Remark in each file) and concatenate. How to do the same ?

flist=glob.glob(*.txt)
out=open('all','w')

for files in flist:
   handle=open(flist).readlines()
   print>>out, handle  <-- Here i want to write only from second line. I dnt
want to loop over handle here and putting all lines except the first one in
another variable. Is there any
fancy way of doing it.
out.close()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Posting to Tkinter NG in new.gmane.org

2009-03-26 Thread Wayne Watson
Title: Signature.html




Yes, a typo.

Alan Gauld wrote:

"Wayne Watson"  wrote
  
  
  My e-mail address is valid. Any ideas? I've
compacted related Trash folders, etc

  
  
It should be news.gmane.org... Or is that just a typo?
  
  
Alan G. 
  
___
  
Tutor maillist  -  Tutor@python.org
  
http://mail.python.org/mailman/listinfo/tutor
  
  


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


“Life is one damn thing after another."
 -- Mark Twain 





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Posting to Tkinter NG in new.gmane.org

2009-03-26 Thread Alan Gauld


"Wayne Watson"  wrote

My e-mail address is valid. Any ideas? I've compacted related Trash 
folders, etc


It should be news.gmane.org... Or is that just a typo?

Alan G. 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor