#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    13
    Rep Power
    0

    Converting Values


    If I have a list like this:
    Code:
    list 1 = [2 12 * * 1 /export/data/rc/jm_wkly_poll.sh]
    Is there way to get the values from that list, meaning 2 - 12 - * - * - 1?

    I am building this list from a file using a readline() in a while statement. I want to grab each one/value in the list and convert it to something different, being 2 is equal to 2 minutes past the hour, * is equal to all, etc.

    I do NOT want to break the list up like this (comma seperated):
    Code:
    list 1 = [2, 12, *, *, 1, /export/data/rc/jm_wkly_poll.sh]
    There is no gurantee on spaces or characters or commas or any value, so I cant key off of that. I need to keep the path to the .sh script in place and all the paths are different, so I cant key off of that either.

    Examle of a full built list:
    ['2 12 * * 1 /export/data/rc/jm_wkly_poll.sh', '0 * * 2 23 /usr/bin/home/$tonk.sh', '0 0 0 * * /export/data/rc/jm_wkly_poll.sh', 2 12 1,15 * * /export/data/curr_items.sh']

    Any ideas?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    From your example and description I would say that the fields are separated by spaces, so you can use the string split() method.

    Code:
    >>> s = '0 0 1,15 * 1 $HOME/usr/bin/o9/recrdCrron.sh'
    >>> s.split()
    ['0', '0', '1,15', '*', '1', '$HOME/usr/bin/o9/recrdCrron.sh']
    >>> s = '2 12 * * 1 /export/data/rc/jm_wkly_poll.sh'
    >>> s.split()
    ['2', '12', '*', '*', '1', '/export/data/rc/jm_wkly_poll.sh']
    >>>
    This will convert the string into a list of substrings. You can extract the fields you want, and use int() to convert the substrings to integers (test for '*' before calling int() though, or it will throw an exception).

    Dave - The Developers' Coach




    Dave - The Developers' Coach
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You should probably do a check to see if the string is a digit/number using the isdigit() method. This would be more acurate than looking for a '*' when it comes to the path, since this wont convert to an int() either.

    Or try and convert all the values but the path at the end using list[:-1] and keep checking for that '*' character.

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo