Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to run the following code on ubuntu but getting file not found error. But same code is working fine on my windows machine
...
for elem in items['stats']:
f = open(r"\root\bot_python\list.txt", "r+")
...
Because the path separator is different between Ubuntu and Windows. See Path separator for Windows and Unix and separator for both Linux and Windows. For python, you could use os.path.join to parse your file path before reading it. Btw, pathlib is also a good option if you're familiar with some object-oriented concepts.
You should use double back slash instead of single. Like this:
...
for elem in items['stats']:
f = open(r"\\root\\bot_python\\list.txt", "r+")
...
I think you need root permission to access the file see you are trying to access a file inside root directory...
Try Running the python script with "sudo python file_name.py"
Maybe it solves your issue.
And use backward slashes for spaces whenever possible.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
So im trying to load an image with pygame but i don't know exactly what its supposed to look and all the examples I've seen are from people on windows and the ones on mac don't seem to help.
This is what I'm currently trying but it doesn't work and says there is no such file or directory as this.
sky_surface = pygame.image.load('/Macintosh HD/Users/Amin/Desktop/Sky.png').convert()
I do have an image called 'Sky.png' on my desktop.
screenshot of image directory as shown in finder
Actually, Macintosh HD should not be a part of the pathname -- the correct path should be, in your case here, /Users/Amin/Desktop/Sky.png.
MacOS (I'm on Monterey now) should have a feature to copy a pathname of a file. In Finder you may right-click on a file to get the context menu and then press option key. You should see the Copy ... as Pathname entry. This will copy the valid pathname to your clipboard -- and as you'll see, it won't contain Macintosh HD prefix.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Python does not adds text to file (although file is created) when run inside IDLE. But if run directly by using cmd or double clicking the file, it works fine. What might be the problem?
Code -
f = open('ERROR.txt', 'a')
f.write("hello")
f.close
I am using python 3 on windows 10.
Note: this is not duplicate. All other questions end by closing the file, but in my case, I already have closed the text file.
f = open('ERROR.txt', 'a')
f.write("hello")
f.close()
Well, the problem is that f.close() is method of file class, and you call f.close instead of function. Try this code above
Another question, if you run your code does the file contain any text?
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I'm pretty new to Python and I'm trying to read a CSV file with Pandas. However I get the following error:
C:\Python\python.exe "C:/Users/Niels Hoogeveen/PycharmProjects/HelloWorld/HelloWorld.py"
C:\Python\python.exe: can't open file 'C:/Users/Niels Hoogeveen/PycharmProjects/HelloWorld/HelloWorld.py': [Errno 2] No such file or directory
I tried the absolute path, but I get the same error time and time again.
See the screenshot below.
What do I need to do?
screenshot of my code and error
Your file is called test.py instead of HelloWorld.py
By the way, it's possible that '/' must be replaced by '\'
Your Python file's name is not HelloWorld.py, it is test.py. :) Just change the name in the PyCharm terminal and it should start to work.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
Can somebody help me out with why this is happening? I have a python 3, virtualenv based environment, and I am writing some scripts with Facebook SDK.
When I write print statement before importing facebook, the print is happening only once.
When I write print statement after importing facebook, the print is happening twice, even though the print is written only once.
Rename your file from facebook.py to something else. As it is, it is importing itself rather than the module.
You are not importing facebook sdk library but instead import your own facebook.py file (which prints out date)
SOLUTION: change your facebook.py filename to something else.
TIP: try to avoid file naming that might cause conflicts with other libraries
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
To follow a protocol, '\r\n' can't be replaced by '\n'
But when I wrote the string below into a file with python, '\r\n' were all replaced by '\n'
"*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n"
According to docs, Python on Linux makes no distinction between text and binary files, so no matter I append a 'b' to the mode or not, there is no difference, all '\r' were gone
How to solve this? Any help will be appreciated ;)
It should work as you said.
One possible reason you don't see the \r is that the editor you're using detect the fileformat (line ending) and hide the CR.
VIM
For example, vim automatically detect the fileformat (ff). Try :set ff. It will show you fileformat=dos if the file consistently have \r\n. Otherwise, it will show you fileformat=unix and ^M as you commented.
Try xxd filename to see the raw bytes as hexadecimal format. It will not hide CR (0d in hex)