-
Notifications
You must be signed in to change notification settings - Fork 0
2. general topics
jetxeberria edited this page Dec 28, 2018
·
3 revisions
2.2 Image processing
The subprocess library allows to manage operative system commands. There are several ways to use it. See here
import subprocess
p = subprocess.Popen(["ls", "-l", "/etc/resolv.conf"], stdout=subprocess.PIPE)
output, err = p.communicate()
print "*** Running ls -l command ***\n", output
Output:
> *** Running ls -l command ***
> -rw-r--r-- 1 root root 157 Nov 7 15:06 /etc/resolv.conf
- sys.path is a variable of module sys that contains the list of directories which will be searched for modules at runtime
import sys
sys.path
- Execute it from linux terminal without joining the interactive python by typing:
python -c 'import sys; print "\n".join(sys.path)'
- Check which modules are built in by typing in Python or Ipython:
import sys
sys.builtin_module_names
To print special unicode characters, find the code in internet and it can be printed directly
text = u'2 \u00B1 1'
Output:
2 (+-) 1
But if it pass through the str() function, it needs to be explicitly advised the encoding
text = '2 {simbol} 1'.format(simbol=u'\u00B1'.encode('utf-8'))
Output:
2 (+-) 1