data=[4, 5, 7, 8, 9, 0, 3, 3, 6, 6]
c = [complex(a, b) for a, b in zip(data[:-1:2], data[1::2])]
print(c)
H:\My Documents\PyCharm>py
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
H:\My Documents\PyCharm>py -2
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
[global]
proxy = 127.0.0.1:3128
# -*- coding: utf-8 -*-
import numpy
import multiprocessing
def sub_sum(z):
return numpy.sum(z)
def parallel_sum(values, cpuz):
boundaries = [i for i in range(0, len(values), len(values)//cpuz)]
boundaries[-1] = len(values)
with multiprocessing.Pool(cpuz) as pool:
rc = pool.starmap(sub_sum, [(values[c1:c2],) for c1, c2 in zip(boundaries[: -1], boundaries[1:])])
return sum(rc)
if __name__ == '__main__':
cpuz = multiprocessing.cpu_count()
n = 999
values = numpy.array([i for i in range(n)])
print('cpuz =', cpuz)
print('sum =', parallel_sum(values, cpuz))
print('sum =', n*(n-1)//2)
import unittest
import mock
class B(object):
def some1(self):
print 'some 1'
class C(object):
def some2(self):
print 'some 2'
class A(object):
def __init__(self):
self.b = B()
self.c = C()
def just_do_it(self):
print 'Hello'
self.b.some1()
self.c.some2()
class BMock(object):
def some1(self):
print 'mock.some 1'
class CMock(object):
def some2(self):
print 'mock.some 2'
class ATestCase(unittest.TestCase):
@mock.patch('main.B')
@mock.patch('main.C')
def test_success_just_do_it(self, c, b):
b.side_effect = BMock
c.side_effect = CMock
a = A()
a.just_do_it()
class Main(object): # основная функция
def __init__(self):
self.ab = AB() # создаем экзмпляр класса с переменными
d1 = Dialog1(self.ab) # Создаем экзэмпляр класса который должен поменять переменную ab.a
d2 = Dialog2(self) # Создаем экзэмпляр класса который должен поменять переменную ab.b
def sum(self):
c = self.ab.a + self.ab.b
print(c)
class Dialog1(object):
def __init__(self, parent):
parent.a = 5 # !!! Пытаюсь поменять значение в переменной созданом в родительском классе Main
class Dialog2(object):
def __init__(self, parent):
parent.ab.b = 6 # !!! Пытаюсь поменять значение в переменной созданом в родительском классе Main
class AB(object):
a = 1
b = 2
m = Main()
print(m.ab.a)
print(m.ab.b)
Python » 3.5.1 Documentation » The Python Standard Library » 29. Python Runtime Services » sys
The character encoding is platform-dependent.
Under Windows, if the stream is interactive (that is, if
its isatty() method returns True), the console codepage is
used, otherwise the ANSI code page.
Under other platforms, the locale encoding is used (see
locale.getpreferredencoding()).
Under all platforms though, you can override this value
by setting the PYTHONIOENCODING environment variable
before starting Python.
When interactive, standard streams are line-buffered. Otherwise,
they are block-buffered like regular text files. You can override
this value with the -u command-line option.
import ctypes
def ansi_encoding():
return 'cp'+str(ctypes.windll.kernel32.GetACP())
def console_output_encoding():
return 'cp'+str(ctypes.windll.kernel32.GetConsoleOutputCP())
# -*- encoding: utf-8 -*-
from __future__ import print_function
import sys
print(sys.version)
print(u'Здравствуй жопа, новый год!')