woooee 814 Nearly a Posting Maven

You want to take another look at the error message as you would not get to the input statement. The program will stop at "def main()" and "def getfibnum()" Also, take a look at this statement
firstnum = 1 = language
firstnum can either equal 1 or language, but not both.

Finally, the statement "fibnum = getfibnum()" will always result in fibnum = None

Look at post #3 here (and beyond) for the way to program a function http://www.daniweb.com/forums/thread20774.html

woooee 814 Nearly a Posting Maven

I would use a dictionary with the category as key, and a list of all words in the subset as the value

Let V be the vocabulary of all words in the documents in D
For each category ci
----->ci=dictionary key
Let Di be the subset of documents in D in category ci
----->Di = value associated with each key = list of words in this category
P(ci) = |Di| / |D|
Let Ti be the concatenation of all the documents in Di
----->Already have this as a list is a concatenation in the sense that I think it is being used here
Let ni be the total number of word occurrences in Ti
----->(not unique occurrences but all occurrences??)
----->ni = len(dictionary[ci]) i.e. the length of the list
For each word wj
Let nij be the number of occurrences of wj in Ti
----->You can loop through each key's list or use a_list.count(wj)
Let P(wj | ci) = (nij + 1) / (ni + |V|)
----->Not sure what all of this means, but it's values should be found in the above calcs

woooee 814 Nearly a Posting Maven

You want to use a counter, incremented by +1, to access that element of each one of the lists. This can be done in fewer lines of code but this is the easiest to understand.

combined_list = []
stop = len(list_1)
for ctr in range(0, stop):
     junk_list = []
     junk_list.append( list_1[ctr] )
     junk_list.append( list_2[ctr] )
     combined_list.append( junk_list )

I will leave it to you to insert the header lits as the first element, and decide what happens if the two lists are not the same length.

woooee 814 Nearly a Posting Maven

Thanks Gribouillis. I didn't know about bisect.

woooee 814 Nearly a Posting Maven

Definitely use a dictionary or SQL database if there are a lot of entries. It is hundreds or thousands of times faster depending. The time consuming part of the code is looping through the list twice. Using a try/except to check the list once with no "in" statement is a workaround, but just a workaround and not better than using a dictionary. As for checking letter by letter, that's what the existing or any compare/find/index has to do. There is no way to find something comparing an entire word to an entire word. The only shortcut that I know of would be to group words according to length. Thus, a five letter word would only look at other 5 letter words, and not words of other lengths.

##if wordq in  a:     ## omit this line - duplicate list checking
try:
   c = a.index(wordq)
   print wordq
   print
   print b[c]
except:
   print wordq, "wasn't found in 'a'"

Edit: There is also sets if dictionaries are more than you want to do at this time. Both dictionaries and sets use a hash as an index, so the execution times should be similiar for both.

list1 = ['a', 'b', 'c', 'd']
list2 = ['b']
set1=set(list1)
set2=set(list2)
set3= set1.intersection(set2)
print "set3 =", set3

set5=set(["z"])
set6=set1.intersection(set5)
print "set6 =", set6
woooee 814 Nearly a Posting Maven

First try "import Tkinter" with a capital "T". If that doesn't work, post the code you used and an exact copy of the error message.

If you have to install, install python-pmw. It will install TCL, Tk, and Tkinter as dependencies if they aren't installed, and you will likely want the PMW extensions if you are going to program GUIs. If it still doesn't work, then re-install python via Synaptic or apt-get on the command line. On some distros, the installer will check for external packages and make python accordingly. That is, if there is no Tkinter installed, it will not configure python with Tkinter, so you have to re-install python so it can be re-configured.

If all of that doesn't work, then use ActiveState's intaller to install Python. http://www.activestate.com/store/download.aspx?prdGUID=b08b04e0-6872-4d9d-a722-7a0c2dea2758 Once it is installed properly you won't have to mess with it again as the updates will take care of themselves.

woooee 814 Nearly a Posting Maven

If you run the above code, it will not work as expected. You want
if shipweight <= 2: as the first if, and the following elif's should use and
elif shipweight >2 and shipweight <6:
Also, what if the weight equals 6? This code doesn't allow for that. BTW, the "standard" way of doing this kind of thing is to use a container like a list. You eliminate a long string of elif, and you can simply modify the list to add/change/delete weight catagories. (No additional elif necessary if another catagory is added.)

def shipping_charges(package_weight):
     charges_list= [ [10, '4.80'],
                     [ 6, '4.70'],
                     [ 2, '3.20'],
                     [ -0.01, '2.10'] ]
     for weight_list in charges_list:
          print "     checking", weight_list[0], "-->", weight_list
          if package_weight > weight_list[0]:
             print "found"
             return weight_list[1]

print 'Welcome to Shipping Company Rate Calculator'
shipweight=raw_input ('Please Enter the Weight of the Item You Wish To Ship: ')
try:
   weight_package = float(shipweight)
   charges = shipping_charges(weight_package)
   print "Your total shipping charges:", charges
except:
   print "You can only enter a number"
woooee 814 Nearly a Posting Maven

On Linux, you can add a path to the PYTHONPATH variable in ~/.bashrc. Add this line
export PYTHONPATH=${PYTHONPATH}:/new/path:/another/path:/colon/separates
The next time you boot, the PYTHONPATH will reflect the changes.

woooee 814 Nearly a Posting Maven

You can use a variable named something like self.red_light_on. Set it to True when the light changes to red, and False on a change to green or yellow. Then

if not self.red_light_on:
     canvas.move(car1,x,0)
     canvas.update()
woooee 814 Nearly a Posting Maven

I would take a look at the following lines. In the first line of code, "i < 100 and 255", what is "and 255" supposed to do? Also, I would add the print statement before the second line of code to see what is happening.

# select regions where red is less than 100
mask = source[R].point(lambda i: i < 100 and 255)

# process the green band
print "source =", len(source), G, source
out = source[G].point(lambda i: i * 0.7)
woooee 814 Nearly a Posting Maven

Literally, what i want is >"if the all the letters in the Word match the letters in the successful letters do whatever"<
any suggestions?
Thank you very much for reading this ;)

So I think you are asking how to do this

found = True
for letter in MainInput:
   if letter not in GuessWord:
      found = False
if found:
   print "Your guess is correct"
##
##   If you want to keep track of incorrect letters
incorrect_list = []
for letter in MainInput:
   if letter not in GuessWord:
      incorrect_list.append(letter)
if len(incorrect_list) == 0 :
   print "Your guess is correct"
##
##   you can also simply use "=="
if MainInput.lower() == GuessWord.lower():
if MainInput in GuessWords:

Of course if there are two "a"s in MainInput and one in GuessWord, the first two examples will still give you a positive result. In which case you could delete that letter or just replace a guessed letter with "*" which would solve the problem.

P.S. If the code is an exact copy of your program, 'householdl' is misspelled (and how do you spell mis-spelled?)

woooee 814 Nearly a Posting Maven

Sorry for the dumb question, I saw the problem, thanks for looking though.

They are pretty much all dumb.....after you find the answer. Also, please mark the post solved.

woooee 814 Nearly a Posting Maven

"How to Think Like a Computer Scientist" is one of many online books that can help with classes. http://www.greenteapress.com/thinkpython/thinkCSpy/html/
http://www.python-eggs.org/

woooee 814 Nearly a Posting Maven

Is anyone else getting a little tired of the "I Googled it and couldn't find anything" lie. "python sum list" brings up "total = sum(list_name)" as the second hit. Searching for "python adding list" gives both the sum() and a for() loop as examples on the fourth hit. But is it a complete waste of time to call them on it? Perhaps we should start posting the Google link. I am more than willing to help anyone with a real programming problem, but this wasting everyone's time can lead to fewer programmers who help because of all of the cruft that one has to wade through.

woooee 814 Nearly a Posting Maven

Assuming the name of your program is helloWorld.py, you would add the first line in the following example which tells the OS to use Python to run this program. Also add the "__main__" section at the bottom and make the file executable by your user name. You can then enter the program's name on the command line, or highlight it and hit Enter if you use MidnightCommander or something similiar, and the program will run. __main__ is usually for testing. It is only called when this program is executed so if you call the function hello() from another program, the __main__ section will be ignored. You can then use any text editor or word processor, or an IDE like Idle to modify and save the file, and then enter helloWorld.py on the command line to run if again. I think a good many of us do not use IDE's and instead have a text editor and terminal window open at the same time. So it's, change the code and save it, run it in the terminal, check the output, change the code and save it, etc.

#!/usr/bin/env python
#
# if that doesn't work then use call python directly as in the following line
##   #!/usr/bin/python2.5
#
#helloWorld.py

from myro import *
init("/dev/rfcomm0")

def hello():
     forward(.5,.5)
     stop()

if __name__ == "__main__":
   hello()
woooee 814 Nearly a Posting Maven

I convert to pdf whenever there is a lot of transferring to be done between different OS's just because it is a common standard and has converters to/from text for all of the machines.

woooee 814 Nearly a Posting Maven

I want to refer back to the previous values without having to list all of them out again

To answer your original question, you can copy a list with

orig_numbers_list=[10,13,32]
for j in range(48, 123):
   orig_numbers_list.append(j)

numbers = orig_numbers_list[:]
print "orig =", orig_numbers_list

del numbers[0]
del numbers[5]
print "\n\ncopy =", numbers

Note the "[:]". The statement "numbers = orig_numbers_list" would yield a pointer to the original list, not a copy, so changing one list would also change the other since they would both point to the same list, so "[:]" identifies a copy operation.

woooee 814 Nearly a Posting Maven

I think the way to go about this is to use modulo or divmod to find the numbers that you can divide the given number by. That is the remainder == 0. You will be working with single numbers which is less confusing. Actually, you can use the (given number / 2) since all numbers greater than the halfway point can't be divided into to the number. Then sum these numbers and see if they add up to the given number.

woooee 814 Nearly a Posting Maven

You do want threading (note the "ing"), not subprocessing which is used to run a single instance. This link is to Doug Hellman's examples which are excellent. http://blog.doughellmann.com/2008/01/pymotw-threading_13.html The other choice would be to use pyprocessing http://pyprocessing.berlios.de/doc/intro.html There is also fork and spawn but threading or pyprocessing are preferrable as they can do more. Learn one of these, whichever appeals to you the most, and that should be enough for most programs.

woooee 814 Nearly a Posting Maven

Note: I just managed to try the new one on a Windows machine, and it worked. WTF.

It might have something to do with line endings. MS Windows uses decimal 13 & 10 and Linux (Mac) uses decimal 13 only. Since MS Windows pickle works on Windows and Mac's works on a Mac, it appears to be the way data is stored. If you store a normal text file on MS Windows and open it on a Mac you will see an odd character at the end, which is the additional decimal 10. There are several to convert files, depending on what you want to do. The quick solution, as stated above, is to use a normal file instead of pickle.

woooee 814 Nearly a Posting Maven

You should have also seen "Press Enter" or whatever, then you hit the Enter key, and afterwards you should see "Bye, "Bye" on the screen. If that doesn't work, I would strongly suggest reinstalling Python as it appears there is a problem. Activestate has the easiest installer for a new user IMHO. http://aspn.activestate.com/ASPN/Downloads/ActivePython

woooee 814 Nearly a Posting Maven

Run it from Idle. There is a "run" option in the menu. Idle will display the output. So enter the code in Idle, save it in Idle, click on the "run" option in the menu, and look at the output all within Idle. Finally, you can try storing your input to a variable but I doubt that will help.

print "Hello World"
x = raw_input("Press Enter")
print "Bye Bye"
woooee 814 Nearly a Posting Maven

Post the code that you have so far. It's a straightforward program which asks for input, calculates the result, and prints the output.

woooee 814 Nearly a Posting Maven
>>> print "hello World"

raw_input("Press ENTER to exit")

That is all I have for my code

Works for me on Linux. Try

print "Hello World"
raw_input("Press ENTER to exit")
raw_input("Press ENTER to exit")
raw_input("Press ENTER to exit")

It may be that when you enter the program name on the command line, it's using that Enter for the raw input. (Being a Linux person I would just say that MS Windows is weird.) Anyway, post back with the solution if you find it. Someone else will surely be searching for that in the future.

woooee 814 Nearly a Posting Maven

First try using idle instead of Notepad. You can enter, save, and run the program from Idle. It should be under the python and then idlelib directories, and is something like Idle.py-I don't remember. That will solve the immediate problem. Your solution should work also, so it may be that it is in a part of the program that is not reached. Post the entire program if you want more info. To answer the question directly, use time.sleep(seconds)

import time
print "Starting Program"
time.sleep(2)
print "2 seconds are up already"

Edit: Here is a link to the python docs. See the "Starting IDLE on Windows" section and welcome to Python. http://www.python.org/idle/doc/idle2.html

woooee 814 Nearly a Posting Maven

I wanted to know if i could get some help to start the menu.I'll do the maths part working with the iterations etc as i learnt about loops today

Post the code for the math and we will help with the menu. Of course it's not going to happen. The strategy here is to keep asking more questions until little by little the entire program is coded by someone else, or rather by many others. Please don't give positive reinforcement to lazy manipulators. It only increases their appetite.

Obviously, no one has tried Google. But that takes initiative and some work.

woooee 814 Nearly a Posting Maven

Possibly, one hundred loops of a for() statement happens so fast that it is done before any other data is received. Try this example which sleeps for half of a second and see if the data changes.

for x in range (0,100):
   s = ser.readline()
   print x, repr(s)
   time.sleep(0.5)
woooee 814 Nearly a Posting Maven

I am trying to create tuple but not able to do it.

You can not change a tuple, you have to use a list. If I read your code correctly, you want something like the following

subject = "test subject"
message = "message test"
sender = "sender@test.com"
data_list = []
for emailadd in mailing_list:
   ##   only the emailadd changes
   data_list.append([subject, message, sender, emailadd])
#
# print it to see if this is what you want
for address in data_list:
   print address   ## should be a list the way you want it
woooee 814 Nearly a Posting Maven

x = len(matches) so when you delete a character, the length of matches is reduced but x remains the same. There are several ways to do this. The easiest would be to test for
if word.lower() in matches.lower(), but if you want to use this example then remove the del matches[c] line since it serves no purpose as far as I can tell. If that doesn't solve your problem, then post back with some sample data.

woooee 814 Nearly a Posting Maven

Read the docs please.

http://www.google.com/search?hl=en&client=opera&rls=en&hs=xhs&q=python+day+of+week&btnG=Search
The very first hit. It's questions like this that cause me to run out of flame retardant. It's interesting that the third hit is Zelller's congruence (for anyone who want's to calculate it themselves). That hit also references calendar.weekday.

woooee 814 Nearly a Posting Maven

A Google for "Tkinter menu" will yield numerous examples. New Mexico Tech http://infohost.nmt.edu/tcc/help/pubs/tkinter/
and Fredrik Lundh http://hem1.passagen.se/eff/
have good Tkinter sites. The following code came from "Charming Python", also a good site. http://www.ibm.com/developerworks/linux/library/l-tkprg/#h5

def help_menu():
    help_btn = Tkinter.Menubutton(menu_frame, text='Help', underline=0)
    help_btn.pack(side=Tkinter.LEFT, padx="2m")
    help_btn.menu = Tkinter.Menu(help_btn)
    help_btn.menu.add_command(label="How To", underline=0, command=HowTo)
    help_btn.menu.add_command(label="About", underline=0, command=About)
    help_btn['menu'] = help_btn.menu
    return help_btn
woooee 814 Nearly a Posting Maven

letters_used and wrong are never incremented. You should be able to tell that from the print letters_used statement. Also, you define letters_used=() (a tuple) and not zero.

woooee 814 Nearly a Posting Maven

Except that neither one thought to test for a < 0 (if someone doesn't know any of the words) or a => len(words). Also, you have 19 words and 20 answers. When doing this type of programming it is better to
(a) use a dictionary with the word as the key, pointing to the answer
(b) or at least test that len(words) == len(answers) especially if you are going to modify the lists at any time.

woooee 814 Nearly a Posting Maven

You can use string_var.isdigit() and string_var.isalpha(), or use a try/except.

try:
   float_var=float(string_var)
   print float_var, "is a number"
except:
   print string_var, "is a string"
woooee 814 Nearly a Posting Maven

My personal preference would be using a dictionary since it would be indexed on the number, but there are several ways to do this along the lines of the following. Add the recs to a dictionary. When a 7 is found, send the dictionary to a function to process. If this isn't what you want, then post your code and we will try to correct it for you.

##   print (or write to a file) the existing dictionary of records in a "replace 4 with 7" order
def process_list(rec_dic):
   write_order = (8, 9, 1, 2, 3, 7, 5, 6, 7)   ## note "7" prints twice here
   print "\nwriting records to the file in this order"
   for key in write_order:
      if key in rec_dic:
         print "     ", rec_dic[key]
woooee 814 Nearly a Posting Maven

Adding these print statements should shed some light on this if I understand what you want to do. Run it this way and if it does not give you an idea of what is happening then post back.

quotelist = []
for line in linelist:
     thesplit = line.split()
     print "\nline"
     print "     split into", thesplit
##     -- quote = Quote(thesplit[0],thesplit[1]) --
##     quotelist.append(quote)
woooee 814 Nearly a Posting Maven

You definitely want to add a print statement here

try:
    s=""
    a=f.read(1)
    while((a.isalnum() )or( a.isspace())):
        s=s+a
        a=f.read()
        print "'a' is now", a
woooee 814 Nearly a Posting Maven

zachabesh meant something like this, using 2 splits per record

test_data = [
"2001.7.1.407 изутрината во тетовски\n",
"2003.5.3.20083 кзк ја штити таканаречен\n",
"2001.6.1.407 test rec #1\n",
"2003.10.3.20083 test rec #2\n",
"2001.11.7.1830 винарските визби во македонија и оваа година\n"]

for rec in test_data:
   rec=rec.strip()
   dots_split = rec.split(".")
   print "\ndots_split =", dots_split
   if len(dots_split) > 3:
      print "year=%s,  month=%s,  catagory=%s" % \
            (dots_split[0], dots_split[1], dots_split[2])
      space_split = dots_split[3].split()
      if len(space_split) > 1:
         print "     id=%s,  name=%s" % (space_split[0], " ".join(space_split[1:]))
         
      else:
         print "space split error", dots_split[3]
   else:
      print "data error", rec
woooee 814 Nearly a Posting Maven

For future reference, you do not want to assume that the characters you search for are found. This is better IMHO, although I too would prefer to use .split(".")

if start == -1: 
   break
najdi = DB.find ('.', start)
if najdi > -1:
      end = DB.find ('.', najdi)
      if end > -1:
         br = DB[start:najdi:end]
woooee 814 Nearly a Posting Maven

Your question is too vague to answer. What does "cannot specify a new filename and can only overwrite an existing one" mean? Are there errors? If so what are they? The saveFile function would be the first place to look. What does "print saveFile" display? Also, it is bad form to have function names the same as variable names.

The next thing I looked at was "self.im_z.save(saveFile)" to see what ".save" did. I found
self.im_z = numpy.zeros((self.im[1].size[1],self.im[1].size[0]), dtype = "uint8" )
self.im_z[y,x] = val / len(self.inFiles)
self.im_z = Image.fromarray(self.im_z)
None of these statements appear to have a "save" method. More duplicate names? There is no way to tell, so all I can suggest is to add some print statements to self.im_z.save(saveFile), where ever it is, so you can see if it is being called. In the following code snippet, the second "test_function()" should give an error something like "int is not callable" because of duplicate names.

def test_function():
   print "test function"

test_function()
test_function=1
test_function()
woooee 814 Nearly a Posting Maven

King Henry VIII slept with a gigantic axe.

No wonder he couldn't produce a male heir.

Never hold your nose and cover your mouth when sneezing, as it can blow out your eyeballs

This one was discussed on another forum, I don't remember where, but it is supposedly impossible.

Smearing a small amount of dog feces on an insect bite will relieve the itching and swelling.

That one may be true. In my teenage years we would come into contact with nettles every so often, and would go to the river and put mud on it, as depriving it of oxygen will stop the itch. I think the itch from an insect bite comes from the mosquito's saliva so cutting off oxygen may help.

BTW, this thread is about suckers being suckered. If you accept any old crap that is published on the internet...you may be one

woooee 814 Nearly a Posting Maven

Note that you are reading an "exe" file. The first character is probably not alphanumeric or a space so it stops. You haven't gotten many responses because of laziness. Add a print statement to see what is being read [probably want to print ord(a) since it is not a text file], and print a message at critical points in the program so you know what is going on. Especially when you are entering a try or except block. If you get an error other than IO or EOF the except block won't print. Also, if the length of s is less than 4, you won't get any output so add an else: "length of s is too small", len(s). As I said, this type of post doesn't get much of a response because you haven't done any debugging yourself.

woooee 814 Nearly a Posting Maven

You can only have one number inside a bracket. You want something like the following to get the fourth element, but only if it is a list of lists

print type(line[0]), line[0]
if (i==2): width = line[0][3]
##
##   or if you want the first three letters
if (i==2): width = line[0][:3]
woooee 814 Nearly a Posting Maven

For future reference, it seems that matplotlib at sourceforge.net (matplotlib.sourceforge.net) would be one solution to statistical calcs like percentile and root mean square, in addition to checking the scipy programs.

woooee 814 Nearly a Posting Maven

You want a separate string to hold the time

now=time.asctime()
now=now.replace(":", " ")
print now

TimeStr = [ "The time is currently " + now, "Right now its " + now, "It's " + now, now ]
 
if phrase == "whats the time":
    speech.say(random.choice(TimeStr))
#
##   you can also use datetime and access month, day, hour, etc individually
now = datetime.datetime.today()
print "\n", now
print now.year, now.hour
woooee 814 Nearly a Posting Maven

Off-topic, how can I join the F-ugly code club? Whenever someone touts a program written in "pure python" I wonder if that means that my programs are in impure python. Maybe a support group would help: "Hello, my name is Joe and I write ugly code"

woooee 814 Nearly a Posting Maven

I would also suggest that you print s1 and s2 at the appropriate points so you can see what is going on. For example in the following snippet, what is the value of s1 if x%d does not equal zero and how does that effect s2?

if x%d==0:
			s1=s1+x/d
woooee 814 Nearly a Posting Maven

i know you have 15 years old.

part, I guess they took a quick look at my profile

That's a new twist. Of course they have a bot to check the profiles so they can send out thousands of e-mails. Last week on the news was a story about a college student who wanted to earn extra money, so signed up to be a secret shopper via the web. I did not know that this is the latest scam. After a couple of assignments she was sent a cashiers check for $1550.00, and told to deposit the check in her account, subtract $200.00 as a commission and send a money order to them for the rest as a test of money order efficiency. A $200.00 commission for sending a money order??, plus sending a $1 money order has the same efficiency as a $1350.00 money order.....no red flags there. The casher's check was conterfeit of course and she's out the money. The "15 years old" reminded me of this. Evidently teenagers are seen as easy marks for these type of scams.

woooee 814 Nearly a Posting Maven

Tix, additional widgets for tkinter, has a notebook that may or may not help. The code is available from here http://tix.sourceforge.net/dist/current/man/html/TixCmd/TixIntro.htm#M28

woooee 814 Nearly a Posting Maven

The problem they are running into is replacing "the" with "xxx" for example, but not finding and replacing "then" with "xxxn". I would suggest using split() to get the words, only replacing exact matches, and join() to reconstruct the sentence. If there are punctuation marks like commas in the phrase then that also has to be taken into account. But you are 90% there from the last two posts and that is enough.