[Tutor] finally

2010-06-23 Thread Christopher King
In a try except clause, you can end with finally block. I know it runs
after the try and except blocks regardless of the outcome, but why use it.
Couldn't you just put the code after the try and except block without using
a finally block. Does the finally command do something I don't know about.
Does it make your program more understandable in some way?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] finally

2010-06-24 Thread Christopher King
you mean it will always run even if the exception is handled?

On Thu, Jun 24, 2010 at 9:06 AM, Hugo Arts  wrote:

> On Thu, Jun 24, 2010 at 4:36 AM, Christopher King 
> wrote:
> > In a try except clause, you can end with finally block. I know it
> runs
> > after the try and except blocks regardless of the outcome, but why use
> it.
> > Couldn't you just put the code after the try and except block without
> using
> > a finally block. Does the finally command do something I don't know
> about.
> > Does it make your program more understandable in some way?
>
> The thing about the finally block is that it *always* runs. If you
> just put some code after the try: except: clause, it won't run if
>
> a) the exception is not handled in the try: except: block, but higher
> up in the call stack
> b) the exception is not handled at all
> c) the exception handler terminates the program
> d) the exception handler raises another exception
>
> If you need to do some cleanup, putting it in a finally block is the
> only way to *guarantee* it will run.
>
> Hugo
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] finally

2010-06-24 Thread Christopher King
i mean isn't handled

On Thu, Jun 24, 2010 at 9:12 AM, Christopher King wrote:

> you mean it will always run even if the exception is handled?
>
>
> On Thu, Jun 24, 2010 at 9:06 AM, Hugo Arts  wrote:
>
>> On Thu, Jun 24, 2010 at 4:36 AM, Christopher King 
>> wrote:
>> > In a try except clause, you can end with finally block. I know it
>> runs
>> > after the try and except blocks regardless of the outcome, but why use
>> it.
>> > Couldn't you just put the code after the try and except block without
>> using
>> > a finally block. Does the finally command do something I don't know
>> about.
>> > Does it make your program more understandable in some way?
>>
>> The thing about the finally block is that it *always* runs. If you
>> just put some code after the try: except: clause, it won't run if
>>
>> a) the exception is not handled in the try: except: block, but higher
>> up in the call stack
>> b) the exception is not handled at all
>> c) the exception handler terminates the program
>> d) the exception handler raises another exception
>>
>> If you need to do some cleanup, putting it in a finally block is the
>> only way to *guarantee* it will run.
>>
>> Hugo
>>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] finally

2010-06-24 Thread Christopher King
what manual?

On Wed, Jun 23, 2010 at 10:59 PM, bob gailer  wrote:

>  On 6/23/2010 7:36 PM, Christopher King wrote:
>
> In a try except clause, you can end with finally block. I know it runs
> after the try and except blocks regardless of the outcome, but why use it.
> Couldn't you just put the code after the try and except block without using
> a finally block. Does the finally command do something I don't know about.
> Does it make your program more understandable in some way?
>
>
> Did you read the manual?
>
> "If finally <#12967e4e8be99cad_finally> is present, it specifies a
> ‘cleanup’ handler. The try <#12967e4e8be99cad_try> clause is executed,
> including any except <#12967e4e8be99cad_except> and 
> else<#12967e4e8be99cad_else>clauses. If an exception occurs in any of the 
> clauses and is not handled,
> the exception is temporarily saved. The 
> finally<#12967e4e8be99cad_finally>clause is executed. If there is a saved 
> exception, it is re-raised at the
> end of the finally <#12967e4e8be99cad_finally> clause. If the 
> finally<#12967e4e8be99cad_finally>clause raises another exception or executes 
> a
> return <http://simple_stmts.html#return> or 
> break<http://simple_stmts.html#break>statement, the saved exception is lost. 
> The exception information is not
> available to the program during execution of the 
> finally<#12967e4e8be99cad_finally>clause.
>
> "When a return <http://simple_stmts.html#return>, 
> break<http://simple_stmts.html#break>or
> continue <http://simple_stmts.html#continue> statement is executed in the
> try <#12967e4e8be99cad_try> suite of a try <#12967e4e8be99cad_try>...
> finally <#12967e4e8be99cad_finally> statement, the 
> finally<#12967e4e8be99cad_finally>clause is also executed ‘on the way out.’ A
> continue <http://simple_stmts.html#continue> statement is illegal in the
> finally <#12967e4e8be99cad_finally> clause. (The reason is a problem with
> the current implementation — this restriction may be lifted in the future)."
>
> --
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Time

2010-06-24 Thread Christopher King
I have a module which measures elapsed time. It can also wait til a certain
amount of time has passed till ending. I can send it to you if you like.

On Thu, Jun 24, 2010 at 8:59 AM, Hugo Arts  wrote:

> On Wed, Jun 23, 2010 at 3:11 AM, Dave Angel  wrote:
> >
> > If you're really looking to measure performance, you should use the
> timeit
> > module.  But for simply deciding how much time has elapsed between two
> > points in your code, you can use the time.time() function.
> >
>
> Another one I think is worth mentioning is the cProfile module. Though
> timeit or time.time are more useful when you simply want to know how
> long some task took, when you're optimizing your code and wondering
> what's taking a lot of time, cProfile will tell you.
>
> Hugo
> ___
> 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] finally

2010-06-24 Thread Christopher King
so if you encounter an error that you won't handle, but you still to close
files and save data, you could use finally?

On Thu, Jun 24, 2010 at 10:05 AM, Christopher King wrote:

> let me try it
>
> On Thu, Jun 24, 2010 at 9:38 AM, Hugo Arts  wrote:
>
>> On Thu, Jun 24, 2010 at 3:13 PM, Christopher King 
>> wrote:
>> > i mean isn't handled
>> >
>>
>> When I said "guaranteed to run," I meant it. finally will *always* run
>> after your try clause, exceptions or not, handled or not.
>> And by manual, he means the python reference manual. He was quoting a
>> part covering the try statement:
>>
>> http://docs.python.org/reference/compound_stmts.html#the-try-statement
>>
>> Hugo
>>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Line wrapping in IDLE possible? Horizontal scroll bar?

2010-06-24 Thread Christopher King
well, if you use a backlash in the middle of a statement, you can continue
the statement on the next line like so.

>>> for \
i \
in \
('neat', 'ha') \
: \
print \
i

neat
ha
>>>
you can abuse it as much as you like [?]

On Thu, Jun 24, 2010 at 10:00 AM, Richard D. Moores wrote:

> I use IDLE v3.1.1 occasionally on Vista. There doesn't seem to be a
> way to configure it to wrap long lines (they do wrap in the IDLE
> shell). Or is there?
>
> Also, when there's an unwrapped long line that extends past the right
> edge of the window frame, the only way to see the line's tail is to
> place the caret on the line and use the right arrow key. Is there a
> way to get a horizontal scroll bar to appear?
>
> Thanks,
>
> Dick Moores
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
<<1B2.gif>>___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class questions

2010-06-26 Thread Christopher King
Well the application of defining ones own error is in a module. For example,
if I make a banking account module, I might define a WithdrawError if there
is a place where a error might occur. That way if client code tries to
withdraw too much, you can have a very descriptive error making it easier to
understand.

On Sat, Jun 26, 2010 at 8:17 AM, Payal wrote:

> Hi,
> Some questions about which I am a bit confused.
>
> 1. I know there is a difference between mro of classic and new style
> classes. but I do not get why we need the new mro, the old one is easy
> to predict and understand?
>
> 2. A friend of mine told me that in C++ abstract classes are classes
> which can not be instatiated. Is she right, do we have them in python,
> if yes can someone give a simple example?
>
> 3. In http://www.alan-g.me.uk/tutor/index.htm , Alan has given an
> example in "User Defined Exceptions",
> >>> class BrokenError(Exception): pass
>
> Even after reading the section a few times over, I fail to get utility
> of such a class. Can someone please explain with better example?
> Alan can you please cleanup that section, maybe make it broader and put
> the stuff about "SystemExit" elsewhere.
>
> Thanks a lot in advance.
>
> With warm regards,
> -Payal
> --
>
>
> ___
> 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] class questions

2010-06-26 Thread Christopher King
only new classes can have properties, a major tool

On Sat, Jun 26, 2010 at 8:17 AM, Payal wrote:

> Hi,
> Some questions about which I am a bit confused.
>
> 1. I know there is a difference between mro of classic and new style
> classes. but I do not get why we need the new mro, the old one is easy
> to predict and understand?
>
> 2. A friend of mine told me that in C++ abstract classes are classes
> which can not be instatiated. Is she right, do we have them in python,
> if yes can someone give a simple example?
>
> 3. In http://www.alan-g.me.uk/tutor/index.htm , Alan has given an
> example in "User Defined Exceptions",
> >>> class BrokenError(Exception): pass
>
> Even after reading the section a few times over, I fail to get utility
> of such a class. Can someone please explain with better example?
> Alan can you please cleanup that section, maybe make it broader and put
> the stuff about "SystemExit" elsewhere.
>
> Thanks a lot in advance.
>
> With warm regards,
> -Payal
> --
>
>
> ___
> 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] finally

2010-06-26 Thread Christopher King
sorry, my reply to all button goofed up

On Sat, Jun 26, 2010 at 7:43 PM, Steven D'Aprano wrote:

> Hi Christopher,
>
> Are you aware you have written directly to me instead of the tutor
> mailing list? It's normally considered rude to do so, unless your
> message truly is meant to be private.
>
>
> On Sun, 27 Jun 2010 09:24:22 am you wrote:
> > what about more complex cleanup code, like saving data or showing a
> > error message
> > how would the with statement coop with that
>
> Exactly the same as simple cleanup code. Just be careful not to rely on
> things which may not have happened inside the try block. E.g. this
> won't work:
>
> x = something()
> try:
>y = x - 8
>z = 100/y
> finally:
>write_data_file(x, y, z)
>
> This will fail if something() returns 8, because z won't be defined, and
> your cleanup block itself will raise a NameError exception.
>
>
> --
> Steven D'Aprano
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] socket

2010-06-26 Thread Christopher King
   I'm wondering how to allow one process to communicate with another
process. In other words, I want to connect two computers. I've looked up
socket but the explanations are too complex. I think I need a 2-way
conversation with a expert to understand it. Or even better, point me to a
easier module.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] differences between mmap and StringIO

2010-07-08 Thread Christopher King
Well, I would just use the builting function open. I think Nick said in the
beggining. Or, I would use the module I created. It's a file object, with
the property file_txt. Unlike the other modules which you have to use read
and write methods, I made a method which allows you to manulipulate like a
string. I didn't even add a appending feature, but doing file.file_txt +=
'bla', you can append. I can send it to you if you like.

On Wed, Jul 7, 2010 at 6:52 PM, Eduardo Vieira wrote:

> Hello, I'm getting confused about the usage of those 2 modules. Which
> should I use one to get/manipulate data from a text file?
>
> Regards,
>
> Eduardo
> www.express-sign-supply.com
> ___
> 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] Request for help learning the right way to deal with listsin lists

2010-07-15 Thread Christopher King
I will spilt it up and add comments.

