sneekula 969 Nearly a Posting Maven

I don't buy it unless it is free!

sneekula 969 Nearly a Posting Maven

A cat with a white stripe on top may not be one.

sneekula 969 Nearly a Posting Maven

To confuse variable Foo.__privatebar with Foo._Foo__privatebar would be a hard thing to do. As you can see, Python uses name mangling to protect a private variable.

sneekula 969 Nearly a Posting Maven

You don't always sort a list of strings alphabetically, sometimes you want to sort by the length of the string:

# sort a list of strings by length of string

text = "I have taken a vow of poverty to annoy me send money"

mylist = text.split()

print( "Original list: \n%s\n" % mylist )

mylist_sorted = sorted(mylist, key=len, reverse=True)
print( "Sorted by length of word: \n%s" % mylist_sorted )

"""my result -->
Original list: 
['I', 'have', 'taken', 'a', 'vow', 'of', 'poverty', 'to', 'annoy',
 'me', 'send', 'money']

Sorted by length of word: 
['poverty', 'taken', 'annoy', 'money', 'have', 'send', 'vow', 'of',
 'to', 'me', 'I', 'a']

In a similar fashion you can find the longest word in a list of words:

# find the longest word in a text

text = "I have taken a vow of poverty to annoy me send money"

# Python25 and higher allows key
word_list = text.split()
print( "The longest word is %s" % max(word_list, key=len) )
sneekula 969 Nearly a Posting Maven

You can use a dialog window in conjunction with a main window. Here is a wxPython example:

# a wxPython general frame with a dialog window
# the dialog shows full size even it the frame is minimized

import wx
import wx.calendar as cal

class MyCalendar(wx.Dialog):
    """create a simple dialog window with a calendar display"""
    def __init__(self, parent, mytitle):
        wx.Dialog.__init__(self, parent, wx.ID_ANY, mytitle)
        # use a box sizer to position controls vertically
        vbox = wx.BoxSizer(wx.VERTICAL)

        # wx.DateTime_Now() sets calendar to current date
        self.calendar = cal.CalendarCtrl(self, wx.ID_ANY, 
            wx.DateTime_Now())
        vbox.Add(self.calendar, 0, wx.EXPAND|wx.ALL, border=20)
        # click on day
        self.calendar.Bind(cal.EVT_CALENDAR_DAY, 
            self.onCalSelected)
        # change month
        self.calendar.Bind(cal.EVT_CALENDAR_MONTH, 
            self.onCalSelected)
        # change year
        self.calendar.Bind(cal.EVT_CALENDAR_YEAR, 
            self.onCalSelected)

        self.label = wx.StaticText(self, -1, 'click on a day')
        vbox.Add(self.label, 0, wx.EXPAND|wx.ALL, border=20)

        self.button = wx.Button(self, -1, 'Exit')
        vbox.Add(self.button, 0, wx.ALL|wx.ALIGN_CENTER, border=20)
        self.button.Bind(wx.EVT_BUTTON, self.onQuit)

        self.SetSizerAndFit(vbox)
        self.Show(True)
        self.Centre()

    def onCalSelected(self, event):
        #date = event.GetDate()
        date = self.calendar.GetDate()
        day = date.GetDay()
        # for some strange reason month starts with zero
        month = date.GetMonth() + 1
        # year is yyyy format
        year = date.GetYear()
        s1 = "%02d/%02d/%d \n" % (month, day, year)
        # or just take a slice of the first 8 characters
        # to show mm/dd/yy
        s2 = str(date)[0:8]
        self.label.SetLabel(s1 + s2)

    def onQuit(self, event):
        self.Destroy()


class MyFrame(wx.Frame):
    """create a frame as the main window"""
    def __init__(self, parent, mytitle, mysize):
        # use wx.ID_ANY or -1 as ID
        wx.Frame.__init__(self, parent, -1, mytitle, 
            pos=(10, 10), size=mysize)
        self.SetBackgroundColour("yellow")
        
        # this dialog will stay up even if MyFrame is minimzed
        mc = MyCalendar(None, 'dialog window with calendar')

        #
        # …
sneekula 969 Nearly a Posting Maven

Generally you would save the following three code files in the same directory:
class Tank as tank.py
class Grid as grid.py
your main code as tank_game.py
then run tank_game

Note that filenames for modules tank and grid are case sensitive!

sneekula 969 Nearly a Posting Maven

Professions can be ...

Judges disappointed
Lawyers disbarred
Gardeners deflowered
Tree surgeons debarked
Cowboys deranged
Celebrities defamed
Clergymen defrocked
Taste testers distasted
Wind farmers disgusted
Cardiologists disheartened
Accountants defiled
Electricians delighted
Programmers deprogrammed
Sculptors disfigured
Product testers detested
Castle architects demoted
Conductors disbanded
Musicians denoted
Churchmebers dismembered
Poker players discarded
Contortionists disjointed
Insurance agents disclaimed
Calendar photographers dismayed
Mimes disquieted
Bankers disinterested
Dressmakers distressed
Dry cleaners depressed?
Teachers degraded
Sailors deported
Landlords displaced

sneekula 969 Nearly a Posting Maven

Well, a whole year has gone by. Actually mostly business as usual, at least for most of us. The black hole has not swallowed us after all, and we still have air to breath. Even Hollywood has managed to supply us with plenty of movies to yawn along with.

Let's hope the following year will be as dull for humanity in general as the last one!

I see, DaniWeb has changed a little, but still manages to get those surprise duplicates popping up.

sneekula 969 Nearly a Posting Maven

Well, a whole year has gone by. Actually mostly business as usual, at least for most of us. The black hole has not swallowed us after all, and we still have air to breath. Even Hollywood has managed to supply us with plenty of movies to yawn along with.

Let's hope the following year will be as dull for humanity in general as the last one!

sneekula 969 Nearly a Posting Maven

the size of

sneekula 969 Nearly a Posting Maven

If my folks would be rich enough to have a cook, I made sure there was something better than ravioli in the fridge.

sneekula 969 Nearly a Posting Maven

My back still acts up now and then 10 years after my car accident. Hope Dani came out better!

sneekula 969 Nearly a Posting Maven

He was a devout Christian, so may the Lord bless him!

sneekula 969 Nearly a Posting Maven

Got a goofy message and ended up with a duplicate, sorry folks!

sneekula 969 Nearly a Posting Maven

Lardmeister suggested something much simpler, something like this:

# using the Tkinter canvas to
# draw a line from coordinates x1,y1 to x2,y2
# create_line(x1, y1, x2, y2, width=1, fill="black")

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

root = tk.Tk()
root.title("drawing lines")

# create the drawing canvas
canvas = tk.Canvas(root, width=450, height=450, bg='white')
canvas.pack()

# draw horizontal lines
x1 = 0
x2 = 450
for k in range(0, 500, 50):
    y1 = k
    y2 = k
    canvas.create_line(x1, y1, x2, y2)

# draw vertical lines
y1 = 0
y2 = 450
for k in range(0, 500, 50):
    x1 = k
    x2 = k
    canvas.create_line(x1, y1, x2, y2)

root.mainloop()
sneekula 969 Nearly a Posting Maven

The function split() is for strings, not for lists. In your program build up a CSV string rather than a list. Something like this:

def main():
    info = ""
    name1 = raw_input("What is your name? ")
    info += name1 + ','
    org_name = raw_input("What organization do you work for? ")
    info += org_name + ','
    title = raw_input("What is your title at this organization? ")
    info += title + ','
    addr1 = raw_input("What is the address of your organization, all on one line? ")
    info += addr1 + ','
    email1 = raw_input("What is your email address? ")
    info += email1 + ','
    phone1 = raw_input("What is your phone number? ")
    info += phone1 + '\n'
    print "We will be writing your information to a file."
    print info

main()

"""my display screen shows for example -->

What is your name? Frank Marsh
What organization do you work for? ACME Co
What is your title at this organization? Helper
What is the address of your organization, all on one line? 123 West St Morghantown WV
What is your email address? framar@hotmail.net
What is your phone number? 123-456-7890
We will be writing your information to a file.
Frank Marsh,ACME Co,Helper,123 West St Morghantown WV,framar@hotmail.net,123-456-7890

"""
sneekula 969 Nearly a Posting Maven

Here is a basic example of the use of Sqlite3

# test the sqlite3 module, write and read a database file
# note that Python25 and higher versions have sqlite3 builtin
# sqlite3.connect(database, timeout=5.0, isolation_level=None,
#   detect_types=0, factory=100)
# timeout=5.0 --> allows multiple access for 5 seconds (for servers)
# isolation_level=None -->  autocommit mode
# detect_types=0 --> native types TEXT, INTEGER, FLOAT, BLOB and NULL
# factory=100 --> statement cache to avoid SQL parsing overhead
# tested with Python26 and Python31
# Source:  Sneekula

import sqlite3

# create/connect to a permanent file database
con = sqlite3.connect("my_db.db3")
# for temporary testing you can use memory only
#con = sqlite3.connect(":memory:")

# establish the cursor, needed to execute the connected db
cur = con.cursor()

# create/execute a table:
# (optionally used capital letters to show commands)
cur.execute('CREATE TABLE IF NOT EXISTS clients \
    (id INT PRIMARY KEY, \
    firstname CHAR(60), \
    lastname CHAR(60))')

# insert several lines at once using a
# list of (id, firstname, lastname) tuples
# use try/except or the existing db will complain about
# the non-unique id since it is already in the db
try:
    clients = [
    (107, "Ella", "Fitzgerald"),
    (108, "Louis", "Armstrong"),
    (109, "Miles", "Davis")
    ]
    cur.executemany("INSERT INTO clients (id, firstname, lastname) \
        VALUES (?, ?, ?)", clients )
except:
    pass

# add another client
# again, use try/except or the existing db will complain about
# the non-unique id if it is already in the db
try:
    new_client = (110, "Benny", "Goodman")
    cur.execute("INSERT INTO …
sneekula 969 Nearly a Posting Maven

The Python world is going through a transition. I do more and more work with Python 3.1.2, but still use Python 2.6.5 for some stuff.

Most folks are waiting for wxPython and PIL to make the transition. In the mean time I am using the PyQT GUI toolkit and the newer version of Tkinter that ships with Python31

sneekula 969 Nearly a Posting Maven

If it's a bug with Windows 7, maybe you have to wait until they release Windows 7.1

sneekula 969 Nearly a Posting Maven

for i in range(number of blocks of 512 bits): looks like pseudo code.

sneekula 969 Nearly a Posting Maven

Sometimes you want a button that toggles between two different actions:

# wxToggleButton2.py
# testing wxPython's
# wx.ToggleButton(parent, id, label, pos, size, style)
# snee

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, -1, mytitle, size=mysize)
        # use panel so position of button behaves
        panel = wx.Panel(self, wx.ID_ANY)

        self.tbtn = wx.ToggleButton(panel, id=-1, label='Toggle Off',
            pos=(20, 25))
        # bind mouse click event to an action
        self.tbtn.Bind(wx.EVT_TOGGLEBUTTON, self.onToggle)

    def onToggle(self, event):
        # self.tbtn.GetValue() toggles between True or False
        if self.tbtn.GetValue():
            self.tbtn.SetLabel('Toggle On')
        else:
            self.tbtn.SetLabel('Toggle Off')


app = wx.App(0)
MyFrame(None, 'wx.ToggleButton test', (300, 100)).Show()
app.MainLoop()
sneekula 969 Nearly a Posting Maven

I think Excel uses vbasic as an internal scripting language. It might be simpler to apply that.

However, the Open Office equivalent spreadsheet can use Python as a scripting language. See module pyuno.

sneekula 969 Nearly a Posting Maven

One way to do this is using a shifted alphabet, here is a simple example:

# rotation_crypt1.py
# use the index in the regular alphabet and apply it to a
# shifted alphabet (all upper case letters for simplicity)

import string

alpha = string.ascii_uppercase

shift = 3
# shift the alphabet with slicing
shift_alpha = alpha[shift:] + alpha[:shift]

# testing
letter = 'X'
coded = shift_alpha[alpha.find(letter)]
print "%s shifted %d gives letter %s" % (letter, shift, coded)

letter = 'Z'
coded = shift_alpha[alpha.find(letter)]
print "%s shifted %d gives letter %s" % (letter, shift, coded)

letter = 'A'
coded = shift_alpha[alpha.find(letter)]
print "%s shifted %d gives letter %s" % (letter, shift, coded)

"""my test result -->
X shifted 3 gives letter A
Z shifted 3 gives letter C
A shifted 3 gives letter D
"""
sneekula 969 Nearly a Posting Maven

Symbian is an operating system designed for mobile devices and smart-phones,

sneekula 969 Nearly a Posting Maven

We never see ourselves as others see us.
~~~ Oliver Hardy

sneekula 969 Nearly a Posting Maven

Time for spaghetti and meatballs with plenty of Parmesan cheese.

sneekula 969 Nearly a Posting Maven

Typical Dutch humor.

sneekula 969 Nearly a Posting Maven

Looks like an applied Bible study.

sneekula 969 Nearly a Posting Maven

A tall glass of grapefruit juice and a toasted Asiago cheese bagel.

sneekula 969 Nearly a Posting Maven

It will make future wars so much easier! Send in your robots, make a mess out of that country and leave. Any politicians dream!

The only defense against such an attack is to have nuclear weapons and a good delivery system, retaliatory weapons produced and stored in secretive deep underground systems.

sneekula 969 Nearly a Posting Maven

Never mind. I downloaded SPE on my Ubuntu machine.
The package installer on ubuntu integrated with SPE works like a charm.
Looks like a neat IDE. Will give it a shot, and see if it's worth moving over from Netbeans/Eclipse.
I like Jython, that's why I stay with Netbeans.

I use Linux Ubuntu on my Dell notebook, and use SPE and wxGlade for my quick wxPython designs. It does work very well. The nice thing about wxGlade is that it produces .py code directly. The code is not too ugly and is easily modified to make a working program. Still using Python 2.5.2 on that machine. But I know from friends that SPE works flawless with Python 2.6 (Windows XP).

Maybe you can give us a taste of Jython GUI code sometime.

sneekula 969 Nearly a Posting Maven

We have established client-server connection in python using send() and recv() . Now we need to send a shell command(eg: ls) from 1st system to 2nd; execute it in 2nd and copy back the result to the 1st. You people out there, please suggest something...

Hijacking an old thrtead is not the way to go. If you really want help, start a new thread with a good descriptive title.

sneekula 969 Nearly a Posting Maven

Actually quite simple using button["text"]:

# explore Tkinter button as simple toggle

import Tkinter as tk  # for Python3 use import tkinter as tk

def toggle_text():
    """toggle button text between Hi and Goodbye"""
    if button["text"] == "Hi":
        # switch to Goodbye
        button["text"] = "Goodbye"
    else:
        # reset to Hi
        button["text"] = "Hi"


root = tk.Tk()
root.title("Click the Button")

button = tk.Button( text="Hi", width=12, command=toggle_text)
button.pack(padx=100, pady=10)

root.mainloop()
vegaseat commented: very good example +10
sneekula 969 Nearly a Posting Maven

You need to add a space between words:

def small():
    words = 'hello, this is my test'
    forbidden = 'l, h, e'
    a = ''
    for word in words.split():
        for letter in word:
            if letter in forbidden:
                letter = ''
            else:
                a = a + letter
        # add a space between words
        a = a + ' '

    print a

small()
sneekula 969 Nearly a Posting Maven

It pays to study up on Python OOP a little.

Here is an example:

# explore wxPython's entry/wx.TextCtrl and label/wx.StaticText

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent=None):
        wx.Frame.__init__(self, parent, -1, size=(300, 200))
        s = "Enter your name below:"
        label = wx.StaticText(self, -1, s)
        # style=wx.TE_PROCESS_ENTER needed for Linux
        self.text_in = wx.TextCtrl(self, -1, size=(250, 20),
            style=wx.TE_PROCESS_ENTER)
        # respond to enter key when focus is on text_in
        self.text_in.Bind(wx.EVT_TEXT_ENTER, self.onEnter)
        # cursor in text_in
        self.text_in.SetFocus()
        
        # create another text control for output
        self.text_out = wx.TextCtrl(self, -1, size=(250, 20))

        sizer = wx.BoxSizer(wx.VERTICAL)
        flag1 = wx.LEFT|wx.TOP|wx.EXPAND
        flag2 = wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND
        flag3 = wx.ALL|wx.EXPAND
        sizer.Add(label, 0, flag=flag1, border=10)
        sizer.Add(self.text_in, 0, flag=flag2, border=10)
        sizer.Add(self.text_out, 0, flag=flag3, border=10)
        self.SetSizerAndFit(sizer)

    def onEnter(self, event):
        """the enter key has been pressed, do something"""
        name = self.text_in.GetValue()
        print(name)  # test
        s = "You entered the name: " + name
        # new text
        self.text_out.ChangeValue(s)
        # appends to existing text
        #self.text_out.AppendText(s)


app = wx.App(0)
# create a MyFrame instance and show the frame
MyFrame().Show()
app.MainLoop()
sneekula 969 Nearly a Posting Maven

Has anybody seen that 2012 movie?

sneekula 969 Nearly a Posting Maven

Don't find a fault, find a fix!

sneekula 969 Nearly a Posting Maven

Yes. It's completely true. Run outside and panic.
Also cancel your xmas plans.

This should be:
Yes. It's completely true. Party like crazy!

sneekula 969 Nearly a Posting Maven

Is't really true that december 21, 2012 is the end of the world? they say the signs are clear. changing climate, frequent disaster. There is even a rumor that the government has found a new planet that can support life that rich people specially the government officials secretly built spaceships for them when the end of the world will occur? they say the government already knows about this but didn't reveal it to avoid panic.

Getting rid of all those dang government officials is something to look forward to then! Just think, there may be a few weeks we can actually live it up, unless of course the greedy bankers get us all first!

sneekula 969 Nearly a Posting Maven

I have to create a new password every month, so it is the name of my first girl friend plus the number of the month.

sneekula 969 Nearly a Posting Maven

A fist full of dark chocolate covered cherries from Trader Joe.

sneekula 969 Nearly a Posting Maven

I like to use tkinter for some real quick stuff, but use mostly wxPython and sometimes Pyqt.

Good Pyqt examples are hard to find. My biggest source of good Pyqt info is:
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/classes.html

sneekula 969 Nearly a Posting Maven

The bulk of Nigerian Scams originate from Amsterdam, Atlanta, Toronto and Madrid.

sneekula 969 Nearly a Posting Maven

You'll end up looking for something unnatural to create things.. call it God and ease your life..:icon_rolleyes:

Amen! Even so I think God created us to be curious and not stupid.

oops was:
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 58368 bytes) in /home/daniweb/httpdocs/forums/includes/class_mail.php(266) : eval()'d code on line 147

sneekula 969 Nearly a Posting Maven

oops

sneekula 969 Nearly a Posting Maven

I have a sweet tooth for song and music. This is my Polish sin.
~~~ Pope John Paul II

sneekula 969 Nearly a Posting Maven

Is this thread about the Unix timestamp 2038 bug when 32-bit integers run out of numbers. If they used the php bcmath library for the timestamp then they could have infinite numbers. Imagine the possibilities if they made a type of integer which could hold infinite numbers. That would be cool and might be what they will have to do by the end of the millennium.

Wonder how large "they could have infinite numbers" is?

sneekula 969 Nearly a Posting Maven

A chicken breast sandwich with pear juice.

sneekula 969 Nearly a Posting Maven

You might have to preprocess the file first.

sneekula 969 Nearly a Posting Maven

Green letters on a black background are really hard to read.