Re: [Tutor] Simple Tkinter question (fwd)

2005-10-07 Thread Danny Yoo


-- Forwarded message --
Date: Thu, 6 Oct 2005 23:55:26 -0700 (PDT)
From: Mike Cheponis <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Simple Tkinter question

Danny, I got it:


from Tkinter import *
from time import *

def my_update():
   for i in range(3):
 tv.set("Now it's %d"%i)
 root.update()
 sleep(1)

root=Tk()
tv=StringVar()
Entry(textvariable=tv).pack()
tv.set("Initial Value of StringVar")
Button(text="Update", command=my_update).pack()
root.mainloop()



Trick is call to update() - which I found by looking at a few pages before the 
one your URL pointed me to, so THANKS!!! again.

Detail is here:   
http://www.pythonware.com/library/tkinter/introduction/x9374-event-processing.htm

-Mike

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


Re: [Tutor] Tutor Digest, Vol 20, Issue 22

2005-10-07 Thread Danny Yoo


On Thu, 6 Oct 2005, sanjay sinha wrote:

> Is there any work done in language convirsion from endlish to hindi and
> vice versa

Hi Sanjay,


Machine Translation (MT) is Hard.  I believe you're asking for some kind
of automatic language translator, and I'm sure there is work being done,
but it's an active research topic.  If you are here because of the NTLK
toolkit:

http://nltk.sourceforge.net/

please be aware that just because something is written in Python doesn't
meant that folks on Tutor know all about it.  *grin*


We can try to help you understand how to program in Python, but that's
pretty much it.  For anything more specific than that, you have to be more
targetted toward the people you talk to.  See:

http://www.catb.org/~esr/faqs/smart-questions.html

We here at Python-tutor can't give you much insight on Machine
Translation, especially since your question really doesn't seem much
related to Python or learning Python.  Basically, you are posting on the
wrong forum.  Instead, try your favorite search engine on something like
"statistical natural language processing" systems, and you should be able
to find useful resources.  For example, the GATE project:

http://www.gate.ac.uk/

might be useful, as their page talks about integrating with many different
languages including Hindi.  But other than that, we can not help you: we
really do not have expertise in this area.

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


Re: [Tutor] Simple Tkinter question (fwd)

2005-10-07 Thread Danny Yoo
> Danny, I got it:
>
> from Tkinter import *
> from time import *
>
> def my_update():
>for i in range(3):
>  tv.set("Now it's %d"%i)
>  root.update()
>  sleep(1)
>
> root=Tk()
> tv=StringVar()
> Entry(textvariable=tv).pack()
> tv.set("Initial Value of StringVar")
> Button(text="Update", command=my_update).pack()
> root.mainloop()
>
> Trick is call to update() - which I found by looking at a few pages
> before the one your URL pointed me to, so THANKS!!! again.

Hi Mike,

Ok, that works too.  Another variation on your approach is the
update_idletasks() method, which like update() should handle all the
graphic-updating commands that are queued up for the GUI.  There's a
little more in:

http://effbot.org/zone/tkinter-performance.htm
http://mail.python.org/pipermail/tkinter-discuss/2005-June/000464.html

that talks about what kind of GUI tasks are considered "idle", and when
you might want to call update() or update_idletasks().


The issue with update() is that while the program is sleeping, GUI
interaction, like button presses, will be ineffective, since we're still
not relinquishing control back to the GUI.

This may or may not be a problem for you.  You've probably seen programs
in the real world whose GUIs lag and drag when they do a lot of work.  If
that kind of program behavior annoys you, then you'll probably want to
search for another solution in your own programs.  *grin*

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


Re: [Tutor] Simple Tkinter question

2005-10-07 Thread Alan Gauld
> def my_update():
>   for i in range(3):
> tv.set("Now it's %d"%i)
> sleep(1)
>
> Button(text="Update", command=my_update).pack()
> root.mainloop()
>
>
> What happens when I hit the Update button is a 3-second pause, then "Now 
> it's 2" is displayed.

This is a common gotcha in GUI programming.

The function executes but the GUI doesn't redraw itself on the screen until 
the
function completes. Normally there is a GUI  function you can call to force
a redraw (or repaint or refresh) of the screeen before each sleep which
should fix this. Unfortunately I can't see one for Tkinter.

Another approach is to use a timer which creates its own events and catch
them in your original function rather than using a loop, thus you change the 
value
in the field and create a one second timer calling yourself, repeat the 
process
until the value is where you want and stop creating timers!

Finally you can bypass the timer by sending an event to yourself which is 
also
associated with your callback, so after each sleep you post an event.

But the simplest solution if you can find the function is to simply force a
redraw after each loop iteration.

There is a downside to this approach which may be why Tkinter doesn't
appear to support it - if your function had a long loop the user would lose
control of the application while the metod executed - you effctively make
the app modal, which is "A Bad Thing". Thats why GUI purists prefer the
timer/event techniques described above.

HTH

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


Re: [Tutor] Simple Tkinter question (fwd)

2005-10-07 Thread Alan Gauld
>> The problem is that the GUI needs control back to be able to update the
>> GUI display.
>
> Thanks, but what I don't understand is:
>
> Why doesn't the call tv.set("string") update what's on the screen. 
> Clearly,
> Tkinter has control at that point, and there's no reason to delay updating 
> the screen,
> is there?

The way most GUIs work is that the display is held in a buffer in memory.
The buffer gets updated by commands then between events the GUI reftreshes
the display. In most cases this results in smoother operation with less 
flicker
on the screen. Unfortunately when a method wants to do lots of updates to
the same field the intermediate values are lost so you need some way of
allowing the refresh to take place.

> I have a bunch of lines selected on the screen.  I'm using Pmw.  This 
> returned
> tuple has a number of items I need to play.  While the sound is playing, I 
> want
> to display the name of the sound on the GUI.  (The playing is done by a 
> routine
> that writes to the serial port - that is, I call a function with the 
> filename of
> the sound, and it plays it).

The best approach to anything in GUI programming(and in real-time work
of any sort!) is to propcess things one at a time, avoiding loops of any 
kind.
When you have multiple items to process create an event for each
subsequent action and allow the event loop to act as your loop.
Thats what the after() function does (Thanks Danny I hadn't seen that one!).

HTH,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


Re: [Tutor] [Fwd: Re: Consistant Overhead Byte Stuffing (COBS)algorithm help]

2005-10-07 Thread Kent Johnson
Michael Cotherman wrote:
>>... is the decoding code, it does what you
>>describe below. It is adding the zeros back in, that
>>is the dst.append('\0')
>>
>>Kent
> 
> Really??? I am a noob, but it looks like it only puts
> a \0 at the end if code (the length) is less than 255,
> as the if statement is out of the for loop? this would
> be part of the coding algorithm, no?

It puts 0 at the end of each segment if the length of the segment is less than 
FF. In the original C code, the for loop is copying the data of a segment. The 
while loop in both codes is looping over segments.

Here is my understanding of the algorithm (with maybe a few fine details left 
out):
To encode:
- look for the first 0 byte in the data
- if it is more than FE bytes from the start, write out and FF and the first FE 
bytes. This is a segment that *doesn't* end with a 0.
- otherwise write out (1+the number of bytes before the 0), then all the bytes 
before the zero. Skip the input pointer to the byte after the 0.
- repeat until no more data

To decode:
- get the next byte from the data. This is the count
- get the next (count-1) bytes from the data and append to the output
- if count < FF then this segment ends with a 0, so append a 0 to the output.
- repeat until no more data

Oh, I see you already wrote the same thing in your previous email!

Kent

> 
> In that theme of writing, here is what I would  do to
> make it decode:
> 
> 
> def UnStuffData(src,dst,len):
>if code == 0xFF:
>   pass
>else:
>   x = src(0)   
>   for code in src:
>  for i in range(1,code):
>  if i == x:   
>  dst.append('\0')  
>  x = src(i)
>  else:
>  dst.append(i)
> 
>dst.pop(0)  #remove first byte
> #  if code < 0xff
> #  dst.append('\0') 
> 
> 
> 
> 
> -mike
> 
> 
> 
> --- Kent Johnson <[EMAIL PROTECTED]> wrote:
> 
> 
>>Michael Cotherman wrote:
>>
>>>def UnStuffData(src,dst,len):
>>>
>>>   for code in src:
>>>  for i in range(1,code):
>>>  dst.append(i)
>>>
>>>  if code < 0xff
>>>  dst.append('\0') 
>>>
>>>the above is the below code uncommented...
>>> it(and the original code) just seem to find the
>>
>>end
>>
>>>and puts a zero there...
>>>
>>>I do not see the existing zeroes replaced.
>>
>>this is
>>
>>>kinda why I wanted to start from the
>>
>>specification...
>>
>>The above is the decoding code, it does what you
>>describe below. It is adding the zeros back in, that
>>is the dst.append('\0')
>>
>>Kent
>>
>>
>>>decoding is:
>>>pop the first byte of the packet off and place
>>>subsequent bytes into the output until you get to
>>
>>the
>>
>>>byte pointed to by the popped byte. When you reach
>>>that byte, read its value as the new 'relative'
>>>pointer, and copy x00 to the output. Proceed as
>>
>>above,
>>
>>>placing bytes to the output until the relative
>>
>>pointer
>>
>>>is reached or the end of the packet occurrs.
>>>
>>>I guess I need to look if I wish for this part of
>>
>>the
>>
>>>program to handle the input as one big existing
>>>string, or work on it a byte at a time as it comes
>>
>>in.
>>
>>> 
>>>
>>>-mike c
>>
>>___
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>>
> 
> 
> 
> 
>   
> __ 
> Yahoo! Mail - PC Magazine Editors' Choice 2005 
> http://mail.yahoo.com
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

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


Re: [Tutor] Making a character jump with pygame

2005-10-07 Thread Lee Harr
>  I've edited the aliens.py example to make my character just move
>back and forth. However I can't make him jump!


It is not really clear to me from your code where you expect the
character to jump. I do not see the word "jump" anywhere. I do
see the word "bounce" and one reference to the top of the image
so I will figure that is where you are working.

You have a .move method for your Player sprite:

def move(self, direction):
if direction: self.facing = direction
self.rect.move_ip(direction*self.speed, 0)
self.rect = self.rect.clamp(SCREENRECT)
if direction < 0:
self.image = self.images[0]
elif direction > 0:
self.image = self.images[1]
self.rect.top = self.origtop - (self.rect.left/self.bounce%2)


origtop is set to the original value of top when the sprite is
created, and bounce = 1 and never changes.

What are you hoping this code will do?

Just as an experiment (to test that changes to self.rect.top
will actually make the sprite move up) I changed

self.rect.top = self.origtop - (self.rect.left/self.bounce%2)
to
self.rect.top -= 1

You might want to look at that.


Help us to help you. Name something "jump" or put in some
comments about what you are expecting, and what is not
working.


>Here's my code (attached). I'm trying to make a platformer Mario style 
>game.

The other thing I notice is that in the controls section...

#handle player input
direction = keystate[K_RIGHT] - keystate[K_LEFT]
player.move(direction)

You handle K_LEFT and K_RIGHT but there is nothing to handle any
"jump" event. How does the user cause the Player to jump?

_
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

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


Re: [Tutor] Matching dictionary entries by partial key

2005-10-07 Thread Kent Johnson
Danny Yoo wrote:
> But as Kent mentioned, though, perhaps the easiest thing to implement is a
> simple linear scan across all your key-values, and not worry until we know
> this is a performance hotspot.  *grin* It really depends on how many
> entries we're searching against.

Another alternative is just a list of (key, value) pairs, that is easy to 
search with linear search. The only reason to keep a dict is if you are at some 
point doing a lookup by key. Without knowing more about your app I don't know 
if that is a requirement or not.

Kent

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


Re: [Tutor] Importing Modules Within Classes

2005-10-07 Thread Eric Walker
That was me using the import within the class. I only did it due to my 
ignorance. I am not advanced enough to use it like that and know what I am 
doing, so as suggested I just moved all of my imports to the top.

Python Newbie.
On Thursday 06 October 2005 08:21 pm, Kent Johnson wrote:
> Daniel Watkins wrote:
> > Recently, there has been an example of someone importing modules within
> > a class definition. eg:
> >
> > class Exemplar:
> >  import re
> >  ...use re...
> >
> > It seems obvious to me that this is incorrect, though more through
> > training than actual observation on my part, and it should be:
> >
> > import re
> >
> > class Exemplar:
> >  ...use re...
>
> It's not really incorrect, it is legal syntax and it will do what you
> expect. It is not idiomatic and in general it is simpler to just put all
> the imports at the top.
>
> > However, someone (I don't recall who) said that there were occasions
> > when it would be appropriate to import modules the former way. I was
> > just wondering under what circumstances importing should be done this
> > way?
>
> That was me. I nest imports quite frequently in Jython code where the first
> import of a module is fairly expensive in time. Putting the import in the
> function that needs it delays the import and perhaps the module won't be
> imported at all.
>
> import is an executable statement. When it runs, the interpreter first
> looks to see if the module has already been imported. If so, the existing
> module is bound to the import name in the current namespace. If the module
> has not yet been imported, it is loaded *and executed*, then bound to the
> name in the current namespace.
>
> So if module A imports B which imports C and D, then importing A will also
> load and execute B, C and D. If any of these are time-consuming you may
> want to defer them.
>
> I found with my Jython programs that I could shorten start-up time quite a
> bit by deferring some imports until they were needed.
>
> Another reason for the nested style of imports is to resolve problems with
> circular imports. There are some subtle problems that can occur when A
> imports B and B imports A. By nesting one of the imports you can defer it
> and sometimes avoid the problem. In this case I think removing the circular
> import is a much better solution - circular dependencies are evil!
>
> Kent
>
> > Cheers,
> > Dan
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Matching dictionary entries by partial key

2005-10-07 Thread William O'Higgins Witteman
On Thu, Oct 06, 2005 at 10:28:23PM -0400, Kent Johnson wrote:
>William O'Higgins Witteman wrote:
>> I'm trying to traverse a dictionary looking for partial matches of the
>> key, and I'm not sure how.  Here's a sample dictionary:
>> 
>> dict = {1234 : value1, 20051234 : value2, 20071234 : value3}
>> 
>> Here's what I'm trying to do:
>> 
>> for key in dict:
>> if key ==  or key == 2005:
>
>  if key.startswith('') or key.startswith('2005'):

This is perfect!  Where do I read about things like this?  I've been
spending a bunch of time with the python.org documentation, "A Byte of
Python" and "Dive Into Python", but I didn't run across this.

>or with a regular expresion:
>  if re.match('|2005', key):

This is good too, and it shows me the syntax (which I had trouble with).

>> do something with dict[key]
>> 
>> The challenge is that I only care about the first four digits of the key
>> for the purpose of this match - is there a way to express this?  I could
>> probably create a wrapper dictionary using just the first four digits of
>> the key as they key, and containing the original key:value pair as a
>> list within it, but that seems cumbersome.  Any one have a suggestion?
>
>If you have a *lot* of keys and need more speed, that might be a good 
>optimization. For a small dict, just use startswith().

Should I compile the regex to further increase the speed?

Thanks for the help.
-- 

yours,

William



signature.asc
Description: Digital signature
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Importing Modules Within Classes

2005-10-07 Thread Pierre Barbier de Reuille


Kent Johnson a écrit :
> Daniel Watkins wrote:
> 
>[...]
> 
>>However, someone (I don't recall who) said that there were occasions
>>when it would be appropriate to import modules the former way. I was
>>just wondering under what circumstances importing should be done this
>>way?
> 
> 
> That was me. I nest imports quite frequently in Jython code where the first 
> import of a module is fairly expensive in time. Putting the import in the 
> function that needs it delays the import and perhaps the module won't be 
> imported at all.
> 
> import is an executable statement. When it runs, the interpreter first looks 
> to see if the module has already been imported. If so, the existing module is 
> bound to the import name in the current namespace. If the module has not yet 
> been imported, it is loaded *and executed*, then bound to the name in the 
> current namespace.
> 
> So if module A imports B which imports C and D, then importing A will also 
> load and execute B, C and D. If any of these are time-consuming you may want 
> to defer them.
> 
> I found with my Jython programs that I could shorten start-up time quite a 
> bit by deferring some imports until they were needed.
> 
> Another reason for the nested style of imports is to resolve problems with 
> circular imports. There are some subtle problems that can occur when A 
> imports B and B imports A. By nesting one of the imports you can defer it and 
> sometimes avoid the problem. In this case I think removing the circular 
> import is a much better solution - circular dependencies are evil!
> 

A third reason is not to load module that will probably not be used :)
In my code, I have objects that have geometrical representations. My
objects can produce images of themselves using differente libraries.
Some are huge and takes time and memory to load ... also one specific
user will probably use only one such library at a time (and will
probably load it before ...) As each function run is quite time
consuming, adding the module check is not a problem also ! (never import
a module in a small function likely to be called in an inner-loop !)

Pierre

-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77fax   : (33) 4 67 61 56 68
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Is it Posible? To Crack And HowTo

2005-10-07 Thread Suranga Sarukkali



All this could look mostly like any of a question of a idiot! 
sorry for that. 
I've heard that Python is good for hacking and when I ask how 
to here on python tutor mailing list answers were all about reading some article 
I've already read before, it's not hacking I'm into now but a similar thing, 
Cracking and I've got lots of software by these we call proprietary software 
developers who are some greedy people having fun licensing software. Can I get 
help to this using python and if how to? or elif can't how to? else where can I 
get started and going?
 
Thanks for all other questions you've answered!
reply to me on [EMAIL PROTECTED] at your earliest 
convenience.
BEGIN:VCARD
VERSION:2.1
N:Sarukkali;Sampath;Suranga;Mrs
FN:Suranga Sarukkali
NICKNAME:sarukk
TEL;HOME;VOICE:0942610560
ADR;HOME:;;12B, 4th Cross Lane, Borupana Road,;Ratmalana,;WP,;10345;Sri Lanka
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:12B, 4th Cross Lane, Borupana Road,=0D=0ARatmalana,, WP, 10345=0D=0ASri Lank=
a
X-WAB-GENDER:2
BDAY:19891011
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
REV:20051007T092040Z
END:VCARD
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Matching dictionary entries by partial key

2005-10-07 Thread Kent Johnson
William O'Higgins Witteman wrote:
> On Thu, Oct 06, 2005 at 10:28:23PM -0400, Kent Johnson wrote:
>> if key.startswith('') or key.startswith('2005'):
> 
> 
> This is perfect!  Where do I read about things like this?  I've been
> spending a bunch of time with the python.org documentation, "A Byte of
> Python" and "Dive Into Python", but I didn't run across this.

Chapter 2 of the Python Library Reference is recommended reading. It documents 
all the builtin functions (e.g. int(), chr(), enumerate()...) and types (list, 
dict, str...). In particular section 2.3.6.1 documents string methods such as 
startswith(). It's worth browsing the table of contents, too - it gives a 
subject-oriented catalog of all the standard library modules.
http://docs.python.org/lib/builtin.html
http://docs.python.org/lib/string-methods.html

> Should I compile the regex to further increase the speed?

Yes, compile it outside the loop and use the compiled regex for the match:

import re
myRe = re.compile('|2005')
for key in dict:
  if myRe.match(key):

BTW dict is a bad name for a dict, it is the name of the actual dict class. In 
general you should avoid using the names of built-ins as variable names because 
your variable will shadow the builtin. It's particularly easy to make this 
mistake with the names 'list', 'dict' and 'file'.

Kent

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


Re: [Tutor] Is it Posible? To Crack And HowTo

2005-10-07 Thread Kent Johnson
Suranga Sarukkali wrote:
> All this could look mostly like any of a question of a idiot! sorry for 
> that.
> I've heard that Python is good for hacking and when I ask how to here on 
> python tutor mailing list answers were all about reading some article 
> I've already read before, it's not hacking I'm into now but a similar 
> thing, Cracking and I've got lots of software by these we call 
> proprietary software developers who are some greedy people having fun 
> licensing software. Can I get help to this using python and if how to? 
> or elif can't how to? else where can I get started and going?

No, you can't get help cracking proprietary software on this list. Many of us 
are professional software developers who make a living as "greedy people having 
fun licensing software".

Kent

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


Re: [Tutor] Importing Modules Within Classes

2005-10-07 Thread Kent Johnson
Pierre Barbier de Reuille wrote:
> (never import
> a module in a small function likely to be called in an inner-loop !)

That's good advice, but I would say "in a *time-critical* inner-loop". After 
the first import, importing a module is fast, it is just a few dictionary 
lookups (looking up the module in sys.modules) and a dictionary write (to the 
local namespace). It's only the first import that is potentially expensive.

Kent

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


Re: [Tutor] FW: Is it Posible? To Crack And HowTo

2005-10-07 Thread Daniel Watkins
> > I've already read before, it's not hacking I'm into now but a
> similar thing, Cracking
Hacking and cracking are two completely different things. Hacking is a
developer with some real talent actually making a contribution to
computing by writing something of use. Cracking is a jackass who's too
cheap to buy some proprietary software and/or too lazy/stupid to learn
how to do what he wants to do in OSS. With the utmost respect,
obviously.

However, I don't want to use up the list, so if you want to comment on
anything I just wrote, feel free to email me personally
([EMAIL PROTECTED] as opposed to tutor@python.org)

> No, you can't get help cracking proprietary software on this list.
> Many of us are professional software developers who make a living as
> "greedy people having fun licensing software".
How do you sleep at night? ;)

Dan

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


Re: [Tutor] FW: Is it Posible? To Crack And HowTo

2005-10-07 Thread Kent Johnson
Daniel Watkins wrote:
>>No, you can't get help cracking proprietary software on this list.
>>Many of us are professional software developers who make a living as
>>"greedy people having fun licensing software".
> 
> How do you sleep at night? ;)