Books =\ #Assign to Books
[Book('War & Peace", [3, 56, 88]), #The first is a Book named 'War & Peace'
Book("Huck Finn", [2, 5, 19])] #You use the book class twice in a row, one
for each book


On Thu, Jul 15, 2010 at 8:09 AM, Payal wrote:

> On Tue, Jul 13, 2010 at 08:35:45AM +0100, Alan Gauld wrote:
> > If the data gets more complex you could put the data into a class:
> >
> > class Book:
> >  def __init__(self, title, pages=[]):
> >  self.title = title
> >  self.pages = pages
> >
> > Books = [ Book('War & Peace", [3,56,88]),
> >   Book("Huck Finn", [2,5,19]) ]
>
> Can someone please explain the above 2 lines?
>
> > for book in Books:
> > print book.title, book.pages
>
> With warm regards,
> -Payal
> --
> ___
> 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] Mutable Properties

2010-09-09 Thread Christopher King
sorry, accidentally hit reply instead of reply to all

On Thu, Sep 9, 2010 at 8:42 AM, Steven D'Aprano  wrote:

> Please don't reply privately to me unless you mean to ask me something
> private or personal.
>
> If you send your reply to the tutor list, I'll respond there.
>
>
> Regards,
>
>
>
> --
> Steven D'Aprano
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Random list exercise

2010-09-09 Thread Christopher King
forgot to send it to the list

On Thu, Sep 9, 2010 at 9:58 PM, Christopher King wrote:

> you could try random.shuffle and save a lot of time, it takes a mutable
> sequence (like a list) and shuffles it
>
>
> On Thu, Sep 9, 2010 at 6:39 PM, lists  wrote:
>
>> >>> Several small and not so small points:
>> >>>
>> >>> 1. you assign wordslen each pass through your loop.  While it doesn't
>> >>> matter in a small loop, it wastes time on the order of the size of
>> your
>> >>> list.  Instead move wordslen = len(...  above your while loop.  Any
>> time you
>> >>> put code in a loop that doesn't change in each iteration, you should
>> move it
>> >>> out of the loop.
>> >>>
>> >>> 2. since you only use chosenword once in your loop, you could remove
>> >>> chosenword = words[index] line and replace chosenword in the
>> append(... with
>> >>> words[index]
>> >>>
>> >>> 3. your list doesn't contain any duplicate words.  Since  your program
>> is
>> >>> supposed to catch this, you should add a duplicate to see if it works.
>> >>> (No!)
>> >>>
>> >>> 4. I think your line del words[index] is supposed to help out with
>> item 3
>> >>> but it doesn't.  It just removes the word you just used selected.
>> >>>
>> >>> 5. And finally, I think you want to print
>> >>>
>> >>> Just minor points.  nice job -- getting there
>> >>> --
>> >>> Joel Goldstick
>>
>> This seems to work Joel,
>>
>> It removes the extraneous assignment of chosenword and gets rid of
>> duplicate entries from the word list.
>>
>> while words: #has entries in it
>>wordslen = len(words) #get the length of the list
>>index = random.randint(0, wordslen -1) #get a random index
>> if words[index] not in randwords: #as long as the word isn't
>> already in the new list
>>randwords.append(words[index]) #append the random word to a new
>> list
>> del words[index] #del the word from the old list
>> else:
>>del words[index] #remove the duplicate word from the source list
>> ___
>> 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] Facebook

2011-01-27 Thread Christopher King
Dear Tutors,
I'm using the Facebook API. How do you get an access token? The
documentations at http://developers.facebook.com/docs/api, but I
can't figure out an easy way to do it.

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


Re: [Tutor] Facebook

2011-01-27 Thread Christopher King
Well actually I got it working now. I used the library from
https://github.com/facebook/python-sdk/. It said you had to create an app,
which I didn't want to do. That is, to get the access token. An access token
is what gives me the right to look at peoples profile.

What I found, was an app already made, in which I can edit the html to
have it request any permission I want it to, and then give me the access
token for my own programs. Its let's you save the code in a permalink. He is
my code: http://fbrell.com/saved/6b455533f5f2c124cdc74a635d09cbd4. It will
not work by itself, so you must slightly edit it. Where it says, put
permissions here, type what permissions you want the token to
have, separated by commas, and click run code. Then click the button. A list
of request-able permissions are here:
http://developers.facebook.com/docs/authentication/permissions/. I've tested
it, and its cool. I posted to my wall from facebook!

On Thu, Jan 27, 2011 at 11:43 AM, Luke Paireepinart
wrote:

> And what have you tried? What libs are you using? Which part is confusing
> you?
>
> -
> Sent from a mobile device. Apologies for brevity and top-posting.
> -
>
> On Jan 27, 2011, at 9:08 AM, Christopher King  wrote:
>
> Dear Tutors,
> I'm using the Facebook API. How do you get an access token? The
> documentations at  <http://developers.facebook.com/docs/api>
> http://developers.facebook.com/docs/api, but I can't figure out an easy
> way to do it.
>
> Sincerely,
> Chris
>
> ___
> 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] Connection Error

2011-06-15 Thread Christopher King
I was playing around with socket. It raised a connection error when I tried
to connect a non-local client to a linux server. It timed out when I tried
to connect a Linux client to a Windows server.
I did succeed when I:
connected a Linux client to a local server
connected a Windows client to a local server and
connected a Android client to a Windows server

The client program I was using was Alert_Sender and Alert_Sender_mobile. The
server program I was using was Alert_Server. Alert_Recv is also a client,
but I plan to always be on the same machine as the Alert_Server. Server and
Client are modules I designed to greatly simplify the socket module (feel
free to download for you own use.)


Alert_Server.py
Description: Binary data


Alert_Recv.py
Description: Binary data


Alert_Sender.py
Description: Binary data


Alert_Sender_Mobile.py
Description: Binary data


server.pyc
Description: Binary data


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


Re: [Tutor] Communicating Between Programs Using Raw Inputs (con'd)

2011-06-20 Thread Christopher King
Well, that's a trick me and jake learned in a book to stop the program
from changing.

On Saturday, June 18, 2011, aditya  wrote:
>
>
> On Sat, Jun 18, 2011 at 9:35 PM, Jacob Bender  wrote:
>
> Dear Tutors,
>
> Alright, I'm using linux (ubuntu) and I took all of your advice and I got 
> something that works and doesn't work at the same time. Here's the source 
> code for my two programs called Lock and Key:
>
> Lock.py:
>
> password = "a"
>
>
> psswd_try = raw_input("What's the password? ")
>
>
> if psswd_try == password:
>
>     print "correct!!!"
>
>     raw_input()
>
> else:
>
>     print "wrong"
>
>     raw_input()
>
> Why do you need to call raw_input() again?  You are giving the input only 
> once so remove raw_input() from both if and else , that should do the work
>
>  Key.py:
>
> import sys
>
>
> sys.stdout.write("a")
>
> In the linux terminal I ran this command(they were both in my home folder, so 
> no directories were needed):
>
> python Key.py | python Lock.py
>
> And all went well except for an EOF error caused by the raw_input inside the 
> "if" statement in my Lock program. However I did get it to print "correct", 
> so I know sys.stdout.write() works for what I want it to, but I don't want 
> the EOF error. Here's the output:
>
> Traceback (most recent call last):
>   File "Lock.py", line 7, in 
>     raw_input()
> EOFError: EOF when reading a line
>
> Please help me get rid of it because I couldn't find a sys.stdout.close() 
> command or any other std command that would help.
>
> Thanks!
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
> --
> RegardsAditya
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Main Function

2011-06-20 Thread Christopher King
Looks all good except for this:
while guess == the_number:
Since you break out at the end, an if statement would be a more logical
choice.
and also:
if tries == 4:
   print("\nYou fail!")
   input("\n\nPress the enter key to exit.")
   break
you don't need to break because the condition already requires the tries to
be under 4, so you don't need both the break statement and the tries < 4.

Something else you could do is instead of
# start the program
main()
input("\n\nPress the enter key to quit.")
you could do
if __name__ == __main__:
  # start the program
  main()
  input("\n\nPress the enter key to quit.")
which means that if its used as a module (say, you want the number chooser
thing)
it won't run the game

also, I liked the print("\nYou fail!")
very nice

On Fri, Jun 17, 2011 at 11:21 PM, Vincent Balmori
wrote:

>
> I answered another question that says "Modify the guess_number program so
> that the program's code is in a function called main(). Don't forget to
> call
> main() so you can play the game." It seems to be working fine, but I would
> like to have a second opinion if there was a better way to put it together.
>
> # Guess My Number
> #
> # The computer picks a random number between 1 and 10
> # The player tries to guess it and the computer lets
> # the player know if the guess is too high, too low
> # or right on the money
>
> import random
>
> def display_instruct():
>print("\tWelcome to 'Guess My Number'!")
>print("\nI'm thinking of a number between 1 and 10.")
>print("Try to guess it in as few attempts as possible.\n")
>
> # set ask_number function
> def ask_number(question, low, high, step = 1):
>"""Ask for a number within a range."""
>response =  None
>while response not in range(low, high, step):
>response = int(input(question))
>return response
>
> # guessing loop
> def num():
># set the initial values
>the_number = random.randint(1, 10)
>tries = 0
>guess = None
>while guess != the_number and tries < 4:
>guess = ask_number("Take a guess:", 1, 10)
>if guess > the_number:
>print("Lower...")
>else:
>print("Higher...")
>tries += 1
>
>if tries == 4:
>print("\nYou fail!")
>input("\n\nPress the enter key to exit.")
>break
>
>while guess == the_number:
>print("\nYou guessed it!  The number was", the_number)
>print("And it only took you", tries, "tries!\n")
>input("\n\nPress the enter key to exit.")
>break
>
> def main():
>display_instruct()
>num()
>
> # start the program
> main()
> input("\n\nPress the enter key to quit.")
> --
> View this message in context:
> http://old.nabble.com/Main-Function-tp31873480p31873480.html
> Sent from the Python - tutor mailing list archive at Nabble.com.
>
> ___
> 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] nitinchandra rubbish on list

2011-06-20 Thread Christopher King
wait a minute, I clicked the link but didn't submit my info,
does that mean my email will start corrupting the list now?

On Mon, Jun 20, 2011 at 2:31 AM, nitin chandra wrote:

> Thank you.
>
> Nitin
>
> On Mon, Jun 20, 2011 at 5:17 AM, Steven D'Aprano 
> wrote:
> > nitin chandra wrote:
> >>
> >> Hello All,
> >>
> >> MY Sincerest APOLOGIES i had joined a a mail box management
> >> services...
> >> But unfortunately It started interfering with my Gmail mail box.
> >
> > Thanks for fixing this!
> >
> >
> >
> > --
> > Steven
> >
> > ___
> > 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


Re: [Tutor] Communicating Between Programs Using Raw Inputs (con'd)

2011-06-20 Thread Christopher King
Also, we tried removing the raw input, but it wouldn't print correct

On Sat, Jun 18, 2011 at 9:55 PM, aditya  wrote:

>
>
> On Sat, Jun 18, 2011 at 9:35 PM, Jacob Bender wrote:
>
>> Dear Tutors,
>>
>> Alright, I'm using linux (ubuntu) and I took all of your advice and I got
>> something that works and doesn't work at the same time. Here's the source
>> code for my two programs called Lock and Key:
>>
>> *Lock.py: *
>>
>> password = "a"
>>
>> psswd_try = raw_input("What's the password? ")
>>
>> if psswd_try == password:
>> print "correct!!!"
>> raw_input()
>> else:
>> print "wrong"
>> raw_input()
>> *
>> *
>
> Why do you need to call raw_input() again?  You are giving the input only
> once so remove raw_input() from both if and else , that should do the work
>
>
>
>> *Key.py*:
>>
>> import sys
>>
>> sys.stdout.write("a")
>>
>> In the linux terminal I ran this command(they were both in my home folder,
>> so no directories were needed):
>>
>> python Key.py | python Lock.py
>>
>> And all went well except for an EOF error caused by the raw_input inside
>> the "if" statement in my Lock program. However I did get it to print
>> "correct", so I know sys.stdout.write() works for what I want it to, but I
>> don't want the EOF error. Here's the output:
>>
>> Traceback (most recent call last):
>>   File "Lock.py", line 7, in 
>> raw_input()
>> EOFError: EOF when reading a line
>>
>> Please help me get rid of it because I couldn't find a sys.stdout.close()
>> command or any other std command that would help.
>>
>> Thanks!
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> --
> Regards
> Aditya
>
>
> ___
> 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] Using class methods

2011-06-21 Thread Christopher King
Well it depends what you mean. If you have a critter object and want
to invoke its method inside the farm, do somethinh like this.
class Farm_class(object):
  def feed(self, critter):
critter.eat(self.food)

or if you want to use a method of the Critter class within the farm do

class Farm_class(object):
  def count(self):
print Critter_class.count()

On Tuesday, June 21, 2011, Andre Engels  wrote:
> On Tue, Jun 21, 2011 at 10:12 AM, David Merrick  wrote:
>> I need help using Class methods in another class. I have a class called
>> Critter and I want to create two critters in a farm  Class Farm and use
>> Class Critter's methods
>
> Could you please specify where your current code does not suffice -
> where does it something different than you want, or where do you want
> to do something (and why) that you don't know how to do?
>
> --
> André Engels, andreeng...@gmail.com
> ___
> 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] Trivia

