Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'oct': 0.02; 'frameworks': 0.04; 'subject:Python': 0.06; '"""': 0.07; 'python': 0.08; 'higher-level': 0.09; 'received:209.85.160.174': 0.09; 'received :mail-gy0-f174.google.com': 0.09; 'output': 0.10; '42,': 0.16; 'simplified': 0.16; 'subject:function': 0.16; 'templating': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.16; 'wed,': 0.17; 'cheers,': 0.18; 'insert': 0.19; 'cc:no real name:2**0': 0.20; 'subject:data': 0.21; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; '(though': 0.23; 'somehow': 0.23; 'pm,': 0.24; 'variable': 0.24; 'fine': 0.26; 'bit': 0.28; 'problem': 0.28; 'accessible': 0.29; 'explicitly': 0.29; 'module.': 0.29; 'message- id:@mail.gmail.com': 0.29; 'print': 0.29; 'script': 0.29; 'cc:addr:python.org': 0.30; 'chris': 0.32; 'pure': 0.32; 'there': 0.33; 'quite': 0.34; 'all.': 0.34; 'received:209.85.160': 0.35; 'doing': 0.36; 'issue': 0.36; 'another': 0.37; 'example,': 0.37; 'using': 0.37; 'but': 0.37; 'something': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'getting': 0.39; 'data': 0.39; 'happens': 0.40; 'more': 0.60; 'your': 0.61; '26,': 0.67; 'afraid': 0.71; 'fragment': 0.84; 'sender:addr:chris': 0.84; 'url:rebertia': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=QkkWLnM52Bz5X8Rrd2PhuSJmyKXqGKBKhM3VC8fYQOQ=; b=JKnm872gkKgMVMAYi4Uw/E+mOrUwpxzIMYeW1beUbdN3V0ZNfpO3BJjP73i248VyPR cLjAD3WmYkCi+3CtKPruh/C2jtA07aDkQ7N3tpv4bbBtgC07uAHa6orSOOBknR0hAorI Kz1kIvPzCpwcvReySiKUc6tOGoIcX6w75LqIs= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: References: Date: Wed, 26 Oct 2011 19:42:09 -0700 X-Google-Sender-Auth: -dRlTn6iMzLO-r8xDcrb8uhNU9I Subject: Re: passing Python data to a javascript function From: Chris Rebert To: Bill Allen Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org 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: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1319683332 news.xs4all.nl 6981 [2001:888:2000:d::a6]:35459 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15019 On Wed, Oct 26, 2011 at 7:25 PM, Bill Allen wrote: > > Benjamin, > > I was afraid I was doing that.=C2=A0=C2=A0 I have simplified it quite a b= it, still not > getting the output I am looking for.=C2=A0=C2=A0 I am down to that I am n= ot passing > the value in the onload=3DshowPID() call correctly.=C2=A0 I know this is = getting a > bit far from a Python issue now, but if you have more insight on this, I > would appreciate it.=C2=A0 Is there another way of passing the data from = the > Python script to the javascript than what I am doing in this CGI? The problem is that you're not passing the data at all. You never interpolate the pid_data value into the string(s) constituting your embedded JavaScript (though you did do it just fine in the pure HTML). The Python variable `pid_data` is not somehow magically accessible to JavaScript; you must explicitly insert its value somewhere. > pid_data =3D str(os.getpid()) > print """ > Change that line to: As an example, if the PID happens to be 42, then the outputted fragment will end up being: As a sidenote, I would recommend using something higher-level than the `cgi` module. Python has an abundance of web frameworks and templating languages; take your pick. Cheers, Chris -- http://rebertia.com