## First we do some setup and create a file with some random numbers#with open('/temp/workfile', 'w') as f: f.write('69\n39\n32\n59\n50\n49\n82\n40\n58\n40\n43\n7\n50\n58\n13\n89\n58\n68\n32\n20\n17\n37\n24\n96\n83\n67\n30\n41\n54\n58\n17\n54\n98\n37\n43\n10\n68\n44\n65\n12\n78\n98\n96\n44\n25\n22\n44\n63\n41\n31\n92\n87\n53\n37\n96\n71\n19\n1\n56\n75\n82\n73\n9\n63\n86\n45\n38\n21\n4\n13\n55\n70\n48\n34\n63\n69\n21\n93\n36\n85\n56\n68\n18\n70\n68\n92\n63\n87\n25\n66\n74\n30\n68\n33\n21\n24\n41\n55\n51\n30')

## Read the file, convert the lines to numbers, and print them out when > 90#with open('/temp/workfile', 'r') as f: pass # TODO: fix this

Expected output : 96 98 98 96 92 96 93 92

I was able to produce output,but is there a cleaner way? This was my approach

## First we do some setup and create a file with some random numbers#with open('/temp/workfile', 'w') as f: f.write('69\n39\n32\n59\n50\n49\n82\n40\n58\n40\n43\n7\n50\n58\n13\n89\n58\n68\n32\n20\n17\n37\n24\n96\n83\n67\n30\n41\n54\n58\n17\n54\n98\n37\n43\n10\n68\n44\n65\n12\n78\n98\n96\n44\n25\n22\n44\n63\n41\n31\n92\n87\n53\n37\n96\n71\n19\n1\n56\n75\n82\n73\n9\n63\n86\n45\n38\n21\n4\n13\n55\n70\n48\n34\n63\n69\n21\n93\n36\n85\n56\n68\n18\n70\n68\n92\n63\n87\n25\n66\n74\n30\n68\n33\n21\n24\n41\n55\n51\n30')

## Read the file, convert the lines to numbers, and print them out when > 90#

with open('/temp/workfile', 'r') as f: arr='' for line in f: if int(line) > 90: arr = arr + ' '+line.rstrip()

Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

with open('/temp/workfile', 'r') as f: print ' '.join(line.rstrip() for line in f if int(line) > 90)

Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.