Created
December 14, 2011 13:01
-
-
Save dketov/1476484 to your computer and use it in GitHub Desktop.
Взаимодействие с ОС
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Аргументы командной строки | |
""" | |
import sys, os | |
print 'sys.argv[0] =', sys.argv[0] | |
pathname = os.path.dirname(sys.argv[0]) | |
print 'path =', pathname | |
print 'full path =', os.path.abspath(pathname) | |
# make sure we have the right number of command line parameters | |
if len(sys.argv) != 3: | |
print "\nSyntax: hexcal month year (where month is 1 - 12)\n" | |
sys.exit(1) | |
# convert the two command line parameters to numerical values | |
# (they come in as strings) | |
try: | |
month = int(sys.argv[1]) | |
year = int(sys.argv[2]) | |
# get the matrix of days and weeks in the month | |
monthMatrix = monthcalendar(year, month) | |
except ValueError, message: | |
print "Error:", message | |
sys.exit(2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Завершение работы программы | |
""" | |
def bye(): | |
import os | |
print 'Bye os world' | |
os._exit(99) | |
print 'Never reached' | |
if __name__ == '__main__': bye() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Переменные окружения | |
""" | |
import os | |
os.environ['USER'] = 'Mel' | |
os.popen('python echoenv.py').read() | |
import os | |
os.environ.keys() | |
os.environ['TEMP'] | |
os.environ['TEMP'] = r'c:\temp' | |
os.environ['TEMP'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Рабочий каталог и путь поиска модулей | |
""" | |
import os, sys | |
print 'my os.getcwd =>', os.getcwd() | |
print 'my sys.path =>', sys.path[:6] | |
if 'linux' in sys.platform: | |
sys.path.append(r'/home/user/python/lib') | |
if 'win32' in sys.platform: | |
sys.path.append(r'C:\python26') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Разбор опций командной строки | |
""" | |
from optparse import OptionParser | |
parser = OptionParser() | |
parser.add_option("-f", "--file", dest="filename", | |
help="write report to FILE", metavar="FILE") | |
parser.add_option("-q", "--quiet", | |
action="store_false", dest="verbose", default=True, | |
help="don't print status messages to stdout") | |
(options, args) = parser.parse_args() | |
print options.verbose | |
print options.filename |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Информация о системе | |
""" | |
import platform | |
print 'uname:', platform.uname() | |
print 'system :', platform.system() | |
print 'node :', platform.node() | |
print 'release :', platform.release() | |
print 'version :', platform.version() | |
print 'machine :', platform.machine() | |
print 'processor:', platform.processor() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment