woooee 814 Nearly a Posting Maven

You are printing separate variables. MemberCounter.members is different from m1.members="Two". Print the id() of each, which will show that they all occupy different memory locations. You might also want to study up on the difference between class objects/attributes and instance objects/attributes Click Here Sometimes you are printing an instance object and sometimes you are printing a class object, which are different variables even though they have the same name. m2 does not have an instance object named "members" so it prints the class object. If you created one
m2.members="Three"
it would print that instead, and
MemberCounter.members will always print the class object.

woooee 814 Nearly a Posting Maven

You also have to have TCL and Tk installed. I don't know if it comes with MS Windows or not but this link has a section for installing
Click Here ofClick Here For further help we will have to see more than
"module not found" of the error message as it may be some other module completly.

woooee 814 Nearly a Posting Maven

module' object has no attribute 'geteuid' windows

There is no "geteuid" in the code you posted. You will have to post the entire error message so we can tell which line it is coming from.

woooee 814 Nearly a Posting Maven

And is input from the command line, or are you using a GUI toolkit to get input and show the dice.

woooee 814 Nearly a Posting Maven

This homework question comes up every year so there are other posts that you can look at. We do not do your homework for you however. Also, posting on multiple forums reduces your chances for an answer because no one wants to waste time on a question that has possibly already been answered on another forum.

ganapathy24 commented: Its not a homework u sherlock... I jus forgot my rar password, but i know the words used in it, in order to generate all the possible combination i raised it.... +0
woooee 814 Nearly a Posting Maven

That's his story and he's sticking to it. Hope he has a note from his doctor.

woooee 814 Nearly a Posting Maven

A pair of doctors in Texas discovered a 61-year-old man who appeared to be constantly drunk for five years had a rare condition that caused his stomach to turn food into alcohol.

Dr. Barbara Cordell, the dean of nursing at Panola College in Carthage, Texas, and Dr. Justin McCarthy, a Lubbock gastroenterologist, said the man's blood alcohol content was consistently high for five years because the yeast in his stomach was turning carbohydrates into ethanol.

The man was treated with anti-fungal medication to bring about a sober state and what was likely the hangover of a lifetime.

woooee 814 Nearly a Posting Maven

I am not sure what you want to do, print names not found or print the food associated with the name. This prints the names not found.

##------------------------------------------------------------------
## names_file = open("file_name", "r").readlines()
names_file = """John
Alice
Mary""".split("\n")

## strip white space and capitalize
names_list = []
for name in names_file:
    add_name = name.strip().upper()
    names_list.append(add_name)
print "names_list", names_list, "\n"

##------------------------------------------------------------------
## data_file = open("this_file_name", "r").readlines()
data_file = """JOHN
EGGS,24,BEEF,36,BACON,56,HAM,66
ALICE
TOMATOES,16,HAM,35,BEANS,35
PAT
APPLES,20,ORANGES,30,LETTUCE,50
Mary
Yogurt,21,Milk,31,Cream,41
George
Beans,22,Peas,23,Onions,33""".split("\n")
for ctr in range(0, len(data_file), 2):
    this_record = data_file[ctr]
    if this_record.strip().upper() not in names_list:
        print this_record, "***NOT Found***", data_file[ctr+1]
woooee 814 Nearly a Posting Maven

You can use and else. What is wrong with the code I posted earlier?

        if j +"\n" == line and num %2 == 1: 
               response= linecache.getline ("SearchText.txt", num +1)
               wordList = re.sub("[^\w]", " ",  response).split()
               searchWord = wordList [z] + " "
               Firstload.write(searchWord)
               # PROBLEM HERE
        else:
               DumpText.write(j + " ")
woooee 814 Nearly a Posting Maven

I don't understand what "stuck in a loop" means. The only loop(s) are the two for() loops and they exit when the data is exhausted.

## with open("SearchText.txt").readlines() as test_records:
test_records =["JOHN",
               "EGGS,24,BEEF,36,BACON,56,HAM,66",
               "ALICE",
               "TOMATOES,16,HAM,35,BEANS,35",
               "PAT",
               "APPLES,20,ORANGES,30,LETTUCE,50"]

response = 2
## response item location 1-->0, 2-->2, 3-->4 == response *2 -2
item_location = response*2-2
for ctr in range(0, len(test_records), 2):
    name = test_records[ctr]
    items = test_records[ctr+1].split(',')
    print items[item_location],
print 
woooee 814 Nearly a Posting Maven

Try using readlines instead, and check that searchWord actually contains something otherwise you can write blanks to the file.

 with open("SearchText.txt").readlines() as records:
     for num, line in enumerate(records):
 ......
         ## the following line will yield an error on the
         ## last record because there is no num+1
         response=records[num +1]
woooee 814 Nearly a Posting Maven

Do you mean you want to limit the amout of time the user has to answer the question or something else? A while loop or a 'return' from a function will work to limit the time

from datetime import datetime, timedelta
import time

current = datetime.now()
stop = current + timedelta(minutes=1)
ctr = 0
while current < stop:
    current = datetime.now()
    print current, "-->", stop
    time.sleep(2)        ## avoid too much printing
woooee 814 Nearly a Posting Maven

Traceback (most recent call last):
File "C:UserslinuxDesktopscreenshot1.py", line 11, in <module>
img.save(SAVE_PATH)

Print SAVE_PATH to see what name the program is trying to use (not the one you think it is). Also you can use
from os import environ
My computer likes environ['HOME'] instead of 'HOMEPATH' but it may be different on different OS's.

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

Using partial is easier and makes more sense IMHO Partial examples

from functools import partial

...

## to send "on" and "host" to callback_power_on function
b = Button(master,
           text="Power On",
           command=partial(callback_power_on, on, host))  

##---------- or if you prefer  ----------------------------
b = Button(master,
           text="Power On",
           command=partial(callback_power_on, data=on, host=host))  
woooee 814 Nearly a Posting Maven

What is "patrons"? It looks like a list of Patron class instances. If so, please include the Patron class code also. In loan_book() you only check the book_id if the patron is not found. If the patron is found you return before the book lookup.

woooee 814 Nearly a Posting Maven

You copied two separate answers to your thread from StackOverflowand combined them which yields the indentation mistakes and the orphaned else statement.

woooee 814 Nearly a Posting Maven

There is no reason to reinvent the wheel. You can use the identify program from ImageMagick to do that for you.

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

You can bind the <BackSpace> key to a function just like any other key. If you want to erase the last character in and entry widget for example, then get the value and set it as value[:-1] For button examples, like a quit button see a tutorial like this one

woooee 814 Nearly a Posting Maven

@woooee Your program is working but it's giving me really messy output, it's all on one line an run togather. I tried pring '\n' right after the print statement but that doesn't seem to be getting the job done. Any ideas?

split it on the newline, "\n", to get a list of individual lines.

woooee 814 Nearly a Posting Maven

Running this stripped down version works on my machine

from tkinter import *
root = Tk()
calc = Frame(root)
calc.grid()

root.title("Calculator")
text_box = Entry(calc, justify=RIGHT)
text_box.grid(row = 0, column = 0, columnspan = 3, pady = 5)
text_box.insert(0, "0") 

root.mainloop()
woooee 814 Nearly a Posting Maven

I would suggest a few print statements to see what the program is doing. Other than that, you did not say what you wanted the program to do and what the problem is (and I have learned that you are always wrong if you try to guess). Also, are you allowed to use append (to the list directly) instead of using "new-string" and what happens if "text_input" contains two words that are the same i.e. the word will be added twice.

## add/uncomment the commented print statements once you
## have fixed the first part of the program
##
def removeStopWords(text_input):
    line_stop_words = []
    stop_words = "a","It","i","it","am","at","on","in","of","to","is","so","too","my","The","the","and","but","are","very","here","even","from","them","then","than","this","that","though"
    print stop_words

    word = "" 
    for word in text_input:
        print "Word in text_input", word
        word_list = string.split(text_input)
        new_string = ""
        for word in word_list:
##            print "word in word_list", word  ## not the same "Word" as the above
            if word not in stop_words:
                new_string = new_string + word + " "
##                print "new string is now", new_string  
        new_string = string.split(new_string)
##        print "new_string after split", new_string
        line_stop_words = line_stop_words + [new_string]
##        print "line stop words is now", line_stop_words
    return(line_stop_words)
woooee 814 Nearly a Posting Maven

You have to pass the list to the function using it i.e.

numbers = get_values()
do_analysis(numbers)
woooee 814 Nearly a Posting Maven

You can also use subprocess to get the results of ls -l. Note the r(epr)

import subprocess
output = subprocess.check_output([r'ls', '-l'])
print output
woooee 814 Nearly a Posting Maven

Geometry managers, pack, grid, and place return None

canvas = Canvas(mainGUI, width=c_width, height=c_height, bg= 'white').place(x=(4.5*(widthOfScreen/12)),y= (2*(heightOfScreen/5)))
print canvas

Take a look at Vegas's code again and I'm sure you will find that the geometry manager is on a separate line.

canvas = Canvas(mainGUI, width=c_width, height=c_height, bg= 'white')
print canvas
print canvas.place(x=(4.5*(widthOfScreen/12)),y= (2*(heightOfScreen/5)))
CodingCabbage commented: Thankyou, very helpful +0
woooee 814 Nearly a Posting Maven

Take a look at the docs for os.stat()

def file_permissions( fname ) :
    st = os.stat(fname)
    ##--- st = tuple, in format
    ##      0    1   2    3    4   5    6    7     8     9
    ##    (mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)
    mode = st[0]

    if mode :
        print "st_mode = ", mode
    if mode & stat.S_ISLNK(st[stat.ST_MODE]) :
        print "is link"
    else :
        print "is NOT link"     
    if mode & stat.S_IREAD :
        print "readable"
    if mode & stat.S_IWRITE :
        print "writable"
    if mode & stat.S_IEXEC:
        print "executable"
woooee 814 Nearly a Posting Maven

Generally you add each "button_name" instance to a list that remains after the loop exits. Note that you also want to increment/change the values for the place manager.

woooee 814 Nearly a Posting Maven

You have to pass the "numbers" list to do_analysis. Now it is using the "numbers" from the import numbers statement. This is not a complete solution but should get you started: passing parameters to a function

def main ():
    # create empty list
    intro()
    numbers = get_values()
    ## get_values()         Huh!!
    do_analysis(numbers)
    input("press enter to continue.") # required
woooee 814 Nearly a Posting Maven

Is this question solved or was clicking the solved button a mistake?

woooee 814 Nearly a Posting Maven

Note that you don't use the "j" variable. It is not necessary. Just iterate through the the list up to the next to last element. You do this over and over until there are no more swaps. In your code you loop enough times to do all of the swaps but this is not an efficient way to do it. Also using letters like i, l, and O is not a good idea as they look too much like numbers.

import random

test_list = [random.randint(1, 10) for ctr in range(20)]
print "original", test_list
found = True
swaps_ctr = 0
while found:
    swaps_ctr += 1
    found = False       ## initial state
    for ctr in range(0, len(test_list)-1):
        if test_list[ctr] > test_list[ctr+1]:
            test_list[ctr+1], test_list[ctr] = test_list[ctr], test_list[ctr+1]
            found = True     ## loop again

print swaps_ ctr, "swaps"
print test_list
for num in set(test_list): ## reduce to one entry per number
    print num, test_list.count(num)

## another way
print "-" * 20
previous_num = -1
for num in test_list: 
    if num != previous_num:
        print num, test_list.count(num)
        previous_num = num
woooee 814 Nearly a Posting Maven

You want to increment count after every input. You do not increment it after the first input statement. Also the final else is not necessary.

import random

count = 0
secret = random.randint (1, 100)

print ("Guessing game - Guess my secret number - number between 1-100")
guess = int(input("Your Guess? "))
count +=1     ## <----------------- or count=1
while (guess != secret):
    count += 1

    if (guess > secret):
        print ("Your guess is higher")
        guess = int(input("Guess again:"))

    elif (guess < secret):
        print ("Your guess is lower")
        guess = int(input("Guess again:"))

print ("You Guessed it!It took you", count, "tries.")
woooee 814 Nearly a Posting Maven

That is the same as

or create the 'insert into' as a string containing the field names themselves.

