[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Edit Python code programmatically

Unnamed One

2/9/2008 12:11:00 PM

Guilherme Polo wrote:
> 2008/2/9, Alex <noname9968@gmail.com>:
>
>> 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 are after inspect, it is included with python.
Yes, I forgot to mention - I'm new to Python. I didn't necessary mention
3rd party library. Simply such wasn't mentioned in library review and
tutorials, so I didn't know of it. What's the module's name?
>> 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.
> Generating code like this is always dangerous. Maybe you could
> generate some other kind of file, then use some library or build one,
> to operator over this file.
No, the code by itself is the goal.
1 Answer

Dustan

2/9/2008 12:35:00 PM

0

On Feb 9, 6:10 am, Alex <noname9...@gmail.com> wrote:
> Guilherme Polo wrote:
> > 2008/2/9, Alex <noname9...@gmail.com>:
>
> >> 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 are after inspect, it is included with python.
>
> Yes, I forgot to mention - I'm new to Python. I didn't necessary mention
> 3rd party library. Simply such wasn't mentioned in library review and
> tutorials, so I didn't know of it. What's the module's name?

inspect.

>> 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.
> > Generating code like this is always dangerous. Maybe you could
> > generate some other kind of file, then use some library or build one,
> > to operator over this file.
>
> No, the code by itself is the goal.