How does this look for my first distributed Program.....?

B

blackneos940

Guest
So it's for EVERYBODY, but mainly, I gave it to a friend for his Birthday..... :3 I just want to see if the comments are too hard to understand..... :) I've got to finalize the Comments in the Code, before I actually send it OUT to him..... :D It's going through Email, so.... :)
Code:
# This is a comment of the Program as well. This Program is published under the GNU GPL, or, when you give it to others, any LATER Version of the GPL, such as Version 2 or above. This is a policy that GUARANTEES the users freedom to use this product in any way they wish. Also, though MANY Programs released under the GNU GPL are free as in free beer, the emphasis is placed on free as in FREEDOM, NOT as in free Beer.  :) This means that you can modify the Program, and make copies of it, to sell or to share. The only requirement is that you MUST grant the people you give the Programs released under the GNU GPL the SAME freedom you yourSELF have. The complete GNU GPL licence can be viewed at https://gnu.org/licenses/gpl.html.

# This is really just a simple Text Editor, and these bodies of text after the # symbol do nothing to the Program. They're just for reference.  :) Also, when you run it, do NOT press enter, as that saves ANY text you put into it. Also, when you put this Program onto your Computer, make sure you remember how to search for it, in case you lost it, or placed it in a Folder, and carelessly forgot about it...  :D So, in summary....  ENJOY!


print ("Welcome to the Shopping List generator! When you are prompted to save your Shopping List for later usage, make sure to put '.txt' at the end, so you can open it in all Text Editors.")

Enter = input ("Press Enter to continue.")

print ("Enter items now:\n")

Shopping_List = input()

file_name = input("Name your file now:\n>>>")

with open (file_name, "wt") as output:

  output.write(file_name)
So..... How are the Comments.....? I kind of want it to stay as is, but I'll still make it better, as it generates Shopping Lists..... :) Of course, you can Copy-Paste it, and change it..... :) Also..... He uses Ubuntu!..... :D I literally thought there were like, five people who actually use a Laptop/Desktop Distro of Linux in my town (aside from Android, of course)..... :) We have Bible Studies every Wednesday where I saw my friend, and this older lady wants to run an older .exe Program for looking up Bible Verses, and I told her I could help her with replacing XP with Windows 2000, and---- Nah, I'm just kidding..... XD I'm putting Linux on there for her..... :3 She wants to keep it non-flashy, so no Kubuntu..... Any recommendations for a simple, yet good Distro for beginners.....? Actually, tonight at the Bible Study place, I met TWO people who use Linux, counting my friend, who I just met, really..... With those guys, one of whom is into IT, and this older lady, who wants me to put Linux on her Laptop..... The future of FOSS is looking bright, isn't it.......? :') Oh, them Feels.....
 
Last edited:


Also, it seems to write the File Name TO the File, and overwrites whatever the person put INTO the File, like, Tomatoes, Garlic, Noodles, Multivitamins..... What's up with THAT.....? :( I like that you can name the File, but it deletes everything WITHIN the File, and replaces it with the File Name..... Weird....... :\
 
Congratulations! An excellent first attempt at creating a useful python program.

Here's a constructive code-review for your code, replete with suggestions of some improvements for your consideration. BTW: I know you are only a beginner with python and I don't know how much you do know about the language, so apologies if you don't understand some of the suggestions I make here. Also, I don't want you to think that I am belittling you or anything that you have done. My intention here is merely to educate and not to offend........ With that disclaimer out of the way, let's get down to business!


1. For Unix/Linux scripts, it is traditional to use a shebang #! style comment in the very first line. The 'shebang' line specifies which interpreter should be used to interpret the script when it is executed in a terminal. In this case it is a python3 script, so you should use something like this as the first line of the script:
Code:
#!/usr/bin/python3

With the shebang in place (and assuming that the execution bit has been set in the users permissions for the script) it will be possible to run the script on the command-line by using the line:
Code:
/path/to/script-name.py

Without the shebang, you would have to execute it like this:
Code:
python3 /path/to/script-name.py



