Forums

Bottle read file in pythonaywhere

Hello everyone! I have a code that works perfect in jupyter notebook but in pythonaywhere doesn't and I cannot find out what's going on:

Working code in jupyter :

enter image description here

But in pythonaywhere it doesn't work:

enter image description here

In jupyter notebook it read the file but in pythonanywhere it doesn't read the file. Somebody could help me please!

many thanks in advance

Do you get any errors when you try to upload the file? They'll appear in the website's error log, which is linked from the "Web" page -- the most recent error will be at the bottom of the logfile.

Hello and thanks for your answer, I donĀ“t have any error when I upload yhe file, the error show up when I hit the button login (for read the file).enter image description here

It is wierd because I can see the file (kmer.txt) already uploaded in the web :

enter image description here

Ah, I see. I think the problem is that you're using a relative path for your filename. The path "kmer.txt" means "the file called "kmer.txt" in this process's current working directory." The current working directory for a process may not be what you think it is, and can also change over time (eg. if you, or some library that you're using, call the os.chdir function).

The best thing to do is to use an absolute path, including the directory that the file is in, starting with a "/". For example, /home/pytbio/mysite/kmer.txt, if that's the location of your file.

Many thanks for your answers again! perfect I understand what you mean but how and where I should do it? I need to type :

with open(/home/pytbio/mysite/filename) as f: ??

quotation marks?? : with open("/home/pytbio/mysite/filename") sorry for this stupid questions but I am biologist and I am a beginner with this

Kind regards

Quotation marks, yes.