Hi All,
I need some help with python coding.
Thank you.
Anyone pro in Python coding here ?
Anyone pro in Python coding here ?
|
Jan 3 2017, 04:47 PM, updated 8y ago
Show posts by this member only | Post
#1
|
Senior Member
1,396 posts Joined: Dec 2012 |
Hi All,
I need some help with python coding. Thank you. |
|
|
|
Jan 3 2017, 04:52 PM
Show posts by this member only | Post
#2
|
Junior Member
430 posts Joined: Oct 2005 |
can just paste the code here and state your problem as well...not just say you need help
|
|
Jan 3 2017, 04:53 PM
Show posts by this member only | Post
#3
|
Senior Member
1,396 posts Joined: Dec 2012 |
|
|
Jan 4 2017, 12:02 AM
Show posts by this member only | Post
#4
|
Senior Member
1,716 posts Joined: Feb 2006 |
What is ur intention?
|
|
Jan 4 2017, 12:05 PM
Show posts by this member only | Post
#5
|
Senior Member
1,396 posts Joined: Dec 2012 |
Below i have attached the python code which i am having problem. The python program reads status_mjpeg.txt file and executes another python script. My problem is, when the python script reaches this line " os.system(' /usr/bin/python PIRoncall.py') " and executes PIRoncall.py, the python script stops reading status_mjpeg.txt file.
CODE import time import subprocess import os while True: fh=open("status_mjpeg.txt","r") line = fh.read(5) print line fh.close() if line == "md_re": print "on" os.system(' /usr/bin/python PIRoncall.py') time.sleep (2) elif line == "ready": print "on" os.system(' /usr/bin/python PIRoffcall.py') time.sleep(2) |
|
Feb 6 2017, 03:56 PM
Show posts by this member only | IPv6 | Post
#6
|
Junior Member
59 posts Joined: Apr 2008 |
QUOTE(GOPI56 @ Jan 4 2017, 12:05 PM) Below i have attached the python code which i am having problem. The python program reads status_mjpeg.txt file and executes another python script. My problem is, when the python script reaches this line " os.system(' /usr/bin/python PIRoncall.py') " and executes PIRoncall.py, the python script stops reading status_mjpeg.txt file. To debug the problem:CODE import time import subprocess import os while True: fh=open("status_mjpeg.txt","r") line = fh.read(5) print line fh.close() if line == "md_re": print "on" os.system(' /usr/bin/python PIRoncall.py') time.sleep (2) elif line == "ready": print "on" os.system(' /usr/bin/python PIRoffcall.py') time.sleep(2) 1. You need to understand what is os.system() from https://docs.python.org/2/library/os.html assuming you are using python 2. 2. Next you need to know what happen when executing PIRoncall.py. You can try to run the command manually in ipython. >> os.system(' /usr/bin/python PIRoncall.py') Hope this can assist you in troubleshooting your issue. |
|
Feb 13 2017, 05:53 PM
Show posts by this member only | Post
#7
|
Junior Member
54 posts Joined: Nov 2004 From: Penang!!! |
QUOTE(GOPI56 @ Jan 4 2017, 12:05 PM) Below i have attached the python code which i am having problem. The python program reads status_mjpeg.txt file and executes another python script. My problem is, when the python script reaches this line " os.system(' /usr/bin/python PIRoncall.py') " and executes PIRoncall.py, the python script stops reading status_mjpeg.txt file. You closed your file atCODE import time import subprocess import os while True: fh=open("status_mjpeg.txt","r") line = fh.read(5) print line fh.close() if line == "md_re": print "on" os.system(' /usr/bin/python PIRoncall.py') time.sleep (2) elif line == "ready": print "on" os.system(' /usr/bin/python PIRoffcall.py') time.sleep(2) CODE fh.close() At that point you stop reading status_mjpeg.txt. And your code looks weird. Why are you launching a new Python script within a Python script? You can import it as a module with: CODE import PIRoncall Hope that helps |
|
Feb 14 2017, 02:06 AM
Show posts by this member only | Post
#8
|
Senior Member
4,544 posts Joined: Dec 2004 From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol |
I think TS already solved his problem months ago, he created multiple threads.
|
|
Feb 17 2017, 11:10 AM
Show posts by this member only | Post
#9
|
Junior Member
79 posts Joined: Apr 2012 |
Hi Guys,
Need your suggestion on how to shorten my code. print "Enter 10 numbers and I'll tell you if it's ODD or EVEN." def odd_or_even(n): if 0 == input % 2: odd_even = "EVEN" else: odd_even = "ODD" return odd_even def ordinal(n): if n % 10 == 1: suffix = "st" elif n % 10 == 2: suffix = "nd" elif n % 10 == 3: suffix = "rd" elif n % 10 == 0 or n % 10 >= 4: suffix = "th" return str(n) + suffix count = 1 while count < 11: input = raw_input("What is your " + ordinal(count) + " number? ") try: input = int(input) except ValueError: print "Please enter an integer." continue print "Your %s number is %s" % (ordinal(count), odd_or_even(input)) count += 1 |
|
Feb 17 2017, 04:30 PM
|
Senior Member
1,716 posts Joined: Feb 2006 |
good enuf
|
Topic ClosedOptions
|
Change to: | 0.0158sec
0.06
5 queries
GZIP Disabled
Time is now: 29th March 2024 - 04:34 AM |