[Tutor] i need help with a code

2010-05-24 Thread patricia welch
here is what I need and I am completely stumped on what to do. I ususally do 
not have a problem doing this. but this one is just killing me.

Programming a Personal Budget Program Write a program for a personal budget

that satisfies these conditions:

. The program should have the following command menu selections: Add New

Expense, Remove Expense, Add New Income, Remove Income, Exit

e The Add New Expense command will prompt the user for the amount of the

expense and the frequency of the expense per month. The total monthly

expense of an item is its expense multiplied by its monthly frequency. The total

initia! budget for monthly expenses is $4,000. If the new expense exceeds what

is left for monthly expenses, the program should display a message that the

expense was rejected because the budget was exceeded. If the expense can be

covered by the monthly budget, the program should display a message that the

expense was accepted and state the budget left after the expense.

. The Remove Expense should prompt the user for the expense amount and its

monthly frequency. tf the expense amount to be removed exceeds whatever

has been used of the current budget, then a message should be displayed to

recheck the expense amounts. Otherwise the remaining budget will be

increased by the amount of the expense reduction and a message displayed

stating the amount of the currently available budget funds.

~

. The Add New Income option will prompt the user for the amount of the

increase in monthly income and increase the monthly budget by that amount. A

message will be displayed indicating the amount of the new available funds.

. The Remove Income option will prompt the user for the amount of reduction in

monthly income. If the reduction exceeds the available funds, then print a

message indicating the amount owing. Otherwise, set the budget to the

difference and print the amount of funds available.

"

c) Programming a Personal Budget Program

addExpense( )

removeExpense( )

addRevenue( )

removeRevenue( )

3. All projects should implement a While loop in their code to display the 
command selection

menu. The While loop should use== a variable* called choice to capture the 
user's menu selection.

The While loop should test to see what value the variable choice has to 
determine which menu

 

Programming a Personal Budget Progra'm

/ /variable declarations:

Declare Integer choice = 0

Declare Real total Budget = 4000

 

/ /main selection menu

While choice != 5

/ /display menu

Display "Menu Selections:"

Display "1_ Add an Expense"

Display "2 - Remove an Expense"

Display "3 - Add Revenue"

Display "4 - Remove Revenue"

Display "5 - Exit"

Display "Enter your selection:"

Input choice

!/check menu selection

If choice == 1 Then "---./

addExpense( )

Else If choice == 2 Then

removeExpense( )

Else If choice == 3 Then

addRevenue( )

Else If choice == 4 Then

removeRevenue( )

Else If choice == 5 Then

Display "Goodbye!"

Else

Display "Invalid input - please try again."

End If

End While
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib

2006-09-17 Thread Patricia
Hi again,

I was able to use urllib2_file, which is a wrapper to urllib2.urlopen(). It
seems to work fine, and I'm able to retrieve the contents of the file using:
 
afile = req.form.list[1].file.read()

Now I have to store this text file (which is about 500k) and an id number into a
mysql database in a web server. I have a table that has two columns user id
(int) and mediumblob. The problem I have now is I don't know how to store them
into the database. I've been looking for examples without any luck. I tried
using load data infile, but it seems that I would need to have this client_side
file stored in the server. I  used load data local infile, and got some errors.
I also thought about storing them like this:

afile = req.form.list[1].file.read()
cursor.execute("""insert into p_report (sales_order, file_cont )
values (%s, %s)""", (1, afile))

I really don't know which is the best way to do it. Which is the right approach?
I'm really hoping someone can give me an idea how to do it because I'm finding
this a frustrating.

Thanks,
Patricia




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] urllib

2006-09-11 Thread Patricia
Hi,

I have used urllib and urllib2 to post data like the following:

dict = {}
dict['data'] = info
dict['system'] = aname

data = urllib.urlencode(dict)
req = urllib2.Request(url)

And to get the data, I emulated a web page with a submit button:   
s = ""
s += ""
s += ""
s += ""
s += ""
s += ""


I would like to know how to send a file. It's a text file that will be 
gzipped before being posted. I'm using python version 2.2.3.


Thanks,
Patricia


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python & mysql question

2006-09-06 Thread Patricia
Hi,

I have to store and retrieve text files from a database table and 
the size of each file is about 500k. Can someone give me an idea 
on how to do this? 

Thanks,
Patricia





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Mod-python

2006-06-12 Thread Patricia G.
Hi, 
When you say you that you want to send this data via Apache do youmean that the web server you are sending to is running Apache 

Yes. If you simply want to emulate a a web page with a submit button thatsends a Post you do it with code a bit like the following
import urllib, urllib2url = "" href="http://www.somesite.com/somefolder/exampl1.cgi">http://www.somesite.com/somefolder/exampl1.cgi"dict = {}dict["field1"] = "value1"
dict["field2"] = "value2"...dict["fieldn"] = "valuen"urldata = urllib.urlencode(dict)req = urllib2.Request(url)req.add_header('User-agent','Mozilla/4.0 (compatible; MSIE 
5.5; Windows NT 5.0')fd = urllib2.urlopen(req,urldata)RegardsPeter Jessop

I'll try this out. Thank you!
Patricia 
>> Hope anyone can point me to the right direction..> Thanks,
> Patricia>> ___> Tutor maillist  -  Tutor@python.org> 
http://mail.python.org/mailman/listinfo/tutor>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Mod-python

2006-06-12 Thread patricia
Hi!

I have about 17 lines of text (about system information) that I need to pass to
a remote web server AND I've been asked to send this data via Apache. I have to
write a python script that will fetch a URL to pass this text. I understand that
if I want to use the POST method, I would need to have a page with a submit
button, and this is not the case. I also know that with GET, the length of the
url is limited. What is the best way to send a long string?

Hope anyone can point me to the right direction..
Thanks,
Patricia

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] connect to a remote machine - Linux

2006-06-12 Thread Patricia G.
Thank you for the great explanation, Danny.. I was confused...
Thank you all for your help!

PatriciaOn 6/11/06, Danny Yoo <[EMAIL PROTECTED]> wrote:
> I'm sorry. I think I didn't explain myself well. My problem is not with> the database.. The part I'm not sure how to do is connect to the remote> computer..Hi Patricia,There's some confusion here.  Let's get that out in the open.
It sounds like you have a remote server.  That server provides login shellservice through ssh, and this login shell service runs on port 22, Ithink.  But if your server is running MySQL, it is very likely that it
provides network access to that MySQL database through port 3306.I think you believe that ssh login access is required to access MySQL onyour remote network server.  But this is not necessarily true: one can
access MySQL remotely without having a login shell account into themachine.  That is, rather than: Client > Login through SSH > Execute mysql clientwhich is three steps, the conventional route here is:
 Client > Connect to networked MySQL using a database driver  (MySQLdb)which is more direct.See: MySQLdb: 
http://sourceforge.net/projects/mysql-pythonas well as: http://www.devshed.com/c/a/Python/MySQL-Connectivity-With-Python/
However, this does mean that the remote MySQL server has to be set up witha separate MySQL username/password account.  That is, MySQL keeps its ownset of usernames and passwords that can be separate from the shell
logins.Also, mysqld --- the software that drives the MySQL server --- has to beenabled to work across tcp.  That requirement sounds obvious enough, butit is not the default in the MySQL server installs I've seen lately, so
double check this with your database system administrator.  In short: youcan not automatically assume that having login access to the machine willgive you MySQL database access, and visa-versa.Does this make sense so far?
> I read somewhere that os.popen would work, but I'm not sure if that will> do for meAlmost certainly no.popen is not for external database access.  People have written databasedrivers to solve this problem for you already.  It is perhaps possible to
bend popen() in such a way to access MySQL, but this will involve anamount of work to get right, and there will be a lot of ways of getting itwrong.  *grin*So I'd recommend changing this question from: "How do I get popen() to
access MySQL across a remote interface?" to a more general: "How do Iconnect to MySQL from Python?"  The link above to MySQLdb will give youthe software necessary to connect your client to a MySQL server, and the
link to the Devshed article is a tutorial on how to use it effectively.Good luck!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] connect to a remote machine - Linux

2006-06-11 Thread Patricia G.

