Re: [Tutor] Python Script Problem. Simple sql problem & py problems.

2005-12-06 Thread w chun
> I wrote my first script (ever) in Python.
>   :
> The second one is more python specific I guess. The programs prints
> the "Exiting" string on exit one time for every action I do. Which
> means that if I add 4 users, I'll see 4 time exiting printed. If I add
> 2 users and delete 1 user, I'll see 3 exiting prints and so on. Any
> idea why does this happen?


hi, and welcome to Python!  for your 1st script, it looks pretty good.
 as far as the 2nd problem is concerned, it's all in the cheers()
function.

first of all, your code won't compile due to indentation issues.  i
assume that your if stmts are lined up like this:

if choc == '1':
 sql_adduser(sql_host, sql_user, sql_pass, sql_dtbs, groupid)
 cheers()

... rather than how they're formatted online.  more importantly, it
appears that you are calling cheers() in a recursive way, for
functionality that doesn't require it.  it is because you call
cheers() again and again recursively that lead you to seeing "Exiting"
for each user you enter (or for any action).  what you should do is to
put things in a while loop to do the desired repeat until the single
exit:

def cheers():
while True:
print "Type [1] to add a user"
print "Type [2] to delete a user"
print "Type [3] to list the dbase"
print "Type [99] to install (default installation, see README)"
print "Type anything else to exit"

choc = raw_input("Choose [1, 2, 3]: ")
if choc == '1':
 sql_adduser(sql_host, sql_user, sql_pass, sql_dtbs, groupid)
elif choc == '2':
 sql_deluser(sql_host, sql_user, sql_pass, sql_dtbs)
elif choc == '3':
 sql_listusers(sql_host, sql_user, sql_pass, sql_dtbs)
elif choc == '99':
 sql_install(sql_host, sql_user, sql_pass, sql_dtbs)
else:
 break
print "Exiting"

cheers()

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2006,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Script Problem. Simple sql problem & py problems.

2005-12-06 Thread Panagiotis Atmatzidis
Hello,

I wrote my first script (ever) in Python. It's an interface for
handling the proftpd virtual users. I wrote the script after reading
the howto.
You can see the browse[1] the code anytime.

These are my first steps in programming in general so.. the problems
that this script has until now, are two:

One is that MySQL's autoincrement works only the first time, I can't
add users after I exit the program the first time. This version or the
script is a re-write. The first one, had no problem with that. The
users were getting the respective key in auto every time I was about
to add a user.

The second one is more python specific I guess. The programs prints
the "Exiting" string on exit one time for every action I do. Which
means that if I add 4 users, I'll see 4 time exiting printed. If I add
2 users and delete 1 user, I'll see 3 exiting prints and so on. Any
idea why does this happen?

Best Regards,

Panagiotis Atmatzidis

[1] http://beast.merseine.nu/files/other/vuhandle.html

ps. This script comes with a specific proftpd configuration file, it
does not make sense without it. If someone wants to test this please
drop a mail and I'll upload the proftpd conf file.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor