Html_Helptool.py

Is there any simple way to improve this revamped code from an earlier version? I am looking for improvements that are SIMPLE, not more that post-advanced please.

import time
import os, signal

A = '''

<!DOCTYPE html> is the declaration tag for a standard HTML
document. This is used to tell the browser what kind of HTML document
it is.

'''
a = '''

<p> This tag defines a PARAGRAPH. These are highly customisable
in CSS, and can be used in any HTML version. There are variations
of this tag, such as:

<p1>
<p2>
<p3>
<p4>
<p5>
<p6>

and so on..

'''
B = '''

<h> This tag defines a HEADER. These, like PARAGRAPHS (see <p>),
are highly custonizable in CSS, and, like PARAGRAPHS, can be used
in any HTML version. There are variations of this tag, such as:

<h1>
<h2>
<h3>
<h4>
<h5>
<h6>

and so on..

'''
b = '''

<a> This tag defines a HYPERLINK. This can be used to turn ANY block
or peice of text into a clickable link. This has a variety of uses, such as:

Redirection
Buttons

and many more.

A hyperlink's syntax is as shows:

<a href = "www.LINK.com"  target = "(_blank, _parent, _self, and _top are

The closing tag is nessesary for this to work with your given parameters.

'''
C = '''

<div> This tag defines a DIVIDED BLOCK where you can store content,
such as pictures, videos, buttons, text, and just about anything you can
think of. This is mainly used for containing things such as:

Buttons
The entire page (Formally known as "Wrapper")
ETC.

This DIV's syntax is as shows:

<div class = "(calls a certain CSS class)"></div>

The closing tag is nessesary for this to work with your given parameters.

'''
c = '''

LINK multiple CSS files to a single HTML document. You can LINK files

The LINK's syntax is as shows:

"text/css">

'''

print("This tool was made to help programmers, like myself,")
print("with HTML tags. It takes your input, say you typed")
print("<div>, it would give you an accurate description of")
print("that tag and a list of its uses.")
print("")
print("")
print("This tool was made by Chase Barnes")
print("")
print("(Remember, type BASE tags -<p>- ONLY)")
print("")

while True:
break
if Pass == 'Slenderman123':
break
else:
print("")
print("The Input is Incorrect")
print("")
else:
print("")
print("")
continue

print("")
print("Welcome, " + Username + "!")
print("")

def main():
Input = input("TAG: ")
if Input == '/exit':
answerexit = input("Are you sure? ")
print("")
print("SHUTTING DOWN..")
print("")
time.sleep(2)
os.kill(os.getpid(), signal.SIGTERM)
print("")
print("SHUTDOWN ABORTED..")
print("")
main()
elif Input == '':
print("")
print("Please enter a tag or command.")
print("")
main()
elif Input == '<!DOCTYPE html>':
print(A)
time.sleep(1)
main()
elif Input == '<p>':
print(a)
time.sleep(1)
main()
elif Input == '<h>':
print(B)
time.sleep(1)
main()
elif Input == '<a>':
print(b)
time.sleep(1)
main()
elif Input == '<div>':
print(C)
time.sleep(1)
main()
else:
print("")
print('''The tag or command you entered is Not Recognized of is not yet
supported by this tool.''')
print("")
main()

main()


Hey, You! Hello there! This programs function is to give information about HTML tags and their uss/functions.

CHANGELOG:

Version_1 (9/15/2017):

  Login Feature added         Six tags are added:             <!DOCTYPE html>             <p>


Users:

  Username: Guest         Password:

How To Use:


DO NOT open in pythons command prompt, open through IDLE or Python shell (IDLE)

After you are logged in, Enter a tag or command!

List of all keywords:

<!DOCTYPE html>
<p>
<h>   <a>     <div>   <link>  /exit       yes         no

• What indentation? Sep 15 '17 at 15:35
• And, also, I have a README.txt file inside the folder of this py file. Sep 15 '17 at 15:36
• I put the contents of the readme inside of the question Sep 15 '17 at 15:38
• Why does every line start with four spaces? Sep 15 '17 at 15:44
• because before I posted the question, I had to indent it that much for it to register as code. That's what it said to do. Sep 15 '17 at 15:45

Variable naming

The names of the variables defined at the top of your script are meaningless and do not convey their purpose.

Check for __main__

Enclose script code to be run within an

if __name__ == '__main__':
<code_here>


block, so that it does not run if the module is solely imported.

Text files

You should consider putting the running "help" text into files (plain text, INI, JSON etc.) and reading them within your source code.

Termination

Terminating the program by

os.kill(os.getpid(), signal.SIGTERM)


seems cumbersome. Use exit or sys.exit instead.

• I tried using sys.exit() and exit(), but It kept saying ("The program is still running, do you want to kill it?" and I want it to 'shutdown' like a computer does, without having to mess with that silly dialogue box, so that is why I used os.kill(os.getpid(), signal.SIGTERM) Sep 16 '17 at 17:28
• @ChaseBarnes This seems like a separate issue you may consider discussing on stackoverflow. stackoverflow.com/questions/38028151/… Sep 18 '17 at 10:52

Recursive calls to loop over the same code again and again are an anti-pattern. If you let the program open for too long, it will die off eventually with a recursion error. Instead, use a while loop:

def main():
while True:
tag = input("TAG: ")
if tag == '/exit':
answerexit = input("Are you sure? ")
print("")
print("SHUTTING DOWN..")
print("")
time.sleep(2)
break
print("")
print("SHUTDOWN ABORTED..")
print("")
else:
handle_tag(tag)
time.sleep(1)

def handle_tag(tag):
# put all your ifs in there


A second thing that I don't get is the whole username/password thing. It's not used anywhere... Ho, yes, you greet the user, I see little too no point with that.

Third, the "manual" part, that is printed upfront would be better as a module docstring. Then you could just:

print(__doc__)


Lastly, I would put the tags description into a dictionary, it will let you add stuff painlessly as you wouldn't have to add a new if each time.

TAGS = {
'<p>': '''
...''',
'<h>': '''
....''',
...
}

def handle_tag(tag):
try:
print(TAGS[tag])
except KeyError:
print('unknown tag', tag)

• could you edit the entire code to show what you mean? I am lost. Sep 16 '17 at 17:24
• @ChaseBarnes what part don't you get exactly? 1) remove username/passwords 2) use a dictionary 3) use a while loop (which I provided the code for)? Sep 16 '17 at 20:39
• I don't get the dictionary. I am not going to remove the Username/Password function because I plan to have a good purpose for that. It's just not finished yet. And I implemented your while True loop! It works like a charm! Sep 18 '17 at 14:05