Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78920 > unrolled thread
| Started by | Igor Korot <ikorot01@gmail.com> |
|---|---|
| First post | 2014-10-09 21:21 -0700 |
| Last post | 2014-10-10 09:52 -0600 |
| Articles | 8 — 6 participants |
Back to article view | Back to comp.lang.python
python on Linux Igor Korot <ikorot01@gmail.com> - 2014-10-09 21:21 -0700
Re: python on Linux John Gordon <gordon@panix.com> - 2014-10-10 04:37 +0000
Re: python on Linux Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2014-10-10 08:31 +0200
Re: python on Linux Chris Angelico <rosuav@gmail.com> - 2014-10-10 17:58 +1100
Re: python on Linux Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2014-10-10 09:48 +0200
Re: python on Linux Peter Pearson <pkpearson@nowhere.invalid> - 2014-10-10 15:44 +0000
Re: python on Linux Chris Angelico <rosuav@gmail.com> - 2014-10-11 02:53 +1100
Re: python on Linux Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-10 09:52 -0600
| From | Igor Korot <ikorot01@gmail.com> |
|---|---|
| Date | 2014-10-09 21:21 -0700 |
| Subject | python on Linux |
| Message-ID | <mailman.14733.1412914913.18130.python-list@python.org> |
Hi, ALL,
When I am on Windows, I can write something like this:
sys.path.append('C:\Users\Igor\Documents\MyLib')
Now, when I'm on Linux, can I do this:
sys.path.append('~/MyLib')
?
I.e., will '~' sign be expanded correctly?
Thank you.
[toc] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2014-10-10 04:37 +0000 |
| Message-ID | <m17nr0$bej$1@reader1.panix.com> |
| In reply to | #78920 |
In <mailman.14733.1412914913.18130.python-list@python.org> Igor Korot <ikorot01@gmail.com> writes:
> sys.path.append('~/MyLib')
> I.e., will '~' sign be expanded correctly?
Not as written.
Use os.path.expanduser() to get user's home directories.
--
John Gordon Imagine what it must be like for a real medical doctor to
gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.
[toc] | [prev] | [next] | [standalone]
| From | Irmen de Jong <irmen.NOSPAM@xs4all.nl> |
|---|---|
| Date | 2014-10-10 08:31 +0200 |
| Message-ID | <54377d29$0$2833$e4fe514c@news.xs4all.nl> |
| In reply to | #78920 |
On 10-10-2014 6:21, Igor Korot wrote:
> Hi, ALL,
> When I am on Windows, I can write something like this:
>
> sys.path.append('C:\Users\Igor\Documents\MyLib')
While this might work on your system, it may not work on others.
- you need to escape the backslashes (or just use forward slashes, they work on windows too)
- not all windows installations and versions have their user folders in
C:\Users\<username>. On windows too, you'll have to use something like %USERPROFILE% to
get to the correct directory if you want it to work correctly in all cases.
Irmen
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-10-10 17:58 +1100 |
| Message-ID | <mailman.14741.1412924297.18130.python-list@python.org> |
| In reply to | #78925 |
On Fri, Oct 10, 2014 at 5:31 PM, Irmen de Jong <irmen.NOSPAM@xs4all.nl> wrote:
> On 10-10-2014 6:21, Igor Korot wrote:
>> Hi, ALL,
>> When I am on Windows, I can write something like this:
>>
>> sys.path.append('C:\Users\Igor\Documents\MyLib')
>
> While this might work on your system, it may not work on others.
>
> - you need to escape the backslashes (or just use forward slashes, they work on windows too)
> - not all windows installations and versions have their user folders in
> C:\Users\<username>. On windows too, you'll have to use something like %USERPROFILE% to
> get to the correct directory if you want it to work correctly in all cases.
AIUI you can use os.path.expanduser() on Windows as well, and it'll
take care of USERPROFILE.
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Irmen de Jong <irmen.NOSPAM@xs4all.nl> |
|---|---|
| Date | 2014-10-10 09:48 +0200 |
| Message-ID | <54378f52$0$2935$e4fe514c@news.xs4all.nl> |
| In reply to | #78928 |
On 10-10-2014 8:58, Chris Angelico wrote: > AIUI you can use os.path.expanduser() on Windows as well, and it'll > take care of USERPROFILE. Nice, didn't know that! I've been using the appdirs module (https://pypi.python.org/pypi/appdirs/) as well to avoid constructing paths manually altogether. Irmen
[toc] | [prev] | [next] | [standalone]
| From | Peter Pearson <pkpearson@nowhere.invalid> |
|---|---|
| Date | 2014-10-10 15:44 +0000 |
| Message-ID | <c9qd6oFqn3eU1@mid.individual.net> |
| In reply to | #78925 |
On Fri, 10 Oct 2014 08:31:04 +0200, Irmen de Jong wrote:
> On 10-10-2014 6:21, Igor Korot wrote:
>> When I am on Windows, I can write something like this:
>>
>> sys.path.append('C:\Users\Igor\Documents\MyLib')
>
> While this might work on your system, it may not work on others.
>
> - you need to escape the backslashes (or just use forward slashes,
> they work on windows too)
And remember that os.path.join() will join path fragments with
the right kind of slashes for your operating system.
--
To email me, substitute nowhere->runbox, invalid->com.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-10-11 02:53 +1100 |
| Message-ID | <mailman.14756.1412956402.18130.python-list@python.org> |
| In reply to | #78955 |
On Sat, Oct 11, 2014 at 2:44 AM, Peter Pearson
<pkpearson@nowhere.invalid> wrote:
> On Fri, 10 Oct 2014 08:31:04 +0200, Irmen de Jong wrote:
>> On 10-10-2014 6:21, Igor Korot wrote:
>
>>> When I am on Windows, I can write something like this:
>>>
>>> sys.path.append('C:\Users\Igor\Documents\MyLib')
>>
>> While this might work on your system, it may not work on others.
>>
>> - you need to escape the backslashes (or just use forward slashes,
>> they work on windows too)
>
> And remember that os.path.join() will join path fragments with
> the right kind of slashes for your operating system.
That's fine if you have the parts separately already, but when it's
primarily a single literal string, just use slashes and save yourself
the trouble.
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2014-10-10 09:52 -0600 |
| Message-ID | <mailman.14755.1412956372.18130.python-list@python.org> |
| In reply to | #78925 |
On Fri, Oct 10, 2014 at 12:31 AM, Irmen de Jong <irmen.NOSPAM@xs4all.nl> wrote: > - you need to escape the backslashes (or just use forward slashes, they work on windows too) Or use a raw string. There is usually no reason to have escape sequences at all in a file system path.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web