2. This line:
Code:
Enter = input ("Press Enter to continue.")
The 'Enter' variable is completely redundant, you are effectively going to be ignoring whatever the user inputs at this point. You don't really care what the user enters. The 'Enter' variable is not used anywhere else in your script, so there is no need for it. So it can simply become this:
Code:
input ("Press Enter to continue.")


3. This one is a bug - When you save your shopping list; rather than writing the content of the shopping list to the file, you appear to be writing the file-name to the file .....
Shouldn't this:
Code:
output.write(file_name)
be this?!:
Code:
output.write(Shopping_List)
Or am I completely losing my marbles? Heh heh XD :)


4. As you have noted in your initial comments, the program only accepts a single line as input for the shopping list. As soon as the user presses enter, they are immediately prompted to enter a file-name for their list.

In order for the user to be able to enter as many lines as they like: you can get input from the user in a loop, looping until the user presses the EOF character (ctrl + d).

Off the top of my head, here's one way of achieving that:
Code:
Shopping_List = []
out = ''
while True:
    try:
        Shopping_List.append(input('>>> ')) # Copying the prompt you used for the file save!
    except EOFError:
        out = '\n'.join(Shopping_List)
        break

In the above code: Shopping_List is declared as a list object instead of a string object - So the shopping list is an actual list! Heh heh! We set up an infinite loop (while True), which will keep prompting the user for input. Each time the user enters a line of text, it is added/appended to the shopping list.

As soon as the user presses the EOF key (ctrl + d); the EOFError exception is thrown, so we use a try-except statement to catch and handle that exception when it occurs.
When the EOFError exception is caught by the program, a newline is appended to the end of the shopping list and we break out of the infinite loop, which will bring us out to the prompt where we are asked for the file-name to save the list as.

Also, don't forget to update your prompts and the comments to tell the user to end their shopping list by using ctrl + d!

With the above changes in place, we would also have to modify the file-save code slightly too. Previously the shopping list object was just a string, so it could be written straight out to the file. But now it is a list of strings, so after prompting the user for the file-name, we need to open the file, iterate through the list and output each string to the file separately.
So after the line where you prompt the user for the file-name, you could do this:
Code:
with open (file_name, "wt") as output:
    for item in Shopping_List:
        output.write(item+'\n');

The above is pretty much identical to your original save code, just an extra line in there, using a for loop to iterate through the list of strings. Also, each time we write out an item from the list, we're appending a newline. So each item (or line of text entered by the user) is separated by a newline. Without the newlines, the entire content of the list would be munged together into a single line in the text file!

I hope you've found this informative and useful!
 
Last edited:
Congratulations! An excellent first attempt at creating a useful python program.

Here's a constructive code-review for your code, replete with suggestions of some improvements for your consideration. BTW: I know you are only a beginner with python and I don't know how much you do know about the language, so apologies if you don't understand some of the suggestions I make here. Also, I don't want you to think that I am belittling you or anything that you have done. My intention here is merely to educate and not to offend........ With that disclaimer out of the way, let's get down to business!


1. For Unix/Linux scripts, it is traditional to use a shebang #! style comment in the very first line. The 'shebang' line specifies which interpreter should be used to interpret the script when it is executed in a terminal. In this case it is a python3 script, so you should use something like this as the first line of the script:
Code:
#!/usr/bin/python3

With the shebang in place (and assuming that the execution bit has been set in the users permissions for the script) it will be possible to run the script on the command-line by using the line:
Code:
/path/to/script-name.py

Without the shebang, you would have to execute it like this:
Code:
python3 /path/to/script-name.py



2. This line:
Code:
Enter = input ("Press Enter to continue.")
The 'Enter' variable is completely redundant, you are effectively going to be ignoring whatever the user inputs at this point. You don't really care what the user enters. The 'Enter' variable is not used anywhere else in your script, so there is no need for it. So it can simply become this:
Code:
input ("Press Enter to continue.")


3. This one is a bug - When you save your shopping list; rather than writing the content of the shopping list to the file, you appear to be writing the file-name to the file .....
Shouldn't this:
Code:
output.write(file_name)
be this?!:
Code:
output.write(Shopping_List)
Or am I completely losing my marbles? Heh heh XD :)


