Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 29th, 2004, 05:40 PM
bquad20 bquad20 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 13 bquad20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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?

Reply With Quote
  #2  
Old July 29th, 2004, 06:35 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,221 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 22 h 21 m 4 sec
Reputation Power: 263
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

Reply With Quote
  #3  
Old August 2nd, 2004, 12:34 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Converting Values


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT