sneekula 969 Nearly a Posting Maven

At Aberystwyth University in Wales, Ross King and colleagues have created a robot called Adam that can not only carry out experiments on yeast metabolism but also reason about the results and plan the next experiment.

sneekula 969 Nearly a Posting Maven

And that would be a bad thing how?

Hehehe, good point. One crook less to worry about!

sneekula 969 Nearly a Posting Maven

Well, if you find a computer that does housework, let us know!

sneekula 969 Nearly a Posting Maven

i guess this should do the trick...

int leap ( int int x)
{
                       if  (!(x%100) && ( x %400 || x %4))
                                     return 1;
 }

well it will return 1 if the year is leap year or not

Ouch, you are in a different world! That looks like old, ugly, and badly written C code.

sneekula 969 Nearly a Posting Maven

Sorry that I responded so late!
I did everything you recommended, but I am still stuck with the "Allow this program Window" popping up. Vista is simply too frustrating! I would vote it as one of Micrsoft's worst products!

sneekula 969 Nearly a Posting Maven

Here would be one way to do this:

text = """\
159 J=1661,3169,1679,3181 SEC=SLAB2
66 J=5597,5596,7523,7522 SEC=WALL1"""

print(text)

print('-'*35)

# create a list of words excluding item containing 'SEC=" 
temp_list = [item for line in text.split('\n')
    for item in line.split()
    if not 'SEC=' in item]

#print temp_list  # test

# rebuild the text from the list
mod_text = ""
for ix, word in enumerate(temp_list):
    if ix % 2:
        # add newline
        mod_text += word + '\n'
    else:
        # add space
        mod_text += word + " "

print(mod_text)
    
"""
my result -->
159 J=1661,3169,1679,3181 SEC=SLAB2
66 J=5597,5596,7523,7522 SEC=WALL1
-----------------------------------
159 J=1661,3169,1679,3181
66 J=5597,5596,7523,7522
"""

Using module re makes it look a little simpler:

import re

text = """\
159 J=1661,3169,1679,3181 SEC=SLAB2
66 J=5597,5596,7523,7522 SEC=WALL1"""

print(text)

print('-'*35)

# if SEC= is followed by cap letters and and numbers
p = re.compile( '(SEC=[A-Z, 1-9]*)')
mod_text = p.sub( '', text)

print(mod_text)

"""
my result -->
159 J=1661,3169,1679,3181 SEC=SLAB2
66 J=5597,5596,7523,7522 SEC=WALL1
-----------------------------------
159 J=1661,3169,1679,3181
66 J=5597,5596,7523,7522
"""
sneekula 969 Nearly a Posting Maven

Thank God I don't live in St. Paul, or I would only have one US Senator.

sneekula 969 Nearly a Posting Maven

If you get a notebook, don't get an HP, it has a lousy keyboard, get a Toshiba, Sony or Acer. Also, looks like the little Acer notbook comes with Widows XP rather than the frustrating Vista.

sneekula 969 Nearly a Posting Maven

Trust is the breath of business,ethics its limbs, to uplift the spirit its goal.

The goal of business is to make money!

sneekula 969 Nearly a Posting Maven

Businesses will spend $13.6 billion on security software this year. This does not include costs for labor, services and hardware.

The worm "Conficker", exploiting the usual weaknesses in Microsoft's Windows operating system, resides in up to 12 million computers worldwide turning them into slaves. Slaves ready to spread the worm to other PCs. Ultimately the worm will be used to spy on critical data.

sneekula 969 Nearly a Posting Maven

You can play with this:

# draw a dragon curve fractal using Tinter's turtle
# dense version using recursion
# modified from: http://www.rosettacode.org/wiki/Dragon_curve

from turtle import *

def dragon(step, length, zig=right, zag=left):
    if step <= 0:
        forward(length)
        return
    step -= 1
    length /= 1.41421
    zig(45)
    dragon(step, length, right, left)
    zag(90)
    dragon(step, length, left, right)
    zig(45)


# set to False to speed things up (default is True)
tracer(False)

# draw in this color
color('red')

# turtle by default starts at (x=0, y=0) center of display
# lift pen up to move to the left by 130 units and up 70 units
# then drop the pen down to start drawing
up()
goto(-130, 70)
down()

# experiment with step and length
step = 12
length = 300
dragon(step, length)

# gives some viewing time ...
import time
time.sleep(7)
sneekula 969 Nearly a Posting Maven

Something like this:

def isLeapYear(year):
    """
    return True if year is a leapyear
    """
    return (not year%4 and year%100 or not year%400) and True

# Testing ...
print( isLeapYear(400) )
print( isLeapYear(800) )
print( isLeapYear(1600) )
print( isLeapYear(1601) )
print( isLeapYear(2004) )
sneekula 969 Nearly a Posting Maven

Strangely enough Python always had the '/' and '//' operators, but it took Python30 to assign them appropriately. So now '/' is floating point and is '//' integer, before they were both integer division operators.

sneekula 969 Nearly a Posting Maven

Here is a Python module that is used for data mining:
http://www.ailab.si/orange

sneekula 969 Nearly a Posting Maven

Please use code tags with your code to preserve the indentations. Otherwise the code is very difficult to read and not too many folks will help.

[code=python]
your Python code here

[/code]

sneekula 969 Nearly a Posting Maven

First let's create a sample image file:

# drawing with PIL (Python Image Library)
# draw and save a small French flag (blue, white, red)

from PIL import Image, ImageDraw

# create a new 24x16 pixel image surface (default is black bg)
img = Image.new("RGB", (24, 16))

# set up the new image surface for drawing
draw = ImageDraw.Draw (img)

# draw a blue rectangle
# x1, y1 are upper left corner coordinates here
w = 8
h = 16
x1 = 0
y1 = 0
draw.polygon([(x1,y1),
(x1+w,y1), (x1+w,y1+h), (x1,y1+h)], fill='blue')

# draw a white rectangle
w = 8
h = 16
x1 = 8
y1 = 0
draw.polygon([(x1,y1),
(x1+w,y1), (x1+w,y1+h), (x1,y1+h)], fill='white')

# draw a red rectangle
w = 8
h = 16
x1 = 16
y1 = 0
draw.polygon([(x1,y1),
(x1+w,y1), (x1+w,y1+h), (x1,y1+h)], fill='red')

img.save("french_flag.bmp")

Now let's take a look at the first line of (r.g.b) tuples:

# show the list of (r, g, b) tuples of a bitmap image

from PIL import Image

# French flag has a simple blue white red left to right pattern
img = Image.open("french_flag.bmp")
w, h = img.size

print(w, h)  # test --> (24, 16) 

data = img.getdata()

# show list of the first line (w pixels wide) of (r,g,b) tuples
print(list(data)[:w])

"""
my output -->
[(0, 0, 255), (0, 0, 255), (0, 0, 255), (0, 0, 255), (0, 0, 255), 
(0, 0, 255), (0, 0, 255), (0, 0, 255), (255, 255, 255), (255, 255, 255), 
(255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), 
(255, 255, 255), (255, 255, 255), (255, 0, 0), (255, 0, 0), (255, 0, 0), 
(255, 0, 0), (255, 0, 0), (255, 0, 0), (255, 0, 0), (255, 0, 0)]
"""
sneekula 969 Nearly a Posting Maven

ok i have added the 4 spaces and no errors displayed but three dots come

...

so shall i add the rest of the code provide or was it going to print it all automatically

Three dots? Are you using the Python shell?

sneekula 969 Nearly a Posting Maven

Sure you can write it the long way, but remember that Python modules are well tested and highly optimized.

sneekula 969 Nearly a Posting Maven

I heard that the PyOpenGL project is pretty much dead. However, the good news is that wxPython has incorporated the Open Graphis Library (OGL). Here is an example:

# the Open Graphics Library (OGL) is now pretty well 
# integrated with wxPython

import wx
import wx.lib.ogl as ogl

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__( self, None, wx.ID_ANY,
            title="explore wx.lib.ogl stuff", size=(400,300))

        canvas = ogl.ShapeCanvas(self)
        canvas.SetBackgroundColour("yellow")

        diagram = ogl.Diagram()
        # marry the two ...
        canvas.SetDiagram(diagram)
        diagram.SetCanvas(canvas)

        # create some standard shapes ...
        # (check how creation order affects overlap)
        circle = ogl.CircleShape(100.0) # radius
        circle.SetX(75.0)  # center x
        circle.SetY(75.0)
        circle.SetPen(wx.RED_PEN)
        circle.SetBrush(wx.CYAN_BRUSH)
        canvas.AddShape(circle)

        text = ogl.TextShape(250, 30)  # (w, h)
        text.SetX(180)  # center x
        text.SetY(240)
        text.AddText("you can drag the circle or the text")
        canvas.AddShape(text)

        diagram.ShowAll(True)

        # use a sizer
        sizer = wx.BoxSizer(wx.VERTICAL)
        # canvas will grow as frame is stretched
        sizer.Add(canvas, 1, wx.GROW)
        self.SetSizer(sizer)
        #self.SetAutoLayout(1)


app = wx.App()
ogl.OGLInitialize()
MyFrame().Show()
app.MainLoop()
sneekula 969 Nearly a Posting Maven

This short example may help you:

# experimenting with Python's csv module
# used to process Comma Separated Values
# the type of files generated by most common spreadsheet programs
# read as a dictionaries and remove one of the keys

import csv

# the csv test data
# here the header line is used for the keys
data = """\
name,age,weight,pay
ted,23,188,33000
mary,37,241,37000
bob,26,167,41000"""

# create the test file
fout = open("mydata.csv", "w")
fout.write(data)
fout.close()

# test it ...
# read the csv data file
# note that csv.DictReader is a generator
# and needs to be read again after use
dic_read = csv.DictReader(open("mydata.csv", "rb"))
# show each row 
# note that each row/line is a dictionary 
# the header line has been converted to the keys
for line in dic_read:
    print(line)


# refresh the generator
dic_read = csv.DictReader(open("mydata.csv", "rb"))
# create a list of processed dictionaries 
dict_list = []
for line in dic_read:
    # remove/delete key 'pay'
    del line['pay'] 
    dict_list.append(line)

print('-'*60)

# show the list of modified dictionaries
for line in dict_list:
    print(line)

"""
my output -->
{'pay': '33000', 'age': '23', 'name': 'ted', 'weight': '188'}
{'pay': '37000', 'age': '37', 'name': 'mary', 'weight': '241'}
{'pay': '41000', 'age': '26', 'name': 'bob', 'weight': '167'}
------------------------------------------------------------
{'age': '23', 'name': 'ted', 'weight': '188'}
{'age': '37', 'name': 'mary', 'weight': '241'}
{'age': '26', 'name': 'bob', 'weight': '167'}

"""
sneekula 969 Nearly a Posting Maven

In Tkinter terminology this widget is called a Scale. Check the manual for details.

sneekula 969 Nearly a Posting Maven

According to the latest Tkinter manual that you can get from:
http://infohost.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf

it is myscale.set(value)

to get a value use:
value = myscale.get()

sneekula 969 Nearly a Posting Maven

Q: "What do you call kids born in a house of ill repute?"
A: "Brothel sprouts."

sneekula 969 Nearly a Posting Maven

When OOP is your only tool everything is objectionable!

sneekula 969 Nearly a Posting Maven

BTW, avoid using tabs for your indentations. Using 4 spaces makes your code more readable and avoids problems with other folks' editors

sneekula 969 Nearly a Posting Maven

One medium-rare sirloin tip steak. Cup of blackberry tea.

sneekula 969 Nearly a Posting Maven

So, where is the user part?

sneekula 969 Nearly a Posting Maven

The power drinks that you can get in many stores here can have up to 800 mg caffeine in them, and some students swig down 2 or 3 of those before an exam. That would be the equivalent of 12 - 15 cups of coffee! They fail the exam because their hands get so shaky they can't write.

Like most everything else, taken in moderation coffeine is just fine. BTW, dogs are very sensitive to caffeine, and the caffeine in one cup of coffee, or the theobromine (a compound related to coffeine) in a bar of chocolate is enough to kill a dog.

nav33n commented: Thanks for the info! I didn't know dogs are sensitive to caffeine :) +10
sneekula 969 Nearly a Posting Maven

Thanks Gribouillis. Now I have to figure out how to test for an uppercase letter. I won't always know it will be a "B."

As always, the solution seems simple after you see it!

You can use one of Python's string functions:

c = 'T'
print(c.isupper())  # --> True
sneekula 969 Nearly a Posting Maven

A dictionary has hashed lookup and is highly optimized in Python, since the language uses dictionaries internally too. I would go with one dictionary.

C++ has the STL map<const Key, Data> container, but I don't know if that would be any memory saving, and don't think the lookup is hashed for speed.

sneekula 969 Nearly a Posting Maven

The best way for your level would be to build up a string in the loop:

alph = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p',\
            'q','r','s','t','u','v','w','x','y','z']
num =[2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9]

# testing only 
phone = "555-GET-FOOD".lower()
#phone = raw_input('enter phone number in the format xxx-xxx-xxxx ').lower()

# build up from an empty string
s = ""
for index in range(len(phone)):
    if phone[index].isalpha():
        s = s + str(num[alph.index(phone[index])])
    else:
        s = s + phone[index]

print s  # 555-438-3663
sneekula 969 Nearly a Posting Maven

Wow, finally someone managed to sell rabbit pellets as candy. I must go right out and get some of those Chocolate Shittles.

sneekula 969 Nearly a Posting Maven

Sauerkraut with pork on mashed potatoes.

sneekula 969 Nearly a Posting Maven

About 4000 years ago, it was the accepted practice in Babylonia that for a month after the wedding, the bride's father would supply his son-in-law with all the mead he could drink. Mead is a honey beer, and because their calender was lunar based, this period was called the "honey month" or what we know to day as the "Honey moon".

sneekula 969 Nearly a Posting Maven

The Tkinter GUI toolkit does not add a scrollbar to a listbox automagically, you have to do it with a few lines of extra code:

# simple example of a scrollable listbox for Tkinter
# for Python30 use 'import tkinter as tk'

import Tkinter as tk

root = tk.Tk()
root.title('a scrollable listbox')

# create the listbox (height/width in char)
listbox = tk.Listbox(root, width=50, height=6)
listbox.grid(row=0, column=0)

# create a vertical scrollbar to the right of the listbox
yscroll = tk.Scrollbar(command=listbox.yview, orient=tk.VERTICAL)
yscroll.grid(row=0, column=1, sticky='n'+'s')
listbox.configure(yscrollcommand=yscroll.set)

# now load the listbox with data
friend_list = [
'Stew', 'Tom', 'Jen', 'Adam', 'Ethel', 'Barb', 'Tiny', 
'Tim', 'Pete', 'Sue', 'Egon', 'Swen', 'Albert']
for item in friend_list:
    # insert each new item to the end of the listbox
    listbox.insert('end', item)

root.mainloop()
sneekula 969 Nearly a Posting Maven

Here is another option to help Python to locate custom modules in custom directories:

If you want to import custom module xyq via the Pythonpath
create a file xyq.pth and stick it into a directory python
will look into, like C:\Python25\Lib\site-packages
The .pth file contains a line showing the directory
in which module xyq is located, for instance:
C:\Python25\Mymodules

lllllIllIlllI commented: Ah beat me to it! :) +2
sneekula 969 Nearly a Posting Maven

As good paying jobs disappear in the USA, so will US customers of these now imported products. I also think that a free society produces better ideas than a 'slave' society.

sneekula 969 Nearly a Posting Maven

We traveled through Mexico a lot when we lived is Arizona; we never drank the water. One thoughtless moment, we rinsed the grapes and suffered for a couple of days for our lapse. Otherwise, we ate tacos from curbside vendors with no problems. Sometimes it was cheaper to drink beer than bottled water. Truth be told, we might wait until the gunfire subsides in the border towns before we would travel the border towns again.

Mexico is in the US news lately, there seems to be a good chance that the ever increasing drug related violence will turn it into another Afghanistan. So the advice there should be:
"Don't stand between the drug lords and the military during a shootout, or you will eat lead instead of tacos!"

sneekula 969 Nearly a Posting Maven

A couple were going out for the evening. They were ready, even had the dog put outside. The taxi arrives, and as the couple start out, the dog shoots back in the house. They don’t want the dog shut in the house, so the wife goes out to the taxi while the husband goes into the house again to fetch the dog.

The wife, not wanting it known that the house will be empty explains to the taxi driver: "My husband is just going upstairs to say good-bye to my mother."

A few minutes later, the husband gets into the cab somewhat out of breath.

"Sorry I took so long" he says. "Stupid bitch was hiding under the bed, and I had to poke her with a coat hanger to get her to come out! Then I had to wrap her in a blanket to keep her from scratching and biting me, as I hauled her ass downstairs and tossed her in the back yard! She better not shidd in the vegetable garden either!"

jbennet commented: haha good one +36
Ezzaral commented: hehehe excellent! +19
William Hemsworth commented: haha ;D +9
sneekula 969 Nearly a Posting Maven

If I right click on the python.exe file I get a popup menu, but I don't see much in there to change the crummy situation. I looked thoroughly at properties, but there is no hint. It looks like Vista stores that information somewhere else. I installed Python initially at least 6 months ago and then reinstalled it trying to get rid of the 'allow' popup. My older XP desk top machine simply does not do silly stuff like that.

sneekula 969 Nearly a Posting Maven

What Operating System are you using?
You can append to the pythonpath in each your programs.

sneekula 969 Nearly a Posting Maven

Thinking is futile, give it up or live in fear.

sneekula 969 Nearly a Posting Maven

The manager of a large law office noticed a new man one day and told him to come into his office. "What is your name?" was the first thing the manager asked the new guy.

"John," the new guy replied.

The manager scowled, "Look, I don’t know what kind of a namby-pamby place you worked at before, but I don’t call anyone by their first name. It breeds familiarity and that leads to a breakdown in authority. I refer to my employees by their last name only - Smith, Jones, Baker - that’s all. I am to be referred to only as Mr. Robertson. Now that we got that straight, what is your last name?"

The new guy sighed and said, "Darling. My name is John Darling."

sneekula 969 Nearly a Posting Maven

In 1221 Genghis Khan killed 1,748,000 people at Nishapur in one hour.

sneekula 969 Nearly a Posting Maven

Spiegeleier mit Krustenbrot und einen Eimer Milch.

(Eating like the Pope)

sneekula 969 Nearly a Posting Maven

I would be more concerned about Tyson Lawson's fingers.

sneekula 969 Nearly a Posting Maven

Your information is case sensitive!

sneekula 969 Nearly a Posting Maven

Sounds like a real adventure! Hope you don't fall into the rebels' hands or get arrested by the corrupt law enforcers. Don't drink the water!

Ezzaral commented: ! +19
sneekula 969 Nearly a Posting Maven

Running PyGame from within wxPython will create a conflict, since each use their own event loops, and the event queue will now contain events that won't match.

sneekula 969 Nearly a Posting Maven

Right clicking on the Allow Popup does not do anything.

Uninstalling and reinstalling does not help, I am still stuck!