Re: Coding style

2006-07-17 Thread dwelch91
PTY wrote:
> Which is better?
> 
> lst = [1,2,3,4,5]
> 
> while lst:
>   lst.pop()
> 
> OR
> 
> while len(lst) > 0:
>   lst.pop()
> 

I think the first one is better, but if all you are doing is removing 
all the items in the list, this is definitely better:

lst = []

-Don
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coding style

2006-07-17 Thread dwelch91
tac-tics wrote:
> 
> I'd say the second one. Empty lists are not false. They are empty. Long
> live dedicated boolean data types.
> 
Uh, no, empty lists are False in a boolean context:

http://docs.python.org/lib/truth.html

-Don
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Howto Determine mimetype without the file name extension?

2006-07-19 Thread dwelch91
Try this:

http://www.demonseed.net/~jp/code/magic.py
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there an easy way to create a database on the fly and let the user input values

2006-10-13 Thread dwelch91
[EMAIL PROTECTED] wrote:
>  I don't realy care what database I use wx.grid or whatever.  I
> wan't it to look at a line
> 
> 128 9023 23428 exc and create the database or pick something out of the
> file as  some sort of a descrition line and then display and allow the
> user to change and add new lines.  What is the easiest set of database
> routines to use for such a project???
> 
> http://www.dexrow.com
> 
kirbybase?


http://www.netpromi.com/kirbybase_python.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yield

2006-11-15 Thread dwelch91
Mateuszk87 wrote:
> Hi.
> 
> may someone explain "yield" function, please. how does it actually work
> and when do you use it?
> 
> thanks in forward
> 
> mateusz
> 

http://docs.python.org/ref/yield.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Python Editor

2006-06-01 Thread dwelch91
Maric Michaud wrote:
> Le Mercredi 31 Mai 2006 12:03, Manoj Kumar P a écrit :
>> Hi,
>>
>> Can anyone tell me a good python editor/IDE?
>> It would be great if you can provide the download link also.
> 
> I didn't see on this list much PyQT users, is there a consensus about it ?
> 
> I vote for linux+kdevelop for a good IDE (didn't try Pydev).
> 

Eric3
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter and dialogs

2006-07-06 Thread dwelch91
I'm trying unsuccessfully to do something in Tk that I though would be 
easy. After Googling this all day, I think I need some help. I am 
admittedly very novice with Tk (I started with it yesterday), so I am 
sure I am overlooking something simple.

The basic idea is that my application will consist of a series of modal 
dialogs, that are chained together in "wizard" fashion. There will be 
some processing in between dialogs, but for the most part, the user will 
do some interaction with each dialog and then click "Next" or 
"Previous". My thinking was that the main (root) Tk window would be 
hidden and that each dialog would be modal and child to that hidden 
window. Is this a reasonable way to do this in Tkinter?

I grabbed the "Dialog" class from effbot's site figuring that was good 
starting point. I did modify it somewhat to convert to the grid layout 
manager, based on advice in the New Mexico Tech Tkinter Reference (by 
John Shipman).

When I run this (Ubuntu 6.06), I get no windows, not even the root Tk one.

Any ideas???

Thanks,

Don




#!/usr/bin/env python
from Tkinter import *

root = None

class Dialog(Toplevel):

 def __init__(self, parent, title = None):
 Toplevel.__init__(self, parent)
 self.transient(parent)

 if title:
 self.title(title)

 print repr(parent)
 self.parent = parent
 self.result = None

 #body = Frame(self)
 #self.initial_focus = self.body(body)
 #body.pack(padx=5, pady=5)

 self.initial_focus = self.body(self)

 self.buttonbox()

 self.bind("", self.ok)
 self.bind("", self.cancel)

 self.grab_set()

 if not self.initial_focus:
 self.initial_focus = self

 self.protocol("WM_DELETE_WINDOW", self.cancel)

 self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
   parent.winfo_rooty()+50))

 self.initial_focus.focus_set()

 self.wait_window(self)


 #
 # construction hooks

 def body(self, master):
 # create dialog body.  return widget that should have
 # initial focus.  this method should be overridden
 pass

 def buttonbox(self):
 # add standard button box. override if you don't want the
 # standard buttons

 box = Frame(self)

 w = Button(box, text="OK", width=10, command=self.ok, 
default=ACTIVE)
 w.pack(side=LEFT, padx=5, pady=5)
 w = Button(box, text="Cancel", width=10, command=self.cancel)
 w.pack(side=LEFT, padx=5, pady=5)

 self.bind("", self.ok)
 self.bind("", self.cancel)

 box.pack()

 #
 # standard button semantics

 def ok(self, event=None):
 if not self.validate():
 self.initial_focus.focus_set() # put focus back
 return

 self.withdraw()
 self.update_idletasks()
 self.apply()
 self.cancel()

 def cancel(self, event=None):
 # put focus back to the parent window
 self.parent.focus_set()
 self.destroy()

 #
 # command hooks

 def validate(self):
 print "validate"
 return True # override

 def apply(self):
 print "apply"
 pass # override


class WelcomeDialog(Dialog):
 def body(self, master):

 Label(master, text="First:").grid(row=0, sticky=W)
 Label(master, text="Second:").grid(row=1, sticky=W)

 self.e1 = Entry(master)
 self.e2 = Entry(master)

 self.e1.grid(row=0, column=1)
 self.e2.grid(row=1, column=1)

 self.cb = Checkbutton(master, text="Hardcopy")
 self.cb.grid(row=2, columnspan=2, sticky=W)

 self.w1 = Button(master, text="OK", width=10, command=self.ok, 
default=ACTIVE)
 #w.pack(side=LEFT, padx=5, pady=5)
 self.w1.grid(row=3, column=0)
 self.w2 = Button(master, text="Cancel", width=10, 
command=self.cancel)
 #w.pack(side=LEFT, padx=5, pady=5)
 self.w2.grid(row=3, column=1)


 def apply(self):
 print "apply"
 first = int(self.e1.get())
 second = int(self.e2.get())
 self.result = first, second

 def buttonbox(self):
 pass


def show_ui():
 welcome = WelcomeDialog(root, "test1")



global root
root = Tk()
root.after_idle(show_ui)
root.mainloop()
-- 
http://mail.python.org/mailman/listinfo/python-list


Detecting 64bit vs. 32bit Linux

2006-07-07 Thread dwelch91
I need to detect whether the operating system I am running on (not the 
Python version) is 64bit or 32bit. One requirement is that I need to 
include support for non-Intel/AMD architectures.

The 2 ways I have thought detecting 64bit are:

1. struct.calcsize("P") == 8
2. '64' in os.uname()[4]

I'm not convinced that either one of these is really adequate. Does 
anybody have any other ideas on how to do this?

Thanks,

Don


-- 
http://mail.python.org/mailman/listinfo/python-list