Can anyone link me or explain the following:
I open a file in a python script. I want the new file's location to be
on the user's desktop in a Windows XP environment. fileHandle = open
(....., 'w' ) what I guess I'm looking for is an environmental
variable that will usually be correct on most XP desktops and will
work in the open statement. Or is there another way?
Thanks 11 5742
On Oct 6, 11:31 pm, goldtech <goldt...@worldpost.comwrote:
Can anyone link me or explain the following:
I open a file in a python script. I want the new file's location to be
on the user's desktop in a Windows XP environment. fileHandle = open
(....., 'w' ) what I guess I'm looking for is an environmental
variable that will usually be correct on most XP desktops and will
work in the open statement. Or is there another way?
This is really a Windows question, not a Python question. You should
have been able to figure it out yourself by examining existing
environment variables.
Something like the code below should work for you if the standard
environment variables haven't been hosed.
----------
import os
Filename = os.getenv("HOMEDRIVE") + os.getenv("HOMEPATH") + "\\Desktop
\MyNewFile"
f = file(Filename, "w")
f.write("Here's a file on the desktop\n")
f.close()
goldtech wrote:
... I want the new file's location to be on the user's desktop in
a Windows XP environment....
How about :
import os.path
handle = open(os.path.expanduser(r'~\DeskTop\somefile.txt') , 'w')
...
-Scott
On Oct 6, 8:31 pm, goldtech <goldt...@worldpost.comwrote:
Can anyone link me or explain the following:
I open a file in a python script. I want the new file's location to be
on the user's desktop in a Windows XP environment. fileHandle = open
(....., 'w' ) what I guess I'm looking for is an environmental
variable that will usually be correct on most XP desktops and will
work in the open statement. Or is there another way?
Thanks
I've always used 'USERPROFILE'. I'm not sure how standard it is, but I
have never run into any issues.
Code for your perusal: -
import os, os.path
-
prof_path = os.environ['USERPROFILE']
-
filename = os.path.join(prof_path,'Desktop','filename.txt')
-
f = open(filename,'w')
-
try:
-
# do stuff with f
-
finally:
-
f.close()
-
Matt
On Oct 6, 2007, at 11:31 PM, goldtech wrote:
Can anyone link me or explain the following:
I open a file in a python script. I want the new file's location to be
on the user's desktop in a Windows XP environment. fileHandle = open
(....., 'w' ) what I guess I'm looking for is an environmental
variable that will usually be correct on most XP desktops and will
work in the open statement. Or is there another way?
Thanks
-- http://mail.python.org/mailman/listinfo/python-list
import os.path
home = os.path.expanduser('~')
desktop = os.path.join(home, 'Desktop')
>
This is really a Windows question, not a Python question. You should
have been able to figure it out yourself by examining existing
environment variables.
I agree, you're right. I learn more by figuring out the code myself.
After Google briefly: In a DOS box type: SET
This was too easy - sorry.
Something like the code below should work for you if the standard
environment variables haven't been hosed.
----------
import os
Filename = os.getenv("HOMEDRIVE") + os.getenv("HOMEPATH") + "\\Desktop
\MyNewFile"
f = file(Filename, "w")
f.write("Here's a file on the desktop\n")
f.close()
Matimus wrote:
On Oct 6, 8:31 pm, goldtech <goldt...@worldpost.comwrote:
>Can anyone link me or explain the following:
I open a file in a python script. I want the new file's location to be on the user's desktop in a Windows XP environment. fileHandle = open (....., 'w' ) what I guess I'm looking for is an environmental variable that will usually be correct on most XP desktops and will work in the open statement. Or is there another way?
Thanks
I've always used 'USERPROFILE'. I'm not sure how standard it is, but I
have never run into any issues.
Code for your perusal: -
import os, os.path
-
prof_path = os.environ['USERPROFILE']
-
filename = os.path.join(prof_path,'Desktop','filename.txt')
-
f = open(filename,'w')
-
try:
-
# do stuff with f
-
finally:
-
f.close()
-
Matt
You are assuming the system is not localized, that won't work if you
distribute your applications internationally. In my system it is not
"Desktop", it is "Escritorio", and I guess it will vary with every
locale. Does someone know a way to find out what name does the desktop
have?
On Oct 7, 1:24 am, Scott David Daniels <Scott.Dani...@Acm.Orgwrote:
goldtech wrote:
... I want the new file's location to be on the user's desktop in
a Windows XP environment....
How about:
import os.path
handle = open(os.path.expanduser(r'~\DeskTop\somefile.txt') , 'w')
...
That doesn't work on my system.
"~" uses the HOME environment variable if set, otherwise uses
HOMEDRIVE and HOMEPATH which is what I posted before. See Lib/
ntpath.py in a recent source distribution.
In my case I set HOME to a path without spaces in it, to simplify my
use of Emacs and Cygwin.
You are assuming the system is not localized, that won't work if you
distribute your applications internationally. In my system it is not
"Desktop", it is "Escritorio", and I guess it will vary with every
locale. Does someone know a way to find out what name does the desktop
have?
I believe you need to read the Desktop value from
"""
HKEY_CURRENT_USER\software\microsoft\windows\curre ntversion\explorer\shell
folders
"""
which should (in my understanding) hold the full path of the
particular folder(s) of interest at that location, including
across localizations.
-tkc
Tim Chase wrote:
>You are assuming the system is not localized, that won't work if you distribute your applications internationally. In my system it is not "Desktop", it is "Escritorio", and I guess it will vary with every locale. Does someone know a way to find out what name does the desktop have?
I believe you need to read the Desktop value from
"""
HKEY_CURRENT_USER\software\microsoft\windows\curre ntversion\explorer\shell
folders
"""
which should (in my understanding) hold the full path of the
particular folder(s) of interest at that location, including
across localizations.
-tkc
Ideally, use the shell API exposed by pywin32:
<code>
from win32com.shell import shell, shellcon
desktop = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
</code>
For slight convenience: http://timgolden.me.uk/python/winshell.html
TJG
Tim Chase wrote:
>You are assuming the system is not localized, that won't work if you distribute your applications internationally. In my system it is not "Desktop", it is "Escritorio", and I guess it will vary with every locale. Does someone know a way to find out what name does the desktop have?
I believe you need to read the Desktop value from
"""
HKEY_CURRENT_USER\software\microsoft\windows\curre ntversion\explorer\shell
folders
"""
which should (in my understanding) hold the full path of the
particular folder(s) of interest at that location, including
across localizations.
-tkc
Ideally, use the shell API exposed by pywin32:
<code>
from win32com.shell import shell, shellcon
desktop = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
</code>
For slight convenience: http://timgolden.me.uk/python/winshell.html
TJG
On Oct 7, 12:30 pm, Tim Golden <t...@timgolden.me.ukwrote:
Tim Chase wrote:
You are assuming the system is not localized, that won't work if you
distribute your applications internationally. In my system it is not
"Desktop", it is "Escritorio", and I guess it will vary with every
locale. Does someone know a way to find out what name does the desktop
have?
I believe you need to read the Desktop value from
"""
HKEY_CURRENT_USER\software\microsoft\windows\curre ntversion\explorer\shell
folders
"""
which should (in my understanding) hold the full path of the
particular folder(s) of interest at that location, including
across localizations.
-tkc
Ideally, use the shell API exposed by pywin32:
<code>
from win32com.shell import shell, shellcon
desktop = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
</code>
For slight convenience:
http://timgolden.me.uk/python/winshell.html
TJG
What happened to your winshell module? I would have thought it perfect
for this. http://timgolden.me.uk/python/winshell.html
Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Noah |
last post by:
I need to create Stuffit (.sit) files on Linux.
Does anyone have any ideas for how to do this?
I checked the Python docs and on SourceForge, but
I didn't see any open source stuffit compatible...
|
by: Tom |
last post by:
I created an msi using the Setup Wizard, but don't seem to be able to create
a shortcut to the applicaton on the desktop (or prompt for one) or the menu.
Also, I would like to add an "uninstall"...
|
by: EC |
last post by:
I am trying to save a file to an end users desktop from the Server on the
click of a button. This works when run the application on my local but does
not work when the application is running on the...
|
by: I_AM_DON_AND_YOU? |
last post by:
There is one more problem I am facing but didn't get the solution. In my
Setup Program I am not been able to create 2 things (when the program is
intalled on the client machine ) : (1) create...
|
by: Michael D. Murphy |
last post by:
Hi,
I am searching for a way to creat desktop shortcuts when running the setup
files that were created within a VB solution using the setup wizard.
Thanks,
Michael
|
by: GrandpaB |
last post by:
I would appreciate assistance learning how to create a Desktop shortcut in my
setup project.
In the left pane of the Setup/File System window I right-clicked User's
Desktop. From the contex...
|
by: paraidy |
last post by:
Hi all, as from object i need to read all byte from a file example c:
\myphoto.jpg and recreate the file with another name to another
directory c:\photo\recreatedphoto.jpg can someone write a...
|
by: pbrown |
last post by:
Hi, I'm using VB.net 2003, and I have a problem.
I need a way of saving a file directly to the desktop, without hardcoding the direct path to the desktop into the program. For example, I'm trying...
|
by: sanghavi |
last post by:
how to create a set up project in vb.net..how to run an application on a different machine
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |