Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #197826
| From | Gilmeh Serda <gilmeh.serda@nothing.here.invalid> |
|---|---|
| Subject | Re: No more Redirect page. |
| Newsgroups | comp.lang.python, alt.comp.software.firefox |
| References | <p9v66l1ltn55trg0vccg1cj83jcpm89mu1@4ax.com> <1141eb5$16llq$1@dont-email.me> |
| Message-ID | <b359S.248240$5lP1.187364@fx12.ams4> (permalink) |
| Organization | Easynews - www.easynews.com |
| Date | 2026-07-25 15:59 +0000 |
Cross-posted to 2 groups.
On Sat, 25 Jul 2026 04:33:42 -0000 (UTC), Lawrence D’Oliveiro wrote:
> I often copy and paste links into the following script for this reason.
Why not use pyperclip? Then you can just use clipboard:
1. Copy original URL
2. Run script (+ options)
3. Paste resulting URL
https://pypi.org/project/pyperclip/
You may also want to read this:
https://github.com/asweigart/pyperclip/blob/master/src/pyperclip/
__init__.py row 19.
If there are only a few options you might even wanna create an alias for
each version, like scra and scrb or something and put it in your .bashrc:
alias scra='scriptname -option1';
alias scrb='scriptname -option2';
Your use of shebang suggests *nix, so...
If I think ArgumentParser is too bulky for a small script, I usually just
use sys module, which you already have imported.
def main(opt):
URL = pyperclip.paste()
if opt == 1:
[...]
elif opt == 2:
[...]
pyperclip.copy(resulting_URL)
if __name__ == '__main__':
args = sys.argv[1:]
if '-option1' in args:
main(1)
elif '-option2' in args:
main(2)
else:
print(usage)
But each to their own... It's your script.
--
Gilmeh
Everybody likes a kidder, but nobody lends him money. -- Arthur Miller
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: No more Redirect page. Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-07-25 04:33 +0000
Re: No more Redirect page. Gilmeh Serda <gilmeh.serda@nothing.here.invalid> - 2026-07-25 15:59 +0000
Re: No more Redirect page. ram@zedat.fu-berlin.de (Stefan Ram) - 2026-07-25 16:24 +0000
Re: No more Redirect page. Gilmeh Serda <gilmeh.serda@nothing.here.invalid> - 2026-07-26 18:32 +0000
Re: No more Redirect page. Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-07-29 23:36 +0000
Re: No more Redirect page. Jon Ribbens <jon+usenet@unequivocal.eu> - 2026-07-29 23:45 +0000
csiph-web