2011-06-30 Thread Christopher King
Just some programming philosophy.

On Fri, Jun 24, 2011 at 3:58 AM, Vincent Balmori
wrote:

>
> "Your whole approach is very fragile in this respect, it only
> takes one small mistake in the data to wreck your program,.
> Somethjing like a config file format would be much more
> robust (and readable) the config reader module would make
> sure you got what you expected back. "
>
> Can you please explain more on what you mean by this?
>
>
> Alan Gauld wrote:
> >
> >
> > "Vincent Balmori"  wrote
> >
> >> It's working fine now with the scoring, but now at the end of the
> >> program
> >> for some reason I get this error message:
> >>
> >
> "/Users/vincentbalmori/Desktop/Python/py3e_source/chapter07/trivia_challenge2.py",
> >> line 27, in next_block
> >>point = int(next_line(the_file))
> >> ValueError: invalid literal for int() with base 10: ''
> >
> > Thats because after the last question you try to read another
> > block and don't check anywhere whether you actually read
> > anything. Your next_block code just assumes there will
> > always be valid data there, but at the end of the file there
> > won't be. You get away with category being blank
> > because replace() doesn't complain. But int() does.
> >
> > Your whole approach is very fragile in this respect, it only
> > takes one small mistake in the data to wreck your program,.
> > Somethjing like a config file format would be much more
> > robust (and readable) the config reader module would make
> > sure you got what you expected back.
> >
> > HTH,
> >
> >
> > --
> > Alan Gauld
> > Author of the Learn to Program web site
> > http://www.alan-g.me.uk/
> >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Trivia-tp31917610p31917979.html
> Sent from the Python - tutor mailing list archive at Nabble.com.
>
> ___
> 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] decorators

2011-06-30 Thread Christopher King
It would be cool if their where decorators that modified decorators. I know
its possible, but I can't think of a use.

On Thu, Jun 23, 2011 at 11:05 PM, Steven D'Aprano wrote:

> Robert wrote:
>
>> Is there a good tutorial out there somewhere about decorators? Google
>> doesn't bring up much.
>>
>>
>
> Define "good" :)
>
> I'm interested in what you think about this article:
>
> http://www.artima.com/weblogs/**viewpost.jsp?thread=240808
>
> Personally, I think it's filled with jargon that will be alien to most
> Python coders, but otherwise interesting.
>
> Here's my cheap introduction to decorators...
>
> Before you understand decorators, you have to understand two things about
> Python:
>
> (1) Functions are "first class objects";
>
> (2) and therefore you can write "factory functions".
>
> Everything else is just a bonus.
>
> What I mean by "first class" is best explained by giving an example of the
> opposite, second class objects. In some languages, functions are "special",
> and by special I mean they are more restricted. You cannot (easily, or at
> all) pass a function as an argument to another function, or give it a new
> name. This makes a lot of code hard to write. For instance, you might want
> to create a Grapher application, that lets the user draw the graph of some
> function. The basic algorithm would be something like this:
>
> def grapher(function, low, high, step):
>for x in range(low, high, step):
>y = function(x)
>draw_pixel(x, y)  # draw a pixel on the graph, somehow...
>
> This is easy in Python, but very hard in languages where functions are
> second class. Because they are second class, you cannot pass them as
> arguments:
>
> grapher(math.sin, 0, 100, 1)
>
> is not allowed in some languages, but is allowed in Python.
>
> One consequence of this is the idea of "factory functions" is allowed. You
> can write a function which builds new functions, and returns them:
>
> >>> def factory(x):
> ... def inner(arg):
> ... return arg + x
> ... return inner  # return the function object itself
> ...
> >>> plusone = factory(1)
> >>> plustwo = factory(2)
> >>>
> >>> plusone(23)
> 24
>
>
> Decorators are a special type of factory function. They take as their
> argument a function, and then modify, wrap, or replace the function to
> perform special processing. Because the decorator itself is a function,
> anything you can do in Python, you can do in a decorator. The only
> limitation is that it must take a single argument, expected to be a
> function. (Or a class, in newer versions of Python.) Everything else is up
> to you!
>
> "Decorator syntax" is the special syntax you often see:
>
> @decorator
> def spam():
>pass
>
>
> is syntactic sugar for the longer version:
>
> def spam():
>pass
>
> spam = decorator(spam)
>
>
>
> What are decorators good for?
>
> The most common use is to *wrap* the function so as to eliminate
> boilerplate code.
>
> Suppose you have a bunch of functions that look like this:
>
>
> def func(arg):
>if isinstance(arg, int) and arg > 0:
>arg = min(arg, 1000)
>do stuff
>else:
>raise ValueError('bad argument')
>
> def func2(arg):
>if isinstance(arg, int) and arg > 0:
>arg = min(arg, 1000)
>do different stuff
>else:
>raise ValueError('bad argument')
>
> def func3(arg):
>if isinstance(arg, int) and arg > 0:
>arg = min(arg, 1000)
>do something else
>else:
>raise ValueError('bad argument')
>
> All of the functions go through the same boilerplate at the beginning and
> end, testing for a valid argument, raising an error if not, adjusting the
> argument value... Only the "do stuff" parts are different. This is a lot of
> duplicated code. We can reduce the duplication, making it easier to maintain
> and test, by moving all the common code into one place:
>
>
> def test_argument(func):
>def inner(arg):
>if not (isinstance(arg, int) and arg > 0):
>raise ValueError('bad argument')
>arg = min(arg, 1000)
>return func(arg)
>return inner
>
>
> @test_argument
> def func(arg):
>do stuff
>
> @test_argument
> def func2(arg):
>do different stuff
>
> @test_argument
> def func3(arg):
>do something else again
>
>
> The common code (the boilerplate) is now inside the decorator. The
> decorator takes a function as an argument, wraps it with an inner function
> that calls the common boilerplate code, tests the argument, raises an error
> if needed, and returns the result of calling the unique "do stuff" part.
>
>
> --
> Steven
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsu

Re: [Tutor] Conceptual Question About Use of Python for Employee Training Program

2011-06-30 Thread Christopher King
What's step 4?

On Sat, Jun 25, 2011 at 10:08 AM, Mac Ryan  wrote:

> On Sat, 25 Jun 2011 06:18:14 -0700 (PDT)
> Adam Carr  wrote:
>
> > Good Morning:
> >
> > I am very new to Python but I am enjoying the learning process. I
> > have a question about the application of Python to a problem at the
> > industrial business where I work. My two main questions are:
> >
> > 1. Can Python be used to achieve the goals of the possible project?
> > 2. Where are the best places to look (books, blogs, websites, etc.)
> > for programming examples or modules that would help me begin to
> > assemble and test some code?
> >
> > We currently have a Windows-PC based safety training program that was
> > put together in MS Access around 2001
>
> 
>
> > Thanks in advance for taking the time to read my long note. I
> > appreciate any help or direction that can be offered.
>
> Hi Adam,
>
>from the way you describe your problem, to me the obvious
> answer would be "web application". This way you will be able to:
>
> 1. Make sure all employees will use the latest up-to-date training
>   material and software version.
>
> 2. Have a central DB able to track employees' activity (this opens up
>   the possibility for extra functionalities like sending a "gentle
>   reminder e-mail" to those who are not taking tests frequently
>   enough, statistics on what topics employees struggle most with,
>   etc...)
>
> 3. Be platform independent.
>
> 5. Save time on developing the GUI (which - done properly - is a very
>   time consuming part of desktop projects).
>
> That said, python is a great tool for web apps too. I personally looked
> a bit into Django (www.djangoproject.com), which is one of the python
> web frameworks and I was impressed by the speed you can prototype a
> fully working application.
>
> As for presenting the training material, for iteration #1 I would
> simply make them available as a download link. But in following
> iteration of the project I would also integrate them with the web (so
> as to make the entire application truly portable. I once used S5 for a
> project. Here you can see a presentation of it that is - coherentely -
> done with the standard presented:
> http://meyerweb.com/eric/tools/s5/s5-intro.html#slide1
> However an alternative I did not experiment with is XOXO, which I read
> has python code examples available (see
> http://microformats.org/wiki/xoxo-sample-code-python)
>
> HTH,
> Mac.
> ___
> 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-30 Thread Christopher King
dude, what are all those story comments, did you just edit the mad
lib program from Python for Absolute Beginners?

On Wed, Jun 29, 2011 at 12:28 AM, 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] Zipping files and Mysql

2011-06-30 Thread Christopher King
/myfiles/my_db/ needs to be a string
that right there is trying to divide nothing by the variable called myfiles,
divided by my_db, divide by nothing

On Mon, Jun 27, 2011 at 3:45 PM,  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)
> ___
> 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] The Card Game

2011-06-30 Thread Christopher King
I would go with __cmp__ which covers them all. 1 for greater, 0 for equal,
-1 for less than.

On Thu, Jun 30, 2011 at 5:35 AM, Alan Gauld wrote:

>
> "Vincent Balmori"  wrote
>
>> I keep getting a Type Error since for the moment since the
>> values of the cards cannot be compared due to their
>> types.
>>
>
> Please send the complete error text sincethat will tell us
> where to look etc.
>
>  I am thinking of creating a Card_Value class that will give each rank
>> and suit a certain value. If there is also a more elegant way of handling
>> some of the code in the main section that will be welcome.
>>
>
> You can get cards to compare themselves by adding a few
> more "magic methods". Then you can do stuff like
>
> if card1 < card2:
>   # 
> elif card2 > card1:
>   # 
> else:
>
> The methods you need to create are
> __gt__(), __lt__(), __eq__(), __le__(), __ge__()
>
> for
>
>  ,<,==,<=,>=
>>
>
> operations.
>
> BTW, In your code you have a comparison using = instead of ==.
> That will fail.
>
> HTH,
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> __**_
> 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] The Card Game

2011-07-01 Thread Christopher King
Sorry, I haven't upgraded to 3 yet.

On Thursday, June 30, 2011, Steven D'Aprano  wrote:
> Christopher King wrote:
>
> I would go with __cmp__ which covers them all. 1 for greater, 0 for equal,
> -1 for less than.
>
>
>
> So-called "rich comparisons" using __lt__, __gt__, etc. have been preferred 
> since Python 2.1. The major advantage of them is that they can be used for 
> more complicated data types, e.g. with sets where > means superset and < 
> means subset:
>
>
>>>> a = set([1, 2, 3, 4])
>>>> b = set([2, 3, 4, 5])
>>>>
>>>> a < b  # a is not a subset of b
> False
>>>> a > b  # neither is it a superset
> False
>>>> a == b  # and they're not equal either
> False
>>>> a & b  # but they do overlap:
> set([2, 3, 4])
>
>
>
> In Python 2.x, __cmp__ is only used as a fall-back if the rich comparisons 
> aren't defined. In Python 3.x, __cmp__ is gone: even if you define it, it 
> won't be used.
>
>
>
> ___
> 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] Algorithm for sequence matching

2011-07-03 Thread Christopher King
I know a way to do that
set1 = set(list1)
set2 = set(list2)
combined = set1&set2

On Sat, Jul 2, 2011 at 5:16 PM, Walter Prins  wrote:

> Hi Ankur,
>
> On 2 July 2011 21:30, ANKUR AGGARWAL  wrote:
>
>> Hey
>> I am looking for an algo for the largest sequence search in the two list.
>>
>> Example : list a accepts some say 'm' numbers. list b accept says 'n'
>> numbers. I want to look for the largest same sequence between the two list
>> and then display it. I tried out but failed to do so.
>> Say A=[11,23,45,21,63,56,78,32]
>> B=[56,78,11,23,45,21,111,234,56543]
>>
>> There are two  similar sequence matching over here [11,23] and [23,45,21]
>> i want to display second sequence because its larger in number. Plz help
>> Thanks in Advance :)
>>
>
> Umm, what about [11,23,45,21]?  That seems to be longer still so should be
> the best one to display, or?
>
> Walter
>
>
> ___
> 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] Program to Predict Chemical Properties and Reactions

2011-07-16 Thread Christopher King
Actually maybe not, depending on the complexity of the pattern, but it would
be difficult. You would have to know how much it decreases for every time
you go down or to the right.
If its more complex than that, you may have to program each rule in, not
just enter them in a prompt. I'm assuming none of the rules conflict,
because that would be a problem too.

On Sat, Jul 16, 2011 at 6:06 PM, Dave Angel  wrote:

> On 07/16/2011 05:32 PM, B G wrote:
>
>> Thanks, Emile-- although I'm not sure I was completely clear about my
>> objective. What I really meant is that is there a way (via machine
>> learning)
>> to give the computer a list of rules and exceptions, and then have it
>> predict based on these rules the ionization energy. Ultimately I'm pretty
>> interested in the idea of building a program that could predict the
>> expected
>> result of a chemical reaction, but that's a huge project, so I wanted to
>> start with something much, much, much smaller and easier.
>>
>> So I don't really want to manually input ionization energy, atomic radius
>> size, etc, since I'm not sure how much that would help towards the bigger
>> goal.  For this project, I already have the ~15 rules that describe trends
>> on the periodic table.  I want to write a program that, based on these
>> rules
>> (and the few exceptions to them), could predict the inputs that I want.
>>  Does this make sense?
>>
>>
>>  Neither ordering nor trends will give values for individual items.  So
> unless these rules are much more numerical than the clues you've mentioned
> so far, the problem is clearly impossible.
>
> But I suspect the problem is possible, and that you have much more
> information than you intend to tell us.
>
> --
>
> DaveA
>
>
> __**_
> 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] how to temporarily disable a function

2011-07-28 Thread Christopher King
On Thu, Jul 28, 2011 at 5:08 AM, Peter Otten <__pete...@web.de> wrote:

> Pete O'Connell wrote:
>
> > Hi I was wondering if there is a way to disable a function.
>
>
You could use this decorator:
class Disabler(object):
def __init__(self, old_function):
self.__old = old_function
self.enabled=True
def __call__(self, *arg, **kwd):
if enabled: return self.__old(*arg, **kwd)
def enable(self): self.enabled = True
def disable(self): self.enabled=False


> ___
> 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] Assigning range :p:

2011-07-28 Thread Christopher King
On Wed, Jul 27, 2011 at 9:11 PM, Thomas C. Hicks  wrote:

> On Wed, 27 Jul 2011 20:16:31 -0400
> Alexander Quest  wrote:

 x=range(1,50)
> mid=x[len(x)/2]
>
> You would have to make sure there is a way to work around decimal points in
the division. Also, I would try it in practice. (remember range(1, 50) does
not include 50.)

> ___
> 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] Mainloop conflict

2011-07-28 Thread Christopher King
Dear Tutor Dudes,
I have a socket Gui program. The only problem is that socket.recv waits
for a response, which totally screws Tkinter I think. I tried making the
timeout extremely small (it was alright if I didn't receive anything, I
was excepting that a lot) but I think that screwed socket. Anyone have words
of wisdom.

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


Re: [Tutor] Mainloop conflict

2011-07-29 Thread Christopher King
I was afraid of that.

On Thursday, July 28, 2011, Dave Angel  wrote:
> On 07/28/2011 08:32 PM, Christopher King wrote:
>>
>> Dear Tutor Dudes,
>> I have a socket Gui program. The only problem is that socket.recv
waits
>> for a response, which totally screws Tkinter I think. I tried making the
>> timeout extremely small (it was alright if I didn't receive anything, I
>> was excepting that a lot) but I think that screwed socket. Anyone have
words
>> of wisdom.
>>
>> Sincerely,
>> Me
>>
> Sure:
>
> Do the socket I/O on a separate thread.
>
> --
>
> DaveA
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Mainloop conflict

2011-07-30 Thread Christopher King
I think I'll go with threading. I've become more familiar with it.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Mailing list documentation

2011-07-31 Thread Christopher King
Wow wow, way is a ser...@might.co.za person doing a tutor response. And why
can I see it if it isn't to me.. I'm sorry Sergey if this
isn't something malicious, it just seems suspicious.

On Sun, Jul 31, 2011 at 3:30 PM, Sergey  wrote:

