Ask Your Question

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

asked 2017-07-05 20:47:54 -0500

happys5 gravatar image

updated 2017-07-06 14:26:51 -0500


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: 
    L = f.readlines()

I have also tried the path

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

I have also tried the path

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

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: 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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-07-06 06:37:28 -0500

dan_fulea gravatar image

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


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.)

edit flag offensive delete link 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.

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-07-05 20:47:54 -0500

Seen: 39 times

Last updated: Jul 06