|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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 |
|
#3
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Converting Values |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|