Ene Uran 638 Posting Virtuoso

GrimJack is the DW moderator for all facts about every aspect of the human race and other forms of life on Earth and beyond. And if it isn't already, this should be made official.

Did it really take you that long to figure this out?

A startling medical discovery:
Apples are more efficient at waking you up in the morning than caffeine.

Ene Uran 638 Posting Virtuoso

The Mexican lady from next door brought over a nice flan, a Spanish custard with caramel sauce. I am in heaven!

Ene Uran 638 Posting Virtuoso

Write a program that goes through a list or folder of your favorite MP3 music files and playes it in the background.

Ene Uran 638 Posting Virtuoso

The problem is that a lot of those modules you are talking about are freeware and as such a labor of love! Love is just a little slower than greed!

Talking about labor of love, here is one beginning Python tutorial that has already been rewritten for Python30:
http://www.swaroopch.com/notes/Python_en:Table_of_Contents

Ene Uran 638 Posting Virtuoso

Have you tried the module psyco, a JIT compiler for i386 machines?
It compiles to i386 code directly rather than bytecode virtual code.

Here is a typical example, I think vegaseat posted that somewhere:

# time a function using time.time() and a decorator
# uses Psyco JIT i386 compiler to speed up code
# (on my computer 1.2 sec with Psyco, 5.3 sec without)
# download and install psyco-1.6.win32-py25.exe
# from: http://psyco.sourceforge.net/

import time
from psyco import full

# this will apply psyco just in time compile to full code
# (comment out to run the test without psyco)
full()

def print_timing(func):
    def wrapper(*arg):
        t1 = time.time()
        res = func(*arg)
        t2 = time.time()
        print '%s took %0.3fms' % (func.__name__, (t2-t1)*1000.0)
        return res
    return wrapper

# declare the @ decorator just above the function
# invokes print_timing()
@print_timing
def getPrimeList(n):
    """
    returns a list of prime numbers from 1 to < n using a sieve algorithm
    """
    if n < 2:  return []
    elif n == 2: return [2]
    # do only odd numbers starting at 3
    s = range(3, n+2, 2)
    # n**0.5 is slightly faster than math.sqrt(n)
    mroot = n ** 0.5
    half = len(s)
    i = 0
    m = 3
    while m <= mroot:
        if s[i]:
            j = (m*m-3)/2
            s[j] = 0
            while j < half:
                s[j] = 0
                j += m
        i = i+1
        m = 2*i+3
    return [2]+[x for x in s if x]


print "prime numbers from 2 to <10,000,000 …
Ene Uran 638 Posting Virtuoso

... and here is how you would do this with Python:

arr = [12, 7, 9, 25, 87]

for item in arr:
    print(item)

Just to compare the syntax, here is the same thing in C:

#include <stdio.h>

int main()
{
    int arr[] = {12, 7, 9, 25, 87};
    int i;
    
    for(i = 0; i < sizeof(arr)/sizeof(int); i++)
    {
        printf("%d\n", arr[i]);
    }

    return 0;
}
Ene Uran 638 Posting Virtuoso

thanks. Can you suggest some tutorials?, all the ones on the net seem to be outdated and i cant get some of them to work...

Swaroop C.H. has rewritten his excellent beginning Python tutorial online book for Python30:
http://www.swaroopch.com/notes/Python_en:Table_of_Contents

Ene Uran 638 Posting Virtuoso

Swaroop C.H. has rewritten his excellent beginning Python tutorial online book for Python30:
http://www.swaroopch.com/notes/Python_en:Table_of_Contents

Ene Uran 638 Posting Virtuoso

PyMedia is older than the hills and hasn't been updated for a few years!

If you are looking for oldies but goodies there is also:
http://pysonic.sourceforge.net/index.html
It uses the ever so popular FMOD.DLL

In case you missed it, the PyGame module will play MP3 files.

Ene Uran 638 Posting Virtuoso

I think the Canadians are very lucky!

Ene Uran 638 Posting Virtuoso

One way to play music files of the popular MP3 music format, is to use the module pygame. Here is an example that works with a number of music file formats (you got to experiment):

# play a MP3 music file using module pygame
# (does not create a GUI frame in this case)
# pygame is free from: http://www.pygame.org/
# ene

import pygame

def play_music(music_file):
    """
    stream music with mixer.music module in blocking manner
    this will stream the sound from disk while playing
    """
    clock = pygame.time.Clock()
    try:
        pygame.mixer.music.load(music_file)
        print "Music file %s loaded!" % music_file
    except pygame.error:
        print "File %s not found! (%s)" % (music_file, pygame.get_error())
        return
    pygame.mixer.music.play()
    while pygame.mixer.music.get_busy():
        # check if playback has finished
        clock.tick(30)


# pick MP3 music file you have ...
# (if not in working folder, use full path)
music_file = "Drumtrack.mp3"

# set up the mixer
freq = 44100     # audio CD quality
bitsize = -16    # unsigned 16 bit
channels = 2     # 1 is mono, 2 is stereo
buffer = 2048    # number of samples (experiment to get right sound)
pygame.mixer.init(freq, bitsize, channels, buffer)

# optional volume 0 to 1.0
pygame.mixer.music.set_volume(0.8)

try:
    play_music(music_file)
except KeyboardInterrupt:
    # if user hits Ctrl/C then exit
    # (works only in console mode)
    pygame.mixer.music.fadeout(1000)
    pygame.mixer.music.stop()
    raise SystemExit
Ene Uran 638 Posting Virtuoso

You can use module pygame in your program and play MP3 music files without having to create a GUI window:

# play a MP3 music file using module pygame
# (does not create a GUI frame in this case)
# pygame is free from: http://www.pygame.org/
# ene

import pygame

def play_music(music_file):
    """
    stream music with mixer.music module in blocking manner
    this will stream the sound from disk while playing
    """
    clock = pygame.time.Clock()
    try:
        pygame.mixer.music.load(music_file)
        print "Music file %s loaded!" % music_file
    except pygame.error:
        print "File %s not found! (%s)" % (music_file, pygame.get_error())
        return
    pygame.mixer.music.play()
    while pygame.mixer.music.get_busy():
        # check if playback has finished
        clock.tick(30)


# pick MP3 music file you have ...
# (if not in working folder, use full path)
music_file = "Drumtrack.mp3"

# set up the mixer
freq = 44100     # audio CD quality
bitsize = -16    # unsigned 16 bit
channels = 2     # 1 is mono, 2 is stereo
buffer = 2048    # number of samples (experiment to get right sound)
pygame.mixer.init(freq, bitsize, channels, buffer)

# optional volume 0 to 1.0
pygame.mixer.music.set_volume(0.8)

try:
    play_music(music_file)
except KeyboardInterrupt:
    # if user hits Ctrl/C then exit
    # (works only in console mode)
    pygame.mixer.music.fadeout(1000)
    pygame.mixer.music.stop()
    raise SystemExit
Ene Uran 638 Posting Virtuoso

Before the invention of the thermometer, brewers used to check the temperature by dipping their thumb into the still warm extract, to find whether it was appropriate for adding yeast. Too hot, the yeast would die. This is where we get the phrase " The Rule of the Thumb".

Ene Uran 638 Posting Virtuoso

This time of the year I like to add a shot of eggnog to my extra strong brew.

Ene Uran 638 Posting Virtuoso

The problem with socialism is that it does't protect you from financial institutions stealing your money.

Ene Uran 638 Posting Virtuoso

Actually, the guy in the flat next to mine plays the accordion. He is a member of a small Mexican band here in LA. He is darn good, so is his band.

Ene Uran 638 Posting Virtuoso

She will have a few hard nuts to crack in her new role:

Ene Uran 638 Posting Virtuoso

Penut butter and blackberry jelly on toasted whole grain English muffins, plus a steaming hot mug of Santos mild roasted coffee.

Ene Uran 638 Posting Virtuoso

Resolving to surprise her husband, an executive's wife stopped by his office. When she opened the door, she found him with his secretary sitting in his lap.

Without hesitating, he dictated, "...and in conclusion, gentlemen, budget cuts or no budget cuts, I cannot continue to operate this office with just one chair."

Ene Uran 638 Posting Virtuoso

d best business ever will b 2 buy people at what they r realy worth & sell them at what they believe they r worth;)

You must be talking about the milions spent on pro sports folks.

Ene Uran 638 Posting Virtuoso

Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.
-– Dr. Seuss

Ene Uran 638 Posting Virtuoso

My dad has his degree in economics, actually taught it for a few years. He is not really a pessimist, but keeps telling me:

When it comes to emerging markets, Eastern and Central Europe account for $1.6 trillion in loans from G10 countries' banks. Followed by Asia with loans of $1.5 trillion and Latin America with $1 trillion.

If you break down the loan originators, European Union banks and United Kingdom banks are where roughly 50% of these emerging market loans came from. In contrast, only 9% originated from U.S. or Japanese banks.

That means it's European Union and U.K. banks that are much more exposed to emerging economies in Eastern Europe, Asia and Latin America. These banks have a disaster on their hand! Their countries could simply run out of money to bail them out!

No smiles in the US however, if the EU and the UK gets ino trouble, it will find its way back to the USA. We are all linked together.

Happy holidays!

Ene Uran 638 Posting Virtuoso

Dictionary follow a hash order to speed up lookup.

Ene Uran 638 Posting Virtuoso

Enjoy when you can, and endure when you must.

Ene Uran 638 Posting Virtuoso

"It's the Afghan national army that went into Najaf and did the work there."

Spoken by George W. Bush during a joint press conference with Iraqi Prime Minister Ayad Allawi (Washington, DC 09/23/2004)

For those of you that are geography-challenged, Najaf is in Iraq.

Ene Uran 638 Posting Virtuoso

Crown Royal. May go through a lot of that next few weeks.

Is that the stuff that doesn't freeze?

Ene Uran 638 Posting Virtuoso

Fear not those who argue, but those who dodge.

(Marie von Ebner-Eschenbach)

Ene Uran 638 Posting Virtuoso

That dress is fugly! Even on the model it's dreadful.

Is it the dress or is it Obama you hate?

Well, Obama will be around for a while, so you better just drink your feelings into the ground!

Ene Uran 638 Posting Virtuoso

U.S. vice presidential hopeful Sarah Palin fell prey to a Canadian prankster on Saturday when he called her impersonating French President Nicolas Sarkozy and got her to accept an invitation to hunt baby seals.

Ene Uran 638 Posting Virtuoso

This is the mask I am going to wear:

Wow, Rudolph William Louis "Rudy" Giuliani! You might get more than just candies in your treat bag!

Ene Uran 638 Posting Virtuoso

Polls show that the Palin/McCain ticket is closing the gab rapidly and Obama is only a few percent ahead now. This is largely due to voters discovering that Sarah Palin has a heart of gold and means what she says.

She protects the unborn.
She will bring back family values.
Make sure that every child has a father.
She will not take away our guns.
She is pro Christianity.
She supports the all important creation approach.
She will ban witchcraft.
She will not tax away your wealth.
Enemies of the US better be worried.
Countries that are not with us will suffer.
She will get and kill Osama.
She will make hockey the true American sport it is.

The word "gab" must be a Freudian slip. You forgot to mention that she has healed many inhibited Republican males from ED.

It would be nice if she protected the born and unborn from having to pay off the huge national debt, close to $12 trillion and growing.

Ene Uran 638 Posting Virtuoso

By giving incentives to the father of the child to marry the mother.

Well, one incentive would be to hold a shotgun on the father's head and perform and old fashioned shotgun wedding.

Or perhaps, "We will give you a small taxfree plumbing business, if you marry this pregnant woman."

Ene Uran 638 Posting Virtuoso

Over 75 percent of white Americans own their home, and less than 50 percent of Hispanos and African Americans don't own their home. And that's a gap, that's a homeownership gap. And we've got to do something about it.
--George W. Bush

Ene Uran 638 Posting Virtuoso

To be honest I cannot tell you why I believe what I believe accept that certain events have happened in my life to sway me in that direction. I know that it is extremely far fetched but, until the required evidence is found, no more far fetched than Evolution


What I meant to say was an unproven assumed axiom. Why does the government consider this OK to be taught in school over any other religion, because it came from a scientific theory? How can this be a requirement in school when it has just as many holes as any other religion?

Let me ask you a question. Can you explain Evolution to someone without including the word "Believe"? I'll say not, because that is all that it is at this point is a belief.

Stop hijacking threads and start your own!

Ene Uran 638 Posting Virtuoso

I shot one in Army Cadets. It was fun.

Did you actually kill something, like a deer, moose, sheep, enemy?

Ene Uran 638 Posting Virtuoso

GOOD GRIEFNESS! This is much too rangy of a test!

Ene Uran 638 Posting Virtuoso

You Are 40% British

You're about as British as a half hearted Anglophile... in other words, a piss poor Brit.
If you are indeed from Britain, you probably consider yourself a European more than anything else.

If you're trying to pass for a Brit, you're going to have to try a little harder.
Go to a football match. Drink until you puke. And head in to work the next morning totally hungover.

Ene Uran 638 Posting Virtuoso

For a child to go hunting and shoot a real gun is a good and wholesome experience.

Ene Uran 638 Posting Virtuoso

And... I'm done.

300. :mrgreen:

Congratulations are in order!

Ene Uran 638 Posting Virtuoso

Without some regulation the internet will selfdestruct just like the financial crisis showed. Criminal elements will simply take over.

Ene Uran 638 Posting Virtuoso

I mean, if you've ever been a governor of a state, you understand the vast potential of broadband technology, you understand how hard it is to make sure that physics, for example, is taught in every classroom in the state. It's difficult to do. It's, like, cost-prohibitive.
--George W. Bush

Ene Uran 638 Posting Virtuoso

Cute cartoon:

Ene Uran 638 Posting Virtuoso

Use my credit card all the time, but I pay up before the money is due.

Ene Uran 638 Posting Virtuoso

Looks like this time around when you sling mud you just lose votes!

Ene Uran 638 Posting Virtuoso

SEN. JOHN MCCAIN, (R), PRESIDENTIAL CANDIDATE:
"You know what they forgot? They forgot to let you decide. My friends, we have got them just where we want them."

The voting public in the USA:
A new national poll suggests that only a quarter of Americans think things are going well in the country, while the rest of those questioned are angry, scared and stressed out. Seventy-five percent of those surveyed in a CNN/Opinion Research Corp. poll released today said things are going badly in the United States

Ene Uran 638 Posting Virtuoso

As luck would have it, I am not a Klingon Warrior. I understand the Klingon programmers are now starting to use C, without comments and indentations, as their macho language. :)

Ene Uran 638 Posting Virtuoso

Here is a general example you can adopt, let us know if it works for your case:

# using module subprocess to pass arguments to and from an
# external program

import subprocess

# put in the corresponding strings for
# "mycmd" --> external program name
# "myarg" --> arg for external program
# several args can be in the list ["mycmd", "myarg1", "myarg2"]
# might need to change bufsize
p = subprocess.Popen(["mycmd", "myarg"], bufsize=2048, shell=True,
    stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)

# allow external program to work
p.wait()

# read the result to a string
result_str = p.stdout.read()
bugmenot commented: Good post, well commented, although not exactly what I was looking for ;) +2
Ene Uran 638 Posting Virtuoso

You can use module subprocess and Popen() to pass arguments to and from external programs.

Ene Uran 638 Posting Virtuoso

You could use Hide() and Show(), or, if the frames are equal in size, position them on top of each other:

# create two frames with wxFrame, only one is showing

import wx

class Frame1(wx.Frame):
    def __init__(self, parent, mytitle):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle)
        self.SetBackgroundColour("green")
        # pass frame1 to frame2 as instance self
        self.frame2 = Frame2(None, 'Frame1', self)

        # create input widgets
        self.button1 = wx.Button(self, wx.ID_ANY, label='Frame2')
        self.button2 = wx.Button(self, wx.ID_ANY, label='Button2')
        self.button3 = wx.Button(self, wx.ID_ANY, label='Button3')
        # bind mouse event to an action
        self.button1.Bind(wx.EVT_BUTTON, self.button1Click)

        # use a box sizer to lay out widgets
        sizer_v = wx.BoxSizer(wx.VERTICAL)
        # Add(widget, proportion, flag, border)
        sizer_v.Add(self.button1, 0, flag=wx.ALL, border=10)
        sizer_v.Add(self.button2, 0, flag=wx.ALL, border=10)
        sizer_v.Add(self.button3, 0, flag=wx.ALL, border=10)
        self.SetSizer(sizer_v)

        # size the frame so all the widgets fit
        self.Fit()

    def button1Click(self, event):
        """button1 has been left clicked"""
        # self is instance frame1
        self.Hide()
        self.frame2.Show()


class Frame2(wx.Frame):
    def __init__(self, parent, mytitle, frame1):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle)
        self.SetBackgroundColour("brown")
        self.frame1 = frame1

        # create input widgets
        self.button1 = wx.Button(self, wx.ID_ANY, label='Frame1')
        self.button2 = wx.Button(self, wx.ID_ANY, label='Button2')
        self.button3 = wx.Button(self, wx.ID_ANY, label='Button3')
        # bind mouse event to an action
        self.button1.Bind(wx.EVT_BUTTON, self.button1Click)
        # responds to exit symbol x on frame2 title bar
        self.Bind(wx.EVT_CLOSE, self.button1Click)

        # use a box sizer to lay out widgets
        sizer_v = wx.BoxSizer(wx.VERTICAL)
        # Add(widget, proportion, flag, border)
        sizer_v.Add(self.button1, 0, flag=wx.ALL, border=10)
        sizer_v.Add(self.button2, 0, flag=wx.ALL, border=10)
        sizer_v.Add(self.button3, 0, flag=wx.ALL, border=10)
        self.SetSizer(sizer_v)

        # size the frame so all the widgets fit
        self.Fit()

    def button1Click(self, event):
        """button1 has been left clicked"""
        # self is instance frame2
        self.Hide() …
Ene Uran 638 Posting Virtuoso

Python? That is for children. A Klingon Warrior uses only machine code, keyed in on the front panel switches in raw binary.