0
Quick feedback on error?
Here's the code: https://code.sololearn.com/cJ6Mf69XnMF8/#py Problem is at line 30: length = wordlist.index('\n')+1 Error I'm getting: ValueError: '\n' is not in list Code is supposed to open and read a user input file which is a word puzzle grid, and then append the lines from the file to a list and search for specific words through that list.
13 Respuestas
+ 2
If you get it in playground problem is that there are no .txt files there, so there will be no lines in list, so no line brakes.
Edit: if you have this in ide, may be reason a parameter in open method, you appending file not reading... as far as I understand.
+ 1
Correct me if I wrong in 'for line in wordlist' you refer to lines that arent there yet, since your file opens to the list named lines, or not? I am only learning Python currently
+ 1
you also need to have some value in the "line" variable in the first place for this to work.
try something like (depending on what you want to do)
f=open(filename.txt)
line=f.readline()
or
line=f.read()
this will put content from the file into the variable "line"
then you can split it or whatever.
+ 1
Look line by line
1 you declare empty list "wordlist=[] "
2. you open file and store it as variable lines
3. for each line in "wordlist " do append but,
there are no lines there.
You need to try "for line in lines" append line to wordlist.
0
Yeah the error is in idle. It can print and display the grid properly but doesn't go beyond that part. I thought the reading of the file was right hm so confused.
0
Derp. I edited to append before I do the rest. Still same error.
0
The list I named 'wordlist'. The file to be opened is stored in 'files' variable. I'm not sure what you're asking about lines?
0
Ifl, I tried that. Still same error.
0
alternatively you can probably do something like
f=file.open(filename)
then (in a loop)
wordlist.append(f.readline())
0
Is anyone's willing to edit the code in the next 5 minutes, awesome. Otherwise I'm screwed cause deadline in 5 and I'm not getting this.
- 1
mmmh... looks like wordlist is still empty when you reach this line?
- 2
well, wordlist is defined as an empty array and then there is no code to add values to it... so that would cause an error when you try to read from it, right?
- 2
try this
wordlist = line.split()
to fill up the array....