sorry for my bad English,
I have a lot of "subscripts" like this:
#trim whitespace start and end
txt = " Hello! "
strippedtxt = txt.strip()
print(strippedtxt)
#Make all text Uppercase
txt = "Hello my friends"
x = txt.upper()
print(x)
#Make all text Lowercase
txt = "Hello my friends"
x = txt.lower()
print(x)
#Make all text like proper in excel
txt = "Hello my friends"
x = txt.title()
print(x)
if the scripts are under 10, it quite easy to find,
but if you have over 100, it is quite hard to manage,
of course, you can google it, but sometimes google-ing requires times like over 20+ minutes to extract that specific code,
sadly, you have that "specific code" working perfectly, but you can't find it where put it,
so, any tips, software, or idea to handle this?
thank you have a nice day
Why do you need these scripts? Where/how do you store them? These are built-in string methods and always available.
these are not functions, and therefore get executed as the script is loaded
why are these in individual scripts?
Each script is too simple to require a separate script, and should be performed inline:
Is this a homework assignment?
If I understand you: you have a number of scripts, that you've written; each perform some task or other, or demonstrate a particular technique in or feature of Python, of which you have maybe 100+ files and you want to organize said scripts, yes?
If so, I may have a solution that may work for you; one that I use and I'll be happy to share, if that's what you need.
To add:
@
perfringo and/or @
Larz60+
Please advise:
What I have is a software solution (none commercial). If the OP comes back and asks about this, can I post a link to said software, in this thread, or would you prefer that we take this to PM?
Thanks.
I think that in case of string methods it's much easier to use help which is built-in into Python interactive interpreter:
>>> str. # two times TAB
str.capitalize( str.find( str.isdecimal( str.istitle( str.mro() str.rjust( str.strip(
str.casefold( str.format( str.isdigit( str.isupper( str.partition( str.rpartition( str.swapcase(
str.center( str.format_map( str.isidentifier( str.join( str.removeprefix( str.rsplit( str.title(
str.count( str.index( str.islower( str.ljust( str.removesuffix( str.rstrip( str.translate(
str.encode( str.isalnum( str.isnumeric( str.lower( str.replace( str.split( str.upper(
str.endswith( str.isalpha( str.isprintable( str.lstrip( str.rfind( str.splitlines( str.zfill(
str.expandtabs( str.isascii( str.isspace( str.maketrans( str.rindex( str.startswith(
String method names are quite descriptive. If you find some promising name(s) you can inspect it closer. What exactly does capitalize do?
>>> help(str.capitalize)
Help on method_descriptor:
capitalize(self, /)
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower
case.
For real snippets of code one can build wiki-like solution. One can use Jupiter notebook, Obsidian or just plain .py files in one folder. In latter case describe/comment your code snippet (what it does, what problem does it solve). Then from terminal you can grep or ack appropriate keywords, get file name(s) and open. It should not take more than 5-10 seconds.
If you have several snippets per file then ack gives row number and then you should learn whether your editor is able to open file on specific row (mine does) or you can provide ack with -C (which gives context i.e surrounding lines too) so that you don't need to open the file.
Also if using
Rich inspect
get nice colorful overview.
For local storage i make some simple as this,with backup online.
div_code\
regex_stuff\
|-- reg_example.py
|-- ect...
string_stuff\
|-- f_string.py
|-- ect ...
Online can save scripts in eg
Google Colab(NoteBook) or
GitHub or
Grepper
Other stuff that help eg
ptpython that show methods automatic.
VS Code(
IntelliSense) or PyCharm also have good autocompletion.
![[Image: 9i5WLj.jpg]](https://imagizer.imageshack.com/v2/xq90/924/9i5WLj.jpg)
thank you all,
(Oct-13-2022, 06:56 AM)perfringo Wrote: [ -> ]Why do you need these scripts? Where/how do you store them? These are built-in string methods and always available.
(Oct-13-2022, 09:01 AM)perfringo Wrote: [ -> ]I think that in case of string methods it's much easier to use help which is built-in into Python interactive interpreter:
>>> str. # two times TAB
str.capitalize( str.find( str.isdecimal( str.istitle( str.mro() str.rjust( str.strip(
str.casefold( str.format( str.isdigit( str.isupper( str.partition( str.rpartition( str.swapcase(
str.center( str.format_map( str.isidentifier( str.join( str.removeprefix( str.rsplit( str.title(
str.count( str.index( str.islower( str.ljust( str.removesuffix( str.rstrip( str.translate(
str.encode( str.isalnum( str.isnumeric( str.lower( str.replace( str.split( str.upper(
str.endswith( str.isalpha( str.isprintable( str.lstrip( str.rfind( str.splitlines( str.zfill(
str.expandtabs( str.isascii( str.isspace( str.maketrans( str.rindex( str.startswith(
String method names are quite descriptive. If you find some promising name(s) you can inspect it closer. What exactly does capitalize do?
>>> help(str.capitalize)
Help on method_descriptor:
capitalize(self, /)
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower
case.
For real snippets of code one can build wiki-like solution. One can use Jupiter notebook, Obsidian or just plain .py files in one folder. In latter case describe/comment your code snippet (what it does, what problem does it solve). Then from terminal you can grep or ack appropriate keywords, get file name(s) and open. It should not take more than 5-10 seconds.
If you have several snippets per file then ack gives row number and then you should learn whether your editor is able to open file on specific row (mine does) or you can provide ack with -C (which gives context i.e surrounding lines too) so that you don't need to open the file.
@
perfringo :
because if in the future I need it again,
I do not need to google-ing again,
I just need it from some the previous "subscripts" that I have googled previously
currently, I put that in a txt file, and over 100 "subscripts"
it does not just "always available" function, sometimes like this:
#delete file to recycle bin, to work need : pip install Send2Trash
from send2trash import send2trash
send2trash(filename)
and about help, I know that already, and I already have 100+ python files, and now I ready have difficulty managing it,
(Oct-13-2022, 06:57 AM)Larz60+ Wrote: [ -> ]these are not functions, and therefore get executed as the script is loaded
why are these in individual scripts?
Each script is too simple to require a separate script, and should be performed inline:
Is this a homework assignment?
@
Larz60+ thank you for reply,
I put the simple scripts, because I put big scripts it will take a lot of space,
the script that I put like : how to ocr image, how to translate, how to find specific tags using soup, and it already over 100 of .py files,
and no, it is not a homework assignment.
(Oct-13-2022, 08:44 AM)rob101 Wrote: [ -> ]If I understand you: you have a number of scripts, that you've written; each perform some task or other, or demonstrate a particular technique in or feature of Python, of which you have maybe 100+ files and you want to organize said scripts, yes?
If so, I may have a solution that may work for you; one that I use and I'll be happy to share, if that's what you need.
To add:
@perfringo and/or @Larz60+
Please advise:
What I have is a software solution (none commercial). If the OP comes back and asks about this, can I post a link to said software, in this thread, or would you prefer that we take this to PM?
Thanks.
@
rob101 Yes, I have that problem,
I already sent you the pm
and thank you for reply
(Oct-13-2022, 10:14 AM)snippsat Wrote: [ -> ]Also if using Rich inspect
get nice colorful overview.
![[Image: gNOIDB.png]](https://imagizer.imageshack.com/v2/xq90/922/gNOIDB.png)
For local storage i make some simple as this,with backup online.
div_code\
regex_stuff\
|-- reg_example.py
|-- ect...
string_stuff\
|-- f_string.py
|-- ect ...
Online can save scripts in eg Google Colab(NoteBook) or GitHub or Grepper
Other stuff that help eg ptpython that show methods automatic.
VS Code(IntelliSense) or PyCharm also have good autocompletion.
![[Image: 9i5WLj.jpg]](https://imagizer.imageshack.com/v2/xq90/924/9i5WLj.jpg)
@
snippsat thank you, although it not what I looking for, this is really nice info, I will add you reputation point