An Apple a day keeps Windows away!
Aia commented: If I were not a gentleman I would tell you were you came from and where you could go. -2
An Apple a day keeps Windows away!
Time to put the death penalty on evil-minded hackers!
In my mind they are nothing but terrorists, out there to do the most damage they can.
There are in fact two things, science and opinion; the former begets knowledge, the latter ignorance.
And in the end it's not the years in your life that count. It is the life in your years.
~~ Abraham Lincoln
Did anyone already get the $600 stimulus check from the US Treasury?
Not yet!
"The administration I'll bring is a group of men and women who are focused on
what's best for America --- honest men and women, decent men and women, women
who will see service to our country as a great privilege and who will not stain the house."
~~ spoken at the Republican debate January 15, 2000
I am surprised nobody has brought up the old wx.ListBox() widget yet. Well, here it is, a fun thing to experiment with (stole the name_list from vegaseat):
# load, sort and clear a wxPython
# wx.ListBox(parent, id, pos, size, choices, style)
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, mytitle, name_list):
wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle)
self.SetBackgroundColour("green")
self.name_list = list(name_list)
self.listbox = wx.ListBox(self, wx.ID_ANY, choices=[])
self.listbox.Bind(wx.EVT_LISTBOX, self.listboxClick)
# create action widgets
self.load_button = wx.Button(self, wx.ID_ANY, "load ListBox")
self.clear_button = wx.Button(self, wx.ID_ANY, "clear ListBox")
self.sort_button = wx.Button(self, wx.ID_ANY, "sort ListBox")
# bind mouse event to an action
self.load_button.Bind(wx.EVT_BUTTON, self.load_buttonClick)
self.clear_button.Bind(wx.EVT_BUTTON, self.clear_buttonClick)
self.sort_button.Bind(wx.EVT_BUTTON, self.sort_buttonClick)
# create an output widget
self.label = wx.StaticText(self, wx.ID_ANY, "")
sizer = wx.GridBagSizer(vgap=5, hgap=5)
# pos=(row, column) span=(rowspan, columnspan)
# wx.ALL puts the specified border on all sides
sizer.Add(self.load_button, pos=(0, 0), flag=wx.ALL, border=5)
# listbox spans 6 rows and 2 columns
sizer.Add(self.listbox, pos=(1, 0), span=(6, 2),
flag=wx.ALL|wx.EXPAND, border=5)
sizer.Add(self.clear_button, pos=(7, 1), flag=wx.ALL, border=5)
sizer.Add(self.sort_button, pos=(7, 0), flag=wx.ALL, border=5)
sizer.Add(self.label, pos=(8, 0), flag=wx.ALL, border=5)
self.SetSizer(sizer)
# size the frame so all the widgets fit
self.Fit()
def load_buttonClick(self, event):
"""load the name list into the bistbox"""
# use self.listbox.Set(name_list) or ...
for name in self.name_list:
self.listbox.Append(name)
def clear_buttonClick(self, event):
"""clear all items from the listbox"""
self.listbox.Clear()
self.label.SetLabel("")
def sort_buttonClick(self, event):
"""sort the items in the listbox"""
# GetItems() is new in wxPython2.8
# puts the listbox items into a list
name_list = self.listbox.GetItems()
name_list.sort()
# Set() clears and reloads the listbox
self.listbox.Set(name_list)
def listboxClick(self, event):
"""display the selected ListBox item"""
selected_item …
Congratulations, looks pretty clever to me!
Aia -- I like your new avatar -- its sinister and mysterious.
Yeah, cool avatar! A timely reminder that we are all being watched!
We need a big government program to find the missing cold, so we can fight global warming.
McCain: "Obama will raise your taxes, I won't."
Here is another quote I agree with, this time from W himself:
"Let me tell you my thoughts about tax relief. When your economy is kind of ooching along, it's important to let people have more of their own money."
Hallelujah! I made it past the first 1000 posts! This calls for a celebration this evening.
A 15 lb watermelon!
If you finish it, that could be a new record. I just had some watermelon too, but not 15 pounds of it.
I could go for the 'Walk On Water' which looks like utter joy!
"For every fatal shooting, there were roughly three non-fatal shootings. And, folks, this is unacceptable in America. It's just unacceptable. And we're going to do something about it."
George W. Bush
May 14, 2001
Mister Aia's and Mister Sinkula's avatars and ideas almost match, very interesting.
Those avatars must come from the days of the black panther movement!
By learning you will understand opportunities.
By teaching you will be learning never to complain.
I couldn't have said it any better!
This must be a picture of a much younger John McCain?
Interesting project, but you have to give us a lot more information.
Does the robot use Python internally, or does it just communicate via a data port? What does the data stream look like?
Most of the DOS commands you are familiar with are contained in these two modules:
import os
os.chdir(path) change directory to the one in path
os.curdir return current directory
os.chmod(path, mode) change the mode of path to the new mode
os.getcwd() return the current working directory
os.mkdir(path[, mode]) create a directory named path with
numeric mode (default 0777)
os.remove(path) removes/deletes file given in path
os.rename(old, new) renames file or directory old to new
os.rmdir(path) removes an empty directory path
os.walk(top[, topdown=True [, onerror=None]]) generates a
list of file names in a directory tree
import shutil
shutil.copy(src, dest) copies the contents of file src to file dest
retains file permissions
shutil.copytree(src, dest[, symlinks]) recursively copies an entire
directory tree rooted at src into dest
shutil.move(src, dest) moves a file or directory to a new location
shutil.rmtree(path[, ignore_errors[, onerror]]) deletes an entire
directory tree
Looks like the expected smear-mail crusade against Obama is in full swing.
Canada is now the number one exporter of oil to the US. Can't understand the folks who tell us that buying oil from foreign countries is supporting terrorism.
Please learn how to use code tags around your code, nobody will read the ugly mess you are presenting otherwise.
A nice looking informative about-box is easy to achieve with the wx.AboutBox() widget. The example also touches on menu construction and wxPython's wordwrap feature:
# testing the fancy wx.AboutBox() widget
import wx
from wx.lib.wordwrap import wordwrap
class MyFrame(wx.Frame):
"""
create a frame, with a menu, statusbar and 2 about dialogs
"""
def __init__(self):
# create a frame/window, no parent, default to wxID_ANY
wx.Frame.__init__(self, None, wx.ID_ANY, "wx.AboutBox test",
pos=(300, 150), size=(300, 350))
self.SetBackgroundColour("brown")
# create a status bar at the bottom
self.CreateStatusBar()
self.SetStatusText("Click on File")
menu = wx.Menu()
# the optional & allows you to use alt/a
# the last string argument shows in the status bar on mouse_over
menu_about = menu.Append(wx.ID_ANY, "&About", "Ho-hum about box")
menu_about2 = menu.Append(wx.ID_ANY, "About&2", "Fancy about box")
menu.AppendSeparator()
# the optional & allows you to use alt/x
menu_exit = menu.Append(wx.ID_ANY, "E&xit", "Quit the program")
# create a menu bar at the top
menuBar = wx.MenuBar()
# the & allows you to use alt/f
menuBar.Append(menu, "&File")
self.SetMenuBar(menuBar)
# bind the menu events to an action/function/method
self.Bind(wx.EVT_MENU, self.onMenuAbout, menu_about)
self.Bind(wx.EVT_MENU, self.onMenuAbout2, menu_about2)
self.Bind(wx.EVT_MENU, self.onMenuExit, menu_exit)
def onMenuAbout(self, event):
"""a somewhat ho-hum about box"""
dlg = wx.MessageDialog(self,
"a simple application using wxFrame, wxMenu\n"
"a statusbar, and this about message.",
"About", wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
def onMenuAbout2(self, event):
"""use the much fancier wx.AboutBox()"""
# first fill the info object
info = wx.AboutDialogInfo()
info.Name = "Bratwurst7"
info.Version = "v.1.7.4"
info.Copyright = "(C) copyfight 2008"
info.Description = wordwrap(
"The Bratwurst7 program is a software program that "
"makes you …
The module xlrd can read Excel spreadsheets without the use of COM:
# module xlrd is used to extract data from Excel spreadsheets.
# Handles older and newer formats. Can be used on any platform.
# Has support for Excel dates and is unicode-aware.
# download installer xlrd-0.6.1.win32.exe from:
# http://pypi.python.org/pypi/xlrd
# or:
# http://www.lexicon.net/sjmachin/xlrd.htm
import xlrd
# pick an Excel file you have
book = xlrd.open_workbook("myfile.xls")
sheet = book.sheet_by_index(0)
for row in range(sheet.nrows):
print sheet.row(row)
I was playing around with wxPython's slider widget and found a nice application for it:
# use slider inputs to calculate cost of petrol in the USA and Europe
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, mytitle, mysize):
wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)
self.SetBackgroundColour("yellow")
# create input widgets
# label for slider1
label_s1 = wx.StaticText(self, wx.ID_ANY, "US cents per US Gallon:")
# can only use integer values!!!
# initial value = 450, min value = 300, max value = 600
self.slider1 = wx.Slider(self, wx.ID_ANY, 450, 300, 600, size=(320, 40),
style=wx.SL_HORIZONTAL|wx.SL_LABELS)
# label for slider2
label_s2 = wx.StaticText(self, wx.ID_ANY, "Euro cents per Liter:")
# initial value = 150, min value = 100, max value = 200
self.slider2 = wx.Slider(self, wx.ID_ANY, 150, 100, 200, size=(320, 40),
style=wx.SL_HORIZONTAL|wx.SL_LABELS)
# label for slider3
label_s3 = wx.StaticText(self, wx.ID_ANY, "US cents per Euro:")
# initial value = 160, min value = 100, max value = 200
self.slider3 = wx.Slider(self, wx.ID_ANY, 160, 100, 200, size=(320, 40),
style=wx.SL_HORIZONTAL|wx.SL_LABELS)
# bind all mouse slider marker drags to the same action
self.Bind(wx.EVT_SLIDER, self.onAction)
# create an output widget
self.label = wx.StaticText(self, wx.ID_ANY, "")
# use a vertical boxsizer for the widget placement
sizer_v = wx.BoxSizer(wx.VERTICAL)
sizer_v.Add(label_s1, 0, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=10)
sizer_v.Add(self.slider1, 0, flag=wx.ALL|wx.EXPAND, border=5)
sizer_v.Add(label_s2, 0, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=10)
sizer_v.Add(self.slider2, 0, flag=wx.ALL|wx.EXPAND, border=5)
sizer_v.Add(label_s3, 0, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=10)
sizer_v.Add(self.slider3, 0, flag=wx.ALL|wx.EXPAND, border=5)
sizer_v.Add(self.label, 0, flag=wx.ALL|wx.EXPAND, border=10)
self.SetSizer(sizer_v)
# show opening result
self.onAction(None)
def onAction(self, event):
""" some action code"""
s = "The result ... \n\n"
# gives integer cents values, convert to …
I hope you understand this better:
def main():
a = 1
b = 2
c = 3
# local variable dictionary
main_var = vars()
print main_var # {'a': 1, 'c': 3, 'b': 2}
# get the key (variable name) of a certain value, for instance 3
mvar = [key for key, val in main_var.items() if val==3][0]
print mvar # c
# in somewhat longer form ...
mvar_list = []
# extract the key:value pairs from the dictionary
for key, val in main_var.items():
# if value is 3 save the key in a list
if val == 3:
mvar_list.append(key)
print mvar_list # ['c']
# pick the first item on the list
print mvar_list[0] # c
main()
A baby cat and a baby rat are called a kitten. Strangely enough, a baby dog and a baby mouse are called a pup.
What do you call an infant llama?
You can input a date the graphical way, let's call it the wxPythonian way, with a simple mouse point and click:
# explore the wx.calendar.CalendarCtrl() control
# allows for point and click date input
import wx
import wx.calendar as cal
class MyCalendar(wx.Dialog):
"""create a simple dialog window with a calendar display"""
def __init__(self, parent, mytitle):
wx.Dialog.__init__(self, parent, wx.ID_ANY, mytitle)
# use a box sizer to position controls vertically
vbox = wx.BoxSizer(wx.VERTICAL)
# wx.DateTime_Now() sets calendar to current date
self.calendar = cal.CalendarCtrl(self, wx.ID_ANY, wx.DateTime_Now())
vbox.Add(self.calendar, 0, wx.EXPAND|wx.ALL, border=20)
# click on day
self.calendar.Bind(cal.EVT_CALENDAR_DAY, self.onCalSelected)
# change month
self.calendar.Bind(cal.EVT_CALENDAR_MONTH, self.onCalSelected)
# change year
self.calendar.Bind(cal.EVT_CALENDAR_YEAR, self.onCalSelected)
self.label = wx.StaticText(self, wx.ID_ANY, 'click on a day')
vbox.Add(self.label, 0, wx.EXPAND|wx.ALL, border=20)
button = wx.Button(self, wx.ID_ANY, 'Exit')
vbox.Add(button, 0, wx.ALL|wx.ALIGN_CENTER, border=20)
self.Bind(wx.EVT_BUTTON, self.onQuit, button)
self.SetSizerAndFit(vbox)
self.Show(True)
self.Centre()
def onCalSelected(self, event):
#date = event.GetDate()
date = self.calendar.GetDate()
day = date.GetDay()
# for some strange reason month starts with zero
month = date.GetMonth() + 1
# year is yyyy format
year = date.GetYear()
s1 = "%02d/%02d/%d \n" % (month, day, year)
# or just take a slice of the first 8 characters to show mm/dd/yy
s2 = str(date)[0:8]
self.label.SetLabel(s1 + s2)
def onQuit(self, event):
self.Destroy()
app = wx.App()
MyCalendar(None, 'wx.calendar.CalendarCtrl()')
app.MainLoop()
Oh the price of petrol!
I just made a back of the envelop calculation from the latest German Automobile Club numbers. As of July 15, 2008 the price of the liter petrol there is 1.55 Euro. The price in the US is $4.25 per gallon. A US gallon is 3.785 liter and the Euro costs US $1.60. It would be nice to make a small Python program to compare the cost of petrol there to the price of petrol in the US.
I calculated the US price to be $1.20 per liter or 0.75 Euro per liter. If you would travel to Germany it would cost you US $9.39 per gallon. Your program ought to spit this out quickly.
You can create a relatively safe numeric input using this function:
def get_num(prompt="Enter a number: "):
"""
the function will loop until a number has been entered,
accepts int or float, returns a float
"""
while True:
try:
return float(raw_input(prompt))
except ValueError:
print "Numeric value required!"
# test it ...
print get_num()
price = get_num("Enter the price: ")
print price
Your mission, should you accept, is to limit the numeric input to a number within a given range.
You can create a relatively safe numeric input with a function:
def get_num(prompt="Enter a number: "):
"""
the function will loop until a number has been entered,
accepts int or float, returns a float
"""
while True:
try:
return float(raw_input(prompt))
except ValueError:
print "Numeric value required!"
print get_num()
print get_num("Enter the price: ")
Here is the most terrifying fact about old people: I'm going to be one soon.
On the other hand, you get the coveted Senior Discount.
Numero Uno place to live in the USA:
Plymouth, Minnesota
Population: 70,100
Topnotch schools, good jobs, affordable housing, low crime, an active outdoor culture, numerous lakes for boaters, water skiers and fishermen. More than 50,000 jobs keep residents employed.
Latest survey by CNN.
According to CNNMoney.com the richest town in the USA is ...
New Canaan, Connecticut
Population: 19,690
Median family income: $231,138
Median home price: $1,465,000
If you have Windows, download the MS installer version of pygame for Python24 from:
http://www.pygame.org/ftp/pygame-1.8.0.win32-py2.4.msi
Local variables are kept in the function's local dictionary which you can access with vars(). To access one function's local dictionary in another function, you have to pass it along:
def my_func(aaa, main_var):
mvar = [key for key, val in main_var.items() if val==aaa][0]
print aaa, main_var, mvar # 123 {'test_var': 123} test_var
def main():
test_var = 123
my_func(test_var, vars())
main()
George W. Bush addressing war veterans:
"You took an oath to defend our flag and our freedom, and you kept that oath underseas and under fire."
Why do people feel that organic vegetables, fertilized with animal dung, are so much healthier?
I read about the rotten cheese story here:
http://news.sbs.com.au/worldnewsaustralia/recycled_cheese_on_supermarkets39_shelves_551143
No pizza for me!
Looks like this particular example shows you that function variables are local to the function.
Will something like this do?
import Tkinter as tk
def set_text_newline(s):
"""start text s on a new line"""
text1.insert(tk.INSERT, '\n' + s)
root = tk.Tk()
# width=width characters, height=lines of text
text1 = tk.Text(root, width=50, height=12, bg='yellow')
text1.pack()
set_text_newline("line one")
set_text_newline("line two")
set_text_newline("line three")
root.mainloop()
I've been talking to Vicente Fox, the new president of Mexico ... to have gas and oil sent to U.S. so we'll not depend on foreign oil...
--George W. Bush
In the High Arctic, the sun sets in October and does not rise again until late February.
Something like this could do it:
mystr = 'Hello everybody. Some times THERE ARE upper case words'
mylist = mystr.split()
#print mylist
newstr = ''
for word in mylist:
if word[0].isupper():
word = word.capitalize()
newstr += word + ' '
print newstr
"""
my output -->
Hello everybody. Some times There Are upper case words
"""
Is Our Children Learning?
Fully 78% of voters cite education as an important issue.
In the last Church Social I met a woman who said she wouldn't vote for Obama because his middle name is Hussein. I asked her what McCain's middle name is, she didn't know!
If only we would stop trying to be happy, we could have a pretty good time.
Question to a Programmer:
"Does your lack of social life result in significant cash reserves?"