woooee 814 Nearly a Posting Maven

I've tried a 'for i in range(53):'loop but
that doesn't work for this

Why not? It seems like the proper way to do this. Note that you salt the variables with the first 2 numbers, so the loop would run 2 less than the number of the total sequence.

Also, do not use i, O, l, etc. as variable names as they look like numbers, i.e. k+l, is that k+el or k+one?

a =  23
b = 7
c = 18

print 1, b
print 2, c
for ctr in range(a-2):
    b, c = c, b+c
    print ctr+3, c
woooee 814 Nearly a Posting Maven

Write program to run some test code in parallel and use a while loop to check is_alive() for each process and/or a manager dictionary that is updated when the function/thread finishes.

def process_status(list_of_ids):
    while True:
        done = True
        for pid in list_of_ids:
            if pid.is_alive():
                done = False

        if done:
            return
        time.sleep(0.1)  ## don't hog the processor
woooee 814 Nearly a Posting Maven

You will have to continuously check the status of the processes, or the value of some variable/dictionary/object to know when it changes. You can use is_alive() to check the status of a process in multiprocessing. You could also use a manager.dict() set to True for each processes' key, and have the function set it to False (or return code) when finished.

Also take a look at pool from multiprocessing Click Here as I am not sure if it is what you want or not.

woooee 814 Nearly a Posting Maven
  1. Hypocrisy
    When the Way is forgotten
    Duty and justice appear;
    Then knowledge and wisdom are born
    Along with hypocrisy.

    When harmonious relationships dissolve
    Then respect and devotion arise;
    When a nation falls to chaos
    Then loyalty and patriotism are born.

    TaoDeChing - Lao Tze

woooee 814 Nearly a Posting Maven

The conscious and intelligent manipulation of the organized habits and opinions of the masses is an important element in democratic society.

Edward Bernays

woooee 814 Nearly a Posting Maven
puntaje  = str(int(A + B + C + D + E + F + G + H + I + J + K + L))

If "B", or any variable is less than 3, then the if statement is not satisfied and B (or any variable) is never declared. Some refactored code

puntaje = 0
for var in [a, b, c, d, e, f, g, h, i, j]:
    if var >= 3:
        puntaje + = 3 ^(int(log((var/3), 2)* 3))
print puntaje
woooee 814 Nearly a Posting Maven

Saw this one one the web so I guess it's a quote

A gaggle of geese
A murder of crows
A bribe of politicians

woooee 814 Nearly a Posting Maven

Add

if ser.isOpen():    
    print "open"
    ## read and write code goes here
else:
    print "closed"

to first make sure the port is open.

Are you using Python3 and trying to write bytes instead of strings? Try

output = "1"
print type(output)
ser.write(output)

Also, this

while not connected:
    serin = ser.read()
    connected = True

only happens once so it is the same as just

serin = ser.read()
woooee 814 Nearly a Posting Maven

The docs are always a good place to start Click Here Strftime is part of the datetime.date class, not datetime.datetime.

woooee 814 Nearly a Posting Maven

PySerial finds the port by he offset so the first port would be offset 0, since it is at the beginning. Port #5 would offset the first 4 ports from the beginning so would be

ser = serial.Serial(4, 9600)

Take a look at the intro docs Click Here
and try python -m serial.tools.list_ports

I would also suggest that you sleep for one or two tenths of a second in the while loop so you don't a lot of computer resources unnecessarily.

woooee 814 Nearly a Posting Maven

I don't see anything in your code that is adding an extension.You might want to use the FileDialog module to get the file name. Also note that you have duplicate PhotoImage statements in the program.

woooee 814 Nearly a Posting Maven

For any future searchers, it is the position in the string that is important. Note that the OP is checking "n" for even or odd, not the number itself. But the code can be easily modified to do either one.

woooee 814 Nearly a Posting Maven

If you print "digit" you will see that it goes from right to left so for input that is an even number in length, the code is bass ackwards. Also a=a/10 only executes under the else. Use a for loop instead of a while loop with your logic or something like the following.

orig_number = "234756"

## sum of odd position
total_sum = 0
for ctr in range(0, len(orig_number), 2):
    print orig_number[ctr],
    total_sum += int(orig_number[ctr])
print "\n2+4+6 =", total_sum

## multiply even positions
total_multiply = 1
for ctr in range(1, len(orig_number), 2):
    total_multiply *= int(orig_number[ctr])
print "3*5*7", total_multiply
woooee 814 Nearly a Posting Maven

Unlike people, you can turn the computer off.

woooee 814 Nearly a Posting Maven

The Xerox Palo Alto Research Center, known as Xerox PARC, developed the graphical user interface (GUI), laser printing, WYSIWYG text editors, and Ethernet. And perhaps more importantly developed object oriented programming.

woooee 814 Nearly a Posting Maven

This certainly sounds like homework, i.e. lists must be used. Another way is to sort the list first and then count.

original_list = ["hello", "hi", "hi", "bye", "hi", "bye"]
original_list.sort()
counter_list = []
ctr = 0
previous = original_list[0]
for word in original_list:
    if word != previous:
        counter_list.append([previous, ctr])
        ctr = 0
        previous = word
    ctr += 1

counter_list.append([word, ctr])
print counter_list
woooee 814 Nearly a Posting Maven

Cross posted so may have already been answered. Check first so you don't waste your time.
http://qt-project.org/forums/viewthread/46750
http://bytes.com/topic/python/answers/958375-how-check-signal-emit-finished-python

woooee 814 Nearly a Posting Maven

There are several ways to do this. I prefer a while loop

##  Not divisible by 3
mylist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

newlist = []
sublist=[]
ctr = 0

while ctr < len(mylist):
    sublist.append(mylist[ctr])
    ctr += 1
    if not ctr % 3:
        newlist.append(sublist)
        sublist = []

if len(sublist):
    newlist.append(sublist)

print(newlist)
woooee 814 Nearly a Posting Maven

using a list, return a 'counterlist' containing all the strings in the original list plus the number of times the string appears in the list

You want a list of lists. While the list in your post can work
CounterList = ["hello", 1, "hi", 2]
a list of list is easier to understand. In your list you would have to check the new word against every other element in CounterList (skip the number), which can be done but is more confusing.

def test_for_word(word, counter_list):
    for ctr in range(len(counter_list)):
        sub_list = counter_list[ctr]
        print "     checking sub_list (word, number)", sub_list
        if word == sub_list[0]:
            sub_list[1] += 1
            return counter_list
    counter_list.append([word, 1])
    return counter_list

original_list = ["hello", "hi", "hi"]
counter_list = []
for word_1 in original_list:
    counter_list = test_for_word(word_1, counter_list)
    print word_1, counter_list
woooee 814 Nearly a Posting Maven

You can also use a function to create the widgets and simplify the code. Note that each entry box is appended to the list so clearing them is just partsing the list. You would get() an entry in same way you do now except you would use list_of_entries[2].get() for entry_box3, etc. Finally, you can use grid() only and

## example only - modify and correct to fit
def create_row(frame, lit, row_in, y_in):
    label = ttk.Label(frame, text=lit, foreground='blue',)
    label.grid(row=row_in, column=1,sticky = 'W', padx = 15, pady = 10)
    entry_box= ttk.Entry(frame, width = 35,)
    ##entry_box.place(x= 100, y = y_in)
    entry_box.grid(row=row_in, column=2)

list_of_entries=[]
row = 1
y = 10
for lit in ["Full Name: ", "Course :", "Ref Num :"]:
    entry_box=create_row(frame1, lit, row, y)
    list_of_entries.append(entry_box)
    row += 1
    y += 39

def clear_entry():
    for entry_box in list_of_entries:
        entry_box.delete(0, END)
woooee 814 Nearly a Posting Maven

this is where my problem is,,,i cant use this fuction to read from the text file and display the corresponding results in the text widget

I don't understand what you mean. Insert is the correct way to insert text into a Text widget.

Edit: Ah, you don't call the read() function (bad name as it shadows Python read functions). You have to click a button, or something, after the text is entered, which will execute the read() function Click Here and start at "This example creates an Entry widget, and a Button that prints the current contents:"

woooee 814 Nearly a Posting Maven

What does it do differently than what you expect? A simple example with an explanation of what you want will get faster and better results

Note that encode_files is declared twice and there are indentation errors in the code.

woooee 814 Nearly a Posting Maven

Please post the entire error message as we have no idea where it may be coming from. The call to encode_files, may be the problem but that code is not included so we can't tell..

woooee 814 Nearly a Posting Maven

I would suggest that you first write it out on paper with 2 or 3 actual examples of what you want and then see how the program differs from the actual examples. For example, balance and remaining balance never change, why? How would you keep track of remaining balance when doing it by hand?

woooee 814 Nearly a Posting Maven

It is a good idea to strip() a record first, unless you are really really sure of the format.

Lambda is a bad habit IMHO. Guido wanted to omit lambda (and map, reduce, & filter) from Python3 because list comprehension is faster and the code is easier to understand. So form the habit of using list comprehension, or partial when you want to pass arguments to a function.

woooee 814 Nearly a Posting Maven

This code from Vegaseat tells you which key is pressed. You can use a similar function that tests for cetain keys and responds accordingly. I think the general binding is

widget.bind("<1>", call_back) (for the number 1).

try:
    import Tkinter as tk     ## Python 2.x
except ImportError:
    import tkinter as tk     ## Python 3.x

def key_in(event):
    ##shows key or tk code for the key
    if event.keysym == 'Escape':
        root.quit()
    if event.char == event.keysym:
        # normal number and letter characters
        label_str.set('Normal Key ' + event.char)
    elif len(event.char) == 1:
        # charcters like []/.,><#$ also Return and ctrl/key
        label_str.set('Punctuation Key %r (%r)' % (event.keysym, event.char) )
    else:
        # everything else
        # F1 to F12, shift keys, caps lock, Home, End, Delete, Arrows ...
        label_str.set('Special Key %r' % (event.keysym))

root = tk.Tk()
label_str=tk.StringVar()
label_str.set(" ")
tk.Label(root,textvariable=label_str, fg="blue").grid()
tk.Label(root, text="Press a key (Escape key to exit):" ).grid(row=1)

ent=tk.Entry(root)
##ent.grid(row=0, column=1)   ##Not packed so will take any entry
ent.bind_all('<Key>', key_in)
ent.focus_set()

root.mainloop()
woooee 814 Nearly a Posting Maven
while not (done):

will loop until done==True
To get done==True in the code you posted, you have have to enter "s" on your only input line, i.e.

    choose=input("\nChoose a class please : f=Fighter, m=Magic User ")

You can also use a return statement to exit the funtion containing the while loop

woooee 814 Nearly a Posting Maven

"Aligning" depends also on the font used. If you are displaying the result in the console, then the console must use a fixed witdth font. If you want to experiment, save the result to a file, open the file with any text/word processor and change the font from proportional to fixed width.

Gribouillis commented: very good! +14
woooee 814 Nearly a Posting Maven

This example from the pyplot examples page, plots two scales, and there are probably more.

woooee 814 Nearly a Posting Maven

That tells you nothing. You have to print it on the line before the error message on every pass through the for loop so you know where and what the error is.

woooee 814 Nearly a Posting Maven

If channelList has less than seven entries then you will get an error on channelList[index]. You will have to print channelList and/or len(channelList) to see where the error is.

woooee 814 Nearly a Posting Maven

Sweet. Much nicer than termios solutions.

woooee 814 Nearly a Posting Maven

We don't know which one of at least 3 or 4 possible statements is causing the error because you did not include the error message. As a shot in the dark I would suggest that you print row or cur or both somewhere around this for() statement

   cur.execute('SELECT channel FROM programs WHERE channel GROUP BY channel')

   for row in cur:

This is a link to an SQLite tutorial but should be OK for whatever SQL engine you are using
http://zetcode.com/db/sqlitepythontutorial/

woooee 814 Nearly a Posting Maven

You have to use the get() method of the StringVar. See the second, or get() example at Click Here i.e convert from a Tkinter variable to a Python variable

woooee 814 Nearly a Posting Maven

builtins.UnicodeDecodeError: 'utf-8'

Don't know much about unicode but it may be that the OS is not set up for utf8, so include this at the top of the file to let the interpreter know to use utf8, or whatever,instead of the encoding set by the OS when you try to print (and I think the line is correct but may only be close)

#/usr/bin/env python3
# -*- coding: utf-8 -*-
woooee 814 Nearly a Posting Maven

as well as the annoying ads that are continuously popping up from the bottom of the screen.

Recently I was flipping through the channels. One show had a popup on the bottom that said "You are watching...". How stupid does someone have to be to not know which show you are watching? Apparently this channel caters to those people. Couldn't help but laugh. The popups are now more entertaining than the shows.

woooee 814 Nearly a Posting Maven

And problem solving skills only work when the problem is defined. A well defined problem is 50% solved or more IMHO.

woooee 814 Nearly a Posting Maven

You would use partial. I don't have Qt installed so can't test, but this should work. Note that if it is self.thrown error, you don't have to pass it to the function as "self" variables can be accessed anywhere within the class.

from PyQt4.QtCore import pyqtSignal, pyqtSlot
from PyQt4.QtGui import QWidget, QApplication
from PyQt4 import QtCore
import sys
from functools import partial

_qObject = QtCore.QObject()

has_error = pyqtSignal(Exception)

class SomeOtherClass(QWidget):

    # this is my UI class

    def __init__(self, parent=None):
        super(SomeOtherClass, self).__init__(parent)

        # Initialise the Class and connect signal to slot
        QtCore.QObject.connect(_qObject, partial(has_error, self.thrown_error))


    @pyqtSlot(Exception)
    def thrown_error(self, my_err):
        #Do Stuff with the Exception
        print(type(my_err), my_err)
        self.close()


def makeError():
    try:
        print 1/0
    except ZeroDivisionError, ze:
        has_error.emit(ze)

makeError()

app = QApplication(sys.argv)
SomeOtherClass()
woooee 814 Nearly a Posting Maven

I only know multiprocessing. The example below starts an infinite loop in a process and uses the terminate method to end the thread, which could also be tied to the backspace key, so perhaps you can adapt the program. You should consider experimenting with a simple example to get the terminate kinks worked out and then move on to the full program

import time
from multiprocessing import Process

class TestClass():
   def __init__(self):
      self.ctr = 0

   def test_f(self, name):
      while True:
         self.ctr += 1
         print "test_f", self.ctr
         time.sleep(0.5)

if __name__ == '__main__':
   CT=TestClass()
   p = Process(target=CT.test_f, args=('P',))
   p.start()

   ## sleep for 5 seconds and terminate
   time.sleep(5.0)
   p.terminate()

Also, note how the function in the class is called in the code above.

def onAction(self, action):

is not part of the class in the code you posted so calling
self.allchannels_timer will not work.

self.thread = threading.Thread(target=self.allchannels_timer)
woooee 814 Nearly a Posting Maven

It is possible that the GUI or whatever that setLabel uses, does not update the screen until the for loop finishes. We don't have enough info to help much further than that as the code is incomplete. Also, please post what you have done to debug this code. If you have added a print statement to show that setLabel is indeed called then the problem is possibly as stated above. If however setLabel is not even being called, then the problem is with one of the for loops.

woooee 814 Nearly a Posting Maven

Tony's question was probably referring to

if len(grades) == 1:
    print ('%s'*len(grades)) % tuple(grades)

I would suggest that you test this further, i.e. if len(grades) == 1 then why multiply the output by len(grades) which is just one.

woooee 814 Nearly a Posting Maven

You will use something similar to the following (but this code is not complete), tutorial for for loop at Click Here explaination of list append and extend at Click Here

grades = ['7.0', '7.5', '6.8', '6.9']
for ctr in range(0, len(grades), 2):
    print grades[ctr], grades[ctr+1]
woooee 814 Nearly a Posting Maven

Print seek_position and see if it is greater than 10. If it is, what happens? Also write a test program using a known string and try different combinations of

test_string[start:end]
woooee 814 Nearly a Posting Maven

You find the location in the line and then seek in the file using the location found in some unknown line. Choose either the line or the file, for example:

## the following "while" line will exit when artist_string is found
## and so the rest of the code (seek_position, etc.)
## will never be executed
##while artist_string not in line:
##    line = f.readline()

for line in f:
    if artist_string in line:
        seek_position = line.find(artist_string)
        print line[seek_position:]
        break
woooee 814 Nearly a Posting Maven

There is no problem with the entry boxes as the code below will show, i.e. name and password are printed correctly. The problem is verifying the input and "passwords" is not defined anywhere in the code you posted so we have no way to know what you are using to check the input against.

from tkinter import *

# Create the window
root = Tk()
root.title("NEOSA Corp Interface")

# Background
##p = PhotoImage(file="CIA.gif")  ## we don't have this image
l = Label(root)

# Password for main screen

e = Entry(l, show="*", width=30)
e.pack(side=TOP, anchor=W, padx=450, pady=300)
e.focus()

######################################################

# Fail entery

def make_entry(parent, caption, width=None, **options):
    Label(parent, text=caption).pack(side=TOP)
    entry = Entry(parent, **options)
    if width:
        entry.config(width=width)
    entry.pack(side=TOP, padx=10, fill=BOTH)
    return entry

def enter(event):
    check_password()

def check_password(failures=[]):
    """ Collect 1's for every failure and quit program in case of failure_max failures """
    print(user.get(), password.get())
    """
    *****  commented because we don't have "passwords"
    if (user.get(), password.get()) in passwords:
        root.destroy()
        print('Logged in')
        return
    failures.append(1)
    if sum(failures) >= failure_max:
        root.destroy()
        raise SystemExit('Unauthorized login attempt')
    else:
        root.title('Try again. Attempt %i/%i' % (sum(failures)+1, failure_max))
    """


#frame for window margin
parent = Frame(root, padx=10, pady=10)
parent.pack(fill=BOTH, expand=True)
#entrys with not shown text
user = make_entry(parent, "User name:", 16, show='')
password = make_entry(parent, "Password:", 16, show="*")
#button to attempt to login
b = Button(parent, borderwidth=4, text="Login", width=10,
           pady=8, command=check_password)
b.pack(side=BOTTOM)
password.bind('<Return>', enter)

user.focus_set()
###########################################################################

# Main Screen Shut Down

b = Button(l, command=quit, text="Shut Down")
b.pack(side=BOTTOM, expand=Y, anchor=S)


l.pack_propagate(0)
l.pack()


root.mainloop()

root = Tk()

# Modify root window …
woooee 814 Nearly a Posting Maven

There is no way to help someone who doesn't have a clue short of a Vulcan mind meld. But

e.focus()

there is no widget method "focus" [Click Here](http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm

and

if (user.get(), password.get()) in passwords:

we have no idea what is in "passwords" but if it is not a list or set of tuples, then it will not be found. I would suggest testing by printing passwords and then looking for user in all of the passwords[0] and password in all of the passwords[1] and print what is and is not found.

Finally, note that "failures" is set to an empty list every time the function is called so max_failures will never be reached

def check_password(failures=[]):

lists are mutable so you can define it outside of the function, and append to it in the function, unlike strings.

def check_password():
    failures.append(1)

failures=[]
for ctr in range(5):
    check_password()
    print failures
print sum(failures)
woooee 814 Nearly a Posting Maven

it runs into an infinite while loop and i am unable to debug it.

Add print statements so you know where it is and what the variables contain.

Instead of testing for i-1!= -1 (which is the first pass of the for loop) and i/j+1 != 8 (which happen on the final loop pass) just set the for loop to range(1, 7) for "i", "j" or both.

         for i in range(8):
              for j in range(8):
                  #valid_moves-valid_move for player 1
                  if depth%2==1:
                     if board[i][j]==2:
                        if i-1!=-1 and j-1!=-1:
                           if i+1!=8 and j+1!=8:

Also, what happens when i-1 is -1 and j is not

if board[i-1][j]==1 and board[i+1][j]==0:

you access the [-1][j] element which may or may not be allowed depending on how the -1 is used, but is probably not what you want. Start with a simplier program and test it as you go along.

woooee 814 Nearly a Posting Maven

I don't understand the game or what it is supposed to do, but you call clearbotones from c (button press). Shouldn't the color be set in c instead of creating new buttons each time? Hint, you use boton[] list. Add a print statement to clearbotones to print each time the new buttons are created and the bg color of the button, so you can see what is happening. Also you can create the buttons in a loop

       for j in range(abs(posH), abs(posH)+7):
            texto = str(matriz[i][j])

            btn = tk.Button(mainFrame,text="",bg="white",width=10,
                                height=5,fg="black",relief=tk.GROOVE,.
                                command=lambda:[c(abs(posH)+num)])

an example using a 3X3 grid which just changes the background color of the clicked button. This employs a dictionary, but you could use a list just as easily. And a class avoids all of the messy globals

from Tkinter import *
from functools import partial

class ButtonTest:
   def __init__(self):
      self.top = Tk()
      self.top.geometry("150x145+10+10")
      self.button_dic = {}     ## pointer to buttons and StringVar()
      self.top.title('Buttons TicTacToe Test')
      self.top_frame = Frame(self.top, width =500, height=500)
      self.buttons()

      self.top_frame.grid(row=0, column=1, sticky="WE")
      for ctr in range(0, 3):   ## configure all columns to the same size
         self.top_frame.grid_columnconfigure(ctr, minsize=50)
         self.top_frame.grid_rowconfigure(ctr, minsize=37)

      exit = Button(self.top_frame, text='Exit', \
             command=self.top.quit).grid(row=10,column=0, columnspan=5)

      self.top.mainloop()

   ##-------------------------------------------------------.
   def buttons(self):
      """ create 9 buttons, a 3x3 grid
      """
      for j in range(1, 10):
         sv=StringVar()
         sv.set(j)
         b_row, b_col = divmod(j-1, 3)
         b = Button(self.top_frame, textvariable=sv, \
                    command=partial(self.cb_handler, j), bg='white')
         b.grid(row=b_row, column=b_col, sticky="WENS")
         self.button_dic[j]=b ## button number-->Tkinter ID

   ##----------------------------------------------------------------
   def cb_handler(self, square_number):
       print square_number, "pressed"
       self.button_dic[square_number].config(bg="red")


##===================================================================
BT=ButtonTest()
woooee 814 Nearly a Posting Maven

The smallest time displayed is seconds. The function is called every 2/10 of a second, so the clock is not updated if the time to the second has not changed.

woooee 814 Nearly a Posting Maven

Post a simple example of what you want to do. 276 lines of code is too much as we are trying to guess from your code what you are trying to do. Note that no sorting is done in the code below and in fact the functions are not necessary as they just return an existing variable.

    def GetListCtrl(self):
        return self.list_ctrl2 

    def GetListCtrl(self):
        return self.list_ctrl