[Tutor] path to executing .py file

2009-04-13 Thread tiefeng wu
Hello everybody!
I'm working on my code repository (svn) auto-backup script which get hotcopy
of svn repository
directory to a directory named by date in same location where script file
is, it executed by a timer
program every 00:00 clock. Everything works fine when I'm testing by double
click it. But when
auto execute it, I got unexpected behavior. The backup directory will be
created under
"C:\Documents and settings\username". I create backup directory by this way:

os.mkdir(os.getcwd() + arch_dir)

is there some way to get path to my executing script, so I can replaced
"os.getcwd()" in above
line?

And I have another question, I've tried remove a copy of svn repository by
calling

shutil.rmtree(svn_repos_copy_dir)

I got error "Access denied!" Is that mean my script has no power to delete
it? Is there some way to
give the right to do that?

thanks

tiefeng wu
2009-04-14
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] path to executing .py file

2009-04-14 Thread tiefeng wu
>
> is there some way to get path to my executing script, so I can replaced
>> "os.getcwd()" in above line?
>>
>
> Look at the recent thread on creating exe files with py2exe.
> Investigate the __file__  variable...


thanks, Alan Gauld. thanks for your patience for such a trivial question:)


> shutil.rmtree(svn_repos_copy_dir)
>>
>> I got error "Access denied!" Is that mean my script has no power to delete
>> it?
>>
>
> More likely the user running the script does not have the correct
> access permissions or someone else is using the repository at
> the time thus locking it.


as I mentioned, that's a COPY of svn repository, I'm sure there's no one
locking it
I tried manually delete it by 'del' and 'rm' under command line, and I got
same error,
but deleting in windows explorer (with same user login as script was called)
with no
problem.

if this question has nothing concerned with this mailing list, I'm sorry an
please ignore it.

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


Re: [Tutor] reading file, adding to each line, writing file

2009-02-04 Thread tiefeng wu
> Hello everybody,
>
> I have easily spent some four hours on this problem, and I am now asking
> for rescue.
>
> Here is what I am trying to do: I have a file ("step2", with some 30 or
> so lines. To each line I would like to add " -d" at the end. Finally, I
> want to save the file under another name ("pyout".
> So far I have managed to read the file, line by line, and save it under
> another name:
>
> 
>
> # add " -d" to each line of a textfile
>
> infile = open("step2", 'r') # open file for appending
> outfile = open("pyout","a") # open file for appending
>
> line = infile.readline()# Invokes readline() method on file
> while line:
> outfile.write(line),# trailing ',' omits newline character
> line = infile.readline()
>
> infile.close()
> outfile.close()
>
> 
>
> As I said, before writing to file "pyout" I would like to append the
> string " -d" to each line. But how, where? I can't append to strings
> (which the lines gained with infile.readline() seem be), and my trial
> and error approach has brought me nothing but a headache.
>
> Thanks for your help!
>
> David
>

Hi David!
My solution of your problem would be the following:

>>> infile = open('step2', 'r')
>>> str = infile.read()
>>> infile.close()
>>> outfile = open('pyout', 'a')
>>> outfile.write(str.replace('\n', ' -d\n'))
>>> outfile.close()

hope helped
cheers!
Tiefeng Wu
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor