sneekula 969 Nearly a Posting Maven

Every now and then Vista comes up with a "Program Compatability Assistant" popup window (see image) when you want to run a .exe file.

If you make the mistake, like I did, and agree with the Administrator option, then from hence foreward everytime you want to run this particular executable the screen goes grey and another popup appears that asks you to allow this program. Really slows things down, frigging annoying, and seemigly no way to reverse this thing!

Does anyone know how to get out of this jail?

sneekula 969 Nearly a Posting Maven

wxPython is much simpler to distribute than PyGTK/GTK (which is a bear for Windows customers).

The other important thing is that the users of PyGTK/GTK are much smaller in number than the users of Tkinter or wxPython. So, if you need PyGTK help, good luck!?

sneekula 969 Nearly a Posting Maven

Try something along that line:

# can be used for Python25/26

def int2bin(num, bits):
    """
    returns the binary of integer num, using bits
    number of digits, will pad with leading zeroes
    """
    bs = ''
    for x in range(0, bits):
        if 2**x == 2**x & num:
            bs = '1' + bs
        else:
            bs = '0' + bs
    return bs


image_file = "red.jpg"  # a testfile

try:
    # read all data into a string
    data = open(image_file, 'rb').read()
except IOError:
    print "Image file %s not found" % image_file
    raise SystemExit

bit_list = []
# create a list padded bits
for ch in data:
    # take the int value of ch and convert to 8 bit strings
    bits8 = int2bin(ord(ch), 8)
    bit_list.append(bits8)

print(bit_list)

"""
my result -->
['11111111', '11011000', '11111111', '11100000', '00000000', ... ]
"""

Sorry about the baddy!

sneekula 969 Nearly a Posting Maven

I assume you mean something simple like this:

# extract the numeric value before the word 'DIFFERENCES'

text = """\
FILE A HAS 2266 LINES OF WHICH 951 WERE IGNORED
FILE B HAS 2193 LINES OF WHICH 878 WERE IGNORED
THERE WERE 2 DIFFERENCES"""

word_list = text.split()
print(word_list)

for ix, word in enumerate(word_list):
    if word.upper() == 'DIFFERENCES':
        # the diff value is just before 'DIFFERENCES'
        diff = int(word_list[ix-1])

print(diff)  # 2
Gribouillis commented: The simpler, the better! +2
sneekula 969 Nearly a Posting Maven

Just in time for April first!

sneekula 969 Nearly a Posting Maven

Pork, red potatoes and peas.

sneekula 969 Nearly a Posting Maven

They have been making diamonds from carbon under those conditions for 20 or more years. Not sure why they would use peanut butter - diamonds are pure crystalline carbon and peanut butter would have too many impurities to be of any use.

Well you know, there is all this contaminated peanut butter sitting around after the Peanut Corporation of America has stopped their filthy production lines.

sneekula 969 Nearly a Posting Maven

Well, the laptop is brand new, so it's the first and only version I've installed. Is there anywhere I can download the missing .dll?

Did you check the directory for base.pyd? Is it really missing? You could try to reinstall it.

My C:\Python26\Lib\site-packages\pygame directory contains a huge amount of .dll and .pyd files. Chances are that more than just one is missing. Maybe you could copy the whole directory from a friend with an XP machine.

sneekula 969 Nearly a Posting Maven

I assume that you installed PyGame with:
pygame-1.8.1release.win32-py2.6.msi

The missing DLL seems to be base.pyd and it should be in your directory C:\Python26\Lib\site-packages\pygame

Vista on occasion does screwy things when installing, depending on your security settings. It does not like DLLs and sometimes does not install them, but also does not let you know.

I tried some simple PyGame programs with Python26 on my Vista machine and they seem to work.

Also, did you have Pygame version 1.7.1 installed previously?
There is a note in their download page to remove it completely, since they have changed installers and the versions will clash.

sneekula 969 Nearly a Posting Maven

Welcome to the wonderful world of Python programming. Just a note, avoid using function and module names for variable names. There are times when it will bite you.

sneekula 969 Nearly a Posting Maven

The total outstanding credit card debt in the US is equal to its GDP.

Much of the taxpayer money given to AIG is used to help foreign banks, AIG keeps this list secret.

sneekula 969 Nearly a Posting Maven

I am enough of an artist to draw freely upon my imagination.
~~~ Albert Einstein, (03/14/1879 - 04/18/1955)

Notice that pi-day (March 14) is coming up soon!

sneekula 969 Nearly a Posting Maven

The following statement used to be true:
"More Monopoly money is printed in a year, than real money printed throughout the world."

sneekula 969 Nearly a Posting Maven

It is the got-to-have-it-today mentality of the US consumers that elected our politicians. Why are we surprised that any solution coming from Washington is all about spending too much and saving too little.

sneekula 969 Nearly a Posting Maven

The US Consumer Confidence Index has fallen to less than 25%, the lowest ever (well at least since 1967).

The good news is that the sales of US gun manufacturers have shot up! There is still confidence in guns?

sneekula 969 Nearly a Posting Maven

Here is proof that there is no evolution:

They say that we only ever use 12% of our brain. The other half is never used.

With evolution we would use 100% of our brain.:)

sneekula 969 Nearly a Posting Maven

Double negatives are a no-no.

sneekula 969 Nearly a Posting Maven

We all know that Obama has made it clear that he is going to make restrictions on outsourcing businesses. If implemented then that means trouble for many countries that relies on outsource businesses like call centers and other businesses. Do you think it’s a sound decision made by him?

Judging from that, I think he means outsourcing work to other countries.

The best way to fight drugs is to remove the user.

The best way to fight outsourcing is to remove the consumer?

sneekula 969 Nearly a Posting Maven

Using the present policies, I would say no!
The folks who ran the banks for many years are still robbing them with bonuses and awards they voted for themselves. These things are simply not performance based, or they would go way negative!

The next big shoe to drop will be the Credit Cards!

If we ever come out of this mess that was many years in the making, we will see a mildly different world. A few things that will change:

Cars and expressways are the transportation solution.
A home is a good investment.
It is easy to find a new job locally.
There is too much farmland, let's pave it over with malls and streets.
Life in the suburb is nice and crime free.
The police will protect my wealth.
The stockmarket will go up over the long run.
The folks that run a bank deserve their bonuses and awards.
My credit rating is high and will always be that way.
My health care is good and will always be good.
Pension funds will take care of my old age needs.
Social Security is fundamentally sound.
My children will have a better life than I do.

sneekula 969 Nearly a Posting Maven

The myth that you ought to own your house and improve it all the time has made banks rich. However, if there is an economic downturn, it makes life miserable for many home owners.
1. Many homes are now of less value than their mortgage.
2. Lose your job and you are stuck in the location, can't sell the thing.
3. People that have used the home equity as a piggy bank are in a mess.
4. Property taxes on your home will likely increase, as states run out of money.

Folks that rented can easily move to where the few jobs are.
You might want to read up on very timely ideas that the futurist Richard Florida has published. Just Google and though shall find.

sneekula 969 Nearly a Posting Maven

Lots of people eat dog poop and know one knows why.

I don't eat it, and don't know anybody that eats it. I do step in it on occasion, that is disgusting enough!

Gerryx1 commented: Humourous and friendly. +3
sneekula 969 Nearly a Posting Maven

Just a question, what is your operating system?

Vista sometimes gets on a silly security trip and simply does not install certain .dll and .pyd files. The nasty thing about it, it doesn't tell you!

sneekula 969 Nearly a Posting Maven

Just a note, the RS232 serial port is quickly disappearing on most newer computers. Has anyone worked with a USB port?

sneekula 969 Nearly a Posting Maven

Is Python30 really slower than Python25?
I used a little timing decorator to give it a test:

# time relatively time consuming functions
# with a decorator function
# apply the decorator right above the function
# you want to time, starting with a @
# works with Python25 and Python30
# (use module timeit for faster function)

import time

def print_timing(func):
    """set up a decorator function for timing"""
    def wrapper(*arg):
        t1 = time.time()
        res = func(*arg)
        t2 = time.time()
        print('%s took %0.3f ms' % (func.__name__, (t2-t1)*1000.0))
        return res
    return wrapper

@print_timing
def get_primes(n):
    """
    standard optimized sieve algorithm to get a list
    of prime numbers from 2 to < n, prime numbers are
    only divisible by unity and themselves
    (1 is not considered a prime number)
    """
    if n < 2:  return []
    if n == 2: return [2]
    # do only odd numbers starting at 3
    s = list(range(3, n+1, 2))
    # n**0.5 simpler than math.sqr(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 += 1
        m = 2*i+3
    # skip zero items in list s
    return [2]+[x for x in s if x]


print( "prime numbers from 2 to <10,000,000 using a sieve algorithm")
prime_list = get_primes(10000000)
print('-'*50)
print("test print just the first 15 primes:")
print(prime_list[:15])
print("... and the last 5 primes:")
print(prime_list[-5:])

"""
my result …
sneekula 969 Nearly a Posting Maven

If you watched the response given by the Governor of Louisiana a few days ago, you wonder if there is evolution.

Ancient Dragon commented: LOL I agree :) +36
sneekula 969 Nearly a Posting Maven

Always remember you're unique, just like everyone else.

sneekula 969 Nearly a Posting Maven

Just a note, since count() is a builtin Python function, avoid using it for your own function name. Use something like mycount().

sneekula 969 Nearly a Posting Maven

Looks like the book made a mild error to confuse the student, the output will be in the hash order of the dictionary, so don't worry.

sneekula 969 Nearly a Posting Maven

Interesting assignment, with an excellent explanation by the teacher. Would be nice to know what table.csv roughly looks like.

Should be relatively simple yet challenging to solve. Just a note, don't use l1, l2, l3 ... for variable names, they look too much like the numbers 11, 12, 13 ...

sneekula 969 Nearly a Posting Maven

I need to convert a number (in decimal form) that is between 1 to 4999 to Roman Numeral Form. However, though the code I have is kinda working, its only outputting the thousand digit, not anything less or any part thats less.

def int2roman(number):
    numerals={1:"I", 4:"IV", 5:"V", 9: "IX", 10:"X", 40:"XL", 50:"L",
              90:"XC", 100:"C", 400:"CD", 500:"D", 900:"CM", 1000:"M"}
    result=""
    for value, numeral in sorted(numerals.items(), reverse=True):
        while number >= value:
            result += numeral
            number -= value
        return result
print int2roman(input("Enter a number (1 to 4999) in decimal form: "))

if I input 1994, I get M instead of the MCMXCIV I should be getting. Any corrections and explanations to my code?
Thanks :)

You are almost there, your return statement needs to be outside the for loop.

def int2roman(number):
    numerals={1:"I", 4:"IV", 5:"V", 9: "IX", 10:"X", 40:"XL", 50:"L",
              90:"XC", 100:"C", 400:"CD", 500:"D", 900:"CM", 1000:"M"}
    result=""
    for value, numeral in sorted(numerals.items(), reverse=True):
        while number >= value:
            result += numeral
            number -= value
    return result

print int2roman(input("Enter a number (1 to 4999) in decimal form: "))

Sorry, didn't see Pen's early response.

sneekula 969 Nearly a Posting Maven

Oh well actually I had to use functions to do this lesson, otherwise I would fail.

In this case, interesting approach! You won't see functions written within an if statement very often.

sneekula 969 Nearly a Posting Maven

I am not sure why you make it so complicated. Anybody with a basic knowledge of Python would code it this way:

while True:
    print "Hello, how are you?"
    language=raw_input("Pick a language: french, german, hungarian, dutch: ")
    if language == "french":
        print"Bonjour, comment allez-vous?"

    elif language == "german":
        print"Hallo, wie geht es Ihnen?"

    elif language == "hungarian":
        print"Szia, hogy vagy?"

    elif language == "dutch":
        print"Hello, hoe zijn u?"
    
    else:
        break
sneekula 969 Nearly a Posting Maven

Generally you use a while loop you can break out of when done. I would use functions and pass arguments to streamline your code:

# random_game.py

import random

def dieroll():
    randomnumber = random.randrange(10)+1
    return randomnumber

def get_spouse(spouse):
    print "Enter the name of three people you could marry: "
    name1 = raw_input("Name1: ")
    spouse[0]= name1
    name2 = raw_input("Name2: ")
    spouse[1]= name2
    name5 = raw_input("Name3: ")
    spouse[2]= name5
    print "Enter the name of one person you wouldn't want to marry:"
    name4 =raw_input("Name4: ")
    spouse[3]= name4
    return spouse

def get_car(car):
    print "Enter the name of 3 cars you want: "
    car1 =raw_input("car1: ")
    car[0]= car1
    car2 = raw_input("car2: ")
    car[1] = car2
    car3=raw_input("car3: ")
    car[2]=car3
    print "Enter the name of one car you don't want: "
    car4 =raw_input("car4: ")
    car[3]=car4
    return car

def show_result(house, spouse, car):
    print
    print
    print "You will live in a", random.choice(house)
    print "Married to", random.choice(spouse)
    print "While driving your", random.choice(car) 
    print "With your", dieroll(), "kids in it!"
    print
    more = raw_input("Any more (yes or no)? ")
    return more.lower()

house = ["Mansion", "Apartment", "Shack", "House"]
spouse = ["EMPTY", "EMPTY", "EMPTY", "EMPTY"]
car = ["EMPTY", "EMPTY", "EMPTY", "EMPTY"]

while True:
    spouse = get_spouse(spouse)
    car = get_car(car)
    more = show_result(house, spouse, car)
    # the while loop will continue until you break out
    if 'n' in more:
        break
    print

print "Thanks for playing!"
raw_input("Press the Enter key to quit .. ")
sneekula 969 Nearly a Posting Maven

Using sys.stdout.writelines() or sys.stdout.write() is kind of cumbersome and on Linux you also need a sys.stdout.flush() to make it work.

I think internally print(s), translates to sys.stdout.write(s)

sneekula 969 Nearly a Posting Maven

pvi101, welcome to the forum.
Looks like this might be a good book after all!
Hope to see you back soon asking the kind of questions like this one. We will all try to help and learn in the process with you.

sneekula 969 Nearly a Posting Maven

Does your book "Programming in Python 3" refer to Python version 3.0 or is it simply the third edition of the book? If it refers to version 3.0+ then the sample code is buggy!

sneekula 969 Nearly a Posting Maven

This little code creates a list of all the files (full path) in a given directory and any of its subdirectories:

# create a list of all the files in a given direcory
# and any of its subdirectories (Python25 & Python30)

import os

def file_lister(currdir, mylist=[]):
    """
    returns a list of all files in a directory and any of
    its subdirectories
    note that default mylist becomes static
    """
    for file in os.listdir(currdir):
        # add directory to filename
        full_name = os.path.join(currdir, file)  
        if not os.path.isdir(full_name):
            mylist.append(full_name)
        else:
            # recurse into subdirs
            file_lister(full_name)
    return mylist

dir_name = r"C:\Python25\Tools" 
file_list = file_lister(dir_name)
for file in file_list:
    print(file)

"""
my partial output -->
C:\Python25\Tools\i18n\makelocalealias.py
C:\Python25\Tools\i18n\msgfmt.py
C:\Python25\Tools\i18n\pygettext.py
C:\Python25\Tools\pynche\ChipViewer.py
C:\Python25\Tools\pynche\ChipViewer.pyc
C:\Python25\Tools\pynche\ColorDB.py
...
...
"""
sneekula 969 Nearly a Posting Maven

A small function that will check if an integer is odd or even:

def is_odd(n):
    """return True if n is an odd integer, else False"""
    if n & 1:
        return True
    else:
        return False
sneekula 969 Nearly a Posting Maven

Write a slide show program that goes through image files in a given subdirectory with a set delay time.

sneekula 969 Nearly a Posting Maven

Makes you sort of wonder which countries are targeted by British nuclear missiles?

sneekula 969 Nearly a Posting Maven

If you remember, there was a claim by McCain's election staff that he invented the Blackberry thing. That would make him a pretty old geek.

He might have invented the Blackberry, but I don't think he ever was a geek.

sneekula 969 Nearly a Posting Maven

Interesting stats,etc on many different things :)

http://www.worldometers.info

Fantastic real time info! Thanks Dude!

sneekula 969 Nearly a Posting Maven

We have been throwing pearls to the swines for eight years, look what we got!

sneekula 969 Nearly a Posting Maven

Nice find!

sneekula 969 Nearly a Posting Maven

Hold all the other crap, just throw in it a pan till it's crispy! I'd be in heaven, till the eventual endless hours on the toilet from all that grease.

Hopefully you can pour off some of the grease. I don't think it would be any worse than the average hamburger.

sneekula 969 Nearly a Posting Maven

Listening to the finacial news and it makes me gag!
You can now own all of General Motors for less than a Billion Dollars.
By year's end GM, Chrysler and Ford may not exist any longer!

Better switch to a classical FM station and a glass of wine.

sneekula 969 Nearly a Posting Maven

Iron antimatter the size of a pinhead would do. You would have to suspend it in an absolute vacuum with a magentic field. If it reacts with matter, it would create twice the energy predicted by Einstein's famous formula.

sneekula 969 Nearly a Posting Maven

Judge: "I know you, don’t I?
Defendant: "Uh, yes. "
Judge: "All right, tell me, how do I know you?"
Defendant: "Judge, do I have to tell you? "
Judge: "Of course, you might be obstructing justice not to tell me."
Defendant: "Okay. I am your bookie."

sneekula 969 Nearly a Posting Maven

ijn south korea they have like 1gb a second internet

Would that be just within that particular country?

sneekula 969 Nearly a Posting Maven

Hehehe! Oh what a great poem!