Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'argument': 0.05; 'explicitly': 0.05; 'subject:Python': 0.06; 'only,': 0.07; 'advance': 0.07; 'string': 0.09; '8bit%:30': 0.09; 'conversions': 0.09; 'executed': 0.09; 'pep': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'recommends': 0.09; 'spaces': 0.09; 'python': 0.11; 'changes': 0.15; 'finney': 0.16; 'helps.': 0.16; 'integer,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'transforming': 0.16; '(you': 0.16; 'code.': 0.18; 'skip:f 30': 0.19; 'command': 0.22; '>>>': 0.22; 'code,': 0.22; '(in': 0.22; 'header:User-Agent:1': 0.23; 'post': 0.26; 'header:X-Complaints-To:1': 0.27; 'characters': 0.30; 'converting': 0.30; 'writes:': 0.31; 'text': 0.33; 'url:python': 0.33; "i'd": 0.34; 'message.': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'but': 0.35; 'sequence': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'so,': 0.37; 'turn': 0.37; 'skip:- 20': 0.37; 'thank': 0.38; 'ben': 0.38; 'feed': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'ensure': 0.60; 'number,': 0.60; 'skip:y 20': 0.60; 'tell': 0.60; 'hope': 0.61; 'url:3': 0.61; 'such': 0.63; '8bit%:16': 0.84; 'characters,': 0.84; 'compose': 0.84; 'received:125': 0.84; 'skip:\xe2 50': 0.84; 'skip:\xe2 30': 0.91; 'quotation': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: passing Python assignment value to shell Date: Thu, 29 May 2014 09:45:02 +1000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:g0IwPlvQ1y2W4YKyz5EsVg3z96M= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1401320719 news.xs4all.nl 2867 [2001:888:2000:d::a6]:47669 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72202 Satish Muthali writes: > so, this is what I have so far: Thank you for presenting your code. Please ensure that you post in text only, without transforming the characters from what you typed. Something in your message composition process is currently converting some ‘"’ (U+0022 QUOTATION MARK) characters into ‘“’ and ‘”’ (U+201C LEFT DOUBLE QUOTATION MARK and U+201D RIGHT DOUBLE QUOTATION MARK) characters, which changes the meaning of your code. Best to turn off all such automated conversions when you compose a message. > reecalc = [s.split() for s in os.Popen("free -ht").read().splitlines()] > freecalc_total = freecalc[4] > freecalc_total = freecalc_total[3] > freecalc_total = freecalc_total.translate(None, 'M’) > > Now I want to feed the value for ‘freecalc_total’ as an argument to a > command executed by the shell. It will need to be a text string representation of that number, since the command line will be a sequence of text string arguments. To create a text string representation of an integer, use ‘str(freecalc_total)’. (In Python 2, use ‘unicode(freecalc_total)’.) If the number is not an integer, you should format it explicitly with a format string :: >>> freecalc_total = 80752.16 >>> freecalc_arg = format(freecalc_total, "14.3f") >>> freecalc_arg ' 80752.160' > For example: > > devnull = open(os.devnull, “w”) > runCommand = subprocess.call([“stressapptest”, “”, “20”],stdout=devnull,stderr=subprocess.STDOUT) > devnull.close() (You should follow PEP 8 for your Python code, which recommends against camelCaseNames and recommends spaces after commas for readability.) So I'd suggest:: freecalc_total = your_computations_as_above() foo_arg = 20 # You don't tell us what this argument is, but it should have a name. command_args = [ "stressapptest", str(freecalc_total), str(foo_arg)] process = subprocess.call( command_args, stdout=devnull, stderr=subprocess.STDOUT) > Many thanks in advance I hope that helps. -- \ “Homer, where are your clothes?” “Uh... dunno.” “You mean Mom | `\ dresses you every day?!” “I guess; or one of her friends.” | _o__) —Lisa & Homer, _The Simpsons_ | Ben Finney