# Import Text.txt file contents from a windows computer to sagecell.

Hello,

The following code will work on my Linux computer if I use the "/usual path/" in Linux but I cannot get Sage to recognize my Windows path. My code

with open('C:\Users\miram\OneDrive\Documents\Programming\Original.txt', 'r') as f:


I have also tried the path

with open('C:\\Users\\miram\\OneDrive\\Documents\\Programming\\Original.txt', 'r') as f:


I have also tried the path

 with open('C:\\Text\\22.PE.Orig.List.txt', 'r') as f:


and with one backslash.

I get the following error:

IOError: [Errno 2] No such file or directory: 'C:\\Text\\22.PE.Orig.List.txt'


What I want to do, as can be seen, is import a text file into SageMath so that I can work with the list created.

I am following: https://ask.sagemath.org/question/287... and have followed the advice for my Linux machine and have not had a problem. I need to do it on my Windows computer, though.

I think my problem is that I am using a sagecell server. Is that true?

edit retag close merge delete

Sort by » oldest newest most voted

Make sure the string is opened and closed in the same way:

'C:\Users\miram\OneDrive\Documents\Programming\Original.txt"


starts with a simple quote ' and ends with a double quote ". Also, try first something like:

filename = r'C:\Users\miram\OneDrive\Documents\Programming\Original.txt'
import os.path
print "Is there any file %s ? %s" % ( filename, os.path.isfile( filename ) )


to make sure the file is found by the operating system. (From the cell and/or from the python started in the Windows OS command line.)

more

:)

Yeah, they were opened and closed by single quotation marks when I tried to import. I just added the double quotation when I typed it in here. Sorry.

( 2017-07-06 14:28:27 -0500 )edit