bumsfeld 413 Nearly a Posting Virtuoso

Looks more like message from lint-filter, telling you to use self. Some of the commercial IDEs have filters built in.

bumsfeld 413 Nearly a Posting Virtuoso

Try this short Tkinter code, only tested it on Windows XP:

from Tkinter import *

root = Tk()

sw = root.winfo_screenwidth()
sh = root.winfo_screenheight()

# test
print "screen width  =", sw
print "screen height =", sh 

# set to full screen use this:
root.geometry("%dx%d+0+0" % (sw, sh))

# more code here

root.mainloop()
bumsfeld 413 Nearly a Posting Virtuoso

Very nice effort, just a a few corrections needed to make this work.

# class.py
# tpm
# A program to calculate the volume and surface area of a sphere from its
# radius given as input.

from math import *   # for pi

class Sphere:

    def __init__(self, radius):   # use double underline on both endes of init
        self.radius = radius

    def getRadius(self):
        return self.radius

    def surfaceArea(self):
        self.area = 4.0 * pi * self.radius ** 2
        return self.area

    def volume(self):
        self.volume = 4.0 / 3.0 * pi * self.radius ** 3
        return self.volume


# main is not part of class, so indent properly
def main():
    r = input('Enter the radius of the sphere ')
    s = Sphere(r)
    print 'The surface area of the sphere is: ', s.surfaceArea()
    print 'The volume of the sphere is: ', s.volume()

main()

I commented on the problems, hope you understand them.

bumsfeld 413 Nearly a Posting Virtuoso

I can not quite figure out what you want to do. I wrote these little test files. Test1.py contains a variable I want to use in Testing1.py.

Test1.py:

# test module, save as test1.py

test_path = "test1234"

Testing1.py:

# testing module test1.py
import test1

print test1.test_path

I am thinking this would work like the situation you told. What do you like to change?

bumsfeld 413 Nearly a Posting Virtuoso

wxPython has Printer Framework that allows you to do print whatever you put on a canvas. This can be colored text of any font. However, you got to get familiar with wxPython GUI. Look at wx.Printout(), wx.PrintData() and wx.PrintPreview()

bumsfeld 413 Nearly a Posting Virtuoso

Python lambda can substitute, just harder to read:

tuple1 = ('\t', '\n')
for k in range(100):
    a = (k % 10 == 9)
    b = 1
    c = 0
    # similar to C conditional expression a ? b : c
    # if a is true return b else c
    f = lambda a, b, c: (a and [b] or [c])[0]
    print "%3d%s" % (k, tuple1[f(a, b, c)]),
bumsfeld 413 Nearly a Posting Virtuoso

Which code snippet are you talking about?

bumsfeld 413 Nearly a Posting Virtuoso

Since your discount is calculated from the total purchase, you do not need to ask for it.
Discount calculations are done using conditional if statements.

Do not use % as a variable name!

All calculations are simple, no need for "from math import *"

bumsfeld 413 Nearly a Posting Virtuoso

Found code in one of the books in the CS library:

# view and delete e-mail using the POP3 protocol

import sys, getpass, poplib, re

# change according to your needs
POPHOST = "pop.domain.com"
POPUSER = "joedoe"
POPPASS = ""
# the number of message body lines to retrieve
MAXLINES = 10
HEADERS = "From To Subject".split()

# headers you're actually interested in
rx_headers  = re.compile('|'.join(headers), re.IGNORECASE)

try:
    # connect to POP3 and identify user
    pop = poplib.POP3(POPHOST)
    pop.user(POPUSER)

    if not POPPASS or POPPASS=='=':
        # if no password was supplied, ask for it
        POPPASS = getpass.getpass("Password for %s@%s:" % (POPUSER, POPHOST))

    # authenticate user
    pop.pass_(POPPASS)

    # get general information (msg_count, box_size)
    stat = pop.stat(  )

    # print some information
    print "Logged in as %s@%s" % (POPUSER, POPHOST)
    print "Status: %d message(s), %d bytes" % stat

    bye = 0
    count_del = 0
    for n in range(stat[0]):

        msgnum = n+1

        # retrieve headers
        response, lines, bytes = pop.top(msgnum, MAXLINES)

        # print message info and headers you're interested in
        print "Message %d (%d bytes)" % (msgnum, bytes)
        print "-" * 30
        print "\n".join(filter(rx_headers.match, lines))
        print "-" * 30

        # input loop
        while 1:
            k = raw_input("(d=delete, s=skip, v=view, q=quit) What?")
            k = k[:1].lower(  )
            if k == 'd':
                # Mark message for deletion
                k = raw_input("Delete message %d? (y/n)" % msgnum)
                if k in "yY":
                    pop.dele(msgnum)
                    print "Message %d marked for deletion" % msgnum
                    count_del += 1
                    break
            elif k == 's':
                print "Message %d left on server" % msgnum
                break
            elif …
bumsfeld 413 Nearly a Posting Virtuoso

G-Do,
you and vegaseat seem to share fascination with midi music files. I have explored vegaseat's code snippet
http://www.daniweb.com/code/snippet431.html
and it work well at least on Windows XP. Midi is great stuff!

I am thinking that pythonmidi is the same package as PMIDI, at least the files/directories are the same.

bumsfeld 413 Nearly a Posting Virtuoso

Please wrap you code in code tags, see:
http://www.daniweb.com/techtalkforums/announcement114-3.html

This way the proper indentations are added.

I would not pass function on as argument, so rewrite you code:

from math import *  # to get pi

def main():
    # first get the area of the whole pizza
    area = area_of_pizza()    
    cost_per_square_inch(area)

def area_of_pizza():
    diameter = input("Enter the diameter of the pizza: ")
    radius = diameter/2.0
    a = pi * radius * radius
    return a

def cost_per_square_inch(area):
    # get the cost of the whole pizza
    cost_of_pizza = input("Enter the cost of the pizza: ")
    # calculate the cost per area unit
    cost = cost_of_pizza/area
    print "The cost per square inch of pizza is $%0.2f" % (cost)


main()

Since you only need math.pi you don't have to import all math functions/constants. You could use:

from math import pi
bumsfeld 413 Nearly a Posting Virtuoso

There is no module called graphics in normal Python distribution! Without this custom module will be hard to help!

I suggest you print p1 and see what it looks like!
If it is tuple like (30, 45), then most likely p1x = p1[0].

bumsfeld 413 Nearly a Posting Virtuoso

Sounds more like Ancient's wife has him broke in!

Happy coding!

bumsfeld 413 Nearly a Posting Virtuoso

Here is simplified approach, the number of new-line characters '\n' give number of lines, the number of spaces are approximately the number of words, and the number of characters is the length of the text string read from file.

You simply use a for loop and and iterate each character in text counting new-lines, spaces. Don't have Unix and don't know if space counts as a character, also new-line. Can use char_from_text.isalnum() to weed these out.

You can also use, I didn't test, number_of_lines = text.count('\n') function.

A more correct answer for the number of words can be obtained by splitting the text string into list of words with word_list = text.split() and then get length of this list with number_words = len(word_list).

bumsfeld 413 Nearly a Posting Virtuoso

This would be example from one of the tutorials:

# Tkinter top-level menus

from Tkinter import *
from tkMessageBox import *

# temporary function to call from menu
def notdone():
    showerror('Not yet', 'Work in progress!')

def makemenu(win):
    top = Menu(win)
    win.config(menu=top)
    
    file = Menu(top)
    file.add_command(label='New...', command=notdone, underline=0)
    file.add_command(label='Open...',command=notdone, underline=0)
    file.add_command(label='Quit', command=win.quit, underline=0)
    top.add_cascade(label='File', menu=file, underline=0)

    edit = Menu(top, tearoff=0)
    edit.add_command(label='Cut', command=notdone, underline=0)
    edit.add_command(label='Paste', command=notdone, underline=0)
    edit.add_separator()
    top.add_cascade(label='Edit', menu=edit, underline=0)

    submenu = Menu(edit, tearoff=0)
    submenu.add_command(label='Spam', command=win.quit, underline=0)
    submenu.add_command(label='Eggs', command=notdone, underline=0)
    edit.add_cascade(label='Stuff', menu=submenu, underline=0)

root = Tk()
root.title('menu_win')
makemenu(root)
msg = Label(root, text='Window menu basics')
msg.pack(expand=YES, fill=BOTH)
msg.config(relief=SUNKEN, width=40, height=7, bg='beige')
root.mainloop()
bumsfeld 413 Nearly a Posting Virtuoso

You mean something like that:

import tkFileDialog
# examples:
def open_it():
    filename = tkFileDialog.askopenfilename()
    print filename  # test
    
def save_it():
    filename = tkFileDialog.askopenfilename()
    print filename  # test
    
def save_as():
    filename = tkFileDialog.asksaveasfilename()
    print filename  # test
bumsfeld 413 Nearly a Posting Virtuoso

You can write much more clean code if you start with Python over again. VB code is usually just to "helter skelter"! Look at your application and rewrite it in Python.

bumsfeld 413 Nearly a Posting Virtuoso

I hope you are talking about Tkinter as GUI. This code might help you. You have to use a if statements to get the right key value to go to the proper function then.

# bind and show a key event with Tkinter 

from Tkinter import *

root = Tk()
prompt = '      Press any key      '
label1 = Label(root, text=prompt, width=len(prompt))
label1.pack()

def key(event):
    if event.char == event.keysym:
        msg = 'Normal Key %r' % event.char
    elif len(event.char) == 1:
        msg = 'Punctuation Key %r (%r)' % (event.keysym, event.char)
    else:
        msg = 'Special Key %r' % event.keysym
    label1.config(text=msg)

label1.bind_all('<Key>', key)

root.mainloop()
bumsfeld 413 Nearly a Posting Virtuoso

Working with SQL I found this site. It may help!
http://www.mayukhbose.com/python/ado/index.php

bumsfeld 413 Nearly a Posting Virtuoso

Maybe GTK is only for Linux?

bumsfeld 413 Nearly a Posting Virtuoso

A friend of me says that you can play mp3, mid and ogg files with Pygame but you need extra install modules for SDLs.

bumsfeld 413 Nearly a Posting Virtuoso

Nice code, I will have to remember that!

bumsfeld 413 Nearly a Posting Virtuoso

I remember in school they talked about DIB (device indepentant bitmaps) to be best for stretching/enlarging. Was C class for graph artists.

bumsfeld 413 Nearly a Posting Virtuoso

Thanks G-do for informing us over the interesting medical work you are doing! Orange sounds like Python based data mining module, things that should be explored. Slovenia is just like Austria, very nice with much history and great people.

bumsfeld 413 Nearly a Posting Virtuoso

Nice project c_shaft05 you do much thinking here!

bumsfeld 413 Nearly a Posting Virtuoso

I know VegaSeat has put some wxPython code examples in the snippet part of this forums. Like:
http://daniweb.com/code/snippet227.html

bumsfeld 413 Nearly a Posting Virtuoso

If you know Windows/DOS batch language you can create and save batch file from within Python program, than run it with os.system("mybatfile.bat")

bumsfeld 413 Nearly a Posting Virtuoso

Windows supplies most of the fonts as "true type fonts" ( .TTF ). Don't know what Linux uses?

bumsfeld 413 Nearly a Posting Virtuoso

I have use the space/tab feature too, but don't always know how many spaces each tab is.

bumsfeld 413 Nearly a Posting Virtuoso

You need to give somewhat more info, like operating system? What have you actually tried? Are your looking for IDLE file that starts the editor?

bumsfeld 413 Nearly a Posting Virtuoso

I knew there had to be a way to avoid these global variables, I am still learning a lot, generator functions are somewhat confusing right now!

bumsfeld 413 Nearly a Posting Virtuoso

**rambling**
man python is great. you can do such nice stuff with next to no code, or programming experience.

--- and it is so easy to experiment with the codes!

bumsfeld 413 Nearly a Posting Virtuoso

You may want to use shutil.copy(sourcefile, destinationfile), it gives copy the current date, shutil.copy2(sourcefile, destinationfile) gives the date of the file you copy.

bumsfeld 413 Nearly a Posting Virtuoso

Looks like your turtle figures out the left and right side of box, but not top and bottom. Could this be because the way if evaluates your and statement? If y is false it doesn't bother with x.

bumsfeld 413 Nearly a Posting Virtuoso

Sorry, awe might not be the corrected word. I am impressed how you get idea and quickly know how to tackle with Python! I feel weak there. Maybe my brains is too saturated with C.

bumsfeld 413 Nearly a Posting Virtuoso

I looked at you updated project2.py.
Looks like you mixed space and tabs, got that fixed.
Random is imported but never used.
Don't you need line to start program?
What is range of steps, 1000 to 5000?

bumsfeld 413 Nearly a Posting Virtuoso

This is pretty complex programming. You are leaving me in awe! Where do you get the idea in first place?

bumsfeld 413 Nearly a Posting Virtuoso

I always learn that the use of global variables is to be discouraged. Is this the only way to copy static variable behaviour in Python?

bumsfeld 413 Nearly a Posting Virtuoso

I understand that PyGame is simply a wrapper for SDL. That creates a problem, Python has a good memory manager, but SDL written in C++ has the usual memory management is up to you thing. THESE TWO WORLDS LIKE TO CLASH AND CRASH!

bumsfeld 413 Nearly a Posting Virtuoso

I don't think Python is better than C++, but you can do thinks at a higher level with it.

bumsfeld 413 Nearly a Posting Virtuoso

Super job Micko! Why don't you post it right here, or better even in the Python snippetts.

bumsfeld 413 Nearly a Posting Virtuoso

Vegaseat, Micko gave the correct answer to CutCrusader's question. Your answer with the zero x in front does not.

bumsfeld 413 Nearly a Posting Virtuoso

I am still mostly using C. I know this probably a little bit old fashioned. I am following Python conversation closely too, looks like a interesting language to me. Does not have many many { and } and ;

bumsfeld 413 Nearly a Posting Virtuoso

I thinks IDLE uses Tkinter (TCL) and that is more internationally than PyWin's wxPython based code.

If you want portability of your code on the internet, don't use these special characters. I have the same problem with other non-english characters too.

bumsfeld 413 Nearly a Posting Virtuoso

What is a &quot supposed to mean? Are you sure you are using PHP?

bumsfeld 413 Nearly a Posting Virtuoso

Can you display that file on an editor? Are you sure you don't have a binary file? In that case use 'rb'

Using the python shell makes things look messy.

bumsfeld 413 Nearly a Posting Virtuoso

I am lost. Do you want to use a dictionary or a list? What does PHP have to do with it?