Ene Uran 638 Posting Virtuoso

Outgoing Secretary of the Interior Dirk Kempthorne has spruced up his office bathroom with $235,000 in renovations before he left.

The renovations included new plumbing, which did need to be replaced. Of course, a new shower came with the work. Other work included wainscot wood paneling from floor to the ceiling. Also included in the bathroom work was a cabinet holding a new refrigerator and freezer.

I guess, if you do a shiddy job, you might as well have a nice bathroom! This is the guy the banking industry should add to their CEO list.

Ene Uran 638 Posting Virtuoso

I am sorry but these are not bureaucrats - they are worse, they are political appointees. "Another person pointed out to me that after Rice’s arrival in 2005 the tone of official State Department publications changed; they began to praise and glorify Rice. “No prior secretary,” said the twenty-year veteran, “did anything like this.”

But than we never had a Secretary of State that could play the piano, dance and sing at the same time!

Ene Uran 638 Posting Virtuoso

The real cost of printing too much money to pay for wars and failed banks will be hyperinflation down the road. Just ask folks from countries like Argentina or Zimbabwe.

Ene Uran 638 Posting Virtuoso

Toast with almond butter and jelly toast, with a cup of good old Santos coffee.

I have stopped eating peanut butter after eight people died and several hundred people ended up in the hospital eating peanut butter made in a filthy plant in the state of Georgia.

Ene Uran 638 Posting Virtuoso

Also, I noticed that your first example uses tabs for indentation, avoid tabs and use four spaces instead. The code is much easier to read, and you don't run into the disastrous mistake of mixing tabs and spaces.

Ene Uran 638 Posting Virtuoso

Widgets in wxPython need a unique integer ID number. When you use -1 then wxPython will pick a unique ID number for you. BTW, wx.ID_ANY is a constant set to -1 and a little more descriptive. You also may want to look at class basics before you use them, so you understand self and __init__() better. Simple wxPython programs can be written without using class.

Here is ZZ's simple image viewer:

import wx

app = wx.App()
frame = wx.Frame(None, -1, "Show an image file")
wx.StaticBitmap(frame, -1, wx.Bitmap('clouds.jpg'))
frame.Show()
app.MainLoop()

My advice, don't bite more off than you can chew. Start with simple code and build up to explore the concepts of wxPython. That's the way to learn. Otherwise GUI stuff will overwhelm you!

There is a book out on wxPython, but it is full of errors and pretty bad. A relatively good tutorial is from:
http://wiki.wxpython.org/index.cgi/AnotherTutorial

If you haven't done so, take a look at DaniWeb's wxPython thread at:
http://www.daniweb.com/forums/thread128350.html

Ene Uran 638 Posting Virtuoso

Before Python 3.0 the wrapper Tkinter.py was called when you used 'import Tkinter'. Now Tkinter has followed wx, and turned into a more modern package approach with a directory named tkinter that uses _init__.py as the wrapper, which means you have to use 'import tkinter'. Here is an example:

# draw a circle with given center (x,y) and radius
# notice that Python25 uses 'Tkinter' and Python30 'tkinter'

# comment/uncomment for the correct Python version
# for Python25 use
#import Tkinter as tk
# for Python30 use
import tkinter as tk

def get_center(x1, y1, x2, y2):
    '''
    for a rectangle with ulc=(x1,y1) and lrc=(x2,y2)
    calculate the center (x,y)
    '''
    x = x1 + (x2 - x1)//2
    y = y1 + (y2 - y1)//2
    return x, y
    
def get_square(x, y, radius):
    '''
    given the center=(x,y) and radius
    calculate the square for the circle to fit into
    return x1, y1, x2, y2 of square's ulc=(x1,y1) and lrc=(x2,y2)
    '''
    x1 = x - radius
    y1 = y - radius
    x2 = x + radius
    y2 = y + radius
    return x1, y1, x2, y2

# create the basic window, let's call it 'root' 
root = tk.Tk()

# create a canvas to draw on
cv = tk.Canvas(root, width=300, height=300, bg='white')
cv.grid()

# draw a circle with given center (x,y) and radius
x, y = 150, 120
radius = 65
# to draw a circle you need to get the ul and lr corner coordinates
# of a square that the circle will fit …
Ene Uran 638 Posting Virtuoso

Here is my console output on Mandriva linux 2009:

Python 3.0 (r30:67503, Dec  9 2008, 13:32:06)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>

I think that all library module names have been converted to lowercase in python 3.0.

Good observation!
Before Python 3.0 the wrapper Tkinter.py was called, now Tkinter has turned into a more modern package with the directory name tkinter that uses _init__.py as the wrapper.

Ene Uran 638 Posting Virtuoso

Do you mean something like that?

import random

def main():
    ##Open a file
    outfile = open('numbers.txt', 'w')
    for count in range(10):
        ##Get random numbers
        rebmun = random.randint(1,99)
        outfile.write(str(rebmun) + '\n')
    outfile.close()

    # read the file you just created
    text = open('numbers.txt','r').read()
    num_list = text.split()
    
    # create a dictionary with ix:val pairs
    num_dict = {}
    for ix, val in enumerate(num_list):
        # test only
        print( ix, val)
        num_dict[ix] = int(val)
        
    # test result
    print('-'*70)
    print(num_dict)

main()

"""
my output -->
(0, '98')
(1, '51')
(2, '97')
(3, '60')
(4, '29')
(5, '23')
(6, '65')
(7, '1')
(8, '56')
(9, '56')
----------------------------------------------------------------------
{0: 98, 1: 51, 2: 97, 3: 60, 4: 29, 5: 23, 6: 65, 7: 1, 8: 56, 9: 56}

"""
Ene Uran 638 Posting Virtuoso

Is there a gui library that has already been ported to python 3? I'm interested in using some of the new python 3 features in the back end for my project.

For the time being you will have to use good old Tkinter that ships with Python3.0.

Ene Uran 638 Posting Virtuoso

A classic, Newton's method to estimate the square root of a number:

# estimate the square root of value v
# using Newton's Method

from math import sqrt

# value to estimate sqr for
v = 222

# initial guess
g = v/2.0

# loop n times
n = 7
for k in range(n):
    # Newton's method
    y = (g + v/g)/2.0
    g = y
    print( "%d) %0.8f  %0.8f  %0.8f" % (k+1, sqrt(v), g, sqrt(v)-g) ) 

"""
my output -->
1) 14.89966443  56.50000000  -41.60033557
2) 14.89966443  30.21460177  -15.31493734
3) 14.89966443  18.78102132  -3.88135690
4) 14.89966443  15.30073237  -0.40106795
5) 14.89966443  14.90492089  -0.00525646
6) 14.89966443  14.89966535  -0.00000093
7) 14.89966443  14.89966443  -0.00000000
"""
Ene Uran 638 Posting Virtuoso

Vpython and wxPython each use their own event loops, so it will not be easy and very smooth.

Ene Uran 638 Posting Virtuoso

First of all, you are mixing spaces and tabs in your indentations, which will srew up most editors. Please use spaces only!

I assume the error happens in the for loop, and it looks like when you reach the integer element in your booklist you are trying to use "in" to compare a string with an integer.

Solution, have your for loop go in steps of 4 like this:
for i in range(0, len(booklist), 4):

Ene Uran 638 Posting Virtuoso
Ene Uran 638 Posting Virtuoso

I've got it working now.

In a forum we try to inform each other. What did you do different?

Ene Uran 638 Posting Virtuoso

Using
class UpdateLabels(threading.Thread):
should work too.

Ene Uran 638 Posting Virtuoso

You simply append the directory to PYTHONPATH before you import your custom module:

import sys
# appends to PYTHONPATH  the location of the example codes
sys.path.append(r'C:\Python25\Examples')
Ene Uran 638 Posting Virtuoso

Avoid Python 2.6 if you can. It was supposed to help preparing folks for Python 3.0, but it is just confusing to most users. Also like scru mentioned, wxPython for Python 2.6 has some errors in it.

I finally managed to get my SciTE IDE editor set for Python30. Actually, it was relatively easy.

Ene Uran 638 Posting Virtuoso

May be because your code block indentations are screwed up.

Ene Uran 638 Posting Virtuoso

You are importing Tkinter twice, first with a namespace and then without, kind of goofy. This "Traffic Simulation" must be homework, because I have seen this import approach a fair number of times on several forums.

Ene Uran 638 Posting Virtuoso

Module subprocess, specifically subprocess.Popen(), has a wait() method. Here is a typical example:

# 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()
Ene Uran 638 Posting Virtuoso

There is a radio show host in the US, named something odd like "Rush Limbaugh", that announced on the radio that he wishes Barack Obama to fail! Luckily, only uninfluential folks listen to stuff like that.

Ene Uran 638 Posting Virtuoso

Just heard in the financial news:
The total of bad loans of the Royal Bank of Scotland is equal to the annual revenue of England. That's just one bank.

Ene Uran 638 Posting Virtuoso

You can roll-start your manual transmission car in reverse.
It constantly surprises me that people do not even see it as possible - I just helped a couple guys start their car, they were trying to push it forward but that was slightly uphill so they were going to turn it around; when I explained how easy rolling it backwards was, they were skeptical but it pop-started so fast I fell on my face (in my youth I would have rolled to my feet but being old and slow and laughing too hard, I needed help up).
I roll-started my old Corolla for 9 months by rolling it backwards because I could put my back to the door frame, push, and hop in to start it. The gear ratio in reverse is even lower than that in first so it actually starts easier in reverse.

What happens if you accidentally put it in first gear?

Ene Uran 638 Posting Virtuoso

Love is like a river, it flows toward the bottom.

Ene Uran 638 Posting Virtuoso

A nice slice of New York crumb cake with Maracaibo dark roast coffee.

Ene Uran 638 Posting Virtuoso

they have to use aircraft grade aluminium for the fins on electricity generating windmillls or else the blades are too heavy and not efficient enough to generate enough power to make them profitable in thier lifespan

and yes, re batteries, nickel has the same issue. A study found that they will run out of the materials to make the batteries in under 30 years if everyone changes to a hybrid car. Thats less than the amount of oil left.

There is plenty of nickel and it can be recycled. Besides, newer batteries will use lithium.

Oh my God, I am dating an engineer and now I start to sound like one!

Ene Uran 638 Posting Virtuoso

All those boos from the crowd for old George Bush was a little sad.

Ene Uran 638 Posting Virtuoso

Facts do not cease to exist just because they are ignored.

Ene Uran 638 Posting Virtuoso

I am learning which bone is attached to ...

Ene Uran 638 Posting Virtuoso

You mean something like this?

import Tkinter as tk
import time
import sys
import datetime as dt 


root = tk.Tk()
root.title("Traffic Simulation")

canvas = tk.Canvas(root, width=1000, height=400, bg="#FFFFFF")
canvas.pack()

for k in range (1,10):
    s = 'orange' + str(k)
    x = k * 50
    y = 20
    canvas.create_text(x, y, text=s)

canvas.update()

root.mainloop()
Ene Uran 638 Posting Virtuoso

You can do (a**2+b**2)**0.5 do get the proper result.

Ene Uran 638 Posting Virtuoso

How do you do that? :)

Simply write the following short code with your IDE editor and then run it from that editor:

age = input("Enter your age: ")
print(age)

Some nice editors like DrPython or even IDLE will show the prompt in the output window, just like you would expect. Some other editors use their own small popup window showing the prompt and an entry field. Annoying, but it works. Many other editors really screw things up, no prompt is shown in their output window, or the cursor is not placed right, or an error is thrown sometimes even before you can enter the data.

Ene Uran 638 Posting Virtuoso

Who says you have to use aluminum to build windmills? The present NiH batteries on hybrid cars do not use cadmium.

The safe life span of a nuclear power plant is 25 years and then you are stuck with a highly radioactive mess. If you use aluminum for your windmills, the metal can easily be recycled.

Ene Uran 638 Posting Virtuoso

Well, it took George Bush eight years to make such an ungodly mess, so it will take Barack Obama and his team a little while to fix it. The first things you may see is that the torture of prisoners is gone, and the US will treat other countries like partners and not like door mats.

Ene Uran 638 Posting Virtuoso

Programs like py2exe work very well with wxPython and will include the needed parts in the distribution package of your code for Windows users. Also wxPython is available for most of the common Operating Systems.

Ene Uran 638 Posting Virtuoso

Here is an example how to do this:

# encoding and decoding a cipher structure

def encode(text):
    text = "".join([c.upper() for c in text if c.isalpha() or c==" "]) 
    temp = ""
    for c in text:
        temp += code_dic[c]
    return temp

def decode(crypt):
    temp = ""
    # use groups of 5
    for x in range(0, len(crypt), 5):
        temp += rev_dic[crypt[x:x+5]]
    return temp    

def swap_dict(d):
    """swap dictionary key:value pairs using a generator expression"""
    return dict((v, k) for (k, v) in d.items())


code_dic = {
'A': '11111', 'B': '11110', 'C': '11101', 'D': '11100', 'E': '11011', 
'F': '11010', 'G': '11001', 'H': '11000', 'I': '10111', 'J': '10110', 
'K': '10101', 'L': '10100', 'M': '10011', 'N': '10010', 'O': '10001', 
'P': '10000', 'Q': '01111', 'R': '01110', 'S': '01101', 'T': '01100', 
'U': '01011', 'V': '01010', 'W': '01001', 'X': '01000', 'Y': '00111', 
'Z': '00110', ' ': '00000'}

rev_dic = swap_dict(code_dic)

text = "Python is great!"
crypt = encode(text)

print(crypt)

print('-'*40)

news = decode(crypt)

print(news)

Notice I added a space char to the dictionary to make the decoded text more readable. There was also a mistake at 'E'.

One word of advice, don't make your variable and function names too long (ala C#) or your code becomes rather hard to read!

Ene Uran 638 Posting Virtuoso

The combination of pydev + eclipse is a huge sluggish thing. I enjoy DrPython, it has some nice downloadable plugins like code assist and run from buffer.

My test criteria for a good editor is how it handles the input() function in its output window.

Ene Uran 638 Posting Virtuoso

if testA:
actionA()
if testB:
actionB()
if textC:
actionC()
else:
actionDefault()

this will bypass all the others as if any of the test things arent right it will skip it and go to action default

This will not work for:
testA = True
testB = False
testC = False

Ene Uran 638 Posting Virtuoso

This would do the trick, but would not be very readable:

if testA:
    actionA()
    if testB:
        actionB()
        if testC:
            actionC()

if not(testA and testB and testC):
   actionDefault()
Ene Uran 638 Posting Virtuoso

If your block is only one statement, then you can do something like this:

number = 2
guess = 2

if number == guess: print("yep it's identical")
Ene Uran 638 Posting Virtuoso

Indentation was done on purpose, and is one of Python's features that makes its syntax more readable. Yes it forces the programmer to use proper indentation, something that is often not done in code written in C. I have seen 300 line C code where every line starts at column 1. Go to the C forum and see how many times people, trying to help, request indentation.

Here is an example of what C will let you get away with:

// example of badly written C code, it works!

#include <stdio.h>
#include <string.h>

int bin2dec(char *bin);

int main(){char bin[80]="";char *p;  int  dec;
while(strcmp(bin,"0")){printf("\n Enter binary number (0 only exits): ");
fgets(bin, sizeof(bin), stdin);if ((p = strchr(bin,'\n')) != NULL){
*p = '\0';}dec=bin2dec(bin);if (dec)
printf("\nDecimal = %d  Hexadecimal = 0x%04X  Octal = 0%o\n",dec,dec,dec);
}getchar();return 0;}int bin2dec(char *bin){int b, k, m, n;
int  len, sum = 0;len = strlen(bin) - 1;for(k = 0; k <= len; k++){
n = (bin[k] - '0');if ((n > 1) || (n < 0)){
puts("\n\n ERROR! BINARY has only 1 and 0!\n");return (0);}
for(b = 1, m = len; m > k; m--){b *= 2;}sum = sum + n * b;}return(sum);}
Ene Uran 638 Posting Virtuoso

why don't you start with 2.6? I suggests this for newbies as there are pretty many tutorials and books there. Only when you have grasped the basics you can consider Py3k. Also few (I guess none) of non standard modules aren't yet out for python!

If you change your mind and go for 2.x then books are there:
Think Python - Bruce Eckel
A byte of python - Swaroop C.H (also py3k is out )
Dive into Python - Mark Pilgrim
All these are available on net plus many many tutorials

Don't bother with Python26! It does not prepare you for Python30.

Ene Uran 638 Posting Virtuoso

I use one tab or four spaces
They give me no problem, so I guess:
1Tab = 4spaces

You may not have a problem with your tabs and your tab setting, but I have run into plenty of problems with other folks' code that have used tabs. Please avoid tabs!

Ene Uran 638 Posting Virtuoso

Like I mentioned in another thread, the problem is that a lot of those modules are freeware done by different folks. Monetary reward is more of a driving force, and it will take a while to get those free things to show up. Python30 has a lot of rather subtle changes that need to be considered to avoid buggy code.

Ene Uran 638 Posting Virtuoso

A successful man is one who can earn more money than his wife can possibly spend. A successful woman is one who can find that man.

Ene Uran 638 Posting Virtuoso

Accidents happen (explains why I didn't get a Xmas present):

Ene Uran 638 Posting Virtuoso

Here is a true Austrian in action.

Ene Uran 638 Posting Virtuoso

Who says elephants don't have a sense of humor?

Hope not ....
Q: "What has 2 grey legs and 2 brown legs?"
A: "An elephant with diarrhea."

Ene Uran 638 Posting Virtuoso

Since so many folks are going around and wishing you a 'Happy New Year', I wonder what would make you happy.

Getting an interesting higher paying job would make me happy.