python


Return a board read from open file board_file. The board file will contain one row of the board per line


for a .txt looking like the below (already opened):
EFJAJCOWSS
SDGKSRFDFF
ASRJDUSKLK
HEANDNDJWA
ANSDNCNEOP
PMSNFHHEJE
JEPQLYNXDL
Return a board that will contain each row on a different line. Newlines are not included in the board.
I have the below code:
def read_board(board_file):
file = open(board_file, 'r')
line = file.readline()
newList = ''
while line != '':
newList = newList + line.strip('\n') + '\n'
line = file.readline()
return newList
The result is : 'EFJAJCOWSS\nSDGKSRFDFF\nASRJDUSKLK\nHEANDNDJWA\nANSDNCNEOP\nPMSNFHHEJE\nJEPQLYNXDL\n'
Any tips on how I can get this to list each row on a different line, as mentioned above? +'\n' doesn't do the trick...
file.readlines() gives list of lines
lst_lines = file.readlines()
lst_lines will be like: ['EFJAJCOWSS\n','SDGKSRFDFF\n'........]
Now you can iterate over lst_lines list with for loop
line[0],line[1] is different line
for line in lst_lines:
print(line)

Related Links

prettifying a part of the html doc using beautifulsoup
Django concatenate two querysets for same model
How can I validate input to accept only binary numbers?
Custom route predicates in Pyramid
Why is my query for a structured property failing with BadFilterError?
Simple Audio Units Host to drive an Audio Units Instrument
kivy language cumbersomeness and rationale behind it
detect if variable is of sympy type
Add markers on line plot from another vector
Does asyncio.wait return only after all done_callbacks were called?
How to parse a htmlpage with lxml with <br /> screwing up?
Python Moviepy module: output video?
Many Problems with python's virtualenv
How to add a title to Seaborn Facet Plot
What is happening in Python 3 when I call list() on an iterator?
In kivy using screenmanager how can I add other widgets like scatter?

Categories

HOME
erlang
checkbox
bower
extract
travis-ci
zend-framework2
heap-memory
rocketmq
recyclerview
simpy
codeblocks
gimp
criteria
cakephp-2.9
lagom
game-maker-studio-1.4
dlib
uiview
bootstrap-popover
android-toolbar
tree-traversal
jconsole
autolayout
explode
spring-test
bcrypt
samsung-mobile
onesignal
net-snmp
bus-error
widevine
vcard
partial-application
dd-wrt
bxslider
ivy
jboss5.x
picturebox
consumer
pyscripter
spring-insight
rhomobile
fabric-digits
service-locator
sql-like
active-model-serializers
ical-dotnet
knockout-3.0
datalog
powermta
matlab-cvst
apiary
prototypejs
automator
gd
mcrypt
instruction-set
info
fontconfig
httplib2
search-box
restivejs
pdfkit
aescryptoserviceprovider
multifile-uploader
dojox.charting
nssplitview
gmsmapview
proxygen
twgl.js
galaxy
java.util.calendar
android-viewholder
vips
p-np
python-winshell
rx-groovy
rspec3
httpie
robocode
magento-1.12
rhel5
left-recursion
gmaps4rails
tcpreplay
formvalidation-plugin
snmp4j
docopt
humanizer
aquafold
phpdocx
opensocial
lov
sim900
nsmatrix
driver-signing
backbone-relational
grunt-contrib-compass
fileconveyor
appfog
magickwand
fluidsynth
wpdb
icsharpcode
tridion2009
android-4.0
code-conversion
cbcentralmanager
attachevent
plone-funnelweb
shim
legacy-code
flexicious
selectmanycheckbox
shared-objects
webkit-transform
handwriting
easygui
ihttphandler
symbol-server
mvvm-foundation
code-design
project-lifecycle

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App