Posts: 89
Threads: 26
Joined: Mar 2020
May-23-2024, 12:52 AM
Hey everyone!
Just learned how to properly pass variables while dropping globals as my Primary method of utilizing them.
My Monitor(s) are ancient and that means my Screen Resolution is very low; with this said... I need to know how to (if possible and permitted by Python 3.12.3+)
1) How to take a Basic Function Construct and make it multi-line; so I don't have to scroll when passing a ton of variables as arguments/parameters.
def basic_function_construct_for_loc_gov_collection_maximum_page_count_using_two_fstring_
variables(loc_gov_collection_name_item_count): This code chokes on the following ...
Traceback Error:
digitalninja@FulgorDragonR1:~/Python3x_loc.gov__headless_recursive_traversing__safeguarding__creating_datasets$ python3 05.21.2024_loc.gov__headless_recursive_traversing__safeguarding__creating_datasets__R2_commenting_middle_of_updates_expansion__for_testing_of_passing_variables_differently.py
File "/home/digitalninja/Python3x_loc.gov__headless_recursive_traversing__safeguarding__creating_datasets/05.21.2024_loc.gov__headless_recursive_traversing__safeguarding__creating_datasets__R2_commenting_middle_of_updates_expansion__for_testing_of_passing_variables_differently.py", line 72
def basic_function_construct_for_loc_gov_collection_maximum_page_count_using_two_fstring_
^
SyntaxError: expected '('
digitalninja@FulgorDragonR1:~/Python3x_loc.gov__headless_recursive_traversing__safeguarding__creating_datasets$ Thanks in advance Python3x Coders! :)
Posts: 89
Threads: 26
Joined: Mar 2020
Okay so I semi-solved it by referencing a StackOverflow post found here: https://stackoverflow.com/questions/2498...8-standard
I went with this approach (Interestingly enough; I am only able to utilize this technique with 1 passed argument/parameter); when I use two of them; Python Chokes with x Python Variable isn't defined.
Current Working Basic Function Construct in multi-line format utilizing the passing of Python Variables as Function Parameters:
loc_gov_collection_name_item_count is a Python Variable declared and defined in the header of My Python Program Code .py File.
The Basic Building of a Multi-Line Technique Python Function Construct: (Python 3.12.3) - debian-12.5.0-amd64...
def basic_function_construct_for_loc_gov_collection_maximum_page_count_using_two_fstring_variables(
loc_gov_collection_name_item_count): The Executing of My Basic Building of a Multi-Line Technique Python Function Construct: (Python 3.12.3) - debian-12.5.0-amd64
basic_function_construct_for_loc_gov_collection_maximum_page_count_using_two_fstring_variables(
loc_gov_collection_name_item_count) Still _require_ More than 1 Python Variable pass into my Basic Function Construct Multi-Line so it's fully scale-able. I will demonstrate what happens when I utilize two. However I may have figured it out while typing this (I'm not sure if the second Python Variable is in the Header). Keyboard Crossed! :)
Posts: 89
Threads: 26
Joined: Mar 2020
Alright! I solved it! Hope it helps a Newbie Like me! :)
Godspeed and stay True to Jesus & Country! Remember: YOU matter; YOUR will Matters; Justice for YOU matters! No matter what anyone says. God gives us three great gifts! 1) Life, 2) Free Will 3) HIS Only Begotten Son, JESUS! What we do with these is OUR gift to Him.
Self-Solve!
Part-A: (Header Declaration of Python Variables)[/b]
loc_gov_collection_name_item_count = 2843
loc_gov_collection_name_item_results_maximum_display_count = 150 [b]Part-B: (Basic Python Multi-Line Construct w/ Passing of Two Variables as Function Parameters)
def basic_function_construct_for_loc_gov_collection_maximum_page_count_using_two_fstring_variables(
loc_gov_collection_name_item_count,
loc_gov_collection_name_item_results_maximum_display_count,
): Part-C: (Basic Python Multi-Line Construct w/ Passing of Two Variables as Function Parameters) - Executing said Function in Multi-Line...
basic_function_construct_for_loc_gov_collection_maximum_page_count_using_two_fstring_variables(
loc_gov_collection_name_item_count,
loc_gov_collection_name_item_results_maximum_display_count,
) :)
Posts: 6,798
Threads: 20
Joined: Feb 2020
Shorter function and variable names would help. More logical functions would help a lot. basic_function_construct_for_loc_gov_collection_maximum_page_count_using_two_fstring_variables just doesn't sound like something that should be a function.
Posts: 89
Threads: 26
Joined: Mar 2020
May-23-2024, 05:17 AM
And some may wonder why nobody is ever on this forum...
So kind! :)
NOT!
(May-23-2024, 03:11 AM)deanhystad Wrote: Shorter function and variable names would help. More logical functions would help a lot. basic_function_construct_for_loc_gov_collection_maximum_page_count_using_two_fstring_variables just doesn't sound like something that should be a function.
Posts: 4,790
Threads: 76
Joined: Jan 2018
(May-23-2024, 01:48 AM)BrandonKastning Wrote: def basic_function_construct_for_loc_gov_collection_maximum_page_count_using_two_fstring_variables(
loc_gov_collection_name_item_count,
loc_gov_collection_name_item_results_maximum_display_count,
): Functions and variable names should be sufficiently explicit but not excessively detailed. I think the problem is similar to the choices you make in natural language. Would you say «Joe Biden drank a tea» or «Joseph Robinette Biden Jr 46th president of the United States, member of the Democratic Party and former vice-president drank a tea» ? If you had 10 sentences involving Joe Biden, you would certainly not choose the latter. The same good sense applies to keep programs readable.
When this naming issue is solved, one good advice: use Black to format automatically your Python code. It will save you a lot of work.
(May-23-2024, 01:56 AM)BrandonKastning Wrote: Godspeed and stay True to Jesus & Country! Remember: YOU matter; YOUR will Matters; Justice for YOU matters! No matter what anyone says. God gives us three great gifts! 1) Life, 2) Free Will 3) HIS Only Begotten Son, JESUS! What we do with these is OUR gift to Him. Not sure superstition helps...
« We can solve any problem by introducing an extra level of indirection »
Posts: 1,950
Threads: 8
Joined: Jun 2018
May-23-2024, 01:30 PM
(This post was last modified: May-23-2024, 01:30 PM by perfringo.)
If I look at this:
def basic_function_construct_for_loc_gov_collection_maximum_page_count_using_two_fstring_variables(
loc_gov_collection_name_item_count,
loc_gov_collection_name_item_results_maximum_display_count,
): I see lot of redundant information which should not be in the name of function. For example: basic_function_construct , for_local_gov_collection , using_two_fstring_variables . It seems to me, that this could be just def maximum_page_count():
There are conventional ways to retain additional information about code:
- There is docstring which can be utilized for additional information about code. Some information could be script level docstring, some function level docstring.
- There are type hints which can be used (instead of
using_two_fstring_variables )
- There are comments (both block and inline)
So one can write something like:
"""Complex program consisting basic function construct to spread the truth"""
def truth(quote: str, source: str) -> str:
"""Join two parameters into str separated with space"""
return " ".join([quote, source])
data = ("Like a dog that returns to his vomit is a fool who repeats his folly.",
"Proverbs 26:11")
print(truth(data[0], data[1]))
Gribouillis likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Posts: 6,798
Threads: 20
Joined: Feb 2020
Quote:1) How to take a Basic Function Construct and make it multi-line; so I don't have to scroll when passing a ton of variables as arguments/parameters.
"passing a ton of variables" should be avoided. If you pass a "ton of variables" to a function it nearly always means the function is not well defined. This is supported by your example function names that don't sound like they describe a well defined task, but rather a grab bag of related activities. Shorter functions that perform well defined tasks and take 5 or fewer arguments will make your code easier to read and understand. And there will be a lot less scrolling involved.
It is good that you are getting away from global variables.
|