Database Creation and Reading - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Database Creation and Reading (/thread-15342.html) |
Database Creation and Reading - Tussocky_Coder - Jan-13-2019 Hi, so I don't know if this is a stupid question or an impossible question but I'd just like to know if you guys can help me. I've decided to start developing a read/write program that stores user info. I was wondering if you knew how to make a script that will ask for someone's name and then create a file with the same name as them? And yes there will be further questions on this subject so all information would be really helpful, thanks! (Oh, and I'm sorry if I posted this in the wrong category, I wasn't really sure) RE: Database Creation and Reading - Larz60+ - Jan-13-2019 Quote: I was wondering if you knew how to make a script that will ask for someone's name and then create a file with the same name as them?Answer is yes RE: Database Creation and Reading - Tussocky_Coder - Jan-14-2019 Could you tell me how to do that plz? RE: Database Creation and Reading - Larz60+ - Jan-15-2019 This is basic python, any tutorial will have you there probably within the first hour. see: http://interactivepython.org/courselib/static/thinkcspy/index.html and: http://www.greenteapress.com/thinkpython/thinkpython.html Here's a simple example (untested) save as write_something.py: def write_some_text(sometext, filename): with open(filename, 'w') as fp: fp.write(sometext) write_some_text('Hey, what do you think about that', 'MyTextFile.txt')you can run from command line with: python write_something.pyTo read back and print: read_me.py: def read_me(filename): with open(filename) as fp: read_text = fp.read() print(read_me('MyTextFile.txt')) |