Re: [Tutor] Zipping files and Mysql

2011-06-28 Thread Timo

On 27-06-11 21:45, gagnr...@verizon.net wrote:

I am trying to write a script that will dump a mysql db and then zip the file.


I do know about mysqldb, but I was wondering if there is anything native to the 
libraries that will allow me to do this without using a seperate piece.   Then 
after I gather the DBs, I need to zip them.   I wrote the following, but wanted 
to know if I am heading in the correct direction.

zipfile.zipfile(/myfiles/my_db/, w, zip_stored)
Well, for what it's worth, I'm using the zipfile module as well in one 
of my projects to make a backup of the user's configuration directory. 
Which works pretty good.


Do have a good look though at the documentation or find some examples 
through your search engine, because the above line won't work at all.


Cheers,
Timo


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


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


Re: [Tutor] Zipping files and Mysql

2011-06-28 Thread gagnrath
First time trying to use it, so I don't expect it to work.   Got to see if I 
have a file i don't mind playing around with to see if I can zip it up using 
the zipfile.

As for the MySQL, I think I may have to resign myself to using an alternate 
method than the straight python libraries.


Jun 28, 2011 04:02:48 AM, timomli...@gmail.com wrote:

===

On 27-06-11 21:45, gagnr...@verizon.net wrote:
> I am trying to write a script that will dump a mysql db and then zip the file.
>
>
> I do know about mysqldb, but I was wondering if there is anything native to 
> the libraries that will allow me to do this without using a seperate piece.   
> Then after I gather the DBs, I need to zip them.   I wrote the following, but 
> wanted to know if I am heading in the correct direction.
>
> zipfile.zipfile(/myfiles/my_db/, w, zip_stored)
Well, for what it's worth, I'm using the zipfile module as well in one 
of my projects to make a backup of the user's configuration directory. 
Which works pretty good.

Do have a good look though at the documentation or find some examples 
through your search engine, because the above line won't work at all.

Cheers,
Timo

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

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


[Tutor] Python GUI

2011-06-28 Thread David Merrick
# Guess My Number GUI
# Create a story based on user input

from tkinter import *
import random
class Application(Frame):
""" GUI application that creates a story based on user input. """
def __init__(self, master):
""" Initialize Frame. """
super(Application, self).__init__(master)
self.grid()
self.create_widgets()

def create_widgets(self):
""" Create widgets to get story information and to display story.
"""
# create instruction label
Label(self,
  text = "Welcome to 'Guess My Number'!\n\nI'm thinking of a
number between 1 and 100.\nTry to guess it in as few attempts as possible."
  ).grid(row = 0, column = 0, columnspan = 2, sticky = W)


# create a label for body parts radio buttons
Label(self,
  text = "Take a guess:"
  ).grid(row = 6, column = 0, sticky = W)
self.numberEnt = Entry(self)
self.numberEnt.grid(row = 6, column = 1, sticky = W)

# create a submit button
Button(self,
  text = "Click to see if you got it",
   command = self.testNumber
   ).grid(row = 7, column = 0, sticky = W)

self.numberTxt = Text(self, width = 75, height = 10, wrap = WORD)
self.numberTxt.grid(row = 8, column = 0, columnspan = 4)

def testNumber(self):
""" Fill text box with new story based on user input. """
# get values from the GUI

# create the story

guess = int(self.numberEnt.get())
tries = 1

while guess != the_number:
if guess > the_number:
  number += "Lower..."
else:
  number += "Higher..."
guess = int(self.numberEnt.get())
tries += 1

# display the text
self.numberTxt.delete(0.0, END)
self.numberTxt.insert(0.0, number)


number += "You guessed it!  The number was" + the_number
number += "And it only took you " + tries + " tries!\n"
self.numberTxt.delete(0.0, END)
self.numberTxt.insert(0.0, number)



# main
number = ""
the_number = random.randint(1, 100)
root = Tk()
root.title("Mad Lib")
app = Application(root)
root.mainloop()

*Output*

Traceback (most recent call last):
  File "I:\Python\programs\guess_my_ numberChapter10.py", line 60, in

number += "You guessed it!  The number was" + the_number
NameError: name 'number' is not defined

Any ides??? Is my code going to work apart from this
problem?

-- 
Dave Merrick

merrick...@gmail.com

Ph   03 3423 121
Cell 027 3089 169
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python GUI

2011-06-28 Thread Luke Paireepinart
The error message tells you everything... On line 60, you try to add to 
"number" but the variable hasn't been defined.

We aren't going to debug your code for you, do YOU think it will work apart 
from this? Have you tried running any of the code? It's almost always better to 
build small parts and test along the way than to write out a whole program and 
try it at the end.

-
Sent from a mobile device. Apologies for brevity and top-posting.
-

On Jun 28, 2011, at 11:28 PM, David Merrick  wrote:

> # Guess My Number GUI
> # Create a story based on user input
> 
> from tkinter import *
> import random
> class Application(Frame):
> """ GUI application that creates a story based on user input. """
> def __init__(self, master):
> """ Initialize Frame. """
> super(Application, self).__init__(master)  
> self.grid()
> self.create_widgets()
> 
> def create_widgets(self):
> """ Create widgets to get story information and to display story. """
> # create instruction label
> Label(self,
>   text = "Welcome to 'Guess My Number'!\n\nI'm thinking of a 
> number between 1 and 100.\nTry to guess it in as few attempts as possible."
>   ).grid(row = 0, column = 0, columnspan = 2, sticky = W)   
> 
> 
> # create a label for body parts radio buttons
> Label(self,
>   text = "Take a guess:"
>   ).grid(row = 6, column = 0, sticky = W)
> self.numberEnt = Entry(self)
> self.numberEnt.grid(row = 6, column = 1, sticky = W)
> 
> # create a submit button
> Button(self,
>   text = "Click to see if you got it",
>command = self.testNumber
>).grid(row = 7, column = 0, sticky = W)
> 
> self.numberTxt = Text(self, width = 75, height = 10, wrap = WORD)
> self.numberTxt.grid(row = 8, column = 0, columnspan = 4)
> 
> def testNumber(self):
> """ Fill text box with new story based on user input. """
> # get values from the GUI
> 
> # create the story
> 
> guess = int(self.numberEnt.get())
> tries = 1
> 
> while guess != the_number:
> if guess > the_number:
>   number += "Lower..."
> else:
>   number += "Higher..." 
> guess = int(self.numberEnt.get())
> tries += 1
> 
> # display the text
> self.numberTxt.delete(0.0, END)
> self.numberTxt.insert(0.0, number)
> 
> 
> number += "You guessed it!  The number was" + the_number
> number += "And it only took you " + tries + " tries!\n"
> self.numberTxt.delete(0.0, END)
> self.numberTxt.insert(0.0, number)   
> 
>  
> 
> # main
> number = ""
> the_number = random.randint(1, 100)
> root = Tk()
> root.title("Mad Lib")
> app = Application(root)
> root.mainloop()
> 
> Output
> 
> Traceback (most recent call last):
>   File "I:\Python\programs\guess_my_ numberChapter10.py", line 60, in 
> number += "You guessed it!  The number was" + the_number
> NameError: name 'number' is not defined
> 
> Any ides??? Is my code going to work apart from this 
> problem?
> 
> -- 
> Dave Merrick
> 
> merrick...@gmail.com
> 
> Ph   03 3423 121
> Cell 027 3089 169
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python GUI

2011-06-28 Thread priyesh raj
>
> Message: 2
> Date: Wed, 29 Jun 2011 16:28:25 +1200
> From: David Merrick 
> To: tutor@python.org
> Subject: [Tutor] Python GUI
> Message-ID: 
> Content-Type: text/plain; charset="utf-8"
>
> # Guess My Number GUI
> # Create a story based on user input
>
> from tkinter import *
> import random
> class Application(Frame):
>""" GUI application that creates a story based on user input. """
>def __init__(self, master):
>""" Initialize Frame. """
>super(Application, self).__init__(master)
>self.grid()
>self.create_widgets()
>
>def create_widgets(self):
>""" Create widgets to get story information and to display story.
> """
># create instruction label
>Label(self,
>  text = "Welcome to 'Guess My Number'!\n\nI'm thinking of a
> number between 1 and 100.\nTry to guess it in as few attempts as possible."
>  ).grid(row = 0, column = 0, columnspan = 2, sticky = W)
>
>
># create a label for body parts radio buttons
>Label(self,
>  text = "Take a guess:"
>  ).grid(row = 6, column = 0, sticky = W)
>self.numberEnt = Entry(self)
>self.numberEnt.grid(row = 6, column = 1, sticky = W)
>
># create a submit button
>Button(self,
>  text = "Click to see if you got it",
>   command = self.testNumber
>   ).grid(row = 7, column = 0, sticky = W)
>
>self.numberTxt = Text(self, width = 75, height = 10, wrap = WORD)
>self.numberTxt.grid(row = 8, column = 0, columnspan = 4)
>
>def testNumber(self):
>""" Fill text box with new story based on user input. """
># get values from the GUI
>
># create the story
>
>guess = int(self.numberEnt.get())
>tries = 1
>
>while guess != the_number:
>if guess > the_number:
>  number += "Lower..."
>else:
>  number += "Higher..."
>guess = int(self.numberEnt.get())
>tries += 1
>
># display the text
>self.numberTxt.delete(0.0, END)
>self.numberTxt.insert(0.0, number)
>
>
> > The problem is here. You have initialised the variable "number" as a
part of the main function and trying to call it within the function of
class. You need to initialise the variable here itself, or need to pass the
variable (which you initialised in main) to this function.


> number += "You guessed it!  The number was" + the_number
> number += "And it only took you " + tries + " tries!\n"
> self.numberTxt.delete(0.0, END)
> self.numberTxt.insert(0.0, number)
>
>
>
> # main
> number = ""
> the_number = random.randint(1, 100)
> root = Tk()
> root.title("Mad Lib")
> app = Application(root)
> root.mainloop()
>
> *Output*
>
> Traceback (most recent call last):
>  File "I:\Python\programs\guess_my_ numberChapter10.py", line 60, in
> 
>number += "You guessed it!  The number was" + the_number
> NameError: name 'number' is not defined
>
> Any ides??? Is my code going to work apart from this
> problem?
>
> --
> Dave Merrick
>
> merrick...@gmail.com
>
> Ph   03 3423 121
> Cell 027 3089 169
> -- next part --
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20110629/4057af9d/attachment-0001.html
> >
>

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