Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.04; 'perl,': 0.05; 'python': 0.08; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:python': 0.10; '2.7.2': 0.16; 'ast,': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'wrote:': 0.18; 'later': 0.19; 'seems': 0.20; 'programming': 0.20; "haven't": 0.20; 'trying': 0.21; 'from:addr:web.de': 0.23; 'string': 0.24; "python's": 0.24; 'suspect': 0.24; 'code.': 0.26; "i'm": 0.28; 'class': 0.29; 'rarely': 0.30; 'subject:source': 0.30; 'actually': 0.31; 'file.': 0.31; 'there': 0.33; 'file': 0.34; 'header:X-Complaints-To:1': 0.34; 'realize': 0.34; 'to:addr:python-list': 0.35; 'received:org': 0.36; 'but': 0.37; 'using': 0.37; 'subject:with': 0.37; 'could': 0.38; 'that.': 0.39; 'to:addr:python.org': 0.40; 'due': 0.66; 'fit.': 0.67; 'subject:write': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Need to write python source with python Followup-To: gmane.comp.python.general Date: Tue, 28 Feb 2012 18:56:43 +0100 Organization: None References: <23135461.7.1330450584442.JavaMail.geo-discussion-forums@pbcrt4> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p50849a89.dip.t-dialin.net X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1330451754 news.xs4all.nl 6905 [2001:888:2000:d::a6]:39012 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20989 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?