Python Forum
Is it possible to multi line a Basic Function Construct line statement? If so how?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it possible to multi line a Basic Function Construct line statement? If so how?
#1
Information 
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! :)
Reply
#2
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! :)
“And one of the elders saith unto me, Weep not: behold, the Lion of the tribe of Juda, the Root of David, hath prevailed to open the book,...” - Revelation 5:5 (KJV)

“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)

#LetHISPeopleGo

Reply
#3
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,
	)
:)
“And one of the elders saith unto me, Weep not: behold, the Lion of the tribe of Juda, the Root of David, hath prevailed to open the book,...” - Revelation 5:5 (KJV)

“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)

#LetHISPeopleGo

Reply
#4
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.
Reply
#5
Thumbs Down 
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.
“And one of the elders saith unto me, Weep not: behold, the Lion of the tribe of Juda, the Root of David, hath prevailed to open the book,...” - Revelation 5:5 (KJV)

“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)

#LetHISPeopleGo

Reply
#6
(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... Bonk
Larz60+ likes this post
« We can solve any problem by introducing an extra level of indirection »
Reply
#7
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.
Reply
#8
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing the code line number arbiel 2 111 5 hours ago
Last Post: arbiel
  How to add multi-line comment section? Winfried 3 435 Jun-04-2024, 07:24 AM
Last Post: Gribouillis
  I can't for the life of me get this basic If statement code to work CandleType1a 8 447 May-21-2024, 03:58 PM
Last Post: CandleType1a
  Line graph with two superimposed lines sawtooth500 4 499 Apr-02-2024, 08:56 PM
Last Post: sawtooth500
  break print_format lengthy line akbarza 4 521 Mar-13-2024, 08:35 AM
Last Post: akbarza
  Reading and storing a line of output from pexpect child eagerissac 1 4,505 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  coma separator is printed on a new line for some reason tester_V 4 643 Feb-02-2024, 06:06 PM
Last Post: tester_V
  problem with spliting line in print akbarza 3 524 Jan-23-2024, 04:11 PM
Last Post: deanhystad
  Unable to understand the meaning of the line of code. jahuja73 0 426 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Receive Input on Same Line? johnywhy 8 1,033 Jan-16-2024, 03:45 AM
Last Post: johnywhy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020