Re: Delete first line from file
what about the following? f = open( 'file.txt', 'r' ) lines = f.readlines() f.close() f = open( 'file.txt'.'w' ) f.write( '\n'.join( lines[1:] ) ) f.close() cheers, pieter On Tue, 1 Mar 2005 12:42:00 +, Peter Nuttall <[EMAIL PROTECTED]> wrote: > On Tue, Mar 01, 2005 at 01:27:27PM +0100, Tor Erik S?nvisen wrote: > > Hi > > > > How can I read the first line of a file and then delete this line, so that > > line 2 is line 1 on next read? > > > > regards > > > > > > I think you can do something like: > > n=false > f=file.open("") #stuff here > g=[] > for line in f.readlines(): >if n: g.append(line) >n=true > > #write g to file > > if you are on a unix box, then using the standard untils might be a > better idea. > > Pete > > -- > http://mail.python.org/mailman/listinfo/python-list > -- pieter claerhout . [EMAIL PROTECTED] . http://www.yellowduck.be/ -- http://mail.python.org/mailman/listinfo/python-list
RE: Finding a script's home directory?
The following should work: os.path.split( os.path.realpath( sys.argv[0] ) )[0] Cheers, pieter -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gabriel Cooper Sent: 24 January 2005 16:40 To: python-list@python.org Subject: Finding a script's home directory? In one of my python programs has a data file I need to load. My solution was to say: if os.path.exists(os.path.join(os.getcwd(), "config.xml")): self.cfgfile = os.path.join(os.getcwd(), "config.xml") Which works fine... as long as you're *in* the script's home directory when you run it (as in, run it as: ./startApp.py as opposed to ./myApp/startApp.py). If I run it from an alternate directory the program looks for the config.xml file in my current directory not the app's home directory. So how do I get the script's home directory? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list