> On Sun, 31 Jul 2011 14:22:41 -0400 Alexander Etter 
> wrote
>
> > Hello everyone, is there a page that contains documentation for this
> mailing
> > list? I've seen a few users top post and others advise against it; if
> there
> > isn't a page listing conventions let's create it and if there is what is
> it's
> > URL and how do you suggest users read it?
> > Alexander
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
>
> ---
> tutor-requ...@python.org
> Fri, 29 Jul 2011 19:52:43 +0200(2 days, 1 hour ago)
>
> Welcome to the Tutor@python.org mailing list! This list is for folks
> who want to ask (and/or answer) questions from folks who wish to learn
> how to program with Python.  Feel free to ask even the most basic of
> questions -- that's what the list is for!
>
> For best results when asking a question on this list: - Try to write
> some code to solve your problem - Show the code you have written -
> Describe what the code does and what you want it to do - If the code
> generates an error, copy and paste the entire error message, including
> the traceback, into your email. - Tell us what OS and Python version
> you are using.
>
> - Don't ask us to do your homework. - Don't assume we know what you
> are talking about. If you are having trouble with a third-party
> library, include a link to the library home page.
>
> When replying to a posting: - Use Reply All to reply to the entire
> list - Don't top post - put your reply after the text to which you are
> replying
>
> For all posts: - Format your email as plain text, not HTML
>
>
> To post to this list, send your email to:
>
>  tutor@python.org
>
> General information about the mailing list is at:
>
>  http://mail.python.org/mailman/listinfo/tutor
>
> If you ever want to unsubscribe or change your options (eg, switch to
> or from digest mode, change your password, etc.), visit your
> subscription page at:
>
>  http://mail.python.org/mailman/options/tutor/***
>
> You can also make such adjustments via email by sending a message to:
>
>  tutor-requ...@python.org
>
> with the word `help' in the subject or body (don't include the
> quotes), and you will get back a message with instructions.
>
> You must know your password to change your options (including changing
> the password, itself) or to unsubscribe.  It is:
>
> ***
>
> Normally, Mailman will remind you of your python.org mailing list
> passwords once every month, although you can disable this if you
> prefer.  This reminder will also include instructions on how to
> unsubscribe or change your account options.  There is also a button on
> your options page that will email your current password to you.
>
>
> 
> South Africas premier free email service - www.webmail.co.za
>
> For super low premiums, click here http://www.dialdirect.co.za/?vdn=15828
>
>
> ___
> 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] Indexing a list with nested tuples

2011-08-05 Thread Christopher King
On Tue, Aug 2, 2011 at 10:44 PM, Alexander Quest wrote:
>
> have [0] to indicate that I want to go to the second value within that
> first item, which is the
> point value
>
Actually [0] is the first element. I would go with [1].
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Converting from a single module to a package

2011-08-05 Thread Christopher King
To make a package, you make a folder named what you want to name the
package, for example: virus_toolkit. Then you make a file in it called
__init__.py. This is what you import if you import the virus_toolkit. You
usually put documentation and general functions in this I believe (I'm not
100% sure on package etiquette.) Then you put various modules inside the
folder, such as brute force, worms, and Trojan_horse. Then you can do from
virus_toolkit import worms, and such, or if you want to unleash a full out
attack and import them all, do from virus_toolkit import *.

On Fri, Aug 5, 2011 at 3:25 PM, Tim Johnson  wrote:

> I'm been coding in python now for close to 10 years.  one of the
> modules that I have composed for re-use has gotten pretty big:
>
> It is implemented as
>
> import tlib as std
>
> I am thinking about 'downsizing' this module and breaking it up into
> smaller components, thus a package. And I would like to do this
> without a lot of code revisions.
>
> I would welcome references to URLs on this topic.
>
> thanks
> --
> Tim
> tim at johnsons-web dot com or akwebsoft dot com
> http://www.akwebsoft.com
> ___
> 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-ideas] multiple intro statements [was: combine for/with statement]

2011-08-05 Thread Christopher King
I give +0. I'm sure that it could come in use somewhere, as long as it isn't
used everywhere.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Python-ideas] Access to function objects

2011-08-06 Thread Christopher King
On Sat, Aug 6, 2011 at 4:10 AM, David Townshend wrote:
>
> def counter(add) as func:
> if not hasattr(func, 'count'):
> func.count = 0
> func.count += 1
> print(func.count)
>
You already can do that without an as statment.

>>> def counter(add):
if not hasattr(counter, 'count'):
counter.count = 0
counter.count += 1
return counter.count
>>> counter('You ever notice how this parameter is never used anyway?')
Output: 1
>>> counter('Oh well')
Output: 2
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using type

2011-08-12 Thread Christopher King
>
>   try:
>  iter(item)  # test for iterability
>  if len(item) == 1 and item == item[0]:
>  gut.append(item)
>  else:
>  gut = gut + flatten(item)
>
>   except TypeError:
>  gut.append(item)
>
I wouldn't put the what you want to do if there is no error in the
try statement. It makes it appear like your checking for an error in all the
code. I would do.

  try:
 iter(item)  # test for iterability
  except TypeError:
 gut.append(item)
  else:
 if len(item) == 1 and item == item[0]: ##By the way, why do you
have this if statment
 gut.append(item)
 else:
 gut = gut + flatten(item)

Oh ya out of curiosity, what is the flatten func for?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Speech

2011-08-23 Thread Christopher King
Hello Tutors,
I need help with text to speech and or speech to text. I know of two
packages, but they require win32, which I can't get to work. The Win32
package was filled with pyd's and no py's..Could some one tell me how to get
win32 to work or a package that doesn't use it.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] eval func with floating...

2011-08-23 Thread Christopher King
> if c:
> print *eval("float(%s)"%a)*
> else:
> print "error! please use -defined operators-!"
>
I would use a assert statement for more readability, like so.
*try: assert c*
*except AssertionError: print "error! please use -defined operators-!"*
else: *print *eval("float(%s)"%a)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Speech

2011-08-23 Thread Christopher King
Sorry, forgot to hit reply all.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] eval func with floating...

2011-08-23 Thread Christopher King
>
> If the user ever sees an AssertionError, your code is buggy.
>
Well you saw that I caught the AssertionError, so the user
wouldn't technically see it. For the other stuff, I didn't know
the etiquette for assertion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] eval func with floating...

2011-08-24 Thread Christopher King
>
> If the user ever sees an AssertionError, your code is buggy.
>
Well you saw that I caught the AssertionError, so the user
wouldn't technically see it. For the other stuff, I didn't know
the etiquette for assertion statements.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Speech

2011-08-24 Thread Christopher King
 how do you unzip a gz on windows?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Speech

2011-08-24 Thread Christopher King
On Tue, Aug 23, 2011 at 8:46 PM, Alex Hall  wrote:

> Depending on what you want, you could try accessible_output.

It requires platform_utils. Anything else?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Speech

2011-08-24 Thread Christopher King
I got the speech module to work actually, except for input. Only say works.
Here's a traceback on speech.input.
Traceback (most recent call last):
  File "C:\Python26\test.py", line 6, in 
print speech.input()
  File "C:\Python26\speech.py", line 162, in input
listener = listenforanything(response)
  File "C:\Python26\speech.py", line 193, in listenforanything
return _startlistening(None, callback)
  File "C:\Python26\speech.py", line 222, in _startlistening
context = _recognizer.CreateRecoContext()
  File
"C:\Python26\lib\site-packages\win32com\gen_py\C866CA3A-32F7-11D2-9602-00
C04F8EE628x0x5x0.py", line 2457, in CreateRecoContext
ret = self._oleobj_.InvokeTypes(10, LCID, 1, (9, 0), (),)
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0,
-214722
1164), None)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with if-elif-else structure

2011-08-25 Thread Christopher King
Looks good, although I would add one or two things.

> #assuming target number 15
>
Put that in a variable for the target number

> roll = (result, initial_mins, initial_max)
> if roll[0] > 15:
>if roll[1] >= 2:

You could even put all the constants in variables

>

   print("Success")
>elif roll[2] >= 2:
>print("Critical failure!")
>else:
>print("Failure.")
> elif roll[0] <= 15:
>if roll[1] >= 2:
>print("Critical success!")
>elif roll[2] >= 2:
>print("Failure")
>else:
>print("Success")
>
Also need a couple comments, plus everything from the other emails.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Speech

2011-08-25 Thread Christopher King
It wasn't on the repo.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quote of the Day version 1.0

2011-09-01 Thread Christopher King
I would use a tuple of dictionaries.
import random

quotes = (
   {'author':"Kahlil Gibran", 'quote':"A candle loses nothing of its light
when
lighting another."), #My favorite
   {'author':"Henrik Ibsen", 'quote':"The strongest man in the world is he
who stands
most alone."})

quote = random.choice(quotes)
print "{quote}\n\tBy {author}".format(**quote)

I use the dictionaries, because your not just storing a list of strings,
your storing two strings of different purposes. I store the dictionaries in
a tuple, because they are all quotes, but they currently never change during
the course of the program. Some quotes have been omitted due to my laziness.
I have not tested or debugged this code(I had to leave you something to do.)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Python-ideas] aliasing

2011-09-01 Thread Christopher King
>
> 
> >>> list = [3,]
> >>> a = list
> >>> list[0] = 6
> >>> a[0]
> 3
> -
>
Slight error in my code. It should be.

>>> list = [3,]
>>> a = list
>>> list[0] = 6
>>> a[0]
6
-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Python-ideas] Terminology for "earthshattering" [was: Add from __experimental__ import bla]

2011-09-02 Thread Christopher King
How about double dot, dot, and no dot releases, (for the number of decimals
in it.) I do believe having terminology for this would be good and cool. *+
0.5*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Python-ideas] Terminology for "earthshattering" [was: Add from __experimental__ import bla]

2011-09-02 Thread Christopher King
What about alpha-omega release, since its the end of many old programs,
the beginning of many new, and it just sounds awesome.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] iretator.send

2011-09-19 Thread Christopher King
Dear tutor dudes,
I know that a for loop uses a an iterators next method in this way

for variable in iterator:
execute_code(variable)

is equivalent to

while True:
try:
variable = iterator.next()
except StopIteration:
break
else:
execute_code(variable)

Is there any syntax that uses the send method of an iterator?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] String switch

2011-10-02 Thread Christopher King
Dear Tutors,
I was wondering how one would make it so all the cases of all the
strings in a python file where switched. I know that for individual strings,
you can use .swapcase(), but I'm making a program to edit others, so it
would be easier to just do something at the top that would switch all other
strings. Thank you in advance.

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


Re: [Tutor] String switch

2011-10-05 Thread Christopher King
There is a program that will open another program, write code at the top of
the program. The code at the top will cause the program to print all strings
afterwards in swap case.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] String switch

2011-10-08 Thread Christopher King
Okay, here's what I what to do
*--Target.py--*
print "Hello World"
*--Target.py Output--*
*Hello World*
*--Main.py--*
target=open("target.py", "r")
old=target.read()
target.close()
target=open("target.py", "w")
target.write('''
Str.__repr__ = Str.__repr__.swapcase()'''+old)
target.close()
*--Modified Target.py--*
Str.__repr__ = Str.__repr__.swapcase()
print "Hello World"
*--Modified Target.py Output--*
*hELLO wORLD*

The only problem is I don't think that "Str.__repr__ =
Str.__repr__.swapcase()" works. What should I use in its place to make the
above a reality.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] String switch

2011-10-09 Thread Christopher King
I know the method of finding every string, and inserting a swapcase in to
the code. Does anyone now a way just to insert code at the top though?

P.S. I use python 2.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] String switch

2011-10-10 Thread Christopher King
Okay, there is a python file called target.py. In the same directory there
is a file named main.py. You are the author of main.py. The code in main.py
will write to target.py. Then the antivirus catches main.py and removes, but
not the modification to target.py. Main.py can not create new files. What
would Main.py have to write to target.py, so that its output is swapped
case. It does not matter how this is achieved. I know that one way is to do
a regex search for every string in the file and then write the text of the
file, with swapcases after strings, back to the file. What is a more elegant
way for this to be achieved.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Socket not connecting

2011-10-19 Thread Christopher King
>
> (I might try increasing the listen value to say 3 or 5 but it shouldn't
> really be necessary)

What exactly is the listen value (by the way, I'm jake's friend he was
talking about.)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Quacks like an object

2011-10-24 Thread Christopher King
Dear Tutors,
I am trying to make an object, which will appear exactly like an object
of my choice. It will should be impossible to tell it is not the object.
This is because I am making an object that modifies it methods so that if
the methods make a change to the object, it will sync those changes to a
file, but I don't want it to be another object, so foreign functions will
not mistake for not being the object. For example
if, I used type on the object, it should return the class of the object it
is trying to mimic. I have tried everything from modifying the object's get
set attribute methods, to having making a new object that has get and set
the same as the object except with a filter for methods, but I had no luck.
In a nutshell, I want an object that walks like another object, quacks like
another object, and basically is another object. Is this possible?

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


Re: [Tutor] Quacks like an object

2011-11-22 Thread Christopher King
>
> You want to persist data changes to a file? Thats easy enough.

Yes, but I want it built in to the objects built in methods like for
example doing
*listquacker[3]="This string needs to be updated immediately**."*
Should write the new data to a file. It should also work for all data
types, not just list.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Physics Engine

2011-11-22 Thread Christopher King
Does anyone know a good physics engine that works with livewires, or a
good reference on how to build 2-D physic engines (preferably the former.)
It needs to work well with rope objects.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Physics Engine

2011-11-23 Thread Christopher King
I'm more of a beginner, so it would be nice for it to work with Livewires.
It doesn't need to be that complex (no need for air pressure, elasticity,
or energy.) I just need enough that I will stay on the ground and that when
I swing sprites around on a rope, they swing in a circle, not a square. A
good reference for making one would  be good to.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor