Re: [Tutor] replacement for .mainloop() in Tk

2007-09-03 Thread Alan Gauld

"Trey Keown" <[EMAIL PROTECTED]> wrote

> 
> from Tkinter import *
> import tkFileDialog
> ##
> self = Tk()

Using self here is a little bit unconventional sinmce its not in
a class. That could confuse some readers.

> self.title("Example Window Title")
> self.iconbitmap("e.ico")
> ##
> ##
> ##
> ##
> 

> Now, as you probably see, there isn't a "self.mainloop()"
> function in the output. My question is-
> *Is there any other thing I could use instead of ".mainloop()" to 
> make a
> window come up? Because I noticed that only one window can be up at 
> a time
> that has a ".mainloop()" attribute.

I'm not sure what you mean by that. You can have as many
windows as you like but there can only be one mainloop call,
usually on the top level tk object not on a window at all.

The mainloop is the event loop of the program. Without that
Tk cannot capture any events and hence can't do anything.
But why would having a mainloop be a problem? You can call
it at the end of your code. (In fact you can call it at the
beginning if you like! The end is just convention - and it does
make inserting new controls etc less problematic)

I'm slightly confused by what you are asking.
What is the problem that you think you have?


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


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


Re: [Tutor] What's up with Python 2.5.1's IDLE?

2007-09-03 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote

> Under Kent's tutelage, I've been experimenting with having no
> PYTHONDOC,

I assume you mean PYTHONPATH?

> and instead putting a .pth file in
> E:\Python25\lib\site-packages\ I named pointers.pth.

I obviously failed to convince you of the superior flexibility
of using PYTHONPATH for your personal libs :-)
If your PC is only usd by you and you only have one
user account then that probably isn't a problem,
except you lose the flexibility of changing PYTHONPATH
dynamically during a session using SET.

> The contents of
> pointers.pth is:
> E:\Python25\
> E:\PythonWork\
> E:\PythonWork\Functions\
> E:\Python25\lib\site-packages\
> E:\Python25\lib\site-packages\mine

I would have expected Python to load the Python25 stuff itself.
You should only need the pointers file to contain the pointers
to the non standard directories (just as you would in PYTHONPATH)

> Here's what the Command Prompt shell shows for sys.path:

> E:\Python25\lib\site-packages\setuptools-0.6c5-py2.5.egg
> E:\Python25\lib\site-packages\dmath-0.9-py2.5.egg
> C:\WINDOWS\system32\python25.zip
> E:\Python25\DLLs
> E:\Python25\lib
> E:\Python25\lib\plat-win
> E:\Python25\lib\lib-tk
> E:\Python25
> E:\Python25\lib\site-packages
> E:\Python25\lib\site-packages\PIL
> E:\PythonWork
> E:\PythonWork\Functions
> E:\Python25\lib\site-packages
> E:\Python25\lib\site-packages\mine
> E:\Python25\lib\site-packages\win32
> E:\Python25\lib\site-packages\win32\lib
> E:\Python25\lib\site-packages\Pythonwin
> E:\Python25\lib\site-packages\wx-2.8-msw-unicode
> >>>
> All good.

Not quite all good - you have multiple entries
for site-packages...

> However, this is what IDLE's shell shows for sys.path:
>
> E:\Python25\Lib\idlelib
> E:\Python24\lib\site-packages\setuptools-0.6c5-py2.4.egg
> C:\WINDOWS\system32\python24.zip
> E:\Python25\Lib\idlelib
> E:\Python24\DLLs
> E:\Python24\lib
> E:\Python24\lib\plat-win
> E:\Python24\lib\lib-tk
> E:\Python24
> E:\Python24\lib\site-packages
> E:\Python24\lib\site-packages\wx-2.6-msw-ansi
>
> I do still have Python 2.4, but why does Python 2.5.1's IDLE's shell
> show all those things from 2.4, and only shows the path to itself in 
> 2.5.1?

It looks like IDLE has its own mechanism for populating sys.path
and it may be reading something in the Registry. This might be
a question to ask on the IDLE mailing list?

> I like the editing ease of having a .pth file rather than a
> troublesome-to-edit PYTHONDOC, but I need to first clear up the
> problem with IDLE (which works fine with a PYTHONDOC).

I'm not sure I understand what you mean by the editing ease?
You can change PYTHONPATH with a simple SET command
(albeit temporarily) and 3 mouse clicks takes you to the dialog
editor.

HTH,

Alan G 


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


Re: [Tutor] replacement for .mainloop() in Tk

2007-09-03 Thread Kent Johnson
Trey Keown wrote:
> Okay, I'm making a program that turns xml code into python code.
> 
> And here would be the corresponding output (well, what I've got so far...)
> 
> 
> from Tkinter import *
> import tkFileDialog
> ##
> self = Tk()
> self.title("Example Window Title")
> self.iconbitmap("e.ico")
> ##
> ##
> ##
> ##
> 
> 
> Now, as you probably see, there isn't a "self.mainloop()" function in the
> output. 

Why not just out put the mainloop() before <> ?

You might be interested in
http://www.bitflipper.ca/rapyd/
though it seems to store its data in pickles, not xml.

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


Re: [Tutor] What's up with Python 2.5.1's IDLE?

2007-09-03 Thread Kent Johnson
Dick Moores wrote:
> However, this is what IDLE's shell shows for sys.path:
>  >>> from sys import path
>  >>> for x in path:
>   print x
> 
>   
> E:\Python25\Lib\idlelib
> E:\Python24\lib\site-packages\setuptools-0.6c5-py2.4.egg
> C:\WINDOWS\system32\python24.zip
> E:\Python25\Lib\idlelib
> E:\Python24\DLLs
> E:\Python24\lib
> E:\Python24\lib\plat-win
> E:\Python24\lib\lib-tk
> E:\Python24
> E:\Python24\lib\site-packages
> E:\Python24\lib\site-packages\wx-2.6-msw-ansi
> 
> I do still have Python 2.4, but why does Python 2.5.1's IDLE's shell 
> show all those things from 2.4, and only shows the path to itself in 2.5.1?

It looks to me like IDLE is running under 2.4 but using the IDLE package 
from 2.5.

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


[Tutor] indexing elements

2007-09-03 Thread chinni
Hi all,

i had some doubt about this line  can any body clarify this plz...
endings = ['st', 'nd', 'rd'] + 17 * ['th'] + ['st', 'nd', 'rd'] + 7 * ['th']
+ ['st']

-- 
Best Regards,
M.Srikanth Kumar,
Jr.Software Developer,
Google India Pvt Ltd..,
HYDERABAD.
Phone no: +91-9866774007
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] More class questions

2007-09-03 Thread Ara Kooser
Hello again,

   Thank you again for your help. I have classes somewhat figured out
and I am beginning to understand the syntax involved in using them.
What I have so far is a very simple text adventure with two rooms, two
items, and some exits.

   Two question which relates directly to classes: Do you create all
your instances at the end of the program or just as needed? Can you
call functions from other classes within a class (So I create an
Object class for items and I want then instances to appear in the Room
class as they are called).

   Third question. Using function I understand how to move a player
around in different rooms using raw_input and if statements but how do
you do that with classes. I created a player class and I want one of
the methods to be moving from room to room. Or should movement be a
separate class?

   I am looking at the code that Paul McGuire wrote for using
pyparsing and I don't quite understand how it all works. I have to
book Game Programming: The L line coming in two weeks. I am just
trying to get a head start.

Thank you.

Ara


CODE BELOW
#
#Text Advenuture - Roguelike
#By Ara Kooser
#Thanks to Chris, e.,Tino and Steven at python tutor


class Player:
#What makes this a player.
pass

#def Move(self):


class Area:

#What makes it an area?
def __init__(self, name, description):
#Number of arguements in the _init_ there must be defined
self.name = name
self.description = description
self.contents = []
self.paths = [None,None,None,None]

#Methods. What you can do.
def AddObject(self,thing):
self.contents.append(thing)

def AddPaths(self,direction):
self.paths.append(direction)

def look(self):
print "Look around the place you are in"
print "You are in the",self.name
print self.description
print "Your exits are:"
print self.paths

def search(self):
print "You search the area and find..."
print self.contents


###
# MAIN
#Start of program
###

first_instance = Area("Outside", "You are standing outside")
first_instance.AddObject("Stick")
first_instance.AddPaths("North")
first_instance.look()
first_instance.search()

print
print

second_instance = Area("Inside", "You are standing inside")
second_instance.AddObject("Iron pot")
second_instance.AddPaths("South")
second_instance.look()
second_instance.search()





-- 
Quis hic locus, quae regio, quae mundi plaga. Ubi sum. Sub ortu solis
an sub cardine glacialis ursae.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] checking if a number is evan or odd

2007-09-03 Thread max baseman
hello just a quick check in, it's about the same program i was asking  
about before ive let it sit for a few days now and i reached a number  
to high to convert to a decimal by adding 0.0
here's the program:

count=1
numstart=268549802
number=0
high=0
a=0
while 1==1:
 numstart=numstart+1
 number=numstart
 count=1
 while number !=1:
 if number/2 == (number+0.0)/2:
 number=number/2
 else:
 number=(number*3)+1
 count=count+1
 if count > a:
 a=count
 print numstart,":",count


after a few days i got this error:

Traceback (most recent call last):
   File "homework6high.py", line 11, in 
 if number/2 == (number+0.0)/2:
OverflowError: long int too large to convert to float

just wondering if theirs a way to check if a larger number is even or  
odd

thanks

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


[Tutor] Metaclass programming

2007-09-03 Thread Orest Kozyar
I have the following code:

class meta(type):

def __call__(cls, *args, **kwargs):
argnames = inspect.getargspec(cls.__init__)[0]
for i, value in enumerate(args):
kwargs[argnames[i]] = value
return type.__call__(cls, kwargs)

class test(object):

__metaclass__ = meta

def __init__(self, x, y, **kwargs):
pass

However, inspect.getargspec(cls.__init__) appears to return only the
arguments of the meta __init__ rather than the test __init__.  Is there any
way I can get access to the test __init__ function from the metaclass?

Orest

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


[Tutor] Dynamically changing a class

2007-09-03 Thread Jason Doege
Hi All,

I'd like to change the behavior of a class' member function dynamically
such that, once changed, all objects of the type would see the new
behavior.

For instance:

>>> class MyClass (object) :
  def mfunc(self, data):
print 'pre change behavior'

>>> aMyClassObj = MyClass()
>>> aMyClassObj.mfunc(data)
pre change behavior
>>> def MyClass.mfunc(self, data):  #this does not work :-(
  print 'post change behavior'

>>> aMyClassObj.mfunc(data)
post change behavior


Does anyone have any guidance on how to accomplish this? I'd also like
to be able to add and delete attributes, similarly.

Best regards,
Jason Doege
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] binary data struct module

2007-09-03 Thread John
Hello,

I have an unformatted mixed type binary file I'm trying to read into Python.
So far, I've gotten as far as:

f2=file(infile,'rb')

Dfmt=['3i','13s','7i','2f','2i','2f','2i','i']  #format for binary reading
first bits

if f2:
print infile + ' has been opened'
#for ft in Dfmt:
#  print ft
a=(struct.unpack(ft,f2.read(struct.calcsize(ft))) for ft in Dfmt)
for ln in a: print ln

Which gives me:

/cygdrive/c/washakie/binfile has been opened
(21, 20060612, 0)
('Version 4.3',)
(21, 12, -86400, -86400, -900, 12, 24)
(-179.0, -90.0)
(360, 180)
(1.0, 1.0)
(24, 16)
(3,)

however, how can I now assign variables based on the 'generator object' a?
What exactly is this? When I try to do something like:

print a[0]
or
print a(0)

I get the error:
Traceback (most recent call last):
  File "readheader.py", line 20, in 
print a[0]
TypeError: 'generator' object is unsubscriptable

My question is, how can I now work with 'a' so that i can use the values?

Thanks!



-- 
Configuration
``
Plone 2.5.3-final,
CMF-1.6.4,
Zope (Zope 2.9.7-final, python 2.4.4, linux2),
Five 1.4.1,
Python 2.4.4 (#1, Jul 3 2007, 22:58:17) [GCC 4.1.1 20070105 (Red Hat
4.1.1-51)],
PIL 1.1.6
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] indexing elements

2007-09-03 Thread Kent Johnson
chinni wrote:
> Hi all,
> 
> i had some doubt about this line  can any body clarify this plz...
> endings = ['st', 'nd', 'rd'] + 17 * ['th'] + ['st', 'nd', 'rd'] + 7 * 
> ['th'] + ['st']

You can try it in the interactive interpreter:
In [8]: endings = ['st', 'nd', 'rd'] + 17 * ['th'] + ['st', 'nd', 'rd'] 
+ 7 * ['th'] + ['st']
In [10]: print endings
['st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 
'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'st', 'nd', 'rd', 'th', 
'th', 'th', 'th', 'th', 'th', 'th', 'st']

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


Re: [Tutor] checking if a number is evan or odd

2007-09-03 Thread Ian Witham
Hi Max,

A better way to check if a number is odd or even would be to find the
remainder after it is divided by two.

for instance: 4 divided by 2 = 2 with 0 remainder
   5 divided by 2 = 2 with 1 remainder
   6 divided by 2 = 3 with 0 remainder
   7 divided by 2 = 3 with 1 remainder

As well as the floor division operator '/', Python has another operator for
finding the remainder (or 'modulus')

On 9/4/07, max baseman <[EMAIL PROTECTED]> wrote:
>
> hello just a quick check in, it's about the same program i was asking
> about before ive let it sit for a few days now and i reached a number
> to high to convert to a decimal by adding 0.0
> here's the program:
>
> count=1
> numstart=268549802
> number=0
> high=0
> a=0
> while 1==1:
>  numstart=numstart+1
>  number=numstart
>  count=1
>  while number !=1:
>  if number/2 == (number+0.0)/2:
>  number=number/2
>  else:
>  number=(number*3)+1
>  count=count+1
>  if count > a:
>  a=count
>  print numstart,":",count
>
>
> after a few days i got this error:
>
> Traceback (most recent call last):
>File "homework6high.py", line 11, in 
>  if number/2 == (number+0.0)/2:
> OverflowError: long int too large to convert to float
>
> just wondering if theirs a way to check if a larger number is even or
> odd
>
> thanks
>
> ___
> 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] indexing elements

2007-09-03 Thread Ian Witham
Hi,

I'm not too sure what your asking here,

your code assigns the following to endings:
['st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th',
'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'st', 'nd', 'rd', 'th',
'th', 'th', 'th', 'th', 'th', 'th', 'st']

This is what we would expect.. 17 * ['th'] causes 17 repetitions of 'th' in
the list.
certain operators, like the multiplication operator in your example, have
additional behavior depending on what kind of data they are applied to.

The repetition operator binds closer than the '+' as the following brackets
show.

endings = ['st', 'nd', 'rd'] + (17 * ['th']) + ['st', 'nd', 'rd'] + (7 *
['th']) + ['st']

Ian.

On 9/4/07, chinni <[EMAIL PROTECTED]> wrote:
>
> Hi all,
>
> i had some doubt about this line  can any body clarify this plz...
> endings = ['st', 'nd', 'rd'] + 17 * ['th'] + ['st', 'nd', 'rd'] + 7 *
> ['th'] + ['st']
>
> --
> Best Regards,
> M.Srikanth Kumar,
> Jr.Software Developer,
> Google India Pvt Ltd..,
> HYDERABAD.
> Phone no: +91-9866774007
> ___
> 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] checking if a number is evan or odd

2007-09-03 Thread max baseman
cool thanks
the problem was from a math book imp 1 but i already did the work i  
was just interested in what number had the most steps i could fin  
wanted to get to 1000 imagine how dismayed i was when it crashed at 965

On Sep 3, 2007, at 8:23 PM, Andrew James wrote:

> I'd just go with
>
> if number%2 == 0:
>number = number/2
>
> Why do you need to convert it to a float?
>
> Off topic:
> Is this a PE problem? I remember doing the same thing.
>
> max baseman wrote:
>> hello just a quick check in, it's about the same program i was  
>> asking  about before ive let it sit for a few days now and i  
>> reached a number  to high to convert to a decimal by adding 0.0
>> here's the program:
>>
>> count=1
>> numstart=268549802
>> number=0
>> high=0
>> a=0
>> while 1==1:
>>  numstart=numstart+1
>>  number=numstart
>>  count=1
>>  while number !=1:
>>  if number/2 == (number+0.0)/2:
>>  number=number/2
>>  else:
>>  number=(number*3)+1
>>  count=count+1
>>  if count > a:
>>  a=count
>>  print numstart,":",count
>>
>>
>> after a few days i got this error:
>>
>> Traceback (most recent call last):
>>File "homework6high.py", line 11, in 
>>  if number/2 == (number+0.0)/2:
>> OverflowError: long int too large to convert to float
>>
>> just wondering if theirs a way to check if a larger number is even  
>> or  odd
>>
>> thanks
>>
>> ___
>> 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] Need some help with wxPython...

2007-09-03 Thread Trey Keown
Hey all,
I'm starting to drift away from Tkinter and enter the realm of wxPython.
I've recently written a simple text editor in Tkinter, and I would like to
know if anyone knows of a good example of a simple wxPython text editor
(with the lines properly indented!!!), because all the examples I can find
are improperly indented, or just don't work. Or perhaps a tutorial that
covers all I need to know for making a text editor would work.
Thanks for any help,
Trey K. aka thetechgeek

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