Module Making 2 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Module Making 2

How would you make this code work? >>Code import _whatever_ as wt wt.text(text="hi") >>Output hi

20th Jun 2020, 8:10 PM
Gurseerit Singh Chahal āœ“
Gurseerit Singh Chahal āœ“ - avatar
9 Answers
+ 1
def text(msg="my default text"): return msg print(text(msg="Hi"))
20th Jun 2020, 8:30 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
Hi! You make first a module file with the name _whatever_.py. In that file you create a function with the name text(), that contain a keyword argument and that return the argument. That id actually all you need to do. /Regards Per B
20th Jun 2020, 8:20 PM
Per Bratthammar
Per Bratthammar - avatar
0
What would be the code tho
20th Jun 2020, 8:21 PM
Gurseerit Singh Chahal āœ“
Gurseerit Singh Chahal āœ“ - avatar
0
I know how to make modules but I don't know how to make that arg
20th Jun 2020, 8:22 PM
Gurseerit Singh Chahal āœ“
Gurseerit Singh Chahal āœ“ - avatar
0
tysm
20th Jun 2020, 8:30 PM
Gurseerit Singh Chahal āœ“
Gurseerit Singh Chahal āœ“ - avatar
0
How would we make it not have to have print?
20th Jun 2020, 8:34 PM
Gurseerit Singh Chahal āœ“
Gurseerit Singh Chahal āœ“ - avatar
0
You can always assign it to a variable and print it out later: my_var = wt.text(msg="hi") But if you call the function from the interactive prompt, it will probably print it out without using print, if you donā€™t assign it. It is one of the specially things with the interactive prompt.
20th Jun 2020, 8:48 PM
Per Bratthammar
Per Bratthammar - avatar
0
What about making a tkinter label
20th Jun 2020, 8:49 PM
Gurseerit Singh Chahal āœ“
Gurseerit Singh Chahal āœ“ - avatar
0
Tkinter: x = Tk() l = Label(x, text="hi") My Module : sysLabel(msg="somthing") Output of both : hi (In GUI)
20th Jun 2020, 8:51 PM
Gurseerit Singh Chahal āœ“
Gurseerit Singh Chahal āœ“ - avatar