JoshuaBurleson 23 Posting Whiz

Don't bump old threads, particularly old solved threads...this one is six years old for goodness sake...

JoshuaBurleson 23 Posting Whiz

You miss the point pyguy62 .
It shall not replace "e" in words,but print all word that not contain 'e'.

Thank you snippsat, I don't know how I misread that; I will add that to my top ten list of reasons not to post after 1 am, sorry guys.

Hold for that "silly" mistake, my point to op was, and remains, that he could make a function abstract and use a parameter then, as opposed to assigning a specific file in the function; it seemed to me he was a little confused about how that worked from his initial post.

JoshuaBurleson 23 Posting Whiz

yeah that happened while I was trying to reformat the comments, and it's too late to fix now, but I complained to the mods. Thanks for pointing that out though. Oh I've never seen the itemgetter before, that's a handy tool; and easier on the eyes to a newbie than lambda, I remember the first time I saw a lambda I was so confused, and then confusion became love when I realized how much easier they can make life.

Also, apparently daniweb didn't like my multiline comments ''' ''' so I changed them each to one line # comments. I don't remember having an issue with that before, maybe I just never did it...

JoshuaBurleson 23 Posting Whiz

I think you misunderstood what he was saying. We could TELL you that you're starting to think correctly, but there's still a big, essential piece missing from the puzzle for you. Pytony pointed you in the right direction though, you're getting closer. Check out what he showed you. and also try seeing exactly what's going on here:

{'115': '115 139-28-4313 1056.30\n135 706-02-6945 -99.06\n143 595-74-5767 4289.07\n155 972-87-1379 3300.26\n162 814-50-7178 3571.94\n}

Look closely at that format, I see a definite pattern. Once you read those this may become clearer, also think about how this format happened as a result of what is being iterated through, and how it's being iterated.

JoshuaBurleson 23 Posting Whiz

This is not the place to start python my friend. It's a very easy language to learn, I suggest you check out our Starting Python sticky thread, and there are tons of books on learning python, many of them free. And I've heard Bucky, at thenewboston has a great set of video tutorials on python. You'll be up for this in no time. Also, check out the requirements for android.

JoshuaBurleson 23 Posting Whiz

so you know, the function you created doesn't need the parameter word, but if you were abstracting the function, which is often considered better; you could make it something sort of like:

def no_e(word):
   noe=word.replace('e','')
   return noe

and then iterate through the words in the file and no_e them.

my interactive experiment with this:

>>> withh='electric slide'
>>> without=[]
>>> for word in withh.split():
	without.append(no_e(word))
>>> for word in without:
	print(word)

lctric
slid
JoshuaBurleson 23 Posting Whiz

I'm going to over complicate the matter,as to show you step by painful step how the process goes, in my mind that is. I'm not going to make functions either, let's see you re-engineer my code, and hopefully simplify it. Also, post your result. "Note that help.txt was a copy of your original post, without the code. I can't state enough that it shouldn't take this many steps and lists. I did that for educational purposes, because I love to have things over explained.

#Overly Thourough Process
#This could surely be done without 3 lists and so many steps

with open('help.txt','r') as f:
    #Readlines will make me a nice, pretty(ish) list
    file_list=f.readlines()

#list for the larger strings
unsanitized_words=[]
#list for words that still have non-alpha characters
iteration_list=[]
value_list=[]#list to be sorted based on frequency of word "more on this later"

for word in file_list:
    #'''These are large strings I'm gonna break 'em down'''
    for real in word.split():
        sub=real.split(',')#'''okay now I want to break them down a bit more'''
        
        for wrd in sub:
            unsanitized_words.append(wrd)#'''and now I have words, given they still have non-alpha chars, so
                                         #they're not sanitized enough for me, into the unsanitized list for them '''
            

for word in unsanitized_words:
    #'''Like a surgeon scrubbing in I'm gonna sanitize the crap out of these words
       #I'll make a new word of each word, without non-alphas,hold for apostrophes'''
    word=word.lower()
    new_word=''
    for char in word:
        if char=="'":
            new_word+=char
        elif char.isalpha():
            new_word+=char
        else:
            pass
    if new_word=='i':#'''and I'll add that word to the …
JoshuaBurleson 23 Posting Whiz

also use code tags when posting code. And as woooee said, this isn't doyourhomeworkweb it's Daniweb, read the forum rules.

JoshuaBurleson 23 Posting Whiz

Post code and ask specific questions, read forum rules and/or pytony's signature.

JoshuaBurleson 23 Posting Whiz

It seems the best way, at least to me, is to have a set amount labels with images on the page, and have something like a next button that will reassign the image value of the label.

JoshuaBurleson 23 Posting Whiz

@Tony: That worked perfectly, so not only did I fix the problem I learned which order events are taken. Thanks Tony and Gribouillis!

JoshuaBurleson 23 Posting Whiz

also I've tried the same with

def search(self,val,event):
   pop_up(val)

to make sure it wasn't just an issue of it being clicked on and having an extra event, as happens when binding '<Return>' to something.

JoshuaBurleson 23 Posting Whiz

I'm trying to utilize partial in order to bind an image to it's associated name in a list "you'll see what I mean" but I'm getting a TypeError thrown on it, this is my first time trying to work with partials so I'm just not quite sure what's going on:

self.lab5.bind('<Button-1>',partial(self.search,val=mem[2]))
'''/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/'''
    def search(self,val):
        pop_up(val)

Traceback:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
    return self.func(*args)
TypeError: search() got multiple values for keyword argument 'val'

any insight would be greatly appreciated!

JoshuaBurleson 23 Posting Whiz

That's not really necessary, did you try running our codes as well? Maybe we should see more of the code, I don't see how it could be relevant but obviously something ridiculous is going wrong...

JoshuaBurleson 23 Posting Whiz

Try it in IDLE, see what happens

JoshuaBurleson 23 Posting Whiz

Thanks for your reply.
1 that's just part of my whole program,I didn't post it all.
2 I TRIED THE CODE AGAIN , IT STILL DOES NOT WORK OUT:IT'S STILL"hit :4 missed :1"

hmm that's weird, I got:

Shoot: a1 b1 c3 c4 f7
Hit: 1 Missed:  4
Hit: 2 Missed:  3
Hit: 3 Missed:  2
Hit: 4 Missed:  1
Hit: 5 Missed:  0
Hit: 5 Missed:  0
JoshuaBurleson 23 Posting Whiz

haha, I'm just starting to learn VB I was going on pythonic pseudo-code, where we don't have to end the while.

JoshuaBurleson 23 Posting Whiz

Worked fine for me, line 6 "guess= list(guess)" was unnecessary, when you split it, you're splitting the string into a list. Also, how are you going to account for user error? ie. what if I entered: Shoot: f7, c4, c3, b1, a1

JoshuaBurleson 23 Posting Whiz

Rev Jim is right, check your algorithm, when you're simply assigning each of them to a random number there's no guarantee that they will all be different.

Have an empty array
while the length of the array is less than six
generate a random number
if that random number isn't in the array add it
else pass and get another random number and try again
when the array is at length six~End
JoshuaBurleson 23 Posting Whiz

well, even i thought of making keys as contact names but in that case we can not enter duplicate names as keys in dictionaries cannot be repeated,
So i assigned a unique number to each name so that even if there are two persons with the same name then also it will accept the data.
And please will you tell me how to use the tags
Like when i am posting program then use tags or for the whole program i need to use tags

Exactly, you can force the user to specify which contact they're looking for; when they're entering the contacts name and information before you have it save you could check if it's already a key and tell the user they need to make it so the name is not a duplicate of a previous entry or that it will update/overwrite the previous one. I know as a user I wouldn't want to have to enter tony5 to get tony...

JoshuaBurleson 23 Posting Whiz

-Are you sure the file is in the same directory as the program calling it?

-you don't append to a dictionary, you can append to a value if that value is a list or you can update a dictionary.

-if you could you're trying to add the file the dictionary for each line in the file.

-note that read lines makes a list of the lines in the file. "try it out"

-stop doing what you're doing.

-think about how you know the file is formatted and keep in mind the the structure of a dictionary entry is {key:value}

-check out woooee's example, it's good, I like it, no, I love it; if it were coffee, I'd drink it.

JoshuaBurleson 23 Posting Whiz

well I've never used graphics but I've used livewires;though I must admit very rarely, however maybe showing you what this "with only one falling snowflake for now" would look like with livewires:

from livewires import games

games.init(screen_width=400, screen_height=400, fps=60)

flake=games.load_image('snowflake.png',transparent=True)
cabin=games.load_image('snowy_cabin.jpg',transparent=False)

games.screen.background=cabin

class Snow(games.Sprite):
    def update(self):
        if self.bottom>games.screen.height:
            self.y=games.screen.height/20

snow=Snow(image=flake,
          x=games.screen.width/2,
          y=games.screen.height/20,
          dy=.25)

games.screen.add(snow)

games.screen.mainloop()
JoshuaBurleson 23 Posting Whiz

Tcll, as you should know people are much less likely to reply to "solved" threads, we also don't like old ones bumped up, just start a new thread.

JoshuaBurleson 23 Posting Whiz

the majority of them seem to be the unicode value -5; I'm not terribly patient with math, Gribboulis is probably your man for this, hope he stops by.

JoshuaBurleson 23 Posting Whiz

Python comes with an IDE called IDLE; I'd suggest reading the beginner threads and also decide which version of python you're going to start with, python 3.2.2 is the most recent version, there are more packages available for python 2.7 but the future is python 3; python 3 is backwards-incompatible with python 2. A good GUI package to start with is tkinter it's built into the python standard library. There a few other IDE's than IDLE available, but that's up to you, and there are plenty of good beginner guides to python.

JoshuaBurleson 23 Posting Whiz

You can't just drop off your homework assignment and expect us to do it for you, put some effort in and we'll help you figure out issues.

JoshuaBurleson 23 Posting Whiz

Yes that probably wasn't the best example to use, I wanted to show him how to do what he was trying to do with his for loop, but yes bigredaltoid pytony is quite right [::-1] makes a reversed copy.

Tony, you used to teach python, since reversed(word) isn't really a copy of the word reversed, that would likely work for his professor, correct?

JoshuaBurleson 23 Posting Whiz

You were thinking in the right direction, you just weren't actually doing anything: I'll give you heavy help on one of them and the idea should become quite clear for all of them.

>>> word=input('word: ')
word: hello
>>> word3=''
>>> for letter in word[::-1]:    #which could also be "for letter in reversed(word):"
	word3+=letter
>>>word3
'olleh'

should be able to do it in 9 lines or less.

Also, tell your professor it's far enough into the semester that you should be farther along than string concatenation by now...I learned the majority of what I know in about a month and a half, of course I wasn't stuck in a class for it. Good luck!

JoshuaBurleson 23 Posting Whiz

No, I just checked out similar clocks on tkinter using the power of google, I didn't even think to go to the color changing one :(

JoshuaBurleson 23 Posting Whiz

oh how do I report it to a mod? I know there's the bad post button; but that's only if the post violates the rules right?

JoshuaBurleson 23 Posting Whiz

:) well just so ya know there is a random module with things like shuffle.

import random
f=open('names.txt','r')
names=f.readlines()
f.close()
selected_names=set()
while len(selected_names)<5:
   random.shuffle(names)
   indx=random.randint(0,len(names)-1)
   selected_names.add(names[indx])

a set will get rid of any duplicates. but you could also do a "if key not in list" kind of thing:

selected_names=[]
while len(selected_names)<5:
   random.shuffle(names)
   indx=random.randint(0,len(names)-1)
   if names[indx] not in selected_names:
      selected_names.append(names[indx])
   else:
      pass
JoshuaBurleson 23 Posting Whiz

Just fooling around I came across an issue updating a digital-clock like label. This:

self.now=time.strftime('%a. %b %d %Y %H:%M:%S',time.localtime())
        self.clock=ttk.Label(self,text=self.now)
        self.clock.pack()
        while True:
            self.now=time.strftime('%a. %b %d %Y %H:%M:%S',time.localtime())
            self.clock['text']=self.now

simply freezes the program, I've managed to get it to update on certain events like the user hitting a button but I'd like it to continuously update. Any ideas?

EDIT: I got this to work using configure, but why does that work and not this?
Double EDIT:After some thinking I decided it was because the program was stuck in an infinite while loop, however this simply revisits the method.

JoshuaBurleson 23 Posting Whiz

hmmm...I feel like this is one of those things that is pretty well documented, here's one option:

>>> f=open('the.txt','r')
>>> text=f.readlines()
>>> text
['this\n', 'is \n', 'a \n', 'file']

There's a class on google code for python, check it out it's not too bad.

JoshuaBurleson 23 Posting Whiz

hit the (CODE) button/tags before you post code, also your strategy for the key is awful...I don't understand why you would

do:d=len(phbuk);phbuk[d+1]=name

How about something more like: phbuk[a]=abc #"or [b,c] depending on your preference"#

Now if i want to delete a particular record just by giving name then how can i do it.

Well if your doing this text based then maybe you should have a menu with which the user chooses to either search, add, or delete, if they choose delete then they could enter the name:

dname=input('Enter a contact to delete: ')
if dname in phbuk.keys():
   del phbuk[dname]
else:
   print('That contact is not in the phonebook!')

but that's just what I would do...

now onto why I feel that your "d" variable was so poor, you're making the key more abstract than it needs to be, dictionaries are so wonderful,to me at least, because organize your data with strings, which can be words or names, which makes your question of how to search so easy, here's what I've done before:

#assuming were under the search option
search_n=input('Enter a contact name to search: ')
if search_n in phbuk.keys():       #note that I would capitalize search_n for both searching/deleting and when saving the contact
   for info in phbuk[search_n]:
      print(info)
else:
   print('Invalid Query')

again, these are just MY suggestions, this is your code, keep up the effort and keep us posted on your developments, also, don't forget those code tags!

JoshuaBurleson 23 Posting Whiz

pyguys version ignores case, non-letter issue, here is the pyTonyc version, as OP did it by himself:

def is_palindrome(sentence):
    lower_letters = ''.join(c.lower() for c in sentence if c.isalpha())
    return lower_letters == lower_letters[::-1]

for test_case in ('A man, a plan, a canal, Panama!','Saippuakivikauppias', 'Not Tony'):
    print('%r %s palindrome' % (test_case, 'is' if is_palindrome(test_case) else 'is not'))

good point, I was just going with this statement

(one word per line)

but yes, you are right, that was does cover alot more ground.

JoshuaBurleson 23 Posting Whiz

Don't forget about the reversed() BIF here, it could save you a few lines:

def is_pal(word):
    rev_word=''
    for letter in reversed(word):
        rev_word+=letter
    if word==rev_word:
        return True
    else:
        return False

likewise, it's much simpler and easier to maintain.

JoshuaBurleson 23 Posting Whiz

use the code tags to display your code

JoshuaBurleson 23 Posting Whiz

Instead of 1 or 0 why don't you return True or False...? Also, even though it's a bad habit of mine, it's considered ugly to use globals when not necessary in a function, you could simply return what you need to, try putting all these things in an array or hash "list or dictionary" and having them returned along with True or False.

>>> def is_good(word):
	word.capitalize()
	if word == 'Python':
		return True
	else:
		return False

	
>>> wrd='C'
>>> is_good(wrd)
False

also for changing global variables:

>>> lis=[0,1,2,3]
>>> 
>>> def plus1(that):
	new=[]
	for i in that:
		i+=1
		new.append(i)
	return new

>>> lis
[0, 1, 2, 3]
>>> lis=plus1(lis)
>>> lis
[1, 2, 3, 4]
paraclete commented: Thank you for the input +0
JoshuaBurleson 23 Posting Whiz

I would abstract the date box into a function and use string formatting to insert the words date and whatever date is, maybe I'm misunderstanding the problem, but I'd do something like:

def make_label(word):
	try:
		lab='| %s:             |\n+-------------------+' % word
		return lab
	except TypeError:
		lab=''
		for words in word:
			slab='| %s:             |\n+-------------------+\n' % words
			lab+=slab
		return lab

	
>>> wrdz=('Date','Time')
>>> label=make_label(wrdz)
>>> print(label)
| Date:             |
+-------------------+
| Time:             |
+-------------------+

also: I see a "potential" issue with this:

for i in range(noCandidates)
        names.append(input("Candidate 1:", "Candidate 2:", "Candidate 3:")

Which just as I posted I saw pytony did too.

JoshuaBurleson 23 Posting Whiz

I'm confused, so you want to create a free web service that does something that people need done, and you DO or DON'T want it to be surveys? Sorry for the confusion.

JoshuaBurleson 23 Posting Whiz

wrong type, watch this magic:

>>> a=input('code: ')
code: 3
>>> a==3
False
>>> a
'3'
>>> print(3)
3
>>> type(a)
<class 'str'>
>>> type(3)
<class 'int'>
>>> a=int(a)
>>> a==3
True

input creates a string, if you want it to be an integer you need to be explicit about it.

JoshuaBurleson 23 Posting Whiz

Here's a little help to get the juices flowing, but for the future you need to show effort around here take heed of Ezzaral's edit notes and read that thread, or for a quicker review of what he's talking about read pytony's signature

def mult_table_numbers():
    alpha = int(input('Starting: '))
    omega = int(input('Ending: '))
    for intg in range(alpha, omega+1):
        for i in range(alpha,omega+1):
            print(str(intg)+'x'+str(i)+'='+str(intg*i))
JoshuaBurleson 23 Posting Whiz

You need to show some effort, but first think about what's happening, obviously it knows the LENgth of the word and displays dashes for letters that haven't been guessed and IF the letter guessed is IN the word then it will show that letter. You need to make the function, show us some work and we'll likely help with more specific issues.

JoshuaBurleson 23 Posting Whiz

It does, but I'm stuck in a pattern of thinking I can't get out of with the use of it, here's what I've been trying:

self.box=Listbox(self)
        self.box.pack()
        list1=['icon_man.gif','group_icon.gif']
        for img in list1:
            imag=PhotoImage(file=img)
            self.box.insert(END,imag)

This just puts the word (pyimage"whatever number") in the box, which makes sense "unfortunately" any alternative ideas?


And to make sure that it wasn't just the listbox being an issue

def create_widget(self):
        self.lab=Label(self)
        self.lab.pack()
        list1=['icon_man.gif','group_icon.gif']
        for file in list1:
            word=PhotoImage(file=file)
            self.lab['image']=word
JoshuaBurleson 23 Posting Whiz

As most of us know in tkinter in order to properly display an image it must be assigned to a variable, however what if you don't know that amount of images that are going to be necessary? i.e. A friend list, how would one display the friends pictures?

JoshuaBurleson 23 Posting Whiz

Does anybody know a good working Python 3.x wrapper for OAUTH2? I'm having issues with the backwards incompatability with simplegeo-python-oauth2.:'(

JoshuaBurleson 23 Posting Whiz

Well Jose,
first how would you determine this matematically?
then show us that you've written the pseudo-code.

JoshuaBurleson 23 Posting Whiz

Nice, thanks.

JoshuaBurleson 23 Posting Whiz

It was easier for me with a function, also if you want to get the correct index value remember that python counts the first as 0, so how do you think you should accommodate for that d3fined?

JoshuaBurleson 23 Posting Whiz

This doesn't belong in code snippets as it is a question, hopefully a mod will fix that soon. Python comments are preceded by # or are within ''' ''' also your indentation is way off. Also, given this code how do you intend the "ATM" to know the customers password? I'd think about implementing a dictionary "I'd use a pickled file". Thanks for putting in effort before posting, next time just post questions as a normal post, code snippets are essentially for finished codes.