![]() |
| ||
| Need help with a simple python program I'm completely new to python and really need help with this. I have written this basic cash fund program that allows a person to withdraw, deposit, and receive a balance from it. But now I need to now add email capabilities, by setting up a database (or list) of account holders' information such as email and other information. When a query is made by a user, they should enter a username or some other means of identification. When the query is accomplished, an email verification of the details should also be sent to the user. Please help! Here is my code so far: from normalDate import ND |
| ||
| Re: Need help with a simple python program A very interesting problem! Just out of curiosity, where is the module normalDate from? |
| ||
| Re: Need help with a simple python program Not sure, I found it on the web but can't remember where. |
| ||
| Re: Need help with a simple python program Hi cleblanc, I need more information about how this program will be used if I am to provide useful information myself. First off, is this program going to be used by people, or is it a mock-up/homework assignment? If it's going to be used by people, it's not necessarily a "basic" program. How are the users going to access it? Is it going to be a webapp? Is it going to be a client-server program? If so, will the client have a GUI or a command-line interface? How will you keep me from logging in as someone else and stealing from them? If you use passwords, how will you secure them? Do you intend to let people have jointly-held accounts? If so, you need to worry about synchronization issues. Have you created a MySQL database to house account information? An SMTP server to send email from? Will you prevent people from overdrawing on their accounts? Are there two kinds of users (customers and administrators)? If so, your program needs to incorporate a way to distinguish between them. What OS are you using? What other platform information can you supply? And on and on. If this is just a mock-up, things get a lot simpler. To store account information, I would just use an insecure text file with information "pickled" into it. Instructions on how to use pickle are included in vegaseat's "Starting Python" sticky thread. Here's what to do: add two more fields (username and email) to your Account class. In the Python shell, import your Account class and create several Account objects, then pickle.dump() them to a text file. Now that the foundation has been laid, the first thing your program should do is load all the Account objects from the text file via pickle.load(), then ask the user for a username. If it can't find the username in the loaded Account objects, it should terminate with an error message. Otherwise, it should proceed to the rest of the program. Every time you make a change to the balance, you should re-pickle the information. If you want to send a record of the session by email, you'll need to create some kind of "history" list, such that every time a transaction is made, the history list gets appended to with a text description of what happened. Then, when the user logs out, send the email with the history list in the message. To send emails, you're likely going to need to use the smtplib and email packages, which means you'll need to set up an SMTP server (or get access to an email account that allows automatic relaying). See here for details on how to use Python to send email; how to set up an SMTP server depends on which OS you're using. |
| ||
| Re: Need help with a simple python program It is a homework assignment. |
| ||
| Re: Need help with a simple python program I tried adding the cPickle module to the code but can't seem to get it to work. I keep getting the following error: Traceback (most recent call last): File "C:\eclipse\workspace\External Files\Module 3\CSC113 Module3 SLP\firm's petty cash fund.py", line 20, in ? load = p.load(f) IOError: (0, 'Error') Any help would be appreciated. Here is the code I have so far: import cPickle as p |
| ||
| Re: Need help with a simple python program Hi cleblanc, It looks like you're trying to load from a file object that is opened for write-access. This is the code I'm talking about: balanceFile = 'accountBalance.data'I don't know how cPickle works, because I've only ever used pickle, but with pickle.load() you need to specify a file object that has been opened with read-access, like so: balanceFile = 'accountBalance.data'But beware! If the file is opened for read-access, you can't write to it without closing it first, and vice versa. To close a file object, you need to say: f.close()Then re-open it with the type of access you need. |
| ||
| Re: Need help with a simple python program Got it thanks! |
| All times are GMT -4. The time now is 5:40 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC