Woo, I'm On Fire1!..... :3

B

blackneos940

Guest
Hey, does anyone here play Sonic Adventure 2: Battle, or any of it's OTHER versions.....? :) Do you like Chao at all.....?? :) Then THIS Program is for YOU!!..... :D Well, not quite yet, actually..... :( It's still in Beta, and I have some issues..... :( Namely, how do I get input with "x = input()", and write that to a file.....? :( I'll post the WHOLE file as an Attachment, but here is what I'm really having trouble with..... :) (Note: I've added some Comments about the issues, which aren't actually in the Code itself..... :))

Code:
file_name = input("Enter the File Name now:\n>>> ")

print ("Alright then! As you give each Animal to your Chao, type it's name in the next Prompt! The name isn't case-sensitive, but you DO need to spell it rig
ht!\n")

t.sleep(7)

animal_name = input("Type the Animal's name now:\n>>> ").capitalize #Basically, I want to write the Animal Name to a Text File... :)

with open(file_name + ".txt", "wb") as le_output:

  le_output.write(bytes(animal_name, 'UTF-8')) #It gives me an Error! What's up with that??   >:(

  le_output.close()

animal_name_2 = input("Got any more Animals to keep track of?\nIf so, write them now! Don\'t worry, I\'ll just add the Animal Name you typed in to the File!\
n>>> ")

So, what do you think.....? :) I'm SO excited..... :D Thank you for any help, guys..... :3
 
Last edited:


The only obvious error I can spot is this line:
Code:
animal_name = input("Type the Animal's name now:\n>>> ").capitalize

Capitalize is a function call, so you need to add () to the end. e.g.
Code:
animal_name = input("Type the Animal's name now:\n>>> ").capitalize()

Without the '()' at the end, animal_name doesn't get assigned a string value. Basically it will end up holding the address of the capitalize function for the string entered by the user. So in your call to le_output.write a couple of lines later, you are attempting to convert something that is not a string to utf-8. And that is why you are getting the error there and not where you are missing the ()'s.

If you were to put a print statement immediately after the line with the call to capitalize (without the brackets)
e.g.
Code:
animal_name = input("Type the Animal's name now:\n>>> ").capitalize
print(animal_name)

The output from the print statement would yield something like:
Code:
<built in method capitalize of str object at 0xdeadbeef>
Where 0xdeadbeef is the hexadecimal address of the string object that was returned by the call to input. NOTE: Your variable probably won't be at 0xdeadbeef - that was just an example! :)

Anyway, put the brackets () at the end of the call to capitalize() and your code should be good to go!
 
The only obvious error I can spot is this line:
Code:
animal_name = input("Type the Animal's name now:\n>>> ").capitalize

Capitalize is a function call, so you need to add () to the end. e.g.
Code:
animal_name = input("Type the Animal's name now:\n>>> ").capitalize()

Without the '()' at the end, animal_name doesn't get assigned a string value. Basically it will end up holding the address of the capitalize function for the string entered by the user. So in your call to le_output.write a couple of lines later, you are attempting to convert something that is not a string to utf-8. And that is why you are getting the error there and not where you are missing the ()'s.

If you were to put a print statement immediately after the line with the call to capitalize (without the brackets)
e.g.
Code:
animal_name = input("Type the Animal's name now:\n>>> ").capitalize
print(animal_name)

The output from the print statement would yield something like:
Code:
<built in method capitalize of str object at 0xdeadbeef>
Where 0xdeadbeef is the hexadecimal address of the string object that was returned by the call to input. NOTE: Your variable probably won't be at 0xdeadbeef - that was just an example! :)

Anyway, put the brackets () at the end of the call to capitalize() and your code should be good to go!
Ah hah!..... :D I forgot about that..... Silly me..... :D I'll append that to the Python Script right away!!..... ^^ I'll also upload the Program, as I forgot to do so..... :) Silly me..... :p Also, how was your guys' Thanksgiving.....? Or, if you live in Canada, how was it in October.....? :) I had fun, and ate a LOT of food....... :D ..... And, judging by Tux on the upper-right portion of my Firefox window, HE had a good Thanksgiving, too!..... ^^ Maybe I'll end the day by feasting on some Distros....... :3
 
The only obvious error I can spot is this line:
Code:
animal_name = input("Type the Animal's name now:\n>>> ").capitalize

Capitalize is a function call, so you need to add () to the end. e.g.
Code:
animal_name = input("Type the Animal's name now:\n>>> ").capitalize()

Without the '()' at the end, animal_name doesn't get assigned a string value. Basically it will end up holding the address of the capitalize function for the string entered by the user. So in your call to le_output.write a couple of lines later, you are attempting to convert something that is not a string to utf-8. And that is why you are getting the error there and not where you are missing the ()'s.

If you were to put a print statement immediately after the line with the call to capitalize (without the brackets)
e.g.
Code:
animal_name = input("Type the Animal's name now:\n>>> ").capitalize
print(animal_name)

The output from the print statement would yield something like:
Code:
<built in method capitalize of str object at 0xdeadbeef>
Where 0xdeadbeef is the hexadecimal address of the string object that was returned by the call to input. NOTE: Your variable probably won't be at 0xdeadbeef - that was just an example! :)

Anyway, put the brackets () at the end of the call to capitalize() and your code should be good to go!
Here ya go!..... ^^ Share it with everyone you know.....! :D It's FOSS!!..... ^^ (Note, it's still in Beta yet.... :) I'm also looking for a way to make my Programs, such as this one, all the more Colorful!..... :D)
 

Attachments

  • SA2B_Animal_Checklist.py.zip
    1.1 KB · Views: 574

Staff online

Members online


Latest posts

Top