ZZucker 342 Practically a Master Poster

In the latest news:
Long-brewing tensions between GOP vice presidential candidate Sarah Palin and key aides to Sen. John McCain are spilling out in public. Several McCain advisers have suggested to CNN that they have become increasingly frustrated with Palin "going rogue," and some advisers say they wonder if the incidents in which she has gone off message were deliberate.

ZZucker 342 Practically a Master Poster

A nobleman decided to march in the holy crusades against the muslims. Concluding that his wife should wear a chastity belt while he is gone, he locks up her nether regions and gives the key to his best friend. He tells him, "If I do not return within four years, unlock my wife and set her free to live a normal life."

So, the husband leaves on horseback and about a half hour later, he sees a cloud of dust behind him. He waits for it to come closer and sees his best friend. "What's wrong," he asks.

"You gave me the wrong key!"

ZZucker 342 Practically a Master Poster

Me and many of my friends are getting a little tired of McCain telling us that he is a maverick, and that this maverickness seemingly is the only thing that differentiates him from Bush. He fails to tell what all is maverickness is about. A real maverick would have voted 90% of the time against Bush rather than with Bush.

ZZucker 342 Practically a Master Poster

Well, happy scary Halloween to everyone! I usually take my sister's kids to collect large amounts of candy in one of the filthy rich LA neighborhoods.

ZZucker 342 Practically a Master Poster

That is a pretty old book. The BOA IDE and wxPython have changed quite a bit since then.

Without your code, help would be hard to give.

ZZucker 342 Practically a Master Poster

I don't see a class in your code.

ZZucker 342 Practically a Master Poster

I haven't had too many problems with wxPython programs on Vista, but the OS has screwed me up in many other ways. Whenever I can I use an older XP machine.

Maybe you can relax the super childish default security scheme they use to a lower level?

ZZucker 342 Practically a Master Poster

Sometimes a test print will help you visualize what is going on:

def insertion_sort(qq):
    for j in range(1, len(qq)):
        key = qq[j]
        i = j - 1
        while (i >=0) and (qq[i] > key):
            qq[i+1] = qq[i]
            i = i - 1
        qq[i+1] = key
        # test print ...
        print qq

x = [65,88,2,9876,33,8]

insertion_sort(x)

print '-'*25

print x

"""
my output --->
[65, 88, 2, 9876, 33, 8]
[2, 65, 88, 9876, 33, 8]
[2, 65, 88, 9876, 33, 8]
[2, 33, 65, 88, 9876, 8]
[2, 8, 33, 65, 88, 9876]
-------------------------
[2, 8, 33, 65, 88, 9876]
"""

Just a note, I would reserve capitalized names for classes or global constants. Also, insertion sorts are pretty slow and inefficient when compared to merge and quick sorts.

ZZucker 342 Practically a Master Poster

Wow BearofNH, the Auberge Pyrenees-Cevennes of Python.

ZZucker 342 Practically a Master Poster

Recursive means that the function calls itself, and it does so in line 4.
In Gribouillis's code it does so in line 8.

ZZucker 342 Practically a Master Poster

Spread the wealth, the way it should be done...

ZZucker 342 Practically a Master Poster

Here is another way you can skin it:

def sum_cube(n, sum=0):
    if n > 0:
        x = n**3
        return sum_cube(n-1, sum+x)
    else:
        return sum

print sum_cube(5)  # 225
ZZucker 342 Practically a Master Poster

You can use the module inspect:

import inspect

class C1(object):
    def __init__(self):
        print "C1"
    def f1(self):
        print "f1"
        pass
    def f2(self):
        print "f2"
        pass

inst1 = C1()

try:
    print inspect.ismethod(inst1.f1)  # True
    print inspect.ismethod(inst1.f2)  # True
    print inspect.ismethod(inst1.f3)  # 'C1' object has no attribute 'f3'
except AttributeError, error:
    print error
ZZucker 342 Practically a Master Poster

One more way for the fun of it:

import random

let = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g' ]
random.shuffle(let)

while len(let):
    print let.pop()
ZZucker 342 Practically a Master Poster

If you reprogram her, it wll last a day.
If you teach her how to program, ........
(she will reprogram you)

ZZucker 342 Practically a Master Poster

Doing nightshift, so it is a toasted butter bagel and orange juice for me.

ZZucker 342 Practically a Master Poster

Who cares what she says, she is so much better looking than Joe Biden or even GI JOE. Who would be scared of something that pretty and charming. Also, she knows how to use her guns safely.

ZZucker 342 Practically a Master Poster

This bites too!

ZZucker 342 Practically a Master Poster

He should be the vice pres again, kind of like him ....

ZZucker 342 Practically a Master Poster

Florida Voter Fraud uncovered:

ZZucker 342 Practically a Master Poster

Eddie's first-grade class was having a game of "Name That Animal". The teacher held up a picture of a cat and asked, "What animal is this?"

"A cat!" said Suzy.

"Good job! Now, what's this animal?"

"A dog!" said Ricky.

"Good! Now what animal is this?" she asked, holding up a picture of a deer.

The class fell silent. After a couple of minutes, the teacher said, "It's what your mom calls your dad."

"A horny bahstard!" called out Eddie.

ZZucker 342 Practically a Master Poster

Afghanistan is the most daring and ambition mission in the history of NATO.
--George W. Bush

I just read in the news that some bomber on a bicycle blew up a German armored vehicle in Afghanistan. There were quite a number of dead. A bicycle vs. an armored car?

ZZucker 342 Practically a Master Poster

This should eventually work:

class MainFrame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, title = 'Sentence Generator',
                pos = (200, 75), size = (WINDOW_WIDTH, WINDOW_HEIGHT))			
        
        self.background = wx.Panel(self)

        self.makeBtn = wx.Button(self.background, label = 'Make') 
        self.makeBtn.Bind(wx.EVT_BUTTON, self.displaySentence)
        
        self.resultBox = wx.TextCtrl(self.background, style = wx.TE_READONLY | wx.TE_MULTILINE)
        
        self.hBox = wx.BoxSizer()
        self.hBox.Add(self.resultBox, proportion = 1, border = 0)
        
        self.hBox.Add(self.makeBtn, proportion = 0, border = 0)
        
        self.vBox = wx.BoxSizer(wx.VERTICAL)
        self.vBox.Add(self.hBox, proportion = 0, flag = wx.EXPAND, border = 0)
        self.vBox.Add(self.result, proportion = 1, flag = wx.EXPAND, border = 0)
        
        self.background.SetSizer(self.vBox)
        self.Show()

    def displaySentence(self, event):
        # looks like result is a list of sentences
        result = self.makeSentence(part1, part2, part3)
        # join the list to a string of sentences
        s = "".join(result)
        # this needs a string
        self.resultBox.SetValue(s)
            
    def makeSentence(self, part1, part2, part3, n=1):
        """return n random sentences"""
        #convert to lists
        p1 = part1.split('\n')
        p2 = part2.split('\n')
        p3 = part3.split('\n')
        #shuffle the lists
        random.shuffle(p1)
        random.shuffle(p2)
        random.shuffle(p3)
        #concatinate the sentences
        sentence = []
        for k in range(n):
            try:
                s = p1[k] + ' ' + p2[k] + ' ' + p3[k]
                s = s.capitalize() + '.' + '\n'
                sentence.append(s)
            except IndexError:
                 break
        # a list of sentences
        return sentence
ZZucker 342 Practically a Master Poster

Never heard that said about him before :D lol

You mean he put up the picture that came with his wallet?

ZZucker 342 Practically a Master Poster

Yeah vega, VPython is an interesting module for 3D modeling (free too). I played around with it and came up with this:

import visual as vs

vs.scene.width = 500
vs.scene.height = 500
vs.scene.title = "draw a cone on a ring (drag with right mouse button)"
# avoid autoscale (autoscale default=True)
vs.scene.autoscale = False

ring = vs.ring(pos=(0,0,0), axis=(8,0,-3), radius=5)
ring.color = (1.0, 1.0, 0.5)
# thickness of ring by default is 1/10th of radius
ring.thickness = 0.3

cone = vs.cone(pos=(0,5.7,0), axis=(0,-1,0), radius=1.8)
cone.color = (0.75, 1.0, 0.2)
Gribouillis commented: wow! +1
ZZucker 342 Practically a Master Poster

Here is an example of re module's sub():

import re

# replace all ;,. characters with _
p = re.compile(r'[;,.]')
s = 'hi;your,face.is;on,fire'
print p.sub('_', s)  # hi_your_face_is_on_fire

or:

import re

s = 'abc123'

p = re.compile("[a-z A-Z]")
# subbing with an empty string "" amounts to strip
print p.sub("", s)  # 123
ZZucker 342 Practically a Master Poster

I hope the cheese is not made in China.

ZZucker 342 Practically a Master Poster

Choose to think for yourself rather than letting someone else do it for you.

That does not sound very devout and pious.

ZZucker 342 Practically a Master Poster

A NASCAR driver's jacket.

ZZucker 342 Practically a Master Poster

Don't go to just any church, go to Catholic Church!

I agree! My church has helped me many times when I was down.

ZZucker 342 Practically a Master Poster

Thanks for the article Grim.
Now that stuff smaks of true voter fraud.

I got one of those automated calls from the RNC this morning, telling me that Obama is a terrorist. I feel urinated on! My vote is going somewhere else this year.

Well, when you hang around with terrorist, you are most likely one too! Just listen to Sarah Palin, she tells the truth.

ZZucker 342 Practically a Master Poster

Meatloaf with tomato-laced gravy and whipped potatoes. All I could find for breakfast!?

