Hello everyone,
In this tutorial I will show you how we can style our output using string format in Python.
Some of you guys should saw in Python scripts that they are printing data like:
[+] Message | Output [+]
And this kind of printing is really looks cool to me.
Some of you guys should try something like this:
print("[+] your message [+]")
Or:
print("[+]", "your message", "[+]")
The second one is looks little bit clearer
Isn't it?, Cause of print function.
But let's suppose we are working on it large scale application and we want to print in stylish way.
But it's weird that we always have to use our style tag like:
[+] or [#]
So on every output we have to keep using our style tag but its consider as bad practice in coding to me.
As a good programmer we should try to code clean and it can be easily understand.
Whenever I code in Python my focus is write clean code and I divide the parts of program into modules (sub programs).
So for this, I always code in OOP (object oriented programming) of python.
In modules I create classes, their functions and I use them into main module by importing.
But anyway in OOP way, I will show you
How to style out put using python string format in Python
Let's create class in Python:
Class test:
def __init__(self):
self = self
Some of you or all notice that why I use constructor function
Well because I inherit other module classes like I create an helper module which have a helper class and that class have those functions, who will in every module.
anyway let's continue:
Class test:
def __init__(self):
self = self
def print(self, *msgs, style = '[+]'):
msg = " ".join( str(msg) for msg in msgs )
print(style, msg, style)
And now in our class we can use something like:
Class test:
def __init__(self):
self = self
def print(self, *msgs, style = '[+]'):
msg = " ".join( str(msg) for msg in msgs )
print(style, msg, style)
def test(self):
self.print("test")
you will output will be like this:
[+] test [+]
cool right?
I know this is not good way to style your output. But it's better if we don't touch builtin functions isn't it?
But don't worry in my next tutorial i will How to style out put using python string format without in OOP way.
Thanks for reading and i write this article cause i can't sleep and it's 5 AM here. My brain is still stuck in coding.
i will be keep posting but mostly in weekend.
Why not check my old one articles?
1. Are hacking minigames the most overused of gaming tropes?
2. HOW TO GET ADSENSE APPROVED 100% WORKING METHOD
3. HOW TO UNBLOCK ANY SITE WITHOUT USING VPN OR PROXY! - EASY LIFE WITH EASY WAYS
My wife is a programmer and she is just as crazy, she does not sleep at night and in her mind she is always processing information hahaha, even though she talks to me about her work I will never understand what she says. Greetings from Venezuela .
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulation
Today one year ago you joined SteemItThank you, for making SteemIt great and Steem on for more years to come!
(You are being celebrated here)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks for the post.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Nice one young programmer..
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Sangat membantu sekali, terimakasih atas tutorialnya, sukses terus. Salam
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
vte balek ya
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
nice work, super photography upovted, hope you also will check my post,, please
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Greetings from Venezuela!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
sangat membantu, bantu sesama ya mas ,..
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations! 🎉 Your Steemversay has arrived. One year ago today you made your steem account along with 177 others. You are one of 9 users who have posted in the last week. Well done you.
I've upvoted your post, I hope it helps. Happy Steemversay ✌️;
p.s I'm a new bot, I've only been alive 20 days :)
Learn more about SteemVersary and view awards at Steemversary
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
thank for sharing your tutorial, very good post...
and thank have your following my steemit, I also followed you @ammadkhalid
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Good day STEEMIAN!
This is all free and opensource information; all you need to do is upvote all posts of @lightingmacsteem and @minnowminer and receive the sharing of the 33 percent of all SBD author rewards on a daily basis, no questions asked.
The @minnowminer program aims to help in the awareness program of the versatile JOULESTEEM circuit, a non-solar non-wind approach to low-power offgrid energy generation by re-distributing and sharing the daily SBD gains of all posts made by @lightingmacsteem and @minnowminer.
The JOULESTEEM circuit is reaching a very encouraging milestone (@lightingmacsteem post #51) that enables it to harness non-conventional offgrid power sources (air and ground as a huge capacitor) which is in turn made to charge big capacity batteries. This makes it very much ideal for low-power energy generation no matter the location, no matter the weather, no matter what time of the day.
To be able to fast-track its adoption worldwide and to where it may be needed most, the @minnowminer program is introduced to encourage all STEEMIANS to help and be part of the quick transformation of the JOULESTEEM circuit.
This is maybe the only straight-to-the-point no-questions-asked sharing scheme that will enable each one to earn and learn as a STEEMIAN.
Keep on STEEMING guys!!!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
i follow you
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
buen post
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Can i make ur team member i am active person on Steemit ..
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks,,it's really helpful post.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit