sneekula 969 Nearly a Posting Maven

Folks who lack will, lack strength.

sneekula 969 Nearly a Posting Maven

I have seen one on my TV set.

sneekula 969 Nearly a Posting Maven

A kumquat and huckleberry combo with holy water.

sneekula 969 Nearly a Posting Maven

I clicked, but there was no free food.

Google Spider commented: Very Funny +1
sneekula 969 Nearly a Posting Maven

"Brown" that name has a good ring to it!

sneekula 969 Nearly a Posting Maven

Some of those Christmas songs make your hair curl.

sneekula 969 Nearly a Posting Maven

SVU is my favourite too, followed by Criminal Intent

sneekula 969 Nearly a Posting Maven

Be kind to unkind folks they need it the most.

sneekula 969 Nearly a Posting Maven

A new refrigerator for my flat.

sneekula 969 Nearly a Posting Maven

You figured it out!

print 011  # --> 9  (the denary for octal 011)
 
print 0xff  # --> 255 (the denary of hex ff)
sneekula 969 Nearly a Posting Maven

There is 'Starting Python' right here to give you a taste:
http://www.daniweb.com/techtalkforums/thread20774.html

A good starter tutorial:
http://bembry.org/technology/python/index.php

Another good starter tutorial:
http://www.ibiblio.org/g2swap/byteofpython/read/

And of course there is always the latest update:
http://www.python.org/doc/current/tut/tut.html

Now watch out, Python takes an open mind and is addictive!

iamthwee commented: Good info matey +9
sneekula 969 Nearly a Posting Maven
sneekula 969 Nearly a Posting Maven

I think there is a logic flaw in either code, since you are not using the result of the recursion call. It seems to pile up in a return stack somewhere! If you uncomment Bumsfeld's internal print statement, it will print a whole bunch (counted 31) of sixes

sneekula 969 Nearly a Posting Maven

Predict the outcome of this Python code:

def sub_one(x):
    print "x before if -->", x
    if x > 1:
        x = x - 1
        sub_one(x)
    print "x after if -->", x
    return x
 
x = 5
final = sub_one(x)
print "final result -->", final

Can you explain the odd behaviour?

sneekula 969 Nearly a Posting Maven

I didn't have a file, so I used just a text string for testing, but here is one way you can solve this:

text = "I love to work, but not paying my taxes!"
 
# text to word list
words = text.split()
print words  # testing the word list
 
# now comes the processing part
new_words = []
for word in words:
    # remove certain punctuations
    for c in '?!,.;:':
        if c in word:
            word = word.replace(c, '')
    # it's a 4 letter word, replace with 'xxxx'
    if len(word) == 4:
        word = 'xxxx'
    new_words.append(word)
 
# list back to text
print ' '.join(new_words)
sneekula 969 Nearly a Posting Maven

One of your problems is right here:

if (winsA) or (winsB) == ((n / 2) + 1):
        break

You have to change the if statement logic a bit, and you are using break when you are clearly not in a loop.

sneekula 969 Nearly a Posting Maven

Wow, that was quick detective work!
My problem was that I used PSPad for my editor and that does not show runtime error messages. So IDLE is good for some things!

The code works well, and I learned something new. Thanks for the well explained path to the truth. I shall follow it in the future.

sneekula 969 Nearly a Posting Maven

The last time I posted a question here, I got a rather nasty response, so please just constructive stuff!

I want to make a scrollable entrybox for Tkinter GUI, the scrollbar shows up and works, but text does not move. Am I missing something?

import Tkinter as tk
 
root = tk.Tk()
 
enter1 = tk.Entry(root, bg='yellow', width=30)
enter1.grid(row=0, column=0)
 
# create a horizontal scrollbar at bottom of enter1
# (similar to code shown for a listbox)
xscroll = tk.Scrollbar(orient='horizontal', command=enter1.xview)
xscroll.grid(row=1, column=0, sticky='ew')
enter1.configure(xscrollcommand=xscroll.set)
 
enter1.insert('end', 'just a very long sentence to put into the enter space')
 
root.mainloop()
sneekula 969 Nearly a Posting Maven

I need a function that returns True or False if an integer n is a prime. Any 'high speed' thoughts?

sneekula 969 Nearly a Posting Maven

Is there a reliable way to 'pluralize' english words with Python?

sneekula 969 Nearly a Posting Maven

How can I best find out how many times a word appears in a text?

sneekula 969 Nearly a Posting Maven

Thanks again, the last code example will work for me. I will have to read up on the module re to digest it all.

sneekula 969 Nearly a Posting Maven

How can I let the Tkinter Button command do more than one function?

sneekula 969 Nearly a Posting Maven

Wouldn't it be easier to use the Tkinter Text widget for output?

sneekula 969 Nearly a Posting Maven

I was just playing around with a matrix the other day and found out this:

# create a 10 x 10 matrix of zeroes
matrix10x10 = [[0 for col in range(10)] for row in range(10)]
 
# fill it with 1 diagonally
for i in range(10):
    matrix10x10[i][i] = 1
 
# show it
for row in matrix10x10:
    print row
 
"""
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
"""
sneekula 969 Nearly a Posting Maven

Thanks mawe and uran, for your very useful information! I figured Python could do that easily!

sneekula 969 Nearly a Posting Maven

I know that you can do integer calculation in Python with astronomically large numbers. What is the precision limit when using floats?

sneekula 969 Nearly a Posting Maven

Thanks ghostdog!
I will have to play with those code ideas. I need to replace several different words in the text file.

sneekula 969 Nearly a Posting Maven

Holy smokes, ghostdog, you make it look real simple! Looks like Python really has the power of simplicity and elegance! Besides, I can actually understand the code as I read it!

sneekula 969 Nearly a Posting Maven

You also complicate your code (and life) by switching to OOP, when python gives you the freedom not to do that with simple programs like that.

sneekula 969 Nearly a Posting Maven

I know you can get the present time this way:

import time
 
now = time.asctime(time.localtime())
 
print now  # Mon Feb 19 10:41:32 2007

How can I make sure that 'now' does not fall on our lunchtime break, let's say 11:30AM to 12:45PM?

sneekula 969 Nearly a Posting Maven

I need to read in a text file, replace selected words and write the changed text back out to a file. Is there an easy way with Python?

sneekula 969 Nearly a Posting Maven

I want to see if a certain word is in a text file, how do I go about that?

sneekula 969 Nearly a Posting Maven

I hope any of the Python experts can elaborate on this a little more for us beginners.

sneekula 969 Nearly a Posting Maven

when in rome do what the romanians do, i dont get it?

Somewhere in the Bushism collection, things uttered by the best president we ever had. I think it is supposed to be "When in Rome do what the Romans do!". I thought you Brits were hanging on to every word this wise man says!

BTW, thanks Ene for the great code! Now I simply have to process the data, reflect the number of students and can give our stockroom guy an idea what is coming up.

sneekula 969 Nearly a Posting Maven

You also might have trouble with solvents: how many mL should 'wash with water, then acetone' count as?

How crucial is completeness? Are you trying to extract keywords for reference, or are you trying to prepare an ingredients list for a lab assistant, or 'other'?

Jeff

Mostly a chemicals list to project purchases and budgets. There has to be some slack for spills etc.

sneekula 969 Nearly a Posting Maven

Yeah, that works like a charm. Thanks.

sneekula 969 Nearly a Posting Maven

Thanks mawe, I am going to play with that. I guess one can assume the 'amount unit chemical' order fairly reliably. Might have to add a list of common units and of course amount has to start with a digit. That would ignore out the second methanol. If I wanted to have the second amount of methanol, I would have to add it to the chemical list as 'cold methanol' or add a list of potential modfiers. Could be an interesting project.

sneekula 969 Nearly a Posting Maven

Here is a little fun "Hallo World" using RUBY.
Ruby is free from: http://www.rubycentral.com/

for s in ('ollaF'..'ollaP')
    printf("%s World!\n", s.reverse)
end
gets()  # console wait

Easy language to learn, great documentation, lots of examples.

sneekula 969 Nearly a Posting Maven

I am using Clisp free from:
http://sourceforge.net/projects/clisp/

(format t "~%~S from DaniWorld!~%" "Hello world")
sneekula 969 Nearly a Posting Maven

I'd go the other way (int to char) so you don't lose data if the int value is >= 256...

You could use RUBY then you don't have to worry about silly issues like that.

sneekula 969 Nearly a Posting Maven

This could be a cooking recipe, but in my case it is a chemical recipe.

Here is a typical generic chemical recipe:
23 g chemicalA is dissolved in 250 ml methanol. The solution is cooled
to 0 - 5 degC and 18 ml compoundB is added dropwise over 60 minutes.
The mixture is heated to reflux overnight, then cooled to 0 - 5 degC
for 3 hours. The precipated product is collected, washed with 50 ml
cold methanol. Yield: 28 g compoundC as a light yellow solid after
drying in vacuum at 70 degC for 6 hours.

I have a list of chemicals I am searching for:
chemicals =

I want to extract amount and unit of measurement for each chemical
from the recipe to give a list of sublists [chemical, amount, unit].
Something like:
recipe1 = [, , ...]

Using Python, how do I go about this best?

sneekula 969 Nearly a Posting Maven

Sorry Jeff, this does not seem to highlight or select the line.

sneekula 969 Nearly a Posting Maven

How would one create a simple spreadsheet with Tkinter?

sneekula 969 Nearly a Posting Maven

Is there a way to preselect/highlight a listbox item with the Tkinter GUI toolkit at the startup of the program without clicking the mouse on it?

sneekula 969 Nearly a Posting Maven

You can also use module numpy:

import numpy
v1 = numpy.array([1, 2, 3, 4])
v2 = numpy.array([4, 3, 2, 1])
# product
print v1*v2                    # [4 6 6 4]
# scalar product
print numpy.add.reduce(v1*v2)  # 20

Numpy is a free high speed numeric extension module used by engineers and scientists.

sneekula 969 Nearly a Posting Maven

I finally got them all to work. Kinda neat! Can hardly wait until you get some good sound with it!

What does Rpg mean? Reverse Polish Game?

sneekula 969 Nearly a Posting Maven

What is MySQLdb?

sneekula 969 Nearly a Posting Maven

The "Starting Python" sticky also has a number of examples of GUI programming. For a beginner, this one shows you how to develop a blah looking console "Hello World!" into a mouse clicking colorful program ...
http://www.daniweb.com/techtalkforums/post304759-96.html

Hey thanks vegas! Your "Hello World" development series is real cool! Like to see a few more of those!

sneekula 969 Nearly a Posting Maven

I think your print to the display will be by far the slowest operation.