First time here? Check out the FAQ!

Ask Your Question
0

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

asked 7 years ago

happys5 gravatar image

updated 7 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 7 years ago

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

Preview: (hide)
link

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 ( 7 years ago )

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: 7 years ago

Seen: 834 times

Last updated: Jul 06 '17