1,075,627 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Posts by woooee which have been Voted Up

You write one ('HBHB', 0xcafe, *ssd) and multiple ('HH', chunk) and then read one ('HBHB', 0xcafe, *ssd) and only one ('HH', chunk), then one ('HBHB', 0xcafe, *ssd) and one ('HH', chunk), etc. In addition to ('HBHB', 0xcafe, *ssd) write the number of items (length) written so you know how many to read.

woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

You have not declared log_size or log1_size anywhere and it appears the indentation is off under the while True, which is an infinite loop since you don't ever exit it. There is no reason from the code you posted to append to "packed" and then write each value from packed instead of just writing to the file directly. Other than that the error message is self explanatory and we of course don't know what the values of the variables are so there is no further way to help.

woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

Tkinter does not have a Circle class; you use create_oval with circle dimensions. Note that you call the function once and have it call itself recursively for as many times as you want.

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

class TestAfter():
    def __init__(self):
        self.root=tk.Tk()
        self.ctr = 3
        self.canvas = tk.Canvas(self.root, width=500, height=500)
        self.canvas.grid()
        self.root.after(750, self.update)

        self.root.mainloop()

    def update(self):
        colors = ["black", "red", "green", "blue"]

        if self.ctr > 0:
            start = 50*self.ctr  ## use same values for x & y
            end = start+50
            self.canvas.create_oval(start, start, end, end,
                               fill=colors[self.ctr], width=2)
            self.ctr -= 1
            self.root.after(750, self.update)

TA=TestAfter()
woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

GUI's have their own "sleep" type methods that should be used. However each GUI uses a different function name so it depends on the GUI toolkit you are using.

woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

I agree that you are doing it the hard way. Note that dollars is multiplied by two after the print and the addition to total

#get the ending limit
days = int(raw_input('How manys days were worked? '))
total = 0
dollars = 0.02
#print table headings
print('\nDays\tDollars')
print('------------------------------')


#print the days and the amount of money that was earned that day
for today in range(days):
    total += dollars  ## 0.02 on first pass
    print(today+1, '\t', '$',format(dollars,',.2f'))
    dollars *=  2  ## set for next pass
print('the total amount of money you earned is: $',format(total,',.2f'))
woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

Does the file have more than one taxon? In the example you posted there is only one so all of the solutions are for one only. Try this as a hint, although there are other ways to do it.

handle = open(fname, "r")
all_data = handle.read()
print all_data.split("taxon")
woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

Once you get the value it is a normal variable and you can do anything with it that you can do to a normal variable. I would suggest that you consider putting everything under one class instead of here's a function, there's a class, here's another function, etc.

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

def another_function(input_var):
    print "another function", input_var

class TestClass():
    def __init__(self):
        root1 = tk.Tk()
        root1.title("Vreme")
        naziv = "Vreme"
        L1 = tk.Label(root1, text="Zadržavanje: ")
        L1.place(x=10, y=30)
        self.E1 = tk.Entry(root1, bd = 2)
        self.E1.insert(0, "Test string")
        self.E1.place(x=100, y=30)
        root1.geometry("300x100+300+200")
##    tk.Button(root1, text="OK", command = lambda: izmeni(E1.get(),root1,vreme1,naziv), width=10).place(x=130, y=65)
        tk.Button(root1, text="OK", command = self.izmeni, width=10).place(x=130, y=65)
        root1.mainloop()

    def izmeni(self):
        value = self.E1.get()
        print "izmeni -->", value
        another_function(value)
        self.function_in_class(value)

    def function_in_class(self, input_var):
        print "functionin_class -->", input_var

TC=TestClass()
woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

I would suggest that you use a button instead of a label, which can execute a funtion when it is clicked. Also, the name "list" is already used by Python so you should not override it, although you never use the variable "list" in the code posted so the "list" code can just be deleted.

woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

There is a typo in get_average that you should be able to run down from the error messages, or at least begin to learn how. Using descriptive variable names would help you with this, as well as help us understand the program. Print the return from get_average and see if it can be summed. Note that get_average returns a kind of sum of averages, not the average. Also, you should loop through containers like a dictionary so your funtion can handle containers that have any number of items instead of

return average(p[1]) + average(p[2]) + average(p[3])

Usually we test programs with known values that should produce known results to tell if the program is calculating correctly or not, so what are the results supposed to be?.

woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

First, remove punctuation (? , . etc). Next all words should be lower() case as an upper case word is different to the computer than a lower case word. To print use the dictionary's key as below, although this code does not do any of the other above suggestions

data="""I love the python programming
 How love the python programming?
 We love the python programming
 Do you like python for kids?
 I like Hello World Computer Programming for Kids and Other Beginners."""

count = {}
for word in data.split():
    if word not in count:
        count[word] = 0
    count[word] += 1

## access the dictionary by key
for word in count:
    print "The word", word, "was found", count[word], "times"

print "\nThere are %d unique words (if Upper and lower case," % (len(count))
print "and words with punctuation, are different words)"
woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

You do not test for the password for the user so if any user's password is found it will return True. This works for me but again will accept any user's password (and note the added print statements to see what is happening).

import crypt

line="victim: HX9LLTdc/jiDE: 503:100:Iama Victim:/home/victim:/bin/sh"
cryptPass = line.split(':')[1].strip(' ')
salt = cryptPass[0:2]
print "cryptPass",  cryptPass, salt

test_file="""apple
orange
egg
lemon
grapes
secret
strawberry
password"""

dictFile = test_file.split("\n")  
for word in dictFile:
    cryptWord = crypt.crypt(word, salt)
    print "     ", cryptWord, cryptPass,
    if cryptWord == cryptPass:
        print "FOUND",
    print
woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

That is a little complicated because I get an error on the first test lookup at

e = self.shelve[key]

because the keys are not correct. If it works for you then there is possibly a difference because of the Python version being used. If it does not work for you, take another look at Doug Hellmann's page as to how he adds data to a shelve object. Deleting is just del self.shelve[key], but you also have to set writeback=True for the changes to take place in the db. Also, Python is already using "string" and "list" and so using them in your program "redefines" them so you can not convert something to a list for example because "list" no longer points to a function. Finally, "b" will never equal 4 because it is set to one on the previous line

    def phonemenu(b):
        b = 1
        if b != 4:
woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9
woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

The following code does the same lookups using a list and a dictionary. Lists are sequential in memory, meaning that the program has to get the offset for the beginning of the item it wants to use, go to that offset, compare to what it wants to find, and go back and do it all over again for each element in the list. A dictionary uses a hash which creates small groups, for lack of a better term, so there is a relatively small number of lookups. For each tenfold increase in data, the dictionary's time increases by ten times also, but is still pretty fast. The list's lookup time increases by 100+ times for the same increase. One would expect the same increases for a tenfold increase in the size of each individual item being stored as that would also increase the anount of memory that has to be traversed. So it appears that you can't really decide on using a list vs. dictionary based on the number of items but have to consider the total amount of memory to be consumed.

import datetime

def add_to_list(num):
    a_list=[]
    start_time=datetime.datetime.now()
    for ctr in xrange(num):
        ##  lookup up each time to show the "cost" of lookups
        if ctr not in a_list:
            a_list.append(ctr)

    print "elapsed time:", datetime.datetime.now()-start_time


def add_to_dict(num):
    a_dict={}
    start_time=datetime.datetime.now()
    for ctr in xrange(num):
        ##  lookup up each time to show the "cost" of lookups
        if ctr not in a_dict:
            a_dict[ctr]=ctr

    print "elapsed time:", datetime.datetime.now()-start_time


for num in [1000, 10000, 100000]:
    print "list of %6d" % (num), 
    add_to_list(num)
    print "dict of %6d" % (num), 
    add_to_dict(num)
    print

""" compare execute times for list vs. dictionary for different
    lengths of input data

list of   1000 elapsed time: 0:00:00.012220
dict of   1000 elapsed time: 0:00:00.000264  Approx 61 times faster

list of  10000 elapsed time: 0:00:01.210761
dict of  10000 elapsed time: 0:00:00.003146  Approx 390 times

list of 100000 elapsed time: 0:02:30.698131
dict of 100000 elapsed time: 0:00:00.03296   Approx 4566.7 times
"""
woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

For future reference, the error was eliminated because you added the plus signs. Also, include the entire error message in the future.

print('Ok,'chara,
print('Ok, '+ chara +
woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9
woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

A hint

from string import ascii_lowercase as letters
print letters[-1:]
print letters[-2:]

print
location=25
print letters[location:]
location -= 1
print letters[location:]
woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

Two from Einstein

“Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.”

“If a cluttered desk is a sign of a cluttered mind, of what, then, is an empty desk a sign?”

woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

10 Great Headlines courtesy of the 2013 Farmer's Almanac
1. Hospitals Sued by 7 Foot Doctors
2. Police Begin Campaign to Run Down Jaywalkers
3. Panda Mating Fails: Veterinarian Takes Over
4. War Dims Hope For Peace
5. Astronaut Takes Blame for Gas in Spacecraft
6. Juvenile Court to Try Shooting Defendant
7. Something Went Wrong in Jet Crash
8. New Study of Obesity Looks for Larger Test Group
9. Cold Wave Linked to Temperatures
10. Typhoon Rips Through Cemetery: Hundreds Dead

woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9

The early bird gets the worm, but the second mouse gets the cheese.

woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9
 
© 2013 DaniWeb® LLC
Page rendered in 0.1839 seconds using 2.76MB