I'm sorry. I think I didn't explain myself well. My problem is not with the database.. The part I'm not sure how to do is connect to the remote computer.. I read somewhere that os.popen would work, but I'm not sure if that will do for me because I have to enter a passphrase and password to connect to the remote machine. 

Any ideas??
 
Thanks,

Patricia   
On 6/11/06, Roy Mac <[EMAIL PROTECTED]> wrote:
Try looking at PyDO - This provides an interface between Python and yourdatabase.  This allows you to change your database at a later time and not
have to change any Python.The excerpt below is from:http://skunkweb.sourceforge.net/PyDO2/api/html/public/pydo-module.html
PyDO (Python Data Objects) is an object-relational wrapper forrelational databases.  It provides a convenient API for retrieving andmanipulating data without constraining in any way how the data ispersisted at the RDBMS level.  Supported databases are:
  * postgresql  * mysql  * sqlite  * mssql  * oracle-Original Message-From: [EMAIL PROTECTED] [mailto:
[EMAIL PROTECTED]] On BehalfOf PatriciaSent: Sunday, June 11, 2006 4:19 PMTo: tutor@python.orgSubject: [Tutor] connect to a remote machine - LinuxHi All,
I need to connect to a remote computer on the same network to store datainto its mysql database, and I need to do this using python script.Although I've used mysql and python before, I have no idea how to access a
remote computer with Python. Also, I would have to enter a passphrase andpassword to successfully connect to it..I'd appreciate any help.Thanks!!Patricia___
Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] connect to a remote machine - Linux

2006-06-11 Thread Patricia
Hi All,

I need to connect to a remote computer on the same network to store data into 
its mysql database, and I need to do this using python script.

Although I've used mysql and python before, I have no idea how to access a 
remote computer with Python. Also, I would have to enter a passphrase and 
password to successfully connect to it.. 

I'd appreciate any help.
Thanks!!

Patricia

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problems when displaying numbers

2006-04-13 Thread Patricia
 
> An example of result before the call to calc_numbers is: [50L, -1, 1, -1]

An example of result before the call is: [50L, -1L, 1L, -1L]

Sorry about that.

Thanks,
Patricia

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problems when displaying numbers

2006-04-12 Thread Patricia
Hi,

This is my code:

conn =  MySQLdb.connect(host = "localhost", user = "root", passwd = "",
db ="mydb")
cursor = conn.cursor()
cursor.execute("""SELECT h, k, l, m, s, t
FROM targets WHERE target_name = %s""", (target))
result = cursor.fetchone()

alist = helperfunc.calc_numbers(list(result)) # read below

cursor.close()
conn.close()

for li in alist:
if li == '':
 s = s + "" 
 else:
 s = s + "%s" % li   # problem here


calc_numbers is a method in helperfunc.py that takes the list of values
that I retrieved from the database and then does some calculations 
(addition & division) and also replaces a specific number with ''.
 
When I display the results, most of the times everything looks right, BUT
sometimes I get i.e.  15%% instead of 15. I don't understand why %% is 
added to some of the numbers being displayed. I've noticed that the numbers 
that show %% are the ones that have been modified in the calc_numbers 
method. The numbers that are not touched in that method, don't show it. 
When I printed the list obatined from the calc_numbers method, the 
numbers that have not been touched have an L at the end (i'm assuming 
it stands for long). As I said these numbers are displayed correctly 
all the time. I'm really hoping someone can point me to the right direction
because I've tried different things and nothing seems to work.

Another quick question, my page shows several drop down boxes with 
pre-selected values. When I submit the form or open the page, the 
preselected values appear, but when I press the reload button, 
they don't. (Mozilla)

Thanks,
Patricia





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] html and mod_python

2006-03-23 Thread Patricia G.
Hi again!
result[0] is the value i got from the database. I tried the following piece of code and got : 
 
"TypeError: not enough arguments for format string"
   if result [0] in range(0, 101, 10):
    selected_value = result[0]
    else:
    selected_value = '-'

    tag = """
    
    %s
    -
    0%
    10%
    20%
    30%
    40%
    50%
    60%
    70%
    80%
    90%
    100%
    """ % (selected_value,selected_value)

    return tag

What did i do wrong?
Thanks,
Patty







___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor