Skip to content

I made a new program using your tutorial and it doesnt seem to work! #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
neutralboy opened this issue May 26, 2017 · 5 comments
Closed

Comments

@neutralboy
Copy link

The program is meant to function as a diary:
The file usr.txt has line 3 as "defusr" and line 4 as "123"
The code is located on http://dpaste.com/1Q0BQGC.txt as GitHub does not seem to recognize proper indentation.

@Akuli
Copy link
Owner

Akuli commented May 26, 2017

Yeah, you need to add 4 spaces before each line if you paste code in GitHub.

Your code is pretty hard to read right now. See Good and bad variable names (it also applies to functions, so create_new_user would be good). The worst problem is that right now I have no idea what f01, x01 and other variables do. So fix the variable names and make a new paste, I'll try to help you then :)

@Akuli
Copy link
Owner

Akuli commented May 26, 2017

Looking at your code a bit more the file stuff has things like read(1) and writelines(...) and close() that I don't use anywhere in the tutorial. The tutorial also has a chapter about files with easier ways to use files, so you may want to use that instead.

Another problem is that you're comparing strings with numbers. See the last example here.

By the way, it's normal to have problems with your code :) Most of the programs I write don't work on the first try either, and that's what the error messages are for.

@neutralboy
Copy link
Author

Thank you very much @Akuli for your useful insight I have made all the changes required and also realized that many lines of code were useless.... here's an edited version
Here's the code!

@Akuli
Copy link
Owner

Akuli commented Jun 2, 2017

Great :) Now it's easier to find problems:

if usrname == usr_file.read(3):

file.read(3) doesn't read the third line from the file. It means "read next 3 characters from the file". Usually it's best to use methods like readline() or just for loop over the file. See my file chapter.

usr_file = open("usrdiary.txt", "w")
print("Your diary has the following content: \n",usr_file)

Here you're confusing the file object from open() with its content. If you want to print the whole content of a file, do something like print(file.read()). You also need "r" instead of "w".

I recommend coming to this free help chat. You don't need to register or anything, just click the link, choose a name and you're ready to go. I'm Akuli there too, so hopefully we can talk there and get things to work :) There are also many other skilled people ready to help you if I'm not there.

@Akuli
Copy link
Owner

Akuli commented Sep 15, 2018

You haven't said anything to me in over a year, so I guess you are not working on this program anymore.

@Akuli Akuli closed this as completed Sep 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants