Форум сайта python.su
#!/usr/bin/python # -*- coding: utf-8 -*- import os import subprocess from stat import * for root, subFolders, fileNames in os.walk('/'): for fileName in fileNames: path = os.path.join(root, fileName) if path[0:6] == '/proc/': break try: mode = os.stat(path).st_mode if S_ISSOCK(mode): print path if subprocess.call('lsof | grep '+path, shell=True): print 'Данный Socket в режиме прослушивания' else: print 'У Socket есть процесс!' except: pass
pal = self.palette()
pal.setBrush(QPalette.Normal,QPalette.Window,QBrush(image))
self.setPalette(pal)
pixmap = QPixmap('fon.png')
pal = self.palette()
pal.setBrush(QPalette.Normal,QPalette.Window,QBrush(pixmap))
pal.setBrush(QPalette.Inactive,QPalette.Window,QBrush(pixmap))
self.setPalette(pal)
self.setMask(pixmap.mask())
image = QImage('menu/fon50.png')
image = image.scaledToWidth(w.xmax/100*60)
image = image.scaledToHeight(w.xmax/100*60)
pixmap = QPixmap(image)
pal = self.palette()
pal.setBrush(QPalette.Normal,QPalette.Window,QBrush(pixmap))
pal.setBrush(QPalette.Inactive,QPalette.Window,QBrush(pixmap))
self.setPalette(pal)
self.setMask(pixmap.mask())
self.setWindowOpacity(0.5)
#!/usr/bin/python #-*- coding: UTF-8 -*- import os, sys, time, wx, socket, threading def show_mes(text): #создаем окно с текстовым сообщением class InsertFrame(wx.Frame): def __init__(self, parent, id=-1): wx.Frame.__init__(self, parent, id, 'Server info',pos=(1480,1070), size=(370, 80), style=(wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER | wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.SIMPLE_BORDER))) panel = wx.Panel(self) info = text.decode('utf-8') pnl = wx.Panel(self, -1, size=(370, 80), style=wx.NO_BORDER) st1 = wx.TextCtrl(pnl, -1, info, size=(370, 80), style=wx.ALIGN_LEFT | wx.TE_WORDWRAP | wx.TE_READONLY | wx.TE_RICH2) #st1.SetBackgroundColour("Yellow") def OnCloseMe(self, event): self.Close(True) def OnCloseWindow(self, event): self.Destroy() if __name__ == '__main__': app = wx.PySimpleApp() frame = InsertFrame(parent=None, id=-1) frame.Show() app.MainLoop() class MyThread(threading.Thread): def run (self): show_mes(text) class GetTextThread(threading.Thread): def run (self): get_text() def get_text(): #получам сообщение от клиента global text while True: conn, addr = s.accept() text = conn.recv(1448) conn.close() #создаем новый поток для вывода окна с сообщением #иначе функция ожидает закрытия окна thrd = MyThread() thrd.start() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind(('', 3036)) s.listen(300) get_text_thread = GetTextThread() get_text_thread.start()
import os, socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('127.0.0.1', 3036)) s.sendall("some info") s.close()
photo = models.ImageField(upload_to= lambda inst, fname: 'avatars/'+hashlib.md5(str(time.time())).hexdigest()+'.'+re.split('\.',fname)[1][:200], verbose_name=u'Фотография', null=True, blank=True)
class Album(models.Model): name = models.CharField(_('Name'), max_length=100, blank=False, null=False) user = models.ForeignKey(User, verbose_name=_('User'), null=True, blank=True, related_name='albums') created = models.DateTimeField(_('Created'), auto_now_add=True) def __unicode__(self): return self.name class Image(models.Model): description = models.TextField(verbose_name =_('Description'), blank=True, null=True) image = ImageField(verbose_name = _('File'), upload_to=....) album = models.ForeignKey('Album', verbose_name=_('Album'), null=False, blank=False, related_name='images')
thumb = ImageField(verbose_name = _('Mini'), upload_to=....)
{% for lang in LANGUAGES %} {% ifequal lang.0 LANGUAGE_CODE %} <a href="#" id="lang_{{ lang.0 }}">{{ lang.1 }}</a> {% else %} <a href="{{ request.path|chlocale:lang.0 }}" id="lang_{{ lang.0 }}_inactive">{{ lang.1 }}</a> {% endifequal %} {% endfor %}
quote_plus(u'Продажа техно'.encode('utf-8'))
'&'.join(['%s=%s' % (quote_plus(n), quote_plus(v)) for n, v in data])
KeyError: u'\u0414'[
Traceback (most recent call last): File "/home/**/Desktop/python/**/**r.py", line 97, in <module> u'Василий'.encode('utf-8')) File "/home/**/Desktop/python/**/**.py", line 78, in send_post self._http_cl.post(post_url, post_data, post_url) File "/home/**/Desktop/python/**/http.py", line 244, in post self.__postData = '&'.join(['%s=%s' % (quote_plus(n), quote_plus(v)) for n, v in data]) File "/usr/lib/python2.7/urllib.py", line 1257, in quote_plus return quote(s, safe) File "/usr/lib/python2.7/urllib.py", line 1250, in quote return ''.join(map(quoter, s)) KeyError: u'\u0414'
import sys from cx_Freeze import setup, Executable base = None if sys.platform == "win32": base = "Win32GUI" setup( name = "app", version = "0.2", description = "Test App", executables = [Executable("app.py", base=base)])
from Tkinter import * def main(): root = Tk() root.geometry('500x400+300+200') # ширина=500, высота=400, x=300, y=200 text1=Text(root,height=7,width=7,font='Arial 14',wrap=WORD) text1.config(state=DISABLED) text1.place(x=10, y=10, width=470, height=300) scrollbar1 = Scrollbar(root) scrollbar1.place(x=480, y=10, width=10, height=300) scrollbar1['command'] = text1.yview text1['yscrollcommand'] = scrollbar1.set def textout(text): text1.config(state=NORMAL) #text1.delete(1.0, END) text1.insert(END, text) text1.config(state=DISABLED) root.mainloop() if __name__ == '__main__': main()
#rez словарь json обьектов def load(self, rez): if not isnstance(rez, dict): raise TypeError('Argument rez mysr have dict type') for key, value in rez.items(): if not hasattr(self, key): continue if isinstance(value, dict): #Если ключ имеет тип словаря значит грузим в атрибут основного обьекта обьект из массива getattr(self, key).load(value) elif isinstance(value, list): for item in value: else: setattr(self, key, value)