Welcome Guest ( Log In | Register )

Bump Topic Topic Closed RSS Feed

Outline · [ Standard ] · Linear+

 Anyone pro in Python coding here ?

views
     
TSGOPI56
post Jan 3 2017, 04:47 PM, updated 8y ago

Regular
******
Senior Member
1,396 posts

Joined: Dec 2012
Hi All,
I need some help with python coding.
Thank you.
pufferfish
post Jan 3 2017, 04:52 PM

Casual
***
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
TSGOPI56
post Jan 3 2017, 04:53 PM

Regular
******
Senior Member
1,396 posts

Joined: Dec 2012
QUOTE(pufferfish @ Jan 3 2017, 05:52 PM)
can just paste the code here and state your problem as well...not just say you need help
*
Ok,currently do not have access to the codes. Later will post.
dewill
post Jan 4 2017, 12:02 AM

Regular
******
Senior Member
1,716 posts

Joined: Feb 2006


What is ur intention?
TSGOPI56
post Jan 4 2017, 12:05 PM

Regular
******
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)

samgooi4189
post Feb 6 2017, 03:56 PM

Getting Started
**
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.

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)

*
To debug the problem:

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.
thegoz
post Feb 13 2017, 05:53 PM

Getting Started
**
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.

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)

*
You closed your file at
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

narf03
post Feb 14 2017, 02:06 AM

Look at all my stars!!
*******
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.
effytheman
post Feb 17 2017, 11:10 AM

Getting Started
**
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
dewill
post Feb 17 2017, 04:30 PM

Regular
******
Senior Member
1,716 posts

Joined: Feb 2006


good enuf

Topic ClosedOptions
 

Change to:
| Lo-Fi Version
0.0158sec    0.06    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 04:34 AM