Favour please - i am working on a cross platform script but i'm using linux and i don't have windows. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Favour please - i am working on a cross platform script but i'm using linux and i don't have windows.

os.uname

24th Jul 2017, 4:54 AM
Michael Bosher
Michael Bosher - avatar
9 Respostas
+ 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))
24th Jul 2017, 5:19 AM
Kirk Schafer
Kirk Schafer - avatar
+ 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.
24th Jul 2017, 7:24 AM
Ipang
+ 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?
24th Jul 2017, 5:43 AM
Kirk Schafer
Kirk Schafer - avatar
+ 2
Just do a dual boot to run both OS in parallel or use Virtual Machines.
24th Jul 2017, 7:38 AM
Hanif Ali
Hanif Ali - avatar
+ 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.
24th Jul 2017, 2:33 PM
Kirk Schafer
Kirk Schafer - avatar
+ 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
24th Jul 2017, 4:55 AM
Michael Bosher
Michael Bosher - avatar
+ 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
24th Jul 2017, 5:38 AM
Michael Bosher
Michael Bosher - avatar
+ 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
24th Jul 2017, 11:21 AM
Bogdan Sass
Bogdan Sass - avatar
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
24th Jul 2017, 10:50 AM
Michael Bosher
Michael Bosher - avatar