On a good day the fun of creating all those licenses lets me sleep with a smile 
on my face. On a bad day, I have nightmares about all the hungry children 
caused by my greed. ;-)

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


Re: [Tutor] Simple Tkinter question (fwd)

2005-10-07 Thread Danny Yoo
[Keeping Tutor in CC]

-- Forwarded message --
Date: Fri, 7 Oct 2005 01:25:26 -0700 (PDT)
From: Mike Cheponis <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Simple Tkinter question (fwd)

On Fri, 7 Oct 2005, Danny Yoo wrote:

> Ok, that works too.  Another variation on your approach is the
> update_idletasks() method, which like update() should handle all the
> graphic-updating commands that are queued up for the GUI.  There's a
> little more in:

Yeah, the instant after I sent you that msg, I tried update_idletasks and it 
worked, too, so I switched to using that.


>http://effbot.org/zone/tkinter-performance.htm
>http://mail.python.org/pipermail/tkinter-discuss/2005-June/000464.html

Thanks, very helpful.


> that talks about what kind of GUI tasks are considered "idle", and when
> you might want to call update() or update_idletasks().
>
>
> The issue with update() is that while the program is sleeping, GUI
> interaction, like button presses, will be ineffective, since we're still
> not relinquishing control back to the GUI.

> This may or may not be a problem for you.  You've probably seen programs
> in the real world whose GUIs lag and drag when they do a lot of work.  If
> that kind of program behavior annoys you, then you'll probably want to
> search for another solution in your own programs.  *grin*

Yeah, one of those references says to _insert_ calls to update_idletasks to get 
the GUI to be more responsive.

I wish I understood Tkinter better; I've looked at most of the on-line stuff, 
and I think I have every Python book ever printed, but some Tk stuff still 
seems mysterious.

well, after I deliver this one program with Tk, I think I'm going to switch to 
wxPython for future GUI front-ends.

Thanks again,

-Mike


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


Re: [Tutor] pylibpcap

2005-10-07 Thread Danny Yoo


On Fri, 7 Oct 2005, Servando Garcia wrote:

>   I need to use pylibpcap. I am looking for any documentation at
> all, tutorial would be nice.

Hi Servando,

Have you looked at the python-libpcap forum?  That's probably be a better
place to ask questions on pylibpcap:

http://sourceforge.net/forum/forum.php?forum_id=44279

Good luck!

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


Re: [Tutor] Is it Posible? To Crack And HowTo

2005-10-07 Thread Danny Yoo


On Fri, 7 Oct 2005, Suranga Sarukkali wrote:

> I've heard that Python is good for hacking and when I ask how to here on
> python tutor mailing list answers were all about reading some article
> I've already read before,

[text cut]

Here, read a little more.  ESR has written an article on the kind of
"hacking" that we do here on Tutor:

http://www.catb.org/~esr/faqs/hacker-howto.html


> I've got lots of software by these we call proprietary software
> developers who are some greedy people having fun licensing software.

It is not polite to call people "greedy" when you do not know who they
are.  And unfortunately, your ethics system is different from that of
professional software developers.  For a concrete example, see Section 1.5
of the ACM Code of Ethics:

http://www.acm.org/constitution/code.html


The whole Open Source movement is based on the power of copyright law and
software licenses:

http://www.opensource.org/licenses/

so I'm not sure I'm following the implication about proprietary software
developent and licenses: the OSS folks have licenses too.

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


Re: [Tutor] Importing Modules Within Classes

2005-10-07 Thread Bill Campbell
On Fri, Oct 07, 2005, Kent Johnson wrote:
>Pierre Barbier de Reuille wrote:
>> (never import
>> a module in a small function likely to be called in an inner-loop !)
>
>That's good advice, but I would say "in a *time-critical* inner-loop". After 
>the first import, importing a module is fast, it is just a few dictionary 
>lookups (looking up the module in sys.modules) and a dictionary write (to the 
>local namespace). It's only the first import that is potentially expensive.

Another way that I use this is to handle parts of a module that may not
always be used (e.g. curses routines for interactive use).

In this case we have a module that provides our curses interactive screen
routines, and it has something like this:

import os
os.environ['cursesstuff'] = True

Then in the more general purpose routines:

# stuff goes here that's not interactive

if os.environ.get('cursestuff']:
import ...
class ...

# other things that don't need the extra functions.

All that's necessary to activate the interactive classes and other related
stuff is to include the curses routines before importing the modules that
may or may not use them.

Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
UUCP:   camco!bill  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
URL: http://www.celestial.com/

``It wasn't raining when Noah built the ark.''
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Did anyone get the Kamaelia "Conversing" chapter 5 to work?

2005-10-07 Thread Michael Sparks
On Friday 07 October 2005 03:04, R. Alan Monroe wrote:
> > I've just double checked what happens when running the contents of that
> > page, and it works as expected (here at least), so I suspect the problems
> > you're seeing are simply due to "code being in HTML" issues.
>
> Yeah I was writing as much as I was able on my own rather than
> copying/pasting the code, so it was mainly an oversight in my own
> work.

That's great to hear - not the oversight part but the fact you were talking
about your work. Out of interest, how did you find the tutorial/exercises and
what level of experience would you say you have? (I know some people find
such questions rude and impertinent though so if you want to not say, I
don't have a problem, I just hope you found it useful/interesting)

Also, if there were bits you found odd, broken, etc, we'd be really interested
in hearing things. Specifically I'm more interested in knowing whether a) the
approach is compehensible based on the tutorial b) whether the tutorial
sucks over some momentary twinge of personal ego. I lived in the North of
England for several years (not recently, but...) , so strong language/views
won't offend ;-)

We're going to be making a 0.3 release of Kamaelia this weekend which has a
lot more facilities than the previous releases, but the core approach remains
the same - bolting together things.

Anyway, thanks for the feedback, it's useful - very useful - and I hope the
tutorial helped with understanding generators, how to use them and what
they could be used for (if you weren't already comfortable with them :-)

Best regards,


Michael.
--
"Though we are not now that which in days of old moved heaven and earth, 
   that which we are, we are: one equal temper of heroic hearts made 
 weak by time and fate but strong in will to strive, to seek, 
  to find and not to yield" -- "Ulysses", Tennyson
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New Python book

2005-10-07 Thread Michael Sparks
On Wednesday 05 October 2005 19:20, Kent Johnson wrote:
> This seems to be an update to his previous book, "Practical Python", rather
> than a completely new book. The TOC is almost identical. I haven't read the
> earlier book, either, so I don't have an opinion. The same sample chapter
> is available for each if anyone wants to compare. (see www.apress.com)

My wife bought me 'Practical Python' for my birthday last year. I found it to
be a very readable style and interesting. I quite like reading books aimed
at beginners/novices/etc because it normally results in a fresh view of
subjects that I feel are done and dusted. 

The thing I find particularly interesting about the approach is the 'project 
oriented' approach in the latter half of the book.  I found the GUI chapters 
to be relatively useless to me.

Having downloaded the sources to the examples for this update though it looks 
like he's using wx extensively throughout, which strikes me as both a good & 
bad choice. Good in that wx is pretty good, bad in that using Tk would IMO be 
better since python ships with Tk. That's highly subjective though.

Best Regards,


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


[Tutor] Config Parser question

2005-10-07 Thread Alberto Troiano








Hey tutors

 

I’m trying to make a configuration file

 

I know how to read the sections and options (using
ConfigParser module from Python 2.3.4 on Win XP)

 

What I wanted to know is that eventually I will need to add sections
and options or change values or erase options or , etc

 

Is there any way that I can do this changes to the
config.ini file?

 

Thanks in advanced

 

Alberto

 

 






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


Re: [Tutor] Simple Tkinter question (fwd)

2005-10-07 Thread Alan Gauld
> I wish I understood Tkinter better; I've looked at most of the on-line 
> stuff, ...
> well, after I deliver this one program with Tk, I think I'm going to 
> switch
> to wxPython for future GUI front-ends.

Most of the issues discssed on this thread apply to every GUI environment.
They all basically work the same way with the GUI providing an event loop
which calls callback functions in response to an event. If a callback 
handler
goes into a long loop the GUI app will freeze. THats how GUIs work,
Tlinter vv wxPython won't change that. wxPython will give a slightly
nicer look n feel to your apps though (especially on Windows).

Alan G. 

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


Re: [Tutor] Is it Posible? To Crack And HowTo

2005-10-07 Thread Michael Sparks
On Friday 07 October 2005 10:20, Suranga Sarukkali wrote:
> All this could look mostly like any of a question of a idiot! sorry for
> that. I've heard that Python is good for hacking and when I ask how to here
> on python tutor mailing list answers were all about reading some article
> I've already read before, it's not hacking I'm into now but a similar
> thing, Cracking and I've got lots of software by these we call proprietary
> software developers who are some greedy people having fun licensing
> software. Can I get help to this using python and if how to? or elif can't
> how to? else where can I get started and going?
>
> Thanks for all other questions you've answered!
> reply to me on [EMAIL PROTECTED] at your earliest convenience.

People who license software are well within their rights to do so. It took
them time, effort and hence money to produce the software, and they
deserve recompense. You wouldn't *demand* that the people emptying
the bins in offces the code was developed in work for no wages would
you?

If you can't afford the software at their prices, I would suggest that it is
they who have a problem rather than you. After all you have a wide variety
of alternatives available.

I don't however respect anyone who doesn't respect the rights of others.
Sure, I don't agree with the poltics of party X and partly that's to do with
not agreeing with their views on what is/isn't greedy. That doesn't give
me the right to damage their livelihood.

If you can't afford their software, then can I request you sta,rt using Free
Software instead? You will still be complying with greedy people's licenses
(they're greedy for freedom), but you will be helping people rather than
hurting people.

You might ask who am I to ask this question this way - a fair question. I'm  a 
person who was once a student, and when unable to pay for a commercial C 
compiler (neither  Microsoft's or Borland's) chose the route of using DJGPP - 
a Free alternative.

I didn't consider rogue copying then acceptable, despite a need, and lack of 
finance, and nor do I now. There are alternatives.

Also, finally consider this: the required ability to *make* a crack (rather
than follow a script) is normally pretty high. You /could/ apply that ability 
soley to destroying the incomes of people (which is what you do if 
you /release. a crack) . Alternatively you could take that energy and ability 
into building better things.

Destruction or construction? your choice. I doubt you'll find many, if any, 
people to aid you in a destructive task.

Regards,


Michael.


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


Re: [Tutor] Is it Posible? To Crack And HowTo

2005-10-07 Thread Alan Gauld
> Suranga Sarukkali wrote:
>> thing, Cracking and I've got lots of software by these we call 
>> proprietary software developers who are some greedy people having fun 
>> licensing software.

Define greedy. Is it reasonable to get paid for the several years worth of 
effort
that goes into creating the proprietary software? Some of the projects I've
been involved with have entailed over 1000 man years of effort. If we sell
1 million copies then each copy must cover the physical production costs
plus at least 1000th of a man-years wage - around $50-100 in the US.
So a factory price of $100-150 would result in a retail price
of $200-300 per package. Is that being greedy? It only just covers the
cost of production and distribution with nothing for future investment and
research. And in practice not that many programs sell 1 million copies!

> > Can I get help to this using python and if how to? or elif can't how to? 
> > else where can I get started and going?

You are unlikely to get help from a public forum to pursue criminal
activities that could land you in court or even prison in most countries.

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


Re: [Tutor] Config Parser question

2005-10-07 Thread Kent Johnson
Alberto Troiano wrote:
> I’m trying to make a configuration file
> 
> I know how to read the sections and options (using ConfigParser module 
> from Python 2.3.4 on Win XP)
> 
> What I wanted to know is that eventually I will need to add sections and 
> options or change values or erase options or , etc
> 
> Is there any way that I can do this changes to the config.ini file?

Sure. See the docs for RawConfigParser add_section(), set() and write(). 
ConfigParser is a subclass of RawConfigParser so you can use any of these 
methods.
http://docs.python.org/lib/RawConfigParser-objects.html

Kent


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


Re: [Tutor] Config Parser question

2005-10-07 Thread Alberto Troiano
Hey Kent

Thank you for the reply

Let me get this straight.. In order to store the new configuration I would
have to make something like this?

import ConfigParser

f=open("config.ini","w+")
c=ConfigParser.ConfigParser()
c.add_section("foo")
c.write(f)

Please let me know if this is correct

Thank you

Alberto

-Mensaje original-
De: Kent Johnson [mailto:[EMAIL PROTECTED] 
Enviado el: Viernes, 07 de Octubre de 2005 18:36
Para: Alberto Troiano
CC: tutor@python.org
Asunto: Re: [Tutor] Config Parser question

Alberto Troiano wrote:
> I'm trying to make a configuration file
> 
> I know how to read the sections and options (using ConfigParser module 
> from Python 2.3.4 on Win XP)
> 
> What I wanted to know is that eventually I will need to add sections and 
> options or change values or erase options or , etc
> 
> Is there any way that I can do this changes to the config.ini file?

Sure. See the docs for RawConfigParser add_section(), set() and write().
ConfigParser is a subclass of RawConfigParser so you can use any of these
methods.
http://docs.python.org/lib/RawConfigParser-objects.html

Kent


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


Re: [Tutor] Is it Posible? To Crack And HowTo

2005-10-07 Thread Danny Yoo


> > I've heard that Python is good for hacking and when I ask how to here
> > on python tutor mailing list answers were all about reading some
> > article I've already read before,

Hi Suranga,

I thought I already read this before too.

http://mail.python.org/pipermail/tutor/2005-July/040002.html
http://mail.python.org/pipermail/tutor/2005-August/040791.html

As a list administrator, I have the responsiblity to warn you in public:
your behavior on the list will not be tolerated much longer if you
continue on this course.  Please reconsider your actions.

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


Re: [Tutor] Config Parser question

2005-10-07 Thread Kent Johnson
Alberto Troiano wrote:
> Let me get this straight.. In order to store the new configuration I would
> have to make something like this?
> 
> import ConfigParser
> 
> f=open("config.ini","w+")
I would use 'w' but to tell the truth I'm not to clear on the difference 
between 'w' and 'w+'

> c=ConfigParser.ConfigParser()
> c.add_section("foo")
you might want 
  c.set('foo', 'bar', 'baz')

> c.write(f)
> 
> Please let me know if this is correct

I think so. Why not try it?

Kent
> 
> Thank you
> 
> Alberto
> 
> -Mensaje original-
> De: Kent Johnson [mailto:[EMAIL PROTECTED] 
> Enviado el: Viernes, 07 de Octubre de 2005 18:36
> Para: Alberto Troiano
> CC: tutor@python.org
> Asunto: Re: [Tutor] Config Parser question
> 
> Alberto Troiano wrote:
> 
>>I'm trying to make a configuration file
>>
>>I know how to read the sections and options (using ConfigParser module 
>>from Python 2.3.4 on Win XP)
>>
>>What I wanted to know is that eventually I will need to add sections and 
>>options or change values or erase options or , etc
>>
>>Is there any way that I can do this changes to the config.ini file?
> 
> 
> Sure. See the docs for RawConfigParser add_section(), set() and write().
> ConfigParser is a subclass of RawConfigParser so you can use any of these
> methods.
> http://docs.python.org/lib/RawConfigParser-objects.html
> 
> Kent
> 
> 
> 
> 

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


Re: [Tutor] [Fwd: Re: Consistant Overhead Byte Stuffing (COBS)algorithm help]

2005-10-07 Thread Michael Cotherman

The c code seems to be walking through the list moving
bytes from src to dst, but the python code below seems
to take one byte from src, start counitng up to the
value from 1 and appending each and every value along
the way to dst, no?

-mike


--- Alan Gauld <[EMAIL PROTECTED]> wrote:

> > I am a noob to converting pointers in C++ to
> arrays in
> > python, although the first time I see it done, I
> will
> > have no problem. Can you help converting the below
> > (what I think is the 'decoder' section) to python?
> 
> It won't be working code but I think this is whats
> happening...
> 
> > UINT CCobsPackets::UnStuffData(unsigned char *src,
> > unsigned char *dst, UINT length)
> 
> def UnStuffData(src,dst,len):
> 
> > {
> > unsigned char *dstStart = dst;
> > unsigned char *end = src + length;
> 
> # I don't think these are needed for Pyhon.
> 
> > while (src < end)
> 
> for code in src:
> 
> > {
> > int code = *src++;
> > for (int i=1; i > {
> > *dst++ = *src++;
> > }
> 
> for i in range(1,code):
>dst.append(i)
> 
> > if (code < 0xFF) 
> > {
> > *dst++ = 0;
> > }
> 
>if code < 0xff
>dst.append('\0')   # may not be needed in
> python...
> 
> > }
> > return (UINT)(dst - dstStart);
> > }





__ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] subclass problem: __names and type-checking

2005-10-07 Thread Brian van den Broek
Hi all,

I'm having an issue which resists my attempts to give a snappy label 
to it. I have a solution that doesn't feel entirely correct, and which 
I cannot actual apply to my original case.

The Issue:
I have a class which I want to subclass. The subclass adds some
additional arguments to __init__. I want both classes to run a sanity
check on their arguments before leaving their respective __init__
methods. I need both to do so, as the _BaseClass may be directly
instantiated. I need to ask permission for the arguments on instance
creation rather than for forgiveness later, as bad arguments passed to
__init__ could take many cpu cycles of other code before they
manifested themselves.

Here's a sketch of where I'm at:

class _BaseClass(object):

 def __init__(self, arg1, arg2):
 self.arg1 = arg1
 self.arg2 = arg2
 if type(self) == _BaseClass:
 # Problem (2) mentioned below shows up here.
 #
 # type test needed otherwise Subclass._validate_args
 # will be called before all subclass args processed by
 # SubClass.__init__, causing AttriuteError
 self._validate_args()

 def _validate_args(self):
 '''Performs sanity check on arguments'''
 if not type(self.arg1) in (int, long):
 raise TypeError
 # etc

class SubClass(_BaseClass):

 def __init__(self, arg1, arg2, arg3, arg4):
 super(SubClass, self).__init__(arg1, arg2)
 self.arg3 = arg3
 self.arg4 = arg4
 if type(self) == SubClass:
 # same reasoning as before -- leaving room for further
 # subclassing.
 self._validate_args()

 def _validate_args(self):
 super(SubClass, self)._validate_args()
 if not isinstance(self.arg3, basestring):
 raise TypeError
 # etc


This works as desired, but leaves two problems:

1) I suspect there may be a better way, as a) this doesn't feel quite 
right and b) in general with Python, it seems that if you are tempted 
to type test, you should rethink, and

2) I originally had __BaseClass rather than _BaseClass. But, with that 
naming, cannot figure out how to write the line

 if type(self) == __BaseClass:

so as to make it work. I know about the name mangling with __somename 
names, but I don't know how to manage it in this case.

The attempt of 4 lines up produces:

NameError: global name '_BaseClass__BaseClass' is not defined

This confuses me. I don't see why the error msg prepends '_BaseClass' 
as that name appears nowhere. That confusion aside, I've no idea how 
to effect what I want.

I think I won't want __BaseClass in the end, as I do expect it is 
possible that it will be instantiated directly, so the '__' seems 
inappropriate. But, the issue of how to do it remains.

So, details of '_' vs '__' aside, is my approach sound? And, how to 
deal with __BaseClass?


Best to all,

Brian vdB



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