Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

help with combining small codes into one big one!

Posted on 2011-03-01
4
Medium Priority
?
475 Views
Last Modified: 2012-06-21
i have three scripts i want to merge them together .. and so far i havent been successful!
import bugdisp
import time

 
for i in range(1, 2):
	bugdisp.sendCommand('savetext c:\hi2393993.txt ' )
	time.sleep(100)

Open in new window

import time
import bugdisp

for i in range(1, 10):
	bugdisp.sendCommand('x A90 1')
	time.sleep(1)

Open in new window

import os


os.system('wbugdisp.exe')
time.sleep(5)

Open in new window

0
Comment
Question by:zoomer003
  • 2
4 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 35009288
I am not a Python expert but this should give you the idea.

You are merging three timer-based loops.  The way to do that is to create a new timer-based loop with the least-common-denominator of the individual timers.  In this case, I made it a one-second loop.  Each time through the loop, each of your actions "checks" to see if it is time for it to execute.  If so, it does.  Then wait a second and check again to see what needs to be done.

import bugdisp
import time
import os

# for 101 seconds, check each second ...

for i in range(0, 100):
	# First time only, start wbugdisp
	if ( i == 0 ): os.system('wbugdisp.exe')

	# First and last time, savetext
	if ( i == 0 ) || ( i == 100 ): bugdisp.sendCommand('savetext c:\hi2393993.txt ' )

	# Every ten seconds, do it
	if ( i < 10 ) == 0: bugdisp.sendCommand('x A90 1')

	# Wait for the next second to tick
	time.sleep(1)

Open in new window

0
 
LVL 6

Expert Comment

by:LeeeRussell
ID: 35009302
What do you want the merged script to do?  I don't think that's obvious from the question you've asked.
0
 
LVL 16

Accepted Solution

by:
sjklein42 earned 2000 total points
ID: 35009374
Sorry, I had a typo in the last test.

import bugdisp
import time
import os

# for 101 seconds, check each second ...

for i in range(0, 100):
	# First time only, start wbugdisp
	if ( i == 0 ): os.system('wbugdisp.exe')

	# First and last time, savetext
	if ( i == 0 ) || ( i == 100 ): bugdisp.sendCommand('savetext c:\hi2393993.txt ' )

	# For the first ten seconds, do this
	if ( i < 10 ): bugdisp.sendCommand('x A90 1')

	# Wait for the next second to tick
	time.sleep(1)

Open in new window

0
 

Author Closing Comment

by:zoomer003
ID: 35018140
Thank you
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Suggested Courses

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question