Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20988 > unrolled thread
| Started by | crstop@gmail.com |
|---|---|
| First post | 2012-02-28 09:36 -0800 |
| Last post | 2012-02-28 11:36 -0800 |
| Articles | 9 — 3 participants |
Back to article view | Back to comp.lang.python
Need to write python source with python crstop@gmail.com - 2012-02-28 09:36 -0800
Re: Need to write python source with python Peter Otten <__peter__@web.de> - 2012-02-28 18:56 +0100
Re: Need to write python source with python 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-28 10:09 -0800
Re: Need to write python source with python 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-28 10:09 -0800
Re: Need to write python source with python crstop@gmail.com - 2012-02-28 10:30 -0800
Re: Need to write python source with python crstop@gmail.com - 2012-02-28 10:30 -0800
Re: Need to write python source with python Peter Otten <__peter__@web.de> - 2012-02-28 20:25 +0100
Re: Need to write python source with python crstop@gmail.com - 2012-02-28 11:36 -0800
Re: Need to write python source with python crstop@gmail.com - 2012-02-28 11:36 -0800
| From | crstop@gmail.com |
|---|---|
| Date | 2012-02-28 09:36 -0800 |
| Subject | Need to write python source with python |
| Message-ID | <23135461.7.1330450584442.JavaMail.geo-discussion-forums@pbcrt4> |
Hi All, I'm new to Python but have experience with a few other programming languages(Java, Perl, JavaScript). I'm using Python 2.7.2 and I'm trying to create and write to a file (.py) a python class and functions from python. I will also need to later read and edit the file. I realize I could just write strings using the available string and file writing methods but suspect there is a better way than that. I have read about pickle, ast, and Django; searched this group and the web but haven't found a solution that seems to fit. Any suggestion?
[toc] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2012-02-28 18:56 +0100 |
| Message-ID | <mailman.245.1330451754.3037.python-list@python.org> |
| In reply to | #20988 |
crstop@gmail.com wrote: > I'm new to Python but have experience with a few other programming > languages(Java, Perl, JavaScript). > > I'm using Python 2.7.2 and I'm trying to create and write to a file (.py) > a python class and functions from python. I will also need to later read > and edit the file. I realize I could just write strings using the > available string and file writing methods but suspect there is a better > way than that. > > I have read about pickle, ast, and Django; searched this group and the web > but haven't found a solution that seems to fit. Any suggestion? Due to Python's dynamic nature it is rarely necessary to generate Python code. What are you actually trying to achieve?
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2012-02-28 10:09 -0800 |
| Message-ID | <11747773.3845.1330452590293.JavaMail.geo-discussion-forums@pbeo1> |
| In reply to | #20989 |
在 2012年2月29日星期三UTC+8上午1时56分43秒,Peter Otten写道: > crstop@gmail.com wrote: > > > I'm new to Python but have experience with a few other programming > > languages(Java, Perl, JavaScript). > > > > I'm using Python 2.7.2 and I'm trying to create and write to a file (.py) > > a python class and functions from python. I will also need to later read > > and edit the file. I realize I could just write strings using the > > available string and file writing methods but suspect there is a better > > way than that. > > > > I have read about pickle, ast, and Django; searched this group and the web > > but haven't found a solution that seems to fit. Any suggestion? > > Due to Python's dynamic nature it is rarely necessary to generate Python > code. What are you actually trying to achieve? Check myHDL, and BOA and pythoncard that can translate user messages to pyhton code as delphie.
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2012-02-28 10:09 -0800 |
| Message-ID | <mailman.246.1330452593.3037.python-list@python.org> |
| In reply to | #20989 |
在 2012年2月29日星期三UTC+8上午1时56分43秒,Peter Otten写道: > crstop@gmail.com wrote: > > > I'm new to Python but have experience with a few other programming > > languages(Java, Perl, JavaScript). > > > > I'm using Python 2.7.2 and I'm trying to create and write to a file (.py) > > a python class and functions from python. I will also need to later read > > and edit the file. I realize I could just write strings using the > > available string and file writing methods but suspect there is a better > > way than that. > > > > I have read about pickle, ast, and Django; searched this group and the web > > but haven't found a solution that seems to fit. Any suggestion? > > Due to Python's dynamic nature it is rarely necessary to generate Python > code. What are you actually trying to achieve? Check myHDL, and BOA and pythoncard that can translate user messages to pyhton code as delphie.
[toc] | [prev] | [next] | [standalone]
| From | crstop@gmail.com |
|---|---|
| Date | 2012-02-28 10:30 -0800 |
| Message-ID | <mailman.250.1330453833.3037.python-list@python.org> |
| In reply to | #20989 |
On Tuesday, February 28, 2012 9:56:43 AM UTC-8, Peter Otten wrote:
> crstop@gmail.com wrote:
>
> > I'm new to Python but have experience with a few other programming
> > languages(Java, Perl, JavaScript).
> >
> > I'm using Python 2.7.2 and I'm trying to create and write to a file (.py)
> > a python class and functions from python. I will also need to later read
> > and edit the file. I realize I could just write strings using the
> > available string and file writing methods but suspect there is a better
> > way than that.
> >
> > I have read about pickle, ast, and Django; searched this group and the web
> > but haven't found a solution that seems to fit. Any suggestion?
>
> Due to Python's dynamic nature it is rarely necessary to generate Python
> code. What are you actually trying to achieve?
I'm trying to generate the script file that will launch a PythonCard resource file.
very basic example from the documentation.
#!/usr/bin/python
"""
__version__ = "$Revision: 1.10 $"
__date__ = "$Date: 2004/04/24 22:13:31 $"
"""
from PythonCard import model
class Minimal(model.Background):
pass
if __name__ == '__main__':
app = model.Application(Minimal)
app.MainLoop()
[toc] | [prev] | [next] | [standalone]
| From | crstop@gmail.com |
|---|---|
| Date | 2012-02-28 10:30 -0800 |
| Message-ID | <6137475.17.1330453824069.JavaMail.geo-discussion-forums@pbjl1> |
| In reply to | #20989 |
On Tuesday, February 28, 2012 9:56:43 AM UTC-8, Peter Otten wrote:
> crstop@gmail.com wrote:
>
> > I'm new to Python but have experience with a few other programming
> > languages(Java, Perl, JavaScript).
> >
> > I'm using Python 2.7.2 and I'm trying to create and write to a file (.py)
> > a python class and functions from python. I will also need to later read
> > and edit the file. I realize I could just write strings using the
> > available string and file writing methods but suspect there is a better
> > way than that.
> >
> > I have read about pickle, ast, and Django; searched this group and the web
> > but haven't found a solution that seems to fit. Any suggestion?
>
> Due to Python's dynamic nature it is rarely necessary to generate Python
> code. What are you actually trying to achieve?
I'm trying to generate the script file that will launch a PythonCard resource file.
very basic example from the documentation.
#!/usr/bin/python
"""
__version__ = "$Revision: 1.10 $"
__date__ = "$Date: 2004/04/24 22:13:31 $"
"""
from PythonCard import model
class Minimal(model.Background):
pass
if __name__ == '__main__':
app = model.Application(Minimal)
app.MainLoop()
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2012-02-28 20:25 +0100 |
| Message-ID | <mailman.256.1330457084.3037.python-list@python.org> |
| In reply to | #20996 |
crstop@gmail.com wrote:
> On Tuesday, February 28, 2012 9:56:43 AM UTC-8, Peter Otten wrote:
>> crstop@gmail.com wrote:
>>
>> > I'm new to Python but have experience with a few other programming
>> > languages(Java, Perl, JavaScript).
>> >
>> > I'm using Python 2.7.2 and I'm trying to create and write to a file
>> > (.py) a python class and functions from python. I will also need to
>> > later read and edit the file. I realize I could just write strings
>> > using the available string and file writing methods but suspect there
>> > is a better way than that.
>> >
>> > I have read about pickle, ast, and Django; searched this group and the
>> > web but haven't found a solution that seems to fit. Any suggestion?
>>
>> Due to Python's dynamic nature it is rarely necessary to generate Python
>> code. What are you actually trying to achieve?
>
> I'm trying to generate the script file that will launch a PythonCard
> resource file.
>
> very basic example from the documentation.
>
> #!/usr/bin/python
> """
> __version__ = "$Revision: 1.10 $"
> __date__ = "$Date: 2004/04/24 22:13:31 $"
> """
>
> from PythonCard import model
>
> class Minimal(model.Background):
> pass
>
> if __name__ == '__main__':
> app = model.Application(Minimal)
> app.MainLoop()
If it doesn't get too complex you could start with Python's built-in string
formatting:
import sys
template = '''\
#!/usr/bin/python
from PythonCard import model
class {Class}(model.Background):
pass
if __name__ == '__main__':
app = model.Application({Class})
app.MainLoop()
'''
resourcename, filename = sys.argv[1:]
with open(resourcename, "U") as f:
data = eval(f.read())
with open(filename, "w") as f:
f.write(template.format(Class=data["application"]["name"]))
If you need logic inside the template, here's on overview:
http://wiki.python.org/moin/Templating
So there are rather too many options than too few.
[toc] | [prev] | [next] | [standalone]
| From | crstop@gmail.com |
|---|---|
| Date | 2012-02-28 11:36 -0800 |
| Message-ID | <mailman.258.1330457764.3037.python-list@python.org> |
| In reply to | #21000 |
On Tuesday, February 28, 2012 11:25:33 AM UTC-8, Peter Otten wrote:
> crstop@gmail.com wrote:
>
> > On Tuesday, February 28, 2012 9:56:43 AM UTC-8, Peter Otten wrote:
> >> crstop@gmail.com wrote:
> >>
> >> > I'm new to Python but have experience with a few other programming
> >> > languages(Java, Perl, JavaScript).
> >> >
> >> > I'm using Python 2.7.2 and I'm trying to create and write to a file
> >> > (.py) a python class and functions from python. I will also need to
> >> > later read and edit the file. I realize I could just write strings
> >> > using the available string and file writing methods but suspect there
> >> > is a better way than that.
> >> >
> >> > I have read about pickle, ast, and Django; searched this group and the
> >> > web but haven't found a solution that seems to fit. Any suggestion?
> >>
> >> Due to Python's dynamic nature it is rarely necessary to generate Python
> >> code. What are you actually trying to achieve?
> >
> > I'm trying to generate the script file that will launch a PythonCard
> > resource file.
> >
> > very basic example from the documentation.
> >
> > #!/usr/bin/python
> > """
> > __version__ = "$Revision: 1.10 $"
> > __date__ = "$Date: 2004/04/24 22:13:31 $"
> > """
> >
> > from PythonCard import model
> >
> > class Minimal(model.Background):
> > pass
> >
> > if __name__ == '__main__':
> > app = model.Application(Minimal)
> > app.MainLoop()
>
> If it doesn't get too complex you could start with Python's built-in string
> formatting:
>
> import sys
>
> template = '''\
> #!/usr/bin/python
> from PythonCard import model
>
> class {Class}(model.Background):
> pass
>
> if __name__ == '__main__':
> app = model.Application({Class})
> app.MainLoop()
> '''
>
> resourcename, filename = sys.argv[1:]
>
> with open(resourcename, "U") as f:
> data = eval(f.read())
>
> with open(filename, "w") as f:
> f.write(template.format(Class=data["application"]["name"]))
>
> If you need logic inside the template, here's on overview:
>
> http://wiki.python.org/moin/Templating
>
> So there are rather too many options than too few.
It shouldn't get very complicated so I look through those options.
Thanks to all posters
[toc] | [prev] | [next] | [standalone]
| From | crstop@gmail.com |
|---|---|
| Date | 2012-02-28 11:36 -0800 |
| Message-ID | <4382344.985.1330457760893.JavaMail.geo-discussion-forums@pbbpk4> |
| In reply to | #21000 |
On Tuesday, February 28, 2012 11:25:33 AM UTC-8, Peter Otten wrote:
> crstop@gmail.com wrote:
>
> > On Tuesday, February 28, 2012 9:56:43 AM UTC-8, Peter Otten wrote:
> >> crstop@gmail.com wrote:
> >>
> >> > I'm new to Python but have experience with a few other programming
> >> > languages(Java, Perl, JavaScript).
> >> >
> >> > I'm using Python 2.7.2 and I'm trying to create and write to a file
> >> > (.py) a python class and functions from python. I will also need to
> >> > later read and edit the file. I realize I could just write strings
> >> > using the available string and file writing methods but suspect there
> >> > is a better way than that.
> >> >
> >> > I have read about pickle, ast, and Django; searched this group and the
> >> > web but haven't found a solution that seems to fit. Any suggestion?
> >>
> >> Due to Python's dynamic nature it is rarely necessary to generate Python
> >> code. What are you actually trying to achieve?
> >
> > I'm trying to generate the script file that will launch a PythonCard
> > resource file.
> >
> > very basic example from the documentation.
> >
> > #!/usr/bin/python
> > """
> > __version__ = "$Revision: 1.10 $"
> > __date__ = "$Date: 2004/04/24 22:13:31 $"
> > """
> >
> > from PythonCard import model
> >
> > class Minimal(model.Background):
> > pass
> >
> > if __name__ == '__main__':
> > app = model.Application(Minimal)
> > app.MainLoop()
>
> If it doesn't get too complex you could start with Python's built-in string
> formatting:
>
> import sys
>
> template = '''\
> #!/usr/bin/python
> from PythonCard import model
>
> class {Class}(model.Background):
> pass
>
> if __name__ == '__main__':
> app = model.Application({Class})
> app.MainLoop()
> '''
>
> resourcename, filename = sys.argv[1:]
>
> with open(resourcename, "U") as f:
> data = eval(f.read())
>
> with open(filename, "w") as f:
> f.write(template.format(Class=data["application"]["name"]))
>
> If you need logic inside the template, here's on overview:
>
> http://wiki.python.org/moin/Templating
>
> So there are rather too many options than too few.
It shouldn't get very complicated so I look through those options.
Thanks to all posters
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web