473,811 Members | 3,467 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A command in a String ?

I have a rather odd question:

Is there a way Python can execute a command within a string ?

For example if I had something like:
_str = "fm=OptionMenu( root,xx,'string 1','string2','s tring3')"

And the execute _str.

The reason why I am trying to do this that as I am aware the OptionMenu
hasn't the ability insert options therefore the options would be inserted
by manipulating strings.

Pete

Jul 18 '05 #1
6 1568
Peter Moscatt wrote:
I have a rather odd question:

Is there a way Python can execute a command within a string ?

For example if I had something like:
_str = "fm=OptionMenu( root,xx,'string 1','string2','s tring3')"

And the execute _str.
exec _str
The reason why I am trying to do this that as I am aware the OptionMenu
hasn't the ability insert options therefore the options would be inserted
by manipulating strings.


does this do what you want?

strings = "string1", "string2", "string3"
fm = OptionMenu(root , xx, *strings)

</F>

Jul 18 '05 #2
Peter Moscatt wrote:
I have a rather odd question:

Is there a way Python can execute a command within a string ?

For example if I had something like:
_str = "fm=OptionMenu( root,xx,'string 1','string2','s tring3')"

And the execute _str.

The reason why I am trying to do this that as I am aware the OptionMenu
hasn't the ability insert options therefore the options would be inserted
by manipulating strings.

Pete


Look into the "eval" operation ...

--
----------------------------------------------------------------------------
Tim Daneliuk tu****@tundrawa re.com
PGP Key: http://www.tundraware.com/PGP/
Jul 18 '05 #3
</F>,

Thanks for the help on this. Yea the 'exec' did the trick.
The second example just placed all the strings in one option button.

Pete

On Wed, 13 Apr 2005 10:34:20 +0200, Fredrik Lundh wrote:
Peter Moscatt wrote:
I have a rather odd question:

Is there a way Python can execute a command within a string ?

For example if I had something like:
_str = "fm=OptionMenu( root,xx,'string 1','string2','s tring3')"

And the execute _str.


exec _str
The reason why I am trying to do this that as I am aware the OptionMenu
hasn't the ability insert options therefore the options would be inserted
by manipulating strings.


does this do what you want?

strings = "string1", "string2", "string3"
fm = OptionMenu(root , xx, *strings)

</F>


Jul 18 '05 #4
Peter Moscatt wrote:
Thanks for the help on this.**Yea*the* 'exec'*did*the* trick.
The second example just placed all the strings in one option button.


Peter, you most certainly do *not* need an exec statement. If you take the
time to explain what you want to do (as opposed to how you want to do it) a
bit more exhaustively, perhaps with some context code, the profit will be
all on your side.

Peter

Jul 18 '05 #5
Peter Moscatt wrote:
strings = "string1", "string2", "string3"
fm = OptionMenu(root , xx, *strings)


Thanks for the help on this. Yea the 'exec' did the trick.
The second example just placed all the strings in one option button.


did you include the asterisk? if you remove that, you get one option. if you
include it, you get three options.

</F>

Jul 18 '05 #6
</F>,

No, I hadn't included the '*' Ya learn something every day.

Pete
On Wed, 13 Apr 2005 11:07:13 +0200, Fredrik Lundh wrote:
Peter Moscatt wrote:
strings = "string1", "string2", "string3"
fm = OptionMenu(root , xx, *strings)


Thanks for the help on this. Yea the 'exec' did the trick.
The second example just placed all the strings in one option button.


did you include the asterisk? if you remove that, you get one option. if you
include it, you get three options.

</F>


Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
9878
by: Bernd Danberg | last post by:
Hi, I have a real strange problem with the command line arguments given to the main-function and together with using std::string: #include <string> int _tmain(int argc, _TCHAR* argv) { std::string str(argv); println(str.c_str());
4
3185
by: lkrubner | last post by:
I'd like to write a PHP script to be used from the command line on a Unix machine. I'd like for the script to put together a string, turn it into a web page, print it, then return control the command line. Obviously it is quite easy to make a string that is valid HTML and send it to the printer. The tough part is making look like a web page. In particular, image tags should print out as images, not image tags. Does anyone have an idea...
5
5834
by: jlea | last post by:
I'm trying to pass a filename, obtained with using the fileName property from the OpenFileDialog, as a application parameter in Process.StartInfo.Arguments and run a MFC/C++ application using the Start method. When I hardcode the application parameter such as "/name=c:\\myFile.txt" all is well in the C++ application. When I use the fileName property to build the parameter, the string becomes @"/name=c:\myFile.txt" which makes the C++...
2
3980
by: paul | last post by:
I have a file type that is going to be associated with my visual basic application and i want the user to be able to double click on a file of said type and have it launch the program and load the file. I know there are certain keys in the registry that i have to create and/or edit. I have located them, namely HKEY_CLASSES_ROOT\.stdf and HKEY_CLASSES_ROOT\stdf_auto_file\shell\open\command The default value for that last key is the path...
7
5225
by: John Wildes | last post by:
Hello All, I've got a VB.net windows form app that I have created to solve some recurring maintenance tasks. What I would like to do is build functionality into this application so that accepts command switches like. C:\FooApp\Foobar.exe /quiet that the application will load and process tasks with no user input, but when C:\FooApp\Foobar.exe is run that it would load my windows form interface. Does that make sense? Can anyone help me...
2
6674
by: micahstrasser | last post by:
I have been trying for days to send a command to the command prompt through the shell() function in vb.net. For some reason it is not working. Here is the code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim command As String command = "systeminfo > C:\temp\sysinfo.txt"
10
6111
by: jimmy | last post by:
Hi again, sorry for posting two questions so close together but im working on a school project which is due in soon and running into some difficulties implementing the database parts. I have the code below which when executed generates the following error message: 'There is already an open datareader with this command which must be closed first' Private Sub MainMenu_Load(ByVal sender As System.Object, ByVal e As
0
1723
by: czerwww | last post by:
Can someone please help me? I have class for database connection and I need set command.commandTimeout. How can I do that? Code: Imports System.Data.SqlClient Imports System.Data Public Class Db Private Shared _ConnString As String = "" Private Shared _Connection As SqlConnection Public Shared Sub SetConnectionString(ByVal connString As String)
3
18722
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however, working with complex reports is tricky Assumption: Reader of this article have basic knowledge of creating data reports. Creating a Parent-Child Command and create a DataReport Suppose we have a database called company with two tables ...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10133
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.