snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#35549

Python

echo to text

os.system("echo 'reply_to_address =\042"+list+"@ftsl.itb.ac.id\042' > config.data")
https://snipt.net/embed/633494151d94de427489a89fdeaa04a9/
https://snipt.net/raw/633494151d94de427489a89fdeaa04a9/
633494151d94de427489a89fdeaa04a9
python
Python
1
2014-04-19T05:09:55
True
False
/api/public/snipt/35549/
echo-to-text
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="n">os</span><span class="o">.</span><span class="n">system</span><span class="p">(</span><span class="s">&quot;echo &#39;reply_to_address =</span><span class="se">\042</span><span class="s">&quot;</span><span class="o">+</span><span class="nb">list</span><span class="o">+</span><span class="s">&quot;@ftsl.itb.ac.id</span><span class="se">\042</span><span class="s">&#39; &gt; config.data&quot;</span><span class="p">)</span> </span></pre></div> </td></tr></table>
python
#35545

Python

read file line per line and trim new line symbol

1
2
3
4
5
6
file = 'fileName'
f = open(file, 'r')
content = f.readlines()
size = len(content)
for i in range(size):
        print content[i].rstrip()
https://snipt.net/embed/eeb2a092a769931ae38fa96367b6b4ac/
https://snipt.net/raw/eeb2a092a769931ae38fa96367b6b4ac/
eeb2a092a769931ae38fa96367b6b4ac
python
Python
6
2014-04-22T22:40:08
True
False
/api/public/snipt/35545/
read-file-line-per-line-and-trim-new-line-symbol
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nb">file</span> <span class="o">=</span> <span class="s">&#39;fileName&#39;</span> </span><span id="L-2"><a name="L-2"></a><span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="nb">file</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a><span class="n">content</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readlines</span><span class="p">()</span> </span><span id="L-4"><a name="L-4"></a><span class="n">size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">content</span><span class="p">)</span> </span><span id="L-5"><a name="L-5"></a><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">size</span><span class="p">):</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">print</span> <span class="n">content</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">rstrip</span><span class="p">()</span> </span></pre></div> </td></tr></table>
python, read