sneekula 969 Nearly a Posting Maven

If a cluttered desk is the sign of a cluttered mind, what is the significance of a clean desk?

sneekula 969 Nearly a Posting Maven

Guess I won't worry too much about Christmas shopping that year.

Good thinking! There is a silver-lining in every cloud.

sneekula 969 Nearly a Posting Maven

A potato bread grilled cheese sandwich with cranberry juice.

sneekula 969 Nearly a Posting Maven

The wisdom of the wise and the experience of the ages are perpetuated by quotations.

sneekula 969 Nearly a Posting Maven

A business that makes nothing but money is a poor business.
~~~ Henry Ford

sneekula 969 Nearly a Posting Maven

Because of the increase in the number of 'double flushes' the introduction of the so-called "low flow" toilets has actually increased water consumption.

sneekula 969 Nearly a Posting Maven

Some people in the US sit in front of a turned off TV and find it more entertaining than turning it on.

sneekula 969 Nearly a Posting Maven

Communicating with smoke signals is kind of slow.

sneekula 969 Nearly a Posting Maven

Maybe this one would be a more elegant dream car.

sneekula 969 Nearly a Posting Maven

Housewife to house painter:
"Let's go to the master bedroom and I will show you the spot my husband touches when he takes his pants off."

Painter: "Lady, I am not that kind of painter, besides I am married."

sneekula 969 Nearly a Posting Maven

Doctor: "I can't find a cause for your complaint. Frankly, I think it's due to heavy drinking."
Patient: "In that case I'll come back when you're sober!"

sneekula 969 Nearly a Posting Maven

I would feel so sorry for all the inovative folks at Yahoo.

sneekula 969 Nearly a Posting Maven

In the summer, a tall mug of cool Stroh's beer with about a two inch head.

sneekula 969 Nearly a Posting Maven

Horses can eat 24 hours without stopping.

sneekula 969 Nearly a Posting Maven

I got one when I joined Daniweb around 2 years back, though I must admit it was more along the lines of the moderator not knowing what an infraction was meant for considering the infraction feature was newly introduced. ;-)

Well, an honorary infraction like that is a nice feather on your cap and should be cherished.

sneekula 969 Nearly a Posting Maven

Pork chops, dressing, beans and cranbeery sauce. An ice cold mug of Stroh's beer.

sneekula 969 Nearly a Posting Maven

Genius is one per cent inspiration, ninety-nine per cent perspiration.
~~~ Thomas Alva Edison

sneekula 969 Nearly a Posting Maven

On a picture the easiest way to distinguish the A319 from the A320 is the location of the rear door with respect to the onset of the tail.

Here is mystery plane #50 (John McCain flew those in his early years)

sneekula 969 Nearly a Posting Maven

If the first code you showed is part of a function you have to tell it that gold is a global variable, start your function code with

global gold
sneekula 969 Nearly a Posting Maven

This must be specific to the Mac OSX. I wonder if PIL has a users forum, or a place you can ask.

sneekula 969 Nearly a Posting Maven

Somewhere above your lines shown you have to give gold a starting value, most likely:
gold = 0

sneekula 969 Nearly a Posting Maven

Just a helpful note, putting our remarks above the line makes your code much more readable:

def search_nested(mylist, val):
    """
    This function will search each cell of mylist for val and
    if found will return the entire row
    """
    #loops i from 0 to the length of mylist (num of rows)
    for i in range(len(mylist)):
        #loops j from 0 to num of cols in each row
        for j in range(len(mylist[i])):
            #print i, j  # my own debugging commented out
            #compare each cell to search value
            if mylist[i][j] == val:
                #if found, return entire row that the value was found in
                return mylist[i]
    #if value not found, return a string instead
    return str(val) + ' not found'


#define 2d list
nested_list = [[1,2,3],[5,6,7],[9,10,11]]  #define 2d list

#call function and display the value the function returns
print search_nested(nested_list, 1)

print search_nested(nested_list, 4)

print search_nested(nested_list, 6)

Also using python code tags give you highlighting:
[code=python]
your Python code here

[/code]

sneekula 969 Nearly a Posting Maven

bachmabt's solution works in your case where you have:
nested_list = [[1,2,3],[5,6,7],[9,10,11]]
but for more complex nesting like:
nested_list = [[1,2,3],[5,6,7],[9,[10,11]]]
you may have eventually flatten the list.

sneekula 969 Nearly a Posting Maven

I am really not a mind reader, so show us some code that gives the error!

sneekula 969 Nearly a Posting Maven

Tkinter only displays gif and ppm images, to show the more popular jpg and png images you have to incorporate the Python image Library (PIL). Here is an example:

# load and display an image with Tkinter
# Tkinter only reads gif and ppm images
# use Python Image Library (PIL) for other image formats
# give Tkinter a namespace to avoid conflicts with PIL
# (they both have class Image) PIL is free from:
# http://www.pythonware.com/products/pil/index.htm

import Tkinter as tk
from PIL import Image, ImageTk

root = tk.Tk()
cv1 = tk.Canvas(root, width=500, height=500)
cv1.pack(fill='both', expand='yes')

# open a jpeg file into an image object
# image should be in the source folder or give full path name
image1 = Image.open("flowers.jpg")
# convert image object to Tkinter PhotoImage object
tkimage1 = ImageTk.PhotoImage(image1)

# tk.NW anchors upper left corner of image
# at canvas coordinates x=10, y=20
cv1.create_image(10, 20, image=tkimage1, anchor=tk.NW)

root.mainloop()
sneekula 969 Nearly a Posting Maven

Be aware that there is a namspace conflict with class Image:

# load and display an image with Tkinter
# Tkinter only reads gif and ppm images
# use Python Image Library (PIL) for other image formats
# give Tkinter a namespace to avoid conflicts with PIL
# (they both have class Image) PIL is free from:
# http://www.pythonware.com/products/pil/index.htm

import Tkinter as tk
from PIL import Image, ImageTk

root = tk.Tk()
cv1 = tk.Canvas(root, width=500, height=500)
cv1.pack(fill='both', expand='yes')

# open a jpeg file into an image object
# image should be in the source folder or give full path name
image1 = Image.open("flowers.jpg")
# convert image object to Tkinter PhotoImage object
tkimage1 = ImageTk.PhotoImage(image1)

# tk.NW anchors upper left corner of image
# at canvas coordinates x=10, y=20
cv1.create_image(10, 20, image=tkimage1, anchor=tk.NW)

root.mainloop()
sneekula 969 Nearly a Posting Maven

We all know, but we don't do your homework! Read the DaniWeb rules.

Aia commented: Very clear +7
sneekula 969 Nearly a Posting Maven

But, why would someone choose Java over Python? Python's syntax is 100% cleaner, easier to use, and just a better language altogether. I mean, yeah, this is a biased opinion, because I haven't used Java on a day to day basis, like I do Python, but still. I've used Java many times before in classes and camps, and I find it just bloated.

Java has been taught by college CS departments for many years. The typical inertia shown by CS staff makes certain that Java will be taught for many more years to come. There are hordes of Java programmers out there. Also Java, being more complex, ensures job security since development is slower and more programmers are needed to do the job.

Python, being easier and quicker to teach, would of course reduce the number of instructors too. Oh my!

sneekula 969 Nearly a Posting Maven

Simple debugging using the Python debug module pdb:

# test the built-in Python Debugger (Pdb in the Python reference)
# at the debugger's '(Pdb)' prompt you can type  h  for help or
# more specifically use   h step  or   h next

import pdb

#help('pdb')

# once the '(Pdb)' prompt shows, you are in the debugger
# and you can trace through by entering:
#
# next (or n) which goes line by line and does not get
# into functions or into every iteration of a loop
#
# step (or s) which is more detailed and for instance
# loops through an entire range()
#
# so use next to get where you want to be and then use step,
# once you have all the details you need, use next again

pdb.set_trace()

# now you can test the following code ...

def hasCap(s):
    """returns True if the string s contains a capital letter"""
    for num in range(65, 91):
        capLetter = chr(num)
        if capLetter in s:
            return True
    return False

str1 = 'Only pick up strings without Capital letters!'
str2 = 'only pick up strings without capital letters!'

# test the function hasCap()
if hasCap(str1):
    print "str1 has a capital letter"
else:
    print "str1 has no capital letter"

if hasCap(str2):
    print "str2 has a capital letter"
else:
    print "str2 has no capital letter"

You need to play with this a little to get familiar with the pdb debugger.

sneekula 969 Nearly a Posting Maven

I have found some bugs just using the Python debugger module pdb:

# test the built-in Python Debugger (Pdb in the Python reference)
# at the debugger's '(Pdb)' prompt you can type  h  for help or
# more specifically use   h step  or   h next

import pdb

#help('pdb')

# once the '(Pdb)' prompt shows, you are in the debugger
# and you can trace through by entering:
#
# next (or n) which goes line by line and does not get
# into functions or into every iteration of a loop
#
# step (or s) which is more detailed and for instance
# loops through an entire range()
#
# so use next to get where you want to be and then use step,
# once you have all the details you need, use next again

pdb.set_trace()

# now you can test the following code

def hasCap(s):
    """returns True if the string s contains a capital letter"""
    for num in range(65, 91):
        capLetter = chr(num)
        if capLetter in s:
            return True
    return False

str1 = 'Only pick up strings without Capital letters!'
str2 = 'only pick up strings without capital letters!'

# test the function hasCap()
if hasCap(str1):
    print "str1 has a capital letter"
else:
    print "str1 has no capital letter"

if hasCap(str2):
    print "str2 has a capital letter"
else:
    print "str2 has no capital letter"
vegaseat commented: very nice +8
sneekula 969 Nearly a Posting Maven

An atheist is a man who has no invisible means of support.

sneekula 969 Nearly a Posting Maven

A society without religion is like a vessel without compass.
-- Emperor Napoleon

sneekula 969 Nearly a Posting Maven

The hottest day on record was 70 degrees Celcius (158 degrees Fahrenheit), and was recorded in the city of Majubea in northern Sudan. Time to hit the pool!

sneekula 969 Nearly a Posting Maven

This would be my dream car.

sneekula 969 Nearly a Posting Maven

I think plane #46 is an Airbus A319.

Plane #48 is a MIG15 with Dutch markings(?)

sneekula 969 Nearly a Posting Maven

Genarally this is done this way:

def get_int(low, high):
    """
    the function will loop until an integer number within the
    given low and high range has been entered
    """
    prompt = "Enter an integer number between %d and %d: " % (low, high)
    while True:
        try:
            n = int(raw_input(prompt))
            if low <= n <= high:
                return n
        except ValueError:
            print "Integer value in range required!"

# test the function
n = get_int(1, 50)
print n
sneekula 969 Nearly a Posting Maven

Then there is Boo, has a Python like syntax and ties in with C#. Vegaseat left a code snippet of Boo code at:
http://www.daniweb.com/code/snippet429.html

sneekula 969 Nearly a Posting Maven

No one died when Clinton lied.
Sorry sight that rhyme implied.
Has the time finally arrived,
When we must to that poor mentality be subscribed?
Glutton for pleasure, this Clinton was
At the eve of the September attack.
Some may say how lucky the man was
When the strike came, it was not his watch.
Others may feel, it ain't right not to cash
What he helped and allowed to be set up.
In his legacy perhaps a tiny stain
Regardless, skeptic I must remain.
For what form of luck can be bestowed,
that compensate for such a large nose?

I don't think I would ever dare to publish such poor peotry! Bold font too!

sneekula 969 Nearly a Posting Maven

Here is an example that should get most of the way there. All you need to do is to supply the search string from the listbox selection:

# searching a long text for a string and scrolling to it
# use ctrl+c to copy, ctrl+x to cut selected text,
# ctrl+v to paste, and ctrl+/ to select all

import Tkinter as tk

def display(data):
    """creates a text display area with a vertical scrollbar"""
    scrollbar = tk.Scrollbar(root)
    text1 = tk.Text(root, yscrollcommand=scrollbar.set)
    text1.insert(0.0, data)
    scrollbar.config(command=text1.yview)
    scrollbar.pack(side='right', fill='y')
    text1.pack(side='left', expand=0, fill='both')
    
    # could bring the search string in from a listbox selection
    pattern = "Chapter 3"
    # line.char(lines start at 1, characters at 0)
    start = "1.0"
    # returns eg. "31.0" --> line 31, character 0
    index = text1.search(pattern, start)
    # scroll text until index line is visible
    # might move to the top line of text field
    text1.see(index)
    
    
root = tk.Tk()

str1 = """\
Chapter 1
.
.
.
.
.
.
.
.
.
.
.
.
.
Chapter 2
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Chapter 3
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
The End
"""

display(str1)

root.mainloop()
sneekula 969 Nearly a Posting Maven

That sort of thing is usually done by subprocess.Popen() or os.popen() functions.

sneekula 969 Nearly a Posting Maven

joshSCH
Presently a banned member. Has the language skills of an 18th century Thames river washer woman. His posts make even iamthwee's worst contributions look like message from heaven. You want to study an unhappy person, take a look.

sneekula 969 Nearly a Posting Maven

iamthwee
Industrious Poster with a large number of reputating browny points. Very smart, but likes to egg folks on a little when he/she gets bored. May just be a perfect geek!

sneekula 969 Nearly a Posting Maven

See, 'The Dude' has no nasty bone in his/her body!

BTW Dude, have you ever pulled up the source code for this site? Very nice HTML ad JavaScript.

sneekula 969 Nearly a Posting Maven

The Dude
A real genius, makes you think and even laugh when you actually don't feel like it. I don't think he/she has not one nasty bone in his/her body! Thanks Dude!

sneekula 969 Nearly a Posting Maven

He is one talented hombre!
Good find there Dude, another very funny site. Thank you!

sneekula 969 Nearly a Posting Maven

At this point only 138 more posts to go!

sneekula 969 Nearly a Posting Maven

yep

falklands was a plus point for her
~~~

Now if Bush would have tackled a small country like that, he could go down as a hero in history too! Lichtenstein comes to mind as a winnable country.

sneekula 969 Nearly a Posting Maven

I always thought you were some kind of car buff. What happened?

Okay, I am still a car buff, but I thought that sounded too Lithuanian.

sneekula 969 Nearly a Posting Maven

Funny movies...
i heard sometimes people drink to keep their body still warm (in winter). this reason can be accepted or not?

In Siberia they drink vodka because most other 'drinkems' are frozen solid.

sneekula 969 Nearly a Posting Maven

Very interesting indeed!