473,387 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

run another *.py under a python script

Hope someone can help me, I would like to run another *.py
"test.py" under this def here
Expand|Select|Wrap|Line Numbers
  1. def access_denied(serial_com):
  2.     # This is called when a tag has been scanned and denied
  3.     # Write your own logic here to do more on the computer
  4. LIKE RIGHT HERE
  5.     say('Access Denied')
  6.     # Send the letter D for deny
  7.     serial_com.write('D')
  8.     print 'Tag access denied.'
  9.  
Oct 13 '10 #1
3 1628
dwblas
626 Expert 512MB
You would use "import" to use the methods of test.py in your current script. Effbot's writeup of import and an example of using import. Note that the directory must be in sys.path so you may have to add the directory containing the program to sys.path first.
Oct 13 '10 #2
I am really a noob at this :(
I can't get it work,, this code I am trying to run inside the main code is this:
Expand|Select|Wrap|Line Numbers
  1. #test.py############
  2. import prowlpy
  3.  
  4. apikey = 'xxxxxxxxxxxxxxxxxxx' #Dummy API-key)
  5. p = prowlpy.Prowl(apikey)
  6. try:
  7.     p.add('CatConnect','Cat Outside Door',"!!!!!!!!!!!!")
  8.  
  9. except Exception,msg:
  10.     print msg
  11. #test.py###############################
  12.  
  13. but i really dont get it how i Run that test.py under the man code:
  14.  
  15. ####MAIN.PY##############
  16. #!/usr/bin/env python
  17.  
  18. import sys
  19. import os
  20. import sqlite3
  21. import serial
  22. import subprocess
  23. import test
  24. # Change this to the port displayed in your Arduino IDE
  25. # It will be com3 or something for Windows...
  26. serial_port = 'com3'
  27. baud_rate = 9600
  28.  
  29. # Define the db path to ./rfids.db, relative to this file
  30. sql_file = os.path.join(os.path.dirname(__file__), 'tags.db')
  31. needs_creation = not os.path.exists(sql_file)
  32. db_connection = sqlite3.connect(sql_file)
  33. db_connection.row_factory = sqlite3.Row
  34.  
  35. if needs_creation:
  36.     print 'Creating initial database...'
  37.     cursor = db_connection.cursor()
  38.     cursor.execute("CREATE TABLE rfid_tags (tag_id text, is_enabled integer)")
  39.     db_connection.commit()
  40.     print 'Database created.'
  41.  
  42. def access_denied(serial_com):
  43.     # This is called when a tag has been scanned and denied
  44.     # Write your own logic here to do more on the computer
  45.  
  46. #right here I would like to run the code
  47.  
  48.     say('Cat Tag')
  49.     # Send the letter D for deny
  50.     serial_com.write('D')
  51.  
  52. ################################
Oct 14 '10 #3
got it to work :) a little messy code but works! thx
Oct 14 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Andrew Chalk | last post by:
Is this possible? In my CGI app. I display a web page with a link (anchor). When the link is clicked I want to exectute a python script rather than go to an HTML page. Many thanks.
11
by: PatPoul | last post by:
I want to do the same thing as <script language="javascript" src="xxx.js"></script> but with a python script : <script language="Python" src="xxx.py"></script> ...
6
by: tatamata | last post by:
Hello. How can I run some Python script within C# program? Thanks, Zlatko
7
by: hlubenow | last post by:
Hi, recently there was a thread about hiding the python-script from the user. The OP could use http://freshmeat.net/projects/pyobfuscate/ H.
1
by: michael.buonomo | last post by:
We have been using the Google recommended python script for about a year. We recently realized that the script was not crawling our sites url's, but just our folders which reside on the server. The...
3
by: telduivel | last post by:
Can someone please help me with this: I have a python script, that at some point calls a linux bash script (.sh). Starting the shell script is the last thing my python script needs to do, so I...
4
by: Quill_Patricia | last post by:
I have a Python script which is used to load data into a database. Up to now this script has been run by customers from the Windows command prompt using "python edg_loader.pyc". Any error messages...
0
by: norseman | last post by:
Gros Bedo wrote: ============================== Yes. man ps explains try ps -AFL | grep then kill -9 found (check it more than twice) 1) If your script is known to hang use what...
1
by: replysonika | last post by:
Hello, I run a Java app with subprocess from Python script. This python script is called from another Python Wrapper. python = subprocess.Popen(, stdout=subprocess.PIPE,...
2
by: gintrado | last post by:
I am very new to Python I'm trying to run a python script from within another python script. I can run the script from a unix command line by typing: nohup python script.py password >...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.