Форум сайта python.su
from __future__ import division from sympy import * x, y, z, t = symbols('x y z t') k, m, n = symbols('k m n', integer=True) f, g, h = symbols('f g h', cls=Function) In [1]: residue(tanh(x), x, 3*I*pi/2) --------------------------------------------------------------------------- PoleError Traceback (most recent call last) /.../.../<ipython-input-1-06ae92309a12> in <module>() ----> 1 residue(tanh(x), x, 3*I*pi/2) /usr/lib/python2.7/dist-packages/sympy/series/residues.pyc in residue(expr, x, x0) 43 if x0 != 0: 44 expr = expr.subs(x, x+x0) ---> 45 s = expr.series(x, 0, 0).removeO() 46 # TODO: this sometimes helps, but the series expansion should rather be 47 # fixed, see #1627: /usr/lib/python2.7/dist-packages/sympy/core/expr.pyc in series(self, x, x0, n, dir) 1560 1561 if n != None: # nseries handling -> 1562 s1 = self._eval_nseries(x, n=n, logx=None) 1563 o = s1.getO() or S.Zero 1564 if o: /usr/lib/python2.7/dist-packages/sympy/core/function.pyc in _eval_nseries(self, x, n, logx) 378 term = e.subs(x, S.Zero) 379 if term.is_bounded is False or term is S.NaN: --> 380 raise PoleError("Cannot expand %s around 0" % (self)) 381 series = term 382 fact = S.One PoleError: Cannot expand tanh(x + 3*I*pi/2) around 0
In [2]: residue(tan(x), x, 3*pi/2) Out[2]: -1
>>> import serial >>> ser = serial.Serial('/dev/ttyUSB0', 9600) >>> ser.isOpen() True >>> ser.inWaiting() 0 >>> print ser.read(ser.inWaiting()) тут вообще ничего не выводит
from django.utils import timezone fdate_time = datetime.datetime.strptime(mydatetime, '%d.%m.%Y %H:%M').replace(tzinfo=timezone.utc)
# -*- coding: utf-8 -*- """ amazon_sender.py ~~~~~~~~ Python helper class that can send emails using Amazon SES and boto. The biggest feature of this class is that encodings are handled properly. It can send both text and html emails. This implementation is using Python's standard library (which opens up for a lot more options). Example:: amazon_sender = AmazonSender(AWS_ID, AWS_SECRET) amazon_sender.send_email(sender=u'???? <john@doe.com>', to='blah@blah.com', subject='Hello friend', text='Just a message', html='<b>Just a message</b>', sender_ascii='Ascii Sender <no_reply@wedoist.com>') :copyright: 2011 by Amir Salihefendic ( http://amix.dk/ ). :license: BSD """ import types from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.utils import COMMASPACE from boto.ses import SESConnection class AmazonSender(object): client = None def __init__(self, aws_key, aws_secret): self.aws_key = aws_key self.aws_secret = aws_secret def send_email(self, sender, to_addresses, subject, text, html=None, reply_addresses=None, sender_ascii=None): if not sender_ascii: sender_ascii = sender client = self.get_client() message = MIMEMultipart('alternative') message.set_charset('UTF-8') message['Subject'] = _encode_str(subject) message['From'] = _encode_str(sender) message['To'] = _convert_to_strings(to_addresses) if reply_addresses: message['Reply-To'] = _convert_to_strings(reply_addresses) message.attach(MIMEText(_encode_str(text), 'plain')) if html: message.attach(MIMEText(_encode_str(html), 'html')) # return client.send_raw_email(sender_ascii, message.as_string(), # destinations=to_addresses) return client.send_raw_email(message.as_string(), sender_ascii, destinations=to_addresses) def vertify_email(self, email): client = self.get_client() return client.verify_email_address(email) def get_client(self): if not self.client: self.client = SESConnection(self.aws_key, self.aws_secret) return self.client #--- Helpers ---------------------------------------------- def _convert_to_strings(list_of_strs): if isinstance(list_of_strs, (list, tuple)): result = COMMASPACE.join(list_of_strs) else: result = list_of_strs return _encode_str(result) def _encode_str(s): if type(s) == types.UnicodeType: return s.encode('utf8') return s
[code python][/code]
class QProxyTypeBox(QtGui.QGroupBox): ''' Бокс для выбора типа прокси. Атрибуты: proxy_type - Может принимать значение: SOCKS4\SOCKS5\HTTP\NONE ''' def __init__(self, parent=None): super(QtGui.QGroupBox, self).__init__(parent) self.setTitle(u'Тип прокси') self.proxy_type = 'HTTP' self.layout = QtGui.QVBoxLayout() self.layout.setContentsMargins(5, 5, 0, 0) self.layout.setAlignment(Qt.AlignLeft) self.layout.setSpacing(0) self.button_group = QtGui.QButtonGroup(self) self.button_group.buttonClicked.connect(self._button_clicked) proxy_types = ('SOCKS5', 'SOCKS4', 'HTTP', 'NONE') for t in proxy_types: b = QtGui.QRadioButton(t) self.button_group.addButton(b) self.layout.addWidget(b) self.button_group.buttons()[1].setChecked(True) self.setMaximumWidth(100) self.setLayout(self.layout) def _button_clicked(self, button): self.proxy_type = str(button.text()) def setNoneButtonEnabled(self, enabled): self.button_group.buttons()[-1].setEnabled(enabled) def getNoneButtonEnabled(self): return self.button_group.buttons()[-1].enabled() noneButtonEnabled = pyqtProperty(bool, getNoneButtonEnabled, setNoneButtonEnabled)
app = QtGui.QApplication([]) p = QProxyTypeBox() p.show() p.noneButtonEnabled = True print p.noneButtonEnabled exit(app.exec_())
print p.noneButtonEnabled AttributeError: 'QProxyTypeBox' object has no attribute 'noneButtonEnabled'
return self.button_group.buttons()[-1].enabled() #Нету свойства enabled, есть isEnabled
import httplib, base64, urllib def tU(x): return unicode(x) def fH(x): return x.decode('hex') def tH(x): return x.encode('hex') def fU8(x): return x.decode('u8') def tU8(x): return x.encode('u8') def fB64(x): return x.decode('base64') def tB64(x): return x.encode('base64') def YaDiskPropfind(method,url,body,headers): conn = httplib.HTTPSConnection("webdav.yandex.ru", port=443) conn.request(method=method,url=url,body=body,headers=headers) resp = conn.getresponse() print '%s - %s'%(str(resp.status),str(resp.reason)) r=resp.read() return r # Метод соединения _method = 'PROPFIND / HTTP/1.1' # Директория на сервере _url = None # Тело запроса _body = """<D:propfind xmlns:D="DAV:"> <D:prop> <D:quota-available-bytes/> <D:quota-used-bytes/> </D:prop> </D:propfind>""" # Заголовки с параметрами запроса _headers = { "User-Agent": "Yandex Disk S60", "Content-Type": "text/xml", "Content-Length": str(len(_body)), "Host": "webdav.yandex.ru", "Accept": "*/*", "Depth": "0", "Authorization": "Basic %s"%tB64("<ИМЯ_АККАУНТА>:<ПАРОЛЬ>")[:-1] } print tU(YaDiskPropfind(_method,_url,_body,_headers))
Traceback (most recent call last): File "E:\private\2000b1a5\default.py", line 81, in menu_action f() File "E:\private\2000b1a5\default.py", line 65, in query_and_exec execfile(script_list[index][1].encode('utf-8'), script_namespace.namespace) File "c:\python\FreeSpace.py", line 41, in ? print tU(YaDiskPropfind(_method,_url,_body,_headers)) File "c:\python\FreeSpace.py", line 16, in YaDiskPropfind r=resp.read() File "E:\HTTPLIB.PY", line 239, in read s = self.fp.read() File "E:\HTTPLIB.PY", line 810, in read assert not self._line_consumed and self._line_left AssertionError
#!/usr/bin/env python # -*- coding: utf-8 -*- # import cgitb import cgi import simplejson as json #Тут он ругаеться что не может импортировать json
[Sun Mar ] [error] [client ***********] Traceback (most recent call last): [Sun Mar ] [error] [client ***********] File "/var/www/html/main.py" [Sun Mar ] [error] [client ***********] import json, referer [Sun Mar ] [error] [client ***********] ImportError: No module named json
def do_city_action(): global sigs, u, k while True: action_id = 1 while action_id < 8: for _ in range(0,5): post = urllib.parse.urlencode({ 'method' : 'doCityAction', 'city' : '1', 'action_id' : str(action_id), 'action_type' : '3', 'sig' : random.choice(sigs), 'user' : u, 'key' : k }) response = request(post) print('Выполнил задание') if int(minidom.parseString(str(response, 'utf8')).getElementsByTagName('energy')[0].firstChild.data) < 10: time.sleep(40*5*60) action_id +=1
admin.py class AdminImageWidget(AdminFileWidget): def render(self, name, value, attrs=None): output = [] if value and hasattr(value, "url"): obj = Image.objects.get(image=value) output.append(('<a target="_blank" href="%s"><img src="%s"></a>' % (value.url, obj.thumbnail.url))) output.append(super(AdminImageWidget, self).render(name, value, attrs)) return mark_safe(u''.join(output)) class ImageInline(admin.StackedInline): model = Image formfield_overrides = { models.ImageField: {'widget': AdminImageWidget}, }
class CommentWithTitle(Comment): title = models.CharField(max_length=300) @models.permalink def delete_comment_url(self): return ('delete_comment', (), {'comment_id': self.pk,})
class CommentWithTitle(Comment): title = models.CharField(max_length=300) def __init__(self, *args, **kwargs): print "new init assign permissions" super(CommentWithTitle, self).__init__(*args, **kwargs) @models.permalink def delete_comment_url(self): return ('delete_comment', (), {'comment_id': self.pk,})