0
Favour please - i am working on a cross platform script but i'm using linux and i don't have windows.
os.uname
9 odpowiedzi
+ 4
CodePlayground's Python runs on Windows servers. You can run the snippet (below) here.
# os.uname does not appear in os's directory:
import os
print(dir(os))
+ 4
@michael, I can't help you with the first issue, but I can tell you location of My Documents on various Windows versions. There are differences but by default Windows created the folder in the boot drive/volume (e.g. C:)
Windows 2000, XP, 2003
\Documents and Settings\(User_Name)\My Documents\
Windows Vista or higher
\Users\(User_Name)\Documents\
Where; (User_Name) is the current user's name.
+ 2
I sometimes use the Little Drops (Python docs) Android app, just checked; it reads:
"Availability: recent flavors of Unix."
Explanation by omission I guess?
+ 2
Just do a dual boot to run both OS in parallel or use Virtual Machines.
+ 2
Environment variables*. At a prompt you would type:
echo %USERPROFILE%
In Python:
import os
print(os.environ) # all variables, same as 'set' (Windows) and 'env' (Linux-like)
print("*"*10) # separator
# ..\Playground output bug workaround (space)
tmp = os.getenv("userprofile")
print(tmp[:1] + " " + tmp[1:])
* There are other ways to ask the OS directly, let me know if you'd like options.
+ 1
could someone with windows type the following into the python console
import os
os.uname
what did it say?
what is the path to my documents on windows?
thanks
+ 1
that strange its listed in the os mod webpage. i'm sure i ve used it before in other scripts. i ll double check
+ 1
For *nix it is better to use $HOME - not all installations use /home/username.
For a cross-platform way of doing this, see:
https://stackoverflow.com/questions/4028904/how-to-get-the-home-directory-in-JUMP_LINK__&&__python__&&__JUMP_LINK
0
Thanks Ipang and everyone else. So basically i just wanted to find the os using a function such as uname or using os.system and piping the results to the console using popen or subprocess. then run an if statement to determine whiçh os is being used, and depending on the os running an os.path.isfile or isdir to double check if the output folder has already been created in the home folder and then start my program script which writes new blocks of code to file as i mentioned in another post.
anyone got a better solution to determing the home folder. my current solution is using os.mknod, mkdir,isfile,isdir and if statements. i also have declared the variable user and then piped the results of os.system('whoami') to the terminal and stored it as a varable using subprocess.
so that way its easier to write a path as '/home/' + user + '/mycode/'
that way the filepath will automatically change to suit the user