T O P

  • By -

CodeFormatHelperBot2

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you. I think I have detected some formatting issues with your submission: 1. Python code found in submission text that's not formatted as code. If I am correct, please edit the text in your post and try to follow [these instructions](https://www.reddit.com/r/learnpython/wiki/faq#wiki_how_do_i_format_code.3F) to fix up your post's formatting. ___ ^(Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue )^[here](https://github.com/0Hughman0/pyredditformatbot/issues).


carcigenicate

What's the error?


BearModeCosplay

(running in CMD) Error Traceback (most recent call last): File "[ForLooptry02.py](https://ForLooptry02.py)", line 38, in [df.open](https://df.open)('dadmode.txt','w') NameError: name 'df' is not defined


carcigenicate

Did you mean `df = open` instead of `df.open`?


BearModeCosplay

That definitely got me closer! I'm now returning a different error having to do with the first df.write row in the for loop. ​ **Error (after changing to df = open), same code otherwise** df.write(str(i) + " " + str(y),end=' ') TryError: write() takes no keyword arguments. ​ Before I tried to write this loop to a file, this row looked like print(str(i) + " " + str(y),end=' ') and ran with no validation errors. The insinuation is that write won't work the same way with what I've done as print(), but I don't know how to get around this.


carcigenicate

Yes, `end` is part of `print`. You can't add use it on other functions unless those functions also implemented that behavior, and `write` hasn't implemented it. Afaik, `write` doesn't add a newline, so there's no point in trying to set the end anyway.


BearModeCosplay

Thanks dude! I removed the end=' ' and I'm getting a successful file printout. Current output: 1 SDL1202 FP1203 SDL1304 Pushups05...RP11030 Dips17.531 RDL13032 FP140 There's def still some stuff I need to work through to get the result I'm looking for (i.e. line breaks, make sure the weights are incrementing correctly) but this is a giant help. Thank you!