Skip to content
Advertisement

Relative paths in Python [duplicate]

This question already has answers here: How do you properly determine the current script directory? (16 answers) Closed 6 months ago. I’m building a simple helper script for work that will copy a couple of template files in our code base to the current directory. I don’t, however, have the absolute path to the directory where the templates are stored.

os.system() execute command under which linux shell?

I am using /bin/tcsh as my default shell. However, the tcsh style command os.system(‘setenv VAR val’) doesn’t work for me. But os.system(‘export VAR=val’) works. So my question is how can I know the os.system() run command under which shell? Answer os.system() just calls the system() system call (“man 3 system”). On most *nixes this means you get /bin/sh. Note that

How to ignore deprecation warnings in Python

I keep getting this : How do I make this message go away? Is there a way to avoid warnings in Python? Answer From documentation of the warnings module: If you’re on Windows: pass -W ignore::DeprecationWarning as an argument to Python. Better though to resolve the issue, by casting to int. (Note that in Python 3.2, deprecation warnings are ignored

Is there a portable way to get the current username in Python?

What is a portable way (e.g. for Linux and Windows) to get the current user’s username? Something similar to os.getuid() would be nice: The pwd module works for Unix only. Some people suggest that getting the username under Windows can be complicated in certain circumstances (e.g., running as a Windows service). Answer Look at getpass module Availability: Unix, Windows p.s.

Advertisement