Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82495 > unrolled thread
| Started by | sir <elearn2014@gmail.com> |
|---|---|
| First post | 2014-12-14 17:05 +0800 |
| Last post | 2014-12-14 23:13 +1100 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.lang.python
which is the right file path format in python3.4 ? sir <elearn2014@gmail.com> - 2014-12-14 17:05 +0800
Re: which is the right file path format in python3.4 ? Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2014-12-14 10:52 +0100
Re: which is the right file path format in python3.4 ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-14 22:03 +1100
Re: which is the right file path format in python3.4 ? Chris Angelico <rosuav@gmail.com> - 2014-12-14 22:09 +1100
Re: which is the right file path format in python3.4 ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-14 22:51 +1100
Re: which is the right file path format in python3.4 ? Chris Angelico <rosuav@gmail.com> - 2014-12-14 23:13 +1100
| From | sir <elearn2014@gmail.com> |
|---|---|
| Date | 2014-12-14 17:05 +0800 |
| Subject | which is the right file path format in python3.4 ? |
| Message-ID | <mailman.16941.1418547951.18130.python-list@python.org> |
My system is :win7+python3.4 . I want to write a new file "named names.txt" in disk f: >>> ff=open(r"F:\names.txt","w") Traceback (most recent call last): File "<stdin>", line 1, in <module> OSError: [Errno 22] Invalid argument: 'F:\\names.txt' >>> ff=open(r"F:/names.txt","w") Traceback (most recent call last): File "<stdin>", line 1, in <module> OSError: [Errno 22] Invalid argument: 'F:/names.txt' >>> ff=open(r"F://names.txt","w") Traceback (most recent call last): File "<stdin>", line 1, in <module> OSError: [Errno 22] Invalid argument: 'F://names.txt' >>> ff=open(r"f://names.txt","w") Traceback (most recent call last): File "<stdin>", line 1, in <module> OSError: [Errno 22] Invalid argument: 'f://names.txt' >>> ff=open(r"f:/names.txt","w") Traceback (most recent call last): File "<stdin>", line 1, in <module> OSError: [Errno 22] Invalid argument: 'f:/names.txt' which is the right file path format in python3.4 ?
[toc] | [next] | [standalone]
| From | Irmen de Jong <irmen.NOSPAM@xs4all.nl> |
|---|---|
| Date | 2014-12-14 10:52 +0100 |
| Message-ID | <548d5dd9$0$2848$e4fe514c@news.xs4all.nl> |
| In reply to | #82495 |
On 14-12-2014 10:05, sir wrote: > My system is :win7+python3.4 . > > I want to write a new file "named names.txt" in disk f: > > >>> ff=open(r"F:\names.txt","w") > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > OSError: [Errno 22] Invalid argument: 'F:\\names.txt' >>>> ff=open(r"F:/names.txt","w") > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > OSError: [Errno 22] Invalid argument: 'F:/names.txt' >>>> ff=open(r"F://names.txt","w") > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > OSError: [Errno 22] Invalid argument: 'F://names.txt' >>>> ff=open(r"f://names.txt","w") > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > OSError: [Errno 22] Invalid argument: 'f://names.txt' >>>> ff=open(r"f:/names.txt","w") > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > OSError: [Errno 22] Invalid argument: 'f:/names.txt' > > which is the right file path format in python3.4 ? They all should work. (They do on my machine when subtituting F with a drive letter that exists here. Win 7, Python 3.4.2). It's something else on your end that is causing the error. Is drive F: full? Do you have the correct permissions? Is it a network share that has certain restrictions? What exact python is is that you are running? Irmen
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-12-14 22:03 +1100 |
| Message-ID | <548d6e92$0$13013$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #82495 |
sir wrote:
> My system is :win7+python3.4 .
>
> I want to write a new file "named names.txt" in disk f:
>
> >>> ff=open(r"F:\names.txt","w")
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> OSError: [Errno 22] Invalid argument: 'F:\\names.txt'
Are you sure that you have an F drive?
Is it a writable disk? e.g. a hard drive, not a CD drive.
Do you have read and write permissions to F drive?
Run this code and show us what it prints:
import os
print(os.stat("F:\\")
print(os.access("F:\\", os.O_RDWR))
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-12-14 22:09 +1100 |
| Subject | Re: which is the right file path format in python3.4 ? |
| Message-ID | <mailman.16942.1418555375.18130.python-list@python.org> |
| In reply to | #82497 |
On Sun, Dec 14, 2014 at 10:03 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Run this code and show us what it prints:
>
> import os
> print(os.stat("F:\\")
> print(os.access("F:\\", os.O_RDWR))
(With an extra close parenthesis on the first print call)
I'm suspicious here that drive F might not even exist. I would expect
a permissions error to be errno 13, but "invalid argument" seems
really weird. Definitely these checks will be informative.
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-12-14 22:51 +1100 |
| Subject | Re: which is the right file path format in python3.4 ? |
| Message-ID | <548d79cb$0$13008$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #82498 |
Chris Angelico wrote:
> On Sun, Dec 14, 2014 at 10:03 PM, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> wrote:
>> Run this code and show us what it prints:
>>
>> import os
>> print(os.stat("F:\\")
>> print(os.access("F:\\", os.O_RDWR))
>
> (With an extra close parenthesis on the first print call)
Thanks.
> I'm suspicious here that drive F might not even exist. I would expect
> a permissions error to be errno 13, but "invalid argument" seems
> really weird. Definitely these checks will be informative.
I don't have access to a Windows box to check, otherwise I would do it
myself. What happens if you specify a non-existent drive letter?
open("Q:\\xxx") # Assuming you don't have a drive Q.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-12-14 23:13 +1100 |
| Subject | Re: which is the right file path format in python3.4 ? |
| Message-ID | <mailman.16943.1418559201.18130.python-list@python.org> |
| In reply to | #82499 |
On Sun, Dec 14, 2014 at 10:51 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> I don't have access to a Windows box to check, otherwise I would do it
> myself. What happens if you specify a non-existent drive letter?
>
> open("Q:\\xxx") # Assuming you don't have a drive Q.
Hmm. I just grabbed one (granted, it's XP not W7) and checked it, and
it's not what I was expecting either.
Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> open("Q:\\xxx")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'Q:\\xxx'
Still, it might be something unusual about the OP's drive. Maybe a
network drive with a broken connection, or a mounted CD, or an alias
for another directory... who knows. Hopefully the stat and access
checks will reveal something.
ChrisA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web