Re: [Tutor] Python 2.7 on Ubuntu 11.10 - Do not unintall

2011-11-02 Thread Joel Montes de Oca

On 11/02/2011 02:26 AM, spa...@gmail.com wrote:
Shouldn't this be treated as a bug then? As a user I should be allowed 
to uninstall the software I want to.

Or you uninstalled other things by mistake?

On Wed, Nov 2, 2011 at 6:18 AM, Joel Montes de Oca 
joelmonte...@gmail.com mailto:joelmonte...@gmail.com wrote:


On Tue 01 Nov 2011 08:56:41 PM EDT, Max gmail wrote:

Heh, yeah.  It's usually a bad idea to do stuff like that (I
know a guy (Windows) who deleted his OS of his system).

On Nov 1, 2011, at 7:40 PM, Joel Montes de Oca wrote:

I just discovered that it is a bad idea to complete
uninstall Python 2.7 on Ubuntu 11.10. If you do, expect a
lot of things not to work, mainly your system. haha

I just reinstalled Python 2.7 and I hope things are not so
bad now when I reboot.

-- 
-Joel M.


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



Yea, It wiped out GNOME and UNITY along with a few other
applications. It wasn't a big deal tho, I just reinstalled
ubuntu-desktop threw apt-get. :)



-- 
-Joel M.

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




--
http://spawgi.wordpress.com
We can do it and do it better.


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


Spawgi,

Like a few people have mentioned before, this isn't a bug. Unity and 
GNOME rely on Python 2.7 to work, which is fine. When I uninstalled 
Python2.7 GNOME and Unity didn't have a way to run their py files, which 
results in a broken environment. The package manager was smart enough to 
list everything that was going to be uninstalled since they rely on 
Python. So instead of leaving broken systems on my computer, it 
uninstalled all the packages that would had been broken, including Unity 
and GNOME.


I just want to add one thing that hasn't been mentioned yet. The only 
bug was the one called Joel M, which failed to read the uninstall list 
until later when I noticed my environments were being uninstalled.  haha!


Synaptic, the package manager I was using, listed everything that was 
going to be uninstalled but I didn't read it. I didn't realize how many 
system tools used python until later. Live and learn.


It wasn't a big deal. All I had to do was reinstall Python2.7 and 
reboot. Of course, after the reboot, I didn't have an environment to log 
into. So I pressed Ctr + Alt + F1 to get into tty1 and then ran sudo 
apt-get install ubuntu-desktop. That took care of the missing 
environment. Then I restarted with sudo shutdown -r now. I didn't really 
need to do that since I think restarting X was enough but I restarted 
anyhow.


As far as the comments about Ubuntu 11.10 being buggy. I don't think 
it's Ubuntu 11.10 that is buggy, I think it's Unity that is a bit buggy. 
I use Unity and sometimes applications do crash or fail to open when you 
click on their icons... Like I said, I think it's an issue with Unity 
but I can't say for sure since I haven't used another environment since 
I installed Ubuntu 11.10.


--
-Joel M.

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


Re: [Tutor] login window using Tk

2011-11-01 Thread Joel Montes de Oca

On 11/01/2011 02:18 PM, Alan Gauld wrote:

On 01/11/11 18:09, Alexander Etter wrote:


Hi, hopefully a more experience hacker can provide clarity, but how
secure does this login need to be? I dont much about python in DRAM but
your login sounds like it could be easily hacked.


That depends entirely on how the user is authenticated.
(assuming basic things like blanked password fields in the UI etc)

For all we know the authentication could be against a central
Single Sign On authentication server someplace.
The OP didn't say.



Question, once the code is compiled to a binary, can someone inject code 
to cause the hidden window to show, skipping the login altogether?


--
-Joel M.

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


[Tutor] Python 2.7 on Ubuntu 11.10 - Do not unintall

2011-11-01 Thread Joel Montes de Oca
I just discovered that it is a bad idea to complete uninstall Python 2.7 
on Ubuntu 11.10. If you do, expect a lot of things not to work, mainly 
your system. haha


I just reinstalled Python 2.7 and I hope things are not so bad now when 
I reboot.


--
-Joel M.

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


Re: [Tutor] Python 2.7 on Ubuntu 11.10 - Do not unintall

2011-11-01 Thread Joel Montes de Oca

On Tue 01 Nov 2011 08:56:41 PM EDT, Max gmail wrote:

Heh, yeah.  It's usually a bad idea to do stuff like that (I know a guy 
(Windows) who deleted his OS of his system).

On Nov 1, 2011, at 7:40 PM, Joel Montes de Oca wrote:


I just discovered that it is a bad idea to complete uninstall Python 2.7 on 
Ubuntu 11.10. If you do, expect a lot of things not to work, mainly your 
system. haha

I just reinstalled Python 2.7 and I hope things are not so bad now when I 
reboot.

--
-Joel M.

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




Yea, It wiped out GNOME and UNITY along with a few other applications. 
It wasn't a big deal tho, I just reinstalled ubuntu-desktop threw 
apt-get. :)



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


[Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Joel Montes de Oca

Hello everyone,

I am having a little trouble with a block of code that isn't behaving 
the way I would expect. Maybe you can give me a hand and point where it 
is going wrong.


The function that is not working correctly belongs to a Paper Rock 
Scissor game I am making.


This particular function is responsible to:
  a) Get the user's choice (Paper, Rock, or Scissors)
  b) Return the user's choice within the variable choice to the 
function that called it.


The function works correctly as long as the user _does not try to enter 
a string other than_ 'P', 'R', or 'S'.


Logic:
Take the user's string and put it in the variable choice.
If choice is not 'P', 'R', or 'S'then pass a message to the user 
and call the function again.
If the choice is 'P', 'R', or 'S'then return choice to where it was 
called from.


The problem is this.

When the user enters a string other than the valid ones, the if 
statements catches it and calls the same function again so the user can 
enter a valid string. But the variable choice does not get assigned the 
new string entered by the user, instead it is empty.


I would expect if the function runs again, the variable choice would be 
updated to the last value given by the user.


The function: ( http://dpaste.com/644857/)

def  UserChoice  ():# The function that returns the choice from the user
print  'Please select (P) for paper, (R) for Rock, or (S) for Scissors.'
choice  =  raw_input('What is your selection?:')

if  choice.lower()  not  in  ('p',  'r','s'):   # Converts the user's 
choice to lowercase and confirms the choice is valid
print  'I am sorry, you entered\''  +  choice.upper()  +  '\'  
which is an invalid response. Please try again.'
raw_input('Press Enter to try again.')
UserChoice  ()  # If the choice is not valid, run the 
function over
else:
return  choice



Output with no problems: ( http://dpaste.com/644866/) 
http://dpaste.com/644866/


Welcome to the PRS game.

Please select (P) for paper, (R) for Rock, or (S) for Scissors.
What is your selection?: s

You threw down Scissors while the computer threw down Rock

LOOSE

Output with problems: ( http://dpaste.com/644868/)

Welcome to the PRS game.

Please select (P) for paper, (R) for Rock, or (S) for Scissors.
What is your selection?: L
I am sorry, you entered 'L' which is an invalid response. Please try again.
Press Enter to try again.
Please select (P) for paper, (R) for Rock, or (S) for Scissors.
What is your selection?: s

You threw down None while the computer threw down Paper

LOOSE

Here's the full source code in case the problem is outside of the 
function: ( http://dpaste.com/644873/)


import  random  # Import the random library

def  main  ():  # The main function that gets called from main()
print  '\nWelcome to the PRS game.\n'

choice  =  UserChoice  ()   # Gets the choice from the user
cchoice  =  ComputerChoice  ()  # Gets the choice from the 
computer

PrintOutcome  (choice,  cchoice)# Passes both choices to the 
PrintChoice function for display


return  0

def  UserChoice  ():# The function that returns the choice from the user
print  'Please select (P) for paper, (R) for Rock, or (S) for Scissors.'
choice  =  raw_input('What is your selection?:')

if  choice.lower()  not  in  ('p',  'r','s'):   # Converts the user's 
choice to lowercase and confirms the choice is valid
print  'I am sorry, you entered\''  +  choice.upper()  +  '\'  
which is an invalid response. Please try again.'
raw_input('Press Enter to try again.')
UserChoice  ()  # If the choice is not valid, run the 
function over
else:
return  choice

def  ComputerChoice  ():# The function that returns the choice 
from the computer
PRS  =  ['Rock',  'Paper',  'Scissors'] # A list of choices

cchoice  =  random.choice(PRS)  # Choose a random item from the list

return  cchoice # Return the function

def  PrintOutcome  (UC,  CC):   # Function responsable to display the 
choices and results
PRS  =  ['Rock',  'Paper',  'Scissors']

# Convert the letters to words
if  UC  ==  'r':
UC  =  PRS[0]
elif  UC  ==  'p':
UC  =  PRS[1]
elif  UC  ==  's':
UC  =  PRS[2]

print  '\n\tYou threw down',  UC,  'while the computer threw down',  CC 
 +'\n'

# find the outcome of the game
if  UC  ==  CC:
print  'We have a tie, both players gain a point!'
elif  UC  ==  'Rock'  and  CC  ==  'Scissors':
print  'WIN'
elif  UC  ==  'Paper'  and  CC  ==  'Rock':
print  'WIN'

Re: [Tutor] Tutor Digest, Vol 92, Issue 127

2011-10-31 Thread Joel Montes de Oca

On Mon 31 Oct 2011 11:59:47 AM EDT, Asokan Pichai wrote:


From: Joel Montes de Oca joelmonte...@gmail.com
mailto:joelmonte...@gmail.com
To: Tutor Python tutor@python.org mailto:tutor@python.org
Subject: [Tutor] Paper Rock Scissors game - User's choice not returned
   properly
Message-ID: 4eaec191.3060...@gmail.com
mailto:4eaec191.3060...@gmail.com
Content-Type: text/plain; charset=iso-8859-1; Format=flowed

Hello everyone,


The function: ( http://dpaste.com/644857/)

def  UserChoice  ():# The function that returns the choice
from the user
   print 'Please select (P) for paper, (R) for Rock, or (S)
for Scissors.'
   choice  =  raw_input('What is your selection?:')

   if  choice.lower()  not  in  ('p', 'r','s'):   # Converts
the user's choice to lowercase and confirms the choice is valid
   print 'I am sorry, you entered\''  +
 choice.upper()  + '\'  which is an invalid response. Please try
again.'
   raw_input('Press Enter to try again.')

   UserChoice  ()  # If the choice is not
valid, run the function over


You should use
return UserChoice()

   else:
   return  choice


Asokan Pichai
SVP - Learning and Development

“Faith consists in believing when it is beyond the power of reason to 
believe. 

Voltaire http://www.brainyquote.com/quotes/quotes/v/voltaire163832.html





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


I am not sure if I understand, why doesn't my way work and what do you 
mean I should return UserChoice()?


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


Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Joel Montes de Oca

On Mon 31 Oct 2011 12:14:40 PM EDT, Hugo Arts wrote:


On Mon, Oct 31, 2011 at 4:41 PM, Joel Montes de Oca
joelmonte...@gmail.com wrote:


Hello everyone,

I am having a little trouble with a block of code that isn't behaving the
way I would expect. Maybe you can give me a hand and point where it 
is going

wrong.

The function that is not working correctly belongs to a Paper Rock 
Scissor

game I am making.

This particular function is responsible to:
a) Get the user's choice (Paper, Rock, or Scissors)
b) Return the user's choice within the variable choice to the function
that called it.

The function works correctly as long as the user does not try to enter a
string other than 'P', 'R', or 'S'.

Logic:
Take the user's string and put it in the variable choice.
If choice is not 'P', 'R', or 'S' then pass a message to the user and
call the function again.
If the choice is 'P', 'R', or 'S' then return choice to where it was
called from.

The problem is this.

When the user enters a string other than the valid ones, the if 
statements
catches it and calls the same function again so the user can enter a 
valid
string. But the variable choice does not get assigned the new string 
entered

by the user, instead it is empty.

I would expect if the function runs again, the variable choice would be
updated to the last value given by the user.

The function: ( http://dpaste.com/644857/)

def UserChoice (): # The function that returns the choice from the user
print 'Please select (P) for paper, (R) for Rock, or (S) for Scissors.'
choice = raw_input('What is your selection?: ')

if choice.lower() not in ('p', 'r','s'): # Converts the user's choice to
lowercase and confirms the choice is valid
print 'I am sorry, you entered \'' + choice.upper() + '\' which is an
invalid response. Please try again.'
raw_input('Press Enter to try again.')
UserChoice () # If the choice is not valid, run the function over
else:
return choice




Your problem is that you don't quite understand recursion.

When a function calls itself, it's not actually any different from
when a function A calls another function B. Once function B is done
running and returns, control goes back to function A. It doesn't
matter if function B is actually the same function as A. In fact, even
if A and B are the same function, they don't share any variables and
are totally separate as if they were two different functions that just
happened to do the same thing.

So, how does this apply to your function? Let's go through a run of
it. We call UserChoice (this is function A) and we input a wrong
letter. So, A calls UserChoice again (this is function B), and this
time we input something valid. So, function B runs the line return
choice.

Control now returns to function A, right at the point where we called
function B. So what do we do here with the choice that was just
returned from function B? Well, looking at the line where it's called,
it's just UserChoice(). So we do nothing. We just throw it away.
Then, we continue on with function A, move out of the if statement,
and fall off the end of the function. And when that happens, Python
returns None from function A to show you that nothing was returned.

If you understood all that, you should be able to fix your problem.

Hugo


Hey Hugo,

I think I understand your explanation. Let me see if I get it.

The code:

def  UserChoice  ():  *# I WILL CALL THIS FUNCTION A*
print  'Please select (P) for paper, (R) for Rock, or (S) for Scissors.'
choice  =  raw_input('What is your selection?:')

if  choice.lower()  not  in  ('p',  'r','s'):
print  'I am sorry, you entered\''  +  choice.upper()  +  '\'  which is 
an invalid response. Please try again.'
raw_input('Press Enter to try again.')
UserChoice  ()  *# I WILL CALL THIS FUNCTION B*
else:
return  choice*# I WILL CALL THE ORIGINAL CALLING FUNCTION, FUNCTION 
MAIN*


OK so when the user uses a valid letter, the variable choice gets 
returned to FUNCTION MAIN. Everything works fine.


When the user enters an invalid letter, FUNCTION B calls FUNCTION A. 
FUNCTION A returns choice to FUNCTION B. FUNCTION B does nothing with 
the return, FUNCTION MAIN gets nothing to returned to it, thus choice is 
NONE.


FUN MAIN
  |
  |
  |__ FUN A
  |
  |
  |_ FUN B

This is how I understand it. So if I want this to work, I need FUN B to 
give something back to FUN A so that FUN A will have something to give 
back to FUN MAIN but that doesn't feel right.


Is there a way to say GO TO FUN A instead of calling the function?



I also found this Youtube video on the topic of recursion in python. 
http://www.youtube.com/watch?v=72hal4Cp_2I


--
-Joel M.

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


Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Joel Montes de Oca

On 10/31/2011 11:41 AM, Joel Montes de Oca wrote:

Hello everyone,

I am having a little trouble with a block of code that isn't behaving 
the way I would expect. Maybe you can give me a hand and point where 
it is going wrong.


The function that is not working correctly belongs to a Paper Rock 
Scissor game I am making.


This particular function is responsible to:
  a) Get the user's choice (Paper, Rock, or Scissors)
  b) Return the user's choice within the variable choice to the 
function that called it.


The function works correctly as long as the user _does not try to 
enter a string other than_ 'P', 'R', or 'S'.


Logic:
Take the user's string and put it in the variable choice.
If choice is not 'P', 'R', or 'S'then pass a message to the user 
and call the function again.
If the choice is 'P', 'R', or 'S'then return choice to where it 
was called from.


The problem is this.

When the user enters a string other than the valid ones, the if 
statements catches it and calls the same function again so the user 
can enter a valid string. But the variable choice does not get 
assigned the new string entered by the user, instead it is empty.


I would expect if the function runs again, the variable choice would 
be updated to the last value given by the user.


The function: ( http://dpaste.com/644857/)

def  UserChoice  ():# The function that returns the choice from the user
print  'Please select (P) for paper, (R) for Rock, or (S) for Scissors.'
choice  =  raw_input('What is your selection?:')

if  choice.lower()  not  in  ('p',  'r','s'):   # Converts the user's 
choice to lowercase and confirms the choice is valid
print  'I am sorry, you entered\''  +  choice.upper()  +  '\'  
which is an invalid response. Please try again.'
raw_input('Press Enter to try again.')
UserChoice  ()  # If the choice is not valid, run the 
function over
else:
return  choice


Output with no problems: ( http://dpaste.com/644866/) 
http://dpaste.com/644866/

Welcome to the PRS game.

Please select (P) for paper, (R) for Rock, or (S) for Scissors.
What is your selection?: s

You threw down Scissors while the computer threw down Rock

LOOSE
Output with problems: ( http://dpaste.com/644868/)

Welcome to the PRS game.

Please select (P) for paper, (R) for Rock, or (S) for Scissors.
What is your selection?: L
I am sorry, you entered 'L' which is an invalid response. Please try again.
Press Enter to try again.
Please select (P) for paper, (R) for Rock, or (S) for Scissors.
What is your selection?: s

You threw down None while the computer threw down Paper

LOOSE
Here's the full source code in case the problem is outside of the 
function: ( http://dpaste.com/644873/)


import  random  # Import the random library

def  main  ():  # The main function that gets called from main()
print  '\nWelcome to the PRS game.\n'

choice  =  UserChoice  ()   # Gets the choice from the user
cchoice  =  ComputerChoice  ()  # Gets the choice from the 
computer

PrintOutcome  (choice,  cchoice)# Passes both choices to the 
PrintChoice function for display


return  0

def  UserChoice  ():# The function that returns the choice from the user
print  'Please select (P) for paper, (R) for Rock, or (S) for Scissors.'
choice  =  raw_input('What is your selection?:')

if  choice.lower()  not  in  ('p',  'r','s'):   # Converts the user's 
choice to lowercase and confirms the choice is valid
print  'I am sorry, you entered\''  +  choice.upper()  +  '\'  
which is an invalid response. Please try again.'
raw_input('Press Enter to try again.')
UserChoice  ()  # If the choice is not valid, run the 
function over
else:
return  choice

def  ComputerChoice  ():# The function that returns the choice 
from the computer
PRS  =  ['Rock',  'Paper',  'Scissors'] # A list of choices

cchoice  =  random.choice(PRS)  # Choose a random item from the list

return  cchoice # Return the function

def  PrintOutcome  (UC,  CC):   # Function responsable to display the 
choices and results
PRS  =  ['Rock',  'Paper',  'Scissors']

# Convert the letters to words
if  UC  ==  'r':
UC  =  PRS[0]
elif  UC  ==  'p':
UC  =  PRS[1]
elif  UC  ==  's':
UC  =  PRS[2]

print  '\n\tYou threw down',  UC,  'while the computer threw down',  CC 
 +'\n'

# find the outcome of the game
if  UC  ==  CC:
print  'We have a tie, both players gain a point!'
elif  UC  ==  'Rock'  and  CC  ==  'Scissors':
print  'WIN'
elif  UC  ==  'Paper

Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Joel Montes de Oca

On 10/31/2011 02:13 PM, Prasad, Ramit wrote:

Just a minor note, this break is redundant. Breaks are used to exit (for/while) 
loops but keep control in the function. A return exits the function immediately.

 if choice.lower() in ('p', 'r','s'):# Converts the user's choice 
to lowercase and confirms the choice is valid
 return choice
 break


There is also a continue which is similar to a break, but instead of exiting the loop, 
it will start the loop code over for the next value (thus continuing the loop).


t = [ 'not this', 'do this', 'not this either', 'most definitely do this' ]
for string in t:

... if string.startswith( 'not' ):
... continue # I want to keep working with the other elements in the 
list
... print string
...
do this
most definitely do this

for string in t:

... if string.startswith( 'not' ):
... break # I want to abort the entire loop now
... print string
...



Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Awesome, thanks for the tip. I removed the break from the code.

Thanks again.

--
-Joel M.

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


Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Joel Montes de Oca

On 10/31/2011 02:14 PM, Marc Tompkins wrote:

On Mon, Oct 31, 2011 at 10:57 AM, Joel Montes de Oca
joelmonte...@gmail.com  wrote:

  I came up with this to solve the problem.

def UserChoice ():# The function that returns the choice from the user
 while 1:

 print 'Please select (P) for paper, (R) for Rock, or (S) for Scissors.'
 choice = raw_input('What is your selection?: ')
 if choice.lower() in ('p', 'r','s'):# Converts the user's choice 
to lowercase and confirms the choice is valid
 return choice
 break
 else:
 print 'Try again.'

It puts the choice into a loop and only exits when the user enters a valid 
value. It works and it's so much easier to read too!


You could simplify it even further by actually using the while:


def UserChoice ():# The function that returns the choice from the user
choice = ''
attempt = 0
while choice.lower() not in ('p', 'r','s'):
if attempt  0: print 'Please try again.'
print 'Please select (P) for paper, (R) for Rock, or (S) for Scissors.'
choice = raw_input('What is your selection?: ')
attempt +=1
return choice.lower()

It's a matter of personal preference, but I try to avoid while 1 or
while True loops if at all possible.  For one thing, it seems
counter-productive to set up a loop that doesn't exit, and then to
have to use 'break' to get out of it!

One last thing:  HTML formatting is pretty, but it tends to screw
things up.  Someone else is bound to say it if I don't, so:  please
use plain text only when submitting code to the list.  Thanks!
Things for the tip Mark, I have set up Thunderbird to send text only 
when emailing the python.org domain.


--
-Joel M.

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


Re: [Tutor] Paper Rock Scissors game - User's choice not returned properly

2011-10-31 Thread Joel Montes de Oca

On 10/31/2011 07:10 PM, Steven D'Aprano wrote:

Alan Gauld wrote:

On 31/10/11 20:22, Peter Otten wrote:

Alan Gauld wrote:


if choice.lower() not in ('prs'): # NB use a single string


That's not a good idea. If a user accidentally enters PR (for 
example) your

version will mistake that for a valid choice.


Good point, although  you could test the first character only...

if choice[0].lower() not in ('prs'): # NB use a single string


Why would you do that? If the user is supposed to enter a single 
letter, why would you accept (for example) screw you hippy, I hate 
this game! as the valid response s?




I agree, I am not sure that I see the benefit of using a single string. 
If anything, it makes it a bit harder to read by someone other than the 
person who wrote it.


   if choice.lower() in ('p', 'r','s'):

I think the code above is a lot clearer.

--
-Joel M.

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


[Tutor] Method to create small and simple database

2011-10-29 Thread Joel Montes de Oca

Hello everyone,

About me:

This is the first time I post to Tutor@Python.org.

I am brand spanking new to Python. I can create simple application, gone 
through a few tutorials and watched the Google Python 2 day class on 
Youtube. (List of classes: http://goo.gl/Ud5rg)


Just yesterday I figured out how to load up a GUI made in Glade and pass 
singles around and what not. Huge accomplishment for me since 
documentation is a bit shaky for noobs like me. :)


I have some programming knowledge. I learned (self tough) VB when I was 
in middle school and then did a intro to C++ in college. Of course 
mentioning that is trivial since I haven't done any programming for 
about 5 years or so.. But I do know basic concepts. Just need a little 
push in the right direction..


--

I think I know how to design my application but I would like to put it 
on here for you guys to review and provide me with feedback/suggestions 
as to the best way to go about it.


--

The application:

I want to build a simple application that keeps track of items borrowers 
check out. So the end user types in the names of /borrowers/ and also 
types in a list of /items/. Then the end user checks out the /items/ to 
the /borrowers/.


The category that my application would fall under is close to 
/collection management tools/. Here's a list of a few other applications 
that do something like what I am aiming for: 
http://www.makeuseof.com/tag/4-open-source-collection-manager-apps/


In addition to the application keeping track of who has what, I would 
like to code the date the items are out, which borrowers have not 
borrowed anything in the last month, and so on. That said, I need to 
setup some kind of database like file. I don't want to have a database 
server though.


The reason I want to build a new tool is because:

   A) I want to play around with Python
   B) My friend needs the application to be simple and geared to his
   needs without too many extra bells  whistles


--


My method:

I was thinking of using the lxmal module to construct a XML file to 
read/write all the information.


I figured this was the easiest way to do what I need since the 
information is setup as a tree. (Easy to think about and see) Example:


app
borrowers

userJohn Doe/user

checked out Item1:Item2:||2011/4/2/checked out

userMary Doe/user

checked out Item3||2011/7/22/checked out

/borrowers
objects

itemItem1/item

createdOn2011/2/1/createdOn

checked_out_times32/checked_out_times

itemItem2/item

createdOn2011/2/1/createdOn

checked_out_times22/checked_out_times

itemItem3/item

createdOn2011/2/1/createdOn

checked_out_times1/checked_out_times
/objects
/app

The application will not be used in an enterprise kind of environment. 
The application is meant to hold about 80 borrowers and about 100 items 
and that's about it.


Is this a good way to go about my project? Is there a better  easier way?

I don't want to trade off better with easy. Someone once suggested 
on Freenode #Python that I should use a sql database. I don't remember 
the name of it. It was something like lightsql or something like that. 
That particular database didn't use a server end. I guess it spit out a 
txt database or something... This might be a good time to mention I know 
very little about database construction or sql commands.


Anyhow, I am looking forward to hearing opinion's and suggestions.

Thanks!


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


Re: [Tutor] Method to create small and simple database

2011-10-29 Thread Joel Montes de Oca

On Sat Oct 29 14:14:24 2011, Joel Montes de Oca wrote:



On Sat Oct 29 13:29:59 2011, Peter Otten wrote:


Joel Montes de Oca wrote:



Hello everyone,

About me:

This is the first time I post to Tutor@Python.org.

I am brand spanking new to Python. I can create simple application,
gone
through a few tutorials and watched the Google Python 2 day class on
Youtube. (List of classes: http://goo.gl/Ud5rg)

Just yesterday I figured out how to load up a GUI made in Glade and
pass
singles around and what not. Huge accomplishment for me since
documentation is a bit shaky for noobs like me. :)

I have some programming knowledge. I learned (self tough) VB when I was
in middle school and then did a intro to C++ in college. Of course
mentioning that is trivial since I haven't done any programming for
about 5 years or so.. But I do know basic concepts. Just need a little
push in the right direction..

--

I think I know how to design my application but I would like to put it
on here for you guys to review and provide me with feedback/suggestions
as to the best way to go about it.

--

The application:

I want to build a simple application that keeps track of items
borrowers
check out. So the end user types in the names of /borrowers/ and also
types in a list of /items/. Then the end user checks out the /items/ to
the /borrowers/.

The category that my application would fall under is close to
/collection management tools/. Here's a list of a few other
applications
that do something like what I am aiming for:
http://www.makeuseof.com/tag/4-open-source-collection-manager-apps/

In addition to the application keeping track of who has what, I would
like to code the date the items are out, which borrowers have not
borrowed anything in the last month, and so on. That said, I need to
setup some kind of database like file. I don't want to have a database
server though.

The reason I want to build a new tool is because:

A) I want to play around with Python
B) My friend needs the application to be simple and geared to his
needs without too many extra bells whistles


--


My method:

I was thinking of using the lxmal module to construct a XML file to
read/write all the information.

I figured this was the easiest way to do what I need since the
information is setup as a tree. (Easy to think about and see) Example:

app
borrowers

userJohn Doe/user

checked out Item1:Item2:||2011/4/2/checked out

userMary Doe/user

checked out Item3||2011/7/22/checked out

/borrowers
objects

itemItem1/item

createdOn2011/2/1/createdOn

checked_out_times32/checked_out_times

itemItem2/item

createdOn2011/2/1/createdOn

checked_out_times22/checked_out_times

itemItem3/item

createdOn2011/2/1/createdOn

checked_out_times1/checked_out_times
/objects
/app

The application will not be used in an enterprise kind of environment.
The application is meant to hold about 80 borrowers and about 100 items
and that's about it.

Is this a good way to go about my project? Is there a better easier
way?

I don't want to trade off better with easy. Someone once suggested
on Freenode #Python that I should use a sql database. I don't remember
the name of it. It was something like lightsql or something like that.
That particular database didn't use a server end. I guess it spit out a
txt database or something... This might be a good time to mention I
know
very little about database construction or sql commands.

Anyhow, I am looking forward to hearing opinion's and suggestions.



Well, using sqlite

http://docs.python.org/library/sqlite3.html

may be both better and easier than lxml, but for the tiny amount of
data you
are planning to handle you can also make do with a few of Python's
lists and
dicts, and use pickle

http://docs.python.org/library/pickle.html

to save the data when you're done. It won't get easier than that.

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




Awesome Peter,

Yea, sqlite3 was what the good folks on irc.freenode.net #Python told
me to use but the pickle module seems like the simpliest way to get
the job done.

I'll look into both of them. I'm going to have to rethink how I am
going to build the program using sqlite or pickle().

Thanks again

-Joel M.



After looking at the Python module documentation for sqlite3 
(http://docs.python.org/library/sqlite3.html#module-sqlite3), it seems 
to me it's the best way to make the small database that I am looking for.


Now I need to look for a basic tutorial on constructing a simple 
database (tables, rows, keys) and how to connect all that stuff 
together. If anyone happens to know of a good intro tutorial or 
documentation to database concepts, please forward it to me.


Thanks!

___
Tutor maillist  -  Tutor