User Profile

Collapse

Profile Sidebar

Collapse
bvdet
bvdet
Last Activity: Jun 8 '23, 03:41 PM
Joined: Oct 20 '06
Location: Nashville, TN
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • The integer "050" is in octal notation and represents the decimal integer "40". "080" is invalid because there is no "8" in octal.
    Examples of octal, hexidecimal and binary numeric literals:
    Code:
    >>> 050
    40
    >>> 080
    Traceback (  File "<interactive input>", line 1
        080
          ^
    SyntaxError: invalid token
    >>>
    ...
    See more | Go to post

    Leave a comment:


  • Here is a regex solution:
    Code:
    import re
    
    pattern = re.compile(r"^\D+?_\D+?_(.+?)_")
    
    def sort_on_TS(a, b):
        return cmp(pattern.match(a).group(1), pattern.match(b).group(1))
    
    for item in sorted(file_list, sort_on_TS):
        print item
    This method uses string method split:
    Code:
    def sort_on_TS(a,b):
        return cmp(a.split("_")[2], b.split("_
    ...
    See more | Go to post

    Leave a comment:


  • Here is another possibility:
    Code:
    window.grab_release()
    window.withdraw()
    # do stuff here
    # restore the window
    window.deiconify()
    window.grab_set()
    See more | Go to post

    Leave a comment:


  • bvdet
    replied to Guess my number problem
    You are welcome. Sometimes the obvious solution is the hardest to see.
    See more | Go to post

    Leave a comment:


  • bvdet
    replied to Guess my number problem
    Move your first guess under the while statement. Initialize tries to 0. I modified your code for Python 2.7:
    Code:
    import random
     
    print "Welcome to guess my number game!!!"
    print "Please enter the number between 1 and 100"
     
    number = random.randint(1, 100)
    print number
    max_guess = 5
    tries = 0
     
    while True:
        guess = int(raw_input("Take a guess:
    ...
    See more | Go to post

    Leave a comment:


  • You are iterating over the lines in the file twice. Try eliminating one of them. It is possible OrderedDict may be slower than a for loop. I don't know one way or the other. You can use module timeit to check different methods.
    See more | Go to post

    Leave a comment:


  • No, write to the file outside of the for loop:
    Code:
    outFile.write("\n".join(log))
    inputFile.close()
    outFile.close()
    See more | Go to post

    Leave a comment:


  • The error is self explanatory. Try fixing the indentation error in that file.
    See more | Go to post

    Leave a comment:


  • bvdet
    replied to how to update Label "e1" ?
    One way is to create a StringVar and assign it to the entry field textvariable option. Use the StringVar object's method set to assign a value. Use a lambda in the browse button command assignment so you can pass the StringVar as an argument for reassignment. You should not need a global variable.

    Code:
     
    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    # http://zetcode.com/gui/tkinter/layout/
    # http://docs.activestate.com/komodo/3.5/komodo-doc-guibuilder.html
    ...
    See more | Go to post

    Leave a comment:


  • Try writing to the file one time.
    Code:
    outFile.write("\n".join(log))
    See more | Go to post

    Leave a comment:


  • The interpreter is attempting to execute the except clause because of an error and it is finding a NameError in the except clause. Idetifier "socket" is not defined. Try removing "socket.err or" and run again to see what the error actually is.
    See more | Go to post

    Leave a comment:


  • Use a for loop and conditionally append to a list.
    Code:
    data = """Jan 1 02:32:40 hello welcome to python world
    Jan 1 02:32:40 hello welcome to python world
    Mar 31 23:31:55 learn python
    Mar 31 23:31:55 learn python be smart
    Mar 31 23:31:56 python is good scripting language
    Jan 1 00:00:01 hello welcome to python world
    Jan 1 00:00:02 hello welcome to python world
    Mar 31 23:31:55 learn
    ...
    See more | Go to post

    Leave a comment:


  • bvdet
    replied to Initializing a class in a new class
    Creates an instance of OldClassFile.Ol dClass with all its associated attributes and methods.
    See more | Go to post

    Leave a comment:


  • Built-in funcation eval: Python documentation for eval

    The function could potentially evaluate malicious code, therefore its use if sometimes frowned upon. A regex solution could potentially be a more robust but complicated solution.

    Code:
    >>> import re
    >>> re.compile("[(](\d+, \d+)[)]")
    <_sre.SRE_Pattern object at 0x0000000005C3EA80>
    >>> pattern = re.compile("[(](\d+,
    ...
    See more | Go to post

    Leave a comment:


  • There may be a better way.
    Code:
    >>> my_string = '(1, 2) (3, 4)'
    >>> eval(my_string.replace(") (", "),("))
    ((1, 2), (3, 4))
    >>> a,b = eval(my_string.replace(") (", "),("))
    >>> a
    (1, 2)
    >>> b
    (3, 4)
    >>>
    See more | Go to post

    Leave a comment:


  • You knew the upper and lower values in your original post. How did you know them? If you are dealing with dates and times instead of strictly formatted data, look into using the time and datetime modules. Example of creating a datetime object from the date/time string:
    Code:
    >>> datetime.datetime.strptime("Jun  6 17:58:13", "%b  %d %H:%M:%S")
    datetime.datetime(1900, 6, 6, 17, 58, 13)
    >>>
    From there...
    See more | Go to post

    Leave a comment:


  • To achieve the output you need, use re to determine an integer representing the seconds and compare to the lower and upper boundaries. Here's an example:
    Code:
    import re
    
    data = """Jun  6 17:58:13 other strings
    Jun  6 17:58:13 other strings
    Jun  6 17:58:14 other strings
    Jun  6 17:58:14 other strings
    Jun  6 17:58:15 other strings
    Jun  6 17:58:15 other strings
    Jun  6 17:58:15 other
    ...
    See more | Go to post

    Leave a comment:


  • bvdet
    replied to on click of button open another script
    You could do something like this:
    Code:
    import Tkinter
     
    top = Tkinter.Tk()
     
    def FstartCallBack():
        top.grab_release()
        top.withdraw()
        # run your script here
        B.pack_forget()
        L = Tkinter.Label(top, text="Activated")
        L.pack()
        top.title("Action Complete")
        top.minsize(width=250, height=20)
        top.wm_deiconify()
    ...
    See more | Go to post

    Leave a comment:


  • bvdet
    replied to Ways of Sorting 2D lists in Python
    In your original post, you stated you wanted to display the highest score.

    enumerate is a built-in function. i and item are identifiers of the values returned by enumerate. From Python help:
    "enumerate(sequ ence[, start=0])
    Return an enumerate object. sequence must be a sequence, an iterator, or some other object which supports iteration. The next() method of the iterator returned by enumerate() returns a tuple containing
    ...
    See more | Go to post

    Leave a comment:


  • bvdet
    replied to Ways of Sorting 2D lists in Python
    Is this what you want to do?
    Code:
    >>> results = [["Ben", 15, 18,25, 6, 9], ["George", 25, 35, 85, 12, 9], ["Evie", 2, 54, 84, 62,18]]
    >>> for i, item in enumerate(results):
    ... 	results[i] = [item[0], max(item[1:])]
    ... 	
    >>> sorted(results)
    [['Ben', 25], ['Evie', 84], ['George', 85]]
    >>>
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...