SQL_lit  = 'insert into sactuelpm (model,date,heure,%s) values (%%s,%%s,%%s,%%s;)' % (e0)
print SQL_lit
cur.execute(SQL_lit, (fields))

which is perfectly legal. It does not matter if you create the execute string in the cur.execute statement or somewhere else, a string is a string.

woooee 814 Nearly a Posting Maven

modelsa,date,heure,%s

You can't have a named field as "%s" It has to be the field name so you will have to use if statements or create the 'insert into' as a string containing the field names themselves.

if e0 = =1:
    cur.execute('insert into suiviactuelms (modelsa,date,heure,field1) values (%s,%s,%s,%s);',(modelidvar, cur_date, t, quantitevar))

elif e0 == 2:
    etc.
woooee 814 Nearly a Posting Maven

You may also have problems with capitalized vs all lower case words. Since I have no idea what "nltk.pos_tag(token_text)" is and don't have the time to search for it, the following code will count the number of words but will have a problem with punctuation you want to keep, like "don't", so this is not a complete solution but is the general idea.

from collections import defaultdict

dict_words = defaultdict(int)
text = "This ball is blue, this small and extraordinary. Like don't other ball."
this_word=[]
for word in text.split():
    for chr in word:
        if ("a" <= chr.lower() <= "z") or (chr in ["'", "`"]):
            this_word.append(chr.lower())
    if len(this_word):
        dict_words["".join(this_word)] += 1
        this_word = []
print dict_words
woooee 814 Nearly a Posting Maven

You have not done anything to find out what is going on so that is why you don't know. Two added print statements will show what pyTony said, i.e. you don't accumulate the count but just return each individual count from each recursion.

def lengthR(mystring):
    '''
    recursive function to count char in mystring
    excluding spaces
    '''
    count=0
    if mystring == '':
        return count

    mystring = mystring[0:-1]
    count += 1
    if mystring.endswith(' '):
        count -= 1
    print "testing", mystring, count
    x = lengthR(mystring)
    print " x =", x
    return x

mystring = "Hello Earth"
print(lengthR(mystring))
woooee 814 Nearly a Posting Maven

Use "if len(a_list)". Also this is what sets are for
if set(a_list).issubset(set(a_string)) ## if all list is in string

woooee 814 Nearly a Posting Maven

I am trying to write a program which, overall takes the names of the files that haven't completed, works out the names of those that haven't run and writes all of these into a batch file.

I would agree. You are perhaps making it too complicated. Write/store the file name when it's processing has finished. If a file in a directory is not in the finished list then process it.

When c does not equal 1.00, extend the list GULP to include gulp < ' + AaBbCc.dat + ' > ' + AaBbCc.out. This must always happen, except when a == 0.3 and b == 0.2 and when a == 0.8 and c == 0.6.

You can extend the list by all names in a directory "except when a == 0.3 and b == 0.2 and when a == 0.8 and c == 0.6" and not have to worry about which ones have run. If the program exits before all files have run then the program name is not in the stored list and will run next time this program is run.

If I understand what you want to do, you will use something like the subprocess modules to run the "bash" commands and when it finishes, and returns to the calling program, write the name of the file to where ever it is being stored.

woooee 814 Nearly a Posting Maven

but it returns : _iNone

The "None" is returned by the function so apparently you are calling it with "print function_name()" instead of "function_name". If that does not help then post the entire code including how you call it.

woooee 814 Nearly a Posting Maven

Your code is a good example of why we use the Python Style Guide You use an upper and lower case "L" for the same field name so the code you posted does not run. The style guide says to use lower_case_with_underscores so to avoid that problem and make your code more readable by others. Try the following code and see if it does the random part. It does not matter if you have the keys in 2 lists or use [0][1] and [2][3] so it is up to you if you want to divide it into two lists or use as is. Note on the first print that the keys are in "dictionary order" not the order they were added.

import random
test_dict = {'One': 3, 'Two': 5, 'Three': 1, 'Four': 4, 'Five':7 }
dict_keys = test_dict.keys()
print dict_keys
random.shuffle(dict_keys)
print dict_keys
TrustyTony commented: clear thinking +12
woooee 814 Nearly a Posting Maven

Google is the best way to find an answer as without code there is no way to tell what "GUI" you wish to use. One example from this forum Click Here

woooee 814 Nearly a Posting Maven

There is a logic error in the code, if someone answers "no" as q_two they still get the q_three = raw_input("Do you pick the revolver up?") statement. Also, you want to limit the input to specific answers.

q_two = ""
while q_two.lower() not in ("no", "yes"):
    q_two = raw_input("Do you investigate ")

As to the Reference Error, you will have to include the complete error message to get any help.

woooee 814 Nearly a Posting Maven

It sounds like we are being given an assignment to "write a program" etc. for someone else. Not a good way to get assistance.

woooee 814 Nearly a Posting Maven

Convert to a list of lists with highest score first, then time, then name. Or take a look at "Complex Sorts" in the Howto Sorting

woooee 814 Nearly a Posting Maven

Now that you have posted the complete error message we know which line is causing it.

level=PhotoImage(file='images\0.gif')

does not look like a valid file name. It is perhaps "/images/0.gif". But that probably is not enough either as you have to provide the complete file name "/path/to/file/images/0.gif". You also must keep a reference to the image object in your Python program, either by storing it in a global variable, or by attaching it to another object. You might want to use something like this just to be on the safe side

fname="/path/to/file/images/0.gif"
if os.path.isfile(fname):
    level=PhotoImage(file=fname)
else:
    print "File not found", fname

If that still doesn't work, then download a gif image from the web to test with as it may be the image that is causing the problem.

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

An example of placing a gif image on a canvas Click Here Most people who are attempting a hangman game use a canvas and [draw lines, circles] (http://effbot.org/tkinterbook/canvas.htm) etc. to get the hangman, but it is your program. You might also consider a Toplevel i.e. a second window for the hangman image

woooee 814 Nearly a Posting Maven

For the record, the way to achieve the results that I think the OP is looking for is to use

from sys import path

I prefer to import sys and use sys.path because it makes the namespaces obvious.

woooee 814 Nearly a Posting Maven

You first have to be able to access each individual row and know what format the row is in; string, list, etc. We do not know this so any code would be shooting in the dark.

woooee 814 Nearly a Posting Maven

The else statement in the following code executes if the number is equal to or greater than since you don't test for an equal condition and will print "try a lower number" when equal. You should test for greater than only as the while loop catches the equal condition. Your Tryz variable is off by one (try the program with 2 attempts). Consider using a function that returns True or False and the number of tries. Also the Python style guide says that lower_case_with_underscores are to be used for variable names and Upper or CamelCase is for class names.

    if Guess < Number:
        Guess = int(raw_input("Try a higher number: "))
    else:
        Guess = int(raw_input("Try a lower number: "))
woooee 814 Nearly a Posting Maven

64 bit, Python 2.7 is predictably twice the memory, except for the string???

"""
Size of empty tuple = 56
Size of empty list = 72
Size of empty dictionary = 280
Size of empty string = 37
"""
woooee 814 Nearly a Posting Maven

There is a little hiccup for stars with 3 and 4 sides. You can divide 360 by the number of sides for stars with 5 sides and up, but for 3 or 4 sides this gives an angle greater than or equal to 90 which will not work. I will leave this conundrum up to the OP to solve for now. Both star_angle and left_angle have to be calculated differently for angles >= 90. Draw it out on a piece of paper and measure the angles and you should be fine.

def draw_star(number_of_sides):
    star_angle=360.0/number_of_sides  ## float for Python 2.X
    left_angle = star_angle*2
    print number_of_sides, star_angle
    turtle.penup()
    turtle.goto(-150, -100)
    turtle.pendown()
    for _ in range(number_of_sides):
        turtle.forward(100)
        turtle.right(star_angle)
        turtle.forward(100)
        turtle.left(left_angle)

    raw_input("Press a key")
    turtle.clear()

for num_sides in range(3, 8):
    draw_star(num_sides)
woooee 814 Nearly a Posting Maven

10 to the 5=100,000 and you only have to test up to the square root and every other number, i.e. not even, which is slightly more than 150 numbers if my arithmetic is correct. So it has to be some other problem. Check any while() loops and that you are not sending the same number(s) through the test over and over.