ZZucker 342 Practically a Master Poster

I played with toy guns, real guns and i turned out fine.

I trust your mom thinks so too.

ZZucker 342 Practically a Master Poster

Hehe, my English is good? I hope you mean capitalization. Just smile, you could be the British Bush, "bushing" the proper language. Just "funnen" you! :)

Take it easy HiHe. When you are as cute as young jbennet, than any "bushin" of the English language can be forgiven!

ZZucker 342 Practically a Master Poster

According to Fox News Senator John McCain has clearly won the third debate against that one.

ZZucker 342 Practically a Master Poster

Who is the true Sarah Palin?

Pretty flattering picture, but Sarah Palin does not have blue hair!

Sarah Palin is not a fraud, she has increased the taxes on the oil companies, and has handed this money as a gift to every resident of Alaska. She is very popular up there!

ZZucker 342 Practically a Master Poster

No diet will remove all the fat from your body because the brain is entirely fat. Without a brain you might look good, but all you could do is run for public office.

ZZucker 342 Practically a Master Poster

Well, Sarah Palin is much like Ronald Reagan, who was an actor too! He made a wonderful super conservative president.

ZZucker 342 Practically a Master Poster

Great music to dance to!

ZZucker 342 Practically a Master Poster

Spiritual healing using some form of art has its place. There is alot more to healing than the usual "take three aspirins and go to bed" and here is my bill for $147.

Marshal Art is very Spiritual too:
http://www.metacafe.com/watch/739631/marshal_art/

ZZucker 342 Practically a Master Poster

Take the kids to a range. Let 'em shoot.

I agree, this great country needs soldiers.

ZZucker 342 Practically a Master Poster

We hate some persons because we do not know them; and will not know them because we hate them.

I wish you would keep your political comments to yourself. Sarah Palin does have a lot more then hate in her rally speeches.

ZZucker 342 Practically a Master Poster

I saw a couple of Cavuto's Faux Snooze polls in senior citizens centers:
Who would vote for McCain? - 5 or 6 hands up
Who would vote for Obama? - about 20 or so hands go up.
Cavuto say - there you have it, evenly split.

Folks in the background are begin laughing at him.

The older seniors couldn't raise their hand fast enough, eventually there would have been another 20 or so going for McCain.

GrimJack commented: Don't put words in our seniors' mouths -1
ZZucker 342 Practically a Master Poster

The 'neocons' are the heart, soul and brain of the conservative movement in the US. After all, they are the ones that picked the ultimate perfect Conservatiive Sarah Palin.

Very well said, I simply adore Sarah! You have defined the heart, soul and brain of the conservative party, but the bread and butter of this great organization is Christianity, well represented by George Bush who prays for this country every morning, and of course oil and guns, here Dick Cheney does an admirable job. I am sure Sarah will easily take over that responsibility.

ZZucker 342 Practically a Master Poster

Good morning! Welcome to DaniWeb!

ZZucker 342 Practically a Master Poster

There are tricky computer languages and there are nice ones. Which one are you taking?

ZZucker 342 Practically a Master Poster

A farmer had 3 beautiful daughters who were getting ready to go out on dates.

The first beau came to the door and said, ''I'm Eddie, I'm here to pick up Betty. We're going for spaghetti, is she ready?"

"No," the farmer said.

The second beau came to the door and said, ''I'm Joe, I'm here to pick up Flo to take her to the show. Is she ready to go?''

"No."

The third beau came to the door and said to the farmer. ''Hello, my name is Chuck.''

The farmer shot Chuck.

ZZucker 342 Practically a Master Poster

Let's say you want to extract the text between two given words. Here is one way, at first we look at it step by step, and then we combine all the steps to one line of code:

# find the text between two given words

str1 = "the quick brown fox jumps over the lazy dog."
word1 = "the"
word2 = "fox"

# do it one step at a time ...

# first split
part1 = str1.split(word1, 1)

print part1         # ['', ' quick brown fox jumps over the lazy dog.']
print part1[-1]     # ' quick brown fox jumps over the lazy dog.'

# second split
part2 = part1[-1].split(word2, 1)

print part2         # [' quick brown ', ' jumps over the lazy dog.']
print part2[0]      # ' quick brown '

print '-'*40

# combine it all ...

print str1.split(word1, 1)[-1].split(word2, 1)[0]  # ' quick brown '
vegaseat commented: very nice code +10
ZZucker 342 Practically a Master Poster

In your code source is not a list or tuple. You can use a helper print source to look at it.

ZZucker 342 Practically a Master Poster

I watched the last presidential debate with a room full of veterans. However, when "My Friends" McCain made General David Patreus the Chairman of the Joint Chiefs of Staff, there were some gasps. Folks were wondering how much McCain really knows about the military, particularly since the real Chairman of the Joint Chiefs of Staff is Navy Admiral Michael Mullen.