473,624 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Edit Python code programmaticall y

Which library could you recommend to perform simple editing of Python
code (from Python program)? For example, open *.py file, find specific
function definition, add another function call inside, find existing
call and change parameter value, etc.

What I'm trying to implement isn't a real visual programming tool, but
some code-generation is necessary. For now I think I can generate Python
syntax manually (like any text file), but it can become more complicated
in future (like partially implementing code-generation library), plus
there'll always be possibility of corrupting files and losing data (or
having to recover valid Python syntax manually) due to coding mistake.

Thanks

Feb 9 '08 #1
3 2150
On Sat, 09 Feb 2008 14:38:29 +0300, Alex wrote:
Which library could you recommend to perform simple editing of Python
code (from Python program)?
I'm not even sure such a library exists.

For example, open *.py file, find specific
function definition, add another function call inside, find existing
call and change parameter value, etc.
Why do you want to do that? I'm not sure what you're trying to
accomplish. Code refactoring? I imagine that's probably best done with
your text editor: at best, your editor will have dedicated refactoring
tools, and at worst, it will have global search and replace.

--
Steven
Feb 9 '08 #2
Alex <no********@gma il.comwrites:
Which library could you recommend to perform simple editing of
Python code (from Python program)? For example, open *.py file, find
specific function definition, add another function call inside, find
existing call and change parameter value, etc.
You might want to look into the Python refactoring tool "Bicycle
Repair Man" <URL:http://bicyclerepair.s ourceforge.net/>, which
presumably needs to do some of this.

--
\ "I washed a sock. Then I put it in the dryer. When I took it |
`\ out, it was gone." -- Steven Wright |
_o__) |
Ben Finney
Feb 9 '08 #3
Steven D'Aprano wrote:
On Sat, 09 Feb 2008 14:38:29 +0300, Alex wrote:

>Which library could you recommend to perform simple editing of Python
code (from Python program)?

I'm not even sure such a library exists.
Yes they exist, that field is called "code-generation", "generative
programming" etc.
>
>For example, open *.py file, find specific
function definition, add another function call inside, find existing
call and change parameter value, etc.

Why do you want to do that? I'm not sure what you're trying to
accomplish. Code refactoring? I imagine that's probably best done with
your text editor: at best, your editor will have dedicated refactoring
tools, and at worst, it will have global search and replace.
I don't feel like describing all ideas - it's nothing really intersting
anyway, just a learning project (to get to know language features), but
obviously it's not for regular programming - I know text editors can do
that just fine. Simply in some situation I think instead of generating
data I'd better generate some code.
Feb 9 '08 #4

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

Similar topics

1
8669
by: Stewart Armbrecht | last post by:
Does anyone know of an example application that demonstrates how to edit a web.config file programmatically using c#?
2
2604
by: TK | last post by:
What's the best way to edit web.config programmatically? I want to have an aspx page as a GUI for web admins to modify the roll-base security portion of the web.config(s) on a server. please help. TK
2
2214
by: jjack100 | last post by:
In asp.net 2.0 you can apply custom themes based on a user profile, etc. And you can change the theme programmatically, etc. But how do you edit or create a theme programmatically? I am working on a content management system where the user needs to be able to select fonts, colors, etc. Right now I can only see how to let the user select from a pre-defined set of themes. In the old days, you could generate the css file from user input...
3
19259
by: misiek | last post by:
Hi all. I have following problem: 1. In my web page I have a GridView control, which does not have a DataSourceId set in designer. 2. When user presses Start button then I create programatically a dataSet, set it as a DataSource for my GridView an add it to Session. 3. I want my users to be able to edit data displayed in GridView, so I added Edit command column. 4. When user clicks Edit, then I get the following error: "The GridView
4
7625
by: Peter | last post by:
(VS 2003) I have a DataGrid and accept button. My problem is when a user starts to edit one of the values in the grid and does not either press Enter or move of the current cell and presses the Accept buton the current typed value does not get passed into the grid, but stays in the edit mode. How can I move the current edit value into the grid without requireing user to press Enter or move to a different cell? Thanks
1
7291
by: Mark Stafford | last post by:
I am attempting to use a DetailsView control to view some data where the fields returned by the database are determined at runtime. I create the TemplateFields on the fly using a class that implements ITemplate and repopulate the Template properters of TemplateField in OnInit. And I am DataBinding by getting a DataTable from my db provider class in Page_Load event. When I databind programmatically in the Page_Load, the data displays in...
5
17505
by: kageyone | last post by:
I am trying to use the .net 2.0 gridview control where I programmatically set the datasource to an xml file read into a dataset. I am able to use the commandfield for the edit button and it puts me in edit mode. I have a template field with an EditItemTemplate textbox. I change the text in this textbox and click the update button. The RowUpdating event fires and my handler takes over. When I try to get the changed text in that textbox, I...
1
6731
by: rogerford | last post by:
I have a grid which i bind with values from Database. I have events to edit and update the grid. I am not using SqlDatasource to connect to DB. Rather i am doing the updating of the grid Programmatically. I have 3 columns, LID(item template column) ,LVal (Edit Item template column) and Edit link My Question: 1) My EditITemTemplate column has a textbox txt_Lval which does not show up on the page load. But if click on edit link that...
0
8233
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
8675
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
8619
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
8474
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
7158
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...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
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
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.