so I'm such a noob in Python it's painful but I'm trying to come up with a way to PING a site, then spit out an 'if/else' clause.  So far I have this:  import subprocess  command = "ping -c 3 www.google.com"  # the shell command process = subprocess.Popen(command, stdout=subprocess.PIPE,      stderr=None, shell=True)  #Launch the shell command: output = process.communicate()  print output[0]   Below is where I go awry, here is part two:  if output == 0.00 print "server is good"  else print "server is hosed"   Obviously part 2 is not working out.   My question is, how do I "read" the results from the ping (the milliseconds)     icmp_seq=0 ttl=44 time=13.384 ms  and say "if the ping time is faster than 12.000 ms then do THIS" else     "do THAT"  Right now I'm just doing a print but soon I'd like to change that so something else.
How do I ping a website or IP address with Python?
Gparted: move extended partition on the left Why are z-values replaced with zero after in_memory use in Python? I am programming a tile based game and I have some basic tiles (grass, dirt, etc..), but I can't figure out how to make good random map generation, because when I do some really random selection, if the tile should be grass/dirt, I get this:    I understand why this is happening, but what I want is to create some random continuous areas of grass or dirt. Something that would make more sense, like this: If p $\equiv$ 3 (mod 4) with p prime, prove -1 is a non-quadratic residue modulo p. If p $\equiv$ 3 (mod 4) with p prime, prove -1 is a non-quadratic residue modulo p.  I suppose this would not be true if p $\equiv$ 1 (modulo 4).  To prove something is a non-square I find to be tricky. It's difficult to see any straightforward way to do this using only the definition of congruence for example. Each number in a subset $S\subseteq \{1,\ldots,2n\}$ does not divide another one. Then $\max |S|$? This problem comes from a seemingly innocuous question from a professor during a lesson for a Math Olympiad course. [A part of this question is really a classic of number theory/combinatorics]  Problem: Let $S$ be a a non-empty subset of $\{1,2,\ldots,2n\}$. It is clear that if $|S|$ is "enough large" then, independently from the choice of $S$, there are for sure some distinct $a,b \in S$ such that $a$ divides $b$.  Then, what is the maximal $k$ such that, for some $S$ with cardinality $k$, if $a,b$ are distinct members of $S$ then $a$ does not divide $b$?  [Ps. I know the solution] How do I change player name in Minecraft smp in offline mode on a Mac? Here is what I tried doing:  #!/bin/sh res=`df | awk 'FNR == 2 { print $5 }'` res2=$((res+0))   Here is my error:     -bash: 53%: syntax error: operand expected (error token is "%")   I Googled 'string to int bash' which showed me $((res+0)) but it doesn't work due to the % in the string (53%). How do I convert it in such a way I can do an if statement such as the one below (but that works)?  if [ "$res2" -ge 50 ] then     echo "Your disk &gt;=50% full!" fi I am trying to change the page size in the QGIS 3.0 Composer but I am not able to see the Composition tab.  I have right clicked an empty space in the toolbar but did not see anything about composition.  I am using Windows 7.  I tried looking at the QGIS docs but they are still in testing. Last two digits of $3^{400}$ When I try to print a Unicode string in a Windows console, I get an error . UnicodeEncodeError: 'charmap' codec can't encode character .... I assume this is because the Windows console does not accept Unicode-only characters. What's the best way around this? Is there any way I can make Python automatically print a ? instead of failing in this situation? Edit:  I'm using Python 2.5.  Note: @LasseV.Karlsen answer with the checkmark is sort of outdated (from 2008). Please use the solutions/answers/suggestions below with care!!  is more relevant as of today (6 Jan 2016). My DOM looks like this:  &lt;div id="d1"&gt;    &lt;div class="c1"&gt;             &lt;a href="#"&gt;&lt;img src="img1_on.gif"&gt;&lt;/a&gt;             &lt;a href="#"&gt;&lt;img src="img2_on.gif"&gt;&lt;/a&gt;    &lt;/div&gt; &lt;/div&gt;   When someone clicks on an image, I want the image src to change to &lt;img src="imgx_off.gif"&gt; where x represents the image number 1 or 2.  Is this possible or do I have to use CSS to change the images? How do i prove that $(p \vee q) \wedge (\neg p \vee r) \rightarrow (q \vee r)$ is a tautology without using the truth table? I'm self studying J. Lee's Introduction to Topological Manifolds, and after doing all other exercises on chapter 2, I can't seem to come with the proper counterexamples for this one.      For each of the following properties, give an example consisting of two subsets $X, Y \subset \mathbb{R}^2 $, both considered as topological spaces with their Euclidean topologies, together with a map $f: X \rightarrow Y$ that has the indicated property.         Open but not closed/continuous   Closed but not open/continuous    Continuous but not open/closed         etc... (all cases)   I think the reason for my difficulty is a lack of geometric intuition of what open, closed and continuous maps look like as deformations of shapes in $\mathbb{R}^2$ (I can construct counterexamples from artificial made up spaces).   I tried squashing balls and 'pumping space' into lines, as well as joining strips in annulus shapes, but all the examples I seem to come up with are either too well behaved (i.e. all 3) or too misbehaved.   Instead of a case by case answered I would prefer a couple worked out cases and some intuition on how to visualise open / closed maps in this context. Has anyone had any success using twitters typeahead.js within visualforce pages? I am trying to get  to work within salesforce visualforce pages.  I have a basic vf page from  example, but it does not respopnd, I suspect there may be some "unknown" workaround needed? Does anyone know?  &lt;apex:page standardController="Contact" showHeader="false" sidebar="false" docType="html-5.0"  standardStylesheets="false"&gt;  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="http://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"&gt;&lt;/script&gt;      &lt;div id="the-basics"&gt;   &lt;input class="typeahead" type="text" placeholder="States of USA"/&gt; &lt;/div&gt;  &lt;script&gt;     var substringMatcher = function(strs) {       return function findMatches(q, cb) {         var matches, substrRegex;          // an array that will be populated with substring matches         matches = [];          // regex used to determine if a string contains the substring `q`         substrRegex = new RegExp(q, 'i');          // iterate through the pool of strings and for any string that         // contains the substring `q`, add it to the `matches` array         $.each(strs, function(i, str) {           if (substrRegex.test(str)) {             // the typeahead jQuery plugin expects suggestions to a             // JavaScript object, refer to typeahead docs for more info             matches.push({ value: str });           }         });          cb(matches);       };     };      var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',       'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',       'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',       'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',       'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',       'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',       'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',       'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',       'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'     ];      $('#the-basics .typeahead').typeahead({       hint: true,       highlight: true,       minLength: 1     },     {       name: 'states',       displayKey: 'value',       source: substringMatcher(states)     }); &lt;/script&gt; Do all accepted students in top-tier engineering programs get invited to interview before getting admitted? Suppose I have some theorem in the paper  Section 1 Theorem 1.1. Let ...  And then later in the paper I want to recall the theorem by reprinting it  Section 4 We recall Theorem 1.1: Theorem 1.1. Let ...  What's the proper way to do this? How to plot a surface from a set of data? Disclaimer: I already read questions like  and  but these did not solve my problem.  I have this set of data:  x       y       z 2.17    0.001   0.82044815 2.17    0.002   0.82345825 2.17    0.004   0.82679255 2.17    0.008   0.83334715 2.17    0.016   0.84395915 2.17    0.032   0.8584953 2.21    0.001   0.77582165 2.21    0.003   0.78520505 2.21    0.009   0.80205985 2.21    0.027   0.83085105 2.24    0.001   0.7227885 2.24    0.002   0.73391615 2.24    0.005   0.7543979 2.24    0.015   0.78798745 2.24    0.003   0.74176635 2.24    0.009   0.77064805 2.24    0.027   0.81042375 2.26    0.001   0.66545585 2.26    0.003   0.7012046 2.26    0.005   0.721067 2.26    0.009   0.7447984 2.26    0.015   0.76715245 2.26    0.027   0.794177 2.27    0.001   0.62916195 2.27    0.003   0.6774642 2.27    0.009   0.72961785 2.27    0.027   0.7861086 2.28    0.001   0.5750828 2.28    0.003   0.65059675 2.28    0.005   0.6802631 2.28    0.009   0.7145367 2.28    0.015   0.74447695 2.28    0.027   0.7774403 2.29    0.001   0.51357255 2.29    0.002   0.581053 2.29    0.003   0.6173075 2.29    0.009   0.6972096 2.29    0.027   0.76793225 2.31    0.001   0.36997965 2.31    0.002   0.474415 2.31    0.003   0.53649295 2.31    0.009   0.6587164 2.31    0.016   0.70870255 2.31    0.027   0.7482423 2.31    0.05    0.7912395 2.34    0.001   0.2204104 2.34    0.002   0.316308 2.34    0.003   0.39256745 2.34    0.004   0.45240835 2.34    0.009   0.5883453 2.34    0.016   0.6590771 2.34    0.027   0.71444205 2.34    0.05    0.7690014 2.38    0.001   0.13286995 2.38    0.002   0.1828288 2.38    0.004   0.2980268 2.38    0.008   0.4507145 2.38    0.016   0.58417075 2.38    0.032   0.6833616   And if I plot it in Mathematica (with ListPlot3D[data]) it looks, without further tweaking and fiddling around, like:    But if I try this pgfplots code  \begin{tikzpicture}   \begin{axis}     \addplot3 [surf] table {data.txt};   \end{axis} \end{tikzpicture}   I only get this:    What do I have to do to get a surface like in Mathematica (color, smoothness, style, etc. does not matter, just a closed surface)? Why does bright pure red/green/blue light look white if bright enough? I believe that white light is white because it contains every wavelength, as white by itself has no frequency by itself.  Can somebody explain why really bright pure red, green, or blue LEDs seem white to us and to cameras?  Also, can a bright light ever be pure(eg is it possible to emit a pure red/pure blue/pure green bright light only with wavelengths in the range of that light), or will the inherent brightness of a light force other wavelengths into the light? Print lines between (and including) two patterns I want to start grepping from the lines that has CK at the end of line and stop grepping when the line has D at the end. I tried grep "$CK" "$D" file..txt, but it didn't work.  Input:  kkkkkkkkkkk    jjjjjjjjjjjjjjjjjj   gggggggggggg/CK   JHGHHHHHHHH    HJKHKKLKLLL    JNBHBHJKJJLKKL   JLKKKLLKJLKJ/D   GGGGGGGGGGGGGG   GGGGGGGGGGGGGG   The desired output:  gggggggggggg/CK   JHGHHHHHHHH    HJKHKKLKLLL    JNBHBHJKJJLKKL   JLKKKLLKJLKJ/D The speed of light as it approaches a massive body No matter how fast you go, you will aways perceive the speed of light as constant. Taking that as a fact, the special relativity theory was formulated. Now, for what I understand about general relativity, just by standing here on the surface of the planet under the effect of gravity, my frame of reference is a little different from someone in geostationary orbit, and time goes by a little slower for me.  So, considering me and someone in geostationary orbit, does both of us would perceive light at the same speed? If so, does that means that the light is slower down here than up there?