4. As you have noted in your initial comments, the program only accepts a single line as input for the shopping list. As soon as the user presses enter, they are immediately prompted to enter a file-name for their list.

In order for the user to be able to enter as many lines as they like: you can get input from the user in a loop, looping until the user presses the EOF character (ctrl + d).

Off the top of my head, here's one way of achieving that:
Code:
Shopping_List = []
out = ''
while True:
    try:
        Shopping_List.append(input('>>> ')) # Copying the prompt you used for the file save!
    except EOFError:
        out = '\n'.join(Shopping_List)
        break

In the above code: Shopping_List is declared as a list object instead of a string object - So the shopping list is an actual list! Heh heh! We set up an infinite loop (while True), which will keep prompting the user for input. Each time the user enters a line of text, it is added/appended to the shopping list.

As soon as the user presses the EOF key (ctrl + d); the EOFError exception is thrown, so we use a try-except statement to catch and handle that exception when it occurs.
When the EOFError exception is caught by the program, a newline is appended to the end of the shopping list and we break out of the infinite loop, which will bring us out to the prompt where we are asked for the file-name to save the list as.

Also, don't forget to update your prompts and the comments to tell the user to end their shopping list by using ctrl + d!

With the above changes in place, we would also have to modify the file-save code slightly too. Previously the shopping list object was just a string, so it could be written straight out to the file. But now it is a list of strings, so after prompting the user for the file-name, we need to open the file, iterate through the list and output each string to the file separately.
So after the line where you prompt the user for the file-name, you could do this:
Code:
with open (file_name, "wt") as output:
    for item in Shopping_List:
        output.write(item+'\n');

The above is pretty much identical to your original save code, just an extra line in there, using a for loop to iterate through the list of strings. Also, each time we write out an item from the list, we're appending a newline. So each item (or line of text entered by the user) is separated by a newline. Without the newlines, the entire content of the list would be munged together into a single line in the text file!

I hope you've found this informative and useful!

Don't worry, good sir!..... :3 FOSS is all ABOUT Constructive Criticism...... :) How could my Program get any better without input from the community.....? :D Okay, then..... I changed what you suggested..... Also.... Hmm..... You ARE right..... :D "input" in this case WILL suffice..... XD Also, I DID change the .output thingy to what it originally was, which was "output.write(Shopping_List)"..... :3 So you were RIGHT!..... :D Not that I'm surprised, of course..... :3
 
Congratulations! An excellent first attempt at creating a useful python program.

Here's a constructive code-review for your code, replete with suggestions of some improvements for your consideration. BTW: I know you are only a beginner with python and I don't know how much you do know about the language, so apologies if you don't understand some of the suggestions I make here. Also, I don't want you to think that I am belittling you or anything that you have done. My intention here is merely to educate and not to offend........ With that disclaimer out of the way, let's get down to business!


1. For Unix/Linux scripts, it is traditional to use a shebang #! style comment in the very first line. The 'shebang' line specifies which interpreter should be used to interpret the script when it is executed in a terminal. In this case it is a python3 script, so you should use something like this as the first line of the script:
Code:
#!/usr/bin/python3

With the shebang in place (and assuming that the execution bit has been set in the users permissions for the script) it will be possible to run the script on the command-line by using the line:
Code:
/path/to/script-name.py

Without the shebang, you would have to execute it like this:
Code:
python3 /path/to/script-name.py



2. This line:
Code:
Enter = input ("Press Enter to continue.")
The 'Enter' variable is completely redundant, you are effectively going to be ignoring whatever the user inputs at this point. You don't really care what the user enters. The 'Enter' variable is not used anywhere else in your script, so there is no need for it. So it can simply become this:
Code:
input ("Press Enter to continue.")


3. This one is a bug - When you save your shopping list; rather than writing the content of the shopping list to the file, you appear to be writing the file-name to the file .....
Shouldn't this:
Code:
output.write(file_name)
be this?!:
Code:
output.write(Shopping_List)
Or am I completely losing my marbles? Heh heh XD :)


4. As you have noted in your initial comments, the program only accepts a single line as input for the shopping list. As soon as the user presses enter, they are immediately prompted to enter a file-name for their list.

In order for the user to be able to enter as many lines as they like: you can get input from the user in a loop, looping until the user presses the EOF character (ctrl + d).

Off the top of my head, here's one way of achieving that:
Code:
Shopping_List = []
out = ''
while True:
    try:
        Shopping_List.append(input('>>> ')) # Copying the prompt you used for the file save!
    except EOFError:
        out = '\n'.join(Shopping_List)
        break

In the above code: Shopping_List is declared as a list object instead of a string object - So the shopping list is an actual list! Heh heh! We set up an infinite loop (while True), which will keep prompting the user for input. Each time the user enters a line of text, it is added/appended to the shopping list.

As soon as the user presses the EOF key (ctrl + d); the EOFError exception is thrown, so we use a try-except statement to catch and handle that exception when it occurs.
When the EOFError exception is caught by the program, a newline is appended to the end of the shopping list and we break out of the infinite loop, which will bring us out to the prompt where we are asked for the file-name to save the list as.

Also, don't forget to update your prompts and the comments to tell the user to end their shopping list by using ctrl + d!

With the above changes in place, we would also have to modify the file-save code slightly too. Previously the shopping list object was just a string, so it could be written straight out to the file. But now it is a list of strings, so after prompting the user for the file-name, we need to open the file, iterate through the list and output each string to the file separately.
So after the line where you prompt the user for the file-name, you could do this:
Code:
with open (file_name, "wt") as output:
    for item in Shopping_List:
        output.write(item+'\n');

The above is pretty much identical to your original save code, just an extra line in there, using a for loop to iterate through the list of strings. Also, each time we write out an item from the list, we're appending a newline. So each item (or line of text entered by the user) is separated by a newline. Without the newlines, the entire content of the list would be munged together into a single line in the text file!

I hope you've found this informative and useful!

Well, I followed everything you said, and..... HOT DIGGETY DOG, it WORKED!!..... :D THANKYOUTHANKYOUTHANKYOUTHANKYOU!!!!..... ^^ So then, here's the Code I have now!..... :3

Code:
# This is a comment, so you can read about the program. This Program is published under the GNU GPL Version 1, or at your option, any LATER Version of the GPL, such as Version 2 or above. This is a policy that GUARANTEES the users freedom to use this product in any way they wish. Also, though MANY Programs released under the GNU GPL are free as in free beer, the emphasis is placed on free as in FREEDOM, NOT as in free Beer.  :) This means that you can modify the Program, and make copies of it, to sell or to share. The only requirement is that you MUST grant the people you give the Programs released under the GNU GPL the SAME freedom you yourSELF have. The complete GNU GPL licence can be viewed at https://gnu.org/licenses/gpl.html.

# This is a comment as well. :)  This is really just a simple Text Editor, and these bodies of text after the # symbol do nothing to the Program. They're just for reference.  :) Also, when you put this Program onto your Computer, make sure you remember how to search for it, in case you lost it, or placed it in a Folder, and carelessly forgot about it... Also, for reasons I'm not sure of yet, when you go back a letter or more, and type, whatever you put IN the Document seems to type OVER the words ahead of your cursor... If you figure out why this is, and change it please let me know at [email protected], so I can put those changes in MY copy of the Program as well. Thanks!...  ^^  :D So, in summary....  ENJOY!  :)

# Oh yes. Remember to end the Program when finished, by pressing CTRL+D!  :)

#!/usr/bin/python3

print ("Welcome to the Shopping List generator! When you are prompted to save your Shopping List for later usage, make sure to put '.txt' at the end, so you can open it in all Text Editors.")

input ("Press Enter to continue.")

print ("Enter items now:\n")

Shopping_List = []

out = ""

print ("When you're finished, be sure to press CTRL+D to exit, so you can name the Shopping List!")

while True:

    try:
  
        Shopping_List.append(input(">>> ")) # Copying the prompt I used for the File save!
    
    except EOFError:
  
        out = "\n".join(Shopping_List)
    
        break

with open ("Shopping_List.txt", "wt") as output:

    for item in Shopping_List:

        output.write(item+"\n")

Well, what d'you think.....? Also, this is what I put into the Shopping List..... :3

Oranges, Grapes, Clementines, Fish, Seafood Snackers (or the equivalent), Hamburger Buns,

Strawberries, Heavy Cream, Taco Shells, Soft and Hard,

Bacon Bits, Tuna Fish, Whole Tuna, Cale, Grass Seeds, Doritos, Pop, American Clear, USB 16GB

Lard, Shrimp, Chicken Wings, Broccoli, Multivitamins, Aspirin, Bottled Water, Milk, Cereal,

Bread, Morningstar Hamburgers, Raw Beef, Eggs, Flour, Sugar, Donuts, GTA V

I like Seafood Snackers, which are Imitation Crab Meat, and the Cale and Grass Seeds and the Seafood in general are for a certain Penguin and a Gnu..... :3
 
Last edited:
Put the ' #!/usr/bin/python3' to the VERY first line of your code. Otherwise, great job!
 
Put the ' #!/usr/bin/python3' to the VERY first line of your code. Otherwise, great job!

Thank you..... :3 But, I DID update it actually, though I just never posted it here..... :D Here's the UPDATED version!..... :D
Code:
# This is a comment, so you can read about the program. This Program is published under the GNU GPL Version 1, or at your option, any LATER Version of the GPL, such as Version 2 or above. This is a policy that GUARANTEES the users freedom to use this product in any way they wish. Also, though MANY Programs released under the GNU GPL are free as in free beer, the emphasis is placed on free as in FREEDOM, NOT as in free Beer.  :) This means that you can modify the Program, and make copies of it, to sell or to share. The only requirement is that you MUST grant the people you give the Programs released under the GNU GPL the SAME freedom you yourSELF have. The complete GNU GPL licence can be viewed at https://gnu.org/licenses/gpl.html.

# This is a comment as well. :)  This is really just a simple Text Editor, and these bodies of text after the # symbol do nothing to the Program. They're just for reference.  :) Also, when you put this Program onto your Computer, make sure you remember how to search for it, in case you lost it, or placed it in a Folder, and carelessly forgot about it... Also, for reasons I'm not sure of yet, when you go back a letter or more, and type, whatever you put IN the Document seems to type OVER the words ahead of your cursor... If you figure out why this is, and change it please let me know at [email protected], so I can put those changes in MY copy of the Program as well. Thanks!...  ^^  :D So, in summary....  ENJOY!  :)

# Oh yes. Remember to end the Program when finished, by pressing CTRL+D!  :)

#!/usr/bin/python3

print ("Welcome to the Shopping List generator! When you are prompted to save your Shopping List for later usage, make sure to put '.txt' at the end, so you can open it in all Text Editors.")

input ("Press Enter to continue.")

print ("Enter items now:\n")

Shopping_List = []

out = ""

print ("When you're finished, be sure to press CTRL+D to exit, so you can name the Shopping List!")

while True:

    try:
    
        Shopping_List.append(input(">>> ")) # Copying the prompt I used for the File save!
      
    except EOFError:
    
        out = "\n".join(Shopping_List)
      
        break

with open ("Shopping_List.txt", "wt") as output:

    for item in Shopping_List:

        output.write(item+"\n")

Well, how does it look.....? :D I had help here, of course..... ;) Also, I uploaded the File, if you want to keep it and share it/improve upon it....... :3

~NAMASTE!..... <3
 

Attachments

  • Shopping_List.py.zip
    1.3 KB · Views: 525
the shebang needs to be before comments, while it would run, good programming practice is to put it on the very first line (before comments, on line 1) . ;)

1. #!/usr/bin/<interpreter>
2. #comments ..etc
 
the shebang needs to be before comments, while it would run, good programming practice is to put it on the very first line (before comments, on line 1) . ;)

1. #!/usr/bin/<interpreter>
2. #comments ..etc
Whoops..... D: I thought I already put it IN there..... :( Thanks!..... :D
 
the shebang needs to be before comments, while it would run, good programming practice is to put it on the very first line (before comments, on line 1) . ;)

1. #!/usr/bin/<interpreter>
2. #comments ..etc

Ah, I see..... :3 Thanks!!..... ^^
 

Members online


Latest posts

Top