Ask Your Question
0

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

asked 2017-07-06 03:47:54 +0100

happys5 gravatar image

updated 2017-07-06 21:26:51 +0100

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

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-07-06 13:37:28 +0100

dan_fulea gravatar image

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

edit flag offensive delete link more

Comments

:)

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 21:28:27 +0100 )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

Stats

Asked: 2017-07-06 03:47:54 +0100

Seen: 811 times

Last updated: Jul 06 '17