100+
P: 440
|
HI,
I have a Samplescript.When I run this Script,it should pop up message saying that whether to run Batch or Interactive
I/P:
SampleScript.py or SampleScript.pyc
>>> SampleScript.py --> Run the script from the prompt
>>> 'Message-Do you want to run as Interactive' --> Program will prompt the message
>>> Yes ---> ( user will type 'Yes' or 'No')
>>> SampleData.txt ---> ( Text file is given as a input)
Application start running
(or )
>>> No
Graphical user interface is pop up
User will input the data
Application start running
Could anybody hlep me in providing the sample code for this
Thanks
PSB
| |
Share this Question
100+
P: 440
|
How to get the inputs from the prompt?
Like filename or any flags
-PSB
| | Expert 5K+
P: 6,596
|
How to get the inputs from the prompt?
Like filename or any flags
-PSB
I don't think that there is a built-in way to "pop up" the standard python shell. Many good toolkits (like wxPython) have shell re-direction in a window that can be controled by the app. In either case: - usersChoice = raw_input("Please enter your choice: ")
prints a prompt and waits for charaters from the user followed be the return key. At which point it returns a string.
| | 100+
P: 440
|
I don't think that there is a built-in way to "pop up" the standard python shell. Many good toolkits (like wxPython) have shell re-direction in a window that can be controled by the app. In either case: - usersChoice = raw_input("Please enter your choice: ")
prints a prompt and waits for charaters from the user followed be the return key. At which point it returns a string.
So we cannot type from the command line argumnets as mentioned below
Say
C:> SampleScript.py
C:> Yes
c:> SampleInput.txt
Similarly in UNIX
/usr/test/> SampleScript.py
/usr/test/> Yes
/usr/test/>SampleInput.txt
Thanks
PSB
| | Expert 5K+
P: 6,596
|
So we cannot type from the command line argumnets as mentioned below
Say
C:> SampleScript.py
C:> Yes
c:> SampleInput.txt
Similarly in UNIX
/usr/test/> SampleScript.py
/usr/test/> Yes
/usr/test/>SampleInput.txt
Thanks
PSB
Oh, but you can. - print "Starting application"
-
usersChoice = ""
-
while usersChoice.lower() not in ("yes", "no"):
-
usersChoice = raw_input("Is your choice 'yes' or 'no'?")
-
-
print usersChoice
-
D:\My Documents\Python\TheScripts examples>test21.py
Starting application
Is your choice 'yes' or 'no'?help
Is your choice 'yes' or 'no'?no
no
D:\My Documents\Python\TheScripts examples>
| | Expert 5K+
P: 6,596
|
Oh, but you can. - print "Starting application"
-
usersChoice = ""
-
while usersChoice.lower() not in ("yes", "no"):
-
usersChoice = raw_input("Is your choice 'yes' or 'no'?")
-
-
print usersChoice
-
D:\My Documents\Python\TheScripts examples>test21.py
Starting application
Is your choice 'yes' or 'no'?help
Is your choice 'yes' or 'no'?no
no
D:\My Documents\Python\TheScripts examples>
Or better, still: - print "Starting application"
-
usersChoice = ""
-
while usersChoice not in ("y", "n"):
-
usersChoice = raw_input("Is your choice 'yes' or 'no'? ")[0:1].lower() # slice prevents index errors
-
print repr(usersChoice)
-
if usersChoice == 'y':
-
print "The reply was affirmative"
-
D:\My Documents\Python\TheScripts examples>test21.py
Starting application
Is your choice 'yes' or 'no'? Yelp
'y'
The reply was affirmative
D:\My Documents\Python\TheScripts examples>
| | 100+
P: 440
|
Oh, but you can. - print "Starting application"
-
usersChoice = ""
-
while usersChoice.lower() not in ("yes", "no"):
-
usersChoice = raw_input("Is your choice 'yes' or 'no'?")
-
-
print usersChoice
-
D:\My Documents\Python\TheScripts examples>test21.py
Starting application
Is your choice 'yes' or 'no'?help
Is your choice 'yes' or 'no'?no
no
D:\My Documents\Python\TheScripts examples>
I hope this will work in UNIX & Windows OS without Tkinter module installed
| | Expert 5K+
P: 6,596
|
I hope this will work in UNIX & Windows OS without Tkinter module installed
Of course it will; it's pure python. Notice that there are no import statements.
| | 100+
P: 440
|
I am looking for the input file to be taken from the cmd line as shown below
Sample.py
----------------
After creating a 'Exe' of an application.I will run the application thru command prompt.The exe has to take the input data from the command prompt (i.e sample.txt)
C:\> Sample.exe sample.txt
And the application will start processing
(or )
From 'pyc'
C:\> Sample.pyc sample.txt
(or)
C:\> Sample.py sample.txt
This can be do able in shell scripting
Has anybody tried on this in Python.So that I would like to know ,how it can be implemented in Python.
Thanks
PSB
| | 100+
P: 440
|
Help!!!
Any solution for this requirement .
-PSB
| | Expert 5K+
P: 6,596
|
I am looking for the input file to be taken from the cmd line as shown below
Sample.py
----------------
After creating a 'Exe' of an application.I will run the application thru command prompt.The exe has to take the input data from the command prompt (i.e sample.txt)
C:\> Sample.exe sample.txt
And the application will start processing
(or )
From 'pyc'
C:\> Sample.pyc sample.txt
(or)
C:\> Sample.py sample.txt
This can be do able in shell scripting
Has anybody tried on this in Python.So that I would like to know ,how it can be implemented in Python.
Thanks
PSB
- import sys
-
-
print "starting module"
-
print sys.argv
-
print "ending module"
-
And the command line and output:
D:\My Documents\Python\TheScripts examples>module1.py hello world
starting module
['D:\\My Documents\\Python\\TheScripts examples\\module1.py', 'hello', 'world']
ending module
| | Expert 5K+
P: 6,596
| - import sys
-
-
print "starting module"
-
print sys.argv
-
print "ending module"
-
And the command line and output:
D:\My Documents\Python\TheScripts examples>module1.py hello world
starting module
['D:\\My Documents\\Python\\TheScripts examples\\module1.py', 'hello', 'world']
ending module
Of course, for this to work with .exe the program will need to be in the PATH environment variable (just like python is in the PATH).
| | 100+
P: 440
|
Of course, for this to work with .exe the program will need to be in the PATH environment variable (just like python is in the PATH).
Thanks Barton,
Here is the sample code. - Main.py
-
#command line arguments
-
# This is only smaple, validation of data has to be performed
-
import sys
-
-
from Batch import Batch
-
from Interactive import Interactive
-
-
#arguments
-
if len(sys.argv)== 1:
-
print 'Interactive'
-
objInteractive = Interactive()
-
objInteractive.call_interactive()
-
elif len(sys.argv)== 2:
-
print 'Batch'
-
option = sys.argv[1]
-
strInputFileData = option
-
objBatch = Batch()
-
objBatch.call_batch(strInputFileData)
-
- Batch.py
-
-
class Batch:
-
def call_batch(self,strFileName):
-
print ' Iam in batch'
-
print strFileName
-
-
- Interactive.py
-
-
from Tkinter import Tk, Label
-
from tkFileDialog import askopenfilename
-
from SimpleDialog import SimpleDialog
-
-
class Interactive:
-
def call_interactive(self):
-
root=Tk()
-
l = Label(root, text="Starting Application")
-
l.pack()
-
l.config(text="Running Full GUI")
-
root.mainloop()
-
C:>Mainpy
Interactive
C:>Mainpy C:Sample.txt
Batch
Thanks
PSB
| | Expert 5K+
P: 6,596
|
Of course, for this to work with .exe the program will need to be in the PATH environment variable (just like python is in the PATH).
I guess that you got in so deep with all that Tkinter stuff, you missed a lot of the basics.
| | 100+
P: 440
|
I guess that you got in so deep with all that Tkinter stuff, you missed a lot of the basics.
Amazing!!!.
Without the application in the PATH ,it is working fine for me.I dont know,How it is working?.
I will try to investigate on this.
| | Expert 5K+
P: 6,596
|
Amazing!!!.
Without the application in the PATH ,it is working fine for me.I dont know,How it is working?.
I will try to investigate on this.
Perhaps the command-line points to the directory of the .exe. That would do it. But that is not likely to be the case in "the real world".
| | 100+
P: 440
|
The batch and interactive execution of the application on DOS prompt is not working consistantly.Some times it work and other times it will not work.It looks like the program thread is stopping to execute the application to run next time.
How to kill the application thread which is running already or How to identify the application is running or not?.
-PSB
| | Expert 5K+
P: 6,596
|
The batch and interactive execution of the application on DOS prompt is not working consistantly.Some times it work and other times it will not work.It looks like the program thread is stopping to execute the application to run next time.
How to kill the application thread which is running already or How to identify the application is running or not?.
-PSB
I have posted an example class with very strick thread controls include - self.workThread.isAlive()
here.
| | | | Question stats - viewed: 2652
- replies: 17
- date asked: May 21 '07
|