0

i'm trying to programm a photo seeker. I have an issue when i wanted to open these photo from a list of path.

I put the list of path in a listBox, so i can click on choosen path and it stocks it in a string variable but i get an issue when i wanted to open the file.

I searched and i found 2 topics on stack overflow : Python os module open file above current directory with relative path

import os.path
import sys

basepath = os.path.dirname(__file__)
filepath = os.path.abspath(os.path.join(basepath, "HelloWord.txt"))
f = open(filepath, "r")

I get an error :

File "C:/Users/jguillot/Desktop/test002.py", line 6, in <module>
f = open(filepath, "r")

TypeError: an integer is required

I don't understand it.

I also look at this topic : Open file in a relative location in Python which have the same solution as the first one.

To understand my error i go on : https://docs.python.org/2/library/os.path.html I did :

import os
from os import path

os.path.exits('C:\Users\jguillot\Desktop\HelloWord.txt')

It returns me False

But if i try :

os.path.exits('C:\Users\jguillot\Desktop')

It returns me True

os.path.exists(path) : Return True if path refers to an existing path. Returns False for broken symbolic links. On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists. (From python manual) I don't understand this error.

Can you explain to me please?

Community
  • 1
  • 1
Jguillot
  • 214
  • 3
  • 14
  • Your test script has 6 lines, but your error is from a script with at least 15. Can you run your test script? – Blender Jul 31 '14 at 13:58
  • Your two `os.path.exists` calls make perfect sense. The first one is asking if the **directory** HelloWorld.txt exists, it probably doesn't. However your Desktop directory certainly does. – AlG Jul 31 '14 at 14:00
  • Is there any other import statements in your original code that gives the 'an integer is required' message? – ChipJust Jul 31 '14 at 14:09
  • @AI G ok, so we can't see if the file 'HelloWorld.txt' exist? – Jguillot Jul 31 '14 at 14:11
  • ChipJust not i just get the information give by my IDE '''Created on date @autor: jguillot'''' – Jguillot Jul 31 '14 at 14:15
  • The code you gave works for me (with a different file and path). I suspect that there could be some other code that is not shown? – ChipJust Jul 31 '14 at 14:18
  • `HelloWord.txt` or `HelloWorld.txt`? – dwitvliet Jul 31 '14 at 14:22
  • @ChipJust I restarted my IDE and it works ... I really don't understand where is the mistake... Thanks – Jguillot Jul 31 '14 at 14:25

0 Answers0