-5
dictionary = file . read()

I'm currently creating a cipher solver for the 2017 cipher challenge I have a word document of fifty eight thousand words but i cannot get the file as a string in python 2.7.9 I have tried many thing i have read online such as the above code but to no avail. I also need this to be easy to understand as i am new to python

Thanks!Don't be negative be constructive!

The word are from: http://www.mieliestronk.com/corncob_lowercase.txt

DSM
  • 342,061
  • 65
  • 592
  • 494
  • 1
    There are many tutorials on line for how to read files in Python. Where are you stuck with all of those? Pick one and give us a [Minimal, complete, verifiable example](http://stackoverflow.com/help/mcve) applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. – Prune Nov 07 '17 at 22:55
  • At least comment before you downvote – Ben Whitehead Nov 07 '17 at 22:55
  • In order to comply with the rules of this forum you should edit your question in line with comment #1 above. – Jon Scott Nov 07 '17 at 23:35
  • Please don't deface your question – Hovercraft Full Of Eels Nov 09 '17 at 23:07

3 Answers3

0

You probably should consult some code examples on the web for reading a file. You need something like:

fp = open(fname, "r")
lines = fp.readlines()
for line in lines:
   do_something_with_the_lines
fp.close()
Paul Coldrey
  • 1,389
  • 11
  • 20
0

All you have to do is:

with open("dictionary.txt") as f: # Open the file and save it as "f"
    dictionary = f.read()         # Read the content of the file and save it to "dictionary"

If you want to read it from a website, try this:

import urllib2
dictionary = urllib2.urlopen("http://www.mieliestronk.com/corncob_lowercase.txt").read() # Open the website from the url and save its contents to "dictionary"
Invision
  • 90
  • 1
  • 10
-1

I think you should check this out for what you're trying to do (http://www.pythonforbeginners.com/files/reading-and-writing-files-in-python)

This should be helpful

sirkrp
  • 1
  • 1
  • FYI I just happened to look at this page and saw many typos and indentation errors. In a tutorial aimed at beginners this is not good. – Paul Cornelius Nov 07 '17 at 23:11