473,498 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Edit Python code programmatically

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 2137
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********@gmail.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.sourceforge.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
8659
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
2590
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...
2
2209
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...
3
19251
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...
4
7617
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...
1
7273
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...
5
17467
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...
1
6686
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...
0
7126
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
7168
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,...
0
7210
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...
1
6891
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...
0
4595
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...
0
3096
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...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1424
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 ...
0
293
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...

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.