User Profile

Collapse

Profile Sidebar

Collapse
woooee
woooee
Last Activity: May 14 '10, 06:42 PM
Joined: Mar 13 '08
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Start with this
    Code:
    if(x > screen_x or x < 0 or y > screen_y or x < 0):
    if(x > screen_x or x < 0 or y > screen_y or y < 0): <=====
    See more | Go to post

    Leave a comment:


  • Since you are sorting numbers, you want to convert to a float as well. Strings sort left to right, so "10" will sort before "2", because "1" is less than "2". Note that floats have limited precision so can be slightly different than the original number but work fine for "normal" calculations.
    Code:
    a = []
    line = "0001 , 4 , 0.34 , 3 , 15 , 25.3"
    a.append(line.split(','))
    ...
    See more | Go to post

    Leave a comment:


  • +1 on opening it as a normal file and splitting on the comma. Also, check the length of each split record before doing anything else. You should not rely on their not being any empty or malformed records in the file.
    See more | Go to post

    Leave a comment:


  • woooee
    replied to How to replace multiple integers at once
    Perhaps using a dictionary and looking at each character individually will be easier to understand. A link to an online book's description of a dictionary http://www.greenteapress.com/thinkpy...l/book012.html
    Code:
    dna = """tgaattctatgaatggactgtccccaaagaagtaggacccactaatg cagatcctgga 
    tccctagctaagatgtattattctgctgtgaattcgatcccactaaagat """
    
    changes_dict = {"t":"a", "a":"t",
    ...
    See more | Go to post

    Leave a comment:


  • You would use a function to compare the columns, but since you are unwilling or unable to even give that a try, there is an even easier-to-understand way. Create a second list with each element containing two tuples. The first tuple contains only the columns that you want to sort in the order that you want to sort them (4 elements each). The second tuple contains the original record (6 elements each). You sort normally and will have the entire...
    See more | Go to post

    Leave a comment:


  • From the Python Sort Wiki...
    See more | Go to post

    Leave a comment:


  • woooee
    replied to How to delete strings from a list
    l is a list of pointers to individual instances of the memb (Member) class, so you should look at the forename that each instance points to, and check what you are doing at the same time. Please don't use "i", "l", " or "O" as single letter variable names because they look too much like numbers. Untested code =
    Code:
    def delete_player(forename):
        """
        Delete a member from the list
    ...
    See more | Go to post

    Leave a comment:


  • woooee
    replied to List index out of range
    Whenever you are doing anything similar, always check for the proper length and print if it's not correct. You will eliminate a lot of unnecessary debugging.
    Code:
    x = line.split(";")
    if len(x) > 8:
        ## process normally
    else:
        print("Bogus line length =", x)
    See more | Go to post

    Leave a comment:


  • sleep() of course has to check the time periodically to see if it should wake up. If you can, submit the program every 15 minutes to the host, run and exit.
    See more | Go to post

    Leave a comment:


  • woooee
    replied to List index out of range
    You will have to post the error message which lists the line that contains the error. My guess is that you have a record with less than 9 items.
    See more | Go to post

    Leave a comment:


  • woooee
    replied to CVS file problem.
    Code:
    f = csv.writer(open("text2.txt" , "w").writerow(str(result))
    Check the number of left parens and right parens in this statement. I good IDE will assist with closing any punctuation you begin.
    See more | Go to post

    Leave a comment:


  • You want to first count the number of asterisks; that will be the cut-off. Next, compare the given word to all possibles. To allow for two letters that are the same, say a word has two "o"s for example, sort both words and compare with a loop, comparing each letter in turn. Increment through the word if a letter is found.

    You can also use lists, which is probably easier. Use the first word as the control. Convert the...
    See more | Go to post

    Leave a comment:


  • woooee
    replied to help needed
    Second column would just be row[2]. I don't understand the rest of the question (do you want row[2] output to be conditioned on row[7]?) so you should provide some sample data to clarify....
    See more | Go to post

    Leave a comment:


  • woooee
    replied to 'Reactivating' a previous while statement
    Pass the sequence to a function which returns the updated sequence. You can do this from the while loop and anywhere else in the program you want, providing the function is defined before the code calling it (the norm is to declare all functions first with the body of the code following).
    See more | Go to post

    Leave a comment:


  • Sets do that
    Code:
    a = set(['a', 'b', 'c'])
    b = set(['c', 'a'])
    print b.issubset(a)
    See more | Go to post

    Leave a comment:


  • If you comment all lines that reference Person.populati on in __del__, it works also, at least as much as I have played with it....
    See more | Go to post

    Leave a comment:


  • It has to do with the __del__ function trying to print Person.populati on after it has been garbage collected. I do not know why this is, but perhaps has to do with reducing the counter in __del__ (as the class is destroyed) when the program exits.

    Edit: If you remove the class instances yourself, then it runs correctly
    Code:
        ## add this code at the end
        ## "de-stantiate" (just kidding)
        swaroop = None
    ...
    See more | Go to post

    Leave a comment:


  • woooee
    replied to remove blocks from a text
    Read the file one record at a time as you would normally do. When you reach a "Description=st ring:" record, append each record to a list until the next "Description=st ring:" record is found. if you want to retain the records in the list, copy them to a file or whatever, then empty the list, rinse and repeat.
    See more | Go to post

    Leave a comment:


  • Antiword will convert to a text file (I'm assuming that is latin-1). It is available for most operating systems. Don't know which OS you are using, so can't point to the specific page for the OS http://www.winfield.demon.nl/#Windows
    See more | Go to post

    Leave a comment:


  • woooee
    replied to simple question using dictionary...
    You can store a variable in a dictionary
    a=5
    test_dict["a"]=a
    print test_dict["a"] prints 5
    You can instead store the data in the dictionary since test_dict["a"] points to a points to 5, it is just as easy to store the value 5 as test_dict["a"]

    You can also do test_dict[a]=3 and print a, test_dict[a] would print 5 3
    or b = test_dict["a"], print b...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...