Great site!
Read in the news:
English-speaking French Foreign Minister Bernard Kouchner was quoted saying:
"Israel could eat Iran if it wanted to!"
What he meant to say:
"Israel could hit Iran if it wanted to!"
(the h is silent in French)
Great site!
Read in the news:
English-speaking French Foreign Minister Bernard Kouchner was quoted saying:
"Israel could eat Iran if it wanted to!"
What he meant to say:
"Israel could hit Iran if it wanted to!"
(the h is silent in French)
Amazing how a bunch of lines can create a nifty pattern, here is an example using a wxPython canvas and a simple DrawLinePoint() function:
# draw a line pattern using a wx.ClientDC() canvas
# wx.ClientDC() does not use the wx.PaintEvent
import wx
import math
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(600, 400))
self.SetBackgroundColour('white')
# this small millisecond delay is needed
wx.FutureCall(10, self.draw_lines)
def draw_lines(self):
# create the canvas to draw on
dc = wx.ClientDC(self)
# set line colour and thickness (pixels)
dc.SetPen(wx.Pen("red", 1))
# get the width and height of the canvas (the client)
width, height = self.GetClientSizeTuple()
# set the dc origin to the canvas center
dc.SetDeviceOrigin(width//2, height//2)
# note that this point is actually the center of the canvas
point1 = (0, 0)
# calculate the usable radius
radius = math.hypot(width//2, height//2)
# not that the angle is in radians
angle = 0
notch = 4 * math.pi/360
while (angle < 2 * math.pi):
# calculate x and y for each end point
x = radius * math.cos(angle)
y = radius * math.sin(angle)
point2 = (x, y)
dc.DrawLinePoint(point1, point2)
# advance the angle a notch
angle += notch
app = wx.App()
MyFrame(None, 'draw a line pattern with DrawLinePoint()').Show(True)
app.MainLoop()
An example on how to load an image onto a wxPython canvas sized to the image. Also, point the mouse to any part of the image, click and display the color pixel pointed to:
# show an image from a file using a wx.ClientDC() canvas
# any previous image on the canvas can be cleared
# wx.ClientDC() does not use the wx.PaintEvent
# optionally show rgb colour tuple at point (x, y) clicked
import wx
class ImagePanel(wx.Panel):
""" create a panel with a canvas to draw on"""
def __init__(self, parent):
wx.Panel.__init__(self, parent, wx.ID_ANY)
self.parent = parent
# pick an image file you have in your working folder
# (can be a .jpg, .png, .gif, or .bmp image file)
image_file = 'Zingerman1.jpg'
self.bmp = wx.Bitmap(image_file)
image_width = self.bmp.GetWidth()
image_height = self.bmp.GetHeight()
# set frame size (also panel) to image size
parent.SetClientSize((image_width, image_height))
# set special cursor
self.SetCursor(wx.StockCursor(wx.CURSOR_CROSS))
# this small delay is needed to allow image loading first
wx.FutureCall(50, self.make_canvas)
# bind mouse left click event
self.Bind(wx.EVT_LEFT_DOWN, self.onClick)
# optionally show some image information
info = "%s %dx%d (click mouse)" %\
(image_file, image_width, image_height)
# the parent is the frame
self.parent.SetTitle(info)
def make_canvas(self):
self.dc = wx.ClientDC(self)
# clear the canvas
self.dc.Clear()
# draw the image
self.dc.DrawBitmap(self.bmp, 0, 0, True)
def onClick(self, event):
# get (x, y) position tuple
pt = event.GetPosition()
colour = self.dc.GetPixelPoint(pt)
s = "RGB = %s at point %s" % (str(colour[:3]), str(pt))
self.parent.SetTitle(s)
app = wx.App()
# create window/frame
frame = wx.Frame(None, wx.ID_ANY, size=(400, 300))
# create …
The average American voter:
Regex it is just that, regular expression. A pattern describing some text.
Yes we know! How about learning some Python first before giving primitive lectures. We are trying to help people and keep a friendly atmosphere here!
BTW, if you need help with the module re, simply type help(re). Or go to this Python expert:
http://www.amk.ca/python/howto/regex/
Give this a try and see if it works:
import subprocess
subprocess.call()
An oldy but goody, drawing a simple bar graph using thick lines for the bars. The wxPython canvas created with wx.ClientDC() makes this project look easy:
# a simple bar graph using a thick line
# the wx.ClientDC surface is wxPython's canvas
# use wx.ClientDC() without the wx.PaintEvent
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(360, 320))
self.SetBackgroundColour('white')
# data to be graphed
self.data = [30, 45, 80, 150, 220, 180, 110, 75, 50, 35, 25, 15]
# call bargraph() 10 ms after the window has been created
# this small delay is needed
wx.FutureCall(10, self.bargraph)
def bargraph(self):
"""draw a simple bar graph"""
# does not use a wx.PaintEvent
dc = wx.ClientDC(self)
# set line colour and thickness (pixels)
dc.SetPen(wx.Pen('black', 2))
# DrawLine(x1, y1, x2, y2) from point (x1,y1) to (x2,y2)
# draw the baseline
dc.DrawLine(20, 260, 340, 260)
# set up the bars
thick = 20
dc.SetPen(wx.Pen('red', thick))
delta = thick + 5
x = 20
for y in self.data:
y1 = 255
y2 = y1 - y
# draw each bar
dc.DrawLine(x, y1, x, y2)
# add values to the top of each bar
s = str(y)
dc.DrawText(s, x-8, y2-25)
x += delta
app = wx.App()
MyFrame(None, 'draw a simple bar graph').Show(True)
app.MainLoop()
As Phil Gramm, main sponsor of the "Enron Loophole" and good buddy of John McCain so smartly says "Dems are Whiners"
My neighbor brought over a batch of her delicious pinachios, a butter cookie with pistachio nuts and chocolate chips. So I am munching those with my usual hot mug of cappuccino.
I hope that Miss Palin will win the debate! It's time for a woman to be President (nearly).
We are Alaska:
Our size is 586,400 Square Miles
We are 2 times the size of Texas
We have 29 volcanoes
We have 33,000 miles of coastline!
1,400 miles North to South
2,700 miles East to West
We own over 1/2 the world's Glaciers
Just 55 miles east of Russia
Alaska purchased from Russia in 1867 for under 2 cents an acre
We are the only state to have coastlines on three different seas:
Arctic Ocean, Pacific Ocean and Bering Sea.
Record high temperature: 1915 +100F
Record low temperature: Tanana -78F
Record Snow: 974 inches in 1 year in Valdez
Our State Flower is the "Forget-me-not"
Our State Sport is "Dog Mushing"
Anchorage with a population of 277,000 is Alaska's largest city with 42 percent of the state's total population.
print "%-10s --> %-10s" % (poss, word)
"%-10s --> %-10s" is a formatting string where %s is a place holder for a string and %-10s means put the string into a 10 space field left adjusted. Conversely %d is a placeholder for an integer and %10.3f would be a placeholder for a float number putting it into a 10 space field with 3 decimals showing.
Look under % formatting in the manual. It works similar to the C language printf().
A class should only group functions together that belong together. I would also avoid globals, they are devils as your program grows. A class handles globals within the class using self.
You want it real sweet and short?
# add file contents to lists
wordlist = [line.strip() for line in file('wordlist.txt')]
possible = [line.strip() for line in file('possible.txt')]
match_list = []
for poss in possible:
for word in wordlist:
# narrow down the wordlist with len() and set()
if len(poss) == len(word) and set(poss) == set(word):
match_list.append((poss, word))
# show result
print "there are %d matches:" % len(match_list)
for match in match_list:
print "%-10s --> %-10s" % (match)
Pulling all the tricks of Python, but harder to read and understand:
for poss in [line.strip() for line in file('possible.txt')]:
for word in [line.strip() for line in file('wordlist.txt')]:
if len(poss) == len(word) and set(poss) == set(word):
print "%-10s --> %-10s" % (poss, word)
By using set() you can really streamline your code:
# modified to allow testing
wordlistfile = open('wordlist.txt', 'r')
possiblefile = open('possible.txt', 'r')
# add file contents to lists
wordlist = []
possible = []
for line in wordlistfile:
wordlist.append(line.strip())
for line in possiblefile:
possible.append(line.strip())
match_list = []
for poss in possible:
for word in wordlist:
# narrow down the wordlist with len() and set()
if len(poss) == len(word):
if set(poss) == set(word):
# now partial match the characters
count = 0
for c in poss:
if c in word:
count += 1
if count == len(poss):
match_list.append((poss, word))
# show result
print "there are %d matches:" % len(match_list)
for match in match_list:
print "%-10s --> %-10s" % (match)
"""
my result -->
there are 10 matches:
raolns --> larson
1itdalig --> digital1
caeaph --> apache
eeirgg --> reggie
nanajo --> joanna
ahtrru --> arthur
sunatr --> saturn
cc0171n --> ncc1701
rfisedn --> friends
aangle --> angela
"""
There are two "print p" in your code.
Sorry, I left the original
for line in wordlistfile:
wordlist.append(line.strip())
for line in possiblefile:
possible.append(line.strip())
still in the loop. Just remove it. On first blush meant that I didn't test it out, just looked at your code.
Why it doesn't print out 'friends', I don't know.
If you look into Main.py, you find:
def opj(path):
"""Convert paths to the platform-specific separator"""
st = apply(os.path.join, tuple(path.split('/')))
# HACK: on Linux, a leading / gets lost...
if path.startswith('/'):
st = '/' + st
return st
The problem is that the 'wx code demo stuff' is unnecessarily complex on the one side and often very shallow where it counts. It is written by the same guy that wrote the book on wxPython, by all reports a frustrating failure.
If you missed Palin's interview where she is pushing McCain as "The Maverik" and can't come up with even one lousy example, here is some of it:
http://www.youtube.com/watch?v=YDdR7YqWZ8s&feature=user
Also has a great train collision in it.
Good grief, even I know that a watt is the product of voltage and current at any given time. No need to have a per there.
Elementary physics! My boyfriend hates junk science and the people that spread it.
I love Jon Steward's approach to all that spin in the news. This one is a already a classic:
http://www.thedailyshow.com/video/index.jhtml?videoId=186056&title=awkward-loan-interview
Many people here at the hospital have pulled their money out of WaMu bank. Not quite sure were they are going to put it? Maybe bury it in the backyard? Might just as well do that, since the banks hardly pay any interest and the government takes what little there is as income tax. An Asian friend of mine recommends buying real gold jewelry.
On first blush, you need to create your wordlist outside the loop, or you will keep appending to it all the time:
#decode scrambled word from a word list in 30 sec or less.
matches = []
thelist = []
myvar = -1
c = -1
p = -1
wordlistfile = open('C:\\Documents and Settings\\William\\Desktop\\wordlist\\wordlist.txt', 'r')
possiblefile = open('C:\\Documents and Settings\\William\\Desktop\\possible.txt', 'r')
#add file contents to lists.
wordlist = []
possible = []
for line in wordlistfile:
wordlist.append(line.strip())
for line in possiblefile:
possible.append(line.strip())
while p < 9:
i = -1
p = p + 1
print p
for line in wordlistfile:
wordlist.append(line.strip())
for line in possiblefile:
possible.append(line.strip())
#match length of words to narrow possible matches
for line in wordlist:
i = i + 1
if len(wordlist[i]) == len(possible[p]):
matches.append(wordlist[i])
#narrow further by checking for instances of charecters
word = possible[p]
x = len(matches)
while c < x:
c = c + 1
for letter in word:
if c == x:
break
if not letter in matches[c]:
del matches[c]
x = x - 1
#start rearanging word.
word = word.strip().lower()
for pos in matches:
tmp1 = []
tmp2 = []
tmp1 = list(pos.lower().strip())
tmp2 = list(word)
tmp1.sort()
tmp2.sort()
if tmp1 == tmp2:
print p
myvar = myvar + 1
thelist.append(pos)
if myvar == 10:
print(thelist[myvar])
break
elif myvar < 9:
print(thelist[myvar] + ', ')
wordlistfile.close()
possiblefile.close()
Most of you know the song
99 bottles of beer on the wall,
99 bottles of beer!
Take one down, pass it around,
98 bottles of beer on the wall!98 bottles of beer on the wall,
98 bottles of beer!
Take one down, pass it around,
97 bottles of beer on the wall!...
...2 bottles of beer on the wall,2 bottles of beer!
Take one down, pass it around,
1 bottle of beer on the wall!1 bottle of beer on the wall,
1 bottle of beer!
Take one down, pass it around,
No more bottles of beer on the wall!
Your mission is to write the entire lyrics of this song using a Python for loop.
Really we people think of it otherwise we will loose lot of things in future.
You also have to think that we will gain a few things.
When C++ is your hammer, everything begins to look like a thumb.
Alaska is the US state with the highest percentage of people who walk to work.
"I never think of the future. It comes soon enough."
My hero, Albert Einstein
700 Billion Dollars with no strings attached.
More giant taxbreaks.
Easier ways to send my loot to the Caymen Island Banks.
Politicians that give discounts to frequent influence buyers.
"Please don't eat me! I have a wife and kids. Eat them!"
No, it was not GWB that said this, but Homer Simpson
The GUI kit for the C++ folks is wxWindows, entirely written in C++. The Pythonistas made a wrapper of it for Python and called it wxPython. Looks like nobody wanted to get into changing the manual.
"For the things we have to learn before we can do them, we learn by doing them."
What's the alternative? - Christian Serbs fleeing their land, ethnic Albanians burning churches to the ground and the rise of Islamic fundamentalism backed by Saudi money in Kosovo.
Christians against the Muslims, that explains your thinking well.
Wow Sarah Palin without her makeup on!
"I seek constantly to improve my manners and graces, for they are the sugar to which all are attracted."
Eating some Crackers and Peanut Butter and enjoying milk :)
Wow Dude, that will give you the energy to thread more of your usually fine threads.
Just finished some hot cocoa and a pair of scrambled eggs with vanilla toast.
The US government is sending you 1 Billion Dollars, the check is in the mail. :)
The Large Hadron Collider (LHC) has to shut down for two months. There was a large helium leak and they discovered it when everbody started talking like Donald Duck. No science when you act like a duck!
Aha -- I just needed to rtfm a bit more clearly. In the fine print on http://docs.python.org/lib/typesseq-strings.html, it says the alternate form (with the # flag) gives this behavior, so:
>>> print "%#.4g" % 6.340024e-34 6.340e-34
I've been looking for this solution for so long, I'm beside myself right now :)
Thanks for letting all of us know!
Well, not really humor but stupefying sadness and joy:
"One of the most meaningful things that's happened to me since I've been the governor -- the president -- governor -- president. Oops. Ex-governor. I went to Bethesda Naval Hospital to give a fellow a Purple Heart, and at the same moment I watched him--get a Purple Heart for action in Iraq - and at that same - right after I gave him the Purple Heart, he was sworn in as a citizen of the United States - a Mexican citizen, now a United States citizen."
(George W. Bush Washington, DC 1/09/2004)
Canada has no president. Canada's government is a Parliamentary democracy (federal constitutional monarchy) whose Monarch is Queen Elizabeth II. Canada has a Prime Minister.
No one died when Clinton lied. But they did when Yugoslavia got bombed.
http://www.antiwar.com/pilger/?articleid=11421
I don't think Clinton lied when the US Air Force was bombing Yugoslavia. The Yugoslav army was conducting mass murder on the ground!
Darn it, I didn't know we were having fun with our favorite cartoon characters over here.
Let me participate and contribute this piece destine to become a classic.
You must be in the wrong thread, I didn't see any cartoon characters! Well, in the VA Hospital we have learned to help folks, so I will post one for you:
What a poor example of Python, violates all the Zen! There is an outcry for loops and functions.
import this
Marching orders were given!
Looky here, McCane is leading the polls again. Pun is intended.
GrimJack, I am impressed. You are unquestionably the smartest person on this forum!
A rat can last longer without water than a camel can.
Now this is a convoluted piece of Bushism the man presented in Washington, DC on
03/13/2001:
"The true threat is whether or not one of these people decide, peak of anger, try to hold us hostage, ourselves; the Israelis, for example, to whom we'll defend, offer our defenses, the South Koreans."
You may want to use a Device Context widget like the one used in:
http://www.daniweb.com/forums/showpost.php?p=688718&postcount=74
The question came up in the forum how to overlap playing cards in wxPython. Here is one way to do it, using a wx.PaintDC() paint canvas and Blit() to handle the card images on the canvas:
# draw card images on a paint canvas and overlap the cards
# note: the name of the card matches the image file
import wx
import random
class CardPanel(wx.Panel):
""" create a panel with a canvas"""
def __init__(self, parent):
wx.Panel.__init__(self, parent, wx.ID_ANY)
# the subdirectory containing the card image files
self.image_dir = "./cards/"
# create the card list
self.card_list = self.create_cards()
self.button = wx.Button(self, wx.ID_ANY, label='deal a hand',
pos=(10, 120))
# bind mouse event to an action
self.button.Bind(wx.EVT_BUTTON, self.draw_hand)
# set up a paint event on a PaintDC canvas
wx.EVT_PAINT(self, self.on_paint)
def create_cards(self):
"""
create a list of 52 cards
suit: club=C, diamond=D, heart=H spade=S
rank: ace=A, 10=T, jack=J, queen=Q, king=K, numbers=2..9
ace of spade would be SA, 8 of heart would be H8 and so on ...
"""
return [suit + rank for suit in "CDHS" for rank in "A23456789TJQK"]
def shuffle_cards(self):
"""random shuffle a list of cards"""
# make a copy of the original list
card_list1 = self.card_list[:]
random.shuffle(card_list1)
return card_list1
def pick_5cards(self):
"""pick five cards from the shuffled list"""
return self.card_list_shuffled[:5]
def on_paint(self, event=None):
# create the paint canvas
self.canvas_dc = wx.PaintDC(self)
# color the game table top
self.canvas_dc.SetBrush(wx.Brush('dark green'))
# DrawRectangle(x, y, width, height)
self.canvas_dc.DrawRectangle(0, 0, 320, 200)
# pick and draw a random hand of five cards
self.draw_hand() …