Re: can you improve this text-only beginner copy program?

Thomas Passin <[email protected]>
Newsgroups gmane.comp.python.general
Message-ID <[email protected]>
On 8/27/2025 1:45 PM, Stefan Ram wrote:
> Ethan Carter <[email protected]> wrote or quoted:
>> You're right.  There's no written statement.  The exercise was suggested
>> by the teacher while in class.  It was something like ``write a program
>> that copies text files by getting source and destination via the
>> command-line.''
> 
>    Well then, I'd think about using "shutil", e.g., "shutil.copy".
>    Check it out in "The Python Library Reference"; it's 11.10.1 in
>    release 3.13.0a0.

It sounds like the main point of the exercise may have been to use 
command line arguments. The Original Post tried to do this in a 
complicated and clumsy (non-Pythonic) way.

Easier and more Pythonic would be to delete the def main() block and then:

if __name__ == '__main__':
     import sys  # could import this at start of file
     if len(sys.argv) == 3:
         copy(sys.argv[1], sys.argv[2])
     else:
         print(usage(sys.argv[0]))

or perhaps easier to read:

if __name__ == '__main__':
     import sys  # could import this at start of file
     try:
         prog, src, dest = sys.argv
     except:
         print(usage(sys.argv[0]))
         sys.exit(1)  # or some other error code
     copy(src, dest)


>> But, yeah, if the Python community doesn't do that, it's all what you
>> say.
> 
>    Community or no community, in Python, you can have:
> 
> def f( s, S ):
>      return 2*s+S
> 
>    . Should the docs then say, "returns 2*S+S"?
> 
>> PS.  Is it just me or there's just us in this used-to-be-very-active
>> group?  Thanks for being my teacher here.  Have a good day!
> 
>    Thanks, you too!
> 
>    On one hand, many people seem to prefer websites for discussions
>    nowadays. On the other hand, if I had not responded, probably
>    someone else would have.
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.