woooee 814 Nearly a Posting Maven

@woooee: Your program opened zillion copies of the progress bar and had to be closed forcefully, see screen capture.

It will open one GUI for each
pr2=Process(target=PB.start_running(), args=())
statement so either multiprocessing has been broken for years and you are the only one to catch it, or the code would have to be different than what was posted here.

woooee 814 Nearly a Posting Maven

Pyguy62 is correct about the button call back. To send arguments to a function from a Tkinter callback you use partial.

from functools import partial
for item in options :
    Button(self.wdw, text= item, command= parital(self.escolha, item=item)).pack()

My problem is that when I launch the second window with the options my main application continues to run with default options

How are you accessing/passing the values from the second window to the first window's program?

Also you probably want to include "takefocus=True" when creating the Toplevel GUI.

woooee 814 Nearly a Posting Maven

And you might want to use a tuple for the key, ("man1", "car"), ("man1", "wallet"), etc. as a dictionary of dictionaries gets messy fast.

woooee 814 Nearly a Posting Maven

self.vbox1 = wx.Sizer(wx.VERTICAL)

self.hbox1 = wx.Sizer(wx.HORIZONTAL)

You possibly want

self.hbox1 = wx.BoxSizer()
self.hbox1.Add(self.yt_username, flag = wx.EXPAND | wx.RIGHT, border = 8)

self.vbox1 = wx.Sizer(wx.VERTICAL) 
# and the above becomes
self.vbox1 = wx.BoxSizer(wx.VERTICAL)

See this example in the "Starting wxPython (GUI code)" thread.

woooee 814 Nearly a Posting Maven

This is a __very__simple__ example of a progress bar, using multiprocessing to display the bar while another function counts down in a label. Perhaps you can adapt some of the code to pygtk.

from multiprocessing import Process
import time

try:
    import Tkinter as tk
except:
    import tkinter as tk

class ProgressBar():
    def __init__(self, root):
        self.root=root
        self.root.geometry("75x50+600+100")

    def mainloop(self):
        self.root.mainloop()

    def start_running(self):
        """ create the progress bar widget
        """
        self.top=tk.Toplevel(self.root)
        self.top.title("Progress Bar")
        self.top.geometry("+500+300")

        canvas = tk.Canvas(self.top, width=265, height=60)
        canvas.pack()

        rc2 = canvas.create_rectangle(15, 20, 245, 50, outline='blue', fill='gray')
        rc1 = canvas.create_rectangle(25, 20, 35, 50, outline='white', fill='blue')

        total=100
        x = 5
        while True:        ## move the small rectangle +5 or -5 units
            total += x
            if total > 310:
                x = -5
            elif total < 100:
                x = 5
            time.sleep(0.2)
            canvas.move(rc1, x, 0)
            canvas.update()

    def start_countdown(self):
        """ a separate process in a separate GUI
        """
        self.label_ctr = tk.IntVar()
        label = tk.Label(self.root, textvariable=self.label_ctr)
        label.pack()
        self.ctr=25
        self.root.after(750, self.update)

    def update(self):
        if self.ctr > 0:
            self.label_ctr.set(self.ctr)
            self.ctr -= 1

            # use recursion-generally a bad idea-but there are only 25 calls
            self.root.after(750, self.update)
        else:
            self.root.destroy()   ## destroy root when zero is reached

root = tk.Tk()

PB=ProgressBar(root)
pr2=Process(target=PB.start_countdown(), args=())
pr2.start()

pr1=Process(target=PB.start_running(), args=())
pr1.start()

## start mainloop in a separate process as a function of the class
## don't know if this is really necessary or not
## the theory is, it is detached from the other 2 processes and so
##    can react to both independently
## also the mainloop() process can be killed=shut down properly
pr3=Process(target=PB.mainloop(), …
woooee 814 Nearly a Posting Maven

You can just update a dialog box, or whatever, each time a file is copied. "Copied x of total files"

woooee 814 Nearly a Posting Maven

You can also use divmod.

whole, remain = divmod(11, 3)
print whole, remain
woooee 814 Nearly a Posting Maven

So, while do_something is copying the files, I want a window to appear on the screen showing something like a "Please wait" message and a spinner

If you want to do two things at once, it requires threading or multiprocessing, I don't know if GTK/Glade has one built in or if you would use Python's. You could also update a progress bar after every file is copied, which would not require multiprocessing.

woooee 814 Nearly a Posting Maven

A way that is perhaps easier to understand, but slightly more processor intensive, is to store the first record, add up all of the columns from all of the records, and then print the values for the columns > 6 in the first record. And I don't understand what the variable "idk" is used for.

woooee 814 Nearly a Posting Maven

everything works fine except secondWindow doesn't show up

You hide it.

def do_something(x, y) :			
			# Code
			return True

		self.mainWindow.hide()
		self.secondWindow.show()
		isdone = do_something(x, y)

                ## isdone is always True so secondWindow is always hidden
		if isdone :
			self.secondWindow.hide()

And Tony is correct. Your indentation is terrible. If you want help, you should make your code as readable as possible. The first rule is to use spaces only instead of tabs. Most text processors/IDE's will convert tabs to spaces for you.

woooee 814 Nearly a Posting Maven

cos i tried testing 21 and 49, and they were tested as prime.
thanks!

What does this mean as "It is" or "It is not a prime number" will print y-1 times for each number tested, or until "not prime" is found. Add a print statement under the for() loop to print "i" and test with an odd number like 25, so prime is not found until 5 is tested. You only have to test for "can be divided by 2" once, and then use the step parameter of the for() to increment from 3, step 2=every other number so you don't waste time dividing by even numbers since you have already checked if it is divisible by 2. Also, the general assumption is that if you are too lazy to key in actual words instead of teeny-bopper slang, you are just lazy and looking for someone to do it for you, so there are very few responses.

woooee 814 Nearly a Posting Maven

I have code for the chart but I just don't know how to insert the data into it.

ASCII "data" is just integers from 0-255

Ene Uran commented: true +13
woooee 814 Nearly a Posting Maven

Check out the difference between copy and deepcopy as well. You probably want deepcopy (not a copy, and not a reference pointer to the list) since b is a list of tuples

a=[[(34,5),(34,6)],[(35,5),(35,6)]]
b=[(36,5),(36,6)]
a.append(copy.deepcopy(b))
JoshuaBurleson commented: good advice, didn't even think of it. +3
woooee 814 Nearly a Posting Maven

You can also use eval().

x=eval("9.15E+02")
print x, type(x)  ## --> 915.0 float
woooee 814 Nearly a Posting Maven

If you want to eliminate certain common words like "the and "and", etc. use a list.

omit_words = ["the", "a", "and", "but", "i"]
    for w in sorted_words[0:30]:
        if w not in omit_words:
woooee 814 Nearly a Posting Maven

The Tkinter keyword is "image" not "self.image"; see the example here. Also, a label is usually in a frame or some other container. Finally, you can not mix grid() and pack() so choose one or the other.

gmail=PhotoImage(file='gmail.gif')
self.lab=Label(image=gmail)
self.lab.photo=gmail
self.lab.pack()
woooee 814 Nearly a Posting Maven

Or, to state Snippsat's post another way, add another print statement.

for l in word:
    total=total+ord(l)-64
    print l, ord(l)-64, total
woooee 814 Nearly a Posting Maven

You would bind <TAB> to a function that would set the focus to the next button. The program would then know which button the <RETURN> should be bound to. See the examples at this page. The program becomes more complicated if you also want to include a button click to set the focus. You would have to then bind <Button-1> to a function that determines the location of the mouse and sets the focus, also allowing the program to know that the <RETURN> is in an entry box or where ever.

woooee 814 Nearly a Posting Maven

See this similar thread for a more complete solution (probably some one in the same class). It is pretty close to what was posted here. Also read this thread.

woooee 814 Nearly a Posting Maven

Which SQL are you using? If it's SQLite, it does not support this feature.

woooee 814 Nearly a Posting Maven

Use instance variables (self.) instead of global variables. Also, you can clean the program up by combining all of the number buttons into one for() loop and pass the number to a common function.

import wx
from functools import partial

class jake(wx.Frame):
    def __init__(self,parent,id):
        self.foo=""
        self.outp=0
        wx.Frame.__init__(self,parent,id,'Virtual Bank', size=(500,550))
        panel=wx.Panel(self)

        ## you can add in 4-->decimal buttons
        for button in (("1", 10, 100), ("2", 110, 100), ("3", 210,100)):
            this_button=wx.Button(panel,label=button[0],
                             pos=(button[1],button[2]),size=(75,75))
            self.Bind(wx.EVT_BUTTON, partial(self.func1, num=button[0]), 
                             this_button)

        info=wx.Button(panel,label="INFO",pos=(210,400),size=(75,75))
        withdraw=wx.Button(panel,label="WITHDRAW",pos=(330,100),size=(130,75))
        deposit=wx.Button(panel,label="DEPOSIT",pos=(330,200),size=(130,75))
        balance=wx.Button(panel,label="BALANCE",pos=(330,300),size=(130,75))
        status=wx.Button(panel,label="STATUS",pos=(330,400),size=(130,75))
        self.Bind(wx.EVT_BUTTON, self.decimalfunc, decimal)
        self.Bind(wx.EVT_BUTTON, self.infofunc, info)
        self.Bind(wx.EVT_BUTTON, self.withdraw, withdraw)
        self.Bind(wx.EVT_BUTTON, self.deposit, deposit)
        self.Bind(wx.EVT_BUTTON, self.showbalance, balance)
        self.Bind(wx.EVT_BUTTON, self.showstatus, status)
        wx.StaticText(panel,-1,str(self.outp),(10,45))
        wx.StaticText(panel,-1,"Welcome To VirtualBank!",(180,20))
        wx.StaticText(panel,-1,"$",(10,40))

    def func1(self, event, num):
        self.foo+=num
        self.outp+=1
        print num, "button pressed and total input is now", self.foo
    def decimalfunc(self,event):
        pass
    def infofunc(self,event):
        pass
    def withdraw(self,event):
        pass
    def deposit(self,event):
        pass
    def showbalance(self,event):
        pass
    def showstatus(self,event):
        pass
        
if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=jake(parent=None,id=-1)
    frame.Show()
    app.MainLoop()
woooee 814 Nearly a Posting Maven

You can pass the acceptable values to the checkInput() function and let it do the work. For the getFloat() function, use a try/except to test for correct input.

def checkInput(prompt, values_list):
    print "\n"
    while True:
        result = input(prompt).strip()
        if result.lower() in values_list:
            return result

        print("Please enter an appropriate value --> " + ", ".join(values_list))


deg = checkInput("Do you have Celsius, Fahrenheit, or Kelvin? ", \
                ['c', 'celsius', 'f', 'fahrenheit', 'k', 'kelvin'])
cdeg = checkInput("Convert to: Fahrenheit or Kelvin? ", \
                 ['f', 'fahrenheit', 'k', 'kelvin'])
print deg, cdeg


def getFloat(prompt):
    while True:
        result = input(prompt)
        try:
            return float(result)
        except:
            print("Enter a number only\n")

fcel = getFloat("What is the degrees in Celsius? ")
print fcel
TrustyTony commented: Good code (except not functions first) +13
woooee 814 Nearly a Posting Maven

However, for just the input(), I need to check to make sure it's not a number and to check to make sure it isn't blank

To make sure it isn't blank, check that len(variable.strip()) > 0
To make sure that it is not a number, you can use not variable.isdigit(), although a number with a comma or decimal point in it is not isdigit() so you can also use

found=False
for ltr in input_string.strip():
    if "a" <= ltr.lower() <= "z":
        found=True
if found...etc 
#
# list comprehension
x = [ltr for ltr in variable if "a" <= ltr.lower() <= "z"]
if len(x)
woooee 814 Nearly a Posting Maven

AFAIK the Tkinter text widget is the only widget that will do sub/super-scripts. You would have to use a gif of the text or some other nasty work around to do it.

woooee 814 Nearly a Posting Maven

Nice. I would never have thought of using GMail.

woooee 814 Nearly a Posting Maven

I want to see how many elements are within each group of coordinates from file2

Does this mean you want to count them or print/copy them?

You only have to store the first file in a container, and check each record from the second file against it. The following uses a dictionary and the test data submitted. To keep track of the number of records found, you can either change the dictionary to point to a list that also contains a counter, or if you think it is easier to understand, use a second dictionary using the same key pointing to a counter. Either way, post your code for more assistance.

file_1 = ["elem1 39887", "elem2 72111"]
file_1_dict = {}
for rec in file_1:
    rec_split = rec.split()
    key = rec_split[0]
    if key not in file_1_dict:  ## allow for possible duplicte entries
        ## compare integers as strings sort from left to right
        file_1_dict[key]=int(rec_split[1])

file_2 = ["elem1 1 57898", "elem1 57899 69887", "elem2 69888 82111"]
for rec in file_2:
    rec_split = rec.split()
    key = rec_split[0]
    if key in file_1_dict:
        low=int(rec_split[1])
        high=int(rec_split[2])
        print "testing key", key, low, high,
        if low < file_1_dict[key] < high:
            print "Found"
        else:
            print "Not Found"
woooee 814 Nearly a Posting Maven

and then i have to write down the programm to get dictionary of people that know each other depending on the pictures they were on together

The index would be the photo, pointing to a list or set of all people in the photo.

now i would have to edit my program to get all the pairs of people that ever apeared on the picture together

If you mean pairs that have been in more than one photo, you would take each photo/key in the dictionary, loop through the items to get one pair at a time, and see if both of the people in the pair are in any other of the dictionary's items.

# pseudo-code
keys_list = dictionary.keys()
for ctr, key in enumerate(keys_list):
    ## assume split into pairs to create tuple, each_pair
    for each_pair in dictionary[key]:
        # search the remainder of the dictionary
        for key_2 in key_list[ctr:]: 
            if pair[0] in dictionary[key_2] and pair[1] in dictionary[key_2]:
                print "found", pair, "in", key, key_2
woooee 814 Nearly a Posting Maven

Computers use numbers not strings. To check for a certain user I would use os.getuid(); root=0 and all other users=some other number. You can print the value for the halton user to find that user's number. I think the hack to get the name is something like
pwd.getpwuid(os.getuid())[0]
Also, you can modify the /etc/fstab file to allow a group to mount the drive, which halton would be in, and eliminate the test for halton or root.

woooee 814 Nearly a Posting Maven

Using a for() loop which may be easier to understand:

input_str = "2BBI,3HHR"
unique_list = []
for ltr in input_str:
    if ltr not in unique_list:
        unique_list.append(ltr)
print unique_list  ## 2BI,3HR
woooee 814 Nearly a Posting Maven

If the OP would post the code for creating the 52 card deck it would yield better/more answers as the logic depends on how the deck it formatted.

player.append(rc(cards))

Note also, that random choice can return the same item/card multiple times. Use random.shuffle(card_deck) and deal the (now randomly arranged) cards in order.

woooee 814 Nearly a Posting Maven

I would suggest that you print "ab" prior to the search. Since it is not passed to the class, the class has no idea what it is.

if __name__=='__main__':
    ab={'josh':'me'}
    AB=AddressBook(ab)  ## AB=class instance, ab=dict

class Interface(Frame):
    def __init__(self, master, AB_instance):
        self.AB_instance=AB_instance

        if query==self.AB_instance.book:

Interface(root, AB) 
#
##--------- or -------------------------------------------------------
if __name__=='__main__':
    ab={'josh':'me'}
#    AB=AddressBook(ab)  ## AB=class instance, ab=dict

class Interface(Frame):
    def __init__(self, master, ab_dict):
        self.ab_dict=ab_dict

        if query in self.ab_dict:  ## search for "josh"

Interface(root, ab)
woooee 814 Nearly a Posting Maven

How are you designating the cards, numbers 1-52, or value and suit (10Heart)?. You can use one of the following depending on how the cards are kept:

# two related lists 
cards = [2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace]
cards_name=['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace']
#
# a list of tuples
cards=[(2. '2'), (3, '3') --> (10, 'Jack'), (10, 'Queen'), (10, 'King'), (11, 'Ace')]
print "value=%s, name=%s"  (cards[0]. cards[1])
#
# a dictionary
cards_dict={}
cards_dict['2']=2
cards_dict['Ace']=11
woooee 814 Nearly a Posting Maven

This should be enough to start things off, but I'm not sure about what is to be done with the "S1", "S2", etc. output.

def process_group(group_list, fp_surface, fp_underline):
    result = test_for_underline(group_list, fp_underline)
    if not result:
        tup_of_Sx = ("S1", "S2", "S3", "S4", "S5", "S6")
        for rec in group_list:
            rec_split = rec.strip().split(",")
            ending=rec_split[-1].strip()
            if ending in tup_of_Sx:
                idx = tup_of_Sx.index(ending)
                output_list = ["         " for x in range(6)]
                output_list[idx]="%9s" % (rec_split[0].strip())
                fp_surface.write("%s\n" % ("".join(output_list)))
            else:   ## headings
                fp_surface.write("\n")
                fp_surface.write(rec)
                for Sx in tup_of_Sx:
                    fp_surface.write("%9s" % (Sx))
                fp_surface.write("\n")

def test_for_underline(group_list, fp_underline):
    """ see if there is a record that starts with an underline.
        If found, write to the underline file and return True
    """
    for rec in group_list:
        if rec.strip().startswith("_"):
            fp_underline.writelines(group_list)
            return True

    return False

surface_found = False
end_found = False
group_list = []

fp_not_surface = open("./test_not_surface", "w")  ## records before *SURFACE
fp_surface = open("./test_surface", "w")          ## records after *SURFACE
fp_underline = open("./test_underline", "w")

fname = "./test2.inp"
fp_in = open(fname, "r")
for rec in fp_in:
    if "end part" in rec.lower():
        end_found = True
    if not end_found:
        if "*SURFACE" in rec:     ## process previous group of records
            surface_found = True
            if len(group_list):
                process_group(group_list, fp_surface, fp_underline)
                group_list = []
        if surface_found:
            if not rec.strip().startswith(("**HM", "**HW")):  ## omit these
                group_list.append(rec)
        else:     ## records before the first "*SURFACE"
            fp_not_surface.write(rec)

if len(group_list):
    process_group(group_list, fp_surface, fp_underline)


fp_in.close()
fp_not_surface.close()
fp_surface.close()
fp_underline.close()
woooee 814 Nearly a Posting Maven

Small typo I think:
if lines.strip().startswith("**HM", "**HW"):

should be

if lines.strip().startswith(("**HM", "**HW")):

It's good to have multiple pairs of eyes checking things.

woooee 814 Nearly a Posting Maven

There is no way to make heads or tails of this code for those of us who don't know what you are trying to do. Some general suggestions

1. Break this code into functions and test each function
2. instead of surface = "*SURFACE" in lines.strip()
   and then if surface:  (which means nothing to anyone reading the code)
   just use if "*SURFACE" in lines.strip(): as it is obvious what the test is
3. nameSurf and elsetName are the same, i.e. [1] (obviously you did not test this)
        starSurf  = nline.split(",")[0].strip()
        nameSurf  = nline.split(",")[1].split("=")[1].strip()
        typeSurf  = nline.split(",")[2].strip()
        elsetName = nline.split(",")[1].split("=")[1].strip()

   instead use: interim_list = nline.split(",") i.e. one split instead of many
        starSurf  = interim_list[0].strip()
        nameSurf  = interim_list[1].split("=")[1].strip()
        etc.
4. instead of
    S1 = lines.strip().endswith("S1")
    S2 = lines.strip().endswith("S2")
    etc. and
   elif (S1 or S2 or S3 or S4 or S5 or S6) and under == False:
   use
   ending = lines.strip()[-2:]
   elif (under==False) and ending in ("S1", "S2", "S3", "S4", "S5", "S6"):
5. and similarly replace
    HM = lines.strip().startswith("**HM")
    HW = lines.strip().startswith("**HW")
    elif HM or HW:
    with
    if lines.strip().startswith("**HM", "**HW"):
6. eliminate all of the many lines.strip() call with one
    line_strip = lines.strip() and use line_strip
woooee 814 Nearly a Posting Maven

It appears that this forum has a reputation for free code as I don't see this much on other forums. But then again, if you are the OP of the "calculating the avg and std" post, you know that you can just keep asking questions until someone provides a complete solution.

woooee 814 Nearly a Posting Maven

What I want to do is move the event handling out to the "Display" instance of the "UUTInfo" class

That would require some form of multiprocessing as you have two processes running at the same time; the wx application and the code that kills it.

woooee 814 Nearly a Posting Maven

It has nothing to do with class instances, but with the self.destroy which shuts down wx. If you want to destroy/close one object only, then you must first create the object and then close/destroy it only. There is a "Starting wxPython" at the top of the threads that has examples of destroy. Also, simplify your code to start with. An example of destroying an object follows. Click on one of the buttons to destroy it.

import wx
 
class Test:
    def __init__(self):
        app = wx.App(False)
        self.app = app
        frame = wx.Frame(None, wx.ID_ANY, "Test App")
        panel = wx.Panel(frame)
        vboxsizer = wx.BoxSizer(wx.VERTICAL)
        self.frame = frame
        self.panel = panel
 
        self.grid = wx.GridSizer(rows=0, cols=3)

        self.button_dict = {}
        x = 10
        y = 20
        for j in range(5):
            print j, x, y
            b = wx.Button(panel, label="Remove Button %d" % (j), id=j, pos=(x, y))
            self.grid.Add(b)
            b.Bind(wx.EVT_BUTTON, self.removeButton)
            self.button_dict[j] = b
            x += 50
            if j == 2:
                x = 10
                y = 30 

        exit = wx.Button(panel, -1, 'Exit', (10, 200))
        exit.Bind(wx.EVT_BUTTON,  self.exit_this)

        vboxsizer.Add(self.grid, 1, border=2, flag=wx.EXPAND|wx.ALL)
        panel.SetSizer(vboxsizer)
        frame.Show(True)
 
        app.MainLoop()
 

    def removeButton(self,e):
        button_num = e.GetId()
        print "ID =", button_num, type(button_num)
        if button_num in self.button_dict:
            self.button_dict[button_num].Destroy()


    def exit_this(self, event):
        self.frame.Destroy()

if __name__ == "__main__":
    t = Test()

Also, you can clean up the code mess by creating the widgets using a simple tuple (NOT tested):

self.widgets_dict = {}
widgets_tup= (("label_1", "This TPS is for the following UUT"),
              ("label_9", "Please Enter UUT Revision and Serial Number"),
              ("label_2", " Manufacturer:"),
              ("Man_Name", "").
              ("label_3", " Model Number:"))
# etc
# …
woooee 814 Nearly a Posting Maven

A numpy array is accessed by row and column. Add some print statements to find out what the data looks like. Also, a numpy array is overkill. Read the records one by one and store/calculate the values. Start with some sample data that is small, say 10 records, so you don't have to go through all of the files and data each time. Also, read the directory tree and send each file name to a common function to process.

woooee 814 Nearly a Posting Maven

A class does not exist, it is a prototype for actual objects. Only a class instance exists. That is why we declare an instance for each class object desired.

class Person(object):
    def __init__(self, name, health=100):
        self.name=name
        self.health=100

    def hurt(self, amount):
        print("%s health = %d - %d" % (self.name, self.health, amount))
        self.health-=amount
     
class Killer(object):
    def __init__(self):
        import random
        power= random.randint(10, 21)
        self.power=power
        print("power:", self.power)
     
    def stab(self,Person):
        Person.hurt(self.power)
     
K = Killer()
James=Person('James')
Karen=Person('Karen')
K.stab(James)
K.stab(Karen)
K.stab(James)
JoshuaBurleson commented: Exactly what I needed. Rather than simply showing the code you explained the mechanical issue at hand. Great post! +2
woooee 814 Nearly a Posting Maven

As I see it, the function UUT_Info() does not know about __name__, wx, or InfoUUT() as they are all declared/defined somewhere else and not passed to the function, but without a complete error message there is no way to tell which name is undefined. You would use something like

from wx import *
import file_that_contains_InfoUUT

def UUT_Info():
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    Display = file_that_contains_InfoUUT.InfoUUT(None, -1, "")
woooee 814 Nearly a Posting Maven

"self" is just a reference to the class, so that the class knows that the function or variable is in it's name space, so you have to include it when calling a function of the class from/within the class, otherwise the compiler will default to looking outside of the class for the function or variable.

class OffSwitch(object):
    def __init__(self):
        self.keycheck='off'
        print self.keycheck

        self.turn_off('yellow')   
  
    def turn_off(self,key):
        self.keycheck = key
        print self.keycheck
     
OS = OffSwitch()
#
# outside the class
OS.turn_off("outside")
woooee 814 Nearly a Posting Maven

I like to use a function as it is simple and the logic obvious

def value_func():
    value = -1
    if true:
        print 'hello world'
     
    # Some unexpected value is set so I would like to leave here
    # but break statement is for loop and not for if
    if value < 0:
        return some_value
woooee 814 Nearly a Posting Maven

You can replace

if ' ' in sentence:
    words = sentence.split()
    encrypted_words = []
else:
#
#etc.  with
words = sentence.split()
for word in words:

If there isn't a space, then "words" will just contain one entry, and the for loop will exit after the first loop. Also

index = lowercase.index(letter)
                if index + shift < 26:
                    index += shift
                    encrypted_letters.append(lowercase[index])
                elif index + shift >= 26:
                    index += shift
                    while index > 25:
                        index -= 26
                    encrypted_letters.append(lowercase[index])
                else:
                    pass
##
##------------- can be replaced with
                index = lowercase.index(letter)
                index += shift
                while index > 25:
                    index -= 26
                encrypted_letters.append(lowercase[index])

as the while loop will never be executed if the index is < 26.

woooee 814 Nearly a Posting Maven

The solutions to all problems are blindingly obvious __after__ you know what it is. Also, you can check the database to make sure that there are pv0 recs with a SELECT * and a fetchall. If the resulting list has a length, then there are records.

woooee 814 Nearly a Posting Maven

See the Read This Before Posting thread, especially the last paragraph. For tutorials, the Python wiki has links http://wiki.python.org/moin/ This link addresses asking for help with your homework (the "books" problem has been posted many times) http://www.daniweb.com/forums/post3625.html#post3625

woooee 814 Nearly a Posting Maven

British beach volleyball stars Shauna Mullin and Zara Dampney will be sporting a teensy weensy high tech bar code on their itsy bitsy bikini bottoms when they compete in a high profile London tournament this week.

The barcode, part of a sponsorship deal with Betfair, will be printed on the back of the bikini bottoms, where advertisers think it will attract the most attention.

When photographed on a smartphone, the QR matrix barcode directs users straight to a specific website, in this case a site owned by online sports betting company Betfair.

woooee 814 Nearly a Posting Maven

Did you commit() afterwards? All of my links are pretty old http://eringary.com/python/pysqlite.html

Gribouillis commented: good point +13
woooee 814 Nearly a Posting Maven

You have 2 ?s and one variable. Also, you should use a dictionary as it is more secure.

#update if meshblock_06=='21'
g.execute('UPDATE meshblock_1107 SET etv_1107==:update_1 WHERE meshblock_06==:select_1', {'update_1':pv[0:2], 'select_1':'21'})
woooee 814 Nearly a Posting Maven

In the first example, both the function and the button object are assigned to the same variable name, so "d1" can refer to either one (you may or may not be calling the function). Second. the function could set a Tkinker StringVar, used as a textvariable of the button, to the value (but there are other ways also). The second button, n1, does not call a function when called. I'm sorry, but your code is not complete enough to fix. I would suggest a Google for "Tkinter button Daniweb".