-2

I have a text file that i want to copy from line by line and paste into a webpage, how would i go about this?

I have no code so far, I can only find things about copying the actual file itself and copying lines into another file

This is my 3rd day learning python so you might need to do some extra explaining lol.

sh4pp
  • 11
  • 2
  • What do you mean by "*paste into a webpage*"? As in manually, not using Python, using the standard "Ctrl+V" or right-click+paste? For the part about copying the file contents into the clipboard, see [How to copy content inside of a txt file to clipboard?](https://stackoverflow.com/q/36391824/2745495) – Gino Mempin Jun 08 '20 at 09:55

1 Answers1

2

If you have pip, you can install a module called pyperclip.

On macOS:

pip3 install pyperclip (sometimes add --user onto the end)

On Windows:

pip install pyperclip

Now that you have this installed, you need to read the file with file.read() and store it into a variable, then call pyperclip.copy(variablename).

Full code:

import pyperclip

with open("path/to/file.txt") as f:
    data = f.read()
    pyperclip.copy(data)