473,772 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extending Python questions

Hi,
I am relative new to Python. Please tell me if the following is
possible.
I have a command line shell written in C. This shell executes some
commands which I would like to import to the python shell.
Here is an example command from my shell:

openconnection www.yahoo.com 12 2000

So I've created a dll (myshell_d.dll) according to the manual
("Extending Python with C or C++") and it works. The problem is the
syntax I have to use now is

myshell.opencon nection('www.ya hoo.com',12,200 0)

It's not only the problem of comfort - it's a problem of changing
*some* scripts. And there's more than that - my shell functions
already know how to handle it's arguments (which's number may vary),
it doesn't need python to do that. All it needs is a pointer to a
string representing the arguments (in our case "www.yahoo. com 12
2000"). I've tried using PyArg_UnpackTup le but without success.

So I have two questions:
1. Is it possible to move the calls to a upper level (i.e. call
"openconnection " and not "myshell.openco nnection") ?
2. Is is possible to remove the brackets and commas? (i.e.
"www.yahoo. com 12 2000" instead of ('www.yahoo.com ',12,2000)?

My final goal is to use the original commands if possible.
thanks in advance,
Eli
Jul 18 '05 #1
3 1301
> myshell.opencon nection('www.ya hoo.com',12,200 0)

It's not only the problem of comfort - it's a problem of changing
*some* scripts. And there's more than that - my shell functions
already know how to handle it's arguments (which's number may vary),
it doesn't need python to do that. All it needs is a pointer to a
string representing the arguments (in our case "www.yahoo. com 12
2000"). I've tried using PyArg_UnpackTup le but without success.
Then don't specify the arguments separately, but instead make it one string
argument, and pass it to your command:

myshell.opencon nection('www.ya hoo.com 12 2000')

So I have two questions:
1. Is it possible to move the calls to a upper level (i.e. call
"openconnection " and not "myshell.openco nnection") ?
from myshell import *
2. Is is possible to remove the brackets and commas? (i.e.
"www.yahoo. com 12 2000" instead of ('www.yahoo.com ',12,2000)?
No. Thats too much of tinkering with pythons parser - you'd render all other
python sources useless, which I suspect outnumber your scripts by a degree
or two... :)
final goal is to use the original commands if possible.
thanks in advance,


What do you use python for in the first place, if you want to keep
everything as it is?

What you can do is to read your scripts _using_ python instead of _passing_
them to python - then you can control the syntax of your scripting
language. The main loop could look like this:

import myshell
for line in sys.stdin.readl ines():
command, rest = line.split()[0], " ".join(line.spl it()[1:])
getattr(myshell , command)(rest)
--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
"Diez B. Roggisch" <de*********@we b.de> wrote in message news:<cm******* ******@news.t-online.com>...
myshell.opencon nection('www.ya hoo.com',12,200 0)

It's not only the problem of comfort - it's a problem of changing
*some* scripts. And there's more than that - my shell functions
already know how to handle it's arguments (which's number may vary),
it doesn't need python to do that. All it needs is a pointer to a
string representing the arguments (in our case "www.yahoo. com 12
2000"). I've tried using PyArg_UnpackTup le but without success.


Then don't specify the arguments separately, but instead make it one string
argument, and pass it to your command:

myshell.opencon nection('www.ya hoo.com 12 2000')

So I have two questions:
1. Is it possible to move the calls to a upper level (i.e. call
"openconnection " and not "myshell.openco nnection") ?


from myshell import *
2. Is is possible to remove the brackets and commas? (i.e.
"www.yahoo. com 12 2000" instead of ('www.yahoo.com ',12,2000)?


No. Thats too much of tinkering with pythons parser - you'd render all other
python sources useless, which I suspect outnumber your scripts by a degree
or two... :)
final goal is to use the original commands if possible.
thanks in advance,


What do you use python for in the first place, if you want to keep
everything as it is?

What you can do is to read your scripts _using_ python instead of _passing_
them to python - then you can control the syntax of your scripting
language. The main loop could look like this:

import myshell
for line in sys.stdin.readl ines():
command, rest = line.split()[0], " ".join(line.spl it()[1:])
getattr(myshell , command)(rest)

Thanks for the reply. I'll try those.
The reason I'm trying it this way is that a user can add python code
inside the scripts.

Eli
Jul 18 '05 #3
>
Thanks for the reply. I'll try those.
The reason I'm trying it this way is that a user can add python code
inside the scripts.


Sorry to say that, but then you'll have to either write a real parser that
understands both syntaxes - and I bet thats more effort as converting your
existing scripts.

You can't have your cake and eat it - if you want python, you should use its
syntax.
--
Regards,

Diez B. Roggisch
Jul 18 '05 #4

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

Similar topics

4
2789
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been working with Python for a year or more now, but only doing simple extending in C/C++. I'm now attempting some embedding and several questions have come to mind. BTW - I'm running Windows 2000 with Python23 and VisualC++ developers
0
1739
by: Hugh Macdonald | last post by:
I've got a slight problem... and I'm stuck as to where to go with it... I'm running on Redhat7.2, using Python 2.2.2 I've got a compiled module that I wrote almost a year ago - it works fine, and I've never had any problems with it... I also did an extension to a plugin (Shake) using Python, so the plugin loads a python module and calls various functions in there.... all in all, fine - I thought I had my head around the system, and...
3
2052
by: Marco Meoni | last post by:
Hi all! I've a problem with a C++ class that has to be included in a python application. One way to do it is Extending and Embedding the Python Interpreter Now i have 2 questions 1) Is there a one-file version of this tutorial? 2) Is there anyone that can help me with this problem? The class is attached. Thanks all. Marco
5
3832
by: vbgunz | last post by:
Hello everyone. I own two books. Learning Python and Python in a nutshell. When cross referencing the two books to try and clarify the ideas behind extending methods and delegates, this is where confusion veered it's ugly head :( Learning Python explains on page 324: Class Interface Techniques (21.3.3 in the ebook) the following is an extender method. ''' #################################### '''
3
1365
by: Redefined Horizons | last post by:
I've got a third-part application that exposes a C API. I'd like to wrap it in Python. Is there a specific forum that covers extending and embedding Python, or are those type of questions O.K. on this list? Scott Huey
3
1806
by: Redefined Horizons | last post by:
I'm trying to understand the argument flags that are used in the method table of an extension module written in C. First let me ask this question about the method table. Is it an C array named "PyMethodDef"? Now, onto my questions about the arguments: I see that even when the Python function we are supplying takes no arguments, (the argument flag is METH_NOARGS), that we still pass the
6
3008
by: Qun Cao | last post by:
Hi Everyone, I am a beginner on cross language development. My problem at hand is to build a python interface for a C++ application built on top of a 3D game engine. The purpose of this python interface is providing a convenient scripting toolkit for the application. One example is that a user can write a python script like: player = Player() game.loadPlayer(player) player.moveTo(location)
3
2686
by: dmoore | last post by:
Hi Folks: I have a question about the use of static members in Python/C extensions. Take the simple example from the "Extending and Embedding the Python Interpreter" docs: A simple module method: static PyObject * spam_system(PyObject *self, PyObject *args)
0
2115
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via callback.setHandler1(callback1) this only seems to affect pythons ability to trigger an "event" in c. PyObject *Handler is always NULL even after I call Register_Handler(...). I thought there was some magic here that was assigning the pointer *Handler to my python...
0
9619
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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
10103
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...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
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...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
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
6713
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();...